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