]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/grid.h
Major redesign of grid classes:
[wxWidgets.git] / include / wx / generic / grid.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: grid.h
3 // Purpose: wxGrid and related classes
4 // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
5 // Modified by:
6 // Created: 1/08/1999
7 // RCS-ID: $Id$
8 // Copyright: (c) Michael Bedward
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12
13 #include "wx/defs.h"
14
15 #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
16 #include "gridg.h"
17 #else
18
19 #ifndef __WXGRID_H__
20 #define __WXGRID_H__
21
22 #ifdef __GNUG__
23 #pragma interface "grid.h"
24 #endif
25
26 #include "wx/panel.h"
27 #include "wx/scrolwin.h"
28 #include "wx/string.h"
29 #include "wx/scrolbar.h"
30 #include "wx/event.h"
31 #include "wx/textctrl.h"
32 #include "wx/combobox.h"
33 #include "wx/dynarray.h"
34
35
36 // Default parameters for wxGrid
37 //
38 #define WXGRID_DEFAULT_NUMBER_ROWS 10
39 #define WXGRID_DEFAULT_NUMBER_COLS 10
40 #ifdef __WXMSW__
41 #define WXGRID_DEFAULT_ROW_HEIGHT 25
42 #else
43 #define WXGRID_DEFAULT_ROW_HEIGHT 30
44 #endif // __WXMSW__
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
52 #define WXGRID_DEFAULT_TOPEDIT_WIDTH 300
53 #define WXGRID_DEFAULT_TOPEDIT_HEIGHT 60
54
55
56 class WXDLLEXPORT wxGrid;
57
58
59 //////////////////////////////////////////////////////////////////////
60 //
61 // Grid table classes
62 //
63 //////////////////////////////////////////////////////////////////////
64
65
66 class WXDLLEXPORT wxGridTableBase : public wxObject
67 {
68 wxGrid * m_view;
69
70 public:
71 wxGridTableBase();
72 virtual ~wxGridTableBase();
73
74 // You must override these functions in a derived table class
75 //
76 virtual long GetNumberRows() = 0;
77 virtual long GetNumberCols() = 0;
78 virtual wxString GetValue( int row, int col ) = 0;
79 virtual void SetValue( int row, int col, const wxString& s ) = 0;
80 virtual bool IsEmptyCell( int row, int col ) = 0;
81
82 // Overriding these is optional
83 //
84 virtual void SetView( wxGrid *grid ) { m_view = grid; }
85 virtual wxGrid * GetView() const { return m_view; }
86
87 virtual void Clear() {}
88 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
89 virtual bool AppendRows( size_t numRows = 1 );
90 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
91 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
92 virtual bool AppendCols( size_t numCols = 1 );
93 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
94
95 virtual wxString GetRowLabelValue( int row );
96 virtual wxString GetColLabelValue( int col );
97 virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {}
98 virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {}
99
100 DECLARE_ABSTRACT_CLASS( wxGridTableBase );
101 };
102
103
104
105 // IDs for messages sent from grid table to view
106 //
107 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
116 };
117
118 class WXDLLEXPORT wxGridTableMessage
119 {
120 wxGridTableBase *m_table;
121 int m_id;
122 int m_comInt1;
123 int m_comInt2;
124
125 public:
126 wxGridTableMessage();
127 wxGridTableMessage( wxGridTableBase *table, int id,
128 int comInt1 = -1,
129 int comInt2 = -1 );
130
131 void SetTableObject( wxGridTableBase *table ) { m_table = table; }
132 wxGridTableBase * GetTableObject() const { return m_table; }
133 void SetId( int id ) { m_id = id; }
134 int GetId() { return m_id; }
135 void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; }
136 int GetCommandInt() { return m_comInt1; }
137 void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; }
138 int GetCommandInt2() { return m_comInt2; }
139 };
140
141
142
143 // ------ wxGridStringArray
144 // A 2-dimensional array of strings for data values
145 //
146
147 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString, wxGridStringArray);
148
149
150
151 // ------ wxGridStringTable
152 //
153 // Simplest type of data table for a grid for small tables of strings
154 // that are stored in memory
155 //
156
157 class WXDLLEXPORT wxGridStringTable : public wxGridTableBase
158 {
159 wxGridStringArray m_data;
160
161 // These only get used if you set your own labels, otherwise the
162 // GetRow/ColLabelValue functions return wxGridTableBase defaults
163 //
164 wxArrayString m_rowLabels;
165 wxArrayString m_colLabels;
166
167 public:
168 wxGridStringTable();
169 wxGridStringTable( int numRows, int numCols );
170 ~wxGridStringTable();
171
172 // these are pure virtual in wxGridTableBase
173 //
174 long GetNumberRows();
175 long GetNumberCols();
176 wxString GetValue( int row, int col );
177 void SetValue( int row, int col, const wxString& s );
178 bool IsEmptyCell( int row, int col );
179
180 // overridden functions from wxGridTableBase
181 //
182 void Clear();
183 bool InsertRows( size_t pos = 0, size_t numRows = 1 );
184 bool AppendRows( size_t numRows = 1 );
185 bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
186 bool InsertCols( size_t pos = 0, size_t numCols = 1 );
187 bool AppendCols( size_t numCols = 1 );
188 bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
189
190 void SetRowLabelValue( int row, const wxString& );
191 void SetColLabelValue( int col, const wxString& );
192 wxString GetRowLabelValue( int row );
193 wxString GetColLabelValue( int col );
194
195 DECLARE_DYNAMIC_CLASS( wxGridStringTable )
196 };
197
198
199
200 //////////////////////////////////////////////////////////////////////
201 //
202 // Grid view classes
203 //
204 //////////////////////////////////////////////////////////////////////
205
206 class WXDLLEXPORT wxGridCellCoords
207 {
208 long m_row;
209 long m_col;
210
211 public:
212 wxGridCellCoords() { m_row = m_col = -1; }
213 wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; }
214
215 // default copy ctor is ok
216
217 long GetRow() const { return m_row; }
218 void SetRow( long n ) { m_row = n; }
219 long GetCol() const { return m_col; }
220 void SetCol( long n ) { m_col = n; }
221 void Set( long row, long col ) { m_row = row; m_col = col; }
222
223 wxGridCellCoords& operator=( const wxGridCellCoords& other )
224 {
225 if ( &other != this )
226 {
227 m_row=other.m_row;
228 m_col=other.m_col;
229 }
230 return *this;
231 }
232
233 bool operator==( const wxGridCellCoords& other )
234 {
235 return (m_row == other.m_row && m_col == other.m_col);
236 }
237
238 bool operator!=( const wxGridCellCoords& other )
239 {
240 return (m_row != other.m_row || m_col != other.m_col);
241 }
242
243 bool operator!()
244 {
245 return (m_row == -1 && m_col == -1 );
246 }
247 };
248
249
250 // For comparisons...
251 //
252 extern wxGridCellCoords wxGridNoCellCoords;
253 extern wxRect wxGridNoCellRect;
254
255 // An array of cell coords...
256 //
257 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords, wxGridCellCoordsArray);
258
259
260
261 // This set of classes is to provide for the use of different types of
262 // cell edit controls in the grid while avoiding the wx class info
263 // system in deference to wxPython
264
265 class WXDLLEXPORT wxGridTextCtrl : public wxTextCtrl
266 {
267 wxGrid *m_grid;
268
269 // TRUE for controls placed over cells,
270 // FALSE for a control on a grid control panel
271 bool m_isCellControl;
272
273 wxString startValue;
274
275 void OnKeyDown( wxKeyEvent& );
276
277 public:
278 wxGridTextCtrl() {}
279 wxGridTextCtrl( wxWindow *,
280 wxGrid *,
281 bool isCellControl,
282 wxWindowID id,
283 const wxString& value = wxEmptyString,
284 const wxPoint& pos = wxDefaultPosition,
285 const wxSize& size = wxDefaultSize,
286 long style = 0 );
287
288 void SetStartValue( const wxString& );
289 wxString GetStartValue() { return startValue; }
290
291 DECLARE_DYNAMIC_CLASS( wxGridTextCtrl )
292 DECLARE_EVENT_TABLE()
293 };
294
295
296 class WXDLLEXPORT wxGridRowLabelWindow : public wxWindow
297 {
298 wxGrid *m_owner;
299
300 void OnPaint( wxPaintEvent& event );
301 void OnMouseEvent( wxMouseEvent& event );
302 void OnKeyDown( wxKeyEvent& event );
303
304 public:
305 wxGridRowLabelWindow() {}
306 wxGridRowLabelWindow( wxGrid *parent, wxWindowID id,
307 const wxPoint &pos, const wxSize &size );
308
309 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow)
310 DECLARE_EVENT_TABLE()
311 };
312
313
314 class WXDLLEXPORT wxGridColLabelWindow : public wxWindow
315 {
316 wxGrid *m_owner;
317
318 void OnPaint( wxPaintEvent &event );
319 void OnMouseEvent( wxMouseEvent& event );
320 void OnKeyDown( wxKeyEvent& event );
321
322 public:
323 wxGridColLabelWindow() {}
324 wxGridColLabelWindow( wxGrid *parent, wxWindowID id,
325 const wxPoint &pos, const wxSize &size );
326
327 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow)
328 DECLARE_EVENT_TABLE()
329 };
330
331
332 class WXDLLEXPORT wxGridCornerLabelWindow : public wxWindow
333 {
334 wxGrid *m_owner;
335
336 void OnMouseEvent( wxMouseEvent& event );
337 void OnKeyDown( wxKeyEvent& event );
338
339 public:
340 wxGridCornerLabelWindow() {}
341 wxGridCornerLabelWindow( wxGrid *parent, wxWindowID id,
342 const wxPoint &pos, const wxSize &size );
343
344 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow)
345 DECLARE_EVENT_TABLE()
346 };
347
348
349
350 class WXDLLEXPORT wxGridWindow : public wxPanel
351 {
352 wxGrid *m_owner;
353 wxGridRowLabelWindow *m_rowLabelWin;
354 wxGridColLabelWindow *m_colLabelWin;
355
356 void OnPaint( wxPaintEvent &event );
357 void OnMouseEvent( wxMouseEvent& event );
358 void OnKeyDown( wxKeyEvent& );
359
360 public:
361 wxGridWindow() {}
362 wxGridWindow( wxGrid *parent,
363 wxGridRowLabelWindow *rowLblWin,
364 wxGridColLabelWindow *colLblWin,
365 wxWindowID id, const wxPoint &pos, const wxSize &size );
366 ~wxGridWindow();
367
368 void ScrollWindow( int dx, int dy, const wxRect *rect );
369
370 DECLARE_DYNAMIC_CLASS(wxGridWindow)
371 DECLARE_EVENT_TABLE()
372 };
373
374
375
376 class WXDLLEXPORT wxGrid : public wxScrolledWindow
377 {
378 protected:
379 bool m_created;
380
381 wxGridWindow *m_gridWin;
382 wxGridRowLabelWindow *m_rowLabelWin;
383 wxGridColLabelWindow *m_colLabelWin;
384 wxGridCornerLabelWindow *m_cornerLabelWin;
385
386 wxBoxSizer *m_mainSizer;
387 wxBoxSizer *m_topSizer;
388 wxBoxSizer *m_middleSizer;
389
390 wxGridTableBase *m_table;
391
392 int m_left;
393 int m_top;
394 int m_right;
395 int m_bottom;
396
397 int m_numRows;
398 int m_numCols;
399
400 wxGridCellCoords m_currentCellCoords;
401 bool m_currentCellHighlighted;
402
403 wxGridCellCoords m_selectedTopLeft;
404 wxGridCellCoords m_selectedBottomRight;
405
406 int m_defaultRowHeight;
407 wxArrayInt m_rowHeights;
408 wxArrayInt m_rowBottoms;
409
410 int m_defaultColWidth;
411 wxArrayInt m_colWidths;
412 wxArrayInt m_colRights;
413
414 int m_rowLabelWidth;
415 int m_colLabelHeight;
416
417 wxColour m_labelBackgroundColour;
418 wxColour m_labelTextColour;
419 wxFont m_labelFont;
420
421 int m_rowLabelHorizAlign;
422 int m_rowLabelVertAlign;
423 int m_colLabelHorizAlign;
424 int m_colLabelVertAlign;
425
426 bool m_defaultRowLabelValues;
427 bool m_defaultColLabelValues;
428
429 wxColour m_gridLineColour;
430 bool m_gridLinesEnabled;
431
432 wxFont m_defaultCellFont;
433
434 wxGridCellCoordsArray m_cellsExposed;
435 wxArrayInt m_rowsExposed;
436 wxArrayInt m_colsExposed;
437 wxArrayInt m_rowLabelsExposed;
438 wxArrayInt m_colLabelsExposed;
439
440 bool m_inOnKeyDown;
441 int m_batchCount;
442
443 int m_cursorMode;
444 enum { WXGRID_CURSOR_DEFAULT,
445 WXGRID_CURSOR_SELECT_CELL,
446 WXGRID_CURSOR_RESIZE_ROW,
447 WXGRID_CURSOR_RESIZE_COL,
448 WXGRID_CURSOR_SELECT_ROW,
449 WXGRID_CURSOR_SELECT_COL
450 };
451
452 int m_dragLastPos;
453 int m_dragRowOrCol;
454 bool m_isDragging;
455
456 wxGridCellCoords m_selectionStart;
457
458 wxCursor m_rowResizeCursor;
459 wxCursor m_colResizeCursor;
460
461 bool m_editable; // applies to whole grid
462 int m_editCtrlType; // for current cell
463 wxWindow* m_cellEditCtrl;
464 bool m_cellEditCtrlEnabled;
465 wxWindow* m_topEditCtrl;
466 bool m_topEditCtrlEnabled;
467
468
469 void Create();
470 void Init();
471 void CalcDimensions();
472 bool Redimension( wxGridTableMessage& );
473
474
475 bool SendEvent( const wxEventType,
476 int row, int col,
477 wxMouseEvent& );
478
479 bool SendEvent( const wxEventType,
480 int row, int col );
481
482
483 void OnPaint( wxPaintEvent& );
484 void OnSize( wxSizeEvent& );
485 void OnKeyDown( wxKeyEvent& );
486
487
488 void SetCurrentCell( const wxGridCellCoords& coords );
489 void SetCurrentCell( int row, int col )
490 { SetCurrentCell( wxGridCellCoords(row, col) ); }
491
492
493 // ------ functions to get/send data (see also public functions)
494 //
495 bool GetModelValues();
496 bool SetModelValues();
497
498
499 ////////////////////// Public section ////////////////////
500
501 public:
502 wxGrid()
503 { Create(); }
504
505 wxGrid( wxWindow *parent,
506 wxWindowID id,
507 const wxPoint& pos = wxDefaultPosition,
508 const wxSize& size = wxDefaultSize,
509 long style = 0,
510 const wxString& name = wxPanelNameStr );
511
512 ~wxGrid();
513
514 bool CreateGrid( int numRows, int numCols );
515
516
517 // ------ grid dimensions
518 //
519 int GetNumberRows() { return m_numRows; }
520 int GetNumberCols() { return m_numCols; }
521
522
523 // ------ display update functions
524 //
525 void CalcRowLabelsExposed( wxRegion& reg );
526 void CalcColLabelsExposed( wxRegion& reg );
527 void CalcCellsExposed( wxRegion& reg );
528
529
530 // ------ event handlers
531 //
532 void ProcessRowLabelMouseEvent( wxMouseEvent& event );
533 void ProcessColLabelMouseEvent( wxMouseEvent& event );
534 void ProcessCornerLabelMouseEvent( wxMouseEvent& event );
535 void ProcessGridCellMouseEvent( wxMouseEvent& event );
536 bool ProcessTableMessage( wxGridTableMessage& );
537
538
539 wxGridTableBase * GetTable() const { return m_table; }
540 void SetTable( wxGridTableBase *table ) { m_table = table; }
541
542 void ClearGrid();
543 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
544 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
545 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
546 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
547 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
548 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
549
550 void DrawGridCellArea( wxDC& dc );
551 void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
552 void DrawAllGridLines( wxDC& dc ); // TODO - delete this ?
553 void DrawCell( wxDC& dc, const wxGridCellCoords& );
554 void DrawCellBackground( wxDC& dc, const wxGridCellCoords& );
555 void DrawCellValue( wxDC& dc, const wxGridCellCoords& );
556
557 void DrawRowLabels( wxDC& dc );
558 void DrawRowLabel( wxDC& dc, int row );
559 void DrawColLabels( wxDC& dc );
560 void DrawColLabel( wxDC& dc, int col );
561
562
563 // ------ Cell text drawing functions
564 //
565 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
566 int horizontalAlignment = wxLEFT,
567 int verticalAlignment = wxTOP );
568
569 // Split a string containing newline chararcters into an array of
570 // strings and return the number of lines
571 //
572 void StringToLines( const wxString& value, wxArrayString& lines );
573
574 void GetTextBoxSize( wxDC& dc,
575 wxArrayString& lines,
576 long *width, long *height );
577
578
579 // ------
580 // Code that does a lot of grid modification can be enclosed
581 // between BeginBatch() and EndBatch() calls to avoid screen
582 // flicker
583 //
584 void BeginBatch() { m_batchCount++; }
585 void EndBatch() { if ( m_batchCount > 0 ) m_batchCount--; }
586 int GetBatchCount() { return m_batchCount; }
587
588
589 // ------ edit control functions
590 //
591 bool IsEditable() { return m_editable; }
592 void EnableEditing( bool edit );
593
594 void EnableCellEditControl( bool enable );
595
596 bool IsCellEditControlEnabled()
597 { return (m_cellEditCtrl && m_cellEditCtrlEnabled); }
598
599 void EnableTopEditControl( bool enable );
600
601 bool IsTopEditControlEnabled()
602 { return (m_topEditCtrl && m_topEditCtrlEnabled); }
603
604 void ShowCellEditControl();
605 void HideCellEditControl();
606 void SetEditControlValue( const wxString& s = wxEmptyString );
607 void SaveEditControlValue();
608
609
610 // ------ grid location functions
611 // Note that all of these functions work with the logical coordinates of
612 // grid cells and labels so you will need to convert from device
613 // coordinates for mouse events etc.
614 //
615 void XYToCell( int x, int y, wxGridCellCoords& );
616 int YToRow( int y );
617 int XToCol( int x );
618
619 int YToEdgeOfRow( int y );
620 int XToEdgeOfCol( int x );
621
622 wxRect CellToRect( int row, int col );
623 wxRect CellToRect( const wxGridCellCoords& coords )
624 { return CellToRect( coords.GetRow(), coords.GetCol() ); }
625
626 int GetGridCursorRow() { return m_currentCellCoords.GetRow(); }
627 int GetGridCursorCol() { return m_currentCellCoords.GetCol(); }
628
629 // check to see if a cell is either wholly visible (the default arg) or
630 // at least partially visible in the grid window
631 //
632 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
633 bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE )
634 { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); }
635 void MakeCellVisible( int row, int col );
636 void MakeCellVisible( const wxGridCellCoords& coords )
637 { MakeCellVisible( coords.GetRow(), coords.GetCol() ); }
638
639
640 // ------ grid cursor movement functions
641 //
642 bool MoveCursorUp();
643 bool MoveCursorDown();
644 bool MoveCursorLeft();
645 bool MoveCursorRight();
646 bool MovePageDown();
647 bool MovePageUp();
648 bool MoveCursorUpBlock();
649 bool MoveCursorDownBlock();
650 bool MoveCursorLeftBlock();
651 bool MoveCursorRightBlock();
652
653
654 // ------ label and gridline formatting
655 //
656 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; }
657 int GetRowLabelSize() { return m_rowLabelWidth; }
658 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; }
659 int GetColLabelSize() { return m_colLabelHeight; }
660 wxColour GetLabelBackgroundColour() { return m_labelBackgroundColour; }
661 wxColour GetLabelTextColour() { return m_labelTextColour; }
662 wxFont GetLabelFont() { return m_labelFont; }
663 void GetRowLabelAlignment( int *horiz, int *vert );
664 void GetColLabelAlignment( int *horiz, int *vert );
665 wxString GetRowLabelValue( int row );
666 wxString GetColLabelValue( int col );
667 wxColour GetGridLineColour() { return m_gridLineColour; }
668
669 void SetRowLabelSize( int width );
670 void SetColLabelSize( int height );
671 void SetLabelBackgroundColour( const wxColour& );
672 void SetLabelTextColour( const wxColour& );
673 void SetLabelFont( const wxFont& );
674 void SetRowLabelAlignment( int horiz, int vert );
675 void SetColLabelAlignment( int horiz, int vert );
676 void SetRowLabelValue( int row, const wxString& );
677 void SetColLabelValue( int col, const wxString& );
678 void SetGridLineColour( const wxColour& );
679
680 void EnableGridLines( bool enable = TRUE );
681 bool GridLinesEnabled() { return m_gridLinesEnabled; }
682
683
684 // ------ row and col formatting
685 //
686 int GetDefaultRowSize();
687 int GetRowSize( int row );
688 int GetDefaultColSize();
689 int GetColSize( int col );
690 wxColour GetDefaultCellBackgroundColour();
691 wxColour GetCellBackgroundColour( int row, int col );
692 wxColour GetDefaultCellTextColour();
693 wxColour GetCellTextColour( int row, int col );
694 wxColour GetCellHighlightColour();
695 wxFont GetDefaultCellFont();
696 wxFont GetCellFont( int row, int col );
697 void GetDefaultCellAlignment( int *horiz, int *vert );
698 void GetCellAlignment( int row, int col, int *horiz, int *vert );
699
700 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
701 void SetRowSize( int row, int height );
702 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
703 void SetColSize( int col, int width );
704 void SetDefaultCellBackgroundColour( const wxColour& );
705 void SetCellBackgroundColour( int row, int col, const wxColour& );
706 void SetDefaultCellTextColour( const wxColour& );
707 void SetCellTextColour( int row, int col, const wxColour& );
708 void SetCellHighlightColour( const wxColour& );
709 void SetDefaultCellFont( const wxFont& );
710 void SetCellFont( int row, int col, const wxFont& );
711 void SetDefaultCellAlignment( int horiz, int vert );
712 void SetCellAlignment( int row, int col, int horiz, int vert );
713
714
715 // ------ cell value accessors
716 //
717 wxString GetCellValue( int row, int col )
718 {
719 if ( m_table )
720 {
721 return m_table->GetValue( row, col );
722 }
723 else
724 {
725 return wxEmptyString;
726 }
727 }
728
729 wxString GetCellValue( const wxGridCellCoords& coords )
730 { return GetCellValue( coords.GetRow(), coords.GetCol() ); }
731
732 void SetCellValue( int row, int col, const wxString& s );
733 void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
734 { SetCellValue( coords.GetRow(), coords.GetCol(), s ); }
735
736
737
738 // ------ selections of blocks of cells
739 //
740 void SelectRow( int row, bool addToSelected = FALSE );
741 void SelectCol( int col, bool addToSelected = FALSE );
742
743 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol );
744
745 void SelectBlock( const wxGridCellCoords& topLeft,
746 const wxGridCellCoords& bottomRight )
747 { SelectBlock( topLeft.GetRow(), topLeft.GetCol(),
748 bottomRight.GetRow(), bottomRight.GetCol() ); }
749
750 void SelectAll();
751
752 bool IsSelection()
753 { return ( m_selectedTopLeft != wxGridNoCellCoords &&
754 m_selectedBottomRight != wxGridNoCellCoords );
755 }
756
757 void ClearSelection();
758
759 bool IsInSelection( int row, int col )
760 { return ( IsSelection() &&
761 row >= m_selectedTopLeft.GetRow() &&
762 col >= m_selectedTopLeft.GetCol() &&
763 row <= m_selectedBottomRight.GetRow() &&
764 col <= m_selectedBottomRight.GetCol() );
765 }
766
767 bool IsInSelection( const wxGridCellCoords& coords )
768 { return IsInSelection( coords.GetRow(), coords.GetCol() ); }
769
770 void GetSelection( int* topRow, int* leftCol, int* bottomRow, int* rightCol )
771 {
772 // these will all be -1 if there is no selected block
773 //
774 *topRow = m_selectedTopLeft.GetRow();
775 *leftCol = m_selectedTopLeft.GetCol();
776 *bottomRow = m_selectedBottomRight.GetRow();
777 *rightCol = m_selectedBottomRight.GetCol();
778 }
779
780 // This function returns the rectangle that encloses the selected cells
781 // in device coords and clipped to the client size of the grid window.
782 //
783 wxRect SelectionToDeviceRect();
784
785
786
787 // ------ For compatibility with previous wxGrid only...
788 //
789 // ************************************************
790 // ** Don't use these in new code because they **
791 // ** are liable to disappear in a future **
792 // ** revision **
793 // ************************************************
794 //
795
796 wxGrid( wxWindow *parent,
797 int x = -1, int y = -1, int w = -1, int h = -1,
798 long style = 0,
799 const wxString& name = wxPanelNameStr )
800 : wxScrolledWindow( parent, -1, wxPoint(x,y), wxSize(w,h), style, name )
801 {
802 Create();
803 }
804
805 void SetCellValue( const wxString& val, int row, int col )
806 { SetCellValue( row, col, val ); }
807
808 void UpdateDimensions()
809 { CalcDimensions(); }
810
811 int GetRows() { return GetNumberRows(); }
812 int GetCols() { return GetNumberCols(); }
813 int GetCursorRow() { return GetGridCursorRow(); }
814 int GetCursorColumn() { return GetGridCursorCol(); }
815
816 int GetScrollPosX() { return 0; }
817 int GetScrollPosY() { return 0; }
818
819 void SetScrollX( int x ) { }
820 void SetScrollY( int y ) { }
821
822 void SetColumnWidth( int col, int width )
823 { SetColSize( col, width ); }
824
825 int GetColumnWidth( int col )
826 { return GetColSize( col ); }
827
828 void SetRowHeight( int row, int height )
829 { SetRowSize( row, height ); }
830
831 int GetRowHeight( int row )
832 { return GetRowSize( row ); }
833
834 int GetViewHeight() // returned num whole rows visible
835 { return 0; }
836
837 int GetViewWidth() // returned num whole cols visible
838 { return 0; }
839
840 void SetLabelSize( int orientation, int sz )
841 {
842 if ( orientation == wxHORIZONTAL )
843 SetColLabelSize( sz );
844 else
845 SetRowLabelSize( sz );
846 }
847
848 int GetLabelSize( int orientation )
849 {
850 if ( orientation == wxHORIZONTAL )
851 return GetColLabelSize();
852 else
853 return GetRowLabelSize();
854 }
855
856 void SetLabelAlignment( int orientation, int align )
857 {
858 if ( orientation == wxHORIZONTAL )
859 SetColLabelAlignment( align, -1 );
860 else
861 SetRowLabelAlignment( align, -1 );
862 }
863
864 int GetLabelAlignment( int orientation, int WXUNUSED(align) )
865 {
866 int h, v;
867 if ( orientation == wxHORIZONTAL )
868 {
869 GetColLabelAlignment( &h, &v );
870 return h;
871 }
872 else
873 {
874 GetRowLabelAlignment( &h, &v );
875 return h;
876 }
877 }
878
879 void SetLabelValue( int orientation, const wxString& val, int pos )
880 {
881 if ( orientation == wxHORIZONTAL )
882 SetColLabelValue( pos, val );
883 else
884 SetRowLabelValue( pos, val );
885 }
886
887 wxString GetLabelValue( int orientation, int pos)
888 {
889 if ( orientation == wxHORIZONTAL )
890 return GetColLabelValue( pos );
891 else
892 return GetRowLabelValue( pos );
893 }
894
895 wxFont GetCellTextFont() const
896 { return m_defaultCellFont; }
897
898 wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const
899 { return m_defaultCellFont; }
900
901 void SetCellTextFont(const wxFont& fnt)
902 { SetDefaultCellFont( fnt ); }
903
904 void SetCellTextFont(const wxFont& fnt, int row, int col)
905 { SetCellFont( row, col, fnt ); }
906
907 void SetCellTextColour(const wxColour& val, int row, int col)
908 { SetCellTextColour( row, col, val ); }
909
910 void SetCellTextColour(const wxColour& col)
911 { SetDefaultCellTextColour( col ); }
912
913 void SetCellBackgroundColour(const wxColour& col)
914 { SetDefaultCellBackgroundColour( col ); }
915
916 void SetCellBackgroundColour(const wxColour& colour, int row, int col)
917 { SetCellBackgroundColour( row, col, colour ); }
918
919 bool GetEditable() { return IsEditable(); }
920 void SetEditable( bool edit = TRUE ) { EnableEditing( edit ); }
921 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
922 void SetEditInPlace(bool edit = TRUE) { EnableCellEditControl( edit ); }
923
924 void SetCellAlignment( int align, int row, int col)
925 { SetCellAlignment(row, col, align, wxCENTER); }
926 void SetCellAlignment( int WXUNUSED(align) ) {}
927 void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col))
928 { }
929 void SetDividerPen(const wxPen& WXUNUSED(pen)) { }
930 wxPen& GetDividerPen() const { return wxNullPen; }
931 void OnActivate(bool WXUNUSED(active)) {}
932
933 // ******** End of compatibility functions **********
934
935
936
937 // ------ control IDs
938 enum { wxGRID_CELLCTRL = 2000,
939 wxGRID_TOPCTRL };
940
941 // ------ control types
942 enum { wxGRID_TEXTCTRL = 2100,
943 wxGRID_CHECKBOX,
944 wxGRID_CHOICE,
945 wxGRID_COMBOBOX };
946
947
948 DECLARE_DYNAMIC_CLASS( wxGrid )
949 DECLARE_EVENT_TABLE()
950 };
951
952
953
954
955
956 //
957 // ------ Grid event class and event types
958 //
959
960 class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
961 {
962 protected:
963 int m_row;
964 int m_col;
965 int m_x;
966 int m_y;
967 bool m_control;
968 bool m_meta;
969 bool m_shift;
970 bool m_alt;
971
972 public:
973 wxGridEvent()
974 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
975 m_control(0), m_meta(0), m_shift(0), m_alt(0)
976 {
977 }
978
979 wxGridEvent(int id, wxEventType type, wxObject* obj,
980 int row=-1, int col=-1, int x=-1, int y=-1,
981 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
982
983 virtual int GetRow() { return m_row; }
984 virtual int GetCol() { return m_col; }
985 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
986 bool ControlDown() { return m_control; }
987 bool MetaDown() { return m_meta; }
988 bool ShiftDown() { return m_shift; }
989 bool AltDown() { return m_alt; }
990
991 DECLARE_DYNAMIC_CLASS(wxGridEvent)
992 };
993
994
995 class WXDLLEXPORT wxGridSizeEvent : public wxNotifyEvent
996 {
997 protected:
998 int m_rowOrCol;
999 int m_x;
1000 int m_y;
1001 bool m_control;
1002 bool m_meta;
1003 bool m_shift;
1004 bool m_alt;
1005
1006 public:
1007 wxGridSizeEvent()
1008 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1009 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1010 {
1011 }
1012
1013 wxGridSizeEvent(int id, wxEventType type, wxObject* obj,
1014 int rowOrCol=-1, int x=-1, int y=-1,
1015 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1016
1017 int GetRowOrCol() { return m_rowOrCol; }
1018 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
1019 bool ControlDown() { return m_control; }
1020 bool MetaDown() { return m_meta; }
1021 bool ShiftDown() { return m_shift; }
1022 bool AltDown() { return m_alt; }
1023
1024 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent)
1025 };
1026
1027
1028 class WXDLLEXPORT wxGridRangeSelectEvent : public wxNotifyEvent
1029 {
1030 protected:
1031 wxGridCellCoords m_topLeft;
1032 wxGridCellCoords m_bottomRight;
1033 bool m_control;
1034 bool m_meta;
1035 bool m_shift;
1036 bool m_alt;
1037
1038 public:
1039 wxGridRangeSelectEvent()
1040 : wxNotifyEvent()
1041 {
1042 m_topLeft = wxGridNoCellCoords;
1043 m_bottomRight = wxGridNoCellCoords;
1044 m_control = FALSE;
1045 m_meta = FALSE;
1046 m_shift = FALSE;
1047 m_alt = FALSE;
1048 }
1049
1050 wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj,
1051 const wxGridCellCoords& topLeft,
1052 const wxGridCellCoords& bottomRight,
1053 bool control=FALSE, bool shift=FALSE,
1054 bool alt=FALSE, bool meta=FALSE);
1055
1056 wxGridCellCoords GetTopLeftCoords() { return m_topLeft; }
1057 wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; }
1058 int GetTopRow() { return m_topLeft.GetRow(); }
1059 int GetBottomRow() { return m_bottomRight.GetRow(); }
1060 int GetLeftCol() { return m_topLeft.GetCol(); }
1061 int GetRightCol() { return m_bottomRight.GetCol(); }
1062 bool ControlDown() { return m_control; }
1063 bool MetaDown() { return m_meta; }
1064 bool ShiftDown() { return m_shift; }
1065 bool AltDown() { return m_alt; }
1066
1067 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent)
1068 };
1069
1070
1071 const wxEventType EVT_GRID_CELL_LEFT_CLICK = wxEVT_FIRST + 1580;
1072 const wxEventType EVT_GRID_CELL_RIGHT_CLICK = wxEVT_FIRST + 1581;
1073 const wxEventType EVT_GRID_CELL_LEFT_DCLICK = wxEVT_FIRST + 1582;
1074 const wxEventType EVT_GRID_CELL_RIGHT_DCLICK = wxEVT_FIRST + 1583;
1075 const wxEventType EVT_GRID_LABEL_LEFT_CLICK = wxEVT_FIRST + 1584;
1076 const wxEventType EVT_GRID_LABEL_RIGHT_CLICK = wxEVT_FIRST + 1585;
1077 const wxEventType EVT_GRID_LABEL_LEFT_DCLICK = wxEVT_FIRST + 1586;
1078 const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK = wxEVT_FIRST + 1587;
1079 const wxEventType EVT_GRID_ROW_SIZE = wxEVT_FIRST + 1588;
1080 const wxEventType EVT_GRID_COL_SIZE = wxEVT_FIRST + 1589;
1081 const wxEventType EVT_GRID_RANGE_SELECT = wxEVT_FIRST + 1590;
1082 const wxEventType EVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1591;
1083 const wxEventType EVT_GRID_SELECT_CELL = wxEVT_FIRST + 1592;
1084
1085
1086 typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
1087 typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
1088 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
1089
1090 #define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1091 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1092 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1093 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1094 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1095 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1096 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1097 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1098 #define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1099 #define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1100 #define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1101 #define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1102 #define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1103
1104
1105 #if 0 // TODO: implement these ? others ?
1106
1107 const wxEventType EVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576;
1108 const wxEventType EVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577;
1109 const wxEventType EVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578;
1110
1111 #define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1112 #define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1113 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1114
1115 #endif
1116
1117 #endif // #ifndef __WXGRID_H__
1118
1119 #endif // ifndef wxUSE_NEW_GRID