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
68 virtual ~wxGridTableBase();
70 // You must override these functions in a derived table class
72 virtual long GetNumberRows() = 0;
73 virtual long GetNumberCols() = 0;
74 virtual wxString
GetValue( int row
, int col
) = 0;
75 virtual void SetValue( int row
, int col
, const wxString
& s
) = 0;
76 virtual bool IsEmptyCell( int row
, int col
) = 0;
78 // Overriding these is optional
80 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
81 virtual wxGrid
* GetView() const { return m_view
; }
83 virtual void Clear() {}
84 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
85 virtual bool AppendRows( size_t numRows
= 1 );
86 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
87 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
88 virtual bool AppendCols( size_t numCols
= 1 );
89 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
91 virtual wxString
GetRowLabelValue( int row
);
92 virtual wxString
GetColLabelValue( int col
);
93 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
94 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
108 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
109 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
110 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
111 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
112 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
113 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
114 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
115 wxGRIDTABLE_NOTIFY_COLS_DELETED
118 class WXDLLEXPORT wxGridTableMessage
121 wxGridTableMessage();
122 wxGridTableMessage( wxGridTableBase
*table
, int id
,
126 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
127 wxGridTableBase
* GetTableObject() const { return m_table
; }
128 void SetId( int id
) { m_id
= id
; }
129 int GetId() { return m_id
; }
130 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
131 int GetCommandInt() { return m_comInt1
; }
132 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
133 int GetCommandInt2() { return m_comInt2
; }
136 wxGridTableBase
*m_table
;
144 // ------ wxGridStringArray
145 // A 2-dimensional array of strings for data values
148 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString
, wxGridStringArray
);
152 // ------ wxGridStringTable
154 // Simplest type of data table for a grid for small tables of strings
155 // that are stored in memory
158 class WXDLLEXPORT wxGridStringTable
: public wxGridTableBase
162 wxGridStringTable( int numRows
, int numCols
);
163 ~wxGridStringTable();
165 // these are pure virtual in wxGridTableBase
167 long GetNumberRows();
168 long GetNumberCols();
169 wxString
GetValue( int row
, int col
);
170 void SetValue( int row
, int col
, const wxString
& s
);
171 bool IsEmptyCell( int row
, int col
);
173 // overridden functions from wxGridTableBase
176 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
177 bool AppendRows( size_t numRows
= 1 );
178 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
179 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
180 bool AppendCols( size_t numCols
= 1 );
181 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
183 void SetRowLabelValue( int row
, const wxString
& );
184 void SetColLabelValue( int col
, const wxString
& );
185 wxString
GetRowLabelValue( int row
);
186 wxString
GetColLabelValue( int col
);
189 wxGridStringArray m_data
;
191 // These only get used if you set your own labels, otherwise the
192 // GetRow/ColLabelValue functions return wxGridTableBase defaults
194 wxArrayString m_rowLabels
;
195 wxArrayString m_colLabels
;
197 DECLARE_DYNAMIC_CLASS( wxGridStringTable
)
202 //////////////////////////////////////////////////////////////////////
206 //////////////////////////////////////////////////////////////////////
208 class WXDLLEXPORT wxGridCellCoords
211 wxGridCellCoords() { m_row
= m_col
= -1; }
212 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
214 // default copy ctor is ok
216 long GetRow() const { return m_row
; }
217 void SetRow( long n
) { m_row
= n
; }
218 long GetCol() const { return m_col
; }
219 void SetCol( long n
) { m_col
= n
; }
220 void Set( long row
, long col
) { m_row
= row
; m_col
= col
; }
222 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
224 if ( &other
!= this )
232 bool operator==( const wxGridCellCoords
& other
)
234 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
237 bool operator!=( const wxGridCellCoords
& other
)
239 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
244 return (m_row
== -1 && m_col
== -1 );
253 // For comparisons...
255 extern wxGridCellCoords wxGridNoCellCoords
;
256 extern wxRect wxGridNoCellRect
;
258 // An array of cell coords...
260 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords
, wxGridCellCoordsArray
);
264 // This set of classes is to provide for the use of different types of
265 // cell edit controls in the grid while avoiding the wx class info
266 // system in deference to wxPython
268 class WXDLLEXPORT wxGridTextCtrl
: public wxTextCtrl
272 wxGridTextCtrl( wxWindow
*,
276 const wxString
& value
= wxEmptyString
,
277 const wxPoint
& pos
= wxDefaultPosition
,
278 const wxSize
& size
= wxDefaultSize
,
281 void SetStartValue( const wxString
& );
282 wxString
GetStartValue() { return startValue
; }
287 // TRUE for controls placed over cells,
288 // FALSE for a control on a grid control panel
289 bool m_isCellControl
;
293 void OnKeyDown( wxKeyEvent
& );
295 DECLARE_DYNAMIC_CLASS( wxGridTextCtrl
)
296 DECLARE_EVENT_TABLE()
300 class WXDLLEXPORT wxGridRowLabelWindow
: public wxWindow
303 wxGridRowLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
304 wxGridRowLabelWindow( wxGrid
*parent
, wxWindowID id
,
305 const wxPoint
&pos
, const wxSize
&size
);
310 void OnPaint( wxPaintEvent
& event
);
311 void OnMouseEvent( wxMouseEvent
& event
);
312 void OnKeyDown( wxKeyEvent
& event
);
314 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow
)
315 DECLARE_EVENT_TABLE()
319 class WXDLLEXPORT wxGridColLabelWindow
: public wxWindow
322 wxGridColLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
323 wxGridColLabelWindow( wxGrid
*parent
, wxWindowID id
,
324 const wxPoint
&pos
, const wxSize
&size
);
329 void OnPaint( wxPaintEvent
&event
);
330 void OnMouseEvent( wxMouseEvent
& event
);
331 void OnKeyDown( wxKeyEvent
& event
);
333 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow
)
334 DECLARE_EVENT_TABLE()
338 class WXDLLEXPORT wxGridCornerLabelWindow
: public wxWindow
341 wxGridCornerLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
342 wxGridCornerLabelWindow( wxGrid
*parent
, wxWindowID id
,
343 const wxPoint
&pos
, const wxSize
&size
);
348 void OnMouseEvent( wxMouseEvent
& event
);
349 void OnKeyDown( wxKeyEvent
& event
);
351 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow
)
352 DECLARE_EVENT_TABLE()
357 class WXDLLEXPORT wxGridWindow
: public wxPanel
362 m_owner
= (wxGrid
*)NULL
;
363 m_rowLabelWin
= (wxGridRowLabelWindow
*)NULL
;
364 m_colLabelWin
= (wxGridColLabelWindow
*)NULL
;
367 wxGridWindow( wxGrid
*parent
,
368 wxGridRowLabelWindow
*rowLblWin
,
369 wxGridColLabelWindow
*colLblWin
,
370 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
373 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
377 wxGridRowLabelWindow
*m_rowLabelWin
;
378 wxGridColLabelWindow
*m_colLabelWin
;
380 void OnPaint( wxPaintEvent
&event
);
381 void OnMouseEvent( wxMouseEvent
& event
);
382 void OnKeyDown( wxKeyEvent
& );
384 DECLARE_DYNAMIC_CLASS(wxGridWindow
)
385 DECLARE_EVENT_TABLE()
390 class WXDLLEXPORT wxGrid
: public wxScrolledWindow
395 m_table
= (wxGridTableBase
*) NULL
;
396 m_gridWin
= (wxGridWindow
*) NULL
;
397 m_rowLabelWin
= (wxGridRowLabelWindow
*) NULL
;
398 m_colLabelWin
= (wxGridColLabelWindow
*) NULL
;
399 m_cornerLabelWin
= (wxGridCornerLabelWindow
*) NULL
;
400 m_cellEditCtrl
= (wxWindow
*) NULL
;
403 wxGrid( wxWindow
*parent
,
405 const wxPoint
& pos
= wxDefaultPosition
,
406 const wxSize
& size
= wxDefaultSize
,
408 const wxString
& name
= wxPanelNameStr
);
412 bool CreateGrid( int numRows
, int numCols
);
415 // ------ grid dimensions
417 int GetNumberRows() { return m_numRows
; }
418 int GetNumberCols() { return m_numCols
; }
421 // ------ display update functions
423 void CalcRowLabelsExposed( wxRegion
& reg
);
424 void CalcColLabelsExposed( wxRegion
& reg
);
425 void CalcCellsExposed( wxRegion
& reg
);
428 // ------ event handlers
430 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
431 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
432 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
433 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
434 bool ProcessTableMessage( wxGridTableMessage
& );
437 wxGridTableBase
* GetTable() const { return m_table
; }
438 void SetTable( wxGridTableBase
*table
) { m_table
= table
; }
441 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
442 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
443 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
444 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
445 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
446 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
448 void DrawGridCellArea( wxDC
& dc
);
449 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
450 void DrawAllGridLines( wxDC
& dc
); // TODO - delete this ?
451 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
452 void DrawCellBackground( wxDC
& dc
, const wxGridCellCoords
& );
453 void DrawCellValue( wxDC
& dc
, const wxGridCellCoords
& );
455 void DrawRowLabels( wxDC
& dc
);
456 void DrawRowLabel( wxDC
& dc
, int row
);
457 void DrawColLabels( wxDC
& dc
);
458 void DrawColLabel( wxDC
& dc
, int col
);
461 // ------ Cell text drawing functions
463 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
464 int horizontalAlignment
= wxLEFT
,
465 int verticalAlignment
= wxTOP
);
467 // Split a string containing newline chararcters into an array of
468 // strings and return the number of lines
470 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
472 void GetTextBoxSize( wxDC
& dc
,
473 wxArrayString
& lines
,
474 long *width
, long *height
);
478 // Code that does a lot of grid modification can be enclosed
479 // between BeginBatch() and EndBatch() calls to avoid screen
482 void BeginBatch() { m_batchCount
++; }
483 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
484 int GetBatchCount() { return m_batchCount
; }
487 // ------ edit control functions
489 bool IsEditable() { return m_editable
; }
490 void EnableEditing( bool edit
);
492 #if 0 // at the moment the cell edit control is always active
493 void EnableCellEditControl( bool enable
);
496 bool IsCellEditControlEnabled()
497 { return (m_cellEditCtrl
&& m_cellEditCtrlEnabled
); }
499 void ShowCellEditControl();
500 void HideCellEditControl();
501 void SetEditControlValue( const wxString
& s
= wxEmptyString
);
502 void SaveEditControlValue();
505 // ------ grid location functions
506 // Note that all of these functions work with the logical coordinates of
507 // grid cells and labels so you will need to convert from device
508 // coordinates for mouse events etc.
510 void XYToCell( int x
, int y
, wxGridCellCoords
& );
514 int YToEdgeOfRow( int y
);
515 int XToEdgeOfCol( int x
);
517 wxRect
CellToRect( int row
, int col
);
518 wxRect
CellToRect( const wxGridCellCoords
& coords
)
519 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
521 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
522 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
524 // check to see if a cell is either wholly visible (the default arg) or
525 // at least partially visible in the grid window
527 bool IsVisible( int row
, int col
, bool wholeCellVisible
= TRUE
);
528 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= TRUE
)
529 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
530 void MakeCellVisible( int row
, int col
);
531 void MakeCellVisible( const wxGridCellCoords
& coords
)
532 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
535 // ------ grid cursor movement functions
537 void SetGridCursor( int row
, int col
)
538 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
541 bool MoveCursorDown();
542 bool MoveCursorLeft();
543 bool MoveCursorRight();
546 bool MoveCursorUpBlock();
547 bool MoveCursorDownBlock();
548 bool MoveCursorLeftBlock();
549 bool MoveCursorRightBlock();
552 // ------ label and gridline formatting
554 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
555 int GetRowLabelSize() { return m_rowLabelWidth
; }
556 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
557 int GetColLabelSize() { return m_colLabelHeight
; }
558 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
559 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
560 wxFont
GetLabelFont() { return m_labelFont
; }
561 void GetRowLabelAlignment( int *horiz
, int *vert
);
562 void GetColLabelAlignment( int *horiz
, int *vert
);
563 wxString
GetRowLabelValue( int row
);
564 wxString
GetColLabelValue( int col
);
565 wxColour
GetGridLineColour() { return m_gridLineColour
; }
567 void SetRowLabelSize( int width
);
568 void SetColLabelSize( int height
);
569 void SetLabelBackgroundColour( const wxColour
& );
570 void SetLabelTextColour( const wxColour
& );
571 void SetLabelFont( const wxFont
& );
572 void SetRowLabelAlignment( int horiz
, int vert
);
573 void SetColLabelAlignment( int horiz
, int vert
);
574 void SetRowLabelValue( int row
, const wxString
& );
575 void SetColLabelValue( int col
, const wxString
& );
576 void SetGridLineColour( const wxColour
& );
578 void EnableGridLines( bool enable
= TRUE
);
579 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
582 // ------ row and col formatting
584 int GetDefaultRowSize();
585 int GetRowSize( int row
);
586 int GetDefaultColSize();
587 int GetColSize( int col
);
588 wxColour
GetDefaultCellBackgroundColour();
589 wxColour
GetCellBackgroundColour( int row
, int col
);
590 wxColour
GetDefaultCellTextColour();
591 wxColour
GetCellTextColour( int row
, int col
);
592 wxFont
GetDefaultCellFont();
593 wxFont
GetCellFont( int row
, int col
);
594 void GetDefaultCellAlignment( int *horiz
, int *vert
);
595 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
597 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
598 void SetRowSize( int row
, int height
);
599 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
600 void SetColSize( int col
, int width
);
601 void SetDefaultCellBackgroundColour( const wxColour
& );
602 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
603 void SetDefaultCellTextColour( const wxColour
& );
604 void SetCellTextColour( int row
, int col
, const wxColour
& );
605 void SetDefaultCellFont( const wxFont
& );
606 void SetCellFont( int row
, int col
, const wxFont
& );
607 void SetDefaultCellAlignment( int horiz
, int vert
);
608 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
611 // ------ cell value accessors
613 wxString
GetCellValue( int row
, int col
)
617 return m_table
->GetValue( row
, col
);
621 return wxEmptyString
;
625 wxString
GetCellValue( const wxGridCellCoords
& coords
)
626 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
628 void SetCellValue( int row
, int col
, const wxString
& s
);
629 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
630 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
634 // ------ selections of blocks of cells
636 void SelectRow( int row
, bool addToSelected
= FALSE
);
637 void SelectCol( int col
, bool addToSelected
= FALSE
);
639 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
641 void SelectBlock( const wxGridCellCoords
& topLeft
,
642 const wxGridCellCoords
& bottomRight
)
643 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
644 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
649 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
650 m_selectedBottomRight
!= wxGridNoCellCoords
);
653 void ClearSelection();
655 bool IsInSelection( int row
, int col
)
656 { return ( IsSelection() &&
657 row
>= m_selectedTopLeft
.GetRow() &&
658 col
>= m_selectedTopLeft
.GetCol() &&
659 row
<= m_selectedBottomRight
.GetRow() &&
660 col
<= m_selectedBottomRight
.GetCol() );
663 bool IsInSelection( const wxGridCellCoords
& coords
)
664 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
666 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
668 // these will all be -1 if there is no selected block
670 *topRow
= m_selectedTopLeft
.GetRow();
671 *leftCol
= m_selectedTopLeft
.GetCol();
672 *bottomRow
= m_selectedBottomRight
.GetRow();
673 *rightCol
= m_selectedBottomRight
.GetCol();
677 // This function returns the rectangle that encloses the block of cells
678 // limited by TopLeft and BottomRight cell in device coords and clipped
679 // to the client size of the grid window.
681 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
682 const wxGridCellCoords
& bottomRight
);
684 // This function returns the rectangle that encloses the selected cells
685 // in device coords and clipped to the client size of the grid window.
687 wxRect
SelectionToDeviceRect()
689 return BlockToDeviceRect( m_selectedTopLeft
,
690 m_selectedBottomRight
);
694 // ------ For compatibility with previous wxGrid only...
696 // ************************************************
697 // ** Don't use these in new code because they **
698 // ** are liable to disappear in a future **
700 // ************************************************
703 wxGrid( wxWindow
*parent
,
704 int x
= -1, int y
= -1, int w
= -1, int h
= -1,
706 const wxString
& name
= wxPanelNameStr
)
707 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
), style
, name
)
712 void SetCellValue( const wxString
& val
, int row
, int col
)
713 { SetCellValue( row
, col
, val
); }
715 void UpdateDimensions()
716 { CalcDimensions(); }
718 int GetRows() { return GetNumberRows(); }
719 int GetCols() { return GetNumberCols(); }
720 int GetCursorRow() { return GetGridCursorRow(); }
721 int GetCursorColumn() { return GetGridCursorCol(); }
723 int GetScrollPosX() { return 0; }
724 int GetScrollPosY() { return 0; }
726 void SetScrollX( int x
) { }
727 void SetScrollY( int y
) { }
729 void SetColumnWidth( int col
, int width
)
730 { SetColSize( col
, width
); }
732 int GetColumnWidth( int col
)
733 { return GetColSize( col
); }
735 void SetRowHeight( int row
, int height
)
736 { SetRowSize( row
, height
); }
738 int GetRowHeight( int row
)
739 { return GetRowSize( row
); }
741 int GetViewHeight() // returned num whole rows visible
744 int GetViewWidth() // returned num whole cols visible
747 void SetLabelSize( int orientation
, int sz
)
749 if ( orientation
== wxHORIZONTAL
)
750 SetColLabelSize( sz
);
752 SetRowLabelSize( sz
);
755 int GetLabelSize( int orientation
)
757 if ( orientation
== wxHORIZONTAL
)
758 return GetColLabelSize();
760 return GetRowLabelSize();
763 void SetLabelAlignment( int orientation
, int align
)
765 if ( orientation
== wxHORIZONTAL
)
766 SetColLabelAlignment( align
, -1 );
768 SetRowLabelAlignment( align
, -1 );
771 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
774 if ( orientation
== wxHORIZONTAL
)
776 GetColLabelAlignment( &h
, &v
);
781 GetRowLabelAlignment( &h
, &v
);
786 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
788 if ( orientation
== wxHORIZONTAL
)
789 SetColLabelValue( pos
, val
);
791 SetRowLabelValue( pos
, val
);
794 wxString
GetLabelValue( int orientation
, int pos
)
796 if ( orientation
== wxHORIZONTAL
)
797 return GetColLabelValue( pos
);
799 return GetRowLabelValue( pos
);
802 wxFont
GetCellTextFont() const
803 { return m_defaultCellFont
; }
805 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
806 { return m_defaultCellFont
; }
808 void SetCellTextFont(const wxFont
& fnt
)
809 { SetDefaultCellFont( fnt
); }
811 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
812 { SetCellFont( row
, col
, fnt
); }
814 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
815 { SetCellTextColour( row
, col
, val
); }
817 void SetCellTextColour(const wxColour
& col
)
818 { SetDefaultCellTextColour( col
); }
820 void SetCellBackgroundColour(const wxColour
& col
)
821 { SetDefaultCellBackgroundColour( col
); }
823 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
824 { SetCellBackgroundColour( row
, col
, colour
); }
826 bool GetEditable() { return IsEditable(); }
827 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
828 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
829 void SetEditInPlace(bool edit
= TRUE
) { }
831 void SetCellAlignment( int align
, int row
, int col
)
832 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
833 void SetCellAlignment( int WXUNUSED(align
) ) {}
834 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
836 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
837 wxPen
& GetDividerPen() const { return wxNullPen
; }
838 void OnActivate(bool WXUNUSED(active
)) {}
840 // ******** End of compatibility functions **********
844 // ------ control IDs
845 enum { wxGRID_CELLCTRL
= 2000,
848 // ------ control types
849 enum { wxGRID_TEXTCTRL
= 2100,
857 wxGridWindow
*m_gridWin
;
858 wxGridRowLabelWindow
*m_rowLabelWin
;
859 wxGridColLabelWindow
*m_colLabelWin
;
860 wxGridCornerLabelWindow
*m_cornerLabelWin
;
862 wxBoxSizer
*m_mainSizer
;
863 wxBoxSizer
*m_topSizer
;
864 wxBoxSizer
*m_middleSizer
;
866 wxGridTableBase
*m_table
;
876 wxGridCellCoords m_currentCellCoords
;
878 wxGridCellCoords m_selectedTopLeft
;
879 wxGridCellCoords m_selectedBottomRight
;
881 int m_defaultRowHeight
;
882 wxArrayInt m_rowHeights
;
883 wxArrayInt m_rowBottoms
;
885 int m_defaultColWidth
;
886 wxArrayInt m_colWidths
;
887 wxArrayInt m_colRights
;
890 int m_colLabelHeight
;
892 wxColour m_labelBackgroundColour
;
893 wxColour m_labelTextColour
;
896 int m_rowLabelHorizAlign
;
897 int m_rowLabelVertAlign
;
898 int m_colLabelHorizAlign
;
899 int m_colLabelVertAlign
;
901 bool m_defaultRowLabelValues
;
902 bool m_defaultColLabelValues
;
904 wxColour m_gridLineColour
;
905 bool m_gridLinesEnabled
;
907 wxFont m_defaultCellFont
;
909 wxGridCellCoordsArray m_cellsExposed
;
910 wxArrayInt m_rowsExposed
;
911 wxArrayInt m_colsExposed
;
912 wxArrayInt m_rowLabelsExposed
;
913 wxArrayInt m_colLabelsExposed
;
919 enum { WXGRID_CURSOR_DEFAULT
,
920 WXGRID_CURSOR_SELECT_CELL
,
921 WXGRID_CURSOR_RESIZE_ROW
,
922 WXGRID_CURSOR_RESIZE_COL
,
923 WXGRID_CURSOR_SELECT_ROW
,
924 WXGRID_CURSOR_SELECT_COL
931 wxGridCellCoords m_selectionStart
;
933 wxCursor m_rowResizeCursor
;
934 wxCursor m_colResizeCursor
;
936 bool m_editable
; // applies to whole grid
937 int m_editCtrlType
; // for current cell
938 wxWindow
* m_cellEditCtrl
;
939 bool m_cellEditCtrlEnabled
;
944 void CalcDimensions();
945 bool Redimension( wxGridTableMessage
& );
948 bool SendEvent( const wxEventType
,
952 bool SendEvent( const wxEventType
,
956 void OnPaint( wxPaintEvent
& );
957 void OnSize( wxSizeEvent
& );
958 void OnKeyDown( wxKeyEvent
& );
961 void SetCurrentCell( const wxGridCellCoords
& coords
);
962 void SetCurrentCell( int row
, int col
)
963 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
966 // ------ functions to get/send data (see also public functions)
968 bool GetModelValues();
969 bool SetModelValues();
972 DECLARE_DYNAMIC_CLASS( wxGrid
)
973 DECLARE_EVENT_TABLE()
981 // ------ Grid event class and event types
984 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
988 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
989 m_control(0), m_meta(0), m_shift(0), m_alt(0)
993 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
994 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
995 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
997 virtual int GetRow() { return m_row
; }
998 virtual int GetCol() { return m_col
; }
999 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1000 bool ControlDown() { return m_control
; }
1001 bool MetaDown() { return m_meta
; }
1002 bool ShiftDown() { return m_shift
; }
1003 bool AltDown() { return m_alt
; }
1015 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
1019 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
1023 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1024 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1028 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1029 int rowOrCol
=-1, int x
=-1, int y
=-1,
1030 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1032 int GetRowOrCol() { return m_rowOrCol
; }
1033 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1034 bool ControlDown() { return m_control
; }
1035 bool MetaDown() { return m_meta
; }
1036 bool ShiftDown() { return m_shift
; }
1037 bool AltDown() { return m_alt
; }
1048 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1052 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1055 wxGridRangeSelectEvent()
1058 m_topLeft
= wxGridNoCellCoords
;
1059 m_bottomRight
= wxGridNoCellCoords
;
1066 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1067 const wxGridCellCoords
& topLeft
,
1068 const wxGridCellCoords
& bottomRight
,
1069 bool control
=FALSE
, bool shift
=FALSE
,
1070 bool alt
=FALSE
, bool meta
=FALSE
);
1072 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1073 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1074 int GetTopRow() { return m_topLeft
.GetRow(); }
1075 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1076 int GetLeftCol() { return m_topLeft
.GetCol(); }
1077 int GetRightCol() { return m_bottomRight
.GetCol(); }
1078 bool ControlDown() { return m_control
; }
1079 bool MetaDown() { return m_meta
; }
1080 bool ShiftDown() { return m_shift
; }
1081 bool AltDown() { return m_alt
; }
1084 wxGridCellCoords m_topLeft
;
1085 wxGridCellCoords m_bottomRight
;
1091 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1095 const wxEventType EVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1096 const wxEventType EVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1097 const wxEventType EVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1098 const wxEventType EVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1099 const wxEventType EVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1100 const wxEventType EVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1101 const wxEventType EVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1102 const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1103 const wxEventType EVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1104 const wxEventType EVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1105 const wxEventType EVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1106 const wxEventType EVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1107 const wxEventType EVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1110 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1111 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1112 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1114 #define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1115 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1116 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1117 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1118 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1119 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1120 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1121 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1122 #define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1123 #define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1124 #define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1125 #define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1126 #define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1129 #if 0 // TODO: implement these ? others ?
1131 const wxEventType EVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1132 const wxEventType EVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1133 const wxEventType EVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1135 #define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1136 #define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1137 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1141 #endif // #ifndef __WXGRID_H__
1143 #endif // ifndef wxUSE_NEW_GRID