]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/grid.h
added wxGridCellEditor::StartingClick(), used by BoolEditor
[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 DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
689
690 void DrawRowLabels( wxDC& dc );
691 void DrawRowLabel( wxDC& dc, int row );
692
693 void DrawColLabels( wxDC& dc );
694 void DrawColLabel( wxDC& dc, int col );
695
696
697 // ------ Cell text drawing functions
698 //
699 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
700 int horizontalAlignment = wxLEFT,
701 int verticalAlignment = wxTOP );
702
703 // Split a string containing newline chararcters into an array of
704 // strings and return the number of lines
705 //
706 void StringToLines( const wxString& value, wxArrayString& lines );
707
708 void GetTextBoxSize( wxDC& dc,
709 wxArrayString& lines,
710 long *width, long *height );
711
712
713 // ------
714 // Code that does a lot of grid modification can be enclosed
715 // between BeginBatch() and EndBatch() calls to avoid screen
716 // flicker
717 //
718 void BeginBatch() { m_batchCount++; }
719 void EndBatch() { if ( m_batchCount > 0 ) m_batchCount--; }
720 int GetBatchCount() { return m_batchCount; }
721
722
723 // ------ edit control functions
724 //
725 bool IsEditable() { return m_editable; }
726 void EnableEditing( bool edit );
727
728 void EnableCellEditControl( bool enable = TRUE );
729 void DisableCellEditControl() { EnableCellEditControl(FALSE); }
730 bool CanEnableCellControl() const;
731 bool IsCellEditControlEnabled() const;
732
733 bool IsCurrentCellReadOnly() const;
734
735 void ShowCellEditControl();
736 void HideCellEditControl();
737 void SetEditControlValue( const wxString& s = wxEmptyString );
738 void SaveEditControlValue();
739
740
741 // ------ grid location functions
742 // Note that all of these functions work with the logical coordinates of
743 // grid cells and labels so you will need to convert from device
744 // coordinates for mouse events etc.
745 //
746 void XYToCell( int x, int y, wxGridCellCoords& );
747 int YToRow( int y );
748 int XToCol( int x );
749
750 int YToEdgeOfRow( int y );
751 int XToEdgeOfCol( int x );
752
753 wxRect CellToRect( int row, int col );
754 wxRect CellToRect( const wxGridCellCoords& coords )
755 { return CellToRect( coords.GetRow(), coords.GetCol() ); }
756
757 int GetGridCursorRow() { return m_currentCellCoords.GetRow(); }
758 int GetGridCursorCol() { return m_currentCellCoords.GetCol(); }
759
760 // check to see if a cell is either wholly visible (the default arg) or
761 // at least partially visible in the grid window
762 //
763 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
764 bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE )
765 { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); }
766 void MakeCellVisible( int row, int col );
767 void MakeCellVisible( const wxGridCellCoords& coords )
768 { MakeCellVisible( coords.GetRow(), coords.GetCol() ); }
769
770
771 // ------ grid cursor movement functions
772 //
773 void SetGridCursor( int row, int col )
774 { SetCurrentCell( wxGridCellCoords(row, col) ); }
775
776 bool MoveCursorUp();
777 bool MoveCursorDown();
778 bool MoveCursorLeft();
779 bool MoveCursorRight();
780 bool MovePageDown();
781 bool MovePageUp();
782 bool MoveCursorUpBlock();
783 bool MoveCursorDownBlock();
784 bool MoveCursorLeftBlock();
785 bool MoveCursorRightBlock();
786
787
788 // ------ label and gridline formatting
789 //
790 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; }
791 int GetRowLabelSize() { return m_rowLabelWidth; }
792 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; }
793 int GetColLabelSize() { return m_colLabelHeight; }
794 wxColour GetLabelBackgroundColour() { return m_labelBackgroundColour; }
795 wxColour GetLabelTextColour() { return m_labelTextColour; }
796 wxFont GetLabelFont() { return m_labelFont; }
797 void GetRowLabelAlignment( int *horiz, int *vert );
798 void GetColLabelAlignment( int *horiz, int *vert );
799 wxString GetRowLabelValue( int row );
800 wxString GetColLabelValue( int col );
801 wxColour GetGridLineColour() { return m_gridLineColour; }
802
803 void SetRowLabelSize( int width );
804 void SetColLabelSize( int height );
805 void SetLabelBackgroundColour( const wxColour& );
806 void SetLabelTextColour( const wxColour& );
807 void SetLabelFont( const wxFont& );
808 void SetRowLabelAlignment( int horiz, int vert );
809 void SetColLabelAlignment( int horiz, int vert );
810 void SetRowLabelValue( int row, const wxString& );
811 void SetColLabelValue( int col, const wxString& );
812 void SetGridLineColour( const wxColour& );
813
814 // this sets the specified attribute for all cells in this row/col
815 void SetRowAttr(int row, wxGridCellAttr *attr);
816 void SetColAttr(int col, wxGridCellAttr *attr);
817
818 void EnableGridLines( bool enable = TRUE );
819 bool GridLinesEnabled() { return m_gridLinesEnabled; }
820
821 // ------ row and col formatting
822 //
823 int GetDefaultRowSize();
824 int GetRowSize( int row );
825 int GetDefaultColSize();
826 int GetColSize( int col );
827 wxColour GetDefaultCellBackgroundColour();
828 wxColour GetCellBackgroundColour( int row, int col );
829 wxColour GetDefaultCellTextColour();
830 wxColour GetCellTextColour( int row, int col );
831 wxFont GetDefaultCellFont();
832 wxFont GetCellFont( int row, int col );
833 void GetDefaultCellAlignment( int *horiz, int *vert );
834 void GetCellAlignment( int row, int col, int *horiz, int *vert );
835
836 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
837 void SetRowSize( int row, int height );
838 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
839
840 void SetColSize( int col, int width );
841 void SetDefaultCellBackgroundColour( const wxColour& );
842 void SetCellBackgroundColour( int row, int col, const wxColour& );
843 void SetDefaultCellTextColour( const wxColour& );
844
845 void SetCellTextColour( int row, int col, const wxColour& );
846 void SetDefaultCellFont( const wxFont& );
847 void SetCellFont( int row, int col, const wxFont& );
848 void SetDefaultCellAlignment( int horiz, int vert );
849 void SetCellAlignment( int row, int col, int horiz, int vert );
850
851 // takes ownership of the pointer
852 void SetDefaultRenderer(wxGridCellRenderer *renderer);
853 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
854 wxGridCellRenderer *GetDefaultRenderer() const;
855 wxGridCellRenderer* GetCellRenderer(int row, int col);
856
857 // takes ownership of the pointer
858 void SetDefaultEditor(wxGridCellEditor *editor);
859 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
860 wxGridCellEditor *GetDefaultEditor() const;
861 wxGridCellEditor* GetCellEditor(int row, int col);
862
863
864 // ------ cell value accessors
865 //
866 wxString GetCellValue( int row, int col )
867 {
868 if ( m_table )
869 {
870 return m_table->GetValue( row, col );
871 }
872 else
873 {
874 return wxEmptyString;
875 }
876 }
877
878 wxString GetCellValue( const wxGridCellCoords& coords )
879 { return GetCellValue( coords.GetRow(), coords.GetCol() ); }
880
881 void SetCellValue( int row, int col, const wxString& s );
882 void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
883 { SetCellValue( coords.GetRow(), coords.GetCol(), s ); }
884
885 // returns TRUE if the cell can't be edited
886 bool IsReadOnly(int row, int col) const;
887
888 // make the cell editable/readonly
889 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
890
891 // ------ selections of blocks of cells
892 //
893 void SelectRow( int row, bool addToSelected = FALSE );
894 void SelectCol( int col, bool addToSelected = FALSE );
895
896 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol );
897
898 void SelectBlock( const wxGridCellCoords& topLeft,
899 const wxGridCellCoords& bottomRight )
900 { SelectBlock( topLeft.GetRow(), topLeft.GetCol(),
901 bottomRight.GetRow(), bottomRight.GetCol() ); }
902
903 void SelectAll();
904
905 bool IsSelection()
906 { return ( m_selectedTopLeft != wxGridNoCellCoords &&
907 m_selectedBottomRight != wxGridNoCellCoords );
908 }
909
910 void ClearSelection();
911
912 bool IsInSelection( int row, int col )
913 { return ( IsSelection() &&
914 row >= m_selectedTopLeft.GetRow() &&
915 col >= m_selectedTopLeft.GetCol() &&
916 row <= m_selectedBottomRight.GetRow() &&
917 col <= m_selectedBottomRight.GetCol() );
918 }
919
920 bool IsInSelection( const wxGridCellCoords& coords )
921 { return IsInSelection( coords.GetRow(), coords.GetCol() ); }
922
923 void GetSelection( int* topRow, int* leftCol, int* bottomRow, int* rightCol )
924 {
925 // these will all be -1 if there is no selected block
926 //
927 *topRow = m_selectedTopLeft.GetRow();
928 *leftCol = m_selectedTopLeft.GetCol();
929 *bottomRow = m_selectedBottomRight.GetRow();
930 *rightCol = m_selectedBottomRight.GetCol();
931 }
932
933
934 // This function returns the rectangle that encloses the block of cells
935 // limited by TopLeft and BottomRight cell in device coords and clipped
936 // to the client size of the grid window.
937 //
938 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
939 const wxGridCellCoords & bottomRight );
940
941 // This function returns the rectangle that encloses the selected cells
942 // in device coords and clipped to the client size of the grid window.
943 //
944 wxRect SelectionToDeviceRect()
945 {
946 return BlockToDeviceRect( m_selectedTopLeft,
947 m_selectedBottomRight );
948 }
949
950 // Access or update the selection fore/back colours
951 wxColour GetSelectionBackground() const
952 { return m_selectionBackground; }
953 wxColour GetSelectionForeground() const
954 { return m_selectionForeground; }
955
956 void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; }
957 void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; }
958
959
960
961 // ------ For compatibility with previous wxGrid only...
962 //
963 // ************************************************
964 // ** Don't use these in new code because they **
965 // ** are liable to disappear in a future **
966 // ** revision **
967 // ************************************************
968 //
969
970 wxGrid( wxWindow *parent,
971 int x = -1, int y = -1, int w = -1, int h = -1,
972 long style = 0,
973 const wxString& name = wxPanelNameStr )
974 : wxScrolledWindow( parent, -1, wxPoint(x,y), wxSize(w,h), style, name )
975 {
976 Create();
977 }
978
979 void SetCellValue( const wxString& val, int row, int col )
980 { SetCellValue( row, col, val ); }
981
982 void UpdateDimensions()
983 { CalcDimensions(); }
984
985 int GetRows() { return GetNumberRows(); }
986 int GetCols() { return GetNumberCols(); }
987 int GetCursorRow() { return GetGridCursorRow(); }
988 int GetCursorColumn() { return GetGridCursorCol(); }
989
990 int GetScrollPosX() { return 0; }
991 int GetScrollPosY() { return 0; }
992
993 void SetScrollX( int x ) { }
994 void SetScrollY( int y ) { }
995
996 void SetColumnWidth( int col, int width )
997 { SetColSize( col, width ); }
998
999 int GetColumnWidth( int col )
1000 { return GetColSize( col ); }
1001
1002 void SetRowHeight( int row, int height )
1003 { SetRowSize( row, height ); }
1004
1005 int GetRowHeight( int row )
1006 { return GetRowSize( row ); }
1007
1008 int GetViewHeight() // returned num whole rows visible
1009 { return 0; }
1010
1011 int GetViewWidth() // returned num whole cols visible
1012 { return 0; }
1013
1014 void SetLabelSize( int orientation, int sz )
1015 {
1016 if ( orientation == wxHORIZONTAL )
1017 SetColLabelSize( sz );
1018 else
1019 SetRowLabelSize( sz );
1020 }
1021
1022 int GetLabelSize( int orientation )
1023 {
1024 if ( orientation == wxHORIZONTAL )
1025 return GetColLabelSize();
1026 else
1027 return GetRowLabelSize();
1028 }
1029
1030 void SetLabelAlignment( int orientation, int align )
1031 {
1032 if ( orientation == wxHORIZONTAL )
1033 SetColLabelAlignment( align, -1 );
1034 else
1035 SetRowLabelAlignment( align, -1 );
1036 }
1037
1038 int GetLabelAlignment( int orientation, int WXUNUSED(align) )
1039 {
1040 int h, v;
1041 if ( orientation == wxHORIZONTAL )
1042 {
1043 GetColLabelAlignment( &h, &v );
1044 return h;
1045 }
1046 else
1047 {
1048 GetRowLabelAlignment( &h, &v );
1049 return h;
1050 }
1051 }
1052
1053 void SetLabelValue( int orientation, const wxString& val, int pos )
1054 {
1055 if ( orientation == wxHORIZONTAL )
1056 SetColLabelValue( pos, val );
1057 else
1058 SetRowLabelValue( pos, val );
1059 }
1060
1061 wxString GetLabelValue( int orientation, int pos)
1062 {
1063 if ( orientation == wxHORIZONTAL )
1064 return GetColLabelValue( pos );
1065 else
1066 return GetRowLabelValue( pos );
1067 }
1068
1069 wxFont GetCellTextFont() const
1070 { return m_defaultCellAttr->GetFont(); }
1071
1072 wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const
1073 { return m_defaultCellAttr->GetFont(); }
1074
1075 void SetCellTextFont(const wxFont& fnt)
1076 { SetDefaultCellFont( fnt ); }
1077
1078 void SetCellTextFont(const wxFont& fnt, int row, int col)
1079 { SetCellFont( row, col, fnt ); }
1080
1081 void SetCellTextColour(const wxColour& val, int row, int col)
1082 { SetCellTextColour( row, col, val ); }
1083
1084 void SetCellTextColour(const wxColour& col)
1085 { SetDefaultCellTextColour( col ); }
1086
1087 void SetCellBackgroundColour(const wxColour& col)
1088 { SetDefaultCellBackgroundColour( col ); }
1089
1090 void SetCellBackgroundColour(const wxColour& colour, int row, int col)
1091 { SetCellBackgroundColour( row, col, colour ); }
1092
1093 bool GetEditable() { return IsEditable(); }
1094 void SetEditable( bool edit = TRUE ) { EnableEditing( edit ); }
1095 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
1096
1097 void SetEditInPlace(bool edit = TRUE) { }
1098
1099 void SetCellAlignment( int align, int row, int col)
1100 { SetCellAlignment(row, col, align, wxCENTER); }
1101 void SetCellAlignment( int WXUNUSED(align) ) {}
1102 void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col))
1103 { }
1104 void SetDividerPen(const wxPen& WXUNUSED(pen)) { }
1105 wxPen& GetDividerPen() const { return wxNullPen; }
1106 void OnActivate(bool WXUNUSED(active)) {}
1107
1108 // ******** End of compatibility functions **********
1109
1110
1111
1112 // ------ control IDs
1113 enum { wxGRID_CELLCTRL = 2000,
1114 wxGRID_TOPCTRL };
1115
1116 // ------ control types
1117 enum { wxGRID_TEXTCTRL = 2100,
1118 wxGRID_CHECKBOX,
1119 wxGRID_CHOICE,
1120 wxGRID_COMBOBOX };
1121
1122 // for wxGridCellBoolEditor
1123 wxWindow *GetGridWindow() const;
1124
1125 protected:
1126 bool m_created;
1127 bool m_displayed;
1128
1129 wxGridWindow *m_gridWin;
1130 wxGridRowLabelWindow *m_rowLabelWin;
1131 wxGridColLabelWindow *m_colLabelWin;
1132 wxGridCornerLabelWindow *m_cornerLabelWin;
1133
1134 wxGridTableBase *m_table;
1135 bool m_ownTable;
1136
1137 int m_left;
1138 int m_top;
1139 int m_right;
1140 int m_bottom;
1141
1142 int m_numRows;
1143 int m_numCols;
1144
1145 wxGridCellCoords m_currentCellCoords;
1146
1147 wxGridCellCoords m_selectedTopLeft;
1148 wxGridCellCoords m_selectedBottomRight;
1149 wxColour m_selectionBackground;
1150 wxColour m_selectionForeground;
1151
1152 int m_defaultRowHeight;
1153 wxArrayInt m_rowHeights;
1154 wxArrayInt m_rowBottoms;
1155
1156 int m_defaultColWidth;
1157 wxArrayInt m_colWidths;
1158 wxArrayInt m_colRights;
1159 int m_rowLabelWidth;
1160 int m_colLabelHeight;
1161
1162 wxColour m_labelBackgroundColour;
1163 wxColour m_labelTextColour;
1164 wxFont m_labelFont;
1165
1166 int m_rowLabelHorizAlign;
1167 int m_rowLabelVertAlign;
1168 int m_colLabelHorizAlign;
1169 int m_colLabelVertAlign;
1170
1171 bool m_defaultRowLabelValues;
1172 bool m_defaultColLabelValues;
1173
1174 wxColour m_gridLineColour;
1175 bool m_gridLinesEnabled;
1176
1177
1178 // do we have some place to store attributes in?
1179 bool CanHaveAttributes();
1180
1181 // returns the attribute we may modify in place: a new one if this cell
1182 // doesn't have any yet or the existing one if it does
1183 //
1184 // DecRef() must be called on the returned pointer, as usual
1185 wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const;
1186
1187 // cell attribute cache (currently we only cache 1, may be will do
1188 // more/better later)
1189 struct CachedAttr
1190 {
1191 int row, col;
1192 wxGridCellAttr *attr;
1193 } m_attrCache;
1194
1195 // invalidates the attribute cache
1196 void ClearAttrCache();
1197
1198 // adds an attribute to cache
1199 void CacheAttr(int row, int col, wxGridCellAttr *attr) const;
1200
1201 // looks for an attr in cache, returns TRUE if found
1202 bool LookupAttr(int row, int col, wxGridCellAttr **attr) const;
1203
1204 // looks for the attr in cache, if not found asks the table and caches the
1205 // result
1206 wxGridCellAttr *GetCellAttr(int row, int col) const;
1207 wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords )
1208 { return GetCellAttr( coords.GetRow(), coords.GetCol() ); }
1209
1210 // the default cell attr object for cells that don't have their own
1211 wxGridCellAttr* m_defaultCellAttr;
1212
1213
1214 wxGridCellCoordsArray m_cellsExposed;
1215 wxArrayInt m_rowsExposed;
1216 wxArrayInt m_colsExposed;
1217 wxArrayInt m_rowLabelsExposed;
1218 wxArrayInt m_colLabelsExposed;
1219
1220 bool m_inOnKeyDown;
1221 int m_batchCount;
1222
1223 enum CursorMode
1224 {
1225 WXGRID_CURSOR_SELECT_CELL,
1226 WXGRID_CURSOR_RESIZE_ROW,
1227 WXGRID_CURSOR_RESIZE_COL,
1228 WXGRID_CURSOR_SELECT_ROW,
1229 WXGRID_CURSOR_SELECT_COL
1230 };
1231
1232 // this method not only sets m_cursorMode but also sets the correct cursor
1233 // for the given mode and, if captureMouse is not FALSE releases the mouse
1234 // if it was captured and captures it if it must be captured
1235 //
1236 // for this to work, you should always use it and not set m_cursorMode
1237 // directly!
1238 void ChangeCursorMode(CursorMode mode,
1239 wxWindow *win = (wxWindow *)NULL,
1240 bool captureMouse = TRUE);
1241
1242 wxWindow *m_winCapture; // the window which captured the mouse
1243 CursorMode m_cursorMode;
1244
1245 int m_dragLastPos;
1246 int m_dragRowOrCol;
1247 bool m_isDragging;
1248 wxPoint m_startDragPos;
1249
1250 bool m_waitForSlowClick;
1251
1252 wxGridCellCoords m_selectionStart;
1253
1254 wxCursor m_rowResizeCursor;
1255 wxCursor m_colResizeCursor;
1256
1257 bool m_editable; // applies to whole grid
1258 bool m_cellEditCtrlEnabled; // is in-place edit currently shown?
1259
1260
1261 void Create();
1262 void Init();
1263 void CalcDimensions();
1264 void CalcWindowSizes();
1265 bool Redimension( wxGridTableMessage& );
1266
1267
1268 bool SendEvent( const wxEventType, int row, int col, wxMouseEvent& );
1269 bool SendEvent( const wxEventType, int row, int col );
1270 bool SendEvent( const wxEventType type)
1271 {
1272 return SendEvent(type,
1273 m_currentCellCoords.GetRow(),
1274 m_currentCellCoords.GetCol());
1275 }
1276
1277 void OnPaint( wxPaintEvent& );
1278 void OnSize( wxSizeEvent& );
1279 void OnKeyDown( wxKeyEvent& );
1280 void OnEraseBackground( wxEraseEvent& );
1281
1282
1283 void SetCurrentCell( const wxGridCellCoords& coords );
1284 void SetCurrentCell( int row, int col )
1285 { SetCurrentCell( wxGridCellCoords(row, col) ); }
1286
1287
1288 // ------ functions to get/send data (see also public functions)
1289 //
1290 bool GetModelValues();
1291 bool SetModelValues();
1292
1293
1294 DECLARE_DYNAMIC_CLASS( wxGrid )
1295 DECLARE_EVENT_TABLE()
1296 };
1297
1298
1299
1300
1301
1302 //
1303 // ------ Grid event class and event types
1304 //
1305
1306 class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
1307 {
1308 public:
1309 wxGridEvent()
1310 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
1311 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1312 {
1313 }
1314
1315 wxGridEvent(int id, wxEventType type, wxObject* obj,
1316 int row=-1, int col=-1, int x=-1, int y=-1,
1317 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1318
1319 virtual int GetRow() { return m_row; }
1320 virtual int GetCol() { return m_col; }
1321 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
1322 bool ControlDown() { return m_control; }
1323 bool MetaDown() { return m_meta; }
1324 bool ShiftDown() { return m_shift; }
1325 bool AltDown() { return m_alt; }
1326
1327 protected:
1328 int m_row;
1329 int m_col;
1330 int m_x;
1331 int m_y;
1332 bool m_control;
1333 bool m_meta;
1334 bool m_shift;
1335 bool m_alt;
1336
1337 DECLARE_DYNAMIC_CLASS(wxGridEvent)
1338 };
1339
1340 class WXDLLEXPORT wxGridSizeEvent : public wxNotifyEvent
1341 {
1342 public:
1343 wxGridSizeEvent()
1344 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1345 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1346 {
1347 }
1348
1349 wxGridSizeEvent(int id, wxEventType type, wxObject* obj,
1350 int rowOrCol=-1, int x=-1, int y=-1,
1351 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1352
1353 int GetRowOrCol() { return m_rowOrCol; }
1354 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
1355 bool ControlDown() { return m_control; }
1356 bool MetaDown() { return m_meta; }
1357 bool ShiftDown() { return m_shift; }
1358 bool AltDown() { return m_alt; }
1359
1360 protected:
1361 int m_rowOrCol;
1362 int m_x;
1363 int m_y;
1364 bool m_control;
1365 bool m_meta;
1366 bool m_shift;
1367 bool m_alt;
1368
1369 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent)
1370 };
1371
1372
1373 class WXDLLEXPORT wxGridRangeSelectEvent : public wxNotifyEvent
1374 {
1375 public:
1376 wxGridRangeSelectEvent()
1377 : wxNotifyEvent()
1378 {
1379 m_topLeft = wxGridNoCellCoords;
1380 m_bottomRight = wxGridNoCellCoords;
1381 m_control = FALSE;
1382 m_meta = FALSE;
1383 m_shift = FALSE;
1384 m_alt = FALSE;
1385 }
1386
1387 wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj,
1388 const wxGridCellCoords& topLeft,
1389 const wxGridCellCoords& bottomRight,
1390 bool control=FALSE, bool shift=FALSE,
1391 bool alt=FALSE, bool meta=FALSE);
1392
1393 wxGridCellCoords GetTopLeftCoords() { return m_topLeft; }
1394 wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; }
1395 int GetTopRow() { return m_topLeft.GetRow(); }
1396 int GetBottomRow() { return m_bottomRight.GetRow(); }
1397 int GetLeftCol() { return m_topLeft.GetCol(); }
1398 int GetRightCol() { return m_bottomRight.GetCol(); }
1399 bool ControlDown() { return m_control; }
1400 bool MetaDown() { return m_meta; }
1401 bool ShiftDown() { return m_shift; }
1402 bool AltDown() { return m_alt; }
1403
1404 protected:
1405 wxGridCellCoords m_topLeft;
1406 wxGridCellCoords m_bottomRight;
1407 bool m_control;
1408 bool m_meta;
1409 bool m_shift;
1410 bool m_alt;
1411
1412 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent)
1413 };
1414
1415 // TODO move to wx/event.h
1416 const wxEventType wxEVT_GRID_CELL_LEFT_CLICK = wxEVT_FIRST + 1580;
1417 const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK = wxEVT_FIRST + 1581;
1418 const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK = wxEVT_FIRST + 1582;
1419 const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK = wxEVT_FIRST + 1583;
1420 const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK = wxEVT_FIRST + 1584;
1421 const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK = wxEVT_FIRST + 1585;
1422 const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK = wxEVT_FIRST + 1586;
1423 const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK = wxEVT_FIRST + 1587;
1424 const wxEventType wxEVT_GRID_ROW_SIZE = wxEVT_FIRST + 1588;
1425 const wxEventType wxEVT_GRID_COL_SIZE = wxEVT_FIRST + 1589;
1426 const wxEventType wxEVT_GRID_RANGE_SELECT = wxEVT_FIRST + 1590;
1427 const wxEventType wxEVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1591;
1428 const wxEventType wxEVT_GRID_SELECT_CELL = wxEVT_FIRST + 1592;
1429 const wxEventType wxEVT_GRID_EDITOR_SHOWN = wxEVT_FIRST + 1593;
1430 const wxEventType wxEVT_GRID_EDITOR_HIDDEN = wxEVT_FIRST + 1594;
1431
1432
1433 typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
1434 typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
1435 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
1436
1437 #define EVT_GRID_CELL_LEFT_CLICK(fn) { wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1438 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1439 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1440 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1441 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1442 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1443 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1444 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1445 #define EVT_GRID_ROW_SIZE(fn) { wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1446 #define EVT_GRID_COL_SIZE(fn) { wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1447 #define EVT_GRID_RANGE_SELECT(fn) { wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1448 #define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1449 #define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1450 #define EVT_GRID_EDITOR_SHOWN(fn) { wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1451 #define EVT_GRID_EDITOR_HIDDEN(fn) { wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1452
1453
1454 #if 0 // TODO: implement these ? others ?
1455
1456 const wxEventType wxEVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576;
1457 const wxEventType wxEVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577;
1458 const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578;
1459
1460 #define EVT_GRID_CREATE_CELL(fn) { wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1461 #define EVT_GRID_CHANGE_LABELS(fn) { wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1462 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1463
1464 #endif
1465
1466 #endif // #ifndef __WXGRID_H__
1467
1468 #endif // ifndef wxUSE_NEW_GRID
1469