]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/grid.h
More life in wxPlot.
[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/string.h"
28 #include "wx/scrolbar.h"
29 #include "wx/event.h"
30 #include "wx/textctrl.h"
31 #include "wx/combobox.h"
32 #include "wx/dynarray.h"
33
34
35 // Default parameters for wxGrid
36 //
37 #define WXGRID_DEFAULT_NUMBER_ROWS 10
38 #define WXGRID_DEFAULT_NUMBER_COLS 10
39 #ifdef __WXMSW__
40 #define WXGRID_DEFAULT_ROW_HEIGHT 25
41 #else
42 #define WXGRID_DEFAULT_ROW_HEIGHT 30
43 #endif // __WXMSW__
44 #define WXGRID_DEFAULT_COL_WIDTH 80
45 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
46 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
47 #define WXGRID_LABEL_EDGE_ZONE 5
48 #define WXGRID_MIN_ROW_HEIGHT 15
49 #define WXGRID_MIN_COL_WIDTH 15
50 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
51 #define WXGRID_DEFAULT_TOPEDIT_WIDTH 300
52 #define WXGRID_DEFAULT_TOPEDIT_HEIGHT 60
53
54
55 class WXDLLEXPORT wxGrid;
56
57
58 //////////////////////////////////////////////////////////////////////
59 //
60 // Grid table classes
61 //
62 //////////////////////////////////////////////////////////////////////
63
64
65 class wxGridTableBase : public wxObject
66 {
67 wxGrid * m_view;
68
69 public:
70 wxGridTableBase();
71 virtual ~wxGridTableBase();
72
73 // You must override these functions in a derived table class
74 //
75 virtual long GetNumberRows() = 0;
76 virtual long GetNumberCols() = 0;
77 virtual wxString GetValue( int row, int col ) = 0;
78 virtual void SetValue( int row, int col, const wxString& s ) = 0;
79 virtual bool IsEmptyCell( int row, int col ) = 0;
80
81 // Overriding these is optional
82 //
83 virtual void SetView( wxGrid *grid ) { m_view = grid; }
84 virtual wxGrid * GetView() const { return m_view; }
85
86 virtual void Clear() {}
87 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
88 virtual bool AppendRows( size_t numRows = 1 );
89 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
90 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
91 virtual bool AppendCols( size_t numCols = 1 );
92 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
93
94 virtual wxString GetRowLabelValue( int row );
95 virtual wxString GetColLabelValue( int col );
96 virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {}
97 virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {}
98
99 DECLARE_ABSTRACT_CLASS( wxGridTableBase );
100 };
101
102
103
104 // IDs for messages sent from grid table to view
105 //
106 enum wxGridTableRequest {
107 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
108 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
109 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
110 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
111 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
112 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
113 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
114 wxGRIDTABLE_NOTIFY_COLS_DELETED
115 };
116
117 class wxGridTableMessage
118 {
119 wxGridTableBase *m_table;
120 int m_id;
121 int m_comInt1;
122 int m_comInt2;
123
124 public:
125 wxGridTableMessage();
126 wxGridTableMessage( wxGridTableBase *table, int id,
127 int comInt1 = -1,
128 int comInt2 = -1 );
129
130 void SetTableObject( wxGridTableBase *table ) { m_table = table; }
131 wxGridTableBase * GetTableObject() const { return m_table; }
132 void SetId( int id ) { m_id = id; }
133 int GetId() { return m_id; }
134 void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; }
135 int GetCommandInt() { return m_comInt1; }
136 void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; }
137 int GetCommandInt2() { return m_comInt2; }
138 };
139
140
141
142 // ------ wxGridStringArray
143 // A 2-dimensional array of strings for data values
144 //
145
146 WX_DECLARE_OBJARRAY(wxArrayString, wxGridStringArray);
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 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 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
254 // This set of classes is to provide for the use of different types of
255 // cell edit controls in the grid while avoiding the wx class info
256 // system in deference to wxPython
257
258 class wxGridTextCtrl : public wxTextCtrl
259 {
260 // TRUE for controls placed over cells,
261 // FALSE for a control on a grid control panel
262 bool m_isCellControl;
263
264 wxString startValue;
265
266 void OnKeyDown( wxKeyEvent& );
267
268 public:
269 wxGridTextCtrl() {}
270 wxGridTextCtrl( wxWindow *,
271 bool isCellControl,
272 wxWindowID id,
273 const wxString& value = wxEmptyString,
274 const wxPoint& pos = wxDefaultPosition,
275 const wxSize& size = wxDefaultSize,
276 long style = 0 );
277
278 void SetStartValue( const wxString& );
279 wxString GetStartValue() { return startValue; }
280
281 DECLARE_DYNAMIC_CLASS( wxGridTextCtrl )
282 DECLARE_EVENT_TABLE()
283 };
284
285
286 class WXDLLEXPORT wxGrid : public wxPanel
287 {
288 DECLARE_DYNAMIC_CLASS( wxGrid )
289
290 protected:
291 bool m_created;
292
293 wxGridTableBase *m_table;
294
295 int m_left;
296 int m_top;
297 int m_right;
298 int m_bottom;
299
300 int m_numRows;
301 int m_numCols;
302
303 wxGridCellCoords m_currentCellCoords;
304 bool m_currentCellHighlighted;
305
306 wxGridCellCoords m_selectedTopLeft;
307 wxGridCellCoords m_selectedBottomRight;
308
309 int m_defaultRowHeight;
310 wxArrayInt m_rowHeights;
311 wxArrayInt m_rowBottoms;
312 int m_sumRowHeights;
313
314 int m_defaultColWidth;
315 wxArrayInt m_colWidths;
316 wxArrayInt m_colRights;
317 int m_sumColWidths;
318
319 int m_rowLabelWidth;
320 int m_colLabelHeight;
321
322 wxColour m_labelBackgroundColour;
323 wxColour m_labelTextColour;
324 wxFont m_labelFont;
325
326 int m_rowLabelHorizAlign;
327 int m_rowLabelVertAlign;
328 int m_colLabelHorizAlign;
329 int m_colLabelVertAlign;
330
331 bool m_defaultRowLabelValues;
332 bool m_defaultColLabelValues;
333
334 wxColour m_gridLineColour;
335 bool m_gridLinesEnabled;
336
337 wxFont m_defaultCellFont;
338
339 wxScrollBar * m_horizScrollBar;
340 wxScrollBar * m_vertScrollBar;
341 int m_scrollBarWidth;
342 int m_scrollPosX;
343 int m_scrollPosY;
344 int m_wholeColsVisible;
345 int m_wholeRowsVisible;
346
347 bool m_inOnKeyDown;
348 bool m_inOnText;
349 bool m_firstPaint;
350 int m_batchCount;
351
352 int m_cursorMode;
353 enum { WXGRID_CURSOR_DEFAULT,
354 WXGRID_CURSOR_SELECT_CELL,
355 WXGRID_CURSOR_RESIZE_ROW,
356 WXGRID_CURSOR_RESIZE_COL,
357 WXGRID_CURSOR_SELECT_ROW,
358 WXGRID_CURSOR_SELECT_COL
359 };
360
361 int m_dragLastPos;
362 int m_dragRowOrCol;
363 bool m_isDragging;
364
365 wxGridCellCoords m_selectionStart;
366
367 wxCursor m_rowResizeCursor;
368 wxCursor m_colResizeCursor;
369
370 bool m_editable; // applies to whole grid
371 int m_editCtrlType; // for current cell
372 wxWindow* m_cellEditCtrl;
373 bool m_cellEditCtrlEnabled;
374 wxWindow* m_topEditCtrl;
375 bool m_topEditCtrlEnabled;
376
377 // ------ internal init and update functions
378 //
379 void Create();
380 void Init();
381 void CalcDimensions();
382 bool IsOnScreen();
383 bool Redimension( wxGridTableMessage& );
384
385 // ------ event processing
386 //
387 bool SendEvent( const wxEventType,
388 int row, int col,
389 wxMouseEvent& );
390
391 bool SendEvent( const wxEventType,
392 int row, int col );
393
394 void OnPaint( wxPaintEvent& );
395 void OnSize( wxSizeEvent& );
396 void OnMouse( wxMouseEvent& );
397 void OnKeyDown( wxKeyEvent& );
398 void OnText( wxCommandEvent& );
399 void OnGridScroll( wxScrollEvent& );
400
401 void SelectCell( const wxGridCellCoords& coords );
402 void SelectCell( int row, int col )
403 { SelectCell( wxGridCellCoords(row, col) ); }
404
405
406 // ------ edit controls
407 //
408 void ShowCellEditControl();
409 void HideCellEditControl();
410 void SaveEditControlValue();
411
412
413 // ------ grid location functions
414 //
415 int XYToArea( int x, int y ); // returns one of the following...
416 enum { WXGRID_NOAREA,
417 WXGRID_ROWLABEL,
418 WXGRID_ROWLABEL_EDGE,
419 WXGRID_COLLABEL,
420 WXGRID_COLLABEL_EDGE,
421 WXGRID_CORNERLABEL,
422 WXGRID_CELL };
423
424 void XYToCell( int x, int y, wxGridCellCoords& );
425 int YToRow( int y );
426 int XToCol( int x );
427
428 int YToEdgeOfRow( int y );
429 int XToEdgeOfCol( int x );
430
431 wxRect CellToRect( int row, int col );
432 wxRect CellToRect( const wxGridCellCoords& coords )
433 { return CellToRect( coords.GetRow(), coords.GetCol() ); }
434
435 bool MoveCursorUp();
436 bool MoveCursorDown();
437 bool MoveCursorLeft();
438 bool MoveCursorRight();
439 bool MovePageDown();
440 bool MovePageUp();
441 bool MoveCursorUpBlock();
442 bool MoveCursorDownBlock();
443 bool MoveCursorLeftBlock();
444 bool MoveCursorRightBlock();
445
446
447 // ------ label drawing functions
448 //
449 void DrawLabelAreas( wxDC& dc );
450 void DrawColLabelBorders( wxDC& dc );
451 void DrawColLabels( wxDC& dc );
452 void DrawColLabel( wxDC& dc, const wxRect&, int col );
453 void DrawRowLabelBorders( wxDC& dc );
454 void DrawRowLabels( wxDC& dc );
455 void DrawRowLabel( wxDC& dc, const wxRect&, int col );
456
457
458 // ------ cell drawing functions
459 //
460 void DrawCellArea( wxDC& dc );
461 void DrawGridLines( wxDC& dc );
462 void DrawCells( wxDC& dc );
463 void DrawCellBackground( wxDC& dc, const wxRect&, int row, int col );
464 void DrawCellValue( wxDC& dc, const wxRect&, int row, int col,
465 const wxString& value = wxEmptyString, bool useValueArg = FALSE );
466
467 // this updates the displayed cell text value but not the underlying
468 // table cell value (it is used to echo text being entered into
469 // the top edit control when in-place editing is turned off)
470 //
471 void DrawCellValue( const wxGridCellCoords& coords, const wxString& value );
472
473 // these are useful when you just need to draw one or a few
474 // cells
475 void DrawCell( int row, int col );
476 void DrawCell( const wxGridCellCoords& coords )
477 { DrawCell( coords.GetRow(), coords.GetCol() ); }
478
479 void DrawCellHighlight( wxDC& dc, int row, int col );
480 void DrawCellHighlight( wxDC& dc, wxGridCellCoords& coords )
481 { DrawCellHighlight( dc, coords.GetRow(), coords.GetCol() ); }
482 void ShowCurrentCellHighlight( wxDC& dc );
483 void HideCurrentCellHighlight( wxDC& dc );
484
485
486 // ------ generic drawing functions
487 //
488 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
489 int horizontalAlignment = wxLEFT,
490 int verticalAlignment = wxTOP );
491
492 // Split a string containing newline chararcters into an array of
493 // strings and return the number of lines
494 //
495 void StringToLines( const wxString& value, wxArrayString& lines );
496
497 void GetTextBoxSize( wxDC& dc,
498 wxArrayString& lines,
499 long *width, long *height );
500
501
502 // ------ functions to get/send data (see also public functions)
503 //
504 bool GetModelValues();
505 bool SetModelValues();
506
507
508 ////////////////////// Public section ////////////////////
509
510 public:
511 wxGrid()
512 { Create(); }
513
514 wxGrid( wxWindow *parent,
515 wxWindowID id,
516 const wxPoint& pos = wxDefaultPosition,
517 const wxSize& size = wxDefaultSize,
518 long style = 0,
519 const wxString& name = wxPanelNameStr )
520 : wxPanel( parent, id, pos, size, style, name )
521 {
522 Create();
523 }
524
525 ~wxGrid();
526
527 bool CreateGrid( int numRows = WXGRID_DEFAULT_NUMBER_ROWS,
528 int numCols = WXGRID_DEFAULT_NUMBER_COLS );
529
530 wxGridTableBase * GetTable() const { return m_table; }
531 void SetTable( wxGridTableBase *table ) { m_table = table; }
532
533 void ClearGrid();
534 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
535 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
536 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
537 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
538 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
539 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
540
541 // ------ editing and edit controls
542 //
543 bool IsEditable() { return m_editable; }
544 void EnableEditing( bool edit );
545
546 void EnableTopEditControl( bool enable );
547 bool IsTopEditControlEnabled()
548 { return (m_topEditCtrl && m_topEditCtrlEnabled); }
549 void EnableCellEditControl( bool enable );
550 bool IsCellEditControlEnabled()
551 { return (m_cellEditCtrl && m_cellEditCtrlEnabled); }
552 void SetEditControlValue( const wxString& s = wxEmptyString );
553
554
555 // ------ grid dimensions
556 //
557 int GetNumberRows() { return m_numRows; }
558 int GetNumberCols() { return m_numCols; }
559 int GetNumberVisibleRows() { return m_wholeRowsVisible; }
560 int GetNumberVisibleCols() { return m_wholeColsVisible; }
561
562
563 // ------
564 // Code that does a lot of grid modification can be enclosed
565 // between BeginBatch() and EndBatch() calls to avoid screen
566 // flicker
567 //
568 void BeginBatch() { m_batchCount++; }
569 void EndBatch() { if ( m_batchCount > 0 ) m_batchCount--; }
570 int GetBatchCount() { return m_batchCount; }
571
572
573 // ------ label and gridline formatting
574 //
575 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; }
576 int GetRowLabelSize() { return m_rowLabelWidth; }
577 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; }
578 int GetColLabelSize() { return m_colLabelHeight; }
579 wxColour GetLabelBackgroundColour() { return m_labelBackgroundColour; }
580 wxColour GetLabelTextColour() { return m_labelTextColour; }
581 wxFont GetLabelFont() { return m_labelFont; }
582 void GetRowLabelAlignment( int *horiz, int *vert );
583 void GetColLabelAlignment( int *horiz, int *vert );
584 wxString GetRowLabelValue( int row );
585 wxString GetColLabelValue( int col );
586 wxColour GetGridLineColour() { return m_gridLineColour; }
587
588 void SetRowLabelSize( int width );
589 void SetColLabelSize( int height );
590 void SetLabelBackgroundColour( const wxColour& );
591 void SetLabelTextColour( const wxColour& );
592 void SetLabelFont( const wxFont& );
593 void SetRowLabelAlignment( int horiz, int vert );
594 void SetColLabelAlignment( int horiz, int vert );
595 void SetRowLabelValue( int row, const wxString& );
596 void SetColLabelValue( int col, const wxString& );
597 void SetGridLineColour( const wxColour& );
598
599 void EnableGridLines( bool enable = TRUE );
600 bool GridLinesEnabled() { return m_gridLinesEnabled; }
601
602
603 // ------ row and col formatting
604 //
605 int GetDefaultRowSize();
606 int GetRowSize( int row );
607 int GetDefaultColSize();
608 int GetColSize( int col );
609 wxColour GetDefaultCellBackgroundColour();
610 wxColour GetCellBackgroundColour( int row, int col );
611 wxColour GetDefaultCellTextColour();
612 wxColour GetCellTextColour( int row, int col );
613 wxColour GetCellHighlightColour();
614 wxFont GetDefaultCellFont();
615 wxFont GetCellFont( int row, int col );
616 void GetDefaultCellAlignment( int *horiz, int *vert );
617 void GetCellAlignment( int row, int col, int *horiz, int *vert );
618
619 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
620 void SetRowSize( int row, int height );
621 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
622 void SetColSize( int col, int width );
623 void SetDefaultCellBackgroundColour( const wxColour& );
624 void SetCellBackgroundColour( int row, int col, const wxColour& );
625 void SetDefaultCellTextColour( const wxColour& );
626 void SetCellTextColour( int row, int col, const wxColour& );
627 void SetCellHighlightColour( const wxColour& );
628 void SetDefaultCellFont( const wxFont& );
629 void SetCellFont( int row, int col, const wxFont& );
630 void SetDefaultCellAlignment( int horiz, int vert );
631 void SetCellAlignment( int row, int col, int horiz, int vert );
632
633
634 // ------ cell value accessors
635 //
636 wxString GetCellValue( int row, int col )
637 {
638 if ( m_table )
639 {
640 return m_table->GetValue( row, col );
641 }
642 else
643 {
644 return wxEmptyString;
645 }
646 }
647
648 wxString GetCellValue( const wxGridCellCoords& coords )
649 { return GetCellValue( coords.GetRow(), coords.GetCol() ); }
650
651 void SetCellValue( int row, int col, const wxString& s );
652 void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
653 { SetCellValue( coords.GetRow(), coords.GetCol(), s ); }
654
655
656 // ------ interaction with data model
657 //
658 bool ProcessTableMessage( wxGridTableMessage& );
659
660
661
662 // ------ grid location functions
663 //
664
665 int GetGridCursorRow() { return m_currentCellCoords.GetRow(); }
666 int GetGridCursorCol() { return m_currentCellCoords.GetCol(); }
667 int GetHorizontalScrollPos() { return m_scrollPosX; }
668 int GetVerticalScrollPos() { return m_scrollPosY; }
669
670 bool IsVisible( const wxGridCellCoords& );
671 void MakeCellVisible( int row, int col );
672 void MakeCellVisible( const wxGridCellCoords& coords )
673 { MakeCellVisible( coords.GetRow(), coords.GetCol() ); }
674
675 void SetGridCursor( int row, int col )
676 { SelectCell( wxGridCellCoords(row, col) ); }
677
678 void SetHorizontalScrollPos( int leftMostCol );
679 void SetVerticalScrollPos( int topMostRow );
680
681
682 // ------ selections of blocks of cells
683 //
684 void SelectRow( int row, bool addToSelected = FALSE );
685 void SelectCol( int col, bool addToSelected = FALSE );
686
687 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol );
688
689 void SelectBlock( const wxGridCellCoords& topLeft,
690 const wxGridCellCoords& bottomRight )
691 { SelectBlock( topLeft.GetRow(), topLeft.GetCol(),
692 bottomRight.GetRow(), bottomRight.GetCol() ); }
693
694 void SelectAll();
695
696 bool IsSelection()
697 { return ( m_selectedTopLeft != wxGridNoCellCoords &&
698 m_selectedBottomRight != wxGridNoCellCoords );
699 }
700
701 void ClearSelection();
702
703 bool IsInSelection( int row, int col )
704 { return ( IsSelection() &&
705 row >= m_selectedTopLeft.GetRow() &&
706 col >= m_selectedTopLeft.GetCol() &&
707 row <= m_selectedBottomRight.GetRow() &&
708 col <= m_selectedBottomRight.GetCol() );
709 }
710
711 bool IsInSelection( const wxGridCellCoords& coords )
712 { return IsInSelection( coords.GetRow(), coords.GetCol() ); }
713
714 void GetSelection( int* topRow, int* leftCol, int* bottomRow, int* rightCol )
715 {
716 // these will all be -1 if there is no selected block
717 //
718 *topRow = m_selectedTopLeft.GetRow();
719 *leftCol = m_selectedTopLeft.GetCol();
720 *bottomRow = m_selectedBottomRight.GetRow();
721 *rightCol = m_selectedBottomRight.GetCol();
722 }
723
724 // get coordinates of selected block edges for repainting etc.
725 //
726 wxRect SelectionToRect();
727
728
729 // ------ For compatibility with previous wxGrid only...
730 //
731 // ************************************************
732 // ** Don't use these in new code because they **
733 // ** are liable to disappear in a future **
734 // ** revision **
735 // ************************************************
736 //
737
738 wxGrid( wxWindow *parent,
739 int x = -1, int y = -1, int w = -1, int h = -1,
740 long style = 0,
741 const wxString& name = wxPanelNameStr )
742 : wxPanel( parent, -1, wxPoint(x,y), wxSize(w,h), style, name )
743 {
744 Create();
745 }
746
747 void SetCellValue( const wxString& val, int row, int col )
748 { SetCellValue( row, col, val ); }
749
750 void AdjustScrollbars()
751 { CalcDimensions(); }
752
753 void UpdateDimensions()
754 { CalcDimensions(); }
755
756 int GetRows() { return GetNumberRows(); }
757 int GetCols() { return GetNumberCols(); }
758 int GetCursorRow() { return GetGridCursorRow(); }
759 int GetCursorColumn() { return GetGridCursorCol(); }
760 int GetScrollPosX() { return GetHorizontalScrollPos(); }
761 int GetScrollPosY() { return GetVerticalScrollPos(); }
762
763 void SetScrollX( int x ) { SetHorizontalScrollPos( x ); }
764 void SetScrollY( int y ) { SetVerticalScrollPos( y ); }
765
766 void SetColumnWidth( int col, int width )
767 { SetColSize( col, width ); }
768
769 int GetColumnWidth( int col )
770 { return GetColSize( col ); }
771
772 void SetRowHeight( int row, int height )
773 { SetRowSize( row, height ); }
774
775 int GetRowHeight( int row )
776 { return GetRowSize( row ); }
777
778 int GetViewHeight()
779 { return m_wholeRowsVisible; }
780
781 int GetViewWidth()
782 { return m_wholeColsVisible; }
783
784 void SetLabelSize( int orientation, int sz )
785 {
786 if ( orientation == wxHORIZONTAL )
787 SetColLabelSize( sz );
788 else
789 SetRowLabelSize( sz );
790 }
791
792 int GetLabelSize( int orientation )
793 {
794 if ( orientation == wxHORIZONTAL )
795 return GetColLabelSize();
796 else
797 return GetRowLabelSize();
798 }
799
800 void SetLabelAlignment( int orientation, int align )
801 {
802 if ( orientation == wxHORIZONTAL )
803 SetColLabelAlignment( align, -1 );
804 else
805 SetRowLabelAlignment( align, -1 );
806 }
807
808 int GetLabelAlignment( int orientation, int WXUNUSED(align) )
809 {
810 int h, v;
811 if ( orientation == wxHORIZONTAL )
812 {
813 GetColLabelAlignment( &h, &v );
814 return h;
815 }
816 else
817 {
818 GetRowLabelAlignment( &h, &v );
819 return h;
820 }
821 }
822
823 void SetLabelValue( int orientation, const wxString& val, int pos )
824 {
825 if ( orientation == wxHORIZONTAL )
826 SetColLabelValue( pos, val );
827 else
828 SetRowLabelValue( pos, val );
829 }
830
831 wxString GetLabelValue( int orientation, int pos)
832 {
833 if ( orientation == wxHORIZONTAL )
834 return GetColLabelValue( pos );
835 else
836 return GetRowLabelValue( pos );
837 }
838
839 wxFont GetCellTextFont() const
840 { return m_defaultCellFont; }
841
842 wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const
843 { return m_defaultCellFont; }
844
845 void SetCellTextFont(const wxFont& fnt)
846 { SetDefaultCellFont( fnt ); }
847
848 void SetCellTextFont(const wxFont& fnt, int row, int col)
849 { SetCellFont( row, col, fnt ); }
850
851 void SetCellTextColour(const wxColour& val, int row, int col)
852 { SetCellTextColour( row, col, val ); }
853
854 void SetCellTextColour(const wxColour& col)
855 { SetDefaultCellTextColour( col ); }
856
857 void SetCellBackgroundColour(const wxColour& col)
858 { SetDefaultCellBackgroundColour( col ); }
859
860 void SetCellBackgroundColour(const wxColour& colour, int row, int col)
861 { SetCellBackgroundColour( row, col, colour ); }
862
863 bool GetEditable() { return IsEditable(); }
864 void SetEditable( bool edit = TRUE ) { EnableEditing( edit ); }
865 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
866 void SetEditInPlace(bool edit = TRUE) { EnableCellEditControl( edit ); }
867
868 void SetCellAlignment( int align, int row, int col)
869 { SetCellAlignment(row, col, align, wxCENTER); }
870 void SetCellAlignment( int WXUNUSED(align) ) {}
871 void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col))
872 { }
873 void SetDividerPen(const wxPen& WXUNUSED(pen)) { }
874 wxPen& GetDividerPen() const { return wxNullPen; }
875 void OnActivate(bool WXUNUSED(active)) {}
876
877 // ******** End of compatibility functions **********
878
879
880 // ------ control IDs
881 enum { wxGRID_HORIZSCROLL = 2000,
882 wxGRID_VERTSCROLL,
883 wxGRID_CELLCTRL,
884 wxGRID_TOPCTRL };
885
886 // ------ control types
887 enum { wxGRID_TEXTCTRL = 100,
888 wxGRID_CHECKBOX,
889 wxGRID_CHOICE,
890 wxGRID_COMBOBOX };
891
892
893 DECLARE_EVENT_TABLE()
894 };
895
896
897
898
899
900 //
901 // ------ Grid event class and event types
902 //
903
904 class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
905 {
906 DECLARE_DYNAMIC_CLASS(wxGridEvent)
907
908 protected:
909 int m_row;
910 int m_col;
911 int m_x;
912 int m_y;
913 bool m_control;
914 bool m_meta;
915 bool m_shift;
916 bool m_alt;
917
918 public:
919 wxGridEvent()
920 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
921 m_control(0), m_meta(0), m_shift(0), m_alt(0)
922 {
923 }
924
925 wxGridEvent(int id, wxEventType type, wxObject* obj,
926 int row=-1, int col=-1, int x=-1, int y=-1,
927 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
928
929 virtual int GetRow() { return m_row; }
930 virtual int GetCol() { return m_col; }
931 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
932 bool ControlDown() { return m_control; }
933 bool MetaDown() { return m_meta; }
934 bool ShiftDown() { return m_shift; }
935 bool AltDown() { return m_alt; }
936 };
937
938
939 class WXDLLEXPORT wxGridSizeEvent : public wxNotifyEvent
940 {
941 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent)
942
943 protected:
944 int m_rowOrCol;
945 int m_x;
946 int m_y;
947 bool m_control;
948 bool m_meta;
949 bool m_shift;
950 bool m_alt;
951
952 public:
953 wxGridSizeEvent()
954 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
955 m_control(0), m_meta(0), m_shift(0), m_alt(0)
956 {
957 }
958
959 wxGridSizeEvent(int id, wxEventType type, wxObject* obj,
960 int rowOrCol=-1, int x=-1, int y=-1,
961 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
962
963 int GetRowOrCol() { return m_rowOrCol; }
964 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
965 bool ControlDown() { return m_control; }
966 bool MetaDown() { return m_meta; }
967 bool ShiftDown() { return m_shift; }
968 bool AltDown() { return m_alt; }
969 };
970
971
972 class WXDLLEXPORT wxGridRangeSelectEvent : public wxNotifyEvent
973 {
974 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent)
975
976 protected:
977 wxGridCellCoords m_topLeft;
978 wxGridCellCoords m_bottomRight;
979 bool m_control;
980 bool m_meta;
981 bool m_shift;
982 bool m_alt;
983
984 public:
985 wxGridRangeSelectEvent()
986 : wxNotifyEvent()
987 {
988 m_topLeft = wxGridNoCellCoords;
989 m_bottomRight = wxGridNoCellCoords;
990 m_control = FALSE;
991 m_meta = FALSE;
992 m_shift = FALSE;
993 m_alt = FALSE;
994 }
995
996 wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj,
997 const wxGridCellCoords& topLeft,
998 const wxGridCellCoords& bottomRight,
999 bool control=FALSE, bool shift=FALSE,
1000 bool alt=FALSE, bool meta=FALSE);
1001
1002 wxGridCellCoords GetTopLeftCoords() { return m_topLeft; }
1003 wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; }
1004 int GetTopRow() { return m_topLeft.GetRow(); }
1005 int GetBottomRow() { return m_bottomRight.GetRow(); }
1006 int GetLeftCol() { return m_topLeft.GetCol(); }
1007 int GetRightCol() { return m_bottomRight.GetCol(); }
1008 bool ControlDown() { return m_control; }
1009 bool MetaDown() { return m_meta; }
1010 bool ShiftDown() { return m_shift; }
1011 bool AltDown() { return m_alt; }
1012 };
1013
1014
1015 const wxEventType EVT_GRID_CELL_LEFT_CLICK = wxEVT_FIRST + 1580;
1016 const wxEventType EVT_GRID_CELL_RIGHT_CLICK = wxEVT_FIRST + 1581;
1017 const wxEventType EVT_GRID_CELL_LEFT_DCLICK = wxEVT_FIRST + 1582;
1018 const wxEventType EVT_GRID_CELL_RIGHT_DCLICK = wxEVT_FIRST + 1583;
1019 const wxEventType EVT_GRID_LABEL_LEFT_CLICK = wxEVT_FIRST + 1584;
1020 const wxEventType EVT_GRID_LABEL_RIGHT_CLICK = wxEVT_FIRST + 1585;
1021 const wxEventType EVT_GRID_LABEL_LEFT_DCLICK = wxEVT_FIRST + 1586;
1022 const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK = wxEVT_FIRST + 1587;
1023 const wxEventType EVT_GRID_ROW_SIZE = wxEVT_FIRST + 1588;
1024 const wxEventType EVT_GRID_COL_SIZE = wxEVT_FIRST + 1589;
1025 const wxEventType EVT_GRID_RANGE_SELECT = wxEVT_FIRST + 1590;
1026 const wxEventType EVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1591;
1027 const wxEventType EVT_GRID_SELECT_CELL = wxEVT_FIRST + 1592;
1028
1029
1030 typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
1031 typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
1032 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
1033
1034 #define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1035 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1036 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1037 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1038 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1039 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1040 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1041 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1042 #define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1043 #define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1044 #define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1045 #define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1046 #define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1047
1048
1049 #if 0 // TODO: implement these ? others ?
1050
1051 const wxEventType EVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576;
1052 const wxEventType EVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577;
1053 const wxEventType EVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578;
1054
1055 #define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1056 #define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1057 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1058
1059 #endif
1060
1061 #endif // #ifndef __WXGRID_H__
1062
1063 #endif // ifndef wxUSE_NEW_GRID