1. EVT_GRID_XXX constants renamed to wxEVT_GRID_XXX
[wxWidgets.git] / include / wx / generic / grid.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: grid.h
3 // Purpose: wxGrid and related classes
4 // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
5 // Modified by:
6 // Created: 1/08/1999
7 // RCS-ID: $Id$
8 // Copyright: (c) Michael Bedward
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12
13 #include "wx/defs.h"
14
15 #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
16 #include "gridg.h"
17 #else
18
19 #ifndef __WXGRID_H__
20 #define __WXGRID_H__
21
22 #ifdef __GNUG__
23 #pragma interface "grid.h"
24 #endif
25
26 #include "wx/panel.h"
27 #include "wx/scrolwin.h"
28 #include "wx/string.h"
29 #include "wx/scrolbar.h"
30 #include "wx/event.h"
31 #include "wx/textctrl.h"
32 #include "wx/combobox.h"
33 #include "wx/dynarray.h"
34 #include "wx/timer.h"
35
36 // Default parameters for wxGrid
37 //
38 #define WXGRID_DEFAULT_NUMBER_ROWS 10
39 #define WXGRID_DEFAULT_NUMBER_COLS 10
40 #ifdef __WXMSW__
41 #define WXGRID_DEFAULT_ROW_HEIGHT 25
42 #else
43 #define WXGRID_DEFAULT_ROW_HEIGHT 30
44 #endif // __WXMSW__
45 #define WXGRID_DEFAULT_COL_WIDTH 80
46 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
47 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
48 #define WXGRID_LABEL_EDGE_ZONE 5
49 #define WXGRID_MIN_ROW_HEIGHT 15
50 #define WXGRID_MIN_COL_WIDTH 15
51 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
52
53 // ----------------------------------------------------------------------------
54 // forward declarations
55 // ----------------------------------------------------------------------------
56
57 class WXDLLEXPORT wxGrid;
58 class WXDLLEXPORT wxGridCellAttr;
59 class WXDLLEXPORT wxGridCellAttrProviderData;
60 class WXDLLEXPORT wxGridColLabelWindow;
61 class WXDLLEXPORT wxGridCornerLabelWindow;
62 class WXDLLEXPORT wxGridRowLabelWindow;
63 class WXDLLEXPORT wxGridTableBase;
64 class WXDLLEXPORT wxGridWindow;
65
66 // ----------------------------------------------------------------------------
67 // wxGridCellRenderer: this class is responsible for actually drawing the cell
68 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
69 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
70 // view of all cells. This is an ABC, you will normally use one of the
71 // predefined derived classes or derive oyur own class from it.
72 // ----------------------------------------------------------------------------
73
74 class WXDLLEXPORT wxGridCellRenderer
75 {
76 public:
77 // draw the given cell on the provided DC inside the given rectangle
78 // using the style specified by the attribute and the default or selected
79 // state corresponding to the isSelected value.
80 //
81 // this pure virtual function has a default implementation which will
82 // prepare the DC using the given attribute: it will draw the rectangle
83 // with the bg colour from attr and set the text colour and font
84 virtual void Draw(wxGrid& grid,
85 wxGridCellAttr& attr,
86 wxDC& dc,
87 const wxRect& rect,
88 int row, int col,
89 bool isSelected) = 0;
90 };
91
92 // the default renderer for the cells containing string data
93 class WXDLLEXPORT wxGridCellStringRenderer : public wxGridCellRenderer
94 {
95 public:
96 // draw the string
97 virtual void Draw(wxGrid& grid,
98 wxGridCellAttr& attr,
99 wxDC& dc,
100 const wxRect& rect,
101 int row, int col,
102 bool isSelected);
103 };
104
105
106 // ----------------------------------------------------------------------------
107 // wxGridCellEditor: This class is responsible for providing and manipulating
108 // the in-place edit controls for the grid. Instances of wxGridCellEditor
109 // (actually, instances of derived classes since it is an ABC) can be
110 // associated with the cell attributes for individual cells, rows, columns, or
111 // even for the entire grid.
112 // ----------------------------------------------------------------------------
113
114 class WXDLLEXPORT wxGridCellEditor
115 {
116 public:
117 wxGridCellEditor();
118 virtual ~wxGridCellEditor();
119
120 bool IsCreated() { return m_control != NULL; }
121
122 // Creates the actual edit control
123 virtual void Create(wxWindow* parent,
124 wxWindowID id,
125 wxEvtHandler* evtHandler) = 0;
126
127 // Size and position the edit control
128 virtual void SetSize(const wxRect& rect);
129
130 // Show or hide the edit control, use the specified attributes to set
131 // colours/fonts for it
132 virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);
133
134 // Fetch the value from the table and prepare the edit control
135 // to begin editing. Set the focus to the edit control.
136 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
137
138 // Complete the editing of the current cell. If saveValue is
139 // true then send the new value back to the table. Returns true
140 // if the value has changed. If necessary, the control may be
141 // destroyed.
142 virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid) = 0;
143
144 // Reset the value in the control back to its starting value
145 virtual void Reset() = 0;
146
147 // If the editor is enabled by pressing keys on the grid,
148 // this will be called to let the editor do something about
149 // that first key if desired.
150 virtual void StartingKey(wxKeyEvent& event);
151
152 // Some types of controls on some platforms may need some help
153 // with the Return key.
154 virtual void HandleReturn(wxKeyEvent& event);
155
156 // Final cleanup
157 virtual void Destroy();
158
159 protected:
160 // the control we show on screen
161 wxControl* m_control;
162
163 // if we change the colours/font of the control from the default ones, we
164 // must restore the default later and we save them here between calls to
165 // Show(TRUE) and Show(FALSE)
166 wxColour m_colFgOld,
167 m_colBgOld;
168 wxFont m_fontOld;
169 };
170
171
172 class WXDLLEXPORT wxGridCellTextEditor : public wxGridCellEditor
173 {
174 public:
175 wxGridCellTextEditor();
176
177 virtual void Create(wxWindow* parent,
178 wxWindowID id,
179 wxEvtHandler* evtHandler);
180
181 virtual void BeginEdit(int row, int col, wxGrid* grid);
182 virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid);
183
184 virtual void Reset();
185 virtual void StartingKey(wxKeyEvent& event);
186 virtual void HandleReturn(wxKeyEvent& event);
187
188 protected:
189 wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
190
191 private:
192 wxString m_startValue;
193 };
194
195 // ----------------------------------------------------------------------------
196 // wxGridCellAttr: this class can be used to alter the cells appearance in
197 // the grid by changing their colour/font/... from default. An object of this
198 // class may be returned by wxGridTable::GetAttr().
199 // ----------------------------------------------------------------------------
200
201 class WXDLLEXPORT wxGridCellAttr
202 {
203 public:
204 // ctors
205 wxGridCellAttr()
206 {
207 Init();
208 SetAlignment(0, 0);
209 }
210
211 // VZ: considering the number of members wxGridCellAttr has now, this ctor
212 // seems to be pretty useless... may be we should just remove it?
213 wxGridCellAttr(const wxColour& colText,
214 const wxColour& colBack,
215 const wxFont& font,
216 int hAlign,
217 int vAlign)
218 : m_colText(colText), m_colBack(colBack), m_font(font)
219 {
220 Init();
221 SetAlignment(hAlign, vAlign);
222 }
223
224 // default copy ctor ok
225
226 // this class is ref counted: it is created with ref count of 1, so
227 // calling DecRef() once will delete it. Calling IncRef() allows to lock
228 // it until the matching DecRef() is called
229 void IncRef() { m_nRef++; }
230 void DecRef() { if ( !--m_nRef ) delete this; }
231 void SafeIncRef() { if ( this ) IncRef(); }
232 void SafeDecRef() { if ( this ) DecRef(); }
233
234 // setters
235 void SetTextColour(const wxColour& colText) { m_colText = colText; }
236 void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; }
237 void SetFont(const wxFont& font) { m_font = font; }
238 void SetAlignment(int hAlign, int vAlign)
239 {
240 m_hAlign = hAlign;
241 m_vAlign = vAlign;
242 }
243 void SetReadOnly(bool isReadOnly = TRUE) { m_isReadOnly = isReadOnly; }
244
245 // takes ownership of the pointer
246 void SetRenderer(wxGridCellRenderer *renderer)
247 { delete m_renderer; m_renderer = renderer; }
248 void SetEditor(wxGridCellEditor* editor)
249 { delete m_editor; m_editor = editor; }
250
251 // accessors
252 bool HasTextColour() const { return m_colText.Ok(); }
253 bool HasBackgroundColour() const { return m_colBack.Ok(); }
254 bool HasFont() const { return m_font.Ok(); }
255 bool HasAlignment() const { return m_hAlign || m_vAlign; }
256 bool HasRenderer() const { return m_renderer != NULL; }
257 bool HasEditor() const { return m_editor != NULL; }
258
259 const wxColour& GetTextColour() const;
260 const wxColour& GetBackgroundColour() const;
261 const wxFont& GetFont() const;
262 void GetAlignment(int *hAlign, int *vAlign) const;
263 wxGridCellRenderer *GetRenderer() const;
264 wxGridCellEditor *GetEditor() const;
265
266 bool IsReadOnly() const { return m_isReadOnly; }
267
268 void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; }
269
270 private:
271 // the common part of all ctors
272 void Init()
273 {
274 m_nRef = 1;
275
276 m_isReadOnly = FALSE;
277
278 m_renderer = NULL;
279 m_editor = NULL;
280 }
281
282 // the dtor is private because only DecRef() can delete us
283 ~wxGridCellAttr() { delete m_renderer; delete m_editor; }
284
285 // the ref count - when it goes to 0, we die
286 size_t m_nRef;
287
288 wxColour m_colText,
289 m_colBack;
290 wxFont m_font;
291 int m_hAlign,
292 m_vAlign;
293
294 wxGridCellRenderer* m_renderer;
295 wxGridCellEditor* m_editor;
296 wxGridCellAttr* m_defGridAttr;
297
298 bool m_isReadOnly;
299
300 // suppress the stupid gcc warning about the class having private dtor and
301 // no friends
302 friend class wxGridCellAttrDummyFriend;
303 };
304
305 // ----------------------------------------------------------------------------
306 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
307 // cell attributes.
308 // ----------------------------------------------------------------------------
309
310 // implementation note: we separate it from wxGridTableBase because we wish to
311 // avoid deriving a new table class if possible, and sometimes it will be
312 // enough to just derive another wxGridCellAttrProvider instead
313 //
314 // the default implementation is reasonably efficient for the generic case,
315 // but you might still wish to implement your own for some specific situations
316 // if you have performance problems with the stock one
317 class WXDLLEXPORT wxGridCellAttrProvider
318 {
319 public:
320 wxGridCellAttrProvider();
321 virtual ~wxGridCellAttrProvider();
322
323 // DecRef() must be called on the returned pointer
324 virtual wxGridCellAttr *GetAttr(int row, int col) const;
325
326 // all these functions take ownership of the pointer, don't call DecRef()
327 // on it
328 virtual void SetAttr(wxGridCellAttr *attr, int row, int col);
329 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
330 virtual void SetColAttr(wxGridCellAttr *attr, int col);
331
332 // these functions must be called whenever some rows/cols are deleted
333 // because the internal data must be updated then
334 void UpdateAttrRows( size_t pos, int numRows );
335 void UpdateAttrCols( size_t pos, int numCols );
336
337 private:
338 void InitData();
339
340 wxGridCellAttrProviderData *m_data;
341 };
342
343 //////////////////////////////////////////////////////////////////////
344 //
345 // Grid table classes
346 //
347 //////////////////////////////////////////////////////////////////////
348
349
350 class WXDLLEXPORT wxGridTableBase : public wxObject
351 {
352 public:
353 wxGridTableBase();
354 virtual ~wxGridTableBase();
355
356 // You must override these functions in a derived table class
357 //
358 virtual long GetNumberRows() = 0;
359 virtual long GetNumberCols() = 0;
360 virtual wxString GetValue( int row, int col ) = 0;
361 virtual void SetValue( int row, int col, const wxString& s ) = 0;
362 virtual bool IsEmptyCell( int row, int col ) = 0;
363
364 // Overriding these is optional
365 //
366 virtual void SetView( wxGrid *grid ) { m_view = grid; }
367 virtual wxGrid * GetView() const { return m_view; }
368
369 virtual void Clear() {}
370 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
371 virtual bool AppendRows( size_t numRows = 1 );
372 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
373 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
374 virtual bool AppendCols( size_t numCols = 1 );
375 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
376
377 virtual wxString GetRowLabelValue( int row );
378 virtual wxString GetColLabelValue( int col );
379 virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {}
380 virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {}
381
382 // Attribute handling
383 //
384
385 // give us the attr provider to use - we take ownership of the pointer
386 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
387
388 // get the currently used attr provider (may be NULL)
389 wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; }
390
391 // change row/col number in attribute if needed
392 void UpdateAttrRows( size_t pos, int numRows );
393 void UpdateAttrCols( size_t pos, int numCols );
394
395 // by default forwarded to wxGridCellAttrProvider if any. May be
396 // overridden to handle attributes directly in this class.
397 virtual wxGridCellAttr *GetAttr( int row, int col );
398
399 // these functions take ownership of the pointer
400 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
401 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
402 virtual void SetColAttr(wxGridCellAttr *attr, int col);
403
404 private:
405 wxGrid * m_view;
406 wxGridCellAttrProvider *m_attrProvider;
407
408 DECLARE_ABSTRACT_CLASS( wxGridTableBase );
409 };
410
411
412 // ----------------------------------------------------------------------------
413 // wxGridTableMessage
414 // ----------------------------------------------------------------------------
415
416 // IDs for messages sent from grid table to view
417 //
418 enum wxGridTableRequest
419 {
420 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
421 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
422 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
423 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
424 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
425 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
426 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
427 wxGRIDTABLE_NOTIFY_COLS_DELETED
428 };
429
430 class WXDLLEXPORT wxGridTableMessage
431 {
432 public:
433 wxGridTableMessage();
434 wxGridTableMessage( wxGridTableBase *table, int id,
435 int comInt1 = -1,
436 int comInt2 = -1 );
437
438 void SetTableObject( wxGridTableBase *table ) { m_table = table; }
439 wxGridTableBase * GetTableObject() const { return m_table; }
440 void SetId( int id ) { m_id = id; }
441 int GetId() { return m_id; }
442 void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; }
443 int GetCommandInt() { return m_comInt1; }
444 void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; }
445 int GetCommandInt2() { return m_comInt2; }
446
447 private:
448 wxGridTableBase *m_table;
449 int m_id;
450 int m_comInt1;
451 int m_comInt2;
452 };
453
454
455
456 // ------ wxGridStringArray
457 // A 2-dimensional array of strings for data values
458 //
459
460 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString, wxGridStringArray);
461
462
463
464 // ------ wxGridStringTable
465 //
466 // Simplest type of data table for a grid for small tables of strings
467 // that are stored in memory
468 //
469
470 class WXDLLEXPORT wxGridStringTable : public wxGridTableBase
471 {
472 public:
473 wxGridStringTable();
474 wxGridStringTable( int numRows, int numCols );
475 ~wxGridStringTable();
476
477 // these are pure virtual in wxGridTableBase
478 //
479 long GetNumberRows();
480 long GetNumberCols();
481 wxString GetValue( int row, int col );
482 void SetValue( int row, int col, const wxString& s );
483 bool IsEmptyCell( int row, int col );
484
485 // overridden functions from wxGridTableBase
486 //
487 void Clear();
488 bool InsertRows( size_t pos = 0, size_t numRows = 1 );
489 bool AppendRows( size_t numRows = 1 );
490 bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
491 bool InsertCols( size_t pos = 0, size_t numCols = 1 );
492 bool AppendCols( size_t numCols = 1 );
493 bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
494
495 void SetRowLabelValue( int row, const wxString& );
496 void SetColLabelValue( int col, const wxString& );
497 wxString GetRowLabelValue( int row );
498 wxString GetColLabelValue( int col );
499
500 private:
501 wxGridStringArray m_data;
502
503 // These only get used if you set your own labels, otherwise the
504 // GetRow/ColLabelValue functions return wxGridTableBase defaults
505 //
506 wxArrayString m_rowLabels;
507 wxArrayString m_colLabels;
508
509 DECLARE_DYNAMIC_CLASS( wxGridStringTable )
510 };
511
512
513
514 //////////////////////////////////////////////////////////////////////
515 //
516 // Grid view classes
517 //
518 //////////////////////////////////////////////////////////////////////
519
520 class WXDLLEXPORT wxGridCellCoords
521 {
522 public:
523 wxGridCellCoords() { m_row = m_col = -1; }
524 wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; }
525
526 // default copy ctor is ok
527
528 long GetRow() const { return m_row; }
529 void SetRow( long n ) { m_row = n; }
530 long GetCol() const { return m_col; }
531 void SetCol( long n ) { m_col = n; }
532 void Set( long row, long col ) { m_row = row; m_col = col; }
533
534 wxGridCellCoords& operator=( const wxGridCellCoords& other )
535 {
536 if ( &other != this )
537 {
538 m_row=other.m_row;
539 m_col=other.m_col;
540 }
541 return *this;
542 }
543
544 bool operator==( const wxGridCellCoords& other )
545 {
546 return (m_row == other.m_row && m_col == other.m_col);
547 }
548
549 bool operator!=( const wxGridCellCoords& other )
550 {
551 return (m_row != other.m_row || m_col != other.m_col);
552 }
553
554 bool operator!()
555 {
556 return (m_row == -1 && m_col == -1 );
557 }
558
559 private:
560 long m_row;
561 long m_col;
562 };
563
564
565 // For comparisons...
566 //
567 extern wxGridCellCoords wxGridNoCellCoords;
568 extern wxRect wxGridNoCellRect;
569
570 // An array of cell coords...
571 //
572 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords, wxGridCellCoordsArray);
573
574
575
576 // ----------------------------------------------------------------------------
577 // wxGrid
578 // ----------------------------------------------------------------------------
579
580 class WXDLLEXPORT wxGrid : public wxScrolledWindow
581 {
582 public:
583 wxGrid()
584 {
585 Create();
586 }
587
588 wxGrid( wxWindow *parent,
589 wxWindowID id,
590 const wxPoint& pos = wxDefaultPosition,
591 const wxSize& size = wxDefaultSize,
592 long style = 0,
593 const wxString& name = wxPanelNameStr );
594
595 ~wxGrid();
596
597 bool CreateGrid( int numRows, int numCols );
598
599
600 // ------ grid dimensions
601 //
602 int GetNumberRows() { return m_numRows; }
603 int GetNumberCols() { return m_numCols; }
604
605
606 // ------ display update functions
607 //
608 void CalcRowLabelsExposed( wxRegion& reg );
609
610 void CalcColLabelsExposed( wxRegion& reg );
611 void CalcCellsExposed( wxRegion& reg );
612
613
614 // ------ event handlers
615 //
616 void ProcessRowLabelMouseEvent( wxMouseEvent& event );
617 void ProcessColLabelMouseEvent( wxMouseEvent& event );
618 void ProcessCornerLabelMouseEvent( wxMouseEvent& event );
619 void ProcessGridCellMouseEvent( wxMouseEvent& event );
620 bool ProcessTableMessage( wxGridTableMessage& );
621
622 void DoEndDragResizeRow();
623 void DoEndDragResizeCol();
624
625 wxGridTableBase * GetTable() const { return m_table; }
626 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE );
627
628 void ClearGrid();
629 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
630 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
631 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
632 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
633 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
634 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
635
636 void DrawGridCellArea( wxDC& dc );
637 void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
638 void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
639 void DrawCell( wxDC& dc, const wxGridCellCoords& );
640 void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
641
642 void DrawRowLabels( wxDC& dc );
643 void DrawRowLabel( wxDC& dc, int row );
644
645 void DrawColLabels( wxDC& dc );
646 void DrawColLabel( wxDC& dc, int col );
647
648
649 // ------ Cell text drawing functions
650 //
651 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
652 int horizontalAlignment = wxLEFT,
653 int verticalAlignment = wxTOP );
654
655 // Split a string containing newline chararcters into an array of
656 // strings and return the number of lines
657 //
658 void StringToLines( const wxString& value, wxArrayString& lines );
659
660 void GetTextBoxSize( wxDC& dc,
661 wxArrayString& lines,
662 long *width, long *height );
663
664
665 // ------
666 // Code that does a lot of grid modification can be enclosed
667 // between BeginBatch() and EndBatch() calls to avoid screen
668 // flicker
669 //
670 void BeginBatch() { m_batchCount++; }
671 void EndBatch() { if ( m_batchCount > 0 ) m_batchCount--; }
672 int GetBatchCount() { return m_batchCount; }
673
674
675 // ------ edit control functions
676 //
677 bool IsEditable() { return m_editable; }
678 void EnableEditing( bool edit );
679
680 void EnableCellEditControl( bool enable = TRUE );
681 void DisableCellEditControl() { EnableCellEditControl(FALSE); }
682 bool CanEnableCellControl() const;
683 bool IsCellEditControlEnabled() const;
684
685 bool IsCurrentCellReadOnly() const;
686
687 void ShowCellEditControl();
688 void HideCellEditControl();
689 void SetEditControlValue( const wxString& s = wxEmptyString );
690 void SaveEditControlValue();
691
692
693 // ------ grid location functions
694 // Note that all of these functions work with the logical coordinates of
695 // grid cells and labels so you will need to convert from device
696 // coordinates for mouse events etc.
697 //
698 void XYToCell( int x, int y, wxGridCellCoords& );
699 int YToRow( int y );
700 int XToCol( int x );
701
702 int YToEdgeOfRow( int y );
703 int XToEdgeOfCol( int x );
704
705 wxRect CellToRect( int row, int col );
706 wxRect CellToRect( const wxGridCellCoords& coords )
707 { return CellToRect( coords.GetRow(), coords.GetCol() ); }
708
709 int GetGridCursorRow() { return m_currentCellCoords.GetRow(); }
710 int GetGridCursorCol() { return m_currentCellCoords.GetCol(); }
711
712 // check to see if a cell is either wholly visible (the default arg) or
713 // at least partially visible in the grid window
714 //
715 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
716 bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE )
717 { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); }
718 void MakeCellVisible( int row, int col );
719 void MakeCellVisible( const wxGridCellCoords& coords )
720 { MakeCellVisible( coords.GetRow(), coords.GetCol() ); }
721
722
723 // ------ grid cursor movement functions
724 //
725 void SetGridCursor( int row, int col )
726 { SetCurrentCell( wxGridCellCoords(row, col) ); }
727
728 bool MoveCursorUp();
729 bool MoveCursorDown();
730 bool MoveCursorLeft();
731 bool MoveCursorRight();
732 bool MovePageDown();
733 bool MovePageUp();
734 bool MoveCursorUpBlock();
735 bool MoveCursorDownBlock();
736 bool MoveCursorLeftBlock();
737 bool MoveCursorRightBlock();
738
739
740 // ------ label and gridline formatting
741 //
742 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; }
743 int GetRowLabelSize() { return m_rowLabelWidth; }
744 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; }
745 int GetColLabelSize() { return m_colLabelHeight; }
746 wxColour GetLabelBackgroundColour() { return m_labelBackgroundColour; }
747 wxColour GetLabelTextColour() { return m_labelTextColour; }
748 wxFont GetLabelFont() { return m_labelFont; }
749 void GetRowLabelAlignment( int *horiz, int *vert );
750 void GetColLabelAlignment( int *horiz, int *vert );
751 wxString GetRowLabelValue( int row );
752 wxString GetColLabelValue( int col );
753 wxColour GetGridLineColour() { return m_gridLineColour; }
754
755 void SetRowLabelSize( int width );
756 void SetColLabelSize( int height );
757 void SetLabelBackgroundColour( const wxColour& );
758 void SetLabelTextColour( const wxColour& );
759 void SetLabelFont( const wxFont& );
760 void SetRowLabelAlignment( int horiz, int vert );
761 void SetColLabelAlignment( int horiz, int vert );
762 void SetRowLabelValue( int row, const wxString& );
763 void SetColLabelValue( int col, const wxString& );
764 void SetGridLineColour( const wxColour& );
765
766 // this sets the specified attribute for all cells in this row/col
767 void SetRowAttr(int row, wxGridCellAttr *attr);
768 void SetColAttr(int col, wxGridCellAttr *attr);
769
770 void EnableGridLines( bool enable = TRUE );
771 bool GridLinesEnabled() { return m_gridLinesEnabled; }
772
773 // ------ row and col formatting
774 //
775 int GetDefaultRowSize();
776 int GetRowSize( int row );
777 int GetDefaultColSize();
778 int GetColSize( int col );
779 wxColour GetDefaultCellBackgroundColour();
780 wxColour GetCellBackgroundColour( int row, int col );
781 wxColour GetDefaultCellTextColour();
782 wxColour GetCellTextColour( int row, int col );
783 wxFont GetDefaultCellFont();
784 wxFont GetCellFont( int row, int col );
785 void GetDefaultCellAlignment( int *horiz, int *vert );
786 void GetCellAlignment( int row, int col, int *horiz, int *vert );
787
788 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
789 void SetRowSize( int row, int height );
790 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
791
792 void SetColSize( int col, int width );
793 void SetDefaultCellBackgroundColour( const wxColour& );
794 void SetCellBackgroundColour( int row, int col, const wxColour& );
795 void SetDefaultCellTextColour( const wxColour& );
796
797 void SetCellTextColour( int row, int col, const wxColour& );
798 void SetDefaultCellFont( const wxFont& );
799 void SetCellFont( int row, int col, const wxFont& );
800 void SetDefaultCellAlignment( int horiz, int vert );
801 void SetCellAlignment( int row, int col, int horiz, int vert );
802
803 // takes ownership of the pointer
804 void SetDefaultRenderer(wxGridCellRenderer *renderer);
805 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
806 wxGridCellRenderer *GetDefaultRenderer() const;
807 wxGridCellRenderer* GetCellRenderer(int row, int col);
808
809 // takes ownership of the pointer
810 void SetDefaultEditor(wxGridCellEditor *editor);
811 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
812 wxGridCellEditor *GetDefaultEditor() const;
813 wxGridCellEditor* GetCellEditor(int row, int col);
814
815
816 // ------ cell value accessors
817 //
818 wxString GetCellValue( int row, int col )
819 {
820 if ( m_table )
821 {
822 return m_table->GetValue( row, col );
823 }
824 else
825 {
826 return wxEmptyString;
827 }
828 }
829
830 wxString GetCellValue( const wxGridCellCoords& coords )
831 { return GetCellValue( coords.GetRow(), coords.GetCol() ); }
832
833 void SetCellValue( int row, int col, const wxString& s );
834 void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
835 { SetCellValue( coords.GetRow(), coords.GetCol(), s ); }
836
837 // returns TRUE if the cell can't be edited
838 bool IsReadOnly(int row, int col) const;
839
840 // make the cell editable/readonly
841 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
842
843 // ------ selections of blocks of cells
844 //
845 void SelectRow( int row, bool addToSelected = FALSE );
846 void SelectCol( int col, bool addToSelected = FALSE );
847
848 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol );
849
850 void SelectBlock( const wxGridCellCoords& topLeft,
851 const wxGridCellCoords& bottomRight )
852 { SelectBlock( topLeft.GetRow(), topLeft.GetCol(),
853 bottomRight.GetRow(), bottomRight.GetCol() ); }
854
855 void SelectAll();
856
857 bool IsSelection()
858 { return ( m_selectedTopLeft != wxGridNoCellCoords &&
859 m_selectedBottomRight != wxGridNoCellCoords );
860 }
861
862 void ClearSelection();
863
864 bool IsInSelection( int row, int col )
865 { return ( IsSelection() &&
866 row >= m_selectedTopLeft.GetRow() &&
867 col >= m_selectedTopLeft.GetCol() &&
868 row <= m_selectedBottomRight.GetRow() &&
869 col <= m_selectedBottomRight.GetCol() );
870 }
871
872 bool IsInSelection( const wxGridCellCoords& coords )
873 { return IsInSelection( coords.GetRow(), coords.GetCol() ); }
874
875 void GetSelection( int* topRow, int* leftCol, int* bottomRow, int* rightCol )
876 {
877 // these will all be -1 if there is no selected block
878 //
879 *topRow = m_selectedTopLeft.GetRow();
880 *leftCol = m_selectedTopLeft.GetCol();
881 *bottomRow = m_selectedBottomRight.GetRow();
882 *rightCol = m_selectedBottomRight.GetCol();
883 }
884
885
886 // This function returns the rectangle that encloses the block of cells
887 // limited by TopLeft and BottomRight cell in device coords and clipped
888 // to the client size of the grid window.
889 //
890 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
891 const wxGridCellCoords & bottomRight );
892
893 // This function returns the rectangle that encloses the selected cells
894 // in device coords and clipped to the client size of the grid window.
895 //
896 wxRect SelectionToDeviceRect()
897 {
898 return BlockToDeviceRect( m_selectedTopLeft,
899 m_selectedBottomRight );
900 }
901
902 // Access or update the selection fore/back colours
903 wxColour GetSelectionBackground() const
904 { return m_selectionBackground; }
905 wxColour GetSelectionForeground() const
906 { return m_selectionForeground; }
907
908 void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; }
909 void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; }
910
911
912
913 // ------ For compatibility with previous wxGrid only...
914 //
915 // ************************************************
916 // ** Don't use these in new code because they **
917 // ** are liable to disappear in a future **
918 // ** revision **
919 // ************************************************
920 //
921
922 wxGrid( wxWindow *parent,
923 int x = -1, int y = -1, int w = -1, int h = -1,
924 long style = 0,
925 const wxString& name = wxPanelNameStr )
926 : wxScrolledWindow( parent, -1, wxPoint(x,y), wxSize(w,h), style, name )
927 {
928 Create();
929 }
930
931 void SetCellValue( const wxString& val, int row, int col )
932 { SetCellValue( row, col, val ); }
933
934 void UpdateDimensions()
935 { CalcDimensions(); }
936
937 int GetRows() { return GetNumberRows(); }
938 int GetCols() { return GetNumberCols(); }
939 int GetCursorRow() { return GetGridCursorRow(); }
940 int GetCursorColumn() { return GetGridCursorCol(); }
941
942 int GetScrollPosX() { return 0; }
943 int GetScrollPosY() { return 0; }
944
945 void SetScrollX( int x ) { }
946 void SetScrollY( int y ) { }
947
948 void SetColumnWidth( int col, int width )
949 { SetColSize( col, width ); }
950
951 int GetColumnWidth( int col )
952 { return GetColSize( col ); }
953
954 void SetRowHeight( int row, int height )
955 { SetRowSize( row, height ); }
956
957 int GetRowHeight( int row )
958 { return GetRowSize( row ); }
959
960 int GetViewHeight() // returned num whole rows visible
961 { return 0; }
962
963 int GetViewWidth() // returned num whole cols visible
964 { return 0; }
965
966 void SetLabelSize( int orientation, int sz )
967 {
968 if ( orientation == wxHORIZONTAL )
969 SetColLabelSize( sz );
970 else
971 SetRowLabelSize( sz );
972 }
973
974 int GetLabelSize( int orientation )
975 {
976 if ( orientation == wxHORIZONTAL )
977 return GetColLabelSize();
978 else
979 return GetRowLabelSize();
980 }
981
982 void SetLabelAlignment( int orientation, int align )
983 {
984 if ( orientation == wxHORIZONTAL )
985 SetColLabelAlignment( align, -1 );
986 else
987 SetRowLabelAlignment( align, -1 );
988 }
989
990 int GetLabelAlignment( int orientation, int WXUNUSED(align) )
991 {
992 int h, v;
993 if ( orientation == wxHORIZONTAL )
994 {
995 GetColLabelAlignment( &h, &v );
996 return h;
997 }
998 else
999 {
1000 GetRowLabelAlignment( &h, &v );
1001 return h;
1002 }
1003 }
1004
1005 void SetLabelValue( int orientation, const wxString& val, int pos )
1006 {
1007 if ( orientation == wxHORIZONTAL )
1008 SetColLabelValue( pos, val );
1009 else
1010 SetRowLabelValue( pos, val );
1011 }
1012
1013 wxString GetLabelValue( int orientation, int pos)
1014 {
1015 if ( orientation == wxHORIZONTAL )
1016 return GetColLabelValue( pos );
1017 else
1018 return GetRowLabelValue( pos );
1019 }
1020
1021 wxFont GetCellTextFont() const
1022 { return m_defaultCellAttr->GetFont(); }
1023
1024 wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const
1025 { return m_defaultCellAttr->GetFont(); }
1026
1027 void SetCellTextFont(const wxFont& fnt)
1028 { SetDefaultCellFont( fnt ); }
1029
1030 void SetCellTextFont(const wxFont& fnt, int row, int col)
1031 { SetCellFont( row, col, fnt ); }
1032
1033 void SetCellTextColour(const wxColour& val, int row, int col)
1034 { SetCellTextColour( row, col, val ); }
1035
1036 void SetCellTextColour(const wxColour& col)
1037 { SetDefaultCellTextColour( col ); }
1038
1039 void SetCellBackgroundColour(const wxColour& col)
1040 { SetDefaultCellBackgroundColour( col ); }
1041
1042 void SetCellBackgroundColour(const wxColour& colour, int row, int col)
1043 { SetCellBackgroundColour( row, col, colour ); }
1044
1045 bool GetEditable() { return IsEditable(); }
1046 void SetEditable( bool edit = TRUE ) { EnableEditing( edit ); }
1047 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
1048
1049 void SetEditInPlace(bool edit = TRUE) { }
1050
1051 void SetCellAlignment( int align, int row, int col)
1052 { SetCellAlignment(row, col, align, wxCENTER); }
1053 void SetCellAlignment( int WXUNUSED(align) ) {}
1054 void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col))
1055 { }
1056 void SetDividerPen(const wxPen& WXUNUSED(pen)) { }
1057 wxPen& GetDividerPen() const { return wxNullPen; }
1058 void OnActivate(bool WXUNUSED(active)) {}
1059
1060 // ******** End of compatibility functions **********
1061
1062
1063
1064 // ------ control IDs
1065 enum { wxGRID_CELLCTRL = 2000,
1066 wxGRID_TOPCTRL };
1067
1068 // ------ control types
1069 enum { wxGRID_TEXTCTRL = 2100,
1070 wxGRID_CHECKBOX,
1071 wxGRID_CHOICE,
1072 wxGRID_COMBOBOX };
1073
1074 protected:
1075 bool m_created;
1076 bool m_displayed;
1077
1078 wxGridWindow *m_gridWin;
1079 wxGridRowLabelWindow *m_rowLabelWin;
1080 wxGridColLabelWindow *m_colLabelWin;
1081 wxGridCornerLabelWindow *m_cornerLabelWin;
1082
1083 wxGridTableBase *m_table;
1084 bool m_ownTable;
1085
1086 int m_left;
1087 int m_top;
1088 int m_right;
1089 int m_bottom;
1090
1091 int m_numRows;
1092 int m_numCols;
1093
1094 wxGridCellCoords m_currentCellCoords;
1095
1096 wxGridCellCoords m_selectedTopLeft;
1097 wxGridCellCoords m_selectedBottomRight;
1098 wxColour m_selectionBackground;
1099 wxColour m_selectionForeground;
1100
1101 int m_defaultRowHeight;
1102 wxArrayInt m_rowHeights;
1103 wxArrayInt m_rowBottoms;
1104
1105 int m_defaultColWidth;
1106 wxArrayInt m_colWidths;
1107 wxArrayInt m_colRights;
1108 int m_rowLabelWidth;
1109 int m_colLabelHeight;
1110
1111 wxColour m_labelBackgroundColour;
1112 wxColour m_labelTextColour;
1113 wxFont m_labelFont;
1114
1115 int m_rowLabelHorizAlign;
1116 int m_rowLabelVertAlign;
1117 int m_colLabelHorizAlign;
1118 int m_colLabelVertAlign;
1119
1120 bool m_defaultRowLabelValues;
1121 bool m_defaultColLabelValues;
1122
1123 wxColour m_gridLineColour;
1124 bool m_gridLinesEnabled;
1125
1126
1127 // do we have some place to store attributes in?
1128 bool CanHaveAttributes();
1129
1130 // returns the attribute we may modify in place: a new one if this cell
1131 // doesn't have any yet or the existing one if it does
1132 //
1133 // DecRef() must be called on the returned pointer, as usual
1134 wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const;
1135
1136 // cell attribute cache (currently we only cache 1, may be will do
1137 // more/better later)
1138 struct CachedAttr
1139 {
1140 int row, col;
1141 wxGridCellAttr *attr;
1142 } m_attrCache;
1143
1144 // invalidates the attribute cache
1145 void ClearAttrCache();
1146
1147 // adds an attribute to cache
1148 void CacheAttr(int row, int col, wxGridCellAttr *attr) const;
1149
1150 // looks for an attr in cache, returns TRUE if found
1151 bool LookupAttr(int row, int col, wxGridCellAttr **attr) const;
1152
1153 // looks for the attr in cache, if not found asks the table and caches the
1154 // result
1155 wxGridCellAttr *GetCellAttr(int row, int col) const;
1156 wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords )
1157 { return GetCellAttr( coords.GetRow(), coords.GetCol() ); }
1158
1159 // the default cell attr object for cells that don't have their own
1160 wxGridCellAttr* m_defaultCellAttr;
1161
1162
1163 wxGridCellCoordsArray m_cellsExposed;
1164 wxArrayInt m_rowsExposed;
1165 wxArrayInt m_colsExposed;
1166 wxArrayInt m_rowLabelsExposed;
1167 wxArrayInt m_colLabelsExposed;
1168
1169 bool m_inOnKeyDown;
1170 int m_batchCount;
1171
1172 enum CursorMode
1173 {
1174 WXGRID_CURSOR_SELECT_CELL,
1175 WXGRID_CURSOR_RESIZE_ROW,
1176 WXGRID_CURSOR_RESIZE_COL,
1177 WXGRID_CURSOR_SELECT_ROW,
1178 WXGRID_CURSOR_SELECT_COL
1179 };
1180
1181 // this method not only sets m_cursorMode but also sets the correct cursor
1182 // for the given mode and, if captureMouse is not FALSE releases the mouse
1183 // if it was captured and captures it if it must be captured
1184 //
1185 // for this to work, you should always use it and not set m_cursorMode
1186 // directly!
1187 void ChangeCursorMode(CursorMode mode,
1188 wxWindow *win = (wxWindow *)NULL,
1189 bool captureMouse = TRUE);
1190
1191 wxWindow *m_winCapture; // the window which captured the mouse
1192 CursorMode m_cursorMode;
1193
1194 int m_dragLastPos;
1195 int m_dragRowOrCol;
1196 bool m_isDragging;
1197 wxPoint m_startDragPos;
1198
1199 bool m_waitForSlowClick;
1200
1201 wxGridCellCoords m_selectionStart;
1202
1203 wxCursor m_rowResizeCursor;
1204 wxCursor m_colResizeCursor;
1205
1206 bool m_editable; // applies to whole grid
1207 bool m_cellEditCtrlEnabled; // is in-place edit currently shown?
1208
1209
1210 void Create();
1211 void Init();
1212 void CalcDimensions();
1213 void CalcWindowSizes();
1214 bool Redimension( wxGridTableMessage& );
1215
1216
1217 bool SendEvent( const wxEventType, int row, int col, wxMouseEvent& );
1218 bool SendEvent( const wxEventType, int row, int col );
1219 bool SendEvent( const wxEventType type)
1220 {
1221 return SendEvent(type,
1222 m_currentCellCoords.GetRow(),
1223 m_currentCellCoords.GetCol());
1224 }
1225
1226 void OnPaint( wxPaintEvent& );
1227 void OnSize( wxSizeEvent& );
1228 void OnKeyDown( wxKeyEvent& );
1229 void OnEraseBackground( wxEraseEvent& );
1230
1231
1232 void SetCurrentCell( const wxGridCellCoords& coords );
1233 void SetCurrentCell( int row, int col )
1234 { SetCurrentCell( wxGridCellCoords(row, col) ); }
1235
1236
1237 // ------ functions to get/send data (see also public functions)
1238 //
1239 bool GetModelValues();
1240 bool SetModelValues();
1241
1242
1243 DECLARE_DYNAMIC_CLASS( wxGrid )
1244 DECLARE_EVENT_TABLE()
1245 };
1246
1247
1248
1249
1250
1251 //
1252 // ------ Grid event class and event types
1253 //
1254
1255 class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
1256 {
1257 public:
1258 wxGridEvent()
1259 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
1260 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1261 {
1262 }
1263
1264 wxGridEvent(int id, wxEventType type, wxObject* obj,
1265 int row=-1, int col=-1, int x=-1, int y=-1,
1266 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1267
1268 virtual int GetRow() { return m_row; }
1269 virtual int GetCol() { return m_col; }
1270 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
1271 bool ControlDown() { return m_control; }
1272 bool MetaDown() { return m_meta; }
1273 bool ShiftDown() { return m_shift; }
1274 bool AltDown() { return m_alt; }
1275
1276 protected:
1277 int m_row;
1278 int m_col;
1279 int m_x;
1280 int m_y;
1281 bool m_control;
1282 bool m_meta;
1283 bool m_shift;
1284 bool m_alt;
1285
1286 DECLARE_DYNAMIC_CLASS(wxGridEvent)
1287 };
1288
1289 class WXDLLEXPORT wxGridSizeEvent : public wxNotifyEvent
1290 {
1291 public:
1292 wxGridSizeEvent()
1293 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1294 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1295 {
1296 }
1297
1298 wxGridSizeEvent(int id, wxEventType type, wxObject* obj,
1299 int rowOrCol=-1, int x=-1, int y=-1,
1300 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1301
1302 int GetRowOrCol() { return m_rowOrCol; }
1303 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
1304 bool ControlDown() { return m_control; }
1305 bool MetaDown() { return m_meta; }
1306 bool ShiftDown() { return m_shift; }
1307 bool AltDown() { return m_alt; }
1308
1309 protected:
1310 int m_rowOrCol;
1311 int m_x;
1312 int m_y;
1313 bool m_control;
1314 bool m_meta;
1315 bool m_shift;
1316 bool m_alt;
1317
1318 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent)
1319 };
1320
1321
1322 class WXDLLEXPORT wxGridRangeSelectEvent : public wxNotifyEvent
1323 {
1324 public:
1325 wxGridRangeSelectEvent()
1326 : wxNotifyEvent()
1327 {
1328 m_topLeft = wxGridNoCellCoords;
1329 m_bottomRight = wxGridNoCellCoords;
1330 m_control = FALSE;
1331 m_meta = FALSE;
1332 m_shift = FALSE;
1333 m_alt = FALSE;
1334 }
1335
1336 wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj,
1337 const wxGridCellCoords& topLeft,
1338 const wxGridCellCoords& bottomRight,
1339 bool control=FALSE, bool shift=FALSE,
1340 bool alt=FALSE, bool meta=FALSE);
1341
1342 wxGridCellCoords GetTopLeftCoords() { return m_topLeft; }
1343 wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; }
1344 int GetTopRow() { return m_topLeft.GetRow(); }
1345 int GetBottomRow() { return m_bottomRight.GetRow(); }
1346 int GetLeftCol() { return m_topLeft.GetCol(); }
1347 int GetRightCol() { return m_bottomRight.GetCol(); }
1348 bool ControlDown() { return m_control; }
1349 bool MetaDown() { return m_meta; }
1350 bool ShiftDown() { return m_shift; }
1351 bool AltDown() { return m_alt; }
1352
1353 protected:
1354 wxGridCellCoords m_topLeft;
1355 wxGridCellCoords m_bottomRight;
1356 bool m_control;
1357 bool m_meta;
1358 bool m_shift;
1359 bool m_alt;
1360
1361 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent)
1362 };
1363
1364 // TODO move to wx/event.h
1365 const wxEventType wxEVT_GRID_CELL_LEFT_CLICK = wxEVT_FIRST + 1580;
1366 const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK = wxEVT_FIRST + 1581;
1367 const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK = wxEVT_FIRST + 1582;
1368 const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK = wxEVT_FIRST + 1583;
1369 const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK = wxEVT_FIRST + 1584;
1370 const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK = wxEVT_FIRST + 1585;
1371 const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK = wxEVT_FIRST + 1586;
1372 const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK = wxEVT_FIRST + 1587;
1373 const wxEventType wxEVT_GRID_ROW_SIZE = wxEVT_FIRST + 1588;
1374 const wxEventType wxEVT_GRID_COL_SIZE = wxEVT_FIRST + 1589;
1375 const wxEventType wxEVT_GRID_RANGE_SELECT = wxEVT_FIRST + 1590;
1376 const wxEventType wxEVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1591;
1377 const wxEventType wxEVT_GRID_SELECT_CELL = wxEVT_FIRST + 1592;
1378 const wxEventType wxEVT_GRID_EDITOR_SHOWN = wxEVT_FIRST + 1593;
1379 const wxEventType wxEVT_GRID_EDITOR_HIDDEN = wxEVT_FIRST + 1594;
1380
1381
1382 typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
1383 typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
1384 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
1385
1386 #define EVT_GRID_CELL_LEFT_CLICK(fn) { wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1387 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1388 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1389 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1390 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1391 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1392 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1393 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1394 #define EVT_GRID_ROW_SIZE(fn) { wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1395 #define EVT_GRID_COL_SIZE(fn) { wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1396 #define EVT_GRID_RANGE_SELECT(fn) { wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1397 #define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1398 #define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1399 #define EVT_GRID_EDITOR_SHOWN(fn) { wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1400 #define EVT_GRID_EDITOR_HIDDEN(fn) { wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1401
1402
1403 #if 0 // TODO: implement these ? others ?
1404
1405 const wxEventType wxEVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576;
1406 const wxEventType wxEVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577;
1407 const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578;
1408
1409 #define EVT_GRID_CREATE_CELL(fn) { wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1410 #define EVT_GRID_CHANGE_LABELS(fn) { wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1411 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1412
1413 #endif
1414
1415 #endif // #ifndef __WXGRID_H__
1416
1417 #endif // ifndef wxUSE_NEW_GRID
1418