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