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