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