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