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
635 bool MoveCursorDown();
636 bool MoveCursorLeft();
637 bool MoveCursorRight();
640 bool MoveCursorUpBlock();
641 bool MoveCursorDownBlock();
642 bool MoveCursorLeftBlock();
643 bool MoveCursorRightBlock();
646 // ------ label and gridline formatting
648 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
649 int GetRowLabelSize() { return m_rowLabelWidth
; }
650 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
651 int GetColLabelSize() { return m_colLabelHeight
; }
652 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
653 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
654 wxFont
GetLabelFont() { return m_labelFont
; }
655 void GetRowLabelAlignment( int *horiz
, int *vert
);
656 void GetColLabelAlignment( int *horiz
, int *vert
);
657 wxString
GetRowLabelValue( int row
);
658 wxString
GetColLabelValue( int col
);
659 wxColour
GetGridLineColour() { return m_gridLineColour
; }
661 void SetRowLabelSize( int width
);
662 void SetColLabelSize( int height
);
663 void SetLabelBackgroundColour( const wxColour
& );
664 void SetLabelTextColour( const wxColour
& );
665 void SetLabelFont( const wxFont
& );
666 void SetRowLabelAlignment( int horiz
, int vert
);
667 void SetColLabelAlignment( int horiz
, int vert
);
668 void SetRowLabelValue( int row
, const wxString
& );
669 void SetColLabelValue( int col
, const wxString
& );
670 void SetGridLineColour( const wxColour
& );
672 void EnableGridLines( bool enable
= TRUE
);
673 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
676 // ------ row and col formatting
678 int GetDefaultRowSize();
679 int GetRowSize( int row
);
680 int GetDefaultColSize();
681 int GetColSize( int col
);
682 wxColour
GetDefaultCellBackgroundColour();
683 wxColour
GetCellBackgroundColour( int row
, int col
);
684 wxColour
GetDefaultCellTextColour();
685 wxColour
GetCellTextColour( int row
, int col
);
686 wxFont
GetDefaultCellFont();
687 wxFont
GetCellFont( int row
, int col
);
688 void GetDefaultCellAlignment( int *horiz
, int *vert
);
689 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
691 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
692 void SetRowSize( int row
, int height
);
693 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
694 void SetColSize( int col
, int width
);
695 void SetDefaultCellBackgroundColour( const wxColour
& );
696 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
697 void SetDefaultCellTextColour( const wxColour
& );
698 void SetCellTextColour( int row
, int col
, const wxColour
& );
699 void SetDefaultCellFont( const wxFont
& );
700 void SetCellFont( int row
, int col
, const wxFont
& );
701 void SetDefaultCellAlignment( int horiz
, int vert
);
702 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
705 // ------ cell value accessors
707 wxString
GetCellValue( int row
, int col
)
711 return m_table
->GetValue( row
, col
);
715 return wxEmptyString
;
719 wxString
GetCellValue( const wxGridCellCoords
& coords
)
720 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
722 void SetCellValue( int row
, int col
, const wxString
& s
);
723 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
724 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
728 // ------ selections of blocks of cells
730 void SelectRow( int row
, bool addToSelected
= FALSE
);
731 void SelectCol( int col
, bool addToSelected
= FALSE
);
733 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
735 void SelectBlock( const wxGridCellCoords
& topLeft
,
736 const wxGridCellCoords
& bottomRight
)
737 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
738 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
743 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
744 m_selectedBottomRight
!= wxGridNoCellCoords
);
747 void ClearSelection();
749 bool IsInSelection( int row
, int col
)
750 { return ( IsSelection() &&
751 row
>= m_selectedTopLeft
.GetRow() &&
752 col
>= m_selectedTopLeft
.GetCol() &&
753 row
<= m_selectedBottomRight
.GetRow() &&
754 col
<= m_selectedBottomRight
.GetCol() );
757 bool IsInSelection( const wxGridCellCoords
& coords
)
758 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
760 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
762 // these will all be -1 if there is no selected block
764 *topRow
= m_selectedTopLeft
.GetRow();
765 *leftCol
= m_selectedTopLeft
.GetCol();
766 *bottomRow
= m_selectedBottomRight
.GetRow();
767 *rightCol
= m_selectedBottomRight
.GetCol();
770 // This function returns the rectangle that encloses the selected cells
771 // in device coords and clipped to the client size of the grid window.
773 wxRect
SelectionToDeviceRect();
777 // ------ For compatibility with previous wxGrid only...
779 // ************************************************
780 // ** Don't use these in new code because they **
781 // ** are liable to disappear in a future **
783 // ************************************************
786 wxGrid( wxWindow
*parent
,
787 int x
= -1, int y
= -1, int w
= -1, int h
= -1,
789 const wxString
& name
= wxPanelNameStr
)
790 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
), style
, name
)
795 void SetCellValue( const wxString
& val
, int row
, int col
)
796 { SetCellValue( row
, col
, val
); }
798 void UpdateDimensions()
799 { CalcDimensions(); }
801 int GetRows() { return GetNumberRows(); }
802 int GetCols() { return GetNumberCols(); }
803 int GetCursorRow() { return GetGridCursorRow(); }
804 int GetCursorColumn() { return GetGridCursorCol(); }
806 int GetScrollPosX() { return 0; }
807 int GetScrollPosY() { return 0; }
809 void SetScrollX( int x
) { }
810 void SetScrollY( int y
) { }
812 void SetColumnWidth( int col
, int width
)
813 { SetColSize( col
, width
); }
815 int GetColumnWidth( int col
)
816 { return GetColSize( col
); }
818 void SetRowHeight( int row
, int height
)
819 { SetRowSize( row
, height
); }
821 int GetRowHeight( int row
)
822 { return GetRowSize( row
); }
824 int GetViewHeight() // returned num whole rows visible
827 int GetViewWidth() // returned num whole cols visible
830 void SetLabelSize( int orientation
, int sz
)
832 if ( orientation
== wxHORIZONTAL
)
833 SetColLabelSize( sz
);
835 SetRowLabelSize( sz
);
838 int GetLabelSize( int orientation
)
840 if ( orientation
== wxHORIZONTAL
)
841 return GetColLabelSize();
843 return GetRowLabelSize();
846 void SetLabelAlignment( int orientation
, int align
)
848 if ( orientation
== wxHORIZONTAL
)
849 SetColLabelAlignment( align
, -1 );
851 SetRowLabelAlignment( align
, -1 );
854 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
857 if ( orientation
== wxHORIZONTAL
)
859 GetColLabelAlignment( &h
, &v
);
864 GetRowLabelAlignment( &h
, &v
);
869 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
871 if ( orientation
== wxHORIZONTAL
)
872 SetColLabelValue( pos
, val
);
874 SetRowLabelValue( pos
, val
);
877 wxString
GetLabelValue( int orientation
, int pos
)
879 if ( orientation
== wxHORIZONTAL
)
880 return GetColLabelValue( pos
);
882 return GetRowLabelValue( pos
);
885 wxFont
GetCellTextFont() const
886 { return m_defaultCellFont
; }
888 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
889 { return m_defaultCellFont
; }
891 void SetCellTextFont(const wxFont
& fnt
)
892 { SetDefaultCellFont( fnt
); }
894 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
895 { SetCellFont( row
, col
, fnt
); }
897 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
898 { SetCellTextColour( row
, col
, val
); }
900 void SetCellTextColour(const wxColour
& col
)
901 { SetDefaultCellTextColour( col
); }
903 void SetCellBackgroundColour(const wxColour
& col
)
904 { SetDefaultCellBackgroundColour( col
); }
906 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
907 { SetCellBackgroundColour( row
, col
, colour
); }
909 bool GetEditable() { return IsEditable(); }
910 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
911 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
912 void SetEditInPlace(bool edit
= TRUE
) { }
914 void SetCellAlignment( int align
, int row
, int col
)
915 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
916 void SetCellAlignment( int WXUNUSED(align
) ) {}
917 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
919 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
920 wxPen
& GetDividerPen() const { return wxNullPen
; }
921 void OnActivate(bool WXUNUSED(active
)) {}
923 // ******** End of compatibility functions **********
927 // ------ control IDs
928 enum { wxGRID_CELLCTRL
= 2000,
931 // ------ control types
932 enum { wxGRID_TEXTCTRL
= 2100,
938 DECLARE_DYNAMIC_CLASS( wxGrid
)
939 DECLARE_EVENT_TABLE()
947 // ------ Grid event class and event types
950 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
964 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
965 m_control(0), m_meta(0), m_shift(0), m_alt(0)
969 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
970 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
971 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
973 virtual int GetRow() { return m_row
; }
974 virtual int GetCol() { return m_col
; }
975 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
976 bool ControlDown() { return m_control
; }
977 bool MetaDown() { return m_meta
; }
978 bool ShiftDown() { return m_shift
; }
979 bool AltDown() { return m_alt
; }
981 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
985 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
998 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
999 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1003 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1004 int rowOrCol
=-1, int x
=-1, int y
=-1,
1005 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1007 int GetRowOrCol() { return m_rowOrCol
; }
1008 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1009 bool ControlDown() { return m_control
; }
1010 bool MetaDown() { return m_meta
; }
1011 bool ShiftDown() { return m_shift
; }
1012 bool AltDown() { return m_alt
; }
1014 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1018 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1021 wxGridCellCoords m_topLeft
;
1022 wxGridCellCoords m_bottomRight
;
1029 wxGridRangeSelectEvent()
1032 m_topLeft
= wxGridNoCellCoords
;
1033 m_bottomRight
= wxGridNoCellCoords
;
1040 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1041 const wxGridCellCoords
& topLeft
,
1042 const wxGridCellCoords
& bottomRight
,
1043 bool control
=FALSE
, bool shift
=FALSE
,
1044 bool alt
=FALSE
, bool meta
=FALSE
);
1046 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1047 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1048 int GetTopRow() { return m_topLeft
.GetRow(); }
1049 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1050 int GetLeftCol() { return m_topLeft
.GetCol(); }
1051 int GetRightCol() { return m_bottomRight
.GetCol(); }
1052 bool ControlDown() { return m_control
; }
1053 bool MetaDown() { return m_meta
; }
1054 bool ShiftDown() { return m_shift
; }
1055 bool AltDown() { return m_alt
; }
1057 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1061 const wxEventType EVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1062 const wxEventType EVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1063 const wxEventType EVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1064 const wxEventType EVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1065 const wxEventType EVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1066 const wxEventType EVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1067 const wxEventType EVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1068 const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1069 const wxEventType EVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1070 const wxEventType EVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1071 const wxEventType EVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1072 const wxEventType EVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1073 const wxEventType EVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1076 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1077 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1078 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1080 #define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1081 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1082 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1083 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1084 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1085 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1086 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1087 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1088 #define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1089 #define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1090 #define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1091 #define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1092 #define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1095 #if 0 // TODO: implement these ? others ?
1097 const wxEventType EVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1098 const wxEventType EVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1099 const wxEventType EVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1101 #define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1102 #define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1103 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1107 #endif // #ifndef __WXGRID_H__
1109 #endif // ifndef wxUSE_NEW_GRID