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