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