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