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
53 // ----------------------------------------------------------------------------
54 // forward declarations
55 // ----------------------------------------------------------------------------
57 class WXDLLEXPORT wxGridCellAttrProviderData
;
58 class WXDLLEXPORT wxGridRowLabelWindow
;
59 class WXDLLEXPORT wxGridColLabelWindow
;
60 class WXDLLEXPORT wxGridCornerLabelWindow
;
61 class WXDLLEXPORT wxGridWindow
;
62 class WXDLLEXPORT wxGrid
;
64 // ----------------------------------------------------------------------------
65 // wxGridCellAttr: this class can be used to alter the cells appearance in
66 // the grid by changing their colour/font/... from default. An object of this
67 // class may be returned by wxGridTable::GetAttr().
68 // ----------------------------------------------------------------------------
70 class WXDLLEXPORT wxGridCellAttr
79 wxGridCellAttr(const wxColour
& colText
,
80 const wxColour
& colBack
,
84 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
86 SetAlignment(hAlign
, vAlign
);
89 // default copy ctor ok
92 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
93 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
94 void SetFont(const wxFont
& font
) { m_font
= font
; }
95 void SetAlignment(int hAlign
, int vAlign
)
102 bool HasTextColour() const { return m_colText
.Ok(); }
103 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
104 bool HasFont() const { return m_font
.Ok(); }
105 bool HasAlignment() const { return m_hAlign
|| m_vAlign
; }
107 const wxColour
& GetTextColour() const { return m_colText
; }
108 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
109 const wxFont
& GetFont() const { return m_font
; }
110 void GetAlignment(int *hAlign
, int *vAlign
)
112 if ( hAlign
) *hAlign
= m_hAlign
;
113 if ( vAlign
) *vAlign
= m_vAlign
;
124 // ----------------------------------------------------------------------------
125 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
127 // ----------------------------------------------------------------------------
129 // implementation note: we separate it from wxGridTableBase because we wish to
130 // avoid deriving a new table class if possible, and sometimes it will be
131 // enough to just derive another wxGridCellAttrProvider instead
133 class WXDLLEXPORT wxGridCellAttrProvider
136 wxGridCellAttrProvider();
137 virtual ~wxGridCellAttrProvider();
139 virtual wxGridCellAttr
*GetAttr(int row
, int col
) const;
140 virtual void SetAttr(const wxGridCellAttr
*attr
, int row
, int col
);
145 wxGridCellAttrProviderData
*m_data
;
148 //////////////////////////////////////////////////////////////////////
150 // Grid table classes
152 //////////////////////////////////////////////////////////////////////
155 class WXDLLEXPORT wxGridTableBase
: public wxObject
159 virtual ~wxGridTableBase();
161 // You must override these functions in a derived table class
163 virtual long GetNumberRows() = 0;
164 virtual long GetNumberCols() = 0;
165 virtual wxString
GetValue( int row
, int col
) = 0;
166 virtual void SetValue( int row
, int col
, const wxString
& s
) = 0;
167 virtual bool IsEmptyCell( int row
, int col
) = 0;
169 // Overriding these is optional
171 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
172 virtual wxGrid
* GetView() const { return m_view
; }
174 virtual void Clear() {}
175 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
176 virtual bool AppendRows( size_t numRows
= 1 );
177 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
178 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
179 virtual bool AppendCols( size_t numCols
= 1 );
180 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
182 virtual wxString
GetRowLabelValue( int row
);
183 virtual wxString
GetColLabelValue( int col
);
184 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
185 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
187 // Attribute handling
190 // give us the attr provider to use - we take ownership of the pointer
191 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
193 // get the currently used attr provider (may be NULL)
194 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
196 // by default forwarded to wxGridCellAttrProvider if any. May be
197 // overridden to handle attributes directly in this class.
198 virtual wxGridCellAttr
*GetAttr( int row
, int col
);
200 // takes ownership of the pointer
201 virtual void SetAttr(const wxGridCellAttr
*attr
, int row
, int col
);
205 wxGridCellAttrProvider
*m_attrProvider
;
207 DECLARE_ABSTRACT_CLASS( wxGridTableBase
);
211 // ----------------------------------------------------------------------------
212 // wxGridTableMessage
213 // ----------------------------------------------------------------------------
215 // IDs for messages sent from grid table to view
217 enum wxGridTableRequest
219 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
220 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
221 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
222 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
223 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
224 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
225 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
226 wxGRIDTABLE_NOTIFY_COLS_DELETED
229 class WXDLLEXPORT wxGridTableMessage
232 wxGridTableMessage();
233 wxGridTableMessage( wxGridTableBase
*table
, int id
,
237 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
238 wxGridTableBase
* GetTableObject() const { return m_table
; }
239 void SetId( int id
) { m_id
= id
; }
240 int GetId() { return m_id
; }
241 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
242 int GetCommandInt() { return m_comInt1
; }
243 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
244 int GetCommandInt2() { return m_comInt2
; }
247 wxGridTableBase
*m_table
;
255 // ------ wxGridStringArray
256 // A 2-dimensional array of strings for data values
259 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString
, wxGridStringArray
);
263 // ------ wxGridStringTable
265 // Simplest type of data table for a grid for small tables of strings
266 // that are stored in memory
269 class WXDLLEXPORT wxGridStringTable
: public wxGridTableBase
273 wxGridStringTable( int numRows
, int numCols
);
274 ~wxGridStringTable();
276 // these are pure virtual in wxGridTableBase
278 long GetNumberRows();
279 long GetNumberCols();
280 wxString
GetValue( int row
, int col
);
281 void SetValue( int row
, int col
, const wxString
& s
);
282 bool IsEmptyCell( int row
, int col
);
284 // overridden functions from wxGridTableBase
287 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
288 bool AppendRows( size_t numRows
= 1 );
289 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
290 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
291 bool AppendCols( size_t numCols
= 1 );
292 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
294 void SetRowLabelValue( int row
, const wxString
& );
295 void SetColLabelValue( int col
, const wxString
& );
296 wxString
GetRowLabelValue( int row
);
297 wxString
GetColLabelValue( int col
);
300 wxGridStringArray m_data
;
302 // These only get used if you set your own labels, otherwise the
303 // GetRow/ColLabelValue functions return wxGridTableBase defaults
305 wxArrayString m_rowLabels
;
306 wxArrayString m_colLabels
;
308 DECLARE_DYNAMIC_CLASS( wxGridStringTable
)
313 //////////////////////////////////////////////////////////////////////
317 //////////////////////////////////////////////////////////////////////
319 class WXDLLEXPORT wxGridCellCoords
322 wxGridCellCoords() { m_row
= m_col
= -1; }
323 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
325 // default copy ctor is ok
327 long GetRow() const { return m_row
; }
328 void SetRow( long n
) { m_row
= n
; }
329 long GetCol() const { return m_col
; }
330 void SetCol( long n
) { m_col
= n
; }
331 void Set( long row
, long col
) { m_row
= row
; m_col
= col
; }
333 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
335 if ( &other
!= this )
343 bool operator==( const wxGridCellCoords
& other
)
345 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
348 bool operator!=( const wxGridCellCoords
& other
)
350 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
355 return (m_row
== -1 && m_col
== -1 );
364 // For comparisons...
366 extern wxGridCellCoords wxGridNoCellCoords
;
367 extern wxRect wxGridNoCellRect
;
369 // An array of cell coords...
371 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords
, wxGridCellCoordsArray
);
375 // This set of classes is to provide for the use of different types of
376 // cell edit controls in the grid while avoiding the wx class info
377 // system in deference to wxPython
379 class WXDLLEXPORT wxGridTextCtrl
: public wxTextCtrl
383 wxGridTextCtrl( wxWindow
*,
387 const wxString
& value
= wxEmptyString
,
388 const wxPoint
& pos
= wxDefaultPosition
,
389 const wxSize
& size
= wxDefaultSize
,
392 void SetStartValue( const wxString
& );
393 wxString
GetStartValue() { return startValue
; }
398 // TRUE for controls placed over cells,
399 // FALSE for a control on a grid control panel
400 bool m_isCellControl
;
404 void OnKeyDown( wxKeyEvent
& );
406 DECLARE_DYNAMIC_CLASS( wxGridTextCtrl
)
407 DECLARE_EVENT_TABLE()
410 // ----------------------------------------------------------------------------
412 // ----------------------------------------------------------------------------
414 class WXDLLEXPORT wxGrid
: public wxScrolledWindow
419 m_table
= (wxGridTableBase
*) NULL
;
420 m_gridWin
= (wxGridWindow
*) NULL
;
421 m_rowLabelWin
= (wxGridRowLabelWindow
*) NULL
;
422 m_colLabelWin
= (wxGridColLabelWindow
*) NULL
;
423 m_cornerLabelWin
= (wxGridCornerLabelWindow
*) NULL
;
424 m_cellEditCtrl
= (wxWindow
*) NULL
;
427 wxGrid( wxWindow
*parent
,
429 const wxPoint
& pos
= wxDefaultPosition
,
430 const wxSize
& size
= wxDefaultSize
,
432 const wxString
& name
= wxPanelNameStr
);
436 bool CreateGrid( int numRows
, int numCols
);
439 // ------ grid dimensions
441 int GetNumberRows() { return m_numRows
; }
442 int GetNumberCols() { return m_numCols
; }
445 // ------ display update functions
447 void CalcRowLabelsExposed( wxRegion
& reg
);
449 void CalcColLabelsExposed( wxRegion
& reg
);
450 void CalcCellsExposed( wxRegion
& reg
);
453 // ------ event handlers
455 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
456 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
457 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
458 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
459 bool ProcessTableMessage( wxGridTableMessage
& );
461 void DoEndDragResizeRow();
462 void DoEndDragResizeCol();
464 wxGridTableBase
* GetTable() const { return m_table
; }
465 void SetTable( wxGridTableBase
*table
) { m_table
= table
; }
468 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
469 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
470 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
471 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
472 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
473 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
475 void DrawGridCellArea( wxDC
& dc
);
476 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
477 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
478 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
479 void DrawCellBackground( wxDC
& dc
, const wxGridCellCoords
& );
480 void DrawCellValue( wxDC
& dc
, const wxGridCellCoords
& );
482 void DrawRowLabels( wxDC
& dc
);
483 void DrawRowLabel( wxDC
& dc
, int row
);
485 void DrawColLabels( wxDC
& dc
);
486 void DrawColLabel( wxDC
& dc
, int col
);
489 // ------ Cell text drawing functions
491 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
492 int horizontalAlignment
= wxLEFT
,
493 int verticalAlignment
= wxTOP
);
495 // Split a string containing newline chararcters into an array of
496 // strings and return the number of lines
498 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
500 void GetTextBoxSize( wxDC
& dc
,
501 wxArrayString
& lines
,
502 long *width
, long *height
);
506 // Code that does a lot of grid modification can be enclosed
507 // between BeginBatch() and EndBatch() calls to avoid screen
510 void BeginBatch() { m_batchCount
++; }
511 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
512 int GetBatchCount() { return m_batchCount
; }
515 // ------ edit control functions
517 bool IsEditable() { return m_editable
; }
518 void EnableEditing( bool edit
);
520 #if 0 // at the moment the cell edit control is always active
521 void EnableCellEditControl( bool enable
);
524 bool IsCellEditControlEnabled()
525 { return (m_cellEditCtrl
&& m_cellEditCtrlEnabled
); }
527 void ShowCellEditControl();
528 void HideCellEditControl();
529 void SetEditControlValue( const wxString
& s
= wxEmptyString
);
530 void SaveEditControlValue();
533 // ------ grid location functions
534 // Note that all of these functions work with the logical coordinates of
535 // grid cells and labels so you will need to convert from device
536 // coordinates for mouse events etc.
538 void XYToCell( int x
, int y
, wxGridCellCoords
& );
542 int YToEdgeOfRow( int y
);
543 int XToEdgeOfCol( int x
);
545 wxRect
CellToRect( int row
, int col
);
546 wxRect
CellToRect( const wxGridCellCoords
& coords
)
547 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
549 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
550 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
552 // check to see if a cell is either wholly visible (the default arg) or
553 // at least partially visible in the grid window
555 bool IsVisible( int row
, int col
, bool wholeCellVisible
= TRUE
);
556 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= TRUE
)
557 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
558 void MakeCellVisible( int row
, int col
);
559 void MakeCellVisible( const wxGridCellCoords
& coords
)
560 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
563 // ------ grid cursor movement functions
565 void SetGridCursor( int row
, int col
)
566 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
569 bool MoveCursorDown();
570 bool MoveCursorLeft();
571 bool MoveCursorRight();
574 bool MoveCursorUpBlock();
575 bool MoveCursorDownBlock();
576 bool MoveCursorLeftBlock();
577 bool MoveCursorRightBlock();
580 // ------ label and gridline formatting
582 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
583 int GetRowLabelSize() { return m_rowLabelWidth
; }
584 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
585 int GetColLabelSize() { return m_colLabelHeight
; }
586 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
587 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
588 wxFont
GetLabelFont() { return m_labelFont
; }
589 void GetRowLabelAlignment( int *horiz
, int *vert
);
590 void GetColLabelAlignment( int *horiz
, int *vert
);
591 wxString
GetRowLabelValue( int row
);
592 wxString
GetColLabelValue( int col
);
593 wxColour
GetGridLineColour() { return m_gridLineColour
; }
595 void SetRowLabelSize( int width
);
596 void SetColLabelSize( int height
);
597 void SetLabelBackgroundColour( const wxColour
& );
598 void SetLabelTextColour( const wxColour
& );
599 void SetLabelFont( const wxFont
& );
600 void SetRowLabelAlignment( int horiz
, int vert
);
601 void SetColLabelAlignment( int horiz
, int vert
);
602 void SetRowLabelValue( int row
, const wxString
& );
603 void SetColLabelValue( int col
, const wxString
& );
604 void SetGridLineColour( const wxColour
& );
606 void EnableGridLines( bool enable
= TRUE
);
607 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
610 // ------ row and col formatting
612 int GetDefaultRowSize();
613 int GetRowSize( int row
);
614 int GetDefaultColSize();
615 int GetColSize( int col
);
616 wxColour
GetDefaultCellBackgroundColour();
617 wxColour
GetCellBackgroundColour( int row
, int col
);
618 wxColour
GetDefaultCellTextColour();
619 wxColour
GetCellTextColour( int row
, int col
);
620 wxFont
GetDefaultCellFont();
621 wxFont
GetCellFont( int row
, int col
);
622 void GetDefaultCellAlignment( int *horiz
, int *vert
);
623 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
625 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
626 void SetRowSize( int row
, int height
);
627 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
629 void SetColSize( int col
, int width
);
630 void SetDefaultCellBackgroundColour( const wxColour
& );
631 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
632 void SetDefaultCellTextColour( const wxColour
& );
634 void SetCellTextColour( int row
, int col
, const wxColour
& );
635 void SetDefaultCellFont( const wxFont
& );
636 void SetCellFont( int row
, int col
, const wxFont
& );
637 void SetDefaultCellAlignment( int horiz
, int vert
);
638 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
641 // ------ cell value accessors
643 wxString
GetCellValue( int row
, int col
)
647 return m_table
->GetValue( row
, col
);
651 return wxEmptyString
;
655 wxString
GetCellValue( const wxGridCellCoords
& coords
)
656 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
658 void SetCellValue( int row
, int col
, const wxString
& s
);
659 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
660 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
664 // ------ selections of blocks of cells
666 void SelectRow( int row
, bool addToSelected
= FALSE
);
667 void SelectCol( int col
, bool addToSelected
= FALSE
);
669 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
671 void SelectBlock( const wxGridCellCoords
& topLeft
,
672 const wxGridCellCoords
& bottomRight
)
673 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
674 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
679 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
680 m_selectedBottomRight
!= wxGridNoCellCoords
);
683 void ClearSelection();
685 bool IsInSelection( int row
, int col
)
686 { return ( IsSelection() &&
687 row
>= m_selectedTopLeft
.GetRow() &&
688 col
>= m_selectedTopLeft
.GetCol() &&
689 row
<= m_selectedBottomRight
.GetRow() &&
690 col
<= m_selectedBottomRight
.GetCol() );
693 bool IsInSelection( const wxGridCellCoords
& coords
)
694 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
696 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
698 // these will all be -1 if there is no selected block
700 *topRow
= m_selectedTopLeft
.GetRow();
701 *leftCol
= m_selectedTopLeft
.GetCol();
702 *bottomRow
= m_selectedBottomRight
.GetRow();
703 *rightCol
= m_selectedBottomRight
.GetCol();
707 // This function returns the rectangle that encloses the block of cells
708 // limited by TopLeft and BottomRight cell in device coords and clipped
709 // to the client size of the grid window.
711 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
712 const wxGridCellCoords
& bottomRight
);
714 // This function returns the rectangle that encloses the selected cells
715 // in device coords and clipped to the client size of the grid window.
717 wxRect
SelectionToDeviceRect()
719 return BlockToDeviceRect( m_selectedTopLeft
,
720 m_selectedBottomRight
);
724 // ------ For compatibility with previous wxGrid only...
726 // ************************************************
727 // ** Don't use these in new code because they **
728 // ** are liable to disappear in a future **
730 // ************************************************
733 wxGrid( wxWindow
*parent
,
734 int x
= -1, int y
= -1, int w
= -1, int h
= -1,
736 const wxString
& name
= wxPanelNameStr
)
737 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
), style
, name
)
742 void SetCellValue( const wxString
& val
, int row
, int col
)
743 { SetCellValue( row
, col
, val
); }
745 void UpdateDimensions()
746 { CalcDimensions(); }
748 int GetRows() { return GetNumberRows(); }
749 int GetCols() { return GetNumberCols(); }
750 int GetCursorRow() { return GetGridCursorRow(); }
751 int GetCursorColumn() { return GetGridCursorCol(); }
753 int GetScrollPosX() { return 0; }
754 int GetScrollPosY() { return 0; }
756 void SetScrollX( int x
) { }
757 void SetScrollY( int y
) { }
759 void SetColumnWidth( int col
, int width
)
760 { SetColSize( col
, width
); }
762 int GetColumnWidth( int col
)
763 { return GetColSize( col
); }
765 void SetRowHeight( int row
, int height
)
766 { SetRowSize( row
, height
); }
768 int GetRowHeight( int row
)
769 { return GetRowSize( row
); }
771 int GetViewHeight() // returned num whole rows visible
774 int GetViewWidth() // returned num whole cols visible
777 void SetLabelSize( int orientation
, int sz
)
779 if ( orientation
== wxHORIZONTAL
)
780 SetColLabelSize( sz
);
782 SetRowLabelSize( sz
);
785 int GetLabelSize( int orientation
)
787 if ( orientation
== wxHORIZONTAL
)
788 return GetColLabelSize();
790 return GetRowLabelSize();
793 void SetLabelAlignment( int orientation
, int align
)
795 if ( orientation
== wxHORIZONTAL
)
796 SetColLabelAlignment( align
, -1 );
798 SetRowLabelAlignment( align
, -1 );
801 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
804 if ( orientation
== wxHORIZONTAL
)
806 GetColLabelAlignment( &h
, &v
);
811 GetRowLabelAlignment( &h
, &v
);
816 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
818 if ( orientation
== wxHORIZONTAL
)
819 SetColLabelValue( pos
, val
);
821 SetRowLabelValue( pos
, val
);
824 wxString
GetLabelValue( int orientation
, int pos
)
826 if ( orientation
== wxHORIZONTAL
)
827 return GetColLabelValue( pos
);
829 return GetRowLabelValue( pos
);
832 wxFont
GetCellTextFont() const
833 { return m_defaultCellFont
; }
835 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
836 { return m_defaultCellFont
; }
838 void SetCellTextFont(const wxFont
& fnt
)
839 { SetDefaultCellFont( fnt
); }
841 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
842 { SetCellFont( row
, col
, fnt
); }
844 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
845 { SetCellTextColour( row
, col
, val
); }
847 void SetCellTextColour(const wxColour
& col
)
848 { SetDefaultCellTextColour( col
); }
850 void SetCellBackgroundColour(const wxColour
& col
)
851 { SetDefaultCellBackgroundColour( col
); }
853 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
854 { SetCellBackgroundColour( row
, col
, colour
); }
856 bool GetEditable() { return IsEditable(); }
857 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
858 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
860 void SetEditInPlace(bool edit
= TRUE
) { }
862 void SetCellAlignment( int align
, int row
, int col
)
863 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
864 void SetCellAlignment( int WXUNUSED(align
) ) {}
865 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
867 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
868 wxPen
& GetDividerPen() const { return wxNullPen
; }
869 void OnActivate(bool WXUNUSED(active
)) {}
871 // ******** End of compatibility functions **********
875 // ------ control IDs
876 enum { wxGRID_CELLCTRL
= 2000,
879 // ------ control types
880 enum { wxGRID_TEXTCTRL
= 2100,
889 wxGridWindow
*m_gridWin
;
890 wxGridRowLabelWindow
*m_rowLabelWin
;
891 wxGridColLabelWindow
*m_colLabelWin
;
892 wxGridCornerLabelWindow
*m_cornerLabelWin
;
894 wxGridTableBase
*m_table
;
904 wxGridCellCoords m_currentCellCoords
;
906 wxGridCellCoords m_selectedTopLeft
;
907 wxGridCellCoords m_selectedBottomRight
;
909 int m_defaultRowHeight
;
910 wxArrayInt m_rowHeights
;
911 wxArrayInt m_rowBottoms
;
913 int m_defaultColWidth
;
914 wxArrayInt m_colWidths
;
915 wxArrayInt m_colRights
;
918 int m_colLabelHeight
;
920 wxColour m_labelBackgroundColour
;
921 wxColour m_labelTextColour
;
924 int m_rowLabelHorizAlign
;
925 int m_rowLabelVertAlign
;
926 int m_colLabelHorizAlign
;
927 int m_colLabelVertAlign
;
929 bool m_defaultRowLabelValues
;
930 bool m_defaultColLabelValues
;
932 wxColour m_gridLineColour
;
933 bool m_gridLinesEnabled
;
935 // default cell attributes
936 wxFont m_defaultCellFont
;
937 int m_defaultCellHAlign
,
940 // do we have some place to store attributes in?
941 bool CanHaveAttributes();
943 wxGridCellCoordsArray m_cellsExposed
;
944 wxArrayInt m_rowsExposed
;
945 wxArrayInt m_colsExposed
;
946 wxArrayInt m_rowLabelsExposed
;
947 wxArrayInt m_colLabelsExposed
;
954 WXGRID_CURSOR_SELECT_CELL
,
955 WXGRID_CURSOR_RESIZE_ROW
,
956 WXGRID_CURSOR_RESIZE_COL
,
957 WXGRID_CURSOR_SELECT_ROW
,
958 WXGRID_CURSOR_SELECT_COL
961 // this method not only sets m_cursorMode but also sets the correct cursor
962 // for the given mode and, if captureMouse is not FALSE releases the mouse
963 // if it was captured and captures it if it must be captured
965 // for this to work, you should always use it and not set m_cursorMode
967 void ChangeCursorMode(CursorMode mode
,
968 wxWindow
*win
= (wxWindow
*)NULL
,
969 bool captureMouse
= TRUE
);
971 wxWindow
*m_winCapture
; // the window which captured the mouse
972 CursorMode m_cursorMode
;
978 wxGridCellCoords m_selectionStart
;
980 wxCursor m_rowResizeCursor
;
981 wxCursor m_colResizeCursor
;
983 bool m_editable
; // applies to whole grid
984 int m_editCtrlType
; // for current cell
985 wxWindow
* m_cellEditCtrl
;
986 bool m_cellEditCtrlEnabled
;
991 void CalcDimensions();
992 void CalcWindowSizes();
993 bool Redimension( wxGridTableMessage
& );
996 bool SendEvent( const wxEventType
,
1000 bool SendEvent( const wxEventType
,
1004 void OnPaint( wxPaintEvent
& );
1005 void OnSize( wxSizeEvent
& );
1006 void OnKeyDown( wxKeyEvent
& );
1009 void SetCurrentCell( const wxGridCellCoords
& coords
);
1010 void SetCurrentCell( int row
, int col
)
1011 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1014 // ------ functions to get/send data (see also public functions)
1016 bool GetModelValues();
1017 bool SetModelValues();
1020 DECLARE_DYNAMIC_CLASS( wxGrid
)
1021 DECLARE_EVENT_TABLE()
1029 // ------ Grid event class and event types
1032 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
1036 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
1037 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1041 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
1042 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
1043 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1045 virtual int GetRow() { return m_row
; }
1046 virtual int GetCol() { return m_col
; }
1047 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1048 bool ControlDown() { return m_control
; }
1049 bool MetaDown() { return m_meta
; }
1050 bool ShiftDown() { return m_shift
; }
1051 bool AltDown() { return m_alt
; }
1063 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
1067 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
1071 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1072 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1076 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1077 int rowOrCol
=-1, int x
=-1, int y
=-1,
1078 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1080 int GetRowOrCol() { return m_rowOrCol
; }
1081 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1082 bool ControlDown() { return m_control
; }
1083 bool MetaDown() { return m_meta
; }
1084 bool ShiftDown() { return m_shift
; }
1085 bool AltDown() { return m_alt
; }
1096 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1100 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1103 wxGridRangeSelectEvent()
1106 m_topLeft
= wxGridNoCellCoords
;
1107 m_bottomRight
= wxGridNoCellCoords
;
1114 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1115 const wxGridCellCoords
& topLeft
,
1116 const wxGridCellCoords
& bottomRight
,
1117 bool control
=FALSE
, bool shift
=FALSE
,
1118 bool alt
=FALSE
, bool meta
=FALSE
);
1120 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1121 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1122 int GetTopRow() { return m_topLeft
.GetRow(); }
1123 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1124 int GetLeftCol() { return m_topLeft
.GetCol(); }
1125 int GetRightCol() { return m_bottomRight
.GetCol(); }
1126 bool ControlDown() { return m_control
; }
1127 bool MetaDown() { return m_meta
; }
1128 bool ShiftDown() { return m_shift
; }
1129 bool AltDown() { return m_alt
; }
1132 wxGridCellCoords m_topLeft
;
1133 wxGridCellCoords m_bottomRight
;
1139 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1143 const wxEventType EVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1144 const wxEventType EVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1145 const wxEventType EVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1146 const wxEventType EVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1147 const wxEventType EVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1148 const wxEventType EVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1149 const wxEventType EVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1150 const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1151 const wxEventType EVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1152 const wxEventType EVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1153 const wxEventType EVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1154 const wxEventType EVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1155 const wxEventType EVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1158 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1159 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1160 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1162 #define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1163 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1164 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1165 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1166 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1167 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1168 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1169 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1170 #define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1171 #define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1172 #define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1173 #define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1174 #define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1177 #if 0 // TODO: implement these ? others ?
1179 const wxEventType EVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1180 const wxEventType EVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1181 const wxEventType EVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1183 #define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1184 #define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1185 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1189 #endif // #ifndef __WXGRID_H__
1191 #endif // ifndef wxUSE_NEW_GRID