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