]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/grid.h
Removed cell highlighting temporarily. Now wxGrid::EnableEditing(bool)
[wxWidgets.git] / include / wx / generic / grid.h
CommitLineData
f85afd4e
MB
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"
2d66e025 27#include "wx/scrolwin.h"
f85afd4e
MB
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
f85afd4e
MB
52
53
6f4968e2 54class WXDLLEXPORT wxGrid;
f85afd4e
MB
55
56
57//////////////////////////////////////////////////////////////////////
58//
59// Grid table classes
60//
61//////////////////////////////////////////////////////////////////////
62
63
2d66e025 64class WXDLLEXPORT wxGridTableBase : public wxObject
f85afd4e
MB
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 );
af111fc3
JS
95 virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {}
96 virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {}
f85afd4e
MB
97
98 DECLARE_ABSTRACT_CLASS( wxGridTableBase );
99};
100
101
102
103// IDs for messages sent from grid table to view
104//
105enum 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
2d66e025 116class WXDLLEXPORT wxGridTableMessage
f85afd4e
MB
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
2d66e025
MB
145WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString, wxGridStringArray);
146
f85afd4e
MB
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
2d66e025 155class WXDLLEXPORT wxGridStringTable : public wxGridTableBase
f85afd4e
MB
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
f85afd4e
MB
198//////////////////////////////////////////////////////////////////////
199//
200// Grid view classes
201//
202//////////////////////////////////////////////////////////////////////
203
2d66e025 204class WXDLLEXPORT wxGridCellCoords
f85afd4e
MB
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//
250extern wxGridCellCoords wxGridNoCellCoords;
251extern wxRect wxGridNoCellRect;
252
2d66e025
MB
253// An array of cell coords...
254//
255WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords, wxGridCellCoordsArray);
256
257
f85afd4e
MB
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
2d66e025 263class WXDLLEXPORT wxGridTextCtrl : public wxTextCtrl
f85afd4e 264{
2d66e025
MB
265 wxGrid *m_grid;
266
f85afd4e
MB
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 *,
2d66e025 278 wxGrid *,
f85afd4e
MB
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
2d66e025 294class WXDLLEXPORT wxGridRowLabelWindow : public wxWindow
f85afd4e 295{
2d66e025
MB
296 wxGrid *m_owner;
297
298 void OnPaint( wxPaintEvent& event );
299 void OnMouseEvent( wxMouseEvent& event );
300 void OnKeyDown( wxKeyEvent& event );
301
302public:
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
312class 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
320public:
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
330class 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
348class 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
358public:
359 wxGridWindow() {}
360 wxGridWindow( wxGrid *parent,
361 wxGridRowLabelWindow *rowLblWin,
362 wxGridColLabelWindow *colLblWin,
363 wxWindowID id, const wxPoint &pos, const wxSize &size );
364 ~wxGridWindow();
f85afd4e 365
2d66e025
MB
366 void ScrollWindow( int dx, int dy, const wxRect *rect );
367
368 DECLARE_DYNAMIC_CLASS(wxGridWindow)
369 DECLARE_EVENT_TABLE()
370};
371
372
373
374class WXDLLEXPORT wxGrid : public wxScrolledWindow
375{
52068ea5 376 protected:
f85afd4e
MB
377 bool m_created;
378
2d66e025
MB
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;
f85afd4e
MB
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;
f85afd4e
MB
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
2d66e025
MB
431 wxGridCellCoordsArray m_cellsExposed;
432 wxArrayInt m_rowsExposed;
433 wxArrayInt m_colsExposed;
434 wxArrayInt m_rowLabelsExposed;
435 wxArrayInt m_colLabelsExposed;
f85afd4e
MB
436
437 bool m_inOnKeyDown;
f85afd4e
MB
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;
2d66e025 457
f85afd4e
MB
458 bool m_editable; // applies to whole grid
459 int m_editCtrlType; // for current cell
460 wxWindow* m_cellEditCtrl;
461 bool m_cellEditCtrlEnabled;
f85afd4e 462
2d66e025
MB
463
464 void Create();
f85afd4e
MB
465 void Init();
466 void CalcDimensions();
f85afd4e 467 bool Redimension( wxGridTableMessage& );
2d66e025 468
f85afd4e 469
f85afd4e
MB
470 bool SendEvent( const wxEventType,
471 int row, int col,
472 wxMouseEvent& );
473
474 bool SendEvent( const wxEventType,
475 int row, int col );
476
2d66e025 477
f85afd4e
MB
478 void OnPaint( wxPaintEvent& );
479 void OnSize( wxSizeEvent& );
f85afd4e 480 void OnKeyDown( wxKeyEvent& );
f85afd4e 481
f85afd4e 482
2d66e025
MB
483 void SetCurrentCell( const wxGridCellCoords& coords );
484 void SetCurrentCell( int row, int col )
485 { SetCurrentCell( wxGridCellCoords(row, col) ); }
f85afd4e 486
f85afd4e 487
f85afd4e
MB
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,
2d66e025
MB
505 const wxString& name = wxPanelNameStr );
506
f85afd4e
MB
507 ~wxGrid();
508
2d66e025
MB
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& );
f85afd4e 532
2d66e025 533
f85afd4e
MB
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
2d66e025
MB
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& );
1f1ce288 551
2d66e025
MB
552 void DrawRowLabels( wxDC& dc );
553 void DrawRowLabel( wxDC& dc, int row );
554 void DrawColLabels( wxDC& dc );
555 void DrawColLabel( wxDC& dc, int col );
f85afd4e
MB
556
557
2d66e025 558 // ------ Cell text drawing functions
f85afd4e 559 //
2d66e025
MB
560 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
561 int horizontalAlignment = wxLEFT,
562 int verticalAlignment = wxTOP );
f85afd4e 563
2d66e025
MB
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 );
f85afd4e 568
2d66e025
MB
569 void GetTextBoxSize( wxDC& dc,
570 wxArrayString& lines,
571 long *width, long *height );
572
573
f85afd4e
MB
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
2d66e025
MB
583
584 // ------ edit control functions
585 //
586 bool IsEditable() { return m_editable; }
587 void EnableEditing( bool edit );
588
1f1ce288 589#if 0 // at the moment the cell edit control is always active
2d66e025 590 void EnableCellEditControl( bool enable );
1f1ce288 591#endif
2d66e025
MB
592
593 bool IsCellEditControlEnabled()
594 { return (m_cellEditCtrl && m_cellEditCtrlEnabled); }
595
2d66e025
MB
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 bool MoveCursorUp();
635 bool MoveCursorDown();
636 bool MoveCursorLeft();
637 bool MoveCursorRight();
638 bool MovePageDown();
639 bool MovePageUp();
640 bool MoveCursorUpBlock();
641 bool MoveCursorDownBlock();
642 bool MoveCursorLeftBlock();
643 bool MoveCursorRightBlock();
644
f85afd4e
MB
645
646 // ------ label and gridline formatting
647 //
648 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; }
649 int GetRowLabelSize() { return m_rowLabelWidth; }
650 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; }
651 int GetColLabelSize() { return m_colLabelHeight; }
652 wxColour GetLabelBackgroundColour() { return m_labelBackgroundColour; }
653 wxColour GetLabelTextColour() { return m_labelTextColour; }
654 wxFont GetLabelFont() { return m_labelFont; }
655 void GetRowLabelAlignment( int *horiz, int *vert );
656 void GetColLabelAlignment( int *horiz, int *vert );
657 wxString GetRowLabelValue( int row );
658 wxString GetColLabelValue( int col );
659 wxColour GetGridLineColour() { return m_gridLineColour; }
660
2d66e025 661 void SetRowLabelSize( int width );
f85afd4e
MB
662 void SetColLabelSize( int height );
663 void SetLabelBackgroundColour( const wxColour& );
664 void SetLabelTextColour( const wxColour& );
665 void SetLabelFont( const wxFont& );
666 void SetRowLabelAlignment( int horiz, int vert );
667 void SetColLabelAlignment( int horiz, int vert );
668 void SetRowLabelValue( int row, const wxString& );
669 void SetColLabelValue( int col, const wxString& );
670 void SetGridLineColour( const wxColour& );
671
672 void EnableGridLines( bool enable = TRUE );
673 bool GridLinesEnabled() { return m_gridLinesEnabled; }
674
2d66e025 675
f85afd4e
MB
676 // ------ row and col formatting
677 //
678 int GetDefaultRowSize();
679 int GetRowSize( int row );
680 int GetDefaultColSize();
681 int GetColSize( int col );
682 wxColour GetDefaultCellBackgroundColour();
683 wxColour GetCellBackgroundColour( int row, int col );
684 wxColour GetDefaultCellTextColour();
685 wxColour GetCellTextColour( int row, int col );
f85afd4e
MB
686 wxFont GetDefaultCellFont();
687 wxFont GetCellFont( int row, int col );
688 void GetDefaultCellAlignment( int *horiz, int *vert );
689 void GetCellAlignment( int row, int col, int *horiz, int *vert );
690
691 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
692 void SetRowSize( int row, int height );
693 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
694 void SetColSize( int col, int width );
695 void SetDefaultCellBackgroundColour( const wxColour& );
696 void SetCellBackgroundColour( int row, int col, const wxColour& );
697 void SetDefaultCellTextColour( const wxColour& );
698 void SetCellTextColour( int row, int col, const wxColour& );
f85afd4e
MB
699 void SetDefaultCellFont( const wxFont& );
700 void SetCellFont( int row, int col, const wxFont& );
701 void SetDefaultCellAlignment( int horiz, int vert );
702 void SetCellAlignment( int row, int col, int horiz, int vert );
703
60a67569 704
f85afd4e
MB
705 // ------ cell value accessors
706 //
707 wxString GetCellValue( int row, int col )
708 {
709 if ( m_table )
710 {
711 return m_table->GetValue( row, col );
712 }
713 else
714 {
715 return wxEmptyString;
716 }
717 }
718
719 wxString GetCellValue( const wxGridCellCoords& coords )
720 { return GetCellValue( coords.GetRow(), coords.GetCol() ); }
721
722 void SetCellValue( int row, int col, const wxString& s );
723 void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
724 { SetCellValue( coords.GetRow(), coords.GetCol(), s ); }
f85afd4e 725
2d66e025 726
f85afd4e
MB
727
728 // ------ selections of blocks of cells
729 //
730 void SelectRow( int row, bool addToSelected = FALSE );
731 void SelectCol( int col, bool addToSelected = FALSE );
732
733 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol );
734
735 void SelectBlock( const wxGridCellCoords& topLeft,
736 const wxGridCellCoords& bottomRight )
737 { SelectBlock( topLeft.GetRow(), topLeft.GetCol(),
738 bottomRight.GetRow(), bottomRight.GetCol() ); }
739
740 void SelectAll();
741
742 bool IsSelection()
743 { return ( m_selectedTopLeft != wxGridNoCellCoords &&
744 m_selectedBottomRight != wxGridNoCellCoords );
745 }
746
747 void ClearSelection();
748
749 bool IsInSelection( int row, int col )
750 { return ( IsSelection() &&
751 row >= m_selectedTopLeft.GetRow() &&
752 col >= m_selectedTopLeft.GetCol() &&
753 row <= m_selectedBottomRight.GetRow() &&
754 col <= m_selectedBottomRight.GetCol() );
755 }
756
757 bool IsInSelection( const wxGridCellCoords& coords )
758 { return IsInSelection( coords.GetRow(), coords.GetCol() ); }
759
760 void GetSelection( int* topRow, int* leftCol, int* bottomRow, int* rightCol )
761 {
762 // these will all be -1 if there is no selected block
763 //
764 *topRow = m_selectedTopLeft.GetRow();
765 *leftCol = m_selectedTopLeft.GetCol();
766 *bottomRow = m_selectedBottomRight.GetRow();
767 *rightCol = m_selectedBottomRight.GetCol();
768 }
769
2d66e025
MB
770 // This function returns the rectangle that encloses the selected cells
771 // in device coords and clipped to the client size of the grid window.
f85afd4e 772 //
2d66e025
MB
773 wxRect SelectionToDeviceRect();
774
f85afd4e
MB
775
776
777 // ------ For compatibility with previous wxGrid only...
778 //
779 // ************************************************
780 // ** Don't use these in new code because they **
781 // ** are liable to disappear in a future **
782 // ** revision **
783 // ************************************************
784 //
785
786 wxGrid( wxWindow *parent,
787 int x = -1, int y = -1, int w = -1, int h = -1,
788 long style = 0,
789 const wxString& name = wxPanelNameStr )
2d66e025 790 : wxScrolledWindow( parent, -1, wxPoint(x,y), wxSize(w,h), style, name )
f85afd4e
MB
791 {
792 Create();
793 }
794
795 void SetCellValue( const wxString& val, int row, int col )
796 { SetCellValue( row, col, val ); }
797
f85afd4e
MB
798 void UpdateDimensions()
799 { CalcDimensions(); }
800
801 int GetRows() { return GetNumberRows(); }
802 int GetCols() { return GetNumberCols(); }
803 int GetCursorRow() { return GetGridCursorRow(); }
804 int GetCursorColumn() { return GetGridCursorCol(); }
f85afd4e 805
2d66e025
MB
806 int GetScrollPosX() { return 0; }
807 int GetScrollPosY() { return 0; }
808
809 void SetScrollX( int x ) { }
810 void SetScrollY( int y ) { }
f85afd4e
MB
811
812 void SetColumnWidth( int col, int width )
813 { SetColSize( col, width ); }
814
815 int GetColumnWidth( int col )
816 { return GetColSize( col ); }
817
818 void SetRowHeight( int row, int height )
819 { SetRowSize( row, height ); }
820
821 int GetRowHeight( int row )
822 { return GetRowSize( row ); }
823
2d66e025
MB
824 int GetViewHeight() // returned num whole rows visible
825 { return 0; }
f85afd4e 826
2d66e025
MB
827 int GetViewWidth() // returned num whole cols visible
828 { return 0; }
f85afd4e
MB
829
830 void SetLabelSize( int orientation, int sz )
831 {
832 if ( orientation == wxHORIZONTAL )
833 SetColLabelSize( sz );
834 else
835 SetRowLabelSize( sz );
836 }
837
838 int GetLabelSize( int orientation )
839 {
840 if ( orientation == wxHORIZONTAL )
841 return GetColLabelSize();
842 else
843 return GetRowLabelSize();
844 }
845
846 void SetLabelAlignment( int orientation, int align )
847 {
848 if ( orientation == wxHORIZONTAL )
849 SetColLabelAlignment( align, -1 );
850 else
851 SetRowLabelAlignment( align, -1 );
852 }
853
af111fc3 854 int GetLabelAlignment( int orientation, int WXUNUSED(align) )
f85afd4e
MB
855 {
856 int h, v;
857 if ( orientation == wxHORIZONTAL )
858 {
859 GetColLabelAlignment( &h, &v );
860 return h;
861 }
862 else
863 {
864 GetRowLabelAlignment( &h, &v );
865 return h;
866 }
867 }
868
869 void SetLabelValue( int orientation, const wxString& val, int pos )
870 {
871 if ( orientation == wxHORIZONTAL )
872 SetColLabelValue( pos, val );
873 else
874 SetRowLabelValue( pos, val );
875 }
876
877 wxString GetLabelValue( int orientation, int pos)
878 {
879 if ( orientation == wxHORIZONTAL )
880 return GetColLabelValue( pos );
881 else
882 return GetRowLabelValue( pos );
883 }
884
885 wxFont GetCellTextFont() const
886 { return m_defaultCellFont; }
887
af111fc3 888 wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const
f85afd4e
MB
889 { return m_defaultCellFont; }
890
891 void SetCellTextFont(const wxFont& fnt)
892 { SetDefaultCellFont( fnt ); }
893
894 void SetCellTextFont(const wxFont& fnt, int row, int col)
895 { SetCellFont( row, col, fnt ); }
896
897 void SetCellTextColour(const wxColour& val, int row, int col)
898 { SetCellTextColour( row, col, val ); }
899
900 void SetCellTextColour(const wxColour& col)
901 { SetDefaultCellTextColour( col ); }
902
903 void SetCellBackgroundColour(const wxColour& col)
904 { SetDefaultCellBackgroundColour( col ); }
905
906 void SetCellBackgroundColour(const wxColour& colour, int row, int col)
907 { SetCellBackgroundColour( row, col, colour ); }
908
909 bool GetEditable() { return IsEditable(); }
910 void SetEditable( bool edit = TRUE ) { EnableEditing( edit ); }
911 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
1f1ce288 912 void SetEditInPlace(bool edit = TRUE) { }
f85afd4e 913
60a67569
JS
914 void SetCellAlignment( int align, int row, int col)
915 { SetCellAlignment(row, col, align, wxCENTER); }
916 void SetCellAlignment( int WXUNUSED(align) ) {}
917 void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col))
918 { }
919 void SetDividerPen(const wxPen& WXUNUSED(pen)) { }
920 wxPen& GetDividerPen() const { return wxNullPen; }
921 void OnActivate(bool WXUNUSED(active)) {}
f85afd4e
MB
922
923 // ******** End of compatibility functions **********
924
2d66e025
MB
925
926
f85afd4e 927 // ------ control IDs
2d66e025 928 enum { wxGRID_CELLCTRL = 2000,
f85afd4e
MB
929 wxGRID_TOPCTRL };
930
931 // ------ control types
2d66e025 932 enum { wxGRID_TEXTCTRL = 2100,
f85afd4e
MB
933 wxGRID_CHECKBOX,
934 wxGRID_CHOICE,
935 wxGRID_COMBOBOX };
936
937
2d66e025 938 DECLARE_DYNAMIC_CLASS( wxGrid )
f85afd4e
MB
939 DECLARE_EVENT_TABLE()
940};
941
942
943
944
945
946//
947// ------ Grid event class and event types
948//
949
950class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
951{
52068ea5 952 protected:
f85afd4e
MB
953 int m_row;
954 int m_col;
955 int m_x;
956 int m_y;
957 bool m_control;
958 bool m_meta;
959 bool m_shift;
960 bool m_alt;
961
962 public:
963 wxGridEvent()
964 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
965 m_control(0), m_meta(0), m_shift(0), m_alt(0)
966 {
967 }
968
969 wxGridEvent(int id, wxEventType type, wxObject* obj,
970 int row=-1, int col=-1, int x=-1, int y=-1,
971 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
972
973 virtual int GetRow() { return m_row; }
974 virtual int GetCol() { return m_col; }
975 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
976 bool ControlDown() { return m_control; }
977 bool MetaDown() { return m_meta; }
978 bool ShiftDown() { return m_shift; }
979 bool AltDown() { return m_alt; }
2d66e025
MB
980
981 DECLARE_DYNAMIC_CLASS(wxGridEvent)
f85afd4e
MB
982};
983
984
985class WXDLLEXPORT wxGridSizeEvent : public wxNotifyEvent
986{
52068ea5 987 protected:
f85afd4e
MB
988 int m_rowOrCol;
989 int m_x;
990 int m_y;
991 bool m_control;
992 bool m_meta;
993 bool m_shift;
994 bool m_alt;
995
996 public:
997 wxGridSizeEvent()
998 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
999 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1000 {
1001 }
1002
1003 wxGridSizeEvent(int id, wxEventType type, wxObject* obj,
1004 int rowOrCol=-1, int x=-1, int y=-1,
1005 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1006
1007 int GetRowOrCol() { return m_rowOrCol; }
1008 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
1009 bool ControlDown() { return m_control; }
1010 bool MetaDown() { return m_meta; }
1011 bool ShiftDown() { return m_shift; }
1012 bool AltDown() { return m_alt; }
2d66e025
MB
1013
1014 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent)
f85afd4e
MB
1015};
1016
1017
1018class WXDLLEXPORT wxGridRangeSelectEvent : public wxNotifyEvent
1019{
52068ea5 1020 protected:
f85afd4e
MB
1021 wxGridCellCoords m_topLeft;
1022 wxGridCellCoords m_bottomRight;
1023 bool m_control;
1024 bool m_meta;
1025 bool m_shift;
1026 bool m_alt;
1027
1028 public:
1029 wxGridRangeSelectEvent()
1030 : wxNotifyEvent()
1031 {
1032 m_topLeft = wxGridNoCellCoords;
1033 m_bottomRight = wxGridNoCellCoords;
1034 m_control = FALSE;
1035 m_meta = FALSE;
1036 m_shift = FALSE;
1037 m_alt = FALSE;
1038 }
1039
1040 wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj,
1041 const wxGridCellCoords& topLeft,
1042 const wxGridCellCoords& bottomRight,
1043 bool control=FALSE, bool shift=FALSE,
1044 bool alt=FALSE, bool meta=FALSE);
1045
1046 wxGridCellCoords GetTopLeftCoords() { return m_topLeft; }
1047 wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; }
1048 int GetTopRow() { return m_topLeft.GetRow(); }
1049 int GetBottomRow() { return m_bottomRight.GetRow(); }
1050 int GetLeftCol() { return m_topLeft.GetCol(); }
1051 int GetRightCol() { return m_bottomRight.GetCol(); }
1052 bool ControlDown() { return m_control; }
1053 bool MetaDown() { return m_meta; }
1054 bool ShiftDown() { return m_shift; }
1055 bool AltDown() { return m_alt; }
2d66e025
MB
1056
1057 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent)
f85afd4e
MB
1058};
1059
1060
b5f788a5
MB
1061const wxEventType EVT_GRID_CELL_LEFT_CLICK = wxEVT_FIRST + 1580;
1062const wxEventType EVT_GRID_CELL_RIGHT_CLICK = wxEVT_FIRST + 1581;
1063const wxEventType EVT_GRID_CELL_LEFT_DCLICK = wxEVT_FIRST + 1582;
1064const wxEventType EVT_GRID_CELL_RIGHT_DCLICK = wxEVT_FIRST + 1583;
1065const wxEventType EVT_GRID_LABEL_LEFT_CLICK = wxEVT_FIRST + 1584;
1066const wxEventType EVT_GRID_LABEL_RIGHT_CLICK = wxEVT_FIRST + 1585;
1067const wxEventType EVT_GRID_LABEL_LEFT_DCLICK = wxEVT_FIRST + 1586;
1068const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK = wxEVT_FIRST + 1587;
1069const wxEventType EVT_GRID_ROW_SIZE = wxEVT_FIRST + 1588;
1070const wxEventType EVT_GRID_COL_SIZE = wxEVT_FIRST + 1589;
1071const wxEventType EVT_GRID_RANGE_SELECT = wxEVT_FIRST + 1590;
1072const wxEventType EVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1591;
749692cc
MB
1073const wxEventType EVT_GRID_SELECT_CELL = wxEVT_FIRST + 1592;
1074
f85afd4e
MB
1075
1076typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
1077typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
1078typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
1079
b5f788a5
MB
1080#define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1081#define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1082#define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1083#define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1084#define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1085#define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1086#define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1087#define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1088#define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1089#define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1090#define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1091#define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
749692cc 1092#define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
f85afd4e
MB
1093
1094
1095#if 0 // TODO: implement these ? others ?
1096
b5f788a5
MB
1097const wxEventType EVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576;
1098const wxEventType EVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577;
1099const wxEventType EVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578;
f85afd4e 1100
b5f788a5
MB
1101#define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1102#define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1103#define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
f85afd4e
MB
1104
1105#endif
1106
1107#endif // #ifndef __WXGRID_H__
1108
1109#endif // ifndef wxUSE_NEW_GRID