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