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