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
8 // Copyright: (c) Michael Bedward
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_GRID_H_
13 #define _WX_GENERIC_GRID_H_
19 #include "wx/scrolwin.h"
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 extern WXDLLIMPEXP_DATA_ADV(const wxChar
) wxGridNameStr
[];
27 // Default parameters for wxGrid
29 #define WXGRID_DEFAULT_NUMBER_ROWS 10
30 #define WXGRID_DEFAULT_NUMBER_COLS 10
31 #if defined(__WXMSW__) || defined(__WXGTK20__)
32 #define WXGRID_DEFAULT_ROW_HEIGHT 25
34 #define WXGRID_DEFAULT_ROW_HEIGHT 30
36 #define WXGRID_DEFAULT_COL_WIDTH 80
37 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
38 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
39 #define WXGRID_LABEL_EDGE_ZONE 2
40 #define WXGRID_MIN_ROW_HEIGHT 15
41 #define WXGRID_MIN_COL_WIDTH 15
42 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
44 // type names for grid table values
45 #define wxGRID_VALUE_STRING _T("string")
46 #define wxGRID_VALUE_BOOL _T("bool")
47 #define wxGRID_VALUE_NUMBER _T("long")
48 #define wxGRID_VALUE_FLOAT _T("double")
49 #define wxGRID_VALUE_CHOICE _T("choice")
51 #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
52 #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
54 // magic constant which tells (to some functions) to automatically calculate
55 // the appropriate size
56 #define wxGRID_AUTOSIZE (-1)
58 // many wxGrid methods work either with columns or rows, this enum is used for
59 // the parameter indicating which one should it be
66 // ----------------------------------------------------------------------------
67 // forward declarations
68 // ----------------------------------------------------------------------------
70 class WXDLLIMPEXP_FWD_ADV wxGrid
;
71 class WXDLLIMPEXP_FWD_ADV wxGridCellAttr
;
72 class WXDLLIMPEXP_FWD_ADV wxGridCellAttrProviderData
;
73 class WXDLLIMPEXP_FWD_ADV wxGridColLabelWindow
;
74 class WXDLLIMPEXP_FWD_ADV wxGridCornerLabelWindow
;
75 class WXDLLIMPEXP_FWD_ADV wxGridRowLabelWindow
;
76 class WXDLLIMPEXP_FWD_ADV wxGridWindow
;
77 class WXDLLIMPEXP_FWD_ADV wxGridTypeRegistry
;
78 class WXDLLIMPEXP_FWD_ADV wxGridSelection
;
80 class WXDLLIMPEXP_FWD_CORE wxCheckBox
;
81 class WXDLLIMPEXP_FWD_CORE wxComboBox
;
82 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
84 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl
;
87 class wxGridOperations
;
88 class wxGridRowOperations
;
89 class wxGridColumnOperations
;
90 class wxGridDirectionOperations
;
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 #define wxSafeIncRef(p) if ( p ) (p)->IncRef()
97 #define wxSafeDecRef(p) if ( p ) (p)->DecRef()
99 // ----------------------------------------------------------------------------
100 // wxGridCellWorker: common base class for wxGridCellRenderer and
103 // NB: this is more an implementation convenience than a design issue, so this
104 // class is not documented and is not public at all
105 // ----------------------------------------------------------------------------
107 class WXDLLIMPEXP_ADV wxGridCellWorker
: public wxClientDataContainer
110 wxGridCellWorker() { m_nRef
= 1; }
112 // this class is ref counted: it is created with ref count of 1, so
113 // calling DecRef() once will delete it. Calling IncRef() allows to lock
114 // it until the matching DecRef() is called
115 void IncRef() { m_nRef
++; }
116 void DecRef() { if ( --m_nRef
== 0 ) delete this; }
118 // interpret renderer parameters: arbitrary string whose interpretatin is
119 // left to the derived classes
120 virtual void SetParameters(const wxString
& params
);
123 // virtual dtor for any base class - private because only DecRef() can
125 virtual ~wxGridCellWorker();
130 // suppress the stupid gcc warning about the class having private dtor and
132 friend class wxGridCellWorkerDummyFriend
;
135 // ----------------------------------------------------------------------------
136 // wxGridCellRenderer: this class is responsible for actually drawing the cell
137 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
138 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
139 // view of all cells. This is an ABC, you will normally use one of the
140 // predefined derived classes or derive your own class from it.
141 // ----------------------------------------------------------------------------
143 class WXDLLIMPEXP_ADV wxGridCellRenderer
: public wxGridCellWorker
146 // draw the given cell on the provided DC inside the given rectangle
147 // using the style specified by the attribute and the default or selected
148 // state corresponding to the isSelected value.
150 // this pure virtual function has a default implementation which will
151 // prepare the DC using the given attribute: it will draw the rectangle
152 // with the bg colour from attr and set the text colour and font
153 virtual void Draw(wxGrid
& grid
,
154 wxGridCellAttr
& attr
,
158 bool isSelected
) = 0;
160 // get the preferred size of the cell for its contents
161 virtual wxSize
GetBestSize(wxGrid
& grid
,
162 wxGridCellAttr
& attr
,
164 int row
, int col
) = 0;
166 // create a new object which is the copy of this one
167 virtual wxGridCellRenderer
*Clone() const = 0;
170 // the default renderer for the cells containing string data
171 class WXDLLIMPEXP_ADV wxGridCellStringRenderer
: public wxGridCellRenderer
175 virtual void Draw(wxGrid
& grid
,
176 wxGridCellAttr
& attr
,
182 // return the string extent
183 virtual wxSize
GetBestSize(wxGrid
& grid
,
184 wxGridCellAttr
& attr
,
188 virtual wxGridCellRenderer
*Clone() const
189 { return new wxGridCellStringRenderer
; }
192 // set the text colours before drawing
193 void SetTextColoursAndFont(const wxGrid
& grid
,
194 const wxGridCellAttr
& attr
,
198 // calc the string extent for given string/font
199 wxSize
DoGetBestSize(const wxGridCellAttr
& attr
,
201 const wxString
& text
);
204 // the default renderer for the cells containing numeric (long) data
205 class WXDLLIMPEXP_ADV wxGridCellNumberRenderer
: public wxGridCellStringRenderer
208 // draw the string right aligned
209 virtual void Draw(wxGrid
& grid
,
210 wxGridCellAttr
& attr
,
216 virtual wxSize
GetBestSize(wxGrid
& grid
,
217 wxGridCellAttr
& attr
,
221 virtual wxGridCellRenderer
*Clone() const
222 { return new wxGridCellNumberRenderer
; }
225 wxString
GetString(const wxGrid
& grid
, int row
, int col
);
228 class WXDLLIMPEXP_ADV wxGridCellFloatRenderer
: public wxGridCellStringRenderer
231 wxGridCellFloatRenderer(int width
= -1, int precision
= -1);
233 // get/change formatting parameters
234 int GetWidth() const { return m_width
; }
235 void SetWidth(int width
) { m_width
= width
; m_format
.clear(); }
236 int GetPrecision() const { return m_precision
; }
237 void SetPrecision(int precision
) { m_precision
= precision
; m_format
.clear(); }
239 // draw the string right aligned with given width/precision
240 virtual void Draw(wxGrid
& grid
,
241 wxGridCellAttr
& attr
,
247 virtual wxSize
GetBestSize(wxGrid
& grid
,
248 wxGridCellAttr
& attr
,
252 // parameters string format is "width[,precision]"
253 virtual void SetParameters(const wxString
& params
);
255 virtual wxGridCellRenderer
*Clone() const;
258 wxString
GetString(const wxGrid
& grid
, int row
, int col
);
261 // formatting parameters
268 // renderer for boolean fields
269 class WXDLLIMPEXP_ADV wxGridCellBoolRenderer
: public wxGridCellRenderer
272 // draw a check mark or nothing
273 virtual void Draw(wxGrid
& grid
,
274 wxGridCellAttr
& attr
,
280 // return the checkmark size
281 virtual wxSize
GetBestSize(wxGrid
& grid
,
282 wxGridCellAttr
& attr
,
286 virtual wxGridCellRenderer
*Clone() const
287 { return new wxGridCellBoolRenderer
; }
290 static wxSize ms_sizeCheckMark
;
293 // ----------------------------------------------------------------------------
294 // wxGridCellEditor: This class is responsible for providing and manipulating
295 // the in-place edit controls for the grid. Instances of wxGridCellEditor
296 // (actually, instances of derived classes since it is an ABC) can be
297 // associated with the cell attributes for individual cells, rows, columns, or
298 // even for the entire grid.
299 // ----------------------------------------------------------------------------
301 class WXDLLIMPEXP_ADV wxGridCellEditor
: public wxGridCellWorker
306 bool IsCreated() { return m_control
!= NULL
; }
307 wxControl
* GetControl() { return m_control
; }
308 void SetControl(wxControl
* control
) { m_control
= control
; }
310 wxGridCellAttr
* GetCellAttr() { return m_attr
; }
311 void SetCellAttr(wxGridCellAttr
* attr
) { m_attr
= attr
; }
313 // Creates the actual edit control
314 virtual void Create(wxWindow
* parent
,
316 wxEvtHandler
* evtHandler
) = 0;
318 // Size and position the edit control
319 virtual void SetSize(const wxRect
& rect
);
321 // Show or hide the edit control, use the specified attributes to set
322 // colours/fonts for it
323 virtual void Show(bool show
, wxGridCellAttr
*attr
= NULL
);
325 // Draws the part of the cell not occupied by the control: the base class
326 // version just fills it with background colour from the attribute
327 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
329 // Fetch the value from the table and prepare the edit control
330 // to begin editing. Set the focus to the edit control.
331 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
333 // Complete the editing of the current cell. Returns true if the value has
334 // changed. If necessary, the control may be destroyed.
335 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
) = 0;
337 // Reset the value in the control back to its starting value
338 virtual void Reset() = 0;
340 // return true to allow the given key to start editing: the base class
341 // version only checks that the event has no modifiers. The derived
342 // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
343 // their IsAcceptedKey() implementation, although, of course, it is not a
344 // mandatory requirment.
346 // NB: if the key is F2 (special), editing will always start and this
347 // method will not be called at all (but StartingKey() will)
348 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
350 // If the editor is enabled by pressing keys on the grid, this will be
351 // called to let the editor do something about that first key if desired
352 virtual void StartingKey(wxKeyEvent
& event
);
354 // if the editor is enabled by clicking on the cell, this method will be
356 virtual void StartingClick();
358 // Some types of controls on some platforms may need some help
359 // with the Return key.
360 virtual void HandleReturn(wxKeyEvent
& event
);
363 virtual void Destroy();
365 // create a new object which is the copy of this one
366 virtual wxGridCellEditor
*Clone() const = 0;
368 // added GetValue so we can get the value which is in the control
369 virtual wxString
GetValue() const = 0;
372 // the dtor is private because only DecRef() can delete us
373 virtual ~wxGridCellEditor();
375 // the control we show on screen
376 wxControl
* m_control
;
378 // a temporary pointer to the attribute being edited
379 wxGridCellAttr
* m_attr
;
381 // if we change the colours/font of the control from the default ones, we
382 // must restore the default later and we save them here between calls to
383 // Show(true) and Show(false)
388 // suppress the stupid gcc warning about the class having private dtor and
390 friend class wxGridCellEditorDummyFriend
;
392 DECLARE_NO_COPY_CLASS(wxGridCellEditor
)
397 // the editor for string/text data
398 class WXDLLIMPEXP_ADV wxGridCellTextEditor
: public wxGridCellEditor
401 wxGridCellTextEditor();
403 virtual void Create(wxWindow
* parent
,
405 wxEvtHandler
* evtHandler
);
406 virtual void SetSize(const wxRect
& rect
);
408 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
410 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
411 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
412 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
414 virtual void Reset();
415 virtual void StartingKey(wxKeyEvent
& event
);
416 virtual void HandleReturn(wxKeyEvent
& event
);
418 // parameters string format is "max_width"
419 virtual void SetParameters(const wxString
& params
);
421 virtual wxGridCellEditor
*Clone() const
422 { return new wxGridCellTextEditor
; }
424 // added GetValue so we can get the value which is in the control
425 virtual wxString
GetValue() const;
428 wxTextCtrl
*Text() const { return (wxTextCtrl
*)m_control
; }
430 // parts of our virtual functions reused by the derived classes
431 void DoCreate(wxWindow
* parent
, wxWindowID id
, wxEvtHandler
* evtHandler
,
433 void DoBeginEdit(const wxString
& startValue
);
434 void DoReset(const wxString
& startValue
);
437 size_t m_maxChars
; // max number of chars allowed
438 wxString m_startValue
;
440 DECLARE_NO_COPY_CLASS(wxGridCellTextEditor
)
443 // the editor for numeric (long) data
444 class WXDLLIMPEXP_ADV wxGridCellNumberEditor
: public wxGridCellTextEditor
447 // allows to specify the range - if min == max == -1, no range checking is
449 wxGridCellNumberEditor(int min
= -1, int max
= -1);
451 virtual void Create(wxWindow
* parent
,
453 wxEvtHandler
* evtHandler
);
455 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
456 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
457 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
459 virtual void Reset();
460 virtual void StartingKey(wxKeyEvent
& event
);
462 // parameters string format is "min,max"
463 virtual void SetParameters(const wxString
& params
);
465 virtual wxGridCellEditor
*Clone() const
466 { return new wxGridCellNumberEditor(m_min
, m_max
); }
468 // added GetValue so we can get the value which is in the control
469 virtual wxString
GetValue() const;
473 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
476 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
477 bool HasRange() const
480 return m_min
!= m_max
;
486 // string representation of m_valueOld
487 wxString
GetString() const
488 { return wxString::Format(_T("%ld"), m_valueOld
); }
496 DECLARE_NO_COPY_CLASS(wxGridCellNumberEditor
)
499 // the editor for floating point numbers (double) data
500 class WXDLLIMPEXP_ADV wxGridCellFloatEditor
: public wxGridCellTextEditor
503 wxGridCellFloatEditor(int width
= -1, int precision
= -1);
505 virtual void Create(wxWindow
* parent
,
507 wxEvtHandler
* evtHandler
);
509 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
510 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
511 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
513 virtual void Reset();
514 virtual void StartingKey(wxKeyEvent
& event
);
516 virtual wxGridCellEditor
*Clone() const
517 { return new wxGridCellFloatEditor(m_width
, m_precision
); }
519 // parameters string format is "width,precision"
520 virtual void SetParameters(const wxString
& params
);
523 // string representation of m_valueOld
524 wxString
GetString() const;
531 DECLARE_NO_COPY_CLASS(wxGridCellFloatEditor
)
534 #endif // wxUSE_TEXTCTRL
538 // the editor for boolean data
539 class WXDLLIMPEXP_ADV wxGridCellBoolEditor
: public wxGridCellEditor
542 wxGridCellBoolEditor() { }
544 virtual void Create(wxWindow
* parent
,
546 wxEvtHandler
* evtHandler
);
548 virtual void SetSize(const wxRect
& rect
);
549 virtual void Show(bool show
, wxGridCellAttr
*attr
= NULL
);
551 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
552 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
553 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
555 virtual void Reset();
556 virtual void StartingClick();
557 virtual void StartingKey(wxKeyEvent
& event
);
559 virtual wxGridCellEditor
*Clone() const
560 { return new wxGridCellBoolEditor
; }
562 // added GetValue so we can get the value which is in the control, see
563 // also UseStringValues()
564 virtual wxString
GetValue() const;
566 // set the string values returned by GetValue() for the true and false
567 // states, respectively
568 static void UseStringValues(const wxString
& valueTrue
= _T("1"),
569 const wxString
& valueFalse
= wxEmptyString
);
571 // return true if the given string is equal to the string representation of
572 // true value which we currently use
573 static bool IsTrueValue(const wxString
& value
);
576 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
581 static wxString ms_stringValues
[2];
583 DECLARE_NO_COPY_CLASS(wxGridCellBoolEditor
)
586 #endif // wxUSE_CHECKBOX
590 // the editor for string data allowing to choose from the list of strings
591 class WXDLLIMPEXP_ADV wxGridCellChoiceEditor
: public wxGridCellEditor
594 // if !allowOthers, user can't type a string not in choices array
595 wxGridCellChoiceEditor(size_t count
= 0,
596 const wxString choices
[] = NULL
,
597 bool allowOthers
= false);
598 wxGridCellChoiceEditor(const wxArrayString
& choices
,
599 bool allowOthers
= false);
601 virtual void Create(wxWindow
* parent
,
603 wxEvtHandler
* evtHandler
);
605 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
607 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
608 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
610 virtual void Reset();
612 // parameters string format is "item1[,item2[...,itemN]]"
613 virtual void SetParameters(const wxString
& params
);
615 virtual wxGridCellEditor
*Clone() const;
617 // added GetValue so we can get the value which is in the control
618 virtual wxString
GetValue() const;
621 wxComboBox
*Combo() const { return (wxComboBox
*)m_control
; }
623 // DJC - (MAPTEK) you at least need access to m_choices if you
624 // wish to override this class
626 wxString m_startValue
;
627 wxArrayString m_choices
;
630 DECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor
)
633 #endif // wxUSE_COMBOBOX
635 // ----------------------------------------------------------------------------
636 // wxGridCellAttr: this class can be used to alter the cells appearance in
637 // the grid by changing their colour/font/... from default. An object of this
638 // class may be returned by wxGridTable::GetAttr().
639 // ----------------------------------------------------------------------------
641 class WXDLLIMPEXP_ADV wxGridCellAttr
: public wxClientDataContainer
655 wxGridCellAttr(wxGridCellAttr
*attrDefault
= NULL
)
659 // MB: args used to be 0,0 here but wxALIGN_LEFT is 0
660 SetAlignment(-1, -1);
663 // VZ: considering the number of members wxGridCellAttr has now, this ctor
664 // seems to be pretty useless... may be we should just remove it?
665 wxGridCellAttr(const wxColour
& colText
,
666 const wxColour
& colBack
,
670 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
673 SetAlignment(hAlign
, vAlign
);
676 // creates a new copy of this object
677 wxGridCellAttr
*Clone() const;
678 void MergeWith(wxGridCellAttr
*mergefrom
);
680 // this class is ref counted: it is created with ref count of 1, so
681 // calling DecRef() once will delete it. Calling IncRef() allows to lock
682 // it until the matching DecRef() is called
683 void IncRef() { m_nRef
++; }
684 void DecRef() { if ( --m_nRef
== 0 ) delete this; }
687 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
688 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
689 void SetFont(const wxFont
& font
) { m_font
= font
; }
690 void SetAlignment(int hAlign
, int vAlign
)
695 void SetSize(int num_rows
, int num_cols
);
696 void SetOverflow(bool allow
= true)
697 { m_overflow
= allow
? Overflow
: SingleCell
; }
698 void SetReadOnly(bool isReadOnly
= true)
699 { m_isReadOnly
= isReadOnly
? ReadOnly
: ReadWrite
; }
701 // takes ownership of the pointer
702 void SetRenderer(wxGridCellRenderer
*renderer
)
703 { wxSafeDecRef(m_renderer
); m_renderer
= renderer
; }
704 void SetEditor(wxGridCellEditor
* editor
)
705 { wxSafeDecRef(m_editor
); m_editor
= editor
; }
707 void SetKind(wxAttrKind kind
) { m_attrkind
= kind
; }
710 bool HasTextColour() const { return m_colText
.Ok(); }
711 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
712 bool HasFont() const { return m_font
.Ok(); }
713 bool HasAlignment() const { return (m_hAlign
!= -1 || m_vAlign
!= -1); }
714 bool HasRenderer() const { return m_renderer
!= NULL
; }
715 bool HasEditor() const { return m_editor
!= NULL
; }
716 bool HasReadWriteMode() const { return m_isReadOnly
!= Unset
; }
717 bool HasOverflowMode() const { return m_overflow
!= UnsetOverflow
; }
718 bool HasSize() const { return m_sizeRows
!= 1 || m_sizeCols
!= 1; }
720 const wxColour
& GetTextColour() const;
721 const wxColour
& GetBackgroundColour() const;
722 const wxFont
& GetFont() const;
723 void GetAlignment(int *hAlign
, int *vAlign
) const;
724 void GetSize(int *num_rows
, int *num_cols
) const;
725 bool GetOverflow() const
726 { return m_overflow
!= SingleCell
; }
727 wxGridCellRenderer
*GetRenderer(const wxGrid
* grid
, int row
, int col
) const;
728 wxGridCellEditor
*GetEditor(const wxGrid
* grid
, int row
, int col
) const;
730 bool IsReadOnly() const { return m_isReadOnly
== wxGridCellAttr::ReadOnly
; }
732 wxAttrKind
GetKind() { return m_attrkind
; }
734 void SetDefAttr(wxGridCellAttr
* defAttr
) { m_defGridAttr
= defAttr
; }
737 // the dtor is private because only DecRef() can delete us
738 virtual ~wxGridCellAttr()
740 wxSafeDecRef(m_renderer
);
741 wxSafeDecRef(m_editor
);
752 enum wxAttrOverflowMode
759 // the common part of all ctors
760 void Init(wxGridCellAttr
*attrDefault
= NULL
);
763 // the ref count - when it goes to 0, we die
774 wxAttrOverflowMode m_overflow
;
776 wxGridCellRenderer
* m_renderer
;
777 wxGridCellEditor
* m_editor
;
778 wxGridCellAttr
* m_defGridAttr
;
780 wxAttrReadMode m_isReadOnly
;
782 wxAttrKind m_attrkind
;
784 // use Clone() instead
785 DECLARE_NO_COPY_CLASS(wxGridCellAttr
)
787 // suppress the stupid gcc warning about the class having private dtor and
789 friend class wxGridCellAttrDummyFriend
;
792 // ----------------------------------------------------------------------------
793 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
795 // ----------------------------------------------------------------------------
797 // implementation note: we separate it from wxGridTableBase because we wish to
798 // avoid deriving a new table class if possible, and sometimes it will be
799 // enough to just derive another wxGridCellAttrProvider instead
801 // the default implementation is reasonably efficient for the generic case,
802 // but you might still wish to implement your own for some specific situations
803 // if you have performance problems with the stock one
804 class WXDLLIMPEXP_ADV wxGridCellAttrProvider
: public wxClientDataContainer
807 wxGridCellAttrProvider();
808 virtual ~wxGridCellAttrProvider();
810 // DecRef() must be called on the returned pointer
811 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
812 wxGridCellAttr::wxAttrKind kind
) const;
814 // all these functions take ownership of the pointer, don't call DecRef()
816 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
817 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
818 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
820 // these functions must be called whenever some rows/cols are deleted
821 // because the internal data must be updated then
822 void UpdateAttrRows( size_t pos
, int numRows
);
823 void UpdateAttrCols( size_t pos
, int numCols
);
828 wxGridCellAttrProviderData
*m_data
;
830 DECLARE_NO_COPY_CLASS(wxGridCellAttrProvider
)
833 // ----------------------------------------------------------------------------
834 // wxGridCellCoords: location of a cell in the grid
835 // ----------------------------------------------------------------------------
837 class WXDLLIMPEXP_ADV wxGridCellCoords
840 wxGridCellCoords() { m_row
= m_col
= -1; }
841 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
843 // default copy ctor is ok
845 int GetRow() const { return m_row
; }
846 void SetRow( int n
) { m_row
= n
; }
847 int GetCol() const { return m_col
; }
848 void SetCol( int n
) { m_col
= n
; }
849 void Set( int row
, int col
) { m_row
= row
; m_col
= col
; }
851 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
853 if ( &other
!= this )
861 bool operator==( const wxGridCellCoords
& other
) const
863 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
866 bool operator!=( const wxGridCellCoords
& other
) const
868 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
871 bool operator!() const
873 return (m_row
== -1 && m_col
== -1 );
882 // For comparisons...
884 extern WXDLLIMPEXP_ADV wxGridCellCoords wxGridNoCellCoords
;
885 extern WXDLLIMPEXP_ADV wxRect wxGridNoCellRect
;
887 // An array of cell coords...
889 WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords
, wxGridCellCoordsArray
,
890 class WXDLLIMPEXP_ADV
);
892 // ----------------------------------------------------------------------------
893 // Grid table classes
894 // ----------------------------------------------------------------------------
896 // the abstract base class
897 class WXDLLIMPEXP_ADV wxGridTableBase
: public wxObject
,
898 public wxClientDataContainer
902 virtual ~wxGridTableBase();
904 // You must override these functions in a derived table class
907 // return the number of rows and columns in this table
908 virtual int GetNumberRows() = 0;
909 virtual int GetNumberCols() = 0;
911 // the methods above are unfortunately non-const even though they should
912 // have been const -- but changing it now is not possible any longer as it
913 // would break the existing code overriding them, so instead we provide
914 // these const synonyms which can be used from const-correct code
915 int GetRowsCount() const
916 { return wx_const_cast(wxGridTableBase
*, this)->GetNumberRows(); }
917 int GetColsCount() const
918 { return wx_const_cast(wxGridTableBase
*, this)->GetNumberCols(); }
921 virtual bool IsEmptyCell( int row
, int col
) = 0;
923 bool IsEmpty(const wxGridCellCoords
& coord
)
925 return IsEmptyCell(coord
.GetRow(), coord
.GetCol());
928 virtual wxString
GetValue( int row
, int col
) = 0;
929 virtual void SetValue( int row
, int col
, const wxString
& value
) = 0;
931 // Data type determination and value access
932 virtual wxString
GetTypeName( int row
, int col
);
933 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
934 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
936 virtual long GetValueAsLong( int row
, int col
);
937 virtual double GetValueAsDouble( int row
, int col
);
938 virtual bool GetValueAsBool( int row
, int col
);
940 virtual void SetValueAsLong( int row
, int col
, long value
);
941 virtual void SetValueAsDouble( int row
, int col
, double value
);
942 virtual void SetValueAsBool( int row
, int col
, bool value
);
944 // For user defined types
945 virtual void* GetValueAsCustom( int row
, int col
, const wxString
& typeName
);
946 virtual void SetValueAsCustom( int row
, int col
, const wxString
& typeName
, void* value
);
949 // Overriding these is optional
951 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
952 virtual wxGrid
* GetView() const { return m_view
; }
954 virtual void Clear() {}
955 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
956 virtual bool AppendRows( size_t numRows
= 1 );
957 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
958 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
959 virtual bool AppendCols( size_t numCols
= 1 );
960 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
962 virtual wxString
GetRowLabelValue( int row
);
963 virtual wxString
GetColLabelValue( int col
);
964 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
965 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
967 // Attribute handling
970 // give us the attr provider to use - we take ownership of the pointer
971 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
973 // get the currently used attr provider (may be NULL)
974 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
976 // Does this table allow attributes? Default implementation creates
977 // a wxGridCellAttrProvider if necessary.
978 virtual bool CanHaveAttributes();
980 // by default forwarded to wxGridCellAttrProvider if any. May be
981 // overridden to handle attributes directly in the table.
982 virtual wxGridCellAttr
*GetAttr( int row
, int col
,
983 wxGridCellAttr::wxAttrKind kind
);
986 // these functions take ownership of the pointer
987 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
988 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
989 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
993 wxGridCellAttrProvider
*m_attrProvider
;
995 DECLARE_ABSTRACT_CLASS(wxGridTableBase
)
996 DECLARE_NO_COPY_CLASS(wxGridTableBase
)
1000 // ----------------------------------------------------------------------------
1001 // wxGridTableMessage
1002 // ----------------------------------------------------------------------------
1004 // IDs for messages sent from grid table to view
1006 enum wxGridTableRequest
1008 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
1009 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
1010 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
1011 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
1012 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
1013 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
1014 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
1015 wxGRIDTABLE_NOTIFY_COLS_DELETED
1018 class WXDLLIMPEXP_ADV wxGridTableMessage
1021 wxGridTableMessage();
1022 wxGridTableMessage( wxGridTableBase
*table
, int id
,
1026 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
1027 wxGridTableBase
* GetTableObject() const { return m_table
; }
1028 void SetId( int id
) { m_id
= id
; }
1029 int GetId() { return m_id
; }
1030 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
1031 int GetCommandInt() { return m_comInt1
; }
1032 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
1033 int GetCommandInt2() { return m_comInt2
; }
1036 wxGridTableBase
*m_table
;
1041 DECLARE_NO_COPY_CLASS(wxGridTableMessage
)
1046 // ------ wxGridStringArray
1047 // A 2-dimensional array of strings for data values
1050 WX_DECLARE_OBJARRAY_WITH_DECL(wxArrayString
, wxGridStringArray
,
1051 class WXDLLIMPEXP_ADV
);
1055 // ------ wxGridStringTable
1057 // Simplest type of data table for a grid for small tables of strings
1058 // that are stored in memory
1061 class WXDLLIMPEXP_ADV wxGridStringTable
: public wxGridTableBase
1064 wxGridStringTable();
1065 wxGridStringTable( int numRows
, int numCols
);
1066 virtual ~wxGridStringTable();
1068 // these are pure virtual in wxGridTableBase
1070 int GetNumberRows();
1071 int GetNumberCols();
1072 wxString
GetValue( int row
, int col
);
1073 void SetValue( int row
, int col
, const wxString
& s
);
1074 bool IsEmptyCell( int row
, int col
);
1076 // overridden functions from wxGridTableBase
1079 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
1080 bool AppendRows( size_t numRows
= 1 );
1081 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
1082 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
1083 bool AppendCols( size_t numCols
= 1 );
1084 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
1086 void SetRowLabelValue( int row
, const wxString
& );
1087 void SetColLabelValue( int col
, const wxString
& );
1088 wxString
GetRowLabelValue( int row
);
1089 wxString
GetColLabelValue( int col
);
1092 wxGridStringArray m_data
;
1094 // These only get used if you set your own labels, otherwise the
1095 // GetRow/ColLabelValue functions return wxGridTableBase defaults
1097 wxArrayString m_rowLabels
;
1098 wxArrayString m_colLabels
;
1100 DECLARE_DYNAMIC_CLASS_NO_COPY( wxGridStringTable
)
1105 // ============================================================================
1106 // Grid view classes
1107 // ============================================================================
1109 // ----------------------------------------------------------------------------
1111 // ----------------------------------------------------------------------------
1113 class WXDLLIMPEXP_ADV wxGrid
: public wxScrolledWindow
1116 // possible selection modes
1117 enum wxGridSelectionModes
1119 wxGridSelectCells
= 0, // allow selecting anything
1120 wxGridSelectRows
= 1, // allow selecting only entire rows
1121 wxGridSelectColumns
= 2, // allow selecting only entire columns
1122 wxGridSelectRowsOrColumns
= wxGridSelectRows
| wxGridSelectColumns
1125 // creation and destruction
1126 // ------------------------
1128 // ctor and Create() create the grid window, as with the other controls
1131 wxGrid(wxWindow
*parent
,
1133 const wxPoint
& pos
= wxDefaultPosition
,
1134 const wxSize
& size
= wxDefaultSize
,
1135 long style
= wxWANTS_CHARS
,
1136 const wxString
& name
= wxGridNameStr
);
1138 bool Create(wxWindow
*parent
,
1140 const wxPoint
& pos
= wxDefaultPosition
,
1141 const wxSize
& size
= wxDefaultSize
,
1142 long style
= wxWANTS_CHARS
,
1143 const wxString
& name
= wxGridNameStr
);
1147 // however to initialize grid data either CreateGrid() or SetTable() must
1150 // this is basically equivalent to
1152 // SetTable(new wxGridStringTable(numRows, numCols), true, selmode)
1154 bool CreateGrid( int numRows
, int numCols
,
1155 wxGridSelectionModes selmode
= wxGridSelectCells
);
1157 bool SetTable( wxGridTableBase
*table
,
1158 bool takeOwnership
= false,
1159 wxGridSelectionModes selmode
= wxGridSelectCells
);
1161 bool ProcessTableMessage(wxGridTableMessage
&);
1163 wxGridTableBase
*GetTable() const { return m_table
; }
1166 void SetSelectionMode(wxGridSelectionModes selmode
);
1167 wxGridSelectionModes
GetSelectionMode() const;
1169 // ------ grid dimensions
1171 int GetNumberRows() const { return m_numRows
; }
1172 int GetNumberCols() const { return m_numCols
; }
1175 // ------ display update functions
1177 wxArrayInt
CalcRowLabelsExposed( const wxRegion
& reg
) const;
1179 wxArrayInt
CalcColLabelsExposed( const wxRegion
& reg
) const;
1180 wxGridCellCoordsArray
CalcCellsExposed( const wxRegion
& reg
) const;
1184 bool InsertRows(int pos
= 0, int numRows
= 1, bool updateLabels
= true)
1186 return DoModifyLines(&wxGridTableBase::InsertRows
,
1187 pos
, numRows
, updateLabels
);
1189 bool InsertCols(int pos
= 0, int numCols
= 1, bool updateLabels
= true)
1191 return DoModifyLines(&wxGridTableBase::InsertCols
,
1192 pos
, numCols
, updateLabels
);
1195 bool AppendRows(int numRows
= 1, bool updateLabels
= true)
1197 return DoAppendLines(&wxGridTableBase::AppendRows
, numRows
, updateLabels
);
1199 bool AppendCols(int numCols
= 1, bool updateLabels
= true)
1201 return DoAppendLines(&wxGridTableBase::AppendCols
, numCols
, updateLabels
);
1204 bool DeleteRows(int pos
= 0, int numRows
= 1, bool updateLabels
= true)
1206 return DoModifyLines(&wxGridTableBase::DeleteRows
,
1207 pos
, numRows
, updateLabels
);
1209 bool DeleteCols(int pos
= 0, int numCols
= 1, bool updateLabels
= true)
1211 return DoModifyLines(&wxGridTableBase::DeleteCols
,
1212 pos
, numCols
, updateLabels
);
1215 void DrawGridCellArea( wxDC
& dc
, const wxGridCellCoordsArray
& cells
);
1216 void DrawGridSpace( wxDC
& dc
);
1217 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
1218 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
1219 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
1220 void DrawHighlight(wxDC
& dc
, const wxGridCellCoordsArray
& cells
);
1222 // this function is called when the current cell highlight must be redrawn
1223 // and may be overridden by the user
1224 virtual void DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
);
1226 virtual void DrawRowLabels( wxDC
& dc
, const wxArrayInt
& rows
);
1227 virtual void DrawRowLabel( wxDC
& dc
, int row
);
1229 virtual void DrawColLabels( wxDC
& dc
, const wxArrayInt
& cols
);
1230 virtual void DrawColLabel( wxDC
& dc
, int col
);
1232 virtual void DrawCornerLabel(wxDC
& dc
);
1234 // ------ Cell text drawing functions
1236 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
1237 int horizontalAlignment
= wxALIGN_LEFT
,
1238 int verticalAlignment
= wxALIGN_TOP
,
1239 int textOrientation
= wxHORIZONTAL
);
1241 void DrawTextRectangle( wxDC
& dc
, const wxArrayString
& lines
, const wxRect
&,
1242 int horizontalAlignment
= wxALIGN_LEFT
,
1243 int verticalAlignment
= wxALIGN_TOP
,
1244 int textOrientation
= wxHORIZONTAL
);
1247 // Split a string containing newline characters into an array of
1248 // strings and return the number of lines
1250 void StringToLines( const wxString
& value
, wxArrayString
& lines
) const;
1252 void GetTextBoxSize( const wxDC
& dc
,
1253 const wxArrayString
& lines
,
1254 long *width
, long *height
) const;
1258 // Code that does a lot of grid modification can be enclosed
1259 // between BeginBatch() and EndBatch() calls to avoid screen
1262 void BeginBatch() { m_batchCount
++; }
1265 int GetBatchCount() { return m_batchCount
; }
1267 virtual void Refresh(bool eraseb
= true, const wxRect
* rect
= NULL
);
1269 // Use this, rather than wxWindow::Refresh(), to force an
1270 // immediate repainting of the grid. Has no effect if you are
1271 // already inside a BeginBatch / EndBatch block.
1273 // This function is necessary because wxGrid has a minimal OnPaint()
1274 // handler to reduce screen flicker.
1276 void ForceRefresh();
1279 // ------ edit control functions
1281 bool IsEditable() const { return m_editable
; }
1282 void EnableEditing( bool edit
);
1284 void EnableCellEditControl( bool enable
= true );
1285 void DisableCellEditControl() { EnableCellEditControl(false); }
1286 bool CanEnableCellControl() const;
1287 bool IsCellEditControlEnabled() const;
1288 bool IsCellEditControlShown() const;
1290 bool IsCurrentCellReadOnly() const;
1292 void ShowCellEditControl();
1293 void HideCellEditControl();
1294 void SaveEditControlValue();
1297 // ------ grid location functions
1298 // Note that all of these functions work with the logical coordinates of
1299 // grid cells and labels so you will need to convert from device
1300 // coordinates for mouse events etc.
1302 wxGridCellCoords
XYToCell(int x
, int y
) const;
1303 void XYToCell(int x
, int y
, wxGridCellCoords
& coords
) const
1304 { coords
= XYToCell(x
, y
); }
1305 wxGridCellCoords
XYToCell(const wxPoint
& pos
) const
1306 { return XYToCell(pos
.x
, pos
.y
); }
1308 int YToRow( int y
, bool clipToMinMax
= false ) const;
1309 int XToCol( int x
, bool clipToMinMax
= false ) const;
1311 int YToEdgeOfRow( int y
) const;
1312 int XToEdgeOfCol( int x
) const;
1314 wxRect
CellToRect( int row
, int col
) const;
1315 wxRect
CellToRect( const wxGridCellCoords
& coords
) const
1316 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
1318 int GetGridCursorRow() const { return m_currentCellCoords
.GetRow(); }
1319 int GetGridCursorCol() const { return m_currentCellCoords
.GetCol(); }
1321 // check to see if a cell is either wholly visible (the default arg) or
1322 // at least partially visible in the grid window
1324 bool IsVisible( int row
, int col
, bool wholeCellVisible
= true ) const;
1325 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= true ) const
1326 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
1327 void MakeCellVisible( int row
, int col
);
1328 void MakeCellVisible( const wxGridCellCoords
& coords
)
1329 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
1332 // ------ grid cursor movement functions
1334 void SetGridCursor(int row
, int col
) { SetCurrentCell(row
, col
); }
1335 void SetGridCursor(const wxGridCellCoords
& c
) { SetCurrentCell(c
); }
1337 void GoToCell(int row
, int col
)
1339 if ( SetCurrentCell(row
, col
) )
1340 MakeCellVisible(row
, col
);
1343 void GoToCell(const wxGridCellCoords
& coords
)
1345 if ( SetCurrentCell(coords
) )
1346 MakeCellVisible(coords
);
1349 bool MoveCursorUp( bool expandSelection
);
1350 bool MoveCursorDown( bool expandSelection
);
1351 bool MoveCursorLeft( bool expandSelection
);
1352 bool MoveCursorRight( bool expandSelection
);
1353 bool MovePageDown();
1355 bool MoveCursorUpBlock( bool expandSelection
);
1356 bool MoveCursorDownBlock( bool expandSelection
);
1357 bool MoveCursorLeftBlock( bool expandSelection
);
1358 bool MoveCursorRightBlock( bool expandSelection
);
1361 // ------ label and gridline formatting
1363 int GetDefaultRowLabelSize() const { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
1364 int GetRowLabelSize() const { return m_rowLabelWidth
; }
1365 int GetDefaultColLabelSize() const { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
1366 int GetColLabelSize() const { return m_colLabelHeight
; }
1367 wxColour
GetLabelBackgroundColour() const { return m_labelBackgroundColour
; }
1368 wxColour
GetLabelTextColour() const { return m_labelTextColour
; }
1369 wxFont
GetLabelFont() const { return m_labelFont
; }
1370 void GetRowLabelAlignment( int *horiz
, int *vert
) const;
1371 void GetColLabelAlignment( int *horiz
, int *vert
) const;
1372 int GetColLabelTextOrientation() const;
1373 wxString
GetRowLabelValue( int row
) const;
1374 wxString
GetColLabelValue( int col
) const;
1376 wxColour
GetCellHighlightColour() const { return m_cellHighlightColour
; }
1377 int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth
; }
1378 int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth
; }
1380 void SetUseNativeColLabels( bool native
= true );
1381 void SetRowLabelSize( int width
);
1382 void SetColLabelSize( int height
);
1383 void HideRowLabels() { SetRowLabelSize( 0 ); }
1384 void HideColLabels() { SetColLabelSize( 0 ); }
1385 void SetLabelBackgroundColour( const wxColour
& );
1386 void SetLabelTextColour( const wxColour
& );
1387 void SetLabelFont( const wxFont
& );
1388 void SetRowLabelAlignment( int horiz
, int vert
);
1389 void SetColLabelAlignment( int horiz
, int vert
);
1390 void SetColLabelTextOrientation( int textOrientation
);
1391 void SetRowLabelValue( int row
, const wxString
& );
1392 void SetColLabelValue( int col
, const wxString
& );
1393 void SetCellHighlightColour( const wxColour
& );
1394 void SetCellHighlightPenWidth(int width
);
1395 void SetCellHighlightROPenWidth(int width
);
1397 void EnableDragRowSize( bool enable
= true );
1398 void DisableDragRowSize() { EnableDragRowSize( false ); }
1399 bool CanDragRowSize() const { return m_canDragRowSize
; }
1400 void EnableDragColSize( bool enable
= true );
1401 void DisableDragColSize() { EnableDragColSize( false ); }
1402 bool CanDragColSize() const { return m_canDragColSize
; }
1403 void EnableDragColMove( bool enable
= true );
1404 void DisableDragColMove() { EnableDragColMove( false ); }
1405 bool CanDragColMove() const { return m_canDragColMove
; }
1406 void EnableDragGridSize(bool enable
= true);
1407 void DisableDragGridSize() { EnableDragGridSize(false); }
1408 bool CanDragGridSize() const { return m_canDragGridSize
; }
1410 void EnableDragCell( bool enable
= true );
1411 void DisableDragCell() { EnableDragCell( false ); }
1412 bool CanDragCell() const { return m_canDragCell
; }
1418 // enable or disable drawing of the lines
1419 void EnableGridLines(bool enable
= true);
1420 bool GridLinesEnabled() const { return m_gridLinesEnabled
; }
1422 // by default grid lines stop at last column/row, but this may be changed
1423 void ClipHorzGridLines(bool clip
)
1424 { DoClipGridLines(m_gridLinesClipHorz
, clip
); }
1425 void ClipVertGridLines(bool clip
)
1426 { DoClipGridLines(m_gridLinesClipVert
, clip
); }
1427 bool AreHorzGridLinesClipped() const { return m_gridLinesClipHorz
; }
1428 bool AreVertGridLinesClipped() const { return m_gridLinesClipVert
; }
1430 // this can be used to change the global grid lines colour
1431 void SetGridLineColour(const wxColour
& col
);
1432 wxColour
GetGridLineColour() const { return m_gridLineColour
; }
1434 // these methods may be overridden to customize individual grid lines
1436 virtual wxPen
GetDefaultGridLinePen();
1437 virtual wxPen
GetRowGridLinePen(int row
);
1438 virtual wxPen
GetColGridLinePen(int col
);
1444 // this sets the specified attribute for this cell or in this row/col
1445 void SetAttr(int row
, int col
, wxGridCellAttr
*attr
);
1446 void SetRowAttr(int row
, wxGridCellAttr
*attr
);
1447 void SetColAttr(int col
, wxGridCellAttr
*attr
);
1449 // returns the attribute we may modify in place: a new one if this cell
1450 // doesn't have any yet or the existing one if it does
1452 // DecRef() must be called on the returned pointer, as usual
1453 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
1456 // shortcuts for setting the column parameters
1458 // set the format for the data in the column: default is string
1459 void SetColFormatBool(int col
);
1460 void SetColFormatNumber(int col
);
1461 void SetColFormatFloat(int col
, int width
= -1, int precision
= -1);
1462 void SetColFormatCustom(int col
, const wxString
& typeName
);
1464 // ------ row and col formatting
1466 int GetDefaultRowSize() const;
1467 int GetRowSize( int row
) const;
1468 int GetDefaultColSize() const;
1469 int GetColSize( int col
) const;
1470 wxColour
GetDefaultCellBackgroundColour() const;
1471 wxColour
GetCellBackgroundColour( int row
, int col
) const;
1472 wxColour
GetDefaultCellTextColour() const;
1473 wxColour
GetCellTextColour( int row
, int col
) const;
1474 wxFont
GetDefaultCellFont() const;
1475 wxFont
GetCellFont( int row
, int col
) const;
1476 void GetDefaultCellAlignment( int *horiz
, int *vert
) const;
1477 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
) const;
1478 bool GetDefaultCellOverflow() const;
1479 bool GetCellOverflow( int row
, int col
) const;
1480 void GetCellSize( int row
, int col
, int *num_rows
, int *num_cols
) const;
1481 wxSize
GetCellSize(const wxGridCellCoords
& coords
)
1484 GetCellSize(coords
.GetRow(), coords
.GetCol(), &s
.x
, &s
.y
);
1488 void SetDefaultRowSize( int height
, bool resizeExistingRows
= false );
1489 void SetRowSize( int row
, int height
);
1490 void SetDefaultColSize( int width
, bool resizeExistingCols
= false );
1492 void SetColSize( int col
, int width
);
1495 int GetColAt( int colPos
) const
1497 if ( m_colAt
.IsEmpty() )
1500 return m_colAt
[colPos
];
1503 void SetColPos( int colID
, int newPos
);
1505 int GetColPos( int colID
) const
1507 if ( m_colAt
.IsEmpty() )
1511 for ( int i
= 0; i
< m_numCols
; i
++ )
1513 if ( m_colAt
[i
] == colID
)
1521 // automatically size the column or row to fit to its contents, if
1522 // setAsMin is true, this optimal width will also be set as minimal width
1524 void AutoSizeColumn( int col
, bool setAsMin
= true )
1525 { AutoSizeColOrRow(col
, setAsMin
, wxGRID_COLUMN
); }
1526 void AutoSizeRow( int row
, bool setAsMin
= true )
1527 { AutoSizeColOrRow(row
, setAsMin
, wxGRID_ROW
); }
1529 // auto size all columns (very ineffective for big grids!)
1530 void AutoSizeColumns( bool setAsMin
= true )
1531 { (void)SetOrCalcColumnSizes(false, setAsMin
); }
1533 void AutoSizeRows( bool setAsMin
= true )
1534 { (void)SetOrCalcRowSizes(false, setAsMin
); }
1536 // auto size the grid, that is make the columns/rows of the "right" size
1537 // and also set the grid size to just fit its contents
1540 // Note for both AutoSizeRowLabelSize and AutoSizeColLabelSize:
1541 // If col equals to wxGRID_AUTOSIZE value then function autosizes labels column
1542 // instead of data column. Note that this operation may be slow for large
1544 // autosize row height depending on label text
1545 void AutoSizeRowLabelSize( int row
);
1547 // autosize column width depending on label text
1548 void AutoSizeColLabelSize( int col
);
1550 // column won't be resized to be lesser width - this must be called during
1551 // the grid creation because it won't resize the column if it's already
1552 // narrower than the minimal width
1553 void SetColMinimalWidth( int col
, int width
);
1554 void SetRowMinimalHeight( int row
, int width
);
1556 /* These members can be used to query and modify the minimal
1557 * acceptable size of grid rows and columns. Call this function in
1558 * your code which creates the grid if you want to display cells
1559 * with a size smaller than the default acceptable minimum size.
1560 * Like the members SetColMinimalWidth and SetRowMinimalWidth,
1561 * the existing rows or columns will not be checked/resized.
1563 void SetColMinimalAcceptableWidth( int width
);
1564 void SetRowMinimalAcceptableHeight( int width
);
1565 int GetColMinimalAcceptableWidth() const;
1566 int GetRowMinimalAcceptableHeight() const;
1568 void SetDefaultCellBackgroundColour( const wxColour
& );
1569 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
1570 void SetDefaultCellTextColour( const wxColour
& );
1572 void SetCellTextColour( int row
, int col
, const wxColour
& );
1573 void SetDefaultCellFont( const wxFont
& );
1574 void SetCellFont( int row
, int col
, const wxFont
& );
1575 void SetDefaultCellAlignment( int horiz
, int vert
);
1576 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
1577 void SetDefaultCellOverflow( bool allow
);
1578 void SetCellOverflow( int row
, int col
, bool allow
);
1579 void SetCellSize( int row
, int col
, int num_rows
, int num_cols
);
1581 // takes ownership of the pointer
1582 void SetDefaultRenderer(wxGridCellRenderer
*renderer
);
1583 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
);
1584 wxGridCellRenderer
*GetDefaultRenderer() const;
1585 wxGridCellRenderer
* GetCellRenderer(int row
, int col
) const;
1587 // takes ownership of the pointer
1588 void SetDefaultEditor(wxGridCellEditor
*editor
);
1589 void SetCellEditor(int row
, int col
, wxGridCellEditor
*editor
);
1590 wxGridCellEditor
*GetDefaultEditor() const;
1591 wxGridCellEditor
* GetCellEditor(int row
, int col
) const;
1595 // ------ cell value accessors
1597 wxString
GetCellValue( int row
, int col
) const
1601 return m_table
->GetValue( row
, col
);
1605 return wxEmptyString
;
1609 wxString
GetCellValue( const wxGridCellCoords
& coords
) const
1610 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
1612 void SetCellValue( int row
, int col
, const wxString
& s
);
1613 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
1614 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
1616 // returns true if the cell can't be edited
1617 bool IsReadOnly(int row
, int col
) const;
1619 // make the cell editable/readonly
1620 void SetReadOnly(int row
, int col
, bool isReadOnly
= true);
1622 // ------ select blocks of cells
1624 void SelectRow( int row
, bool addToSelected
= false );
1625 void SelectCol( int col
, bool addToSelected
= false );
1627 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
,
1628 bool addToSelected
= false );
1630 void SelectBlock( const wxGridCellCoords
& topLeft
,
1631 const wxGridCellCoords
& bottomRight
,
1632 bool addToSelected
= false )
1633 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1634 bottomRight
.GetRow(), bottomRight
.GetCol(),
1639 bool IsSelection() const;
1641 // ------ deselect blocks or cells
1643 void DeselectRow( int row
);
1644 void DeselectCol( int col
);
1645 void DeselectCell( int row
, int col
);
1647 void ClearSelection();
1649 bool IsInSelection( int row
, int col
) const;
1651 bool IsInSelection( const wxGridCellCoords
& coords
) const
1652 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
1654 wxGridCellCoordsArray
GetSelectedCells() const;
1655 wxGridCellCoordsArray
GetSelectionBlockTopLeft() const;
1656 wxGridCellCoordsArray
GetSelectionBlockBottomRight() const;
1657 wxArrayInt
GetSelectedRows() const;
1658 wxArrayInt
GetSelectedCols() const;
1660 // This function returns the rectangle that encloses the block of cells
1661 // limited by TopLeft and BottomRight cell in device coords and clipped
1662 // to the client size of the grid window.
1664 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
1665 const wxGridCellCoords
& bottomRight
) const;
1667 // Access or update the selection fore/back colours
1668 wxColour
GetSelectionBackground() const
1669 { return m_selectionBackground
; }
1670 wxColour
GetSelectionForeground() const
1671 { return m_selectionForeground
; }
1673 void SetSelectionBackground(const wxColour
& c
) { m_selectionBackground
= c
; }
1674 void SetSelectionForeground(const wxColour
& c
) { m_selectionForeground
= c
; }
1677 // Methods for a registry for mapping data types to Renderers/Editors
1678 void RegisterDataType(const wxString
& typeName
,
1679 wxGridCellRenderer
* renderer
,
1680 wxGridCellEditor
* editor
);
1682 virtual wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
1683 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const
1684 { return GetDefaultEditorForCell(c
.GetRow(), c
.GetCol()); }
1685 virtual wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
1686 virtual wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
1687 virtual wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
1689 // grid may occupy more space than needed for its rows/columns, this
1690 // function allows to set how big this extra space is
1691 void SetMargins(int extraWidth
, int extraHeight
)
1693 m_extraWidth
= extraWidth
;
1694 m_extraHeight
= extraHeight
;
1699 // Accessors for component windows
1700 wxWindow
* GetGridWindow() const { return (wxWindow
*)m_gridWin
; }
1701 wxWindow
* GetGridRowLabelWindow() const { return (wxWindow
*)m_rowLabelWin
; }
1702 wxWindow
* GetGridColLabelWindow() const { return (wxWindow
*)m_colLabelWin
; }
1703 wxWindow
* GetGridCornerLabelWindow() const { return (wxWindow
*)m_cornerLabelWin
; }
1705 // Allow adjustment of scroll increment. The default is (15, 15).
1706 void SetScrollLineX(int x
) { m_scrollLineX
= x
; }
1707 void SetScrollLineY(int y
) { m_scrollLineY
= y
; }
1708 int GetScrollLineX() const { return m_scrollLineX
; }
1709 int GetScrollLineY() const { return m_scrollLineY
; }
1711 // ------- drag and drop
1712 #if wxUSE_DRAG_AND_DROP
1713 virtual void SetDropTarget(wxDropTarget
*dropTarget
);
1714 #endif // wxUSE_DRAG_AND_DROP
1717 #ifdef WXWIN_COMPATIBILITY_2_8
1718 // ------ For compatibility with previous wxGrid only...
1720 // ************************************************
1721 // ** Don't use these in new code because they **
1722 // ** are liable to disappear in a future **
1724 // ************************************************
1727 wxGrid( wxWindow
*parent
,
1728 int x
, int y
, int w
= wxDefaultCoord
, int h
= wxDefaultCoord
,
1729 long style
= wxWANTS_CHARS
,
1730 const wxString
& name
= wxPanelNameStr
)
1731 : wxScrolledWindow( parent
, wxID_ANY
, wxPoint(x
,y
), wxSize(w
,h
),
1732 (style
|wxWANTS_CHARS
), name
)
1738 void SetCellValue( const wxString
& val
, int row
, int col
)
1739 { SetCellValue( row
, col
, val
); }
1741 void UpdateDimensions()
1742 { CalcDimensions(); }
1744 int GetRows() const { return GetNumberRows(); }
1745 int GetCols() const { return GetNumberCols(); }
1746 int GetCursorRow() const { return GetGridCursorRow(); }
1747 int GetCursorColumn() const { return GetGridCursorCol(); }
1749 int GetScrollPosX() const { return 0; }
1750 int GetScrollPosY() const { return 0; }
1752 void SetScrollX( int WXUNUSED(x
) ) { }
1753 void SetScrollY( int WXUNUSED(y
) ) { }
1755 void SetColumnWidth( int col
, int width
)
1756 { SetColSize( col
, width
); }
1758 int GetColumnWidth( int col
) const
1759 { return GetColSize( col
); }
1761 void SetRowHeight( int row
, int height
)
1762 { SetRowSize( row
, height
); }
1764 // GetRowHeight() is below
1766 int GetViewHeight() const // returned num whole rows visible
1769 int GetViewWidth() const // returned num whole cols visible
1772 void SetLabelSize( int orientation
, int sz
)
1774 if ( orientation
== wxHORIZONTAL
)
1775 SetColLabelSize( sz
);
1777 SetRowLabelSize( sz
);
1780 int GetLabelSize( int orientation
) const
1782 if ( orientation
== wxHORIZONTAL
)
1783 return GetColLabelSize();
1785 return GetRowLabelSize();
1788 void SetLabelAlignment( int orientation
, int align
)
1790 if ( orientation
== wxHORIZONTAL
)
1791 SetColLabelAlignment( align
, -1 );
1793 SetRowLabelAlignment( align
, -1 );
1796 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) ) const
1799 if ( orientation
== wxHORIZONTAL
)
1801 GetColLabelAlignment( &h
, &v
);
1806 GetRowLabelAlignment( &h
, &v
);
1811 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
1813 if ( orientation
== wxHORIZONTAL
)
1814 SetColLabelValue( pos
, val
);
1816 SetRowLabelValue( pos
, val
);
1819 wxString
GetLabelValue( int orientation
, int pos
) const
1821 if ( orientation
== wxHORIZONTAL
)
1822 return GetColLabelValue( pos
);
1824 return GetRowLabelValue( pos
);
1827 wxFont
GetCellTextFont() const
1828 { return m_defaultCellAttr
->GetFont(); }
1830 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
1831 { return m_defaultCellAttr
->GetFont(); }
1833 void SetCellTextFont(const wxFont
& fnt
)
1834 { SetDefaultCellFont( fnt
); }
1836 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
1837 { SetCellFont( row
, col
, fnt
); }
1839 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
1840 { SetCellTextColour( row
, col
, val
); }
1842 void SetCellTextColour(const wxColour
& col
)
1843 { SetDefaultCellTextColour( col
); }
1845 void SetCellBackgroundColour(const wxColour
& col
)
1846 { SetDefaultCellBackgroundColour( col
); }
1848 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
1849 { SetCellBackgroundColour( row
, col
, colour
); }
1851 bool GetEditable() const { return IsEditable(); }
1852 void SetEditable( bool edit
= true ) { EnableEditing( edit
); }
1853 bool GetEditInPlace() const { return IsCellEditControlEnabled(); }
1855 void SetEditInPlace(bool WXUNUSED(edit
) = true) { }
1857 void SetCellAlignment( int align
, int row
, int col
)
1858 { SetCellAlignment(row
, col
, align
, wxALIGN_CENTER
); }
1859 void SetCellAlignment( int WXUNUSED(align
) ) {}
1860 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
1862 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
1863 wxPen
& GetDividerPen() const;
1864 void OnActivate(bool WXUNUSED(active
)) {}
1866 // ******** End of compatibility functions **********
1870 // ------ control IDs
1871 enum { wxGRID_CELLCTRL
= 2000,
1874 // ------ control types
1875 enum { wxGRID_TEXTCTRL
= 2100,
1879 #endif // WXWIN_COMPATIBILITY_2_8
1882 // override some base class functions
1883 virtual bool Enable(bool enable
= true);
1884 virtual wxWindow
*GetMainWindowOfCompositeControl()
1885 { return (wxWindow
*)m_gridWin
; }
1888 // implementation only
1889 void CancelMouseCapture();
1892 virtual wxSize
DoGetBestSize() const;
1896 wxGridWindow
*m_gridWin
;
1897 wxGridRowLabelWindow
*m_rowLabelWin
;
1898 wxGridColLabelWindow
*m_colLabelWin
;
1899 wxGridCornerLabelWindow
*m_cornerLabelWin
;
1901 wxGridTableBase
*m_table
;
1907 wxGridCellCoords m_currentCellCoords
;
1909 // the corners of the block being currently selected or wxGridNoCellCoords
1910 wxGridCellCoords m_selectedBlockTopLeft
;
1911 wxGridCellCoords m_selectedBlockBottomRight
;
1913 // when selecting blocks of cells (either from the keyboard using Shift
1914 // with cursor keys, or by dragging the mouse), the selection is anchored
1915 // at m_currentCellCoords which defines one of the corners of the rectangle
1916 // being selected -- and this variable defines the other corner, i.e. it's
1917 // either m_selectedBlockTopLeft or m_selectedBlockBottomRight depending on
1918 // which of them is not m_currentCellCoords
1920 // if no block selection is in process, it is set to wxGridNoCellCoords
1921 wxGridCellCoords m_selectedBlockCorner
;
1923 wxGridSelection
*m_selection
;
1925 wxColour m_selectionBackground
;
1926 wxColour m_selectionForeground
;
1928 // NB: *never* access m_row/col arrays directly because they are created
1929 // on demand, *always* use accessor functions instead!
1931 // init the m_rowHeights/Bottoms arrays with default values
1932 void InitRowHeights();
1934 int m_defaultRowHeight
;
1935 int m_minAcceptableRowHeight
;
1936 wxArrayInt m_rowHeights
;
1937 wxArrayInt m_rowBottoms
;
1939 // init the m_colWidths/Rights arrays
1940 void InitColWidths();
1942 int m_defaultColWidth
;
1943 int m_minAcceptableColWidth
;
1944 wxArrayInt m_colWidths
;
1945 wxArrayInt m_colRights
;
1947 bool m_nativeColumnLabels
;
1949 // get the col/row coords
1950 int GetColWidth(int col
) const;
1951 int GetColLeft(int col
) const;
1952 int GetColRight(int col
) const;
1954 // this function must be public for compatibility...
1956 int GetRowHeight(int row
) const;
1959 int GetRowTop(int row
) const;
1960 int GetRowBottom(int row
) const;
1962 int m_rowLabelWidth
;
1963 int m_colLabelHeight
;
1965 // the size of the margin left to the right and bottom of the cell area
1969 wxColour m_labelBackgroundColour
;
1970 wxColour m_labelTextColour
;
1973 int m_rowLabelHorizAlign
;
1974 int m_rowLabelVertAlign
;
1975 int m_colLabelHorizAlign
;
1976 int m_colLabelVertAlign
;
1977 int m_colLabelTextOrientation
;
1979 bool m_defaultRowLabelValues
;
1980 bool m_defaultColLabelValues
;
1982 wxColour m_gridLineColour
;
1983 bool m_gridLinesEnabled
;
1984 bool m_gridLinesClipHorz
,
1985 m_gridLinesClipVert
;
1986 wxColour m_cellHighlightColour
;
1987 int m_cellHighlightPenWidth
;
1988 int m_cellHighlightROPenWidth
;
1991 // common part of AutoSizeColumn/Row() and GetBestSize()
1992 int SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
= true);
1993 int SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
= true);
1995 // common part of AutoSizeColumn/Row()
1996 void AutoSizeColOrRow(int n
, bool setAsMin
, wxGridDirection direction
);
1998 // Calculate the minimum acceptable size for labels area
1999 wxCoord
CalcColOrRowLabelAreaMinSize(wxGridDirection direction
);
2001 // if a column has a minimal width, it will be the value for it in this
2003 wxLongToLongHashMap m_colMinWidths
,
2006 // get the minimal width of the given column/row
2007 int GetColMinimalWidth(int col
) const;
2008 int GetRowMinimalHeight(int col
) const;
2010 // do we have some place to store attributes in?
2011 bool CanHaveAttributes() const;
2013 // cell attribute cache (currently we only cache 1, may be will do
2014 // more/better later)
2018 wxGridCellAttr
*attr
;
2021 // invalidates the attribute cache
2022 void ClearAttrCache();
2024 // adds an attribute to cache
2025 void CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const;
2027 // looks for an attr in cache, returns true if found
2028 bool LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const;
2030 // looks for the attr in cache, if not found asks the table and caches the
2032 wxGridCellAttr
*GetCellAttr(int row
, int col
) const;
2033 wxGridCellAttr
*GetCellAttr(const wxGridCellCoords
& coords
) const
2034 { return GetCellAttr( coords
.GetRow(), coords
.GetCol() ); }
2036 // the default cell attr object for cells that don't have their own
2037 wxGridCellAttr
* m_defaultCellAttr
;
2044 wxGridTypeRegistry
* m_typeRegistry
;
2048 WXGRID_CURSOR_SELECT_CELL
,
2049 WXGRID_CURSOR_RESIZE_ROW
,
2050 WXGRID_CURSOR_RESIZE_COL
,
2051 WXGRID_CURSOR_SELECT_ROW
,
2052 WXGRID_CURSOR_SELECT_COL
,
2053 WXGRID_CURSOR_MOVE_COL
2056 // this method not only sets m_cursorMode but also sets the correct cursor
2057 // for the given mode and, if captureMouse is not false releases the mouse
2058 // if it was captured and captures it if it must be captured
2060 // for this to work, you should always use it and not set m_cursorMode
2062 void ChangeCursorMode(CursorMode mode
,
2063 wxWindow
*win
= NULL
,
2064 bool captureMouse
= true);
2066 wxWindow
*m_winCapture
; // the window which captured the mouse
2068 // this variable is used not for finding the correct current cursor but
2069 // mainly for finding out what is going to happen if the mouse starts being
2070 // dragged right now
2072 // by default it is WXGRID_CURSOR_SELECT_CELL meaning that nothing else is
2073 // going on, and it is set to one of RESIZE/SELECT/MOVE values while the
2074 // corresponding operation will be started if the user starts dragging the
2075 // mouse from the current position
2076 CursorMode m_cursorMode
;
2083 bool m_canDragRowSize
;
2084 bool m_canDragColSize
;
2085 bool m_canDragColMove
;
2086 bool m_canDragGridSize
;
2089 // the last position (horizontal or vertical depending on whether the user
2090 // is resizing a column or a row) where a row or column separator line was
2091 // dragged by the user or -1 of there is no drag operation in progress
2095 // true if a drag operation is in progress; when this is true,
2096 // m_startDragPos is valid, i.e. not wxDefaultPosition
2099 // the position (in physical coordinates) where the user started dragging
2100 // the mouse or wxDefaultPosition if mouse isn't being dragged
2102 // notice that this can be != wxDefaultPosition while m_isDragging is still
2103 // false because we wait until the mouse is moved some distance away before
2104 // setting m_isDragging to true
2105 wxPoint m_startDragPos
;
2107 bool m_waitForSlowClick
;
2109 wxGridCellCoords m_selectionStart
;
2111 wxCursor m_rowResizeCursor
;
2112 wxCursor m_colResizeCursor
;
2114 bool m_editable
; // applies to whole grid
2115 bool m_cellEditCtrlEnabled
; // is in-place edit currently shown?
2117 int m_scrollLineX
; // X scroll increment
2118 int m_scrollLineY
; // Y scroll increment
2123 void CalcDimensions();
2124 void CalcWindowSizes();
2125 bool Redimension( wxGridTableMessage
& );
2128 // generate the appropriate grid event and return -1 if it was vetoed, 1 if
2129 // it was processed (but not vetoed) and 0 if it wasn't processed
2130 int SendEvent(const wxEventType evtType
,
2133 int SendEvent(const wxEventType evtType
,
2134 const wxGridCellCoords
& coords
,
2136 { return SendEvent(evtType
, coords
.GetRow(), coords
.GetCol(), e
); }
2137 int SendEvent(const wxEventType evtType
, int row
, int col
);
2138 int SendEvent(const wxEventType evtType
, const wxGridCellCoords
& coords
)
2139 { return SendEvent(evtType
, coords
.GetRow(), coords
.GetCol()); }
2140 int SendEvent(const wxEventType evtType
)
2141 { return SendEvent(evtType
, m_currentCellCoords
); }
2143 void OnPaint( wxPaintEvent
& );
2144 void OnSize( wxSizeEvent
& );
2145 void OnKeyDown( wxKeyEvent
& );
2146 void OnKeyUp( wxKeyEvent
& );
2147 void OnChar( wxKeyEvent
& );
2148 void OnEraseBackground( wxEraseEvent
& );
2151 bool SetCurrentCell( const wxGridCellCoords
& coords
);
2152 bool SetCurrentCell( int row
, int col
)
2153 { return SetCurrentCell( wxGridCellCoords(row
, col
) ); }
2156 // this function is called to extend the block being currently selected
2157 // from mouse and keyboard event handlers
2158 void UpdateBlockBeingSelected(int topRow
, int leftCol
,
2159 int bottomRow
, int rightCol
);
2161 void UpdateBlockBeingSelected(const wxGridCellCoords
& topLeft
,
2162 const wxGridCellCoords
& bottomRight
)
2163 { UpdateBlockBeingSelected(topLeft
.GetRow(), topLeft
.GetCol(),
2164 bottomRight
.GetRow(), bottomRight
.GetCol()); }
2166 // ------ functions to get/send data (see also public functions)
2168 bool GetModelValues();
2169 bool SetModelValues();
2171 friend class WXDLLIMPEXP_FWD_ADV wxGridSelection
;
2172 friend class wxGridRowOperations
;
2173 friend class wxGridColumnOperations
;
2175 // they call our private Process{{Corner,Col,Row}Label,GridCell}MouseEvent()
2176 friend class wxGridCornerLabelWindow
;
2177 friend class wxGridColLabelWindow
;
2178 friend class wxGridRowLabelWindow
;
2179 friend class wxGridWindow
;
2182 // implement wxScrolledWindow method to return m_gridWin size
2183 virtual wxSize
GetSizeAvailableForScrollTarget(const wxSize
& size
);
2185 // redraw the grid lines, should be called after changing their attributes
2186 void RedrawGridLines();
2188 // common part of Clip{Horz,Vert}GridLines
2189 void DoClipGridLines(bool& var
, bool clip
);
2192 // event handlers and their helpers
2193 // --------------------------------
2195 // process mouse drag event in WXGRID_CURSOR_SELECT_CELL mode
2196 void DoGridCellDrag(wxMouseEvent
& event
,
2197 const wxGridCellCoords
& coords
,
2200 // process row/column resizing drag event
2201 void DoGridLineDrag(wxMouseEvent
& event
, const wxGridOperations
& oper
);
2203 // process mouse drag event in the grid window
2204 void DoGridDragEvent(wxMouseEvent
& event
, const wxGridCellCoords
& coords
);
2206 // process different clicks on grid cells
2207 void DoGridCellLeftDown(wxMouseEvent
& event
,
2208 const wxGridCellCoords
& coords
,
2209 const wxPoint
& pos
);
2210 void DoGridCellLeftDClick(wxMouseEvent
& event
,
2211 const wxGridCellCoords
& coords
,
2212 const wxPoint
& pos
);
2213 void DoGridCellLeftUp(wxMouseEvent
& event
, const wxGridCellCoords
& coords
);
2215 // process movement (but not dragging) event in the grid cell area
2216 void DoGridMouseMoveEvent(wxMouseEvent
& event
,
2217 const wxGridCellCoords
& coords
,
2218 const wxPoint
& pos
);
2220 // process mouse events in the grid window
2221 void ProcessGridCellMouseEvent(wxMouseEvent
& event
);
2223 // process mouse events in the row/column labels/corner windows
2224 void ProcessRowLabelMouseEvent(wxMouseEvent
& event
);
2225 void ProcessColLabelMouseEvent(wxMouseEvent
& event
);
2226 void ProcessCornerLabelMouseEvent(wxMouseEvent
& event
);
2228 void DoEndDragResizeRow();
2229 void DoEndDragResizeCol();
2230 void DoEndDragMoveCol();
2233 // common implementations of methods defined for both rows and columns
2234 void DeselectLine(int line
, const wxGridOperations
& oper
);
2235 void DoEndDragResizeLine(const wxGridOperations
& oper
);
2236 int PosToLine(int pos
, bool clipToMinMax
,
2237 const wxGridOperations
& oper
) const;
2238 int PosToEdgeOfLine(int pos
, const wxGridOperations
& oper
) const;
2240 bool DoMoveCursor(bool expandSelection
,
2241 const wxGridDirectionOperations
& diroper
);
2242 bool DoMoveCursorByPage(const wxGridDirectionOperations
& diroper
);
2243 bool DoMoveCursorByBlock(bool expandSelection
,
2244 const wxGridDirectionOperations
& diroper
);
2245 void AdvanceToNextNonEmpty(wxGridCellCoords
& coords
,
2246 const wxGridDirectionOperations
& diroper
);
2248 // common part of {Insert,Delete}{Rows,Cols}
2249 bool DoModifyLines(bool (wxGridTableBase::*funcModify
)(size_t, size_t),
2250 int pos
, int num
, bool updateLabels
);
2251 // Append{Rows,Cols} is a bit different because of one less parameter
2252 bool DoAppendLines(bool (wxGridTableBase::*funcAppend
)(size_t),
2253 int num
, bool updateLabels
);
2255 DECLARE_DYNAMIC_CLASS( wxGrid
)
2256 DECLARE_EVENT_TABLE()
2257 DECLARE_NO_COPY_CLASS(wxGrid
)
2260 // ----------------------------------------------------------------------------
2261 // wxGridUpdateLocker prevents updates to a grid during its lifetime
2262 // ----------------------------------------------------------------------------
2264 class WXDLLIMPEXP_ADV wxGridUpdateLocker
2267 // if the pointer is NULL, Create() can be called later
2268 wxGridUpdateLocker(wxGrid
*grid
= NULL
)
2273 // can be called if ctor was used with a NULL pointer, must not be called
2275 void Create(wxGrid
*grid
)
2277 wxASSERT_MSG( !m_grid
, _T("shouldn't be called more than once") );
2282 ~wxGridUpdateLocker()
2289 void Init(wxGrid
*grid
)
2293 m_grid
->BeginBatch();
2298 DECLARE_NO_COPY_CLASS(wxGridUpdateLocker
)
2301 // ----------------------------------------------------------------------------
2302 // Grid event class and event types
2303 // ----------------------------------------------------------------------------
2305 class WXDLLIMPEXP_ADV wxGridEvent
: public wxNotifyEvent
,
2306 public wxKeyboardState
2312 Init(-1, -1, -1, -1, false);
2318 int row
= -1, int col
= -1,
2319 int x
= -1, int y
= -1,
2321 const wxKeyboardState
& kbd
= wxKeyboardState())
2322 : wxNotifyEvent(type
, id
),
2323 wxKeyboardState(kbd
)
2325 Init(row
, col
, x
, y
, sel
);
2326 SetEventObject(obj
);
2329 // explicitly specifying inline allows gcc < 3.4 to
2330 // handle the deprecation attribute even in the constructor.
2331 wxDEPRECATED( inline
2339 bool shift
= false, bool alt
= false, bool meta
= false));
2341 virtual int GetRow() { return m_row
; }
2342 virtual int GetCol() { return m_col
; }
2343 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
2344 bool Selecting() { return m_selecting
; }
2346 virtual wxEvent
*Clone() const { return new wxGridEvent(*this); }
2356 void Init(int row
, int col
, int x
, int y
, bool sel
)
2365 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEvent
)
2368 class WXDLLIMPEXP_ADV wxGridSizeEvent
: public wxNotifyEvent
,
2369 public wxKeyboardState
2378 wxGridSizeEvent(int id
,
2382 int x
= -1, int y
= -1,
2383 const wxKeyboardState
& kbd
= wxKeyboardState())
2384 : wxNotifyEvent(type
, id
),
2385 wxKeyboardState(kbd
)
2387 Init(rowOrCol
, x
, y
);
2389 SetEventObject(obj
);
2392 wxDEPRECATED( inline
2393 wxGridSizeEvent(int id
,
2401 bool meta
= false) );
2403 int GetRowOrCol() { return m_rowOrCol
; }
2404 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
2406 virtual wxEvent
*Clone() const { return new wxGridSizeEvent(*this); }
2414 void Init(int rowOrCol
, int x
, int y
)
2416 m_rowOrCol
= rowOrCol
;
2421 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridSizeEvent
)
2425 class WXDLLIMPEXP_ADV wxGridRangeSelectEvent
: public wxNotifyEvent
,
2426 public wxKeyboardState
2429 wxGridRangeSelectEvent()
2432 Init(wxGridNoCellCoords
, wxGridNoCellCoords
, false);
2435 wxGridRangeSelectEvent(int id
,
2438 const wxGridCellCoords
& topLeft
,
2439 const wxGridCellCoords
& bottomRight
,
2441 const wxKeyboardState
& kbd
= wxKeyboardState())
2442 : wxNotifyEvent(type
, id
),
2443 wxKeyboardState(kbd
)
2445 Init(topLeft
, bottomRight
, sel
);
2447 SetEventObject(obj
);
2450 wxDEPRECATED( inline
2451 wxGridRangeSelectEvent(int id
,
2454 const wxGridCellCoords
& topLeft
,
2455 const wxGridCellCoords
& bottomRight
,
2460 bool meta
= false) );
2462 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
2463 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
2464 int GetTopRow() { return m_topLeft
.GetRow(); }
2465 int GetBottomRow() { return m_bottomRight
.GetRow(); }
2466 int GetLeftCol() { return m_topLeft
.GetCol(); }
2467 int GetRightCol() { return m_bottomRight
.GetCol(); }
2468 bool Selecting() { return m_selecting
; }
2470 virtual wxEvent
*Clone() const { return new wxGridRangeSelectEvent(*this); }
2473 void Init(const wxGridCellCoords
& topLeft
,
2474 const wxGridCellCoords
& bottomRight
,
2477 m_topLeft
= topLeft
;
2478 m_bottomRight
= bottomRight
;
2479 m_selecting
= selecting
;
2482 wxGridCellCoords m_topLeft
;
2483 wxGridCellCoords m_bottomRight
;
2486 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridRangeSelectEvent
)
2490 class WXDLLIMPEXP_ADV wxGridEditorCreatedEvent
: public wxCommandEvent
2493 wxGridEditorCreatedEvent()
2501 wxGridEditorCreatedEvent(int id
, wxEventType type
, wxObject
* obj
,
2502 int row
, int col
, wxControl
* ctrl
);
2504 int GetRow() { return m_row
; }
2505 int GetCol() { return m_col
; }
2506 wxControl
* GetControl() { return m_ctrl
; }
2507 void SetRow(int row
) { m_row
= row
; }
2508 void SetCol(int col
) { m_col
= col
; }
2509 void SetControl(wxControl
* ctrl
) { m_ctrl
= ctrl
; }
2511 virtual wxEvent
*Clone() const { return new wxGridEditorCreatedEvent(*this); }
2518 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEditorCreatedEvent
)
2522 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_LEFT_CLICK
;
2523 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK
;
2524 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK
;
2525 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK
;
2526 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK
;
2527 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK
;
2528 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK
;
2529 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK
;
2530 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_ROW_SIZE
;
2531 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_COL_SIZE
;
2532 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_RANGE_SELECT
;
2533 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_CHANGE
;
2534 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_SELECT_CELL
;
2535 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_EDITOR_SHOWN
;
2536 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_EDITOR_HIDDEN
;
2537 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_EDITOR_CREATED
;
2538 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_CELL_BEGIN_DRAG
;
2539 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_GRID_COL_MOVE
;
2542 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
2543 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
2544 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
2545 typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction
)(wxGridEditorCreatedEvent
&);
2547 #define wxGridEventHandler(func) \
2548 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridEventFunction, &func)
2550 #define wxGridSizeEventHandler(func) \
2551 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridSizeEventFunction, &func)
2553 #define wxGridRangeSelectEventHandler(func) \
2554 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridRangeSelectEventFunction, &func)
2556 #define wxGridEditorCreatedEventHandler(func) \
2557 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridEditorCreatedEventFunction, &func)
2559 #define wx__DECLARE_GRIDEVT(evt, id, fn) \
2560 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn))
2562 #define wx__DECLARE_GRIDSIZEEVT(evt, id, fn) \
2563 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridSizeEventHandler(fn))
2565 #define wx__DECLARE_GRIDRANGESELEVT(evt, id, fn) \
2566 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridRangeSelectEventHandler(fn))
2568 #define wx__DECLARE_GRIDEDITOREVT(evt, id, fn) \
2569 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEditorCreatedEventHandler(fn))
2571 #define EVT_GRID_CMD_CELL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_CLICK, id, fn)
2572 #define EVT_GRID_CMD_CELL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_CLICK, id, fn)
2573 #define EVT_GRID_CMD_CELL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_DCLICK, id, fn)
2574 #define EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_DCLICK, id, fn)
2575 #define EVT_GRID_CMD_LABEL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_CLICK, id, fn)
2576 #define EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_CLICK, id, fn)
2577 #define EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_DCLICK, id, fn)
2578 #define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn)
2579 #define EVT_GRID_CMD_ROW_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn)
2580 #define EVT_GRID_CMD_COL_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn)
2581 #define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn)
2582 #define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn)
2583 #define EVT_GRID_CMD_CELL_CHANGE(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGE, id, fn)
2584 #define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn)
2585 #define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn)
2586 #define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn)
2587 #define EVT_GRID_CMD_EDITOR_CREATED(id, fn) wx__DECLARE_GRIDEDITOREVT(EDITOR_CREATED, id, fn)
2588 #define EVT_GRID_CMD_CELL_BEGIN_DRAG(id, fn) wx__DECLARE_GRIDEVT(CELL_BEGIN_DRAG, id, fn)
2590 // same as above but for any id (exists mainly for backwards compatibility but
2591 // then it's also true that you rarely have multiple grid in the same window)
2592 #define EVT_GRID_CELL_LEFT_CLICK(fn) EVT_GRID_CMD_CELL_LEFT_CLICK(wxID_ANY, fn)
2593 #define EVT_GRID_CELL_RIGHT_CLICK(fn) EVT_GRID_CMD_CELL_RIGHT_CLICK(wxID_ANY, fn)
2594 #define EVT_GRID_CELL_LEFT_DCLICK(fn) EVT_GRID_CMD_CELL_LEFT_DCLICK(wxID_ANY, fn)
2595 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) EVT_GRID_CMD_CELL_RIGHT_DCLICK(wxID_ANY, fn)
2596 #define EVT_GRID_LABEL_LEFT_CLICK(fn) EVT_GRID_CMD_LABEL_LEFT_CLICK(wxID_ANY, fn)
2597 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_CLICK(wxID_ANY, fn)
2598 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) EVT_GRID_CMD_LABEL_LEFT_DCLICK(wxID_ANY, fn)
2599 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn)
2600 #define EVT_GRID_ROW_SIZE(fn) EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn)
2601 #define EVT_GRID_COL_SIZE(fn) EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn)
2602 #define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn)
2603 #define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn)
2604 #define EVT_GRID_CELL_CHANGE(fn) EVT_GRID_CMD_CELL_CHANGE(wxID_ANY, fn)
2605 #define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn)
2606 #define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn)
2607 #define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn)
2608 #define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn)
2609 #define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn)
2611 #if 0 // TODO: implement these ? others ?
2613 extern const int wxEVT_GRID_CREATE_CELL
;
2614 extern const int wxEVT_GRID_CHANGE_LABELS
;
2615 extern const int wxEVT_GRID_CHANGE_SEL_LABEL
;
2617 #define EVT_GRID_CREATE_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2618 #define EVT_GRID_CHANGE_LABELS(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2619 #define EVT_GRID_CHANGE_SEL_LABEL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2623 #endif // wxUSE_GRID
2624 #endif // _WX_GENERIC_GRID_H_