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