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
70 virtual ~wxGridTableBase();
72 // You must override these functions in a derived table class
74 virtual long GetNumberRows() = 0;
75 virtual long GetNumberCols() = 0;
76 virtual wxString
GetValue( int row
, int col
) = 0;
77 virtual void SetValue( int row
, int col
, const wxString
& s
) = 0;
78 virtual bool IsEmptyCell( int row
, int col
) = 0;
80 // Overriding these is optional
82 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
83 virtual wxGrid
* GetView() const { return m_view
; }
85 virtual void Clear() {}
86 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
87 virtual bool AppendRows( size_t numRows
= 1 );
88 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
89 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
90 virtual bool AppendCols( size_t numCols
= 1 );
91 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
93 virtual wxString
GetRowLabelValue( int row
);
94 virtual wxString
GetColLabelValue( int col
);
95 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
96 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
98 DECLARE_ABSTRACT_CLASS( wxGridTableBase
);
103 // IDs for messages sent from grid table to view
105 enum wxGridTableRequest
{
106 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
107 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
108 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
109 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
110 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
111 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
112 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
113 wxGRIDTABLE_NOTIFY_COLS_DELETED
116 class WXDLLEXPORT wxGridTableMessage
118 wxGridTableBase
*m_table
;
124 wxGridTableMessage();
125 wxGridTableMessage( wxGridTableBase
*table
, int id
,
129 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
130 wxGridTableBase
* GetTableObject() const { return m_table
; }
131 void SetId( int id
) { m_id
= id
; }
132 int GetId() { return m_id
; }
133 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
134 int GetCommandInt() { return m_comInt1
; }
135 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
136 int GetCommandInt2() { return m_comInt2
; }
141 // ------ wxGridStringArray
142 // A 2-dimensional array of strings for data values
145 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString
, wxGridStringArray
);
149 // ------ wxGridStringTable
151 // Simplest type of data table for a grid for small tables of strings
152 // that are stored in memory
155 class WXDLLEXPORT wxGridStringTable
: public wxGridTableBase
157 wxGridStringArray m_data
;
159 // These only get used if you set your own labels, otherwise the
160 // GetRow/ColLabelValue functions return wxGridTableBase defaults
162 wxArrayString m_rowLabels
;
163 wxArrayString m_colLabels
;
167 wxGridStringTable( int numRows
, int numCols
);
168 ~wxGridStringTable();
170 // these are pure virtual in wxGridTableBase
172 long GetNumberRows();
173 long GetNumberCols();
174 wxString
GetValue( int row
, int col
);
175 void SetValue( int row
, int col
, const wxString
& s
);
176 bool IsEmptyCell( int row
, int col
);
178 // overridden functions from wxGridTableBase
181 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
182 bool AppendRows( size_t numRows
= 1 );
183 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
184 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
185 bool AppendCols( size_t numCols
= 1 );
186 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
188 void SetRowLabelValue( int row
, const wxString
& );
189 void SetColLabelValue( int col
, const wxString
& );
190 wxString
GetRowLabelValue( int row
);
191 wxString
GetColLabelValue( int col
);
193 DECLARE_DYNAMIC_CLASS( wxGridStringTable
)
198 //////////////////////////////////////////////////////////////////////
202 //////////////////////////////////////////////////////////////////////
204 class WXDLLEXPORT wxGridCellCoords
210 wxGridCellCoords() { m_row
= m_col
= -1; }
211 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
213 // default copy ctor is ok
215 long GetRow() const { return m_row
; }
216 void SetRow( long n
) { m_row
= n
; }
217 long GetCol() const { return m_col
; }
218 void SetCol( long n
) { m_col
= n
; }
219 void Set( long row
, long col
) { m_row
= row
; m_col
= col
; }
221 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
223 if ( &other
!= this )
231 bool operator==( const wxGridCellCoords
& other
)
233 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
236 bool operator!=( const wxGridCellCoords
& other
)
238 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
243 return (m_row
== -1 && m_col
== -1 );
248 // For comparisons...
250 extern wxGridCellCoords wxGridNoCellCoords
;
251 extern wxRect wxGridNoCellRect
;
253 // An array of cell coords...
255 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords
, wxGridCellCoordsArray
);
259 // This set of classes is to provide for the use of different types of
260 // cell edit controls in the grid while avoiding the wx class info
261 // system in deference to wxPython
263 class WXDLLEXPORT wxGridTextCtrl
: public wxTextCtrl
267 // TRUE for controls placed over cells,
268 // FALSE for a control on a grid control panel
269 bool m_isCellControl
;
273 void OnKeyDown( wxKeyEvent
& );
277 wxGridTextCtrl( wxWindow
*,
281 const wxString
& value
= wxEmptyString
,
282 const wxPoint
& pos
= wxDefaultPosition
,
283 const wxSize
& size
= wxDefaultSize
,
286 void SetStartValue( const wxString
& );
287 wxString
GetStartValue() { return startValue
; }
289 DECLARE_DYNAMIC_CLASS( wxGridTextCtrl
)
290 DECLARE_EVENT_TABLE()
294 class WXDLLEXPORT wxGridRowLabelWindow
: public wxWindow
298 void OnPaint( wxPaintEvent
& event
);
299 void OnMouseEvent( wxMouseEvent
& event
);
300 void OnKeyDown( wxKeyEvent
& event
);
303 wxGridRowLabelWindow() {}
304 wxGridRowLabelWindow( wxGrid
*parent
, wxWindowID id
,
305 const wxPoint
&pos
, const wxSize
&size
);
307 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow
)
308 DECLARE_EVENT_TABLE()
312 class WXDLLEXPORT wxGridColLabelWindow
: public wxWindow
316 void OnPaint( wxPaintEvent
&event
);
317 void OnMouseEvent( wxMouseEvent
& event
);
318 void OnKeyDown( wxKeyEvent
& event
);
321 wxGridColLabelWindow() {}
322 wxGridColLabelWindow( wxGrid
*parent
, wxWindowID id
,
323 const wxPoint
&pos
, const wxSize
&size
);
325 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow
)
326 DECLARE_EVENT_TABLE()
330 class WXDLLEXPORT wxGridCornerLabelWindow
: public wxWindow
334 void OnMouseEvent( wxMouseEvent
& event
);
335 void OnKeyDown( wxKeyEvent
& event
);
338 wxGridCornerLabelWindow() {}
339 wxGridCornerLabelWindow( wxGrid
*parent
, wxWindowID id
,
340 const wxPoint
&pos
, const wxSize
&size
);
342 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow
)
343 DECLARE_EVENT_TABLE()
348 class WXDLLEXPORT wxGridWindow
: public wxPanel
351 wxGridRowLabelWindow
*m_rowLabelWin
;
352 wxGridColLabelWindow
*m_colLabelWin
;
354 void OnPaint( wxPaintEvent
&event
);
355 void OnMouseEvent( wxMouseEvent
& event
);
356 void OnKeyDown( wxKeyEvent
& );
360 wxGridWindow( wxGrid
*parent
,
361 wxGridRowLabelWindow
*rowLblWin
,
362 wxGridColLabelWindow
*colLblWin
,
363 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
366 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
368 DECLARE_DYNAMIC_CLASS(wxGridWindow
)
369 DECLARE_EVENT_TABLE()
374 class WXDLLEXPORT wxGrid
: public wxScrolledWindow
379 wxGridWindow
*m_gridWin
;
380 wxGridRowLabelWindow
*m_rowLabelWin
;
381 wxGridColLabelWindow
*m_colLabelWin
;
382 wxGridCornerLabelWindow
*m_cornerLabelWin
;
384 wxBoxSizer
*m_mainSizer
;
385 wxBoxSizer
*m_topSizer
;
386 wxBoxSizer
*m_middleSizer
;
388 wxGridTableBase
*m_table
;
398 wxGridCellCoords m_currentCellCoords
;
400 wxGridCellCoords m_selectedTopLeft
;
401 wxGridCellCoords m_selectedBottomRight
;
403 int m_defaultRowHeight
;
404 wxArrayInt m_rowHeights
;
405 wxArrayInt m_rowBottoms
;
407 int m_defaultColWidth
;
408 wxArrayInt m_colWidths
;
409 wxArrayInt m_colRights
;
412 int m_colLabelHeight
;
414 wxColour m_labelBackgroundColour
;
415 wxColour m_labelTextColour
;
418 int m_rowLabelHorizAlign
;
419 int m_rowLabelVertAlign
;
420 int m_colLabelHorizAlign
;
421 int m_colLabelVertAlign
;
423 bool m_defaultRowLabelValues
;
424 bool m_defaultColLabelValues
;
426 wxColour m_gridLineColour
;
427 bool m_gridLinesEnabled
;
429 wxFont m_defaultCellFont
;
431 wxGridCellCoordsArray m_cellsExposed
;
432 wxArrayInt m_rowsExposed
;
433 wxArrayInt m_colsExposed
;
434 wxArrayInt m_rowLabelsExposed
;
435 wxArrayInt m_colLabelsExposed
;
441 enum { WXGRID_CURSOR_DEFAULT
,
442 WXGRID_CURSOR_SELECT_CELL
,
443 WXGRID_CURSOR_RESIZE_ROW
,
444 WXGRID_CURSOR_RESIZE_COL
,
445 WXGRID_CURSOR_SELECT_ROW
,
446 WXGRID_CURSOR_SELECT_COL
453 wxGridCellCoords m_selectionStart
;
455 wxCursor m_rowResizeCursor
;
456 wxCursor m_colResizeCursor
;
458 bool m_editable
; // applies to whole grid
459 int m_editCtrlType
; // for current cell
460 wxWindow
* m_cellEditCtrl
;
461 bool m_cellEditCtrlEnabled
;
466 void CalcDimensions();
467 bool Redimension( wxGridTableMessage
& );
470 bool SendEvent( const wxEventType
,
474 bool SendEvent( const wxEventType
,
478 void OnPaint( wxPaintEvent
& );
479 void OnSize( wxSizeEvent
& );
480 void OnKeyDown( wxKeyEvent
& );
483 void SetCurrentCell( const wxGridCellCoords
& coords
);
484 void SetCurrentCell( int row
, int col
)
485 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
488 // ------ functions to get/send data (see also public functions)
490 bool GetModelValues();
491 bool SetModelValues();
494 ////////////////////// Public section ////////////////////
500 wxGrid( wxWindow
*parent
,
502 const wxPoint
& pos
= wxDefaultPosition
,
503 const wxSize
& size
= wxDefaultSize
,
505 const wxString
& name
= wxPanelNameStr
);
509 bool CreateGrid( int numRows
, int numCols
);
512 // ------ grid dimensions
514 int GetNumberRows() { return m_numRows
; }
515 int GetNumberCols() { return m_numCols
; }
518 // ------ display update functions
520 void CalcRowLabelsExposed( wxRegion
& reg
);
521 void CalcColLabelsExposed( wxRegion
& reg
);
522 void CalcCellsExposed( wxRegion
& reg
);
525 // ------ event handlers
527 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
528 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
529 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
530 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
531 bool ProcessTableMessage( wxGridTableMessage
& );
534 wxGridTableBase
* GetTable() const { return m_table
; }
535 void SetTable( wxGridTableBase
*table
) { m_table
= table
; }
538 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
539 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
540 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
541 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
542 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
543 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
545 void DrawGridCellArea( wxDC
& dc
);
546 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
547 void DrawAllGridLines( wxDC
& dc
); // TODO - delete this ?
548 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
549 void DrawCellBackground( wxDC
& dc
, const wxGridCellCoords
& );
550 void DrawCellValue( wxDC
& dc
, const wxGridCellCoords
& );
552 void DrawRowLabels( wxDC
& dc
);
553 void DrawRowLabel( wxDC
& dc
, int row
);
554 void DrawColLabels( wxDC
& dc
);
555 void DrawColLabel( wxDC
& dc
, int col
);
558 // ------ Cell text drawing functions
560 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
561 int horizontalAlignment
= wxLEFT
,
562 int verticalAlignment
= wxTOP
);
564 // Split a string containing newline chararcters into an array of
565 // strings and return the number of lines
567 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
569 void GetTextBoxSize( wxDC
& dc
,
570 wxArrayString
& lines
,
571 long *width
, long *height
);
575 // Code that does a lot of grid modification can be enclosed
576 // between BeginBatch() and EndBatch() calls to avoid screen
579 void BeginBatch() { m_batchCount
++; }
580 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
581 int GetBatchCount() { return m_batchCount
; }
584 // ------ edit control functions
586 bool IsEditable() { return m_editable
; }
587 void EnableEditing( bool edit
);
589 #if 0 // at the moment the cell edit control is always active
590 void EnableCellEditControl( bool enable
);
593 bool IsCellEditControlEnabled()
594 { return (m_cellEditCtrl
&& m_cellEditCtrlEnabled
); }
596 void ShowCellEditControl();
597 void HideCellEditControl();
598 void SetEditControlValue( const wxString
& s
= wxEmptyString
);
599 void SaveEditControlValue();
602 // ------ grid location functions
603 // Note that all of these functions work with the logical coordinates of
604 // grid cells and labels so you will need to convert from device
605 // coordinates for mouse events etc.
607 void XYToCell( int x
, int y
, wxGridCellCoords
& );
611 int YToEdgeOfRow( int y
);
612 int XToEdgeOfCol( int x
);
614 wxRect
CellToRect( int row
, int col
);
615 wxRect
CellToRect( const wxGridCellCoords
& coords
)
616 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
618 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
619 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
621 // check to see if a cell is either wholly visible (the default arg) or
622 // at least partially visible in the grid window
624 bool IsVisible( int row
, int col
, bool wholeCellVisible
= TRUE
);
625 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= TRUE
)
626 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
627 void MakeCellVisible( int row
, int col
);
628 void MakeCellVisible( const wxGridCellCoords
& coords
)
629 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
632 // ------ grid cursor movement functions
634 void SetGridCursor( int row
, int col
)
635 { SelectCell( wxGridCellCoords(row
, col
) ); }
638 bool MoveCursorDown();
639 bool MoveCursorLeft();
640 bool MoveCursorRight();
643 bool MoveCursorUpBlock();
644 bool MoveCursorDownBlock();
645 bool MoveCursorLeftBlock();
646 bool MoveCursorRightBlock();
649 // ------ label and gridline formatting
651 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
652 int GetRowLabelSize() { return m_rowLabelWidth
; }
653 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
654 int GetColLabelSize() { return m_colLabelHeight
; }
655 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
656 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
657 wxFont
GetLabelFont() { return m_labelFont
; }
658 void GetRowLabelAlignment( int *horiz
, int *vert
);
659 void GetColLabelAlignment( int *horiz
, int *vert
);
660 wxString
GetRowLabelValue( int row
);
661 wxString
GetColLabelValue( int col
);
662 wxColour
GetGridLineColour() { return m_gridLineColour
; }
664 void SetRowLabelSize( int width
);
665 void SetColLabelSize( int height
);
666 void SetLabelBackgroundColour( const wxColour
& );
667 void SetLabelTextColour( const wxColour
& );
668 void SetLabelFont( const wxFont
& );
669 void SetRowLabelAlignment( int horiz
, int vert
);
670 void SetColLabelAlignment( int horiz
, int vert
);
671 void SetRowLabelValue( int row
, const wxString
& );
672 void SetColLabelValue( int col
, const wxString
& );
673 void SetGridLineColour( const wxColour
& );
675 void EnableGridLines( bool enable
= TRUE
);
676 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
679 // ------ row and col formatting
681 int GetDefaultRowSize();
682 int GetRowSize( int row
);
683 int GetDefaultColSize();
684 int GetColSize( int col
);
685 wxColour
GetDefaultCellBackgroundColour();
686 wxColour
GetCellBackgroundColour( int row
, int col
);
687 wxColour
GetDefaultCellTextColour();
688 wxColour
GetCellTextColour( int row
, int col
);
689 wxFont
GetDefaultCellFont();
690 wxFont
GetCellFont( int row
, int col
);
691 void GetDefaultCellAlignment( int *horiz
, int *vert
);
692 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
694 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
695 void SetRowSize( int row
, int height
);
696 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
697 void SetColSize( int col
, int width
);
698 void SetDefaultCellBackgroundColour( const wxColour
& );
699 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
700 void SetDefaultCellTextColour( const wxColour
& );
701 void SetCellTextColour( int row
, int col
, const wxColour
& );
702 void SetDefaultCellFont( const wxFont
& );
703 void SetCellFont( int row
, int col
, const wxFont
& );
704 void SetDefaultCellAlignment( int horiz
, int vert
);
705 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
708 // ------ cell value accessors
710 wxString
GetCellValue( int row
, int col
)
714 return m_table
->GetValue( row
, col
);
718 return wxEmptyString
;
722 wxString
GetCellValue( const wxGridCellCoords
& coords
)
723 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
725 void SetCellValue( int row
, int col
, const wxString
& s
);
726 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
727 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
731 // ------ selections of blocks of cells
733 void SelectRow( int row
, bool addToSelected
= FALSE
);
734 void SelectCol( int col
, bool addToSelected
= FALSE
);
736 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
738 void SelectBlock( const wxGridCellCoords
& topLeft
,
739 const wxGridCellCoords
& bottomRight
)
740 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
741 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
746 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
747 m_selectedBottomRight
!= wxGridNoCellCoords
);
750 void ClearSelection();
752 bool IsInSelection( int row
, int col
)
753 { return ( IsSelection() &&
754 row
>= m_selectedTopLeft
.GetRow() &&
755 col
>= m_selectedTopLeft
.GetCol() &&
756 row
<= m_selectedBottomRight
.GetRow() &&
757 col
<= m_selectedBottomRight
.GetCol() );
760 bool IsInSelection( const wxGridCellCoords
& coords
)
761 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
763 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
765 // these will all be -1 if there is no selected block
767 *topRow
= m_selectedTopLeft
.GetRow();
768 *leftCol
= m_selectedTopLeft
.GetCol();
769 *bottomRow
= m_selectedBottomRight
.GetRow();
770 *rightCol
= m_selectedBottomRight
.GetCol();
773 // This function returns the rectangle that encloses the selected cells
774 // in device coords and clipped to the client size of the grid window.
776 wxRect
SelectionToDeviceRect();
780 // ------ For compatibility with previous wxGrid only...
782 // ************************************************
783 // ** Don't use these in new code because they **
784 // ** are liable to disappear in a future **
786 // ************************************************
789 wxGrid( wxWindow
*parent
,
790 int x
= -1, int y
= -1, int w
= -1, int h
= -1,
792 const wxString
& name
= wxPanelNameStr
)
793 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
), style
, name
)
798 void SetCellValue( const wxString
& val
, int row
, int col
)
799 { SetCellValue( row
, col
, val
); }
801 void UpdateDimensions()
802 { CalcDimensions(); }
804 int GetRows() { return GetNumberRows(); }
805 int GetCols() { return GetNumberCols(); }
806 int GetCursorRow() { return GetGridCursorRow(); }
807 int GetCursorColumn() { return GetGridCursorCol(); }
809 int GetScrollPosX() { return 0; }
810 int GetScrollPosY() { return 0; }
812 void SetScrollX( int x
) { }
813 void SetScrollY( int y
) { }
815 void SetColumnWidth( int col
, int width
)
816 { SetColSize( col
, width
); }
818 int GetColumnWidth( int col
)
819 { return GetColSize( col
); }
821 void SetRowHeight( int row
, int height
)
822 { SetRowSize( row
, height
); }
824 int GetRowHeight( int row
)
825 { return GetRowSize( row
); }
827 int GetViewHeight() // returned num whole rows visible
830 int GetViewWidth() // returned num whole cols visible
833 void SetLabelSize( int orientation
, int sz
)
835 if ( orientation
== wxHORIZONTAL
)
836 SetColLabelSize( sz
);
838 SetRowLabelSize( sz
);
841 int GetLabelSize( int orientation
)
843 if ( orientation
== wxHORIZONTAL
)
844 return GetColLabelSize();
846 return GetRowLabelSize();
849 void SetLabelAlignment( int orientation
, int align
)
851 if ( orientation
== wxHORIZONTAL
)
852 SetColLabelAlignment( align
, -1 );
854 SetRowLabelAlignment( align
, -1 );
857 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
860 if ( orientation
== wxHORIZONTAL
)
862 GetColLabelAlignment( &h
, &v
);
867 GetRowLabelAlignment( &h
, &v
);
872 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
874 if ( orientation
== wxHORIZONTAL
)
875 SetColLabelValue( pos
, val
);
877 SetRowLabelValue( pos
, val
);
880 wxString
GetLabelValue( int orientation
, int pos
)
882 if ( orientation
== wxHORIZONTAL
)
883 return GetColLabelValue( pos
);
885 return GetRowLabelValue( pos
);
888 wxFont
GetCellTextFont() const
889 { return m_defaultCellFont
; }
891 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
892 { return m_defaultCellFont
; }
894 void SetCellTextFont(const wxFont
& fnt
)
895 { SetDefaultCellFont( fnt
); }
897 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
898 { SetCellFont( row
, col
, fnt
); }
900 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
901 { SetCellTextColour( row
, col
, val
); }
903 void SetCellTextColour(const wxColour
& col
)
904 { SetDefaultCellTextColour( col
); }
906 void SetCellBackgroundColour(const wxColour
& col
)
907 { SetDefaultCellBackgroundColour( col
); }
909 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
910 { SetCellBackgroundColour( row
, col
, colour
); }
912 bool GetEditable() { return IsEditable(); }
913 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
914 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
915 void SetEditInPlace(bool edit
= TRUE
) { }
917 void SetCellAlignment( int align
, int row
, int col
)
918 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
919 void SetCellAlignment( int WXUNUSED(align
) ) {}
920 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
922 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
923 wxPen
& GetDividerPen() const { return wxNullPen
; }
924 void OnActivate(bool WXUNUSED(active
)) {}
926 // ******** End of compatibility functions **********
930 // ------ control IDs
931 enum { wxGRID_CELLCTRL
= 2000,
934 // ------ control types
935 enum { wxGRID_TEXTCTRL
= 2100,
941 DECLARE_DYNAMIC_CLASS( wxGrid
)
942 DECLARE_EVENT_TABLE()
950 // ------ Grid event class and event types
953 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
967 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
968 m_control(0), m_meta(0), m_shift(0), m_alt(0)
972 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
973 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
974 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
976 virtual int GetRow() { return m_row
; }
977 virtual int GetCol() { return m_col
; }
978 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
979 bool ControlDown() { return m_control
; }
980 bool MetaDown() { return m_meta
; }
981 bool ShiftDown() { return m_shift
; }
982 bool AltDown() { return m_alt
; }
984 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
988 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
1001 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1002 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1006 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1007 int rowOrCol
=-1, int x
=-1, int y
=-1,
1008 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1010 int GetRowOrCol() { return m_rowOrCol
; }
1011 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1012 bool ControlDown() { return m_control
; }
1013 bool MetaDown() { return m_meta
; }
1014 bool ShiftDown() { return m_shift
; }
1015 bool AltDown() { return m_alt
; }
1017 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1021 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1024 wxGridCellCoords m_topLeft
;
1025 wxGridCellCoords m_bottomRight
;
1032 wxGridRangeSelectEvent()
1035 m_topLeft
= wxGridNoCellCoords
;
1036 m_bottomRight
= wxGridNoCellCoords
;
1043 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1044 const wxGridCellCoords
& topLeft
,
1045 const wxGridCellCoords
& bottomRight
,
1046 bool control
=FALSE
, bool shift
=FALSE
,
1047 bool alt
=FALSE
, bool meta
=FALSE
);
1049 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1050 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1051 int GetTopRow() { return m_topLeft
.GetRow(); }
1052 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1053 int GetLeftCol() { return m_topLeft
.GetCol(); }
1054 int GetRightCol() { return m_bottomRight
.GetCol(); }
1055 bool ControlDown() { return m_control
; }
1056 bool MetaDown() { return m_meta
; }
1057 bool ShiftDown() { return m_shift
; }
1058 bool AltDown() { return m_alt
; }
1060 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1064 const wxEventType EVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1065 const wxEventType EVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1066 const wxEventType EVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1067 const wxEventType EVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1068 const wxEventType EVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1069 const wxEventType EVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1070 const wxEventType EVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1071 const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1072 const wxEventType EVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1073 const wxEventType EVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1074 const wxEventType EVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1075 const wxEventType EVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1076 const wxEventType EVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1079 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1080 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1081 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1083 #define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1084 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1085 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1086 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1087 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1088 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1089 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1090 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1091 #define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1092 #define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1093 #define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1094 #define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1095 #define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1098 #if 0 // TODO: implement these ? others ?
1100 const wxEventType EVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1101 const wxEventType EVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1102 const wxEventType EVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1104 #define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1105 #define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1106 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1110 #endif // #ifndef __WXGRID_H__
1112 #endif // ifndef wxUSE_NEW_GRID