]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/grid.h
detect and report errors in XRC specification of grid sizers
[wxWidgets.git] / include / wx / generic / grid.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/grid.h
3 // Purpose: wxGrid and related classes
4 // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
5 // Modified by: Santiago Palacios
6 // Created: 1/08/1999
7 // RCS-ID: $Id$
8 // Copyright: (c) Michael Bedward
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GENERIC_GRID_H_
13 #define _WX_GENERIC_GRID_H_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_GRID
18
19 #include "wx/scrolwin.h"
20
21 // ----------------------------------------------------------------------------
22 // constants
23 // ----------------------------------------------------------------------------
24
25 extern WXDLLIMPEXP_DATA_ADV(const char) wxGridNameStr[];
26
27 // Default parameters for wxGrid
28 //
29 #define WXGRID_DEFAULT_NUMBER_ROWS 10
30 #define WXGRID_DEFAULT_NUMBER_COLS 10
31 #if defined(__WXMSW__) || defined(__WXGTK20__)
32 #define WXGRID_DEFAULT_ROW_HEIGHT 25
33 #else
34 #define WXGRID_DEFAULT_ROW_HEIGHT 30
35 #endif // __WXMSW__
36 #define WXGRID_DEFAULT_COL_WIDTH 80
37 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
38 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
39 #define WXGRID_LABEL_EDGE_ZONE 2
40 #define WXGRID_MIN_ROW_HEIGHT 15
41 #define WXGRID_MIN_COL_WIDTH 15
42 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
43
44 // type names for grid table values
45 #define wxGRID_VALUE_STRING _T("string")
46 #define wxGRID_VALUE_BOOL _T("bool")
47 #define wxGRID_VALUE_NUMBER _T("long")
48 #define wxGRID_VALUE_FLOAT _T("double")
49 #define wxGRID_VALUE_CHOICE _T("choice")
50
51 #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
52 #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
53
54 // magic constant which tells (to some functions) to automatically calculate
55 // the appropriate size
56 #define wxGRID_AUTOSIZE (-1)
57
58 // many wxGrid methods work either with columns or rows, this enum is used for
59 // the parameter indicating which one should it be
60 enum wxGridDirection
61 {
62 wxGRID_COLUMN,
63 wxGRID_ROW
64 };
65
66 // ----------------------------------------------------------------------------
67 // forward declarations
68 // ----------------------------------------------------------------------------
69
70 class WXDLLIMPEXP_FWD_ADV wxGrid;
71 class WXDLLIMPEXP_FWD_ADV wxGridCellAttr;
72 class WXDLLIMPEXP_FWD_ADV wxGridCellAttrProviderData;
73 class WXDLLIMPEXP_FWD_ADV wxGridColLabelWindow;
74 class WXDLLIMPEXP_FWD_ADV wxGridCornerLabelWindow;
75 class WXDLLIMPEXP_FWD_ADV wxGridRowLabelWindow;
76 class WXDLLIMPEXP_FWD_ADV wxGridWindow;
77 class WXDLLIMPEXP_FWD_ADV wxGridTypeRegistry;
78 class WXDLLIMPEXP_FWD_ADV wxGridSelection;
79
80 class WXDLLIMPEXP_FWD_CORE wxHeaderCtrl;
81 class WXDLLIMPEXP_FWD_CORE wxCheckBox;
82 class WXDLLIMPEXP_FWD_CORE wxComboBox;
83 class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
84 #if wxUSE_SPINCTRL
85 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl;
86 #endif
87
88 class wxGridOperations;
89 class wxGridRowOperations;
90 class wxGridColumnOperations;
91 class wxGridDirectionOperations;
92
93
94 // ----------------------------------------------------------------------------
95 // macros
96 // ----------------------------------------------------------------------------
97
98 #define wxSafeIncRef(p) if ( p ) (p)->IncRef()
99 #define wxSafeDecRef(p) if ( p ) (p)->DecRef()
100
101 // ----------------------------------------------------------------------------
102 // wxGridCellWorker: common base class for wxGridCellRenderer and
103 // wxGridCellEditor
104 //
105 // NB: this is more an implementation convenience than a design issue, so this
106 // class is not documented and is not public at all
107 // ----------------------------------------------------------------------------
108
109 class WXDLLIMPEXP_ADV wxGridCellWorker : public wxClientDataContainer
110 {
111 public:
112 wxGridCellWorker() { m_nRef = 1; }
113
114 // this class is ref counted: it is created with ref count of 1, so
115 // calling DecRef() once will delete it. Calling IncRef() allows to lock
116 // it until the matching DecRef() is called
117 void IncRef() { m_nRef++; }
118 void DecRef() { if ( --m_nRef == 0 ) delete this; }
119
120 // interpret renderer parameters: arbitrary string whose interpretatin is
121 // left to the derived classes
122 virtual void SetParameters(const wxString& params);
123
124 protected:
125 // virtual dtor for any base class - private because only DecRef() can
126 // delete us
127 virtual ~wxGridCellWorker();
128
129 private:
130 size_t m_nRef;
131
132 // suppress the stupid gcc warning about the class having private dtor and
133 // no friends
134 friend class wxGridCellWorkerDummyFriend;
135 };
136
137 // ----------------------------------------------------------------------------
138 // wxGridCellRenderer: this class is responsible for actually drawing the cell
139 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
140 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
141 // view of all cells. This is an ABC, you will normally use one of the
142 // predefined derived classes or derive your own class from it.
143 // ----------------------------------------------------------------------------
144
145 class WXDLLIMPEXP_ADV wxGridCellRenderer : public wxGridCellWorker
146 {
147 public:
148 // draw the given cell on the provided DC inside the given rectangle
149 // using the style specified by the attribute and the default or selected
150 // state corresponding to the isSelected value.
151 //
152 // this pure virtual function has a default implementation which will
153 // prepare the DC using the given attribute: it will draw the rectangle
154 // with the bg colour from attr and set the text colour and font
155 virtual void Draw(wxGrid& grid,
156 wxGridCellAttr& attr,
157 wxDC& dc,
158 const wxRect& rect,
159 int row, int col,
160 bool isSelected) = 0;
161
162 // get the preferred size of the cell for its contents
163 virtual wxSize GetBestSize(wxGrid& grid,
164 wxGridCellAttr& attr,
165 wxDC& dc,
166 int row, int col) = 0;
167
168 // create a new object which is the copy of this one
169 virtual wxGridCellRenderer *Clone() const = 0;
170 };
171
172 // ----------------------------------------------------------------------------
173 // wxGridCellEditor: This class is responsible for providing and manipulating
174 // the in-place edit controls for the grid. Instances of wxGridCellEditor
175 // (actually, instances of derived classes since it is an ABC) can be
176 // associated with the cell attributes for individual cells, rows, columns, or
177 // even for the entire grid.
178 // ----------------------------------------------------------------------------
179
180 class WXDLLIMPEXP_ADV wxGridCellEditor : public wxGridCellWorker
181 {
182 public:
183 wxGridCellEditor();
184
185 bool IsCreated() { return m_control != NULL; }
186 wxControl* GetControl() { return m_control; }
187 void SetControl(wxControl* control) { m_control = control; }
188
189 wxGridCellAttr* GetCellAttr() { return m_attr; }
190 void SetCellAttr(wxGridCellAttr* attr) { m_attr = attr; }
191
192 // Creates the actual edit control
193 virtual void Create(wxWindow* parent,
194 wxWindowID id,
195 wxEvtHandler* evtHandler) = 0;
196
197 // Size and position the edit control
198 virtual void SetSize(const wxRect& rect);
199
200 // Show or hide the edit control, use the specified attributes to set
201 // colours/fonts for it
202 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
203
204 // Draws the part of the cell not occupied by the control: the base class
205 // version just fills it with background colour from the attribute
206 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
207
208
209 // The methods called by wxGrid when a cell is edited: first BeginEdit() is
210 // called, then EndEdit() is and if it returns true and if the change is
211 // not vetoed by a user-defined event handler, finally ApplyEdit() is called
212
213 // Fetch the value from the table and prepare the edit control
214 // to begin editing. Set the focus to the edit control.
215 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
216
217 // Returns false if nothing changed, otherwise returns true and return the
218 // new value in its string form in the newval output parameter.
219 //
220 // This should also store the new value in its real type internally so that
221 // it could be used by ApplyEdit() but it must not modify the grid as the
222 // change could still be vetoed.
223 virtual bool EndEdit(int row, int col, const wxGrid *grid,
224 const wxString& oldval, wxString *newval) = 0;
225
226 // Complete the editing of the current cell by storing the value saved by
227 // the previous call to EndEdit() in the grid
228 virtual void ApplyEdit(int row, int col, wxGrid* grid) = 0;
229
230
231 // Reset the value in the control back to its starting value
232 virtual void Reset() = 0;
233
234 // return true to allow the given key to start editing: the base class
235 // version only checks that the event has no modifiers. The derived
236 // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
237 // their IsAcceptedKey() implementation, although, of course, it is not a
238 // mandatory requirment.
239 //
240 // NB: if the key is F2 (special), editing will always start and this
241 // method will not be called at all (but StartingKey() will)
242 virtual bool IsAcceptedKey(wxKeyEvent& event);
243
244 // If the editor is enabled by pressing keys on the grid, this will be
245 // called to let the editor do something about that first key if desired
246 virtual void StartingKey(wxKeyEvent& event);
247
248 // if the editor is enabled by clicking on the cell, this method will be
249 // called
250 virtual void StartingClick();
251
252 // Some types of controls on some platforms may need some help
253 // with the Return key.
254 virtual void HandleReturn(wxKeyEvent& event);
255
256 // Final cleanup
257 virtual void Destroy();
258
259 // create a new object which is the copy of this one
260 virtual wxGridCellEditor *Clone() const = 0;
261
262 // added GetValue so we can get the value which is in the control
263 virtual wxString GetValue() const = 0;
264
265 protected:
266 // the dtor is private because only DecRef() can delete us
267 virtual ~wxGridCellEditor();
268
269 // the control we show on screen
270 wxControl* m_control;
271
272 // a temporary pointer to the attribute being edited
273 wxGridCellAttr* m_attr;
274
275 // if we change the colours/font of the control from the default ones, we
276 // must restore the default later and we save them here between calls to
277 // Show(true) and Show(false)
278 wxColour m_colFgOld,
279 m_colBgOld;
280 wxFont m_fontOld;
281
282 // suppress the stupid gcc warning about the class having private dtor and
283 // no friends
284 friend class wxGridCellEditorDummyFriend;
285
286 wxDECLARE_NO_COPY_CLASS(wxGridCellEditor);
287 };
288
289
290 // ----------------------------------------------------------------------------
291 // wxGridCellAttr: this class can be used to alter the cells appearance in
292 // the grid by changing their colour/font/... from default. An object of this
293 // class may be returned by wxGridTable::GetAttr().
294 // ----------------------------------------------------------------------------
295
296 class WXDLLIMPEXP_ADV wxGridCellAttr : public wxClientDataContainer
297 {
298 public:
299 enum wxAttrKind
300 {
301 Any,
302 Default,
303 Cell,
304 Row,
305 Col,
306 Merged
307 };
308
309 // ctors
310 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL)
311 {
312 Init(attrDefault);
313
314 // MB: args used to be 0,0 here but wxALIGN_LEFT is 0
315 SetAlignment(-1, -1);
316 }
317
318 // VZ: considering the number of members wxGridCellAttr has now, this ctor
319 // seems to be pretty useless... may be we should just remove it?
320 wxGridCellAttr(const wxColour& colText,
321 const wxColour& colBack,
322 const wxFont& font,
323 int hAlign,
324 int vAlign)
325 : m_colText(colText), m_colBack(colBack), m_font(font)
326 {
327 Init();
328 SetAlignment(hAlign, vAlign);
329 }
330
331 // creates a new copy of this object
332 wxGridCellAttr *Clone() const;
333 void MergeWith(wxGridCellAttr *mergefrom);
334
335 // this class is ref counted: it is created with ref count of 1, so
336 // calling DecRef() once will delete it. Calling IncRef() allows to lock
337 // it until the matching DecRef() is called
338 void IncRef() { m_nRef++; }
339 void DecRef() { if ( --m_nRef == 0 ) delete this; }
340
341 // setters
342 void SetTextColour(const wxColour& colText) { m_colText = colText; }
343 void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; }
344 void SetFont(const wxFont& font) { m_font = font; }
345 void SetAlignment(int hAlign, int vAlign)
346 {
347 m_hAlign = hAlign;
348 m_vAlign = vAlign;
349 }
350 void SetSize(int num_rows, int num_cols);
351 void SetOverflow(bool allow = true)
352 { m_overflow = allow ? Overflow : SingleCell; }
353 void SetReadOnly(bool isReadOnly = true)
354 { m_isReadOnly = isReadOnly ? ReadOnly : ReadWrite; }
355
356 // takes ownership of the pointer
357 void SetRenderer(wxGridCellRenderer *renderer)
358 { wxSafeDecRef(m_renderer); m_renderer = renderer; }
359 void SetEditor(wxGridCellEditor* editor)
360 { wxSafeDecRef(m_editor); m_editor = editor; }
361
362 void SetKind(wxAttrKind kind) { m_attrkind = kind; }
363
364 // accessors
365 bool HasTextColour() const { return m_colText.Ok(); }
366 bool HasBackgroundColour() const { return m_colBack.Ok(); }
367 bool HasFont() const { return m_font.Ok(); }
368 bool HasAlignment() const { return (m_hAlign != -1 || m_vAlign != -1); }
369 bool HasRenderer() const { return m_renderer != NULL; }
370 bool HasEditor() const { return m_editor != NULL; }
371 bool HasReadWriteMode() const { return m_isReadOnly != Unset; }
372 bool HasOverflowMode() const { return m_overflow != UnsetOverflow; }
373 bool HasSize() const { return m_sizeRows != 1 || m_sizeCols != 1; }
374
375 const wxColour& GetTextColour() const;
376 const wxColour& GetBackgroundColour() const;
377 const wxFont& GetFont() const;
378 void GetAlignment(int *hAlign, int *vAlign) const;
379 void GetSize(int *num_rows, int *num_cols) const;
380 bool GetOverflow() const
381 { return m_overflow != SingleCell; }
382 wxGridCellRenderer *GetRenderer(const wxGrid* grid, int row, int col) const;
383 wxGridCellEditor *GetEditor(const wxGrid* grid, int row, int col) const;
384
385 bool IsReadOnly() const { return m_isReadOnly == wxGridCellAttr::ReadOnly; }
386
387 wxAttrKind GetKind() { return m_attrkind; }
388
389 void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; }
390
391 protected:
392 // the dtor is private because only DecRef() can delete us
393 virtual ~wxGridCellAttr()
394 {
395 wxSafeDecRef(m_renderer);
396 wxSafeDecRef(m_editor);
397 }
398
399 private:
400 enum wxAttrReadMode
401 {
402 Unset = -1,
403 ReadWrite,
404 ReadOnly
405 };
406
407 enum wxAttrOverflowMode
408 {
409 UnsetOverflow = -1,
410 Overflow,
411 SingleCell
412 };
413
414 // the common part of all ctors
415 void Init(wxGridCellAttr *attrDefault = NULL);
416
417
418 // the ref count - when it goes to 0, we die
419 size_t m_nRef;
420
421 wxColour m_colText,
422 m_colBack;
423 wxFont m_font;
424 int m_hAlign,
425 m_vAlign;
426 int m_sizeRows,
427 m_sizeCols;
428
429 wxAttrOverflowMode m_overflow;
430
431 wxGridCellRenderer* m_renderer;
432 wxGridCellEditor* m_editor;
433 wxGridCellAttr* m_defGridAttr;
434
435 wxAttrReadMode m_isReadOnly;
436
437 wxAttrKind m_attrkind;
438
439 // use Clone() instead
440 wxDECLARE_NO_COPY_CLASS(wxGridCellAttr);
441
442 // suppress the stupid gcc warning about the class having private dtor and
443 // no friends
444 friend class wxGridCellAttrDummyFriend;
445 };
446
447 // ----------------------------------------------------------------------------
448 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
449 // cell attributes.
450 // ----------------------------------------------------------------------------
451
452 // implementation note: we separate it from wxGridTableBase because we wish to
453 // avoid deriving a new table class if possible, and sometimes it will be
454 // enough to just derive another wxGridCellAttrProvider instead
455 //
456 // the default implementation is reasonably efficient for the generic case,
457 // but you might still wish to implement your own for some specific situations
458 // if you have performance problems with the stock one
459 class WXDLLIMPEXP_ADV wxGridCellAttrProvider : public wxClientDataContainer
460 {
461 public:
462 wxGridCellAttrProvider();
463 virtual ~wxGridCellAttrProvider();
464
465 // DecRef() must be called on the returned pointer
466 virtual wxGridCellAttr *GetAttr(int row, int col,
467 wxGridCellAttr::wxAttrKind kind ) const;
468
469 // all these functions take ownership of the pointer, don't call DecRef()
470 // on it
471 virtual void SetAttr(wxGridCellAttr *attr, int row, int col);
472 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
473 virtual void SetColAttr(wxGridCellAttr *attr, int col);
474
475 // these functions must be called whenever some rows/cols are deleted
476 // because the internal data must be updated then
477 void UpdateAttrRows( size_t pos, int numRows );
478 void UpdateAttrCols( size_t pos, int numCols );
479
480 private:
481 void InitData();
482
483 wxGridCellAttrProviderData *m_data;
484
485 wxDECLARE_NO_COPY_CLASS(wxGridCellAttrProvider);
486 };
487
488 // ----------------------------------------------------------------------------
489 // wxGridCellCoords: location of a cell in the grid
490 // ----------------------------------------------------------------------------
491
492 class WXDLLIMPEXP_ADV wxGridCellCoords
493 {
494 public:
495 wxGridCellCoords() { m_row = m_col = -1; }
496 wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; }
497
498 // default copy ctor is ok
499
500 int GetRow() const { return m_row; }
501 void SetRow( int n ) { m_row = n; }
502 int GetCol() const { return m_col; }
503 void SetCol( int n ) { m_col = n; }
504 void Set( int row, int col ) { m_row = row; m_col = col; }
505
506 wxGridCellCoords& operator=( const wxGridCellCoords& other )
507 {
508 if ( &other != this )
509 {
510 m_row=other.m_row;
511 m_col=other.m_col;
512 }
513 return *this;
514 }
515
516 bool operator==( const wxGridCellCoords& other ) const
517 {
518 return (m_row == other.m_row && m_col == other.m_col);
519 }
520
521 bool operator!=( const wxGridCellCoords& other ) const
522 {
523 return (m_row != other.m_row || m_col != other.m_col);
524 }
525
526 bool operator!() const
527 {
528 return (m_row == -1 && m_col == -1 );
529 }
530
531 private:
532 int m_row;
533 int m_col;
534 };
535
536
537 // For comparisons...
538 //
539 extern WXDLLIMPEXP_ADV wxGridCellCoords wxGridNoCellCoords;
540 extern WXDLLIMPEXP_ADV wxRect wxGridNoCellRect;
541
542 // An array of cell coords...
543 //
544 WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords, wxGridCellCoordsArray,
545 class WXDLLIMPEXP_ADV);
546
547 // ----------------------------------------------------------------------------
548 // Grid table classes
549 // ----------------------------------------------------------------------------
550
551 // the abstract base class
552 class WXDLLIMPEXP_ADV wxGridTableBase : public wxObject,
553 public wxClientDataContainer
554 {
555 public:
556 wxGridTableBase();
557 virtual ~wxGridTableBase();
558
559 // You must override these functions in a derived table class
560 //
561
562 // return the number of rows and columns in this table
563 virtual int GetNumberRows() = 0;
564 virtual int GetNumberCols() = 0;
565
566 // the methods above are unfortunately non-const even though they should
567 // have been const -- but changing it now is not possible any longer as it
568 // would break the existing code overriding them, so instead we provide
569 // these const synonyms which can be used from const-correct code
570 int GetRowsCount() const
571 { return const_cast<wxGridTableBase *>(this)->GetNumberRows(); }
572 int GetColsCount() const
573 { return const_cast<wxGridTableBase *>(this)->GetNumberCols(); }
574
575
576 virtual bool IsEmptyCell( int row, int col )
577 {
578 return GetValue(row, col).empty();
579 }
580
581 bool IsEmpty(const wxGridCellCoords& coord)
582 {
583 return IsEmptyCell(coord.GetRow(), coord.GetCol());
584 }
585
586 virtual wxString GetValue( int row, int col ) = 0;
587 virtual void SetValue( int row, int col, const wxString& value ) = 0;
588
589 // Data type determination and value access
590 virtual wxString GetTypeName( int row, int col );
591 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
592 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
593
594 virtual long GetValueAsLong( int row, int col );
595 virtual double GetValueAsDouble( int row, int col );
596 virtual bool GetValueAsBool( int row, int col );
597
598 virtual void SetValueAsLong( int row, int col, long value );
599 virtual void SetValueAsDouble( int row, int col, double value );
600 virtual void SetValueAsBool( int row, int col, bool value );
601
602 // For user defined types
603 virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
604 virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
605
606
607 // Overriding these is optional
608 //
609 virtual void SetView( wxGrid *grid ) { m_view = grid; }
610 virtual wxGrid * GetView() const { return m_view; }
611
612 virtual void Clear() {}
613 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
614 virtual bool AppendRows( size_t numRows = 1 );
615 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
616 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
617 virtual bool AppendCols( size_t numCols = 1 );
618 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
619
620 virtual wxString GetRowLabelValue( int row );
621 virtual wxString GetColLabelValue( int col );
622 virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {}
623 virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {}
624
625 // Attribute handling
626 //
627
628 // give us the attr provider to use - we take ownership of the pointer
629 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
630
631 // get the currently used attr provider (may be NULL)
632 wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; }
633
634 // Does this table allow attributes? Default implementation creates
635 // a wxGridCellAttrProvider if necessary.
636 virtual bool CanHaveAttributes();
637
638 // by default forwarded to wxGridCellAttrProvider if any. May be
639 // overridden to handle attributes directly in the table.
640 virtual wxGridCellAttr *GetAttr( int row, int col,
641 wxGridCellAttr::wxAttrKind kind );
642
643
644 // these functions take ownership of the pointer
645 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
646 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
647 virtual void SetColAttr(wxGridCellAttr *attr, int col);
648
649 private:
650 wxGrid * m_view;
651 wxGridCellAttrProvider *m_attrProvider;
652
653 DECLARE_ABSTRACT_CLASS(wxGridTableBase)
654 wxDECLARE_NO_COPY_CLASS(wxGridTableBase);
655 };
656
657
658 // ----------------------------------------------------------------------------
659 // wxGridTableMessage
660 // ----------------------------------------------------------------------------
661
662 // IDs for messages sent from grid table to view
663 //
664 enum wxGridTableRequest
665 {
666 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
667 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
668 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
669 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
670 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
671 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
672 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
673 wxGRIDTABLE_NOTIFY_COLS_DELETED
674 };
675
676 class WXDLLIMPEXP_ADV wxGridTableMessage
677 {
678 public:
679 wxGridTableMessage();
680 wxGridTableMessage( wxGridTableBase *table, int id,
681 int comInt1 = -1,
682 int comInt2 = -1 );
683
684 void SetTableObject( wxGridTableBase *table ) { m_table = table; }
685 wxGridTableBase * GetTableObject() const { return m_table; }
686 void SetId( int id ) { m_id = id; }
687 int GetId() { return m_id; }
688 void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; }
689 int GetCommandInt() { return m_comInt1; }
690 void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; }
691 int GetCommandInt2() { return m_comInt2; }
692
693 private:
694 wxGridTableBase *m_table;
695 int m_id;
696 int m_comInt1;
697 int m_comInt2;
698
699 wxDECLARE_NO_COPY_CLASS(wxGridTableMessage);
700 };
701
702
703
704 // ------ wxGridStringArray
705 // A 2-dimensional array of strings for data values
706 //
707
708 WX_DECLARE_OBJARRAY_WITH_DECL(wxArrayString, wxGridStringArray,
709 class WXDLLIMPEXP_ADV);
710
711
712
713 // ------ wxGridStringTable
714 //
715 // Simplest type of data table for a grid for small tables of strings
716 // that are stored in memory
717 //
718
719 class WXDLLIMPEXP_ADV wxGridStringTable : public wxGridTableBase
720 {
721 public:
722 wxGridStringTable();
723 wxGridStringTable( int numRows, int numCols );
724 virtual ~wxGridStringTable();
725
726 // these are pure virtual in wxGridTableBase
727 //
728 int GetNumberRows();
729 int GetNumberCols();
730 wxString GetValue( int row, int col );
731 void SetValue( int row, int col, const wxString& s );
732
733 // overridden functions from wxGridTableBase
734 //
735 void Clear();
736 bool InsertRows( size_t pos = 0, size_t numRows = 1 );
737 bool AppendRows( size_t numRows = 1 );
738 bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
739 bool InsertCols( size_t pos = 0, size_t numCols = 1 );
740 bool AppendCols( size_t numCols = 1 );
741 bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
742
743 void SetRowLabelValue( int row, const wxString& );
744 void SetColLabelValue( int col, const wxString& );
745 wxString GetRowLabelValue( int row );
746 wxString GetColLabelValue( int col );
747
748 private:
749 wxGridStringArray m_data;
750
751 // These only get used if you set your own labels, otherwise the
752 // GetRow/ColLabelValue functions return wxGridTableBase defaults
753 //
754 wxArrayString m_rowLabels;
755 wxArrayString m_colLabels;
756
757 DECLARE_DYNAMIC_CLASS_NO_COPY( wxGridStringTable )
758 };
759
760
761
762 // ============================================================================
763 // Grid view classes
764 // ============================================================================
765
766 // ----------------------------------------------------------------------------
767 // wxGridSizesInfo stores information about sizes of the rows or columns.
768 //
769 // It assumes that most of the columns or rows have default size and so stores
770 // the default size separately and uses a hash to map column or row numbers to
771 // their non default size for those which don't have the default size.
772 // ----------------------------------------------------------------------------
773
774 // Hashmap to store postions as the keys and sizes as the values
775 WX_DECLARE_HASH_MAP_WITH_DECL( unsigned, int, wxIntegerHash, wxIntegerEqual,
776 wxUnsignedToIntHashMap, class WXDLLIMPEXP_ADV );
777
778 struct WXDLLIMPEXP_ADV wxGridSizesInfo
779 {
780 // default ctor, initialize m_sizeDefault and m_customSizes later
781 wxGridSizesInfo() { }
782
783 // ctor used by wxGrid::Get{Col,Row}Sizes()
784 wxGridSizesInfo(int defSize, const wxArrayInt& allSizes);
785
786 // default copy ctor, assignment operator and dtor are ok
787
788 // Get the size of the element with the given index
789 int GetSize(unsigned pos) const;
790
791
792 // default size
793 int m_sizeDefault;
794
795 // position -> size map containing all elements with non-default size
796 wxUnsignedToIntHashMap m_customSizes;
797 };
798
799 // ----------------------------------------------------------------------------
800 // wxGrid
801 // ----------------------------------------------------------------------------
802
803 class WXDLLIMPEXP_ADV wxGrid : public wxScrolledWindow
804 {
805 public:
806 // possible selection modes
807 enum wxGridSelectionModes
808 {
809 wxGridSelectCells = 0, // allow selecting anything
810 wxGridSelectRows = 1, // allow selecting only entire rows
811 wxGridSelectColumns = 2, // allow selecting only entire columns
812 wxGridSelectRowsOrColumns = wxGridSelectRows | wxGridSelectColumns
813 };
814
815 // creation and destruction
816 // ------------------------
817
818 // ctor and Create() create the grid window, as with the other controls
819 wxGrid() { Init(); }
820
821 wxGrid(wxWindow *parent,
822 wxWindowID id,
823 const wxPoint& pos = wxDefaultPosition,
824 const wxSize& size = wxDefaultSize,
825 long style = wxWANTS_CHARS,
826 const wxString& name = wxGridNameStr)
827 {
828 Init();
829
830 Create(parent, id, pos, size, style, name);
831 }
832
833 bool Create(wxWindow *parent,
834 wxWindowID id,
835 const wxPoint& pos = wxDefaultPosition,
836 const wxSize& size = wxDefaultSize,
837 long style = wxWANTS_CHARS,
838 const wxString& name = wxGridNameStr);
839
840 virtual ~wxGrid();
841
842 // however to initialize grid data either CreateGrid() or SetTable() must
843 // be also called
844
845 // this is basically equivalent to
846 //
847 // SetTable(new wxGridStringTable(numRows, numCols), true, selmode)
848 //
849 bool CreateGrid( int numRows, int numCols,
850 wxGridSelectionModes selmode = wxGridSelectCells );
851
852 bool SetTable( wxGridTableBase *table,
853 bool takeOwnership = false,
854 wxGridSelectionModes selmode = wxGridSelectCells );
855
856 bool ProcessTableMessage(wxGridTableMessage&);
857
858 wxGridTableBase *GetTable() const { return m_table; }
859
860
861 void SetSelectionMode(wxGridSelectionModes selmode);
862 wxGridSelectionModes GetSelectionMode() const;
863
864 // ------ grid dimensions
865 //
866 int GetNumberRows() const { return m_numRows; }
867 int GetNumberCols() const { return m_numCols; }
868
869
870 // ------ display update functions
871 //
872 wxArrayInt CalcRowLabelsExposed( const wxRegion& reg ) const;
873
874 wxArrayInt CalcColLabelsExposed( const wxRegion& reg ) const;
875 wxGridCellCoordsArray CalcCellsExposed( const wxRegion& reg ) const;
876
877
878 void ClearGrid();
879 bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true)
880 {
881 return DoModifyLines(&wxGridTableBase::InsertRows,
882 pos, numRows, updateLabels);
883 }
884 bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true)
885 {
886 return DoModifyLines(&wxGridTableBase::InsertCols,
887 pos, numCols, updateLabels);
888 }
889
890 bool AppendRows(int numRows = 1, bool updateLabels = true)
891 {
892 return DoAppendLines(&wxGridTableBase::AppendRows, numRows, updateLabels);
893 }
894 bool AppendCols(int numCols = 1, bool updateLabels = true)
895 {
896 return DoAppendLines(&wxGridTableBase::AppendCols, numCols, updateLabels);
897 }
898
899 bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true)
900 {
901 return DoModifyLines(&wxGridTableBase::DeleteRows,
902 pos, numRows, updateLabels);
903 }
904 bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true)
905 {
906 return DoModifyLines(&wxGridTableBase::DeleteCols,
907 pos, numCols, updateLabels);
908 }
909
910 void DrawGridCellArea( wxDC& dc , const wxGridCellCoordsArray& cells );
911 void DrawGridSpace( wxDC& dc );
912 void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
913 void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
914 void DrawCell( wxDC& dc, const wxGridCellCoords& );
915 void DrawHighlight(wxDC& dc, const wxGridCellCoordsArray& cells);
916
917 // this function is called when the current cell highlight must be redrawn
918 // and may be overridden by the user
919 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
920
921 virtual void DrawRowLabels( wxDC& dc, const wxArrayInt& rows );
922 virtual void DrawRowLabel( wxDC& dc, int row );
923
924 virtual void DrawColLabels( wxDC& dc, const wxArrayInt& cols );
925 virtual void DrawColLabel( wxDC& dc, int col );
926
927 virtual void DrawCornerLabel(wxDC& dc);
928
929 // ------ Cell text drawing functions
930 //
931 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
932 int horizontalAlignment = wxALIGN_LEFT,
933 int verticalAlignment = wxALIGN_TOP,
934 int textOrientation = wxHORIZONTAL );
935
936 void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect&,
937 int horizontalAlignment = wxALIGN_LEFT,
938 int verticalAlignment = wxALIGN_TOP,
939 int textOrientation = wxHORIZONTAL );
940
941
942 // Split a string containing newline characters into an array of
943 // strings and return the number of lines
944 //
945 void StringToLines( const wxString& value, wxArrayString& lines ) const;
946
947 void GetTextBoxSize( const wxDC& dc,
948 const wxArrayString& lines,
949 long *width, long *height ) const;
950
951
952 // ------
953 // Code that does a lot of grid modification can be enclosed
954 // between BeginBatch() and EndBatch() calls to avoid screen
955 // flicker
956 //
957 void BeginBatch() { m_batchCount++; }
958 void EndBatch();
959
960 int GetBatchCount() { return m_batchCount; }
961
962 virtual void Refresh(bool eraseb = true, const wxRect* rect = NULL);
963
964 // Use this, rather than wxWindow::Refresh(), to force an
965 // immediate repainting of the grid. Has no effect if you are
966 // already inside a BeginBatch / EndBatch block.
967 //
968 // This function is necessary because wxGrid has a minimal OnPaint()
969 // handler to reduce screen flicker.
970 //
971 void ForceRefresh();
972
973
974 // ------ edit control functions
975 //
976 bool IsEditable() const { return m_editable; }
977 void EnableEditing( bool edit );
978
979 void EnableCellEditControl( bool enable = true );
980 void DisableCellEditControl() { EnableCellEditControl(false); }
981 bool CanEnableCellControl() const;
982 bool IsCellEditControlEnabled() const;
983 bool IsCellEditControlShown() const;
984
985 bool IsCurrentCellReadOnly() const;
986
987 void ShowCellEditControl();
988 void HideCellEditControl();
989 void SaveEditControlValue();
990
991
992 // ------ grid location functions
993 // Note that all of these functions work with the logical coordinates of
994 // grid cells and labels so you will need to convert from device
995 // coordinates for mouse events etc.
996 //
997 wxGridCellCoords XYToCell(int x, int y) const;
998 void XYToCell(int x, int y, wxGridCellCoords& coords) const
999 { coords = XYToCell(x, y); }
1000 wxGridCellCoords XYToCell(const wxPoint& pos) const
1001 { return XYToCell(pos.x, pos.y); }
1002
1003 // these functions return the index of the row/columns corresponding to the
1004 // given logical position in pixels
1005 //
1006 // if clipToMinMax is false (default, wxNOT_FOUND is returned if the
1007 // position is outside any row/column, otherwise the first/last element is
1008 // returned in this case
1009 int YToRow( int y, bool clipToMinMax = false ) const;
1010 int XToCol( int x, bool clipToMinMax = false ) const;
1011
1012 int YToEdgeOfRow( int y ) const;
1013 int XToEdgeOfCol( int x ) const;
1014
1015 wxRect CellToRect( int row, int col ) const;
1016 wxRect CellToRect( const wxGridCellCoords& coords ) const
1017 { return CellToRect( coords.GetRow(), coords.GetCol() ); }
1018
1019 int GetGridCursorRow() const { return m_currentCellCoords.GetRow(); }
1020 int GetGridCursorCol() const { return m_currentCellCoords.GetCol(); }
1021
1022 // check to see if a cell is either wholly visible (the default arg) or
1023 // at least partially visible in the grid window
1024 //
1025 bool IsVisible( int row, int col, bool wholeCellVisible = true ) const;
1026 bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = true ) const
1027 { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); }
1028 void MakeCellVisible( int row, int col );
1029 void MakeCellVisible( const wxGridCellCoords& coords )
1030 { MakeCellVisible( coords.GetRow(), coords.GetCol() ); }
1031
1032
1033 // ------ grid cursor movement functions
1034 //
1035 void SetGridCursor(int row, int col) { SetCurrentCell(row, col); }
1036 void SetGridCursor(const wxGridCellCoords& c) { SetCurrentCell(c); }
1037
1038 void GoToCell(int row, int col)
1039 {
1040 if ( SetCurrentCell(row, col) )
1041 MakeCellVisible(row, col);
1042 }
1043
1044 void GoToCell(const wxGridCellCoords& coords)
1045 {
1046 if ( SetCurrentCell(coords) )
1047 MakeCellVisible(coords);
1048 }
1049
1050 bool MoveCursorUp( bool expandSelection );
1051 bool MoveCursorDown( bool expandSelection );
1052 bool MoveCursorLeft( bool expandSelection );
1053 bool MoveCursorRight( bool expandSelection );
1054 bool MovePageDown();
1055 bool MovePageUp();
1056 bool MoveCursorUpBlock( bool expandSelection );
1057 bool MoveCursorDownBlock( bool expandSelection );
1058 bool MoveCursorLeftBlock( bool expandSelection );
1059 bool MoveCursorRightBlock( bool expandSelection );
1060
1061
1062 // ------ label and gridline formatting
1063 //
1064 int GetDefaultRowLabelSize() const { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; }
1065 int GetRowLabelSize() const { return m_rowLabelWidth; }
1066 int GetDefaultColLabelSize() const { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; }
1067 int GetColLabelSize() const { return m_colLabelHeight; }
1068 wxColour GetLabelBackgroundColour() const { return m_labelBackgroundColour; }
1069 wxColour GetLabelTextColour() const { return m_labelTextColour; }
1070 wxFont GetLabelFont() const { return m_labelFont; }
1071 void GetRowLabelAlignment( int *horiz, int *vert ) const;
1072 void GetColLabelAlignment( int *horiz, int *vert ) const;
1073 int GetColLabelTextOrientation() const;
1074 wxString GetRowLabelValue( int row ) const;
1075 wxString GetColLabelValue( int col ) const;
1076
1077 wxColour GetCellHighlightColour() const { return m_cellHighlightColour; }
1078 int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; }
1079 int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth; }
1080
1081 // this one will use wxHeaderCtrl for the column labels
1082 void UseNativeColHeader(bool native = true);
1083
1084 // this one will still draw them manually but using the native renderer
1085 // instead of using the same appearance as for the row labels
1086 void SetUseNativeColLabels( bool native = true );
1087
1088 void SetRowLabelSize( int width );
1089 void SetColLabelSize( int height );
1090 void HideRowLabels() { SetRowLabelSize( 0 ); }
1091 void HideColLabels() { SetColLabelSize( 0 ); }
1092 void SetLabelBackgroundColour( const wxColour& );
1093 void SetLabelTextColour( const wxColour& );
1094 void SetLabelFont( const wxFont& );
1095 void SetRowLabelAlignment( int horiz, int vert );
1096 void SetColLabelAlignment( int horiz, int vert );
1097 void SetColLabelTextOrientation( int textOrientation );
1098 void SetRowLabelValue( int row, const wxString& );
1099 void SetColLabelValue( int col, const wxString& );
1100 void SetCellHighlightColour( const wxColour& );
1101 void SetCellHighlightPenWidth(int width);
1102 void SetCellHighlightROPenWidth(int width);
1103
1104 void EnableDragRowSize( bool enable = true );
1105 void DisableDragRowSize() { EnableDragRowSize( false ); }
1106 bool CanDragRowSize() const { return m_canDragRowSize; }
1107 void EnableDragColSize( bool enable = true );
1108 void DisableDragColSize() { EnableDragColSize( false ); }
1109 bool CanDragColSize() const { return m_canDragColSize; }
1110 void EnableDragColMove( bool enable = true );
1111 void DisableDragColMove() { EnableDragColMove( false ); }
1112 bool CanDragColMove() const { return m_canDragColMove; }
1113 void EnableDragGridSize(bool enable = true);
1114 void DisableDragGridSize() { EnableDragGridSize(false); }
1115 bool CanDragGridSize() const { return m_canDragGridSize; }
1116
1117 void EnableDragCell( bool enable = true );
1118 void DisableDragCell() { EnableDragCell( false ); }
1119 bool CanDragCell() const { return m_canDragCell; }
1120
1121
1122 // grid lines
1123 // ----------
1124
1125 // enable or disable drawing of the lines
1126 void EnableGridLines(bool enable = true);
1127 bool GridLinesEnabled() const { return m_gridLinesEnabled; }
1128
1129 // by default grid lines stop at last column/row, but this may be changed
1130 void ClipHorzGridLines(bool clip)
1131 { DoClipGridLines(m_gridLinesClipHorz, clip); }
1132 void ClipVertGridLines(bool clip)
1133 { DoClipGridLines(m_gridLinesClipVert, clip); }
1134 bool AreHorzGridLinesClipped() const { return m_gridLinesClipHorz; }
1135 bool AreVertGridLinesClipped() const { return m_gridLinesClipVert; }
1136
1137 // this can be used to change the global grid lines colour
1138 void SetGridLineColour(const wxColour& col);
1139 wxColour GetGridLineColour() const { return m_gridLineColour; }
1140
1141 // these methods may be overridden to customize individual grid lines
1142 // appearance
1143 virtual wxPen GetDefaultGridLinePen();
1144 virtual wxPen GetRowGridLinePen(int row);
1145 virtual wxPen GetColGridLinePen(int col);
1146
1147
1148 // attributes
1149 // ----------
1150
1151 // this sets the specified attribute for this cell or in this row/col
1152 void SetAttr(int row, int col, wxGridCellAttr *attr);
1153 void SetRowAttr(int row, wxGridCellAttr *attr);
1154 void SetColAttr(int col, wxGridCellAttr *attr);
1155
1156 // returns the attribute we may modify in place: a new one if this cell
1157 // doesn't have any yet or the existing one if it does
1158 //
1159 // DecRef() must be called on the returned pointer, as usual
1160 wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const;
1161
1162
1163 // shortcuts for setting the column parameters
1164
1165 // set the format for the data in the column: default is string
1166 void SetColFormatBool(int col);
1167 void SetColFormatNumber(int col);
1168 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1169 void SetColFormatCustom(int col, const wxString& typeName);
1170
1171 // ------ row and col formatting
1172 //
1173 int GetDefaultRowSize() const;
1174 int GetRowSize( int row ) const;
1175 bool IsRowShown(int row) const { return GetRowSize(row) != 0; }
1176 int GetDefaultColSize() const;
1177 int GetColSize( int col ) const;
1178 bool IsColShown(int col) const { return GetColSize(col) != 0; }
1179 wxColour GetDefaultCellBackgroundColour() const;
1180 wxColour GetCellBackgroundColour( int row, int col ) const;
1181 wxColour GetDefaultCellTextColour() const;
1182 wxColour GetCellTextColour( int row, int col ) const;
1183 wxFont GetDefaultCellFont() const;
1184 wxFont GetCellFont( int row, int col ) const;
1185 void GetDefaultCellAlignment( int *horiz, int *vert ) const;
1186 void GetCellAlignment( int row, int col, int *horiz, int *vert ) const;
1187 bool GetDefaultCellOverflow() const;
1188 bool GetCellOverflow( int row, int col ) const;
1189 void GetCellSize( int row, int col, int *num_rows, int *num_cols ) const;
1190 wxSize GetCellSize(const wxGridCellCoords& coords)
1191 {
1192 wxSize s;
1193 GetCellSize(coords.GetRow(), coords.GetCol(), &s.x, &s.y);
1194 return s;
1195 }
1196
1197 // ------ row and col sizes
1198 void SetDefaultRowSize( int height, bool resizeExistingRows = false );
1199 void SetRowSize( int row, int height );
1200 void HideRow(int row) { SetRowSize(row, 0); }
1201 void ShowRow(int row) { SetRowSize(row, -1); }
1202
1203 void SetDefaultColSize( int width, bool resizeExistingCols = false );
1204 void SetColSize( int col, int width );
1205 void HideCol(int col) { SetColSize(col, 0); }
1206 void ShowCol(int col) { SetColSize(col, -1); }
1207
1208 // the row and column sizes can be also set all at once using
1209 // wxGridSizesInfo which holds all of them at once
1210
1211 wxGridSizesInfo GetColSizes() const
1212 { return wxGridSizesInfo(GetDefaultColSize(), m_colWidths); }
1213 wxGridSizesInfo GetRowSizes() const
1214 { return wxGridSizesInfo(GetDefaultRowSize(), m_rowHeights); }
1215
1216 void SetColSizes(const wxGridSizesInfo& sizeInfo);
1217 void SetRowSizes(const wxGridSizesInfo& sizeInfo);
1218
1219
1220 // ------- columns (only, for now) reordering
1221
1222 // columns index <-> positions mapping: by default, the position of the
1223 // column is the same as its index, but the columns can also be reordered
1224 // (either by calling SetColPos() explicitly or by the user dragging the
1225 // columns around) in which case their indices don't correspond to their
1226 // positions on display any longer
1227 //
1228 // internally we always work with indices except for the functions which
1229 // have "Pos" in their names (and which work with columns, not pixels) and
1230 // only the display and hit testing code really cares about display
1231 // positions at all
1232
1233 // set the positions of all columns at once (this method uses the same
1234 // conventions as wxHeaderCtrl::SetColumnsOrder() for the order array)
1235 void SetColumnsOrder(const wxArrayInt& order);
1236
1237 // return the column index corresponding to the given (valid) position
1238 int GetColAt(int pos) const
1239 {
1240 return m_colAt.empty() ? pos : m_colAt[pos];
1241 }
1242
1243 // reorder the columns so that the column with the given index is now shown
1244 // as the position pos
1245 void SetColPos(int idx, int pos);
1246
1247 // return the position at which the column with the given index is
1248 // displayed: notice that this is a slow operation as we don't maintain the
1249 // reverse mapping currently
1250 int GetColPos(int idx) const
1251 {
1252 if ( m_colAt.IsEmpty() )
1253 return idx;
1254
1255 for ( int i = 0; i < m_numCols; i++ )
1256 {
1257 if ( m_colAt[i] == idx )
1258 return i;
1259 }
1260
1261 wxFAIL_MSG( "invalid column index" );
1262
1263 return wxNOT_FOUND;
1264 }
1265
1266 // reset the columns positions to the default order
1267 void ResetColPos();
1268
1269
1270 // automatically size the column or row to fit to its contents, if
1271 // setAsMin is true, this optimal width will also be set as minimal width
1272 // for this column
1273 void AutoSizeColumn( int col, bool setAsMin = true )
1274 { AutoSizeColOrRow(col, setAsMin, wxGRID_COLUMN); }
1275 void AutoSizeRow( int row, bool setAsMin = true )
1276 { AutoSizeColOrRow(row, setAsMin, wxGRID_ROW); }
1277
1278 // auto size all columns (very ineffective for big grids!)
1279 void AutoSizeColumns( bool setAsMin = true )
1280 { (void)SetOrCalcColumnSizes(false, setAsMin); }
1281
1282 void AutoSizeRows( bool setAsMin = true )
1283 { (void)SetOrCalcRowSizes(false, setAsMin); }
1284
1285 // auto size the grid, that is make the columns/rows of the "right" size
1286 // and also set the grid size to just fit its contents
1287 void AutoSize();
1288
1289 // Note for both AutoSizeRowLabelSize and AutoSizeColLabelSize:
1290 // If col equals to wxGRID_AUTOSIZE value then function autosizes labels column
1291 // instead of data column. Note that this operation may be slow for large
1292 // tables.
1293 // autosize row height depending on label text
1294 void AutoSizeRowLabelSize( int row );
1295
1296 // autosize column width depending on label text
1297 void AutoSizeColLabelSize( int col );
1298
1299 // column won't be resized to be lesser width - this must be called during
1300 // the grid creation because it won't resize the column if it's already
1301 // narrower than the minimal width
1302 void SetColMinimalWidth( int col, int width );
1303 void SetRowMinimalHeight( int row, int width );
1304
1305 /* These members can be used to query and modify the minimal
1306 * acceptable size of grid rows and columns. Call this function in
1307 * your code which creates the grid if you want to display cells
1308 * with a size smaller than the default acceptable minimum size.
1309 * Like the members SetColMinimalWidth and SetRowMinimalWidth,
1310 * the existing rows or columns will not be checked/resized.
1311 */
1312 void SetColMinimalAcceptableWidth( int width );
1313 void SetRowMinimalAcceptableHeight( int width );
1314 int GetColMinimalAcceptableWidth() const;
1315 int GetRowMinimalAcceptableHeight() const;
1316
1317 void SetDefaultCellBackgroundColour( const wxColour& );
1318 void SetCellBackgroundColour( int row, int col, const wxColour& );
1319 void SetDefaultCellTextColour( const wxColour& );
1320
1321 void SetCellTextColour( int row, int col, const wxColour& );
1322 void SetDefaultCellFont( const wxFont& );
1323 void SetCellFont( int row, int col, const wxFont& );
1324 void SetDefaultCellAlignment( int horiz, int vert );
1325 void SetCellAlignment( int row, int col, int horiz, int vert );
1326 void SetDefaultCellOverflow( bool allow );
1327 void SetCellOverflow( int row, int col, bool allow );
1328 void SetCellSize( int row, int col, int num_rows, int num_cols );
1329
1330 // takes ownership of the pointer
1331 void SetDefaultRenderer(wxGridCellRenderer *renderer);
1332 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
1333 wxGridCellRenderer *GetDefaultRenderer() const;
1334 wxGridCellRenderer* GetCellRenderer(int row, int col) const;
1335
1336 // takes ownership of the pointer
1337 void SetDefaultEditor(wxGridCellEditor *editor);
1338 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
1339 wxGridCellEditor *GetDefaultEditor() const;
1340 wxGridCellEditor* GetCellEditor(int row, int col) const;
1341
1342
1343
1344 // ------ cell value accessors
1345 //
1346 wxString GetCellValue( int row, int col ) const
1347 {
1348 if ( m_table )
1349 {
1350 return m_table->GetValue( row, col );
1351 }
1352 else
1353 {
1354 return wxEmptyString;
1355 }
1356 }
1357
1358 wxString GetCellValue( const wxGridCellCoords& coords ) const
1359 { return GetCellValue( coords.GetRow(), coords.GetCol() ); }
1360
1361 void SetCellValue( int row, int col, const wxString& s );
1362 void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1363 { SetCellValue( coords.GetRow(), coords.GetCol(), s ); }
1364
1365 // returns true if the cell can't be edited
1366 bool IsReadOnly(int row, int col) const;
1367
1368 // make the cell editable/readonly
1369 void SetReadOnly(int row, int col, bool isReadOnly = true);
1370
1371 // ------ select blocks of cells
1372 //
1373 void SelectRow( int row, bool addToSelected = false );
1374 void SelectCol( int col, bool addToSelected = false );
1375
1376 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1377 bool addToSelected = false );
1378
1379 void SelectBlock( const wxGridCellCoords& topLeft,
1380 const wxGridCellCoords& bottomRight,
1381 bool addToSelected = false )
1382 { SelectBlock( topLeft.GetRow(), topLeft.GetCol(),
1383 bottomRight.GetRow(), bottomRight.GetCol(),
1384 addToSelected ); }
1385
1386 void SelectAll();
1387
1388 bool IsSelection() const;
1389
1390 // ------ deselect blocks or cells
1391 //
1392 void DeselectRow( int row );
1393 void DeselectCol( int col );
1394 void DeselectCell( int row, int col );
1395
1396 void ClearSelection();
1397
1398 bool IsInSelection( int row, int col ) const;
1399
1400 bool IsInSelection( const wxGridCellCoords& coords ) const
1401 { return IsInSelection( coords.GetRow(), coords.GetCol() ); }
1402
1403 wxGridCellCoordsArray GetSelectedCells() const;
1404 wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
1405 wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
1406 wxArrayInt GetSelectedRows() const;
1407 wxArrayInt GetSelectedCols() const;
1408
1409 // This function returns the rectangle that encloses the block of cells
1410 // limited by TopLeft and BottomRight cell in device coords and clipped
1411 // to the client size of the grid window.
1412 //
1413 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
1414 const wxGridCellCoords & bottomRight ) const;
1415
1416 // Access or update the selection fore/back colours
1417 wxColour GetSelectionBackground() const
1418 { return m_selectionBackground; }
1419 wxColour GetSelectionForeground() const
1420 { return m_selectionForeground; }
1421
1422 void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; }
1423 void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; }
1424
1425
1426 // Methods for a registry for mapping data types to Renderers/Editors
1427 void RegisterDataType(const wxString& typeName,
1428 wxGridCellRenderer* renderer,
1429 wxGridCellEditor* editor);
1430 // DJC MAPTEK
1431 virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1432 wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1433 { return GetDefaultEditorForCell(c.GetRow(), c.GetCol()); }
1434 virtual wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1435 virtual wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1436 virtual wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
1437
1438 // grid may occupy more space than needed for its rows/columns, this
1439 // function allows to set how big this extra space is
1440 void SetMargins(int extraWidth, int extraHeight)
1441 {
1442 m_extraWidth = extraWidth;
1443 m_extraHeight = extraHeight;
1444
1445 CalcDimensions();
1446 }
1447
1448 // Accessors for component windows
1449 wxWindow* GetGridWindow() const { return (wxWindow*)m_gridWin; }
1450 wxWindow* GetGridRowLabelWindow() const { return (wxWindow*)m_rowLabelWin; }
1451 wxWindow* GetGridColLabelWindow() const { return m_colWindow; }
1452 wxWindow* GetGridCornerLabelWindow() const { return (wxWindow*)m_cornerLabelWin; }
1453
1454 // This one can only be called if we are using the native header window
1455 wxHeaderCtrl *GetGridColHeader() const
1456 {
1457 wxASSERT_MSG( m_useNativeHeader, "no column header window" );
1458
1459 // static_cast<> doesn't work without the full class declaration in
1460 // view and we prefer to avoid adding more compile-time dependencies
1461 // even at the cost of using reinterpret_cast<>
1462 return reinterpret_cast<wxHeaderCtrl *>(m_colWindow);
1463 }
1464
1465 // Allow adjustment of scroll increment. The default is (15, 15).
1466 void SetScrollLineX(int x) { m_scrollLineX = x; }
1467 void SetScrollLineY(int y) { m_scrollLineY = y; }
1468 int GetScrollLineX() const { return m_scrollLineX; }
1469 int GetScrollLineY() const { return m_scrollLineY; }
1470
1471 // ------- drag and drop
1472 #if wxUSE_DRAG_AND_DROP
1473 virtual void SetDropTarget(wxDropTarget *dropTarget);
1474 #endif // wxUSE_DRAG_AND_DROP
1475
1476
1477 // ------- sorting support
1478
1479 // wxGrid doesn't support sorting on its own but it can indicate the sort
1480 // order in the column header (currently only if native header control is
1481 // used though)
1482
1483 // return the column currently displaying the sort indicator or wxNOT_FOUND
1484 // if none
1485 int GetSortingColumn() const { return m_sortCol; }
1486
1487 // return true if this column is currently used for sorting
1488 bool IsSortingBy(int col) const { return GetSortingColumn() == col; }
1489
1490 // return the current sorting order (on GetSortingColumn()): true for
1491 // ascending sort and false for descending; it doesn't make sense to call
1492 // it if GetSortingColumn() returns wxNOT_FOUND
1493 bool IsSortOrderAscending() const { return m_sortIsAscending; }
1494
1495 // set the sorting column (or unsets any existing one if wxNOT_FOUND) and
1496 // the order in which to sort
1497 void SetSortingColumn(int col, bool ascending = true);
1498
1499 // unset any existing sorting column
1500 void UnsetSortingColumn() { SetSortingColumn(wxNOT_FOUND); }
1501
1502 #ifdef WXWIN_COMPATIBILITY_2_8
1503 // ------ For compatibility with previous wxGrid only...
1504 //
1505 // ************************************************
1506 // ** Don't use these in new code because they **
1507 // ** are liable to disappear in a future **
1508 // ** revision **
1509 // ************************************************
1510 //
1511
1512 wxGrid( wxWindow *parent,
1513 int x, int y, int w = wxDefaultCoord, int h = wxDefaultCoord,
1514 long style = wxWANTS_CHARS,
1515 const wxString& name = wxPanelNameStr )
1516 {
1517 Init();
1518 Create(parent, wxID_ANY, wxPoint(x, y), wxSize(w, h), style, name);
1519 }
1520
1521 void SetCellValue( const wxString& val, int row, int col )
1522 { SetCellValue( row, col, val ); }
1523
1524 void UpdateDimensions()
1525 { CalcDimensions(); }
1526
1527 int GetRows() const { return GetNumberRows(); }
1528 int GetCols() const { return GetNumberCols(); }
1529 int GetCursorRow() const { return GetGridCursorRow(); }
1530 int GetCursorColumn() const { return GetGridCursorCol(); }
1531
1532 int GetScrollPosX() const { return 0; }
1533 int GetScrollPosY() const { return 0; }
1534
1535 void SetScrollX( int WXUNUSED(x) ) { }
1536 void SetScrollY( int WXUNUSED(y) ) { }
1537
1538 void SetColumnWidth( int col, int width )
1539 { SetColSize( col, width ); }
1540
1541 int GetColumnWidth( int col ) const
1542 { return GetColSize( col ); }
1543
1544 void SetRowHeight( int row, int height )
1545 { SetRowSize( row, height ); }
1546
1547 // GetRowHeight() is below
1548
1549 int GetViewHeight() const // returned num whole rows visible
1550 { return 0; }
1551
1552 int GetViewWidth() const // returned num whole cols visible
1553 { return 0; }
1554
1555 void SetLabelSize( int orientation, int sz )
1556 {
1557 if ( orientation == wxHORIZONTAL )
1558 SetColLabelSize( sz );
1559 else
1560 SetRowLabelSize( sz );
1561 }
1562
1563 int GetLabelSize( int orientation ) const
1564 {
1565 if ( orientation == wxHORIZONTAL )
1566 return GetColLabelSize();
1567 else
1568 return GetRowLabelSize();
1569 }
1570
1571 void SetLabelAlignment( int orientation, int align )
1572 {
1573 if ( orientation == wxHORIZONTAL )
1574 SetColLabelAlignment( align, -1 );
1575 else
1576 SetRowLabelAlignment( align, -1 );
1577 }
1578
1579 int GetLabelAlignment( int orientation, int WXUNUSED(align) ) const
1580 {
1581 int h, v;
1582 if ( orientation == wxHORIZONTAL )
1583 {
1584 GetColLabelAlignment( &h, &v );
1585 return h;
1586 }
1587 else
1588 {
1589 GetRowLabelAlignment( &h, &v );
1590 return h;
1591 }
1592 }
1593
1594 void SetLabelValue( int orientation, const wxString& val, int pos )
1595 {
1596 if ( orientation == wxHORIZONTAL )
1597 SetColLabelValue( pos, val );
1598 else
1599 SetRowLabelValue( pos, val );
1600 }
1601
1602 wxString GetLabelValue( int orientation, int pos) const
1603 {
1604 if ( orientation == wxHORIZONTAL )
1605 return GetColLabelValue( pos );
1606 else
1607 return GetRowLabelValue( pos );
1608 }
1609
1610 wxFont GetCellTextFont() const
1611 { return m_defaultCellAttr->GetFont(); }
1612
1613 wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const
1614 { return m_defaultCellAttr->GetFont(); }
1615
1616 void SetCellTextFont(const wxFont& fnt)
1617 { SetDefaultCellFont( fnt ); }
1618
1619 void SetCellTextFont(const wxFont& fnt, int row, int col)
1620 { SetCellFont( row, col, fnt ); }
1621
1622 void SetCellTextColour(const wxColour& val, int row, int col)
1623 { SetCellTextColour( row, col, val ); }
1624
1625 void SetCellTextColour(const wxColour& col)
1626 { SetDefaultCellTextColour( col ); }
1627
1628 void SetCellBackgroundColour(const wxColour& col)
1629 { SetDefaultCellBackgroundColour( col ); }
1630
1631 void SetCellBackgroundColour(const wxColour& colour, int row, int col)
1632 { SetCellBackgroundColour( row, col, colour ); }
1633
1634 bool GetEditable() const { return IsEditable(); }
1635 void SetEditable( bool edit = true ) { EnableEditing( edit ); }
1636 bool GetEditInPlace() const { return IsCellEditControlEnabled(); }
1637
1638 void SetEditInPlace(bool WXUNUSED(edit) = true) { }
1639
1640 void SetCellAlignment( int align, int row, int col)
1641 { SetCellAlignment(row, col, align, wxALIGN_CENTER); }
1642 void SetCellAlignment( int WXUNUSED(align) ) {}
1643 void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col))
1644 { }
1645 void SetDividerPen(const wxPen& WXUNUSED(pen)) { }
1646 wxPen& GetDividerPen() const;
1647 void OnActivate(bool WXUNUSED(active)) {}
1648
1649 // ******** End of compatibility functions **********
1650
1651
1652
1653 // ------ control IDs
1654 enum { wxGRID_CELLCTRL = 2000,
1655 wxGRID_TOPCTRL };
1656
1657 // ------ control types
1658 enum { wxGRID_TEXTCTRL = 2100,
1659 wxGRID_CHECKBOX,
1660 wxGRID_CHOICE,
1661 wxGRID_COMBOBOX };
1662 #endif // WXWIN_COMPATIBILITY_2_8
1663
1664
1665 // override some base class functions
1666 virtual bool Enable(bool enable = true);
1667 virtual wxWindow *GetMainWindowOfCompositeControl()
1668 { return (wxWindow*)m_gridWin; }
1669 virtual void Fit();
1670
1671 // implementation only
1672 void CancelMouseCapture();
1673
1674 protected:
1675 virtual wxSize DoGetBestSize() const;
1676
1677 bool m_created;
1678
1679 wxGridWindow *m_gridWin;
1680 wxGridCornerLabelWindow *m_cornerLabelWin;
1681 wxGridRowLabelWindow *m_rowLabelWin;
1682
1683 // the real type of the column window depends on m_useNativeHeader value:
1684 // if it is true, its dynamic type is wxHeaderCtrl, otherwise it is
1685 // wxGridColLabelWindow, use accessors below when the real type matters
1686 wxWindow *m_colWindow;
1687
1688 wxGridColLabelWindow *GetColLabelWindow() const
1689 {
1690 wxASSERT_MSG( !m_useNativeHeader, "no column label window" );
1691
1692 return reinterpret_cast<wxGridColLabelWindow *>(m_colWindow);
1693 }
1694
1695 wxGridTableBase *m_table;
1696 bool m_ownTable;
1697
1698 int m_numRows;
1699 int m_numCols;
1700
1701 wxGridCellCoords m_currentCellCoords;
1702
1703 // the corners of the block being currently selected or wxGridNoCellCoords
1704 wxGridCellCoords m_selectedBlockTopLeft;
1705 wxGridCellCoords m_selectedBlockBottomRight;
1706
1707 // when selecting blocks of cells (either from the keyboard using Shift
1708 // with cursor keys, or by dragging the mouse), the selection is anchored
1709 // at m_currentCellCoords which defines one of the corners of the rectangle
1710 // being selected -- and this variable defines the other corner, i.e. it's
1711 // either m_selectedBlockTopLeft or m_selectedBlockBottomRight depending on
1712 // which of them is not m_currentCellCoords
1713 //
1714 // if no block selection is in process, it is set to wxGridNoCellCoords
1715 wxGridCellCoords m_selectedBlockCorner;
1716
1717 wxGridSelection *m_selection;
1718
1719 wxColour m_selectionBackground;
1720 wxColour m_selectionForeground;
1721
1722 // NB: *never* access m_row/col arrays directly because they are created
1723 // on demand, *always* use accessor functions instead!
1724
1725 // init the m_rowHeights/Bottoms arrays with default values
1726 void InitRowHeights();
1727
1728 int m_defaultRowHeight;
1729 int m_minAcceptableRowHeight;
1730 wxArrayInt m_rowHeights;
1731 wxArrayInt m_rowBottoms;
1732
1733 // init the m_colWidths/Rights arrays
1734 void InitColWidths();
1735
1736 int m_defaultColWidth;
1737 int m_minAcceptableColWidth;
1738 wxArrayInt m_colWidths;
1739 wxArrayInt m_colRights;
1740
1741 int m_sortCol;
1742 bool m_sortIsAscending;
1743
1744 bool m_useNativeHeader,
1745 m_nativeColumnLabels;
1746
1747 // get the col/row coords
1748 int GetColWidth(int col) const;
1749 int GetColLeft(int col) const;
1750 int GetColRight(int col) const;
1751
1752 // this function must be public for compatibility...
1753 public:
1754 int GetRowHeight(int row) const;
1755 protected:
1756
1757 int GetRowTop(int row) const;
1758 int GetRowBottom(int row) const;
1759
1760 int m_rowLabelWidth;
1761 int m_colLabelHeight;
1762
1763 // the size of the margin left to the right and bottom of the cell area
1764 int m_extraWidth,
1765 m_extraHeight;
1766
1767 wxColour m_labelBackgroundColour;
1768 wxColour m_labelTextColour;
1769 wxFont m_labelFont;
1770
1771 int m_rowLabelHorizAlign;
1772 int m_rowLabelVertAlign;
1773 int m_colLabelHorizAlign;
1774 int m_colLabelVertAlign;
1775 int m_colLabelTextOrientation;
1776
1777 bool m_defaultRowLabelValues;
1778 bool m_defaultColLabelValues;
1779
1780 wxColour m_gridLineColour;
1781 bool m_gridLinesEnabled;
1782 bool m_gridLinesClipHorz,
1783 m_gridLinesClipVert;
1784 wxColour m_cellHighlightColour;
1785 int m_cellHighlightPenWidth;
1786 int m_cellHighlightROPenWidth;
1787
1788
1789 // common part of AutoSizeColumn/Row() and GetBestSize()
1790 int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = true);
1791 int SetOrCalcRowSizes(bool calcOnly, bool setAsMin = true);
1792
1793 // common part of AutoSizeColumn/Row()
1794 void AutoSizeColOrRow(int n, bool setAsMin, wxGridDirection direction);
1795
1796 // Calculate the minimum acceptable size for labels area
1797 wxCoord CalcColOrRowLabelAreaMinSize(wxGridDirection direction);
1798
1799 // if a column has a minimal width, it will be the value for it in this
1800 // hash table
1801 wxLongToLongHashMap m_colMinWidths,
1802 m_rowMinHeights;
1803
1804 // get the minimal width of the given column/row
1805 int GetColMinimalWidth(int col) const;
1806 int GetRowMinimalHeight(int col) const;
1807
1808 // do we have some place to store attributes in?
1809 bool CanHaveAttributes() const;
1810
1811 // cell attribute cache (currently we only cache 1, may be will do
1812 // more/better later)
1813 struct CachedAttr
1814 {
1815 int row, col;
1816 wxGridCellAttr *attr;
1817 } m_attrCache;
1818
1819 // invalidates the attribute cache
1820 void ClearAttrCache();
1821
1822 // adds an attribute to cache
1823 void CacheAttr(int row, int col, wxGridCellAttr *attr) const;
1824
1825 // looks for an attr in cache, returns true if found
1826 bool LookupAttr(int row, int col, wxGridCellAttr **attr) const;
1827
1828 // looks for the attr in cache, if not found asks the table and caches the
1829 // result
1830 wxGridCellAttr *GetCellAttr(int row, int col) const;
1831 wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords ) const
1832 { return GetCellAttr( coords.GetRow(), coords.GetCol() ); }
1833
1834 // the default cell attr object for cells that don't have their own
1835 wxGridCellAttr* m_defaultCellAttr;
1836
1837
1838 bool m_inOnKeyDown;
1839 int m_batchCount;
1840
1841
1842 wxGridTypeRegistry* m_typeRegistry;
1843
1844 enum CursorMode
1845 {
1846 WXGRID_CURSOR_SELECT_CELL,
1847 WXGRID_CURSOR_RESIZE_ROW,
1848 WXGRID_CURSOR_RESIZE_COL,
1849 WXGRID_CURSOR_SELECT_ROW,
1850 WXGRID_CURSOR_SELECT_COL,
1851 WXGRID_CURSOR_MOVE_COL
1852 };
1853
1854 // this method not only sets m_cursorMode but also sets the correct cursor
1855 // for the given mode and, if captureMouse is not false releases the mouse
1856 // if it was captured and captures it if it must be captured
1857 //
1858 // for this to work, you should always use it and not set m_cursorMode
1859 // directly!
1860 void ChangeCursorMode(CursorMode mode,
1861 wxWindow *win = NULL,
1862 bool captureMouse = true);
1863
1864 wxWindow *m_winCapture; // the window which captured the mouse
1865
1866 // this variable is used not for finding the correct current cursor but
1867 // mainly for finding out what is going to happen if the mouse starts being
1868 // dragged right now
1869 //
1870 // by default it is WXGRID_CURSOR_SELECT_CELL meaning that nothing else is
1871 // going on, and it is set to one of RESIZE/SELECT/MOVE values while the
1872 // corresponding operation will be started if the user starts dragging the
1873 // mouse from the current position
1874 CursorMode m_cursorMode;
1875
1876
1877 //Column positions
1878 wxArrayInt m_colAt;
1879
1880 bool m_canDragRowSize;
1881 bool m_canDragColSize;
1882 bool m_canDragColMove;
1883 bool m_canDragGridSize;
1884 bool m_canDragCell;
1885
1886 // the last position (horizontal or vertical depending on whether the user
1887 // is resizing a column or a row) where a row or column separator line was
1888 // dragged by the user or -1 of there is no drag operation in progress
1889 int m_dragLastPos;
1890 int m_dragRowOrCol;
1891
1892 // true if a drag operation is in progress; when this is true,
1893 // m_startDragPos is valid, i.e. not wxDefaultPosition
1894 bool m_isDragging;
1895
1896 // the position (in physical coordinates) where the user started dragging
1897 // the mouse or wxDefaultPosition if mouse isn't being dragged
1898 //
1899 // notice that this can be != wxDefaultPosition while m_isDragging is still
1900 // false because we wait until the mouse is moved some distance away before
1901 // setting m_isDragging to true
1902 wxPoint m_startDragPos;
1903
1904 bool m_waitForSlowClick;
1905
1906 wxGridCellCoords m_selectionStart;
1907
1908 wxCursor m_rowResizeCursor;
1909 wxCursor m_colResizeCursor;
1910
1911 bool m_editable; // applies to whole grid
1912 bool m_cellEditCtrlEnabled; // is in-place edit currently shown?
1913
1914 int m_scrollLineX; // X scroll increment
1915 int m_scrollLineY; // Y scroll increment
1916
1917 void Init(); // common part of all ctors
1918 void Create();
1919 void CreateColumnWindow();
1920 void CalcDimensions();
1921 void CalcWindowSizes();
1922 bool Redimension( wxGridTableMessage& );
1923
1924
1925 // generate the appropriate grid event and return -1 if it was vetoed, 1 if
1926 // it was processed (but not vetoed) and 0 if it wasn't processed
1927 int SendEvent(const wxEventType evtType,
1928 int row, int col,
1929 wxMouseEvent& e);
1930 int SendEvent(const wxEventType evtType,
1931 const wxGridCellCoords& coords,
1932 wxMouseEvent& e)
1933 { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), e); }
1934 int SendEvent(const wxEventType evtType,
1935 int row, int col,
1936 const wxString& s = wxString());
1937 int SendEvent(const wxEventType evtType,
1938 const wxGridCellCoords& coords,
1939 const wxString& s = wxString())
1940 { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), s); }
1941 int SendEvent(const wxEventType evtType, const wxString& s = wxString())
1942 { return SendEvent(evtType, m_currentCellCoords, s); }
1943
1944 void OnPaint( wxPaintEvent& );
1945 void OnSize( wxSizeEvent& );
1946 void OnKeyDown( wxKeyEvent& );
1947 void OnKeyUp( wxKeyEvent& );
1948 void OnChar( wxKeyEvent& );
1949 void OnEraseBackground( wxEraseEvent& );
1950
1951
1952 bool SetCurrentCell( const wxGridCellCoords& coords );
1953 bool SetCurrentCell( int row, int col )
1954 { return SetCurrentCell( wxGridCellCoords(row, col) ); }
1955
1956
1957 // this function is called to extend the block being currently selected
1958 // from mouse and keyboard event handlers
1959 void UpdateBlockBeingSelected(int topRow, int leftCol,
1960 int bottomRow, int rightCol);
1961
1962 void UpdateBlockBeingSelected(const wxGridCellCoords& topLeft,
1963 const wxGridCellCoords& bottomRight)
1964 { UpdateBlockBeingSelected(topLeft.GetRow(), topLeft.GetCol(),
1965 bottomRight.GetRow(), bottomRight.GetCol()); }
1966
1967 // ------ functions to get/send data (see also public functions)
1968 //
1969 bool GetModelValues();
1970 bool SetModelValues();
1971
1972 friend class WXDLLIMPEXP_FWD_ADV wxGridSelection;
1973 friend class wxGridRowOperations;
1974 friend class wxGridColumnOperations;
1975
1976 // they call our private Process{{Corner,Col,Row}Label,GridCell}MouseEvent()
1977 friend class wxGridCornerLabelWindow;
1978 friend class wxGridColLabelWindow;
1979 friend class wxGridRowLabelWindow;
1980 friend class wxGridWindow;
1981
1982 friend class wxGridHeaderCtrl;
1983
1984 private:
1985 // implement wxScrolledWindow method to return m_gridWin size
1986 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
1987
1988 // redraw the grid lines, should be called after changing their attributes
1989 void RedrawGridLines();
1990
1991 // common part of Clip{Horz,Vert}GridLines
1992 void DoClipGridLines(bool& var, bool clip);
1993
1994 // update the sorting indicator shown in the specified column (whose index
1995 // must be valid)
1996 //
1997 // this will use GetSortingColumn() and IsSortOrderAscending() to determine
1998 // the sorting indicator to effectively show
1999 void UpdateColumnSortingIndicator(int col);
2000
2001 // update the grid after changing the columns order (common part of
2002 // SetColPos() and ResetColPos())
2003 void RefreshAfterColPosChange();
2004
2005
2006 // return the position (not index) of the column at the given logical pixel
2007 // position
2008 //
2009 // this always returns a valid position, even if the coordinate is out of
2010 // bounds (in which case first/last column is returned)
2011 int XToPos(int x) const;
2012
2013
2014 // event handlers and their helpers
2015 // --------------------------------
2016
2017 // process mouse drag event in WXGRID_CURSOR_SELECT_CELL mode
2018 void DoGridCellDrag(wxMouseEvent& event,
2019 const wxGridCellCoords& coords,
2020 bool isFirstDrag);
2021
2022 // process row/column resizing drag event
2023 void DoGridLineDrag(wxMouseEvent& event, const wxGridOperations& oper);
2024
2025 // process mouse drag event in the grid window
2026 void DoGridDragEvent(wxMouseEvent& event, const wxGridCellCoords& coords);
2027
2028 // process different clicks on grid cells
2029 void DoGridCellLeftDown(wxMouseEvent& event,
2030 const wxGridCellCoords& coords,
2031 const wxPoint& pos);
2032 void DoGridCellLeftDClick(wxMouseEvent& event,
2033 const wxGridCellCoords& coords,
2034 const wxPoint& pos);
2035 void DoGridCellLeftUp(wxMouseEvent& event, const wxGridCellCoords& coords);
2036
2037 // process movement (but not dragging) event in the grid cell area
2038 void DoGridMouseMoveEvent(wxMouseEvent& event,
2039 const wxGridCellCoords& coords,
2040 const wxPoint& pos);
2041
2042 // process mouse events in the grid window
2043 void ProcessGridCellMouseEvent(wxMouseEvent& event);
2044
2045 // process mouse events in the row/column labels/corner windows
2046 void ProcessRowLabelMouseEvent(wxMouseEvent& event);
2047 void ProcessColLabelMouseEvent(wxMouseEvent& event);
2048 void ProcessCornerLabelMouseEvent(wxMouseEvent& event);
2049
2050 void DoColHeaderClick(int col);
2051
2052 void DoStartResizeCol(int col);
2053 void DoUpdateResizeCol(int x);
2054 void DoUpdateResizeColWidth(int w);
2055 void DoStartMoveCol(int col);
2056
2057 void DoEndDragResizeRow();
2058 void DoEndDragResizeCol(wxMouseEvent *event = NULL);
2059 void DoEndMoveCol(int pos);
2060
2061
2062 // common implementations of methods defined for both rows and columns
2063 void DeselectLine(int line, const wxGridOperations& oper);
2064 void DoEndDragResizeLine(const wxGridOperations& oper);
2065 int PosToLinePos(int pos, bool clipToMinMax,
2066 const wxGridOperations& oper) const;
2067 int PosToLine(int pos, bool clipToMinMax,
2068 const wxGridOperations& oper) const;
2069 int PosToEdgeOfLine(int pos, const wxGridOperations& oper) const;
2070
2071 bool DoMoveCursor(bool expandSelection,
2072 const wxGridDirectionOperations& diroper);
2073 bool DoMoveCursorByPage(const wxGridDirectionOperations& diroper);
2074 bool DoMoveCursorByBlock(bool expandSelection,
2075 const wxGridDirectionOperations& diroper);
2076 void AdvanceToNextNonEmpty(wxGridCellCoords& coords,
2077 const wxGridDirectionOperations& diroper);
2078
2079 // common part of {Insert,Delete}{Rows,Cols}
2080 bool DoModifyLines(bool (wxGridTableBase::*funcModify)(size_t, size_t),
2081 int pos, int num, bool updateLabels);
2082 // Append{Rows,Cols} is a bit different because of one less parameter
2083 bool DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t),
2084 int num, bool updateLabels);
2085
2086 // Common part of Set{Col,Row}Sizes
2087 void DoSetSizes(const wxGridSizesInfo& sizeInfo,
2088 const wxGridOperations& oper);
2089
2090 DECLARE_DYNAMIC_CLASS( wxGrid )
2091 DECLARE_EVENT_TABLE()
2092 wxDECLARE_NO_COPY_CLASS(wxGrid);
2093 };
2094
2095 // ----------------------------------------------------------------------------
2096 // wxGridUpdateLocker prevents updates to a grid during its lifetime
2097 // ----------------------------------------------------------------------------
2098
2099 class WXDLLIMPEXP_ADV wxGridUpdateLocker
2100 {
2101 public:
2102 // if the pointer is NULL, Create() can be called later
2103 wxGridUpdateLocker(wxGrid *grid = NULL)
2104 {
2105 Init(grid);
2106 }
2107
2108 // can be called if ctor was used with a NULL pointer, must not be called
2109 // more than once
2110 void Create(wxGrid *grid)
2111 {
2112 wxASSERT_MSG( !m_grid, _T("shouldn't be called more than once") );
2113
2114 Init(grid);
2115 }
2116
2117 ~wxGridUpdateLocker()
2118 {
2119 if ( m_grid )
2120 m_grid->EndBatch();
2121 }
2122
2123 private:
2124 void Init(wxGrid *grid)
2125 {
2126 m_grid = grid;
2127 if ( m_grid )
2128 m_grid->BeginBatch();
2129 }
2130
2131 wxGrid *m_grid;
2132
2133 wxDECLARE_NO_COPY_CLASS(wxGridUpdateLocker);
2134 };
2135
2136 // ----------------------------------------------------------------------------
2137 // Grid event class and event types
2138 // ----------------------------------------------------------------------------
2139
2140 class WXDLLIMPEXP_ADV wxGridEvent : public wxNotifyEvent,
2141 public wxKeyboardState
2142 {
2143 public:
2144 wxGridEvent()
2145 : wxNotifyEvent()
2146 {
2147 Init(-1, -1, -1, -1, false);
2148 }
2149
2150 wxGridEvent(int id,
2151 wxEventType type,
2152 wxObject* obj,
2153 int row = -1, int col = -1,
2154 int x = -1, int y = -1,
2155 bool sel = true,
2156 const wxKeyboardState& kbd = wxKeyboardState())
2157 : wxNotifyEvent(type, id),
2158 wxKeyboardState(kbd)
2159 {
2160 Init(row, col, x, y, sel);
2161 SetEventObject(obj);
2162 }
2163
2164 // explicitly specifying inline allows gcc < 3.4 to
2165 // handle the deprecation attribute even in the constructor.
2166 wxDEPRECATED_CONSTRUCTOR(
2167 wxGridEvent(int id,
2168 wxEventType type,
2169 wxObject* obj,
2170 int row, int col,
2171 int x, int y,
2172 bool sel,
2173 bool control,
2174 bool shift = false, bool alt = false, bool meta = false));
2175
2176 virtual int GetRow() { return m_row; }
2177 virtual int GetCol() { return m_col; }
2178 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
2179 bool Selecting() { return m_selecting; }
2180
2181 virtual wxEvent *Clone() const { return new wxGridEvent(*this); }
2182
2183 protected:
2184 int m_row;
2185 int m_col;
2186 int m_x;
2187 int m_y;
2188 bool m_selecting;
2189
2190 private:
2191 void Init(int row, int col, int x, int y, bool sel)
2192 {
2193 m_row = row;
2194 m_col = col;
2195 m_x = x;
2196 m_y = y;
2197 m_selecting = sel;
2198 }
2199
2200 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEvent)
2201 };
2202
2203 class WXDLLIMPEXP_ADV wxGridSizeEvent : public wxNotifyEvent,
2204 public wxKeyboardState
2205 {
2206 public:
2207 wxGridSizeEvent()
2208 : wxNotifyEvent()
2209 {
2210 Init(-1, -1, -1);
2211 }
2212
2213 wxGridSizeEvent(int id,
2214 wxEventType type,
2215 wxObject* obj,
2216 int rowOrCol = -1,
2217 int x = -1, int y = -1,
2218 const wxKeyboardState& kbd = wxKeyboardState())
2219 : wxNotifyEvent(type, id),
2220 wxKeyboardState(kbd)
2221 {
2222 Init(rowOrCol, x, y);
2223
2224 SetEventObject(obj);
2225 }
2226
2227 wxDEPRECATED_CONSTRUCTOR(
2228 wxGridSizeEvent(int id,
2229 wxEventType type,
2230 wxObject* obj,
2231 int rowOrCol,
2232 int x, int y,
2233 bool control,
2234 bool shift = false,
2235 bool alt = false,
2236 bool meta = false) );
2237
2238 int GetRowOrCol() { return m_rowOrCol; }
2239 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
2240
2241 virtual wxEvent *Clone() const { return new wxGridSizeEvent(*this); }
2242
2243 protected:
2244 int m_rowOrCol;
2245 int m_x;
2246 int m_y;
2247
2248 private:
2249 void Init(int rowOrCol, int x, int y)
2250 {
2251 m_rowOrCol = rowOrCol;
2252 m_x = x;
2253 m_y = y;
2254 }
2255
2256 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridSizeEvent)
2257 };
2258
2259
2260 class WXDLLIMPEXP_ADV wxGridRangeSelectEvent : public wxNotifyEvent,
2261 public wxKeyboardState
2262 {
2263 public:
2264 wxGridRangeSelectEvent()
2265 : wxNotifyEvent()
2266 {
2267 Init(wxGridNoCellCoords, wxGridNoCellCoords, false);
2268 }
2269
2270 wxGridRangeSelectEvent(int id,
2271 wxEventType type,
2272 wxObject* obj,
2273 const wxGridCellCoords& topLeft,
2274 const wxGridCellCoords& bottomRight,
2275 bool sel = true,
2276 const wxKeyboardState& kbd = wxKeyboardState())
2277 : wxNotifyEvent(type, id),
2278 wxKeyboardState(kbd)
2279 {
2280 Init(topLeft, bottomRight, sel);
2281
2282 SetEventObject(obj);
2283 }
2284
2285 wxDEPRECATED_CONSTRUCTOR(
2286 wxGridRangeSelectEvent(int id,
2287 wxEventType type,
2288 wxObject* obj,
2289 const wxGridCellCoords& topLeft,
2290 const wxGridCellCoords& bottomRight,
2291 bool sel,
2292 bool control,
2293 bool shift = false,
2294 bool alt = false,
2295 bool meta = false) );
2296
2297 wxGridCellCoords GetTopLeftCoords() { return m_topLeft; }
2298 wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; }
2299 int GetTopRow() { return m_topLeft.GetRow(); }
2300 int GetBottomRow() { return m_bottomRight.GetRow(); }
2301 int GetLeftCol() { return m_topLeft.GetCol(); }
2302 int GetRightCol() { return m_bottomRight.GetCol(); }
2303 bool Selecting() { return m_selecting; }
2304
2305 virtual wxEvent *Clone() const { return new wxGridRangeSelectEvent(*this); }
2306
2307 protected:
2308 void Init(const wxGridCellCoords& topLeft,
2309 const wxGridCellCoords& bottomRight,
2310 bool selecting)
2311 {
2312 m_topLeft = topLeft;
2313 m_bottomRight = bottomRight;
2314 m_selecting = selecting;
2315 }
2316
2317 wxGridCellCoords m_topLeft;
2318 wxGridCellCoords m_bottomRight;
2319 bool m_selecting;
2320
2321 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridRangeSelectEvent)
2322 };
2323
2324
2325 class WXDLLIMPEXP_ADV wxGridEditorCreatedEvent : public wxCommandEvent
2326 {
2327 public:
2328 wxGridEditorCreatedEvent()
2329 : wxCommandEvent()
2330 {
2331 m_row = 0;
2332 m_col = 0;
2333 m_ctrl = NULL;
2334 }
2335
2336 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
2337 int row, int col, wxControl* ctrl);
2338
2339 int GetRow() { return m_row; }
2340 int GetCol() { return m_col; }
2341 wxControl* GetControl() { return m_ctrl; }
2342 void SetRow(int row) { m_row = row; }
2343 void SetCol(int col) { m_col = col; }
2344 void SetControl(wxControl* ctrl) { m_ctrl = ctrl; }
2345
2346 virtual wxEvent *Clone() const { return new wxGridEditorCreatedEvent(*this); }
2347
2348 private:
2349 int m_row;
2350 int m_col;
2351 wxControl* m_ctrl;
2352
2353 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEditorCreatedEvent)
2354 };
2355
2356
2357 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_LEFT_CLICK, wxGridEvent );
2358 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEvent );
2359 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEvent );
2360 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_RIGHT_DCLICK, wxGridEvent );
2361 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_LEFT_CLICK, wxGridEvent );
2362 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEvent );
2363 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEvent );
2364 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_RIGHT_DCLICK, wxGridEvent );
2365 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_ROW_SIZE, wxGridSizeEvent );
2366 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_SIZE, wxGridSizeEvent );
2367 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEvent );
2368 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_CHANGING, wxGridEvent );
2369 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_CHANGED, wxGridEvent );
2370 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_SELECT_CELL, wxGridEvent );
2371 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_SHOWN, wxGridEvent );
2372 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_HIDDEN, wxGridEvent );
2373 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_CREATED, wxGridEditorCreatedEvent );
2374 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_BEGIN_DRAG, wxGridEvent );
2375 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_MOVE, wxGridEvent );
2376 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_SORT, wxGridEvent );
2377
2378 typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
2379 typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
2380 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
2381 typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreatedEvent&);
2382
2383 #define wxGridEventHandler(func) \
2384 wxEVENT_HANDLER_CAST(wxGridEventFunction, func)
2385
2386 #define wxGridSizeEventHandler(func) \
2387 wxEVENT_HANDLER_CAST(wxGridSizeEventFunction, func)
2388
2389 #define wxGridRangeSelectEventHandler(func) \
2390 wxEVENT_HANDLER_CAST(wxGridRangeSelectEventFunction, func)
2391
2392 #define wxGridEditorCreatedEventHandler(func) \
2393 wxEVENT_HANDLER_CAST(wxGridEditorCreatedEventFunction, func)
2394
2395 #define wx__DECLARE_GRIDEVT(evt, id, fn) \
2396 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn))
2397
2398 #define wx__DECLARE_GRIDSIZEEVT(evt, id, fn) \
2399 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridSizeEventHandler(fn))
2400
2401 #define wx__DECLARE_GRIDRANGESELEVT(evt, id, fn) \
2402 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridRangeSelectEventHandler(fn))
2403
2404 #define wx__DECLARE_GRIDEDITOREVT(evt, id, fn) \
2405 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEditorCreatedEventHandler(fn))
2406
2407 #define EVT_GRID_CMD_CELL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_CLICK, id, fn)
2408 #define EVT_GRID_CMD_CELL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_CLICK, id, fn)
2409 #define EVT_GRID_CMD_CELL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_DCLICK, id, fn)
2410 #define EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_DCLICK, id, fn)
2411 #define EVT_GRID_CMD_LABEL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_CLICK, id, fn)
2412 #define EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_CLICK, id, fn)
2413 #define EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_DCLICK, id, fn)
2414 #define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn)
2415 #define EVT_GRID_CMD_ROW_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn)
2416 #define EVT_GRID_CMD_COL_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn)
2417 #define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn)
2418 #define EVT_GRID_CMD_COL_SORT(id, fn) wx__DECLARE_GRIDEVT(COL_SORT, id, fn)
2419 #define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn)
2420 #define EVT_GRID_CMD_CELL_CHANGING(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGING, id, fn)
2421 #define EVT_GRID_CMD_CELL_CHANGED(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGED, id, fn)
2422 #define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn)
2423 #define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn)
2424 #define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn)
2425 #define EVT_GRID_CMD_EDITOR_CREATED(id, fn) wx__DECLARE_GRIDEDITOREVT(EDITOR_CREATED, id, fn)
2426 #define EVT_GRID_CMD_CELL_BEGIN_DRAG(id, fn) wx__DECLARE_GRIDEVT(CELL_BEGIN_DRAG, id, fn)
2427
2428 // same as above but for any id (exists mainly for backwards compatibility but
2429 // then it's also true that you rarely have multiple grid in the same window)
2430 #define EVT_GRID_CELL_LEFT_CLICK(fn) EVT_GRID_CMD_CELL_LEFT_CLICK(wxID_ANY, fn)
2431 #define EVT_GRID_CELL_RIGHT_CLICK(fn) EVT_GRID_CMD_CELL_RIGHT_CLICK(wxID_ANY, fn)
2432 #define EVT_GRID_CELL_LEFT_DCLICK(fn) EVT_GRID_CMD_CELL_LEFT_DCLICK(wxID_ANY, fn)
2433 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) EVT_GRID_CMD_CELL_RIGHT_DCLICK(wxID_ANY, fn)
2434 #define EVT_GRID_LABEL_LEFT_CLICK(fn) EVT_GRID_CMD_LABEL_LEFT_CLICK(wxID_ANY, fn)
2435 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_CLICK(wxID_ANY, fn)
2436 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) EVT_GRID_CMD_LABEL_LEFT_DCLICK(wxID_ANY, fn)
2437 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn)
2438 #define EVT_GRID_ROW_SIZE(fn) EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn)
2439 #define EVT_GRID_COL_SIZE(fn) EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn)
2440 #define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn)
2441 #define EVT_GRID_COL_SORT(fn) EVT_GRID_CMD_COL_SORT(wxID_ANY, fn)
2442 #define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn)
2443 #define EVT_GRID_CELL_CHANGING(fn) EVT_GRID_CMD_CELL_CHANGING(wxID_ANY, fn)
2444 #define EVT_GRID_CELL_CHANGED(fn) EVT_GRID_CMD_CELL_CHANGED(wxID_ANY, fn)
2445 #define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn)
2446 #define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn)
2447 #define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn)
2448 #define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn)
2449 #define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn)
2450
2451 // we used to have a single wxEVT_GRID_CELL_CHANGE event but it was split into
2452 // wxEVT_GRID_CELL_CHANGING and CHANGED ones in wx 2.9.0, however the CHANGED
2453 // is basically the same as the old CHANGE event so we keep the name for
2454 // compatibility
2455 #if WXWIN_COMPATIBILITY_2_8
2456 #define wxEVT_GRID_CELL_CHANGE wxEVT_GRID_CELL_CHANGED
2457
2458 #define EVT_GRID_CMD_CELL_CHANGE EVT_GRID_CMD_CELL_CHANGED
2459 #define EVT_GRID_CELL_CHANGE EVT_GRID_CELL_CHANGED
2460 #endif // WXWIN_COMPATIBILITY_2_8
2461
2462 #if 0 // TODO: implement these ? others ?
2463
2464 extern const int wxEVT_GRID_CREATE_CELL;
2465 extern const int wxEVT_GRID_CHANGE_LABELS;
2466 extern const int wxEVT_GRID_CHANGE_SEL_LABEL;
2467
2468 #define EVT_GRID_CREATE_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2469 #define EVT_GRID_CHANGE_LABELS(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2470 #define EVT_GRID_CHANGE_SEL_LABEL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2471
2472 #endif
2473
2474 #endif // wxUSE_GRID
2475 #endif // _WX_GENERIC_GRID_H_