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/string.h"
28 #include "wx/scrolbar.h"
30 #include "wx/textctrl.h"
31 #include "wx/combobox.h"
32 #include "wx/dynarray.h"
35 // Default parameters for wxGrid
37 #define WXGRID_DEFAULT_NUMBER_ROWS 10
38 #define WXGRID_DEFAULT_NUMBER_COLS 10
40 #define WXGRID_DEFAULT_ROW_HEIGHT 25
42 #define WXGRID_DEFAULT_ROW_HEIGHT 30
44 #define WXGRID_DEFAULT_COL_WIDTH 80
45 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
46 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
47 #define WXGRID_LABEL_EDGE_ZONE 5
48 #define WXGRID_MIN_ROW_HEIGHT 15
49 #define WXGRID_MIN_COL_WIDTH 15
50 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
51 #define WXGRID_DEFAULT_TOPEDIT_WIDTH 300
52 #define WXGRID_DEFAULT_TOPEDIT_HEIGHT 60
58 //////////////////////////////////////////////////////////////////////
62 //////////////////////////////////////////////////////////////////////
65 class wxGridTableBase
: public wxObject
71 virtual ~wxGridTableBase();
73 // You must override these functions in a derived table class
75 virtual long GetNumberRows() = 0;
76 virtual long GetNumberCols() = 0;
77 virtual wxString
GetValue( int row
, int col
) = 0;
78 virtual void SetValue( int row
, int col
, const wxString
& s
) = 0;
79 virtual bool IsEmptyCell( int row
, int col
) = 0;
81 // Overriding these is optional
83 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
84 virtual wxGrid
* GetView() const { return m_view
; }
86 virtual void Clear() {}
87 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
88 virtual bool AppendRows( size_t numRows
= 1 );
89 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
90 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
91 virtual bool AppendCols( size_t numCols
= 1 );
92 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
94 virtual wxString
GetRowLabelValue( int row
);
95 virtual wxString
GetColLabelValue( int col
);
96 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
97 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
99 DECLARE_ABSTRACT_CLASS( wxGridTableBase
);
104 // IDs for messages sent from grid table to view
106 enum wxGridTableRequest
{
107 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
108 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
109 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
110 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
111 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
112 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
113 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
114 wxGRIDTABLE_NOTIFY_COLS_DELETED
117 class wxGridTableMessage
119 wxGridTableBase
*m_table
;
125 wxGridTableMessage();
126 wxGridTableMessage( wxGridTableBase
*table
, int id
,
130 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
131 wxGridTableBase
* GetTableObject() const { return m_table
; }
132 void SetId( int id
) { m_id
= id
; }
133 int GetId() { return m_id
; }
134 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
135 int GetCommandInt() { return m_comInt1
; }
136 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
137 int GetCommandInt2() { return m_comInt2
; }
142 // ------ wxGridStringArray
143 // A 2-dimensional array of strings for data values
146 WX_DECLARE_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 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 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
;
254 // This set of classes is to provide for the use of different types of
255 // cell edit controls in the grid while avoiding the wx class info
256 // system in deference to wxPython
258 class wxGridTextCtrl
: public wxTextCtrl
260 // TRUE for controls placed over cells,
261 // FALSE for a control on a grid control panel
262 bool m_isCellControl
;
266 void OnKeyDown( wxKeyEvent
& );
270 wxGridTextCtrl( wxWindow
*,
273 const wxString
& value
= wxEmptyString
,
274 const wxPoint
& pos
= wxDefaultPosition
,
275 const wxSize
& size
= wxDefaultSize
,
278 void SetStartValue( const wxString
& );
279 wxString
GetStartValue() { return startValue
; }
281 DECLARE_DYNAMIC_CLASS( wxGridTextCtrl
)
282 DECLARE_EVENT_TABLE()
286 class wxGrid
: public wxPanel
288 DECLARE_DYNAMIC_CLASS( wxGrid
)
293 wxGridTableBase
*m_table
;
303 wxGridCellCoords m_currentCellCoords
;
304 bool m_currentCellHighlighted
;
306 wxGridCellCoords m_selectedTopLeft
;
307 wxGridCellCoords m_selectedBottomRight
;
309 int m_defaultRowHeight
;
310 wxArrayInt m_rowHeights
;
311 wxArrayInt m_rowBottoms
;
313 int m_defaultColWidth
;
314 wxArrayInt m_colWidths
;
315 wxArrayInt m_colRights
;
318 int m_colLabelHeight
;
320 wxColour m_labelBackgroundColour
;
321 wxColour m_labelTextColour
;
324 int m_rowLabelHorizAlign
;
325 int m_rowLabelVertAlign
;
326 int m_colLabelHorizAlign
;
327 int m_colLabelVertAlign
;
329 bool m_defaultRowLabelValues
;
330 bool m_defaultColLabelValues
;
332 wxColour m_gridLineColour
;
333 bool m_gridLinesEnabled
;
335 wxFont m_defaultCellFont
;
337 wxScrollBar
* m_horizScrollBar
;
338 wxScrollBar
* m_vertScrollBar
;
339 int m_scrollBarWidth
;
342 int m_wholeColsVisible
;
343 int m_wholeRowsVisible
;
351 enum { WXGRID_CURSOR_DEFAULT
,
352 WXGRID_CURSOR_SELECT_CELL
,
353 WXGRID_CURSOR_RESIZE_ROW
,
354 WXGRID_CURSOR_RESIZE_COL
,
355 WXGRID_CURSOR_SELECT_ROW
,
356 WXGRID_CURSOR_SELECT_COL
363 wxGridCellCoords m_selectionStart
;
365 wxCursor m_rowResizeCursor
;
366 wxCursor m_colResizeCursor
;
368 bool m_editable
; // applies to whole grid
369 int m_editCtrlType
; // for current cell
370 wxWindow
* m_cellEditCtrl
;
371 bool m_cellEditCtrlEnabled
;
372 wxWindow
* m_topEditCtrl
;
373 bool m_topEditCtrlEnabled
;
375 // ------ internal init and update functions
379 void CalcDimensions();
381 bool Redimension( wxGridTableMessage
& );
383 // ------ event processing
385 bool SendEvent( const wxEventType
,
389 bool SendEvent( const wxEventType
,
392 void OnPaint( wxPaintEvent
& );
393 void OnSize( wxSizeEvent
& );
394 void OnMouse( wxMouseEvent
& );
395 void OnKeyDown( wxKeyEvent
& );
396 void OnText( wxKeyEvent
& );
397 void OnGridScroll( wxScrollEvent
& );
399 void SelectCell( const wxGridCellCoords
& coords
);
400 void SelectCell( int row
, int col
)
401 { SelectCell( wxGridCellCoords(row
, col
) ); }
404 // ------ edit controls
406 void ShowCellEditControl();
407 void HideCellEditControl();
408 void SaveEditControlValue();
411 // ------ grid location functions
413 int XYToArea( int x
, int y
); // returns one of the following...
414 enum { WXGRID_NOAREA
,
416 WXGRID_ROWLABEL_EDGE
,
418 WXGRID_COLLABEL_EDGE
,
422 void XYToCell( int x
, int y
, wxGridCellCoords
& );
426 int YToEdgeOfRow( int y
);
427 int XToEdgeOfCol( int x
);
429 wxRect
CellToRect( int row
, int col
);
430 wxRect
CellToRect( const wxGridCellCoords
& coords
)
431 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
434 bool MoveCursorDown();
435 bool MoveCursorLeft();
436 bool MoveCursorRight();
439 bool MoveCursorUpBlock();
440 bool MoveCursorDownBlock();
441 bool MoveCursorLeftBlock();
442 bool MoveCursorRightBlock();
445 // ------ label drawing functions
447 void DrawLabelAreas( wxDC
& dc
);
448 void DrawColLabelBorders( wxDC
& dc
);
449 void DrawColLabels( wxDC
& dc
);
450 void DrawColLabel( wxDC
& dc
, const wxRect
&, int col
);
451 void DrawRowLabelBorders( wxDC
& dc
);
452 void DrawRowLabels( wxDC
& dc
);
453 void DrawRowLabel( wxDC
& dc
, const wxRect
&, int col
);
456 // ------ cell drawing functions
458 void DrawCellArea( wxDC
& dc
);
459 void DrawGridLines( wxDC
& dc
);
460 void DrawCells( wxDC
& dc
);
461 void DrawCellBackground( wxDC
& dc
, const wxRect
&, int row
, int col
);
462 void DrawCellValue( wxDC
& dc
, const wxRect
&, int row
, int col
,
463 const wxString
& value
= wxEmptyString
, bool useValueArg
= FALSE
);
465 // this updates the displayed cell text value but not the underlying
466 // table cell value (it is used to echo text being entered into
467 // the top edit control when in-place editing is turned off)
469 void DrawCellValue( const wxGridCellCoords
& coords
, const wxString
& value
);
471 // these are useful when you just need to draw one or a few
473 void DrawCell( int row
, int col
);
474 void DrawCell( const wxGridCellCoords
& coords
)
475 { DrawCell( coords
.GetRow(), coords
.GetCol() ); }
477 void DrawCellHighlight( wxDC
& dc
, int row
, int col
);
478 void DrawCellHighlight( wxDC
& dc
, wxGridCellCoords
& coords
)
479 { DrawCellHighlight( dc
, coords
.GetRow(), coords
.GetCol() ); }
480 void ShowCurrentCellHighlight( wxDC
& dc
);
481 void HideCurrentCellHighlight( wxDC
& dc
);
484 // ------ generic drawing functions
486 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
487 int horizontalAlignment
= wxLEFT
,
488 int verticalAlignment
= wxTOP
);
490 // Split a string containing newline chararcters into an array of
491 // strings and return the number of lines
493 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
495 void GetTextBoxSize( wxDC
& dc
,
496 wxArrayString
& lines
,
497 long *width
, long *height
);
500 // ------ functions to get/send data (see also public functions)
502 bool GetModelValues();
503 bool SetModelValues();
506 ////////////////////// Public section ////////////////////
512 wxGrid( wxWindow
*parent
,
514 const wxPoint
& pos
= wxDefaultPosition
,
515 const wxSize
& size
= wxDefaultSize
,
517 const wxString
& name
= wxPanelNameStr
)
518 : wxPanel( parent
, id
, pos
, size
, style
, name
)
525 bool CreateGrid( int numRows
= WXGRID_DEFAULT_NUMBER_ROWS
,
526 int numCols
= WXGRID_DEFAULT_NUMBER_COLS
);
528 wxGridTableBase
* GetTable() const { return m_table
; }
529 void SetTable( wxGridTableBase
*table
) { m_table
= table
; }
532 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
533 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
534 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
535 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
536 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
537 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
539 // ------ editing and edit controls
541 bool IsEditable() { return m_editable
; }
542 void EnableEditing( bool edit
);
544 void EnableTopEditControl( bool enable
);
545 bool IsTopEditControlEnabled()
546 { return (m_topEditCtrl
&& m_topEditCtrlEnabled
); }
547 void EnableCellEditControl( bool enable
);
548 bool IsCellEditControlEnabled()
549 { return (m_cellEditCtrl
&& m_cellEditCtrlEnabled
); }
550 void SetEditControlValue( const wxString
& s
= wxEmptyString
);
553 // ------ grid dimensions
555 int GetNumberRows() { return m_numRows
; }
556 int GetNumberCols() { return m_numCols
; }
557 int GetNumberVisibleRows() { return m_wholeRowsVisible
; }
558 int GetNumberVisibleCols() { return m_wholeColsVisible
; }
562 // Code that does a lot of grid modification can be enclosed
563 // between BeginBatch() and EndBatch() calls to avoid screen
566 void BeginBatch() { m_batchCount
++; }
567 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
568 int GetBatchCount() { return m_batchCount
; }
571 // ------ label and gridline formatting
573 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
574 int GetRowLabelSize() { return m_rowLabelWidth
; }
575 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
576 int GetColLabelSize() { return m_colLabelHeight
; }
577 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
578 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
579 wxFont
GetLabelFont() { return m_labelFont
; }
580 void GetRowLabelAlignment( int *horiz
, int *vert
);
581 void GetColLabelAlignment( int *horiz
, int *vert
);
582 wxString
GetRowLabelValue( int row
);
583 wxString
GetColLabelValue( int col
);
584 wxColour
GetGridLineColour() { return m_gridLineColour
; }
586 void SetRowLabelSize( int width
);
587 void SetColLabelSize( int height
);
588 void SetLabelBackgroundColour( const wxColour
& );
589 void SetLabelTextColour( const wxColour
& );
590 void SetLabelFont( const wxFont
& );
591 void SetRowLabelAlignment( int horiz
, int vert
);
592 void SetColLabelAlignment( int horiz
, int vert
);
593 void SetRowLabelValue( int row
, const wxString
& );
594 void SetColLabelValue( int col
, const wxString
& );
595 void SetGridLineColour( const wxColour
& );
597 void EnableGridLines( bool enable
= TRUE
);
598 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
601 // ------ row and col formatting
603 int GetDefaultRowSize();
604 int GetRowSize( int row
);
605 int GetDefaultColSize();
606 int GetColSize( int col
);
607 wxColour
GetDefaultCellBackgroundColour();
608 wxColour
GetCellBackgroundColour( int row
, int col
);
609 wxColour
GetDefaultCellTextColour();
610 wxColour
GetCellTextColour( int row
, int col
);
611 wxColour
GetCellHighlightColour();
612 wxFont
GetDefaultCellFont();
613 wxFont
GetCellFont( int row
, int col
);
614 void GetDefaultCellAlignment( int *horiz
, int *vert
);
615 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
617 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
618 void SetRowSize( int row
, int height
);
619 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
620 void SetColSize( int col
, int width
);
621 void SetDefaultCellBackgroundColour( const wxColour
& );
622 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
623 void SetDefaultCellTextColour( const wxColour
& );
624 void SetCellTextColour( int row
, int col
, const wxColour
& );
625 void SetCellHighlightColour( const wxColour
& );
626 void SetDefaultCellFont( const wxFont
& );
627 void SetCellFont( int row
, int col
, const wxFont
& );
628 void SetDefaultCellAlignment( int horiz
, int vert
);
629 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
632 // ------ cell value accessors
634 wxString
GetCellValue( int row
, int col
)
638 return m_table
->GetValue( row
, col
);
642 return wxEmptyString
;
646 wxString
GetCellValue( const wxGridCellCoords
& coords
)
647 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
649 void SetCellValue( int row
, int col
, const wxString
& s
);
650 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
651 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
654 // ------ interaction with data model
656 bool ProcessTableMessage( wxGridTableMessage
& );
660 // ------ grid location functions
663 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
664 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
665 int GetHorizontalScrollPos() { return m_scrollPosX
; }
666 int GetVerticalScrollPos() { return m_scrollPosY
; }
668 bool IsVisible( const wxGridCellCoords
& );
669 void MakeCellVisible( int row
, int col
);
670 void MakeCellVisible( const wxGridCellCoords
& coords
)
671 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
673 void SetGridCursor( int row
, int col
)
674 { SelectCell( wxGridCellCoords(row
, col
) ); }
676 void SetHorizontalScrollPos( int leftMostCol
);
677 void SetVerticalScrollPos( int topMostRow
);
680 // ------ selections of blocks of cells
682 void SelectRow( int row
, bool addToSelected
= FALSE
);
683 void SelectCol( int col
, bool addToSelected
= FALSE
);
685 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
687 void SelectBlock( const wxGridCellCoords
& topLeft
,
688 const wxGridCellCoords
& bottomRight
)
689 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
690 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
695 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
696 m_selectedBottomRight
!= wxGridNoCellCoords
);
699 void ClearSelection();
701 bool IsInSelection( int row
, int col
)
702 { return ( IsSelection() &&
703 row
>= m_selectedTopLeft
.GetRow() &&
704 col
>= m_selectedTopLeft
.GetCol() &&
705 row
<= m_selectedBottomRight
.GetRow() &&
706 col
<= m_selectedBottomRight
.GetCol() );
709 bool IsInSelection( const wxGridCellCoords
& coords
)
710 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
712 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
714 // these will all be -1 if there is no selected block
716 *topRow
= m_selectedTopLeft
.GetRow();
717 *leftCol
= m_selectedTopLeft
.GetCol();
718 *bottomRow
= m_selectedBottomRight
.GetRow();
719 *rightCol
= m_selectedBottomRight
.GetCol();
722 // get coordinates of selected block edges for repainting etc.
724 wxRect
SelectionToRect();
727 // ------ For compatibility with previous wxGrid only...
729 // ************************************************
730 // ** Don't use these in new code because they **
731 // ** are liable to disappear in a future **
733 // ************************************************
736 wxGrid( wxWindow
*parent
,
737 int x
= -1, int y
= -1, int w
= -1, int h
= -1,
739 const wxString
& name
= wxPanelNameStr
)
740 : wxPanel( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
), style
, name
)
745 void SetCellValue( const wxString
& val
, int row
, int col
)
746 { SetCellValue( row
, col
, val
); }
748 void AdjustScrollbars()
749 { CalcDimensions(); }
751 void UpdateDimensions()
752 { CalcDimensions(); }
754 int GetRows() { return GetNumberRows(); }
755 int GetCols() { return GetNumberCols(); }
756 int GetCursorRow() { return GetGridCursorRow(); }
757 int GetCursorColumn() { return GetGridCursorCol(); }
758 int GetScrollPosX() { return GetHorizontalScrollPos(); }
759 int GetScrollPosY() { return GetVerticalScrollPos(); }
761 void SetScrollX( int x
) { SetHorizontalScrollPos( x
); }
762 void SetScrollY( int y
) { SetVerticalScrollPos( y
); }
764 void SetColumnWidth( int col
, int width
)
765 { SetColSize( col
, width
); }
767 int GetColumnWidth( int col
)
768 { return GetColSize( col
); }
770 void SetRowHeight( int row
, int height
)
771 { SetRowSize( row
, height
); }
773 int GetRowHeight( int row
)
774 { return GetRowSize( row
); }
777 { return m_wholeRowsVisible
; }
780 { return m_wholeColsVisible
; }
782 void SetLabelSize( int orientation
, int sz
)
784 if ( orientation
== wxHORIZONTAL
)
785 SetColLabelSize( sz
);
787 SetRowLabelSize( sz
);
790 int GetLabelSize( int orientation
)
792 if ( orientation
== wxHORIZONTAL
)
793 return GetColLabelSize();
795 return GetRowLabelSize();
798 void SetLabelAlignment( int orientation
, int align
)
800 if ( orientation
== wxHORIZONTAL
)
801 SetColLabelAlignment( align
, -1 );
803 SetRowLabelAlignment( align
, -1 );
806 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
809 if ( orientation
== wxHORIZONTAL
)
811 GetColLabelAlignment( &h
, &v
);
816 GetRowLabelAlignment( &h
, &v
);
821 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
823 if ( orientation
== wxHORIZONTAL
)
824 SetColLabelValue( pos
, val
);
826 SetRowLabelValue( pos
, val
);
829 wxString
GetLabelValue( int orientation
, int pos
)
831 if ( orientation
== wxHORIZONTAL
)
832 return GetColLabelValue( pos
);
834 return GetRowLabelValue( pos
);
837 wxFont
GetCellTextFont() const
838 { return m_defaultCellFont
; }
840 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
841 { return m_defaultCellFont
; }
843 void SetCellTextFont(const wxFont
& fnt
)
844 { SetDefaultCellFont( fnt
); }
846 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
847 { SetCellFont( row
, col
, fnt
); }
849 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
850 { SetCellTextColour( row
, col
, val
); }
852 void SetCellTextColour(const wxColour
& col
)
853 { SetDefaultCellTextColour( col
); }
855 void SetCellBackgroundColour(const wxColour
& col
)
856 { SetDefaultCellBackgroundColour( col
); }
858 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
859 { SetCellBackgroundColour( row
, col
, colour
); }
861 bool GetEditable() { return IsEditable(); }
862 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
863 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
864 void SetEditInPlace(bool edit
= TRUE
) { EnableCellEditControl( edit
); }
866 void SetCellAlignment( int align
, int row
, int col
)
867 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
868 void SetCellAlignment( int WXUNUSED(align
) ) {}
869 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
871 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
872 wxPen
& GetDividerPen() const { return wxNullPen
; }
873 void OnActivate(bool WXUNUSED(active
)) {}
875 // ******** End of compatibility functions **********
878 // ------ control IDs
879 enum { wxGRID_HORIZSCROLL
= 2000,
884 // ------ control types
885 enum { wxGRID_TEXTCTRL
= 100,
891 DECLARE_EVENT_TABLE()
899 // ------ Grid event class and event types
902 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
904 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
918 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
919 m_control(0), m_meta(0), m_shift(0), m_alt(0)
923 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
924 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
925 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
927 virtual int GetRow() { return m_row
; }
928 virtual int GetCol() { return m_col
; }
929 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
930 bool ControlDown() { return m_control
; }
931 bool MetaDown() { return m_meta
; }
932 bool ShiftDown() { return m_shift
; }
933 bool AltDown() { return m_alt
; }
937 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
939 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
952 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
953 m_control(0), m_meta(0), m_shift(0), m_alt(0)
957 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
958 int rowOrCol
=-1, int x
=-1, int y
=-1,
959 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
961 int GetRowOrCol() { return m_rowOrCol
; }
962 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
963 bool ControlDown() { return m_control
; }
964 bool MetaDown() { return m_meta
; }
965 bool ShiftDown() { return m_shift
; }
966 bool AltDown() { return m_alt
; }
970 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
972 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
975 wxGridCellCoords m_topLeft
;
976 wxGridCellCoords m_bottomRight
;
983 wxGridRangeSelectEvent()
986 m_topLeft
= wxGridNoCellCoords
;
987 m_bottomRight
= wxGridNoCellCoords
;
994 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
995 const wxGridCellCoords
& topLeft
,
996 const wxGridCellCoords
& bottomRight
,
997 bool control
=FALSE
, bool shift
=FALSE
,
998 bool alt
=FALSE
, bool meta
=FALSE
);
1000 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1001 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1002 int GetTopRow() { return m_topLeft
.GetRow(); }
1003 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1004 int GetLeftCol() { return m_topLeft
.GetCol(); }
1005 int GetRightCol() { return m_bottomRight
.GetCol(); }
1006 bool ControlDown() { return m_control
; }
1007 bool MetaDown() { return m_meta
; }
1008 bool ShiftDown() { return m_shift
; }
1009 bool AltDown() { return m_alt
; }
1013 const wxEventType EVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1014 const wxEventType EVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1015 const wxEventType EVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1016 const wxEventType EVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1017 const wxEventType EVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1018 const wxEventType EVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1019 const wxEventType EVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1020 const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1021 const wxEventType EVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1022 const wxEventType EVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1023 const wxEventType EVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1024 const wxEventType EVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1025 const wxEventType EVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1028 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1029 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1030 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1032 #define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1033 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1034 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1035 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1036 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1037 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1038 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1039 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1040 #define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1041 #define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1042 #define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1043 #define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1044 #define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1047 #if 0 // TODO: implement these ? others ?
1049 const wxEventType EVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1050 const wxEventType EVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1051 const wxEventType EVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1053 #define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1054 #define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1055 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1059 #endif // #ifndef __WXGRID_H__
1061 #endif // ifndef wxUSE_NEW_GRID