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 row
, const wxString
& ) {}
97 virtual void SetColLabelValue( int 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
)
200 // ------ sketchy experimental code to create a grid table for a given type
202 // This doesn't work at the moment !!
205 #define _WX_DECLARE_GRIDTABLE( T, name ) \
208 WX_DECLARE_ARRAY( T, T##Row ) \
209 WX_DECLARE_OBJARRAY( T##Row, T##Array ) \
211 class WXDLLEXPORT name : public wxGridTableBase \
219 name( int numRows, int numCols ); \
222 wxString GetValue( int row, int col ); \
223 wxString SetValue( int row, int col, const wxString& s ); \
225 DECLARE_DYNAMIC_CLASS( name ) \
229 #define WX_DECLARE_GRIDTABLE(T, name) \
230 typedef T name##var; \
231 _WX_DECLARE_GRIDTABLE(name##var, name)
238 //////////////////////////////////////////////////////////////////////
242 //////////////////////////////////////////////////////////////////////
244 class wxGridCellCoords
250 wxGridCellCoords() { m_row
= m_col
= -1; }
251 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
253 // default copy ctor is ok
255 long GetRow() const { return m_row
; }
256 void SetRow( long n
) { m_row
= n
; }
257 long GetCol() const { return m_col
; }
258 void SetCol( long n
) { m_col
= n
; }
259 void Set( long row
, long col
) { m_row
= row
; m_col
= col
; }
261 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
263 if ( &other
!= this )
271 bool operator==( const wxGridCellCoords
& other
)
273 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
276 bool operator!=( const wxGridCellCoords
& other
)
278 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
283 return (m_row
== -1 && m_col
== -1 );
288 // For comparisons...
290 extern wxGridCellCoords wxGridNoCellCoords
;
291 extern wxRect wxGridNoCellRect
;
294 // This set of classes is to provide for the use of different types of
295 // cell edit controls in the grid while avoiding the wx class info
296 // system in deference to wxPython
298 class wxGridTextCtrl
: public wxTextCtrl
300 // TRUE for controls placed over cells,
301 // FALSE for a control on a grid control panel
302 bool m_isCellControl
;
306 void OnKeyDown( wxKeyEvent
& );
310 wxGridTextCtrl( wxWindow
*,
313 const wxString
& value
= wxEmptyString
,
314 const wxPoint
& pos
= wxDefaultPosition
,
315 const wxSize
& size
= wxDefaultSize
,
318 void SetStartValue( const wxString
& );
319 wxString
GetStartValue() { return startValue
; }
321 DECLARE_DYNAMIC_CLASS( wxGridTextCtrl
)
322 DECLARE_EVENT_TABLE()
326 class wxGrid
: public wxPanel
328 DECLARE_DYNAMIC_CLASS( wxGrid
)
333 wxGridTableBase
*m_table
;
343 wxGridCellCoords m_currentCellCoords
;
344 bool m_currentCellHighlighted
;
346 wxGridCellCoords m_selectedTopLeft
;
347 wxGridCellCoords m_selectedBottomRight
;
349 int m_defaultRowHeight
;
350 wxArrayInt m_rowHeights
;
351 wxArrayInt m_rowBottoms
;
353 int m_defaultColWidth
;
354 wxArrayInt m_colWidths
;
355 wxArrayInt m_colRights
;
358 int m_colLabelHeight
;
360 wxColour m_labelBackgroundColour
;
361 wxColour m_labelTextColour
;
364 int m_rowLabelHorizAlign
;
365 int m_rowLabelVertAlign
;
366 int m_colLabelHorizAlign
;
367 int m_colLabelVertAlign
;
369 bool m_defaultRowLabelValues
;
370 bool m_defaultColLabelValues
;
372 wxColour m_gridLineColour
;
373 bool m_gridLinesEnabled
;
375 wxFont m_defaultCellFont
;
377 wxScrollBar
* m_horizScrollBar
;
378 wxScrollBar
* m_vertScrollBar
;
379 int m_scrollBarWidth
;
382 int m_wholeColsVisible
;
383 int m_wholeRowsVisible
;
391 enum { WXGRID_CURSOR_DEFAULT
,
392 WXGRID_CURSOR_SELECT_CELL
,
393 WXGRID_CURSOR_RESIZE_ROW
,
394 WXGRID_CURSOR_RESIZE_COL
,
395 WXGRID_CURSOR_SELECT_ROW
,
396 WXGRID_CURSOR_SELECT_COL
403 wxGridCellCoords m_selectionStart
;
405 wxCursor m_rowResizeCursor
;
406 wxCursor m_colResizeCursor
;
408 bool m_editable
; // applies to whole grid
409 int m_editCtrlType
; // for current cell
410 wxWindow
* m_cellEditCtrl
;
411 bool m_cellEditCtrlEnabled
;
412 wxWindow
* m_topEditCtrl
;
413 bool m_topEditCtrlEnabled
;
416 // ------ internal init and update functions
420 void CalcDimensions();
422 bool Redimension( wxGridTableMessage
& );
424 // ------ event processing
426 bool SendEvent( const wxEventType
,
430 bool SendEvent( const wxEventType
,
433 void OnPaint( wxPaintEvent
& );
434 void OnSize( wxSizeEvent
& );
435 void OnMouse( wxMouseEvent
& );
436 void OnKeyDown( wxKeyEvent
& );
437 void OnText( wxKeyEvent
& );
438 void OnGridScroll( wxScrollEvent
& );
440 void SelectCell( const wxGridCellCoords
& coords
);
441 void SelectCell( int row
, int col
)
442 { SelectCell( wxGridCellCoords(row
, col
) ); }
445 // ------ edit controls
447 void ShowCellEditControl();
448 void HideCellEditControl();
449 void SaveEditControlValue();
452 // ------ grid location functions
454 int XYToArea( int x
, int y
); // returns one of the following...
455 enum { WXGRID_NOAREA
,
457 WXGRID_ROWLABEL_EDGE
,
459 WXGRID_COLLABEL_EDGE
,
463 void XYToCell( int x
, int y
, wxGridCellCoords
& );
467 int YToEdgeOfRow( int y
);
468 int XToEdgeOfCol( int x
);
470 wxRect
CellToRect( int row
, int col
);
471 wxRect
CellToRect( const wxGridCellCoords
& coords
)
472 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
475 bool MoveCursorDown();
476 bool MoveCursorLeft();
477 bool MoveCursorRight();
480 bool MoveCursorUpBlock();
481 bool MoveCursorDownBlock();
482 bool MoveCursorLeftBlock();
483 bool MoveCursorRightBlock();
486 // ------ label drawing functions
488 void DrawLabelAreas( wxDC
& dc
);
489 void DrawColLabelBorders( wxDC
& dc
);
490 void DrawColLabels( wxDC
& dc
);
491 void DrawColLabel( wxDC
& dc
, const wxRect
&, int col
);
492 void DrawRowLabelBorders( wxDC
& dc
);
493 void DrawRowLabels( wxDC
& dc
);
494 void DrawRowLabel( wxDC
& dc
, const wxRect
&, int col
);
497 // ------ cell drawing functions
499 void DrawCellArea( wxDC
& dc
);
500 void DrawGridLines( wxDC
& dc
);
501 void DrawCells( wxDC
& dc
);
502 void DrawCellBackground( wxDC
& dc
, const wxRect
&, int row
, int col
);
503 void DrawCellValue( wxDC
& dc
, const wxRect
&, int row
, int col
);
505 // this one is useful when you just need to draw one or a few
507 void DrawCell( int row
, int col
);
508 void DrawCell( const wxGridCellCoords
& coords
)
509 { DrawCell( coords
.GetRow(), coords
.GetCol() ); }
511 void DrawCellHighlight( wxDC
& dc
, int row
, int col
);
512 void DrawCellHighlight( wxDC
& dc
, wxGridCellCoords
& coords
)
513 { DrawCellHighlight( dc
, coords
.GetRow(), coords
.GetCol() ); }
514 void ShowCurrentCellHighlight( wxDC
& dc
);
515 void HideCurrentCellHighlight( wxDC
& dc
);
518 // ------ generic drawing functions
520 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
521 int horizontalAlignment
= wxLEFT
,
522 int verticalAlignment
= wxTOP
);
524 // Split a string containing newline chararcters into an array of
525 // strings and return the number of lines
527 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
529 void GetTextBoxSize( wxDC
& dc
,
530 wxArrayString
& lines
,
531 long *width
, long *height
);
534 // ------ functions to get/send data (see also public functions)
536 bool GetModelValues();
537 bool SetModelValues();
540 ////////////////////// Public section ////////////////////
546 wxGrid( wxWindow
*parent
,
548 const wxPoint
& pos
= wxDefaultPosition
,
549 const wxSize
& size
= wxDefaultSize
,
551 const wxString
& name
= wxPanelNameStr
)
552 : wxPanel( parent
, id
, pos
, size
, style
, name
)
559 bool CreateGrid( int numRows
= WXGRID_DEFAULT_NUMBER_ROWS
,
560 int numCols
= WXGRID_DEFAULT_NUMBER_COLS
);
562 wxGridTableBase
* GetTable() const { return m_table
; }
563 void SetTable( wxGridTableBase
*table
) { m_table
= table
; }
566 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
567 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
568 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
569 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
570 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
571 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
573 // ------ editing and edit controls
575 bool IsEditable() { return m_editable
; }
576 void EnableEditing( bool edit
);
578 void EnableTopEditControl( bool enable
);
579 bool IsTopEditControlEnabled()
580 { return (m_topEditCtrl
&& m_topEditCtrlEnabled
); }
581 void EnableCellEditControl( bool enable
);
582 bool IsCellEditControlEnabled()
583 { return (m_cellEditCtrl
&& m_cellEditCtrlEnabled
); }
584 void SetEditControlValue( const wxString
& s
= wxEmptyString
);
587 // ------ grid dimensions
589 int GetNumberRows() { return m_numRows
; }
590 int GetNumberCols() { return m_numCols
; }
591 int GetNumberVisibleRows() { return m_wholeRowsVisible
; }
592 int GetNumberVisibleCols() { return m_wholeColsVisible
; }
596 // Code that does a lot of grid modification can be enclosed
597 // between BeginBatch() and EndBatch() calls to avoid screen
600 void BeginBatch() { m_batchCount
++; }
601 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
602 int GetBatchCount() { return m_batchCount
; }
605 // ------ label and gridline formatting
607 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
608 int GetRowLabelSize() { return m_rowLabelWidth
; }
609 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
610 int GetColLabelSize() { return m_colLabelHeight
; }
611 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
612 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
613 wxFont
GetLabelFont() { return m_labelFont
; }
614 void GetRowLabelAlignment( int *horiz
, int *vert
);
615 void GetColLabelAlignment( int *horiz
, int *vert
);
616 wxString
GetRowLabelValue( int row
);
617 wxString
GetColLabelValue( int col
);
618 wxColour
GetGridLineColour() { return m_gridLineColour
; }
620 void SetRowLabelSize( int width
);
621 void SetColLabelSize( int height
);
622 void SetLabelBackgroundColour( const wxColour
& );
623 void SetLabelTextColour( const wxColour
& );
624 void SetLabelFont( const wxFont
& );
625 void SetRowLabelAlignment( int horiz
, int vert
);
626 void SetColLabelAlignment( int horiz
, int vert
);
627 void SetRowLabelValue( int row
, const wxString
& );
628 void SetColLabelValue( int col
, const wxString
& );
629 void SetGridLineColour( const wxColour
& );
631 void EnableGridLines( bool enable
= TRUE
);
632 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
635 // ------ row and col formatting
637 int GetDefaultRowSize();
638 int GetRowSize( int row
);
639 int GetDefaultColSize();
640 int GetColSize( int col
);
641 wxColour
GetDefaultCellBackgroundColour();
642 wxColour
GetCellBackgroundColour( int row
, int col
);
643 wxColour
GetDefaultCellTextColour();
644 wxColour
GetCellTextColour( int row
, int col
);
645 wxColour
GetCellHighlightColour();
646 wxFont
GetDefaultCellFont();
647 wxFont
GetCellFont( int row
, int col
);
648 void GetDefaultCellAlignment( int *horiz
, int *vert
);
649 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
651 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
652 void SetRowSize( int row
, int height
);
653 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
654 void SetColSize( int col
, int width
);
655 void SetDefaultCellBackgroundColour( const wxColour
& );
656 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
657 void SetDefaultCellTextColour( const wxColour
& );
658 void SetCellTextColour( int row
, int col
, const wxColour
& );
659 void SetCellHighlightColour( const wxColour
& );
660 void SetDefaultCellFont( const wxFont
& );
661 void SetCellFont( int row
, int col
, const wxFont
& );
662 void SetDefaultCellAlignment( int horiz
, int vert
);
663 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
666 // ------ cell value accessors
668 wxString
GetCellValue( int row
, int col
)
672 return m_table
->GetValue( row
, col
);
676 return wxEmptyString
;
680 wxString
GetCellValue( const wxGridCellCoords
& coords
)
681 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
683 void SetCellValue( int row
, int col
, const wxString
& s
);
684 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
685 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
688 // ------ interaction with data model
690 bool ProcessTableMessage( wxGridTableMessage
& );
694 // ------ grid location functions
697 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
698 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
699 int GetHorizontalScrollPos() { return m_scrollPosX
; }
700 int GetVerticalScrollPos() { return m_scrollPosY
; }
702 bool IsVisible( const wxGridCellCoords
& );
703 void MakeCellVisible( int row
, int col
);
704 void MakeCellVisible( const wxGridCellCoords
& coords
)
705 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
707 void SetGridCursor( int row
, int col
)
708 { SelectCell( wxGridCellCoords(row
, col
) ); }
710 void SetHorizontalScrollPos( int leftMostCol
);
711 void SetVerticalScrollPos( int topMostRow
);
714 // ------ selections of blocks of cells
716 void SelectRow( int row
, bool addToSelected
= FALSE
);
717 void SelectCol( int col
, bool addToSelected
= FALSE
);
719 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
721 void SelectBlock( const wxGridCellCoords
& topLeft
,
722 const wxGridCellCoords
& bottomRight
)
723 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
724 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
729 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
730 m_selectedBottomRight
!= wxGridNoCellCoords
);
733 void ClearSelection();
735 bool IsInSelection( int row
, int col
)
736 { return ( IsSelection() &&
737 row
>= m_selectedTopLeft
.GetRow() &&
738 col
>= m_selectedTopLeft
.GetCol() &&
739 row
<= m_selectedBottomRight
.GetRow() &&
740 col
<= m_selectedBottomRight
.GetCol() );
743 bool IsInSelection( const wxGridCellCoords
& coords
)
744 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
746 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
748 // these will all be -1 if there is no selected block
750 *topRow
= m_selectedTopLeft
.GetRow();
751 *leftCol
= m_selectedTopLeft
.GetCol();
752 *bottomRow
= m_selectedBottomRight
.GetRow();
753 *rightCol
= m_selectedBottomRight
.GetCol();
756 // get coordinates of selected block edges for repainting etc.
758 wxRect
SelectionToRect();
761 // ------ For compatibility with previous wxGrid only...
763 // ************************************************
764 // ** Don't use these in new code because they **
765 // ** are liable to disappear in a future **
767 // ************************************************
770 wxGrid( wxWindow
*parent
,
771 int x
= -1, int y
= -1, int w
= -1, int h
= -1,
773 const wxString
& name
= wxPanelNameStr
)
774 : wxPanel( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
), style
, name
)
779 void SetCellValue( const wxString
& val
, int row
, int col
)
780 { SetCellValue( row
, col
, val
); }
782 void AdjustScrollbars()
783 { CalcDimensions(); }
785 void UpdateDimensions()
786 { CalcDimensions(); }
788 int GetRows() { return GetNumberRows(); }
789 int GetCols() { return GetNumberCols(); }
790 int GetCursorRow() { return GetGridCursorRow(); }
791 int GetCursorColumn() { return GetGridCursorCol(); }
792 int GetScrollPosX() { return GetHorizontalScrollPos(); }
793 int GetScrollPosY() { return GetVerticalScrollPos(); }
795 void SetScrollX( int x
) { SetHorizontalScrollPos( x
); }
796 void SetScrollY( int y
) { SetVerticalScrollPos( y
); }
798 void SetColumnWidth( int col
, int width
)
799 { SetColSize( col
, width
); }
801 int GetColumnWidth( int col
)
802 { return GetColSize( col
); }
804 void SetRowHeight( int row
, int height
)
805 { SetRowSize( row
, height
); }
807 int GetRowHeight( int row
)
808 { return GetRowSize( row
); }
811 { return m_wholeRowsVisible
; }
814 { return m_wholeColsVisible
; }
816 void SetLabelSize( int orientation
, int sz
)
818 if ( orientation
== wxHORIZONTAL
)
819 SetColLabelSize( sz
);
821 SetRowLabelSize( sz
);
824 int GetLabelSize( int orientation
)
826 if ( orientation
== wxHORIZONTAL
)
827 return GetColLabelSize();
829 return GetRowLabelSize();
832 void SetLabelAlignment( int orientation
, int align
)
834 if ( orientation
== wxHORIZONTAL
)
835 SetColLabelAlignment( align
, -1 );
837 SetRowLabelAlignment( align
, -1 );
840 int GetLabelAlignment( int orientation
, int align
)
843 if ( orientation
== wxHORIZONTAL
)
845 GetColLabelAlignment( &h
, &v
);
850 GetRowLabelAlignment( &h
, &v
);
855 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
857 if ( orientation
== wxHORIZONTAL
)
858 SetColLabelValue( pos
, val
);
860 SetRowLabelValue( pos
, val
);
863 wxString
GetLabelValue( int orientation
, int pos
)
865 if ( orientation
== wxHORIZONTAL
)
866 return GetColLabelValue( pos
);
868 return GetRowLabelValue( pos
);
871 wxFont
GetCellTextFont() const
872 { return m_defaultCellFont
; }
874 wxFont
GetCellTextFont(int row
, int col
) const
875 { return m_defaultCellFont
; }
877 void SetCellTextFont(const wxFont
& fnt
)
878 { SetDefaultCellFont( fnt
); }
880 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
881 { SetCellFont( row
, col
, fnt
); }
883 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
884 { SetCellTextColour( row
, col
, val
); }
886 void SetCellTextColour(const wxColour
& col
)
887 { SetDefaultCellTextColour( col
); }
889 void SetCellBackgroundColour(const wxColour
& col
)
890 { SetDefaultCellBackgroundColour( col
); }
892 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
893 { SetCellBackgroundColour( row
, col
, colour
); }
895 bool GetEditable() { return IsEditable(); }
896 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
897 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
898 void SetEditInPlace(bool edit
= TRUE
) { EnableCellEditControl( edit
); }
901 // ******** End of compatibility functions **********
904 // ------ control IDs
905 enum { wxGRID_HORIZSCROLL
= 2000,
910 // ------ control types
911 enum { wxGRID_TEXTCTRL
= 100,
917 DECLARE_EVENT_TABLE()
925 // ------ Grid event class and event types
928 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
930 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
944 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
945 m_control(0), m_meta(0), m_shift(0), m_alt(0)
949 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
950 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
951 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
953 virtual int GetRow() { return m_row
; }
954 virtual int GetCol() { return m_col
; }
955 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
956 bool ControlDown() { return m_control
; }
957 bool MetaDown() { return m_meta
; }
958 bool ShiftDown() { return m_shift
; }
959 bool AltDown() { return m_alt
; }
963 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
965 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
978 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
979 m_control(0), m_meta(0), m_shift(0), m_alt(0)
983 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
984 int rowOrCol
=-1, int x
=-1, int y
=-1,
985 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
987 int GetRowOrCol() { return m_rowOrCol
; }
988 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
989 bool ControlDown() { return m_control
; }
990 bool MetaDown() { return m_meta
; }
991 bool ShiftDown() { return m_shift
; }
992 bool AltDown() { return m_alt
; }
996 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
998 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1001 wxGridCellCoords m_topLeft
;
1002 wxGridCellCoords m_bottomRight
;
1009 wxGridRangeSelectEvent()
1012 m_topLeft
= wxGridNoCellCoords
;
1013 m_bottomRight
= wxGridNoCellCoords
;
1020 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1021 const wxGridCellCoords
& topLeft
,
1022 const wxGridCellCoords
& bottomRight
,
1023 bool control
=FALSE
, bool shift
=FALSE
,
1024 bool alt
=FALSE
, bool meta
=FALSE
);
1026 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1027 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1028 int GetTopRow() { return m_topLeft
.GetRow(); }
1029 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1030 int GetLeftCol() { return m_topLeft
.GetCol(); }
1031 int GetRightCol() { return m_bottomRight
.GetCol(); }
1032 bool ControlDown() { return m_control
; }
1033 bool MetaDown() { return m_meta
; }
1034 bool ShiftDown() { return m_shift
; }
1035 bool AltDown() { return m_alt
; }
1039 const wxEventType EVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1040 const wxEventType EVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1041 const wxEventType EVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1042 const wxEventType EVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1043 const wxEventType EVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1044 const wxEventType EVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1045 const wxEventType EVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1046 const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1047 const wxEventType EVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1048 const wxEventType EVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1049 const wxEventType EVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1050 const wxEventType EVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1052 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1053 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1054 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1056 #define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1057 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1058 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1059 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1060 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1061 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1062 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1063 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1064 #define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1065 #define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1066 #define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1067 #define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1070 #if 0 // TODO: implement these ? others ?
1072 const wxEventType EVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1575;
1073 const wxEventType EVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1074 const wxEventType EVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1075 const wxEventType EVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1077 #define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1078 #define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1079 #define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1080 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1084 #endif // #ifndef __WXGRID_H__
1086 #endif // ifndef wxUSE_NEW_GRID