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