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