1 ///////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/grid.cpp
3 // Purpose: wxGrid and related classes
4 // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
5 // Modified by: Robin Dunn, Vadim Zeitlin, Santiago Palacios
8 // Copyright: (c) Michael Bedward (mbedward@ozemail.com.au)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/dcclient.h"
24 #include "wx/settings.h"
26 #include "wx/textctrl.h"
27 #include "wx/checkbox.h"
28 #include "wx/combobox.h"
29 #include "wx/valtext.h"
32 #include "wx/listbox.h"
35 #include "wx/textfile.h"
36 #include "wx/spinctrl.h"
37 #include "wx/tokenzr.h"
38 #include "wx/renderer.h"
41 #include "wx/generic/gridsel.h"
43 #if defined(__WXMOTIF__)
44 #define WXUNUSED_MOTIF(identifier) WXUNUSED(identifier)
46 #define WXUNUSED_MOTIF(identifier) identifier
49 #if defined(__WXGTK__)
50 #define WXUNUSED_GTK(identifier) WXUNUSED(identifier)
52 #define WXUNUSED_GTK(identifier) identifier
55 // Required for wxIs... functions
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridCellAttr
*, wxArrayAttrs
,
63 class WXDLLIMPEXP_ADV
);
65 struct wxGridCellWithAttr
67 wxGridCellWithAttr(int row
, int col
, wxGridCellAttr
*attr_
)
68 : coords(row
, col
), attr(attr_
)
77 wxGridCellCoords coords
;
81 // DECLARE_NO_COPY_CLASS(wxGridCellWithAttr)
82 // without rewriting the macros, which require a public copy constructor.
85 WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellWithAttr
, wxGridCellWithAttrArray
,
86 class WXDLLIMPEXP_ADV
);
88 #include "wx/arrimpl.cpp"
90 WX_DEFINE_OBJARRAY(wxGridCellCoordsArray
)
91 WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray
)
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_CLICK
)
98 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_CLICK
)
99 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_DCLICK
)
100 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_DCLICK
)
101 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_BEGIN_DRAG
)
102 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_CLICK
)
103 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_CLICK
)
104 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_DCLICK
)
105 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_DCLICK
)
106 DEFINE_EVENT_TYPE(wxEVT_GRID_ROW_SIZE
)
107 DEFINE_EVENT_TYPE(wxEVT_GRID_COL_SIZE
)
108 DEFINE_EVENT_TYPE(wxEVT_GRID_COL_MOVE
)
109 DEFINE_EVENT_TYPE(wxEVT_GRID_RANGE_SELECT
)
110 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGE
)
111 DEFINE_EVENT_TYPE(wxEVT_GRID_SELECT_CELL
)
112 DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN
)
113 DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN
)
114 DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_CREATED
)
116 // ----------------------------------------------------------------------------
118 // ----------------------------------------------------------------------------
120 class WXDLLIMPEXP_ADV wxGridRowLabelWindow
: public wxWindow
123 wxGridRowLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
124 wxGridRowLabelWindow( wxGrid
*parent
, wxWindowID id
,
125 const wxPoint
&pos
, const wxSize
&size
);
130 void OnPaint( wxPaintEvent
& event
);
131 void OnMouseEvent( wxMouseEvent
& event
);
132 void OnMouseWheel( wxMouseEvent
& event
);
133 void OnKeyDown( wxKeyEvent
& event
);
134 void OnKeyUp( wxKeyEvent
& );
135 void OnChar( wxKeyEvent
& );
137 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow
)
138 DECLARE_EVENT_TABLE()
139 DECLARE_NO_COPY_CLASS(wxGridRowLabelWindow
)
143 class WXDLLIMPEXP_ADV wxGridColLabelWindow
: public wxWindow
146 wxGridColLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
147 wxGridColLabelWindow( wxGrid
*parent
, wxWindowID id
,
148 const wxPoint
&pos
, const wxSize
&size
);
153 void OnPaint( wxPaintEvent
& event
);
154 void OnMouseEvent( wxMouseEvent
& event
);
155 void OnMouseWheel( wxMouseEvent
& event
);
156 void OnKeyDown( wxKeyEvent
& event
);
157 void OnKeyUp( wxKeyEvent
& );
158 void OnChar( wxKeyEvent
& );
160 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow
)
161 DECLARE_EVENT_TABLE()
162 DECLARE_NO_COPY_CLASS(wxGridColLabelWindow
)
166 class WXDLLIMPEXP_ADV wxGridCornerLabelWindow
: public wxWindow
169 wxGridCornerLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
170 wxGridCornerLabelWindow( wxGrid
*parent
, wxWindowID id
,
171 const wxPoint
&pos
, const wxSize
&size
);
176 void OnMouseEvent( wxMouseEvent
& event
);
177 void OnMouseWheel( wxMouseEvent
& event
);
178 void OnKeyDown( wxKeyEvent
& event
);
179 void OnKeyUp( wxKeyEvent
& );
180 void OnChar( wxKeyEvent
& );
181 void OnPaint( wxPaintEvent
& event
);
183 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow
)
184 DECLARE_EVENT_TABLE()
185 DECLARE_NO_COPY_CLASS(wxGridCornerLabelWindow
)
188 class WXDLLIMPEXP_ADV wxGridWindow
: public wxWindow
194 m_rowLabelWin
= NULL
;
195 m_colLabelWin
= NULL
;
198 wxGridWindow( wxGrid
*parent
,
199 wxGridRowLabelWindow
*rowLblWin
,
200 wxGridColLabelWindow
*colLblWin
,
201 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
204 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
206 wxGrid
* GetOwner() { return m_owner
; }
210 wxGridRowLabelWindow
*m_rowLabelWin
;
211 wxGridColLabelWindow
*m_colLabelWin
;
213 void OnPaint( wxPaintEvent
&event
);
214 void OnMouseWheel( wxMouseEvent
& event
);
215 void OnMouseEvent( wxMouseEvent
& event
);
216 void OnKeyDown( wxKeyEvent
& );
217 void OnKeyUp( wxKeyEvent
& );
218 void OnChar( wxKeyEvent
& );
219 void OnEraseBackground( wxEraseEvent
& );
220 void OnFocus( wxFocusEvent
& );
222 DECLARE_DYNAMIC_CLASS(wxGridWindow
)
223 DECLARE_EVENT_TABLE()
224 DECLARE_NO_COPY_CLASS(wxGridWindow
)
228 class wxGridCellEditorEvtHandler
: public wxEvtHandler
231 wxGridCellEditorEvtHandler(wxGrid
* grid
, wxGridCellEditor
* editor
)
238 void OnKillFocus(wxFocusEvent
& event
);
239 void OnKeyDown(wxKeyEvent
& event
);
240 void OnChar(wxKeyEvent
& event
);
242 void SetInSetFocus(bool inSetFocus
) { m_inSetFocus
= inSetFocus
; }
246 wxGridCellEditor
*m_editor
;
248 // Work around the fact that a focus kill event can be sent to
249 // a combobox within a set focus event.
252 DECLARE_EVENT_TABLE()
253 DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler
)
254 DECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler
)
258 IMPLEMENT_ABSTRACT_CLASS(wxGridCellEditorEvtHandler
, wxEvtHandler
)
260 BEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler
, wxEvtHandler
)
261 EVT_KILL_FOCUS( wxGridCellEditorEvtHandler::OnKillFocus
)
262 EVT_KEY_DOWN( wxGridCellEditorEvtHandler::OnKeyDown
)
263 EVT_CHAR( wxGridCellEditorEvtHandler::OnChar
)
267 // ----------------------------------------------------------------------------
268 // the internal data representation used by wxGridCellAttrProvider
269 // ----------------------------------------------------------------------------
271 // this class stores attributes set for cells
272 class WXDLLIMPEXP_ADV wxGridCellAttrData
275 void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
276 wxGridCellAttr
*GetAttr(int row
, int col
) const;
277 void UpdateAttrRows( size_t pos
, int numRows
);
278 void UpdateAttrCols( size_t pos
, int numCols
);
281 // searches for the attr for given cell, returns wxNOT_FOUND if not found
282 int FindIndex(int row
, int col
) const;
284 wxGridCellWithAttrArray m_attrs
;
287 // this class stores attributes set for rows or columns
288 class WXDLLIMPEXP_ADV wxGridRowOrColAttrData
291 // empty ctor to suppress warnings
292 wxGridRowOrColAttrData() {}
293 ~wxGridRowOrColAttrData();
295 void SetAttr(wxGridCellAttr
*attr
, int rowOrCol
);
296 wxGridCellAttr
*GetAttr(int rowOrCol
) const;
297 void UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
);
300 wxArrayInt m_rowsOrCols
;
301 wxArrayAttrs m_attrs
;
304 // NB: this is just a wrapper around 3 objects: one which stores cell
305 // attributes, and 2 others for row/col ones
306 class WXDLLIMPEXP_ADV wxGridCellAttrProviderData
309 wxGridCellAttrData m_cellAttrs
;
310 wxGridRowOrColAttrData m_rowAttrs
,
315 // ----------------------------------------------------------------------------
316 // data structures used for the data type registry
317 // ----------------------------------------------------------------------------
319 struct wxGridDataTypeInfo
321 wxGridDataTypeInfo(const wxString
& typeName
,
322 wxGridCellRenderer
* renderer
,
323 wxGridCellEditor
* editor
)
324 : m_typeName(typeName
), m_renderer(renderer
), m_editor(editor
)
327 ~wxGridDataTypeInfo()
329 wxSafeDecRef(m_renderer
);
330 wxSafeDecRef(m_editor
);
334 wxGridCellRenderer
* m_renderer
;
335 wxGridCellEditor
* m_editor
;
337 DECLARE_NO_COPY_CLASS(wxGridDataTypeInfo
)
341 WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridDataTypeInfo
*, wxGridDataTypeInfoArray
,
342 class WXDLLIMPEXP_ADV
);
345 class WXDLLIMPEXP_ADV wxGridTypeRegistry
348 wxGridTypeRegistry() {}
349 ~wxGridTypeRegistry();
351 void RegisterDataType(const wxString
& typeName
,
352 wxGridCellRenderer
* renderer
,
353 wxGridCellEditor
* editor
);
355 // find one of already registered data types
356 int FindRegisteredDataType(const wxString
& typeName
);
358 // try to FindRegisteredDataType(), if this fails and typeName is one of
359 // standard typenames, register it and return its index
360 int FindDataType(const wxString
& typeName
);
362 // try to FindDataType(), if it fails see if it is not one of already
363 // registered data types with some params in which case clone the
364 // registered data type and set params for it
365 int FindOrCloneDataType(const wxString
& typeName
);
367 wxGridCellRenderer
* GetRenderer(int index
);
368 wxGridCellEditor
* GetEditor(int index
);
371 wxGridDataTypeInfoArray m_typeinfo
;
375 // ----------------------------------------------------------------------------
376 // conditional compilation
377 // ----------------------------------------------------------------------------
379 #ifndef WXGRID_DRAW_LINES
380 #define WXGRID_DRAW_LINES 1
383 // ----------------------------------------------------------------------------
385 // ----------------------------------------------------------------------------
387 //#define DEBUG_ATTR_CACHE
388 #ifdef DEBUG_ATTR_CACHE
389 static size_t gs_nAttrCacheHits
= 0;
390 static size_t gs_nAttrCacheMisses
= 0;
393 // ----------------------------------------------------------------------------
395 // ----------------------------------------------------------------------------
397 wxGridCellCoords
wxGridNoCellCoords( -1, -1 );
398 wxRect
wxGridNoCellRect( -1, -1, -1, -1 );
401 // TODO: this doesn't work at all, grid cells have different sizes and approx
402 // calculations don't work as because of the size mismatch scrollbars
403 // sometimes fail to be shown when they should be or vice versa
405 // The scroll bars may be a little flakey once in a while, but that is
406 // surely much less horrible than having scroll lines of only 1!!!
409 // Well, it's still seriously broken so it might be better but needs
412 static const size_t GRID_SCROLL_LINE_X
= 15; // 1;
413 static const size_t GRID_SCROLL_LINE_Y
= GRID_SCROLL_LINE_X
;
415 // the size of hash tables used a bit everywhere (the max number of elements
416 // in these hash tables is the number of rows/columns)
417 static const int GRID_HASH_SIZE
= 100;
420 // ----------------------------------------------------------------------------
422 // ----------------------------------------------------------------------------
424 static inline int GetScrollX(int x
)
426 return (x
+ GRID_SCROLL_LINE_X
- 1) / GRID_SCROLL_LINE_X
;
429 static inline int GetScrollY(int y
)
431 return (y
+ GRID_SCROLL_LINE_Y
- 1) / GRID_SCROLL_LINE_Y
;
435 // ============================================================================
437 // ============================================================================
439 // ----------------------------------------------------------------------------
441 // ----------------------------------------------------------------------------
443 wxGridCellEditor::wxGridCellEditor()
449 wxGridCellEditor::~wxGridCellEditor()
454 void wxGridCellEditor::Create(wxWindow
* WXUNUSED(parent
),
455 wxWindowID
WXUNUSED(id
),
456 wxEvtHandler
* evtHandler
)
459 m_control
->PushEventHandler(evtHandler
);
462 void wxGridCellEditor::PaintBackground(const wxRect
& rectCell
,
463 wxGridCellAttr
*attr
)
465 // erase the background because we might not fill the cell
466 wxClientDC
dc(m_control
->GetParent());
467 wxGridWindow
* gridWindow
= wxDynamicCast(m_control
->GetParent(), wxGridWindow
);
469 gridWindow
->GetOwner()->PrepareDC(dc
);
471 dc
.SetPen(*wxTRANSPARENT_PEN
);
472 dc
.SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
473 dc
.DrawRectangle(rectCell
);
475 // redraw the control we just painted over
476 m_control
->Refresh();
479 void wxGridCellEditor::Destroy()
483 m_control
->PopEventHandler( true /* delete it*/ );
485 m_control
->Destroy();
490 void wxGridCellEditor::Show(bool show
, wxGridCellAttr
*attr
)
492 wxASSERT_MSG(m_control
, wxT("The wxGridCellEditor must be created first!"));
494 m_control
->Show(show
);
498 // set the colours/fonts if we have any
501 m_colFgOld
= m_control
->GetForegroundColour();
502 m_control
->SetForegroundColour(attr
->GetTextColour());
504 m_colBgOld
= m_control
->GetBackgroundColour();
505 m_control
->SetBackgroundColour(attr
->GetBackgroundColour());
507 // Workaround for GTK+1 font setting problem on some platforms
508 #if !defined(__WXGTK__) || defined(__WXGTK20__)
509 m_fontOld
= m_control
->GetFont();
510 m_control
->SetFont(attr
->GetFont());
513 // can't do anything more in the base class version, the other
514 // attributes may only be used by the derived classes
519 // restore the standard colours fonts
520 if ( m_colFgOld
.Ok() )
522 m_control
->SetForegroundColour(m_colFgOld
);
523 m_colFgOld
= wxNullColour
;
526 if ( m_colBgOld
.Ok() )
528 m_control
->SetBackgroundColour(m_colBgOld
);
529 m_colBgOld
= wxNullColour
;
532 // Workaround for GTK+1 font setting problem on some platforms
533 #if !defined(__WXGTK__) || defined(__WXGTK20__)
534 if ( m_fontOld
.Ok() )
536 m_control
->SetFont(m_fontOld
);
537 m_fontOld
= wxNullFont
;
543 void wxGridCellEditor::SetSize(const wxRect
& rect
)
545 wxASSERT_MSG(m_control
, wxT("The wxGridCellEditor must be created first!"));
547 m_control
->SetSize(rect
, wxSIZE_ALLOW_MINUS_ONE
);
550 void wxGridCellEditor::HandleReturn(wxKeyEvent
& event
)
555 bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent
& event
)
557 bool ctrl
= event
.ControlDown();
558 bool alt
= event
.AltDown();
561 // On the Mac the Alt key is more like shift and is used for entry of
562 // valid characters, so check for Ctrl and Meta instead.
563 alt
= event
.MetaDown();
566 // Assume it's not a valid char if ctrl or alt is down, but if both are
567 // down then it may be because of an AltGr key combination, so let them
568 // through in that case.
569 if ((ctrl
|| alt
) && !(ctrl
&& alt
))
576 // If it's a F-Key or other special key then it shouldn't start the
578 if (event
.GetKeyCode() >= WXK_START
)
582 // if the unicode key code is not really a unicode character (it may
583 // be a function key or etc., the platforms appear to always give us a
584 // small value in this case) then fallback to the ASCII key code but
585 // don't do anything for function keys or etc.
586 key
= event
.GetUnicodeKey();
589 key
= event
.GetKeyCode();
590 keyOk
= (key
<= 127);
593 key
= event
.GetKeyCode();
594 keyOk
= (key
<= 255);
600 void wxGridCellEditor::StartingKey(wxKeyEvent
& event
)
605 void wxGridCellEditor::StartingClick()
611 // ----------------------------------------------------------------------------
612 // wxGridCellTextEditor
613 // ----------------------------------------------------------------------------
615 wxGridCellTextEditor::wxGridCellTextEditor()
620 void wxGridCellTextEditor::Create(wxWindow
* parent
,
622 wxEvtHandler
* evtHandler
)
624 m_control
= new wxTextCtrl(parent
, id
, wxEmptyString
,
625 wxDefaultPosition
, wxDefaultSize
626 #if defined(__WXMSW__)
627 , wxTE_PROCESS_TAB
| wxTE_AUTO_SCROLL
| wxNO_BORDER
631 // set max length allowed in the textctrl, if the parameter was set
634 ((wxTextCtrl
*)m_control
)->SetMaxLength(m_maxChars
);
637 wxGridCellEditor::Create(parent
, id
, evtHandler
);
640 void wxGridCellTextEditor::PaintBackground(const wxRect
& WXUNUSED(rectCell
),
641 wxGridCellAttr
* WXUNUSED(attr
))
643 // as we fill the entire client area,
644 // don't do anything here to minimize flicker
647 void wxGridCellTextEditor::SetSize(const wxRect
& rectOrig
)
649 wxRect
rect(rectOrig
);
651 // Make the edit control large enough to allow for internal margins
653 // TODO: remove this if the text ctrl sizing is improved esp. for unix
655 #if defined(__WXGTK__)
663 #elif defined(__WXMSW__)
677 int extra_x
= ( rect
.x
> 2 ) ? 2 : 1;
678 int extra_y
= ( rect
.y
> 2 ) ? 2 : 1;
680 #if defined(__WXMOTIF__)
685 rect
.SetLeft( wxMax(0, rect
.x
- extra_x
) );
686 rect
.SetTop( wxMax(0, rect
.y
- extra_y
) );
687 rect
.SetRight( rect
.GetRight() + 2 * extra_x
);
688 rect
.SetBottom( rect
.GetBottom() + 2 * extra_y
);
691 wxGridCellEditor::SetSize(rect
);
694 void wxGridCellTextEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
696 wxASSERT_MSG(m_control
, wxT("The wxGridCellEditor must be created first!"));
698 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
700 DoBeginEdit(m_startValue
);
703 void wxGridCellTextEditor::DoBeginEdit(const wxString
& startValue
)
705 Text()->SetValue(startValue
);
706 Text()->SetInsertionPointEnd();
707 Text()->SetSelection(-1, -1);
711 bool wxGridCellTextEditor::EndEdit(int row
, int col
, wxGrid
* grid
)
713 wxASSERT_MSG(m_control
, wxT("The wxGridCellEditor must be created first!"));
715 bool changed
= false;
716 wxString value
= Text()->GetValue();
717 if (value
!= m_startValue
)
721 grid
->GetTable()->SetValue(row
, col
, value
);
723 m_startValue
= wxEmptyString
;
725 // No point in setting the text of the hidden control
726 //Text()->SetValue(m_startValue);
731 void wxGridCellTextEditor::Reset()
733 wxASSERT_MSG(m_control
, wxT("The wxGridCellEditor must be created first!"));
735 DoReset(m_startValue
);
738 void wxGridCellTextEditor::DoReset(const wxString
& startValue
)
740 Text()->SetValue(startValue
);
741 Text()->SetInsertionPointEnd();
744 bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent
& event
)
746 return wxGridCellEditor::IsAcceptedKey(event
);
749 void wxGridCellTextEditor::StartingKey(wxKeyEvent
& event
)
751 // Since this is now happening in the EVT_CHAR event EmulateKeyPress is no
752 // longer an appropriate way to get the character into the text control.
753 // Do it ourselves instead. We know that if we get this far that we have
754 // a valid character, so not a whole lot of testing needs to be done.
756 wxTextCtrl
* tc
= Text();
761 ch
= event
.GetUnicodeKey();
763 ch
= (wxChar
)event
.GetKeyCode();
765 ch
= (wxChar
)event
.GetKeyCode();
771 // delete the character at the cursor
772 pos
= tc
->GetInsertionPoint();
773 if (pos
< tc
->GetLastPosition())
774 tc
->Remove(pos
, pos
+ 1);
778 // delete the character before the cursor
779 pos
= tc
->GetInsertionPoint();
781 tc
->Remove(pos
- 1, pos
);
790 void wxGridCellTextEditor::HandleReturn( wxKeyEvent
&
791 WXUNUSED_GTK(WXUNUSED_MOTIF(event
)) )
793 #if defined(__WXMOTIF__) || defined(__WXGTK__)
794 // wxMotif needs a little extra help...
795 size_t pos
= (size_t)( Text()->GetInsertionPoint() );
796 wxString
s( Text()->GetValue() );
797 s
= s
.Left(pos
) + wxT("\n") + s
.Mid(pos
);
799 Text()->SetInsertionPoint( pos
);
801 // the other ports can handle a Return key press
807 void wxGridCellTextEditor::SetParameters(const wxString
& params
)
817 if ( params
.ToLong(&tmp
) )
819 m_maxChars
= (size_t)tmp
;
823 wxLogDebug( _T("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params
.c_str() );
828 // return the value in the text control
829 wxString
wxGridCellTextEditor::GetValue() const
831 return Text()->GetValue();
834 // ----------------------------------------------------------------------------
835 // wxGridCellNumberEditor
836 // ----------------------------------------------------------------------------
838 wxGridCellNumberEditor::wxGridCellNumberEditor(int min
, int max
)
844 void wxGridCellNumberEditor::Create(wxWindow
* parent
,
846 wxEvtHandler
* evtHandler
)
851 // create a spin ctrl
852 m_control
= new wxSpinCtrl(parent
, wxID_ANY
, wxEmptyString
,
853 wxDefaultPosition
, wxDefaultSize
,
857 wxGridCellEditor::Create(parent
, id
, evtHandler
);
862 // just a text control
863 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
866 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
871 void wxGridCellNumberEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
873 // first get the value
874 wxGridTableBase
*table
= grid
->GetTable();
875 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
877 m_valueOld
= table
->GetValueAsLong(row
, col
);
882 wxString sValue
= table
->GetValue(row
, col
);
883 if (! sValue
.ToLong(&m_valueOld
) && ! sValue
.empty())
885 wxFAIL_MSG( _T("this cell doesn't have numeric value") );
893 Spin()->SetValue((int)m_valueOld
);
899 DoBeginEdit(GetString());
903 bool wxGridCellNumberEditor::EndEdit(int row
, int col
,
913 value
= Spin()->GetValue();
914 changed
= value
!= m_valueOld
;
916 text
= wxString::Format(wxT("%ld"), value
);
921 text
= Text()->GetValue();
922 changed
= (text
.empty() || text
.ToLong(&value
)) && (value
!= m_valueOld
);
927 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_NUMBER
))
928 grid
->GetTable()->SetValueAsLong(row
, col
, value
);
930 grid
->GetTable()->SetValue(row
, col
, text
);
936 void wxGridCellNumberEditor::Reset()
941 Spin()->SetValue((int)m_valueOld
);
946 DoReset(GetString());
950 bool wxGridCellNumberEditor::IsAcceptedKey(wxKeyEvent
& event
)
952 if ( wxGridCellEditor::IsAcceptedKey(event
) )
954 int keycode
= event
.GetKeyCode();
955 if ( (keycode
< 128) &&
956 (wxIsdigit(keycode
) || keycode
== '+' || keycode
== '-'))
965 void wxGridCellNumberEditor::StartingKey(wxKeyEvent
& event
)
967 int keycode
= event
.GetKeyCode();
970 if ( wxIsdigit(keycode
) || keycode
== '+' || keycode
== '-')
972 wxGridCellTextEditor::StartingKey(event
);
981 if ( wxIsdigit(keycode
) )
983 wxSpinCtrl
* spin
= (wxSpinCtrl
*)m_control
;
984 spin
->SetValue(keycode
- '0');
985 spin
->SetSelection(1,1);
994 void wxGridCellNumberEditor::SetParameters(const wxString
& params
)
1005 if ( params
.BeforeFirst(_T(',')).ToLong(&tmp
) )
1009 if ( params
.AfterFirst(_T(',')).ToLong(&tmp
) )
1013 // skip the error message below
1018 wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string '%s' ignored"), params
.c_str());
1022 // return the value in the spin control if it is there (the text control otherwise)
1023 wxString
wxGridCellNumberEditor::GetValue() const
1030 long value
= Spin()->GetValue();
1031 s
.Printf(wxT("%ld"), value
);
1036 s
= Text()->GetValue();
1042 // ----------------------------------------------------------------------------
1043 // wxGridCellFloatEditor
1044 // ----------------------------------------------------------------------------
1046 wxGridCellFloatEditor::wxGridCellFloatEditor(int width
, int precision
)
1049 m_precision
= precision
;
1052 void wxGridCellFloatEditor::Create(wxWindow
* parent
,
1054 wxEvtHandler
* evtHandler
)
1056 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
1058 #if wxUSE_VALIDATORS
1059 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
1063 void wxGridCellFloatEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1065 // first get the value
1066 wxGridTableBase
*table
= grid
->GetTable();
1067 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
1069 m_valueOld
= table
->GetValueAsDouble(row
, col
);
1074 wxString sValue
= table
->GetValue(row
, col
);
1075 if (! sValue
.ToDouble(&m_valueOld
) && ! sValue
.empty())
1077 wxFAIL_MSG( _T("this cell doesn't have float value") );
1082 DoBeginEdit(GetString());
1085 bool wxGridCellFloatEditor::EndEdit(int row
, int col
,
1089 wxString
text(Text()->GetValue());
1091 if ( (text
.empty() || text
.ToDouble(&value
)) &&
1092 !wxIsSameDouble(value
, m_valueOld
) )
1094 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_FLOAT
))
1095 grid
->GetTable()->SetValueAsDouble(row
, col
, value
);
1097 grid
->GetTable()->SetValue(row
, col
, text
);
1105 void wxGridCellFloatEditor::Reset()
1107 DoReset(GetString());
1110 void wxGridCellFloatEditor::StartingKey(wxKeyEvent
& event
)
1112 int keycode
= event
.GetKeyCode();
1114 tmpbuf
[0] = (char) keycode
;
1116 wxString
strbuf(tmpbuf
, *wxConvCurrent
);
1119 bool is_decimal_point
= ( strbuf
==
1120 wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT
, wxLOCALE_CAT_NUMBER
) );
1122 bool is_decimal_point
= ( strbuf
== _T(".") );
1125 if ( wxIsdigit(keycode
) || keycode
== '+' || keycode
== '-'
1126 || is_decimal_point
)
1128 wxGridCellTextEditor::StartingKey(event
);
1130 // skip Skip() below
1137 void wxGridCellFloatEditor::SetParameters(const wxString
& params
)
1148 if ( params
.BeforeFirst(_T(',')).ToLong(&tmp
) )
1152 if ( params
.AfterFirst(_T(',')).ToLong(&tmp
) )
1154 m_precision
= (int)tmp
;
1156 // skip the error message below
1161 wxLogDebug(_T("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params
.c_str());
1165 wxString
wxGridCellFloatEditor::GetString() const
1168 if ( m_precision
== -1 && m_width
!= -1)
1170 // default precision
1171 fmt
.Printf(_T("%%%d.f"), m_width
);
1173 else if ( m_precision
!= -1 && m_width
== -1)
1176 fmt
.Printf(_T("%%.%df"), m_precision
);
1178 else if ( m_precision
!= -1 && m_width
!= -1 )
1180 fmt
.Printf(_T("%%%d.%df"), m_width
, m_precision
);
1184 // default width/precision
1188 return wxString::Format(fmt
, m_valueOld
);
1191 bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent
& event
)
1193 if ( wxGridCellEditor::IsAcceptedKey(event
) )
1195 int keycode
= event
.GetKeyCode();
1196 printf("%d\n", keycode
);
1197 // accept digits, 'e' as in '1e+6', also '-', '+', and '.'
1199 tmpbuf
[0] = (char) keycode
;
1201 wxString
strbuf(tmpbuf
, *wxConvCurrent
);
1204 bool is_decimal_point
=
1205 ( strbuf
== wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT
,
1206 wxLOCALE_CAT_NUMBER
) );
1208 bool is_decimal_point
= ( strbuf
== _T(".") );
1211 if ( (keycode
< 128) &&
1212 (wxIsdigit(keycode
) || tolower(keycode
) == 'e' ||
1213 is_decimal_point
|| keycode
== '+' || keycode
== '-') )
1222 #endif // wxUSE_TEXTCTRL
1226 // ----------------------------------------------------------------------------
1227 // wxGridCellBoolEditor
1228 // ----------------------------------------------------------------------------
1230 void wxGridCellBoolEditor::Create(wxWindow
* parent
,
1232 wxEvtHandler
* evtHandler
)
1234 m_control
= new wxCheckBox(parent
, id
, wxEmptyString
,
1235 wxDefaultPosition
, wxDefaultSize
,
1238 wxGridCellEditor::Create(parent
, id
, evtHandler
);
1241 void wxGridCellBoolEditor::SetSize(const wxRect
& r
)
1243 bool resize
= false;
1244 wxSize size
= m_control
->GetSize();
1245 wxCoord minSize
= wxMin(r
.width
, r
.height
);
1247 // check if the checkbox is not too big/small for this cell
1248 wxSize sizeBest
= m_control
->GetBestSize();
1249 if ( !(size
== sizeBest
) )
1251 // reset to default size if it had been made smaller
1257 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
1259 // leave 1 pixel margin
1260 size
.x
= size
.y
= minSize
- 2;
1267 m_control
->SetSize(size
);
1270 // position it in the centre of the rectangle (TODO: support alignment?)
1272 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1273 // the checkbox without label still has some space to the right in wxGTK,
1274 // so shift it to the right
1276 #elif defined(__WXMSW__)
1277 // here too, but in other way
1282 int hAlign
= wxALIGN_CENTRE
;
1283 int vAlign
= wxALIGN_CENTRE
;
1285 GetCellAttr()->GetAlignment(& hAlign
, & vAlign
);
1288 if (hAlign
== wxALIGN_LEFT
)
1296 y
= r
.y
+ r
.height
/ 2 - size
.y
/ 2;
1298 else if (hAlign
== wxALIGN_RIGHT
)
1300 x
= r
.x
+ r
.width
- size
.x
- 2;
1301 y
= r
.y
+ r
.height
/ 2 - size
.y
/ 2;
1303 else if (hAlign
== wxALIGN_CENTRE
)
1305 x
= r
.x
+ r
.width
/ 2 - size
.x
/ 2;
1306 y
= r
.y
+ r
.height
/ 2 - size
.y
/ 2;
1309 m_control
->Move(x
, y
);
1312 void wxGridCellBoolEditor::Show(bool show
, wxGridCellAttr
*attr
)
1314 m_control
->Show(show
);
1318 wxColour colBg
= attr
? attr
->GetBackgroundColour() : *wxLIGHT_GREY
;
1319 CBox()->SetBackgroundColour(colBg
);
1323 void wxGridCellBoolEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1325 wxASSERT_MSG(m_control
,
1326 wxT("The wxGridCellEditor must be created first!"));
1328 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
1330 m_startValue
= grid
->GetTable()->GetValueAsBool(row
, col
);
1334 wxString
cellval( grid
->GetTable()->GetValue(row
, col
) );
1335 m_startValue
= !( !cellval
|| (cellval
== wxT("0")) );
1338 CBox()->SetValue(m_startValue
);
1342 bool wxGridCellBoolEditor::EndEdit(int row
, int col
,
1345 wxASSERT_MSG(m_control
,
1346 wxT("The wxGridCellEditor must be created first!"));
1348 bool changed
= false;
1349 bool value
= CBox()->GetValue();
1350 if ( value
!= m_startValue
)
1355 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
1356 grid
->GetTable()->SetValueAsBool(row
, col
, value
);
1358 grid
->GetTable()->SetValue(row
, col
, value
? _T("1") : wxEmptyString
);
1364 void wxGridCellBoolEditor::Reset()
1366 wxASSERT_MSG(m_control
,
1367 wxT("The wxGridCellEditor must be created first!"));
1369 CBox()->SetValue(m_startValue
);
1372 void wxGridCellBoolEditor::StartingClick()
1374 CBox()->SetValue(!CBox()->GetValue());
1377 bool wxGridCellBoolEditor::IsAcceptedKey(wxKeyEvent
& event
)
1379 if ( wxGridCellEditor::IsAcceptedKey(event
) )
1381 int keycode
= event
.GetKeyCode();
1394 void wxGridCellBoolEditor::StartingKey(wxKeyEvent
& event
)
1396 int keycode
= event
.GetKeyCode();
1400 CBox()->SetValue(!CBox()->GetValue());
1404 CBox()->SetValue(true);
1408 CBox()->SetValue(false);
1414 // return the value as "1" for true and the empty string for false
1415 wxString
wxGridCellBoolEditor::GetValue() const
1417 bool bSet
= CBox()->GetValue();
1418 return bSet
? _T("1") : wxEmptyString
;
1421 #endif // wxUSE_CHECKBOX
1425 // ----------------------------------------------------------------------------
1426 // wxGridCellChoiceEditor
1427 // ----------------------------------------------------------------------------
1429 wxGridCellChoiceEditor::wxGridCellChoiceEditor(const wxArrayString
& choices
,
1431 : m_choices(choices
),
1432 m_allowOthers(allowOthers
) { }
1434 wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count
,
1435 const wxString choices
[],
1437 : m_allowOthers(allowOthers
)
1441 m_choices
.Alloc(count
);
1442 for ( size_t n
= 0; n
< count
; n
++ )
1444 m_choices
.Add(choices
[n
]);
1449 wxGridCellEditor
*wxGridCellChoiceEditor::Clone() const
1451 wxGridCellChoiceEditor
*editor
= new wxGridCellChoiceEditor
;
1452 editor
->m_allowOthers
= m_allowOthers
;
1453 editor
->m_choices
= m_choices
;
1458 void wxGridCellChoiceEditor::Create(wxWindow
* parent
,
1460 wxEvtHandler
* evtHandler
)
1462 m_control
= new wxComboBox(parent
, id
, wxEmptyString
,
1463 wxDefaultPosition
, wxDefaultSize
,
1465 m_allowOthers
? 0 : wxCB_READONLY
);
1467 wxGridCellEditor::Create(parent
, id
, evtHandler
);
1470 void wxGridCellChoiceEditor::PaintBackground(const wxRect
& rectCell
,
1471 wxGridCellAttr
* attr
)
1473 // as we fill the entire client area, don't do anything here to minimize
1476 // TODO: It doesn't actually fill the client area since the height of a
1477 // combo always defaults to the standard. Until someone has time to
1478 // figure out the right rectangle to paint, just do it the normal way.
1479 wxGridCellEditor::PaintBackground(rectCell
, attr
);
1482 void wxGridCellChoiceEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1484 wxASSERT_MSG(m_control
,
1485 wxT("The wxGridCellEditor must be created first!"));
1487 wxGridCellEditorEvtHandler
* evtHandler
= NULL
;
1489 evtHandler
= wxDynamicCast(m_control
->GetEventHandler(), wxGridCellEditorEvtHandler
);
1491 // Don't immediately end if we get a kill focus event within BeginEdit
1493 evtHandler
->SetInSetFocus(true);
1495 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
1499 Combo()->SetValue(m_startValue
);
1503 // find the right position, or default to the first if not found
1504 int pos
= Combo()->FindString(m_startValue
);
1505 if (pos
== wxNOT_FOUND
)
1507 Combo()->SetSelection(pos
);
1510 Combo()->SetInsertionPointEnd();
1511 Combo()->SetFocus();
1515 // When dropping down the menu, a kill focus event
1516 // happens after this point, so we can't reset the flag yet.
1517 #if !defined(__WXGTK20__)
1518 evtHandler
->SetInSetFocus(false);
1523 bool wxGridCellChoiceEditor::EndEdit(int row
, int col
,
1526 wxString value
= Combo()->GetValue();
1527 if ( value
== m_startValue
)
1530 grid
->GetTable()->SetValue(row
, col
, value
);
1535 void wxGridCellChoiceEditor::Reset()
1537 Combo()->SetValue(m_startValue
);
1538 Combo()->SetInsertionPointEnd();
1541 void wxGridCellChoiceEditor::SetParameters(const wxString
& params
)
1551 wxStringTokenizer
tk(params
, _T(','));
1552 while ( tk
.HasMoreTokens() )
1554 m_choices
.Add(tk
.GetNextToken());
1558 // return the value in the text control
1559 wxString
wxGridCellChoiceEditor::GetValue() const
1561 return Combo()->GetValue();
1564 #endif // wxUSE_COMBOBOX
1566 // ----------------------------------------------------------------------------
1567 // wxGridCellEditorEvtHandler
1568 // ----------------------------------------------------------------------------
1570 void wxGridCellEditorEvtHandler::OnKillFocus(wxFocusEvent
& event
)
1572 // Don't disable the cell if we're just starting to edit it
1577 m_grid
->DisableCellEditControl();
1582 void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent
& event
)
1584 switch ( event
.GetKeyCode() )
1588 m_grid
->DisableCellEditControl();
1592 m_grid
->GetEventHandler()->ProcessEvent( event
);
1596 case WXK_NUMPAD_ENTER
:
1597 if (!m_grid
->GetEventHandler()->ProcessEvent(event
))
1598 m_editor
->HandleReturn(event
);
1607 void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent
& event
)
1609 int row
= m_grid
->GetGridCursorRow();
1610 int col
= m_grid
->GetGridCursorCol();
1611 wxRect rect
= m_grid
->CellToRect( row
, col
);
1613 m_grid
->GetGridWindow()->GetClientSize( &cw
, &ch
);
1615 // if cell width is smaller than grid client area, cell is wholly visible
1616 bool wholeCellVisible
= (rect
.GetWidth() < cw
);
1618 switch ( event
.GetKeyCode() )
1623 case WXK_NUMPAD_ENTER
:
1628 if ( wholeCellVisible
)
1630 // no special processing needed...
1635 // do special processing for partly visible cell...
1637 // get the widths of all cells previous to this one
1639 for ( int i
= 0; i
< col
; i
++ )
1641 colXPos
+= m_grid
->GetColSize(i
);
1644 int xUnit
= 1, yUnit
= 1;
1645 m_grid
->GetScrollPixelsPerUnit(&xUnit
, &yUnit
);
1648 m_grid
->Scroll(colXPos
/ xUnit
- 1, m_grid
->GetScrollPos(wxVERTICAL
));
1652 m_grid
->Scroll(colXPos
/ xUnit
, m_grid
->GetScrollPos(wxVERTICAL
));
1660 if ( wholeCellVisible
)
1662 // no special processing needed...
1667 // do special processing for partly visible cell...
1670 wxString value
= m_grid
->GetCellValue(row
, col
);
1671 if ( wxEmptyString
!= value
)
1673 // get width of cell CONTENTS (text)
1675 wxFont font
= m_grid
->GetCellFont(row
, col
);
1676 m_grid
->GetTextExtent(value
, &textWidth
, &y
, NULL
, NULL
, &font
);
1678 // try to RIGHT align the text by scrolling
1679 int client_right
= m_grid
->GetGridWindow()->GetClientSize().GetWidth();
1681 // (m_grid->GetScrollLineX()*2) is a factor for not scrolling to far,
1682 // otherwise the last part of the cell content might be hidden below the scroll bar
1683 // FIXME: maybe there is a more suitable correction?
1684 textWidth
-= (client_right
- (m_grid
->GetScrollLineX() * 2));
1685 if ( textWidth
< 0 )
1691 // get the widths of all cells previous to this one
1693 for ( int i
= 0; i
< col
; i
++ )
1695 colXPos
+= m_grid
->GetColSize(i
);
1698 // and add the (modified) text width of the cell contents
1699 // as we'd like to see the last part of the cell contents
1700 colXPos
+= textWidth
;
1702 int xUnit
= 1, yUnit
= 1;
1703 m_grid
->GetScrollPixelsPerUnit(&xUnit
, &yUnit
);
1704 m_grid
->Scroll(colXPos
/ xUnit
- 1, m_grid
->GetScrollPos(wxVERTICAL
));
1715 // ----------------------------------------------------------------------------
1716 // wxGridCellWorker is an (almost) empty common base class for
1717 // wxGridCellRenderer and wxGridCellEditor managing ref counting
1718 // ----------------------------------------------------------------------------
1720 void wxGridCellWorker::SetParameters(const wxString
& WXUNUSED(params
))
1725 wxGridCellWorker::~wxGridCellWorker()
1729 // ============================================================================
1731 // ============================================================================
1733 // ----------------------------------------------------------------------------
1734 // wxGridCellRenderer
1735 // ----------------------------------------------------------------------------
1737 void wxGridCellRenderer::Draw(wxGrid
& grid
,
1738 wxGridCellAttr
& attr
,
1741 int WXUNUSED(row
), int WXUNUSED(col
),
1744 dc
.SetBackgroundMode( wxSOLID
);
1746 // grey out fields if the grid is disabled
1747 if ( grid
.IsEnabled() )
1751 dc
.SetBrush( wxBrush(grid
.GetSelectionBackground(), wxSOLID
) );
1755 dc
.SetBrush( wxBrush(attr
.GetBackgroundColour(), wxSOLID
) );
1760 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
), wxSOLID
));
1763 dc
.SetPen( *wxTRANSPARENT_PEN
);
1764 dc
.DrawRectangle(rect
);
1767 // ----------------------------------------------------------------------------
1768 // wxGridCellStringRenderer
1769 // ----------------------------------------------------------------------------
1771 void wxGridCellStringRenderer::SetTextColoursAndFont(const wxGrid
& grid
,
1772 const wxGridCellAttr
& attr
,
1776 dc
.SetBackgroundMode( wxTRANSPARENT
);
1778 // TODO some special colours for attr.IsReadOnly() case?
1780 // different coloured text when the grid is disabled
1781 if ( grid
.IsEnabled() )
1785 dc
.SetTextBackground( grid
.GetSelectionBackground() );
1786 dc
.SetTextForeground( grid
.GetSelectionForeground() );
1790 dc
.SetTextBackground( attr
.GetBackgroundColour() );
1791 dc
.SetTextForeground( attr
.GetTextColour() );
1796 dc
.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
1797 dc
.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
));
1800 dc
.SetFont( attr
.GetFont() );
1803 wxSize
wxGridCellStringRenderer::DoGetBestSize(const wxGridCellAttr
& attr
,
1805 const wxString
& text
)
1807 wxCoord x
= 0, y
= 0, max_x
= 0;
1808 dc
.SetFont(attr
.GetFont());
1809 wxStringTokenizer
tk(text
, _T('\n'));
1810 while ( tk
.HasMoreTokens() )
1812 dc
.GetTextExtent(tk
.GetNextToken(), &x
, &y
);
1813 max_x
= wxMax(max_x
, x
);
1816 y
*= 1 + text
.Freq(wxT('\n')); // multiply by the number of lines.
1818 return wxSize(max_x
, y
);
1821 wxSize
wxGridCellStringRenderer::GetBestSize(wxGrid
& grid
,
1822 wxGridCellAttr
& attr
,
1826 return DoGetBestSize(attr
, dc
, grid
.GetCellValue(row
, col
));
1829 void wxGridCellStringRenderer::Draw(wxGrid
& grid
,
1830 wxGridCellAttr
& attr
,
1832 const wxRect
& rectCell
,
1836 wxRect rect
= rectCell
;
1839 // erase only this cells background, overflow cells should have been erased
1840 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1843 attr
.GetAlignment(&hAlign
, &vAlign
);
1845 int overflowCols
= 0;
1847 if (attr
.GetOverflow())
1849 int cols
= grid
.GetNumberCols();
1850 int best_width
= GetBestSize(grid
,attr
,dc
,row
,col
).GetWidth();
1851 int cell_rows
, cell_cols
;
1852 attr
.GetSize( &cell_rows
, &cell_cols
); // shouldn't get here if <= 0
1853 if ((best_width
> rectCell
.width
) && (col
< cols
) && grid
.GetTable())
1855 int i
, c_cols
, c_rows
;
1856 for (i
= col
+cell_cols
; i
< cols
; i
++)
1858 bool is_empty
= true;
1859 for (int j
=row
; j
< row
+ cell_rows
; j
++)
1861 // check w/ anchor cell for multicell block
1862 grid
.GetCellSize(j
, i
, &c_rows
, &c_cols
);
1865 if (!grid
.GetTable()->IsEmptyCell(j
+ c_rows
, i
))
1874 rect
.width
+= grid
.GetColSize(i
);
1882 if (rect
.width
>= best_width
)
1886 overflowCols
= i
- col
- cell_cols
+ 1;
1887 if (overflowCols
>= cols
)
1888 overflowCols
= cols
- 1;
1891 if (overflowCols
> 0) // redraw overflow cells w/ proper hilight
1893 hAlign
= wxALIGN_LEFT
; // if oveflowed then it's left aligned
1895 clip
.x
+= rectCell
.width
;
1896 // draw each overflow cell individually
1897 int col_end
= col
+ cell_cols
+ overflowCols
;
1898 if (col_end
>= grid
.GetNumberCols())
1899 col_end
= grid
.GetNumberCols() - 1;
1900 for (int i
= col
+ cell_cols
; i
<= col_end
; i
++)
1902 clip
.width
= grid
.GetColSize(i
) - 1;
1903 dc
.DestroyClippingRegion();
1904 dc
.SetClippingRegion(clip
);
1906 SetTextColoursAndFont(grid
, attr
, dc
,
1907 grid
.IsInSelection(row
,i
));
1909 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
1910 rect
, hAlign
, vAlign
);
1911 clip
.x
+= grid
.GetColSize(i
) - 1;
1917 dc
.DestroyClippingRegion();
1921 // now we only have to draw the text
1922 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1924 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
1925 rect
, hAlign
, vAlign
);
1928 // ----------------------------------------------------------------------------
1929 // wxGridCellNumberRenderer
1930 // ----------------------------------------------------------------------------
1932 wxString
wxGridCellNumberRenderer::GetString(const wxGrid
& grid
, int row
, int col
)
1934 wxGridTableBase
*table
= grid
.GetTable();
1936 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
1938 text
.Printf(_T("%ld"), table
->GetValueAsLong(row
, col
));
1942 text
= table
->GetValue(row
, col
);
1948 void wxGridCellNumberRenderer::Draw(wxGrid
& grid
,
1949 wxGridCellAttr
& attr
,
1951 const wxRect
& rectCell
,
1955 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1957 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1959 // draw the text right aligned by default
1961 attr
.GetAlignment(&hAlign
, &vAlign
);
1962 hAlign
= wxALIGN_RIGHT
;
1964 wxRect rect
= rectCell
;
1967 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
1970 wxSize
wxGridCellNumberRenderer::GetBestSize(wxGrid
& grid
,
1971 wxGridCellAttr
& attr
,
1975 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
1978 // ----------------------------------------------------------------------------
1979 // wxGridCellFloatRenderer
1980 // ----------------------------------------------------------------------------
1982 wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width
, int precision
)
1985 SetPrecision(precision
);
1988 wxGridCellRenderer
*wxGridCellFloatRenderer::Clone() const
1990 wxGridCellFloatRenderer
*renderer
= new wxGridCellFloatRenderer
;
1991 renderer
->m_width
= m_width
;
1992 renderer
->m_precision
= m_precision
;
1993 renderer
->m_format
= m_format
;
1998 wxString
wxGridCellFloatRenderer::GetString(const wxGrid
& grid
, int row
, int col
)
2000 wxGridTableBase
*table
= grid
.GetTable();
2005 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
2007 val
= table
->GetValueAsDouble(row
, col
);
2012 text
= table
->GetValue(row
, col
);
2013 hasDouble
= text
.ToDouble(&val
);
2020 if ( m_width
== -1 )
2022 if ( m_precision
== -1 )
2024 // default width/precision
2025 m_format
= _T("%f");
2029 m_format
.Printf(_T("%%.%df"), m_precision
);
2032 else if ( m_precision
== -1 )
2034 // default precision
2035 m_format
.Printf(_T("%%%d.f"), m_width
);
2039 m_format
.Printf(_T("%%%d.%df"), m_width
, m_precision
);
2043 text
.Printf(m_format
, val
);
2046 //else: text already contains the string
2051 void wxGridCellFloatRenderer::Draw(wxGrid
& grid
,
2052 wxGridCellAttr
& attr
,
2054 const wxRect
& rectCell
,
2058 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
2060 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
2062 // draw the text right aligned by default
2064 attr
.GetAlignment(&hAlign
, &vAlign
);
2065 hAlign
= wxALIGN_RIGHT
;
2067 wxRect rect
= rectCell
;
2070 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
2073 wxSize
wxGridCellFloatRenderer::GetBestSize(wxGrid
& grid
,
2074 wxGridCellAttr
& attr
,
2078 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
2081 void wxGridCellFloatRenderer::SetParameters(const wxString
& params
)
2085 // reset to defaults
2091 wxString tmp
= params
.BeforeFirst(_T(','));
2095 if ( tmp
.ToLong(&width
) )
2097 SetWidth((int)width
);
2101 wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params
.c_str());
2105 tmp
= params
.AfterFirst(_T(','));
2109 if ( tmp
.ToLong(&precision
) )
2111 SetPrecision((int)precision
);
2115 wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params
.c_str());
2121 // ----------------------------------------------------------------------------
2122 // wxGridCellBoolRenderer
2123 // ----------------------------------------------------------------------------
2125 wxSize
wxGridCellBoolRenderer::ms_sizeCheckMark
;
2127 // FIXME these checkbox size calculations are really ugly...
2129 // between checkmark and box
2130 static const wxCoord wxGRID_CHECKMARK_MARGIN
= 2;
2132 wxSize
wxGridCellBoolRenderer::GetBestSize(wxGrid
& grid
,
2133 wxGridCellAttr
& WXUNUSED(attr
),
2138 // compute it only once (no locks for MT safeness in GUI thread...)
2139 if ( !ms_sizeCheckMark
.x
)
2141 // get checkbox size
2142 wxCheckBox
*checkbox
= new wxCheckBox(&grid
, wxID_ANY
, wxEmptyString
);
2143 wxSize size
= checkbox
->GetBestSize();
2144 wxCoord checkSize
= size
.y
+ 2 * wxGRID_CHECKMARK_MARGIN
;
2146 // FIXME wxGTK::wxCheckBox::GetBestSize() gives "wrong" result
2147 #if defined(__WXGTK__) || defined(__WXMOTIF__)
2148 checkSize
-= size
.y
/ 2;
2153 ms_sizeCheckMark
.x
= ms_sizeCheckMark
.y
= checkSize
;
2156 return ms_sizeCheckMark
;
2159 void wxGridCellBoolRenderer::Draw(wxGrid
& grid
,
2160 wxGridCellAttr
& attr
,
2166 wxGridCellRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
2168 // draw a check mark in the centre (ignoring alignment - TODO)
2169 wxSize size
= GetBestSize(grid
, attr
, dc
, row
, col
);
2171 // don't draw outside the cell
2172 wxCoord minSize
= wxMin(rect
.width
, rect
.height
);
2173 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
2175 // and even leave (at least) 1 pixel margin
2176 size
.x
= size
.y
= minSize
- 2;
2179 // draw a border around checkmark
2181 attr
.GetAlignment(&hAlign
, &vAlign
);
2184 if (hAlign
== wxALIGN_CENTRE
)
2186 rectBorder
.x
= rect
.x
+ rect
.width
/ 2 - size
.x
/ 2;
2187 rectBorder
.y
= rect
.y
+ rect
.height
/ 2 - size
.y
/ 2;
2188 rectBorder
.width
= size
.x
;
2189 rectBorder
.height
= size
.y
;
2191 else if (hAlign
== wxALIGN_LEFT
)
2193 rectBorder
.x
= rect
.x
+ 2;
2194 rectBorder
.y
= rect
.y
+ rect
.height
/ 2 - size
.y
/ 2;
2195 rectBorder
.width
= size
.x
;
2196 rectBorder
.height
= size
.y
;
2198 else if (hAlign
== wxALIGN_RIGHT
)
2200 rectBorder
.x
= rect
.x
+ rect
.width
- size
.x
- 2;
2201 rectBorder
.y
= rect
.y
+ rect
.height
/ 2 - size
.y
/ 2;
2202 rectBorder
.width
= size
.x
;
2203 rectBorder
.height
= size
.y
;
2207 if ( grid
.GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
) )
2209 value
= grid
.GetTable()->GetValueAsBool(row
, col
);
2213 wxString
cellval( grid
.GetTable()->GetValue(row
, col
) );
2214 value
= !( !cellval
|| (cellval
== wxT("0")) );
2219 wxRect rectMark
= rectBorder
;
2222 // MSW DrawCheckMark() is weird (and should probably be changed...)
2223 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
/ 2);
2227 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
);
2230 dc
.SetTextForeground(attr
.GetTextColour());
2231 dc
.DrawCheckMark(rectMark
);
2234 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2235 dc
.SetPen(wxPen(attr
.GetTextColour(), 1, wxSOLID
));
2236 dc
.DrawRectangle(rectBorder
);
2239 // ----------------------------------------------------------------------------
2241 // ----------------------------------------------------------------------------
2243 void wxGridCellAttr::Init(wxGridCellAttr
*attrDefault
)
2247 m_isReadOnly
= Unset
;
2252 m_attrkind
= wxGridCellAttr::Cell
;
2254 m_sizeRows
= m_sizeCols
= 1;
2255 m_overflow
= UnsetOverflow
;
2257 SetDefAttr(attrDefault
);
2260 wxGridCellAttr
*wxGridCellAttr::Clone() const
2262 wxGridCellAttr
*attr
= new wxGridCellAttr(m_defGridAttr
);
2264 if ( HasTextColour() )
2265 attr
->SetTextColour(GetTextColour());
2266 if ( HasBackgroundColour() )
2267 attr
->SetBackgroundColour(GetBackgroundColour());
2269 attr
->SetFont(GetFont());
2270 if ( HasAlignment() )
2271 attr
->SetAlignment(m_hAlign
, m_vAlign
);
2273 attr
->SetSize( m_sizeRows
, m_sizeCols
);
2277 attr
->SetRenderer(m_renderer
);
2278 m_renderer
->IncRef();
2282 attr
->SetEditor(m_editor
);
2287 attr
->SetReadOnly();
2289 attr
->SetKind( m_attrkind
);
2294 void wxGridCellAttr::MergeWith(wxGridCellAttr
*mergefrom
)
2296 if ( !HasTextColour() && mergefrom
->HasTextColour() )
2297 SetTextColour(mergefrom
->GetTextColour());
2298 if ( !HasBackgroundColour() && mergefrom
->HasBackgroundColour() )
2299 SetBackgroundColour(mergefrom
->GetBackgroundColour());
2300 if ( !HasFont() && mergefrom
->HasFont() )
2301 SetFont(mergefrom
->GetFont());
2302 if ( !HasAlignment() && mergefrom
->HasAlignment() )
2305 mergefrom
->GetAlignment( &hAlign
, &vAlign
);
2306 SetAlignment(hAlign
, vAlign
);
2308 if ( !HasSize() && mergefrom
->HasSize() )
2309 mergefrom
->GetSize( &m_sizeRows
, &m_sizeCols
);
2311 // Directly access member functions as GetRender/Editor don't just return
2312 // m_renderer/m_editor
2314 // Maybe add support for merge of Render and Editor?
2315 if (!HasRenderer() && mergefrom
->HasRenderer() )
2317 m_renderer
= mergefrom
->m_renderer
;
2318 m_renderer
->IncRef();
2320 if ( !HasEditor() && mergefrom
->HasEditor() )
2322 m_editor
= mergefrom
->m_editor
;
2325 if ( !HasReadWriteMode() && mergefrom
->HasReadWriteMode() )
2326 SetReadOnly(mergefrom
->IsReadOnly());
2328 if (!HasOverflowMode() && mergefrom
->HasOverflowMode() )
2329 SetOverflow(mergefrom
->GetOverflow());
2331 SetDefAttr(mergefrom
->m_defGridAttr
);
2334 void wxGridCellAttr::SetSize(int num_rows
, int num_cols
)
2336 // The size of a cell is normally 1,1
2338 // If this cell is larger (2,2) then this is the top left cell
2339 // the other cells that will be covered (lower right cells) must be
2340 // set to negative or zero values such that
2341 // row + num_rows of the covered cell points to the larger cell (this cell)
2342 // same goes for the col + num_cols.
2344 // Size of 0,0 is NOT valid, neither is <=0 and any positive value
2346 wxASSERT_MSG( (!((num_rows
> 0) && (num_cols
<= 0)) ||
2347 !((num_rows
<= 0) && (num_cols
> 0)) ||
2348 !((num_rows
== 0) && (num_cols
== 0))),
2349 wxT("wxGridCellAttr::SetSize only takes two postive values or negative/zero values"));
2351 m_sizeRows
= num_rows
;
2352 m_sizeCols
= num_cols
;
2355 const wxColour
& wxGridCellAttr::GetTextColour() const
2357 if (HasTextColour())
2361 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2363 return m_defGridAttr
->GetTextColour();
2367 wxFAIL_MSG(wxT("Missing default cell attribute"));
2368 return wxNullColour
;
2372 const wxColour
& wxGridCellAttr::GetBackgroundColour() const
2374 if (HasBackgroundColour())
2378 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2380 return m_defGridAttr
->GetBackgroundColour();
2384 wxFAIL_MSG(wxT("Missing default cell attribute"));
2385 return wxNullColour
;
2389 const wxFont
& wxGridCellAttr::GetFont() const
2395 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2397 return m_defGridAttr
->GetFont();
2401 wxFAIL_MSG(wxT("Missing default cell attribute"));
2406 void wxGridCellAttr::GetAlignment(int *hAlign
, int *vAlign
) const
2415 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2417 m_defGridAttr
->GetAlignment(hAlign
, vAlign
);
2421 wxFAIL_MSG(wxT("Missing default cell attribute"));
2425 void wxGridCellAttr::GetSize( int *num_rows
, int *num_cols
) const
2428 *num_rows
= m_sizeRows
;
2430 *num_cols
= m_sizeCols
;
2433 // GetRenderer and GetEditor use a slightly different decision path about
2434 // which attribute to use. If a non-default attr object has one then it is
2435 // used, otherwise the default editor or renderer is fetched from the grid and
2436 // used. It should be the default for the data type of the cell. If it is
2437 // NULL (because the table has a type that the grid does not have in its
2438 // registry), then the grid's default editor or renderer is used.
2440 wxGridCellRenderer
* wxGridCellAttr::GetRenderer(wxGrid
* grid
, int row
, int col
) const
2442 wxGridCellRenderer
*renderer
= NULL
;
2444 if ( m_renderer
&& this != m_defGridAttr
)
2446 // use the cells renderer if it has one
2447 renderer
= m_renderer
;
2450 else // no non-default cell renderer
2452 // get default renderer for the data type
2455 // GetDefaultRendererForCell() will do IncRef() for us
2456 renderer
= grid
->GetDefaultRendererForCell(row
, col
);
2459 if ( renderer
== NULL
)
2461 if ( (m_defGridAttr
!= NULL
) && (m_defGridAttr
!= this) )
2463 // if we still don't have one then use the grid default
2464 // (no need for IncRef() here neither)
2465 renderer
= m_defGridAttr
->GetRenderer(NULL
, 0, 0);
2467 else // default grid attr
2469 // use m_renderer which we had decided not to use initially
2470 renderer
= m_renderer
;
2477 // we're supposed to always find something
2478 wxASSERT_MSG(renderer
, wxT("Missing default cell renderer"));
2483 // same as above, except for s/renderer/editor/g
2484 wxGridCellEditor
* wxGridCellAttr::GetEditor(wxGrid
* grid
, int row
, int col
) const
2486 wxGridCellEditor
*editor
= NULL
;
2488 if ( m_editor
&& this != m_defGridAttr
)
2490 // use the cells editor if it has one
2494 else // no non default cell editor
2496 // get default editor for the data type
2499 // GetDefaultEditorForCell() will do IncRef() for us
2500 editor
= grid
->GetDefaultEditorForCell(row
, col
);
2503 if ( editor
== NULL
)
2505 if ( (m_defGridAttr
!= NULL
) && (m_defGridAttr
!= this) )
2507 // if we still don't have one then use the grid default
2508 // (no need for IncRef() here neither)
2509 editor
= m_defGridAttr
->GetEditor(NULL
, 0, 0);
2511 else // default grid attr
2513 // use m_editor which we had decided not to use initially
2521 // we're supposed to always find something
2522 wxASSERT_MSG(editor
, wxT("Missing default cell editor"));
2527 // ----------------------------------------------------------------------------
2528 // wxGridCellAttrData
2529 // ----------------------------------------------------------------------------
2531 void wxGridCellAttrData::SetAttr(wxGridCellAttr
*attr
, int row
, int col
)
2533 int n
= FindIndex(row
, col
);
2534 if ( n
== wxNOT_FOUND
)
2536 // add the attribute
2537 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
2541 // free the old attribute
2542 m_attrs
[(size_t)n
].attr
->DecRef();
2546 // change the attribute
2547 m_attrs
[(size_t)n
].attr
= attr
;
2551 // remove this attribute
2552 m_attrs
.RemoveAt((size_t)n
);
2557 wxGridCellAttr
*wxGridCellAttrData::GetAttr(int row
, int col
) const
2559 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2561 int n
= FindIndex(row
, col
);
2562 if ( n
!= wxNOT_FOUND
)
2564 attr
= m_attrs
[(size_t)n
].attr
;
2571 void wxGridCellAttrData::UpdateAttrRows( size_t pos
, int numRows
)
2573 size_t count
= m_attrs
.GetCount();
2574 for ( size_t n
= 0; n
< count
; n
++ )
2576 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2577 wxCoord row
= coords
.GetRow();
2578 if ((size_t)row
>= pos
)
2582 // If rows inserted, include row counter where necessary
2583 coords
.SetRow(row
+ numRows
);
2585 else if (numRows
< 0)
2587 // If rows deleted ...
2588 if ((size_t)row
>= pos
- numRows
)
2590 // ...either decrement row counter (if row still exists)...
2591 coords
.SetRow(row
+ numRows
);
2595 // ...or remove the attribute
2596 // No need to DecRef the attribute itself since this is
2597 // done be wxGridCellWithAttr's destructor!
2598 m_attrs
.RemoveAt(n
);
2607 void wxGridCellAttrData::UpdateAttrCols( size_t pos
, int numCols
)
2609 size_t count
= m_attrs
.GetCount();
2610 for ( size_t n
= 0; n
< count
; n
++ )
2612 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2613 wxCoord col
= coords
.GetCol();
2614 if ( (size_t)col
>= pos
)
2618 // If rows inserted, include row counter where necessary
2619 coords
.SetCol(col
+ numCols
);
2621 else if (numCols
< 0)
2623 // If rows deleted ...
2624 if ((size_t)col
>= pos
- numCols
)
2626 // ...either decrement row counter (if row still exists)...
2627 coords
.SetCol(col
+ numCols
);
2631 // ...or remove the attribute
2632 // No need to DecRef the attribute itself since this is
2633 // done be wxGridCellWithAttr's destructor!
2634 m_attrs
.RemoveAt(n
);
2643 int wxGridCellAttrData::FindIndex(int row
, int col
) const
2645 size_t count
= m_attrs
.GetCount();
2646 for ( size_t n
= 0; n
< count
; n
++ )
2648 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2649 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
2658 // ----------------------------------------------------------------------------
2659 // wxGridRowOrColAttrData
2660 // ----------------------------------------------------------------------------
2662 wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
2664 size_t count
= m_attrs
.Count();
2665 for ( size_t n
= 0; n
< count
; n
++ )
2667 m_attrs
[n
]->DecRef();
2671 wxGridCellAttr
*wxGridRowOrColAttrData::GetAttr(int rowOrCol
) const
2673 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2675 int n
= m_rowsOrCols
.Index(rowOrCol
);
2676 if ( n
!= wxNOT_FOUND
)
2678 attr
= m_attrs
[(size_t)n
];
2685 void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr
*attr
, int rowOrCol
)
2687 int i
= m_rowsOrCols
.Index(rowOrCol
);
2688 if ( i
== wxNOT_FOUND
)
2690 // add the attribute
2691 m_rowsOrCols
.Add(rowOrCol
);
2696 size_t n
= (size_t)i
;
2699 // change the attribute
2700 m_attrs
[n
]->DecRef();
2705 // remove this attribute
2706 m_attrs
[n
]->DecRef();
2707 m_rowsOrCols
.RemoveAt(n
);
2708 m_attrs
.RemoveAt(n
);
2713 void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
)
2715 size_t count
= m_attrs
.GetCount();
2716 for ( size_t n
= 0; n
< count
; n
++ )
2718 int & rowOrCol
= m_rowsOrCols
[n
];
2719 if ( (size_t)rowOrCol
>= pos
)
2721 if ( numRowsOrCols
> 0 )
2723 // If rows inserted, include row counter where necessary
2724 rowOrCol
+= numRowsOrCols
;
2726 else if ( numRowsOrCols
< 0)
2728 // If rows deleted, either decrement row counter (if row still exists)
2729 if ((size_t)rowOrCol
>= pos
- numRowsOrCols
)
2730 rowOrCol
+= numRowsOrCols
;
2733 m_rowsOrCols
.RemoveAt(n
);
2734 m_attrs
[n
]->DecRef();
2735 m_attrs
.RemoveAt(n
);
2744 // ----------------------------------------------------------------------------
2745 // wxGridCellAttrProvider
2746 // ----------------------------------------------------------------------------
2748 wxGridCellAttrProvider::wxGridCellAttrProvider()
2750 m_data
= (wxGridCellAttrProviderData
*)NULL
;
2753 wxGridCellAttrProvider::~wxGridCellAttrProvider()
2758 void wxGridCellAttrProvider::InitData()
2760 m_data
= new wxGridCellAttrProviderData
;
2763 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
,
2764 wxGridCellAttr::wxAttrKind kind
) const
2766 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2771 case (wxGridCellAttr::Any
):
2772 // Get cached merge attributes.
2773 // Currently not used as no cache implemented as not mutable
2774 // attr = m_data->m_mergeAttr.GetAttr(row, col);
2777 // Basically implement old version.
2778 // Also check merge cache, so we don't have to re-merge every time..
2779 wxGridCellAttr
*attrcell
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
2780 wxGridCellAttr
*attrrow
= m_data
->m_rowAttrs
.GetAttr(row
);
2781 wxGridCellAttr
*attrcol
= m_data
->m_colAttrs
.GetAttr(col
);
2783 if ((attrcell
!= attrrow
) && (attrrow
!= attrcol
) && (attrcell
!= attrcol
))
2785 // Two or more are non NULL
2786 attr
= new wxGridCellAttr
;
2787 attr
->SetKind(wxGridCellAttr::Merged
);
2789 // Order is important..
2792 attr
->MergeWith(attrcell
);
2797 attr
->MergeWith(attrcol
);
2802 attr
->MergeWith(attrrow
);
2806 // store merge attr if cache implemented
2808 //m_data->m_mergeAttr.SetAttr(attr, row, col);
2812 // one or none is non null return it or null.
2831 case (wxGridCellAttr::Cell
):
2832 attr
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
2835 case (wxGridCellAttr::Col
):
2836 attr
= m_data
->m_colAttrs
.GetAttr(col
);
2839 case (wxGridCellAttr::Row
):
2840 attr
= m_data
->m_rowAttrs
.GetAttr(row
);
2845 // (wxGridCellAttr::Default):
2846 // (wxGridCellAttr::Merged):
2854 void wxGridCellAttrProvider::SetAttr(wxGridCellAttr
*attr
,
2860 m_data
->m_cellAttrs
.SetAttr(attr
, row
, col
);
2863 void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr
*attr
, int row
)
2868 m_data
->m_rowAttrs
.SetAttr(attr
, row
);
2871 void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr
*attr
, int col
)
2876 m_data
->m_colAttrs
.SetAttr(attr
, col
);
2879 void wxGridCellAttrProvider::UpdateAttrRows( size_t pos
, int numRows
)
2883 m_data
->m_cellAttrs
.UpdateAttrRows( pos
, numRows
);
2885 m_data
->m_rowAttrs
.UpdateAttrRowsOrCols( pos
, numRows
);
2889 void wxGridCellAttrProvider::UpdateAttrCols( size_t pos
, int numCols
)
2893 m_data
->m_cellAttrs
.UpdateAttrCols( pos
, numCols
);
2895 m_data
->m_colAttrs
.UpdateAttrRowsOrCols( pos
, numCols
);
2899 // ----------------------------------------------------------------------------
2900 // wxGridTypeRegistry
2901 // ----------------------------------------------------------------------------
2903 wxGridTypeRegistry::~wxGridTypeRegistry()
2905 size_t count
= m_typeinfo
.Count();
2906 for ( size_t i
= 0; i
< count
; i
++ )
2907 delete m_typeinfo
[i
];
2910 void wxGridTypeRegistry::RegisterDataType(const wxString
& typeName
,
2911 wxGridCellRenderer
* renderer
,
2912 wxGridCellEditor
* editor
)
2914 wxGridDataTypeInfo
* info
= new wxGridDataTypeInfo(typeName
, renderer
, editor
);
2916 // is it already registered?
2917 int loc
= FindRegisteredDataType(typeName
);
2918 if ( loc
!= wxNOT_FOUND
)
2920 delete m_typeinfo
[loc
];
2921 m_typeinfo
[loc
] = info
;
2925 m_typeinfo
.Add(info
);
2929 int wxGridTypeRegistry::FindRegisteredDataType(const wxString
& typeName
)
2931 size_t count
= m_typeinfo
.GetCount();
2932 for ( size_t i
= 0; i
< count
; i
++ )
2934 if ( typeName
== m_typeinfo
[i
]->m_typeName
)
2943 int wxGridTypeRegistry::FindDataType(const wxString
& typeName
)
2945 int index
= FindRegisteredDataType(typeName
);
2946 if ( index
== wxNOT_FOUND
)
2948 // check whether this is one of the standard ones, in which case
2949 // register it "on the fly"
2951 if ( typeName
== wxGRID_VALUE_STRING
)
2953 RegisterDataType(wxGRID_VALUE_STRING
,
2954 new wxGridCellStringRenderer
,
2955 new wxGridCellTextEditor
);
2958 #endif // wxUSE_TEXTCTRL
2960 if ( typeName
== wxGRID_VALUE_BOOL
)
2962 RegisterDataType(wxGRID_VALUE_BOOL
,
2963 new wxGridCellBoolRenderer
,
2964 new wxGridCellBoolEditor
);
2967 #endif // wxUSE_CHECKBOX
2969 if ( typeName
== wxGRID_VALUE_NUMBER
)
2971 RegisterDataType(wxGRID_VALUE_NUMBER
,
2972 new wxGridCellNumberRenderer
,
2973 new wxGridCellNumberEditor
);
2975 else if ( typeName
== wxGRID_VALUE_FLOAT
)
2977 RegisterDataType(wxGRID_VALUE_FLOAT
,
2978 new wxGridCellFloatRenderer
,
2979 new wxGridCellFloatEditor
);
2982 #endif // wxUSE_TEXTCTRL
2984 if ( typeName
== wxGRID_VALUE_CHOICE
)
2986 RegisterDataType(wxGRID_VALUE_CHOICE
,
2987 new wxGridCellStringRenderer
,
2988 new wxGridCellChoiceEditor
);
2991 #endif // wxUSE_COMBOBOX
2996 // we get here only if just added the entry for this type, so return
2998 index
= m_typeinfo
.GetCount() - 1;
3004 int wxGridTypeRegistry::FindOrCloneDataType(const wxString
& typeName
)
3006 int index
= FindDataType(typeName
);
3007 if ( index
== wxNOT_FOUND
)
3009 // the first part of the typename is the "real" type, anything after ':'
3010 // are the parameters for the renderer
3011 index
= FindDataType(typeName
.BeforeFirst(_T(':')));
3012 if ( index
== wxNOT_FOUND
)
3017 wxGridCellRenderer
*renderer
= GetRenderer(index
);
3018 wxGridCellRenderer
*rendererOld
= renderer
;
3019 renderer
= renderer
->Clone();
3020 rendererOld
->DecRef();
3022 wxGridCellEditor
*editor
= GetEditor(index
);
3023 wxGridCellEditor
*editorOld
= editor
;
3024 editor
= editor
->Clone();
3025 editorOld
->DecRef();
3027 // do it even if there are no parameters to reset them to defaults
3028 wxString params
= typeName
.AfterFirst(_T(':'));
3029 renderer
->SetParameters(params
);
3030 editor
->SetParameters(params
);
3032 // register the new typename
3033 RegisterDataType(typeName
, renderer
, editor
);
3035 // we just registered it, it's the last one
3036 index
= m_typeinfo
.GetCount() - 1;
3042 wxGridCellRenderer
* wxGridTypeRegistry::GetRenderer(int index
)
3044 wxGridCellRenderer
* renderer
= m_typeinfo
[index
]->m_renderer
;
3051 wxGridCellEditor
* wxGridTypeRegistry::GetEditor(int index
)
3053 wxGridCellEditor
* editor
= m_typeinfo
[index
]->m_editor
;
3060 // ----------------------------------------------------------------------------
3062 // ----------------------------------------------------------------------------
3064 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
3066 wxGridTableBase::wxGridTableBase()
3068 m_view
= (wxGrid
*) NULL
;
3069 m_attrProvider
= (wxGridCellAttrProvider
*) NULL
;
3072 wxGridTableBase::~wxGridTableBase()
3074 delete m_attrProvider
;
3077 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
3079 delete m_attrProvider
;
3080 m_attrProvider
= attrProvider
;
3083 bool wxGridTableBase::CanHaveAttributes()
3085 if ( ! GetAttrProvider() )
3087 // use the default attr provider by default
3088 SetAttrProvider(new wxGridCellAttrProvider
);
3094 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
, wxGridCellAttr::wxAttrKind kind
)
3096 if ( m_attrProvider
)
3097 return m_attrProvider
->GetAttr(row
, col
, kind
);
3099 return (wxGridCellAttr
*)NULL
;
3102 void wxGridTableBase::SetAttr(wxGridCellAttr
* attr
, int row
, int col
)
3104 if ( m_attrProvider
)
3106 attr
->SetKind(wxGridCellAttr::Cell
);
3107 m_attrProvider
->SetAttr(attr
, row
, col
);
3111 // as we take ownership of the pointer and don't store it, we must
3117 void wxGridTableBase::SetRowAttr(wxGridCellAttr
*attr
, int row
)
3119 if ( m_attrProvider
)
3121 attr
->SetKind(wxGridCellAttr::Row
);
3122 m_attrProvider
->SetRowAttr(attr
, row
);
3126 // as we take ownership of the pointer and don't store it, we must
3132 void wxGridTableBase::SetColAttr(wxGridCellAttr
*attr
, int col
)
3134 if ( m_attrProvider
)
3136 attr
->SetKind(wxGridCellAttr::Col
);
3137 m_attrProvider
->SetColAttr(attr
, col
);
3141 // as we take ownership of the pointer and don't store it, we must
3147 bool wxGridTableBase::InsertRows( size_t WXUNUSED(pos
),
3148 size_t WXUNUSED(numRows
) )
3150 wxFAIL_MSG( wxT("Called grid table class function InsertRows\nbut your derived table class does not override this function") );
3155 bool wxGridTableBase::AppendRows( size_t WXUNUSED(numRows
) )
3157 wxFAIL_MSG( wxT("Called grid table class function AppendRows\nbut your derived table class does not override this function"));
3162 bool wxGridTableBase::DeleteRows( size_t WXUNUSED(pos
),
3163 size_t WXUNUSED(numRows
) )
3165 wxFAIL_MSG( wxT("Called grid table class function DeleteRows\nbut your derived table class does not override this function"));
3170 bool wxGridTableBase::InsertCols( size_t WXUNUSED(pos
),
3171 size_t WXUNUSED(numCols
) )
3173 wxFAIL_MSG( wxT("Called grid table class function InsertCols\nbut your derived table class does not override this function"));
3178 bool wxGridTableBase::AppendCols( size_t WXUNUSED(numCols
) )
3180 wxFAIL_MSG(wxT("Called grid table class function AppendCols\nbut your derived table class does not override this function"));
3185 bool wxGridTableBase::DeleteCols( size_t WXUNUSED(pos
),
3186 size_t WXUNUSED(numCols
) )
3188 wxFAIL_MSG( wxT("Called grid table class function DeleteCols\nbut your derived table class does not override this function"));
3193 wxString
wxGridTableBase::GetRowLabelValue( int row
)
3197 // RD: Starting the rows at zero confuses users,
3198 // no matter how much it makes sense to us geeks.
3204 wxString
wxGridTableBase::GetColLabelValue( int col
)
3206 // default col labels are:
3207 // cols 0 to 25 : A-Z
3208 // cols 26 to 675 : AA-ZZ
3213 for ( n
= 1; ; n
++ )
3215 s
+= (wxChar
) (_T('A') + (wxChar
)(col
% 26));
3221 // reverse the string...
3223 for ( i
= 0; i
< n
; i
++ )
3231 wxString
wxGridTableBase::GetTypeName( int WXUNUSED(row
), int WXUNUSED(col
) )
3233 return wxGRID_VALUE_STRING
;
3236 bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row
), int WXUNUSED(col
),
3237 const wxString
& typeName
)
3239 return typeName
== wxGRID_VALUE_STRING
;
3242 bool wxGridTableBase::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
3244 return CanGetValueAs(row
, col
, typeName
);
3247 long wxGridTableBase::GetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
) )
3252 double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
) )
3257 bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
) )
3262 void wxGridTableBase::SetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
),
3263 long WXUNUSED(value
) )
3267 void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
),
3268 double WXUNUSED(value
) )
3272 void wxGridTableBase::SetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
),
3273 bool WXUNUSED(value
) )
3277 void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
3278 const wxString
& WXUNUSED(typeName
) )
3283 void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
3284 const wxString
& WXUNUSED(typeName
),
3285 void* WXUNUSED(value
) )
3289 //////////////////////////////////////////////////////////////////////
3291 // Message class for the grid table to send requests and notifications
3295 wxGridTableMessage::wxGridTableMessage()
3297 m_table
= (wxGridTableBase
*) NULL
;
3303 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
3304 int commandInt1
, int commandInt2
)
3308 m_comInt1
= commandInt1
;
3309 m_comInt2
= commandInt2
;
3312 //////////////////////////////////////////////////////////////////////
3314 // A basic grid table for string data. An object of this class will
3315 // created by wxGrid if you don't specify an alternative table class.
3318 WX_DEFINE_OBJARRAY(wxGridStringArray
)
3320 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
3322 wxGridStringTable::wxGridStringTable()
3327 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
3330 m_data
.Alloc( numRows
);
3333 sa
.Alloc( numCols
);
3334 sa
.Add( wxEmptyString
, numCols
);
3336 m_data
.Add( sa
, numRows
);
3339 wxGridStringTable::~wxGridStringTable()
3343 int wxGridStringTable::GetNumberRows()
3345 return m_data
.GetCount();
3348 int wxGridStringTable::GetNumberCols()
3350 if ( m_data
.GetCount() > 0 )
3351 return m_data
[0].GetCount();
3356 wxString
wxGridStringTable::GetValue( int row
, int col
)
3358 wxCHECK_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3360 _T("invalid row or column index in wxGridStringTable") );
3362 return m_data
[row
][col
];
3365 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& value
)
3367 wxCHECK_RET( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3368 _T("invalid row or column index in wxGridStringTable") );
3370 m_data
[row
][col
] = value
;
3373 bool wxGridStringTable::IsEmptyCell( int row
, int col
)
3375 wxCHECK_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3377 _T("invalid row or column index in wxGridStringTable") );
3379 return (m_data
[row
][col
] == wxEmptyString
);
3382 void wxGridStringTable::Clear()
3385 int numRows
, numCols
;
3387 numRows
= m_data
.GetCount();
3390 numCols
= m_data
[0].GetCount();
3392 for ( row
= 0; row
< numRows
; row
++ )
3394 for ( col
= 0; col
< numCols
; col
++ )
3396 m_data
[row
][col
] = wxEmptyString
;
3402 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
3404 size_t curNumRows
= m_data
.GetCount();
3405 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3406 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3408 if ( pos
>= curNumRows
)
3410 return AppendRows( numRows
);
3414 sa
.Alloc( curNumCols
);
3415 sa
.Add( wxEmptyString
, curNumCols
);
3416 m_data
.Insert( sa
, pos
, numRows
);
3420 wxGridTableMessage
msg( this,
3421 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
3425 GetView()->ProcessTableMessage( msg
);
3431 bool wxGridStringTable::AppendRows( size_t numRows
)
3433 size_t curNumRows
= m_data
.GetCount();
3434 size_t curNumCols
= ( curNumRows
> 0
3435 ? m_data
[0].GetCount()
3436 : ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3439 if ( curNumCols
> 0 )
3441 sa
.Alloc( curNumCols
);
3442 sa
.Add( wxEmptyString
, curNumCols
);
3445 m_data
.Add( sa
, numRows
);
3449 wxGridTableMessage
msg( this,
3450 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
3453 GetView()->ProcessTableMessage( msg
);
3459 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
3461 size_t curNumRows
= m_data
.GetCount();
3463 if ( pos
>= curNumRows
)
3465 wxFAIL_MSG( wxString::Format
3467 wxT("Called wxGridStringTable::DeleteRows(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu rows"),
3469 (unsigned long)numRows
,
3470 (unsigned long)curNumRows
3476 if ( numRows
> curNumRows
- pos
)
3478 numRows
= curNumRows
- pos
;
3481 if ( numRows
>= curNumRows
)
3487 m_data
.RemoveAt( pos
, numRows
);
3492 wxGridTableMessage
msg( this,
3493 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
3497 GetView()->ProcessTableMessage( msg
);
3503 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
3507 size_t curNumRows
= m_data
.GetCount();
3508 size_t curNumCols
= ( curNumRows
> 0
3509 ? m_data
[0].GetCount()
3510 : ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3512 if ( pos
>= curNumCols
)
3514 return AppendCols( numCols
);
3517 if ( !m_colLabels
.IsEmpty() )
3519 m_colLabels
.Insert( wxEmptyString
, pos
, numCols
);
3522 for ( i
= pos
; i
< pos
+ numCols
; i
++ )
3523 m_colLabels
[i
] = wxGridTableBase::GetColLabelValue( i
);
3526 for ( row
= 0; row
< curNumRows
; row
++ )
3528 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
3530 m_data
[row
].Insert( wxEmptyString
, col
);
3536 wxGridTableMessage
msg( this,
3537 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
3541 GetView()->ProcessTableMessage( msg
);
3547 bool wxGridStringTable::AppendCols( size_t numCols
)
3551 size_t curNumRows
= m_data
.GetCount();
3556 // TODO: something better than this ?
3558 wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\nCall AppendRows() first") );
3563 for ( row
= 0; row
< curNumRows
; row
++ )
3565 m_data
[row
].Add( wxEmptyString
, numCols
);
3570 wxGridTableMessage
msg( this,
3571 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
3574 GetView()->ProcessTableMessage( msg
);
3580 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
3584 size_t curNumRows
= m_data
.GetCount();
3585 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3586 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3588 if ( pos
>= curNumCols
)
3590 wxFAIL_MSG( wxString::Format
3592 wxT("Called wxGridStringTable::DeleteCols(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu cols"),
3594 (unsigned long)numCols
,
3595 (unsigned long)curNumCols
3602 colID
= GetView()->GetColAt( pos
);
3606 if ( numCols
> curNumCols
- colID
)
3608 numCols
= curNumCols
- colID
;
3611 if ( !m_colLabels
.IsEmpty() )
3613 m_colLabels
.RemoveAt( colID
, numCols
);
3616 for ( row
= 0; row
< curNumRows
; row
++ )
3618 if ( numCols
>= curNumCols
)
3620 m_data
[row
].Clear();
3624 m_data
[row
].RemoveAt( colID
, numCols
);
3630 wxGridTableMessage
msg( this,
3631 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
3635 GetView()->ProcessTableMessage( msg
);
3641 wxString
wxGridStringTable::GetRowLabelValue( int row
)
3643 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
3645 // using default label
3647 return wxGridTableBase::GetRowLabelValue( row
);
3651 return m_rowLabels
[row
];
3655 wxString
wxGridStringTable::GetColLabelValue( int col
)
3657 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
3659 // using default label
3661 return wxGridTableBase::GetColLabelValue( col
);
3665 return m_colLabels
[col
];
3669 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
3671 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
3673 int n
= m_rowLabels
.GetCount();
3676 for ( i
= n
; i
<= row
; i
++ )
3678 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
3682 m_rowLabels
[row
] = value
;
3685 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
3687 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
3689 int n
= m_colLabels
.GetCount();
3692 for ( i
= n
; i
<= col
; i
++ )
3694 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
3698 m_colLabels
[col
] = value
;
3702 //////////////////////////////////////////////////////////////////////
3703 //////////////////////////////////////////////////////////////////////
3705 IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow
, wxWindow
)
3707 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxWindow
)
3708 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
3709 EVT_MOUSEWHEEL( wxGridRowLabelWindow::OnMouseWheel
)
3710 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
3711 EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown
)
3712 EVT_KEY_UP( wxGridRowLabelWindow::OnKeyUp
)
3713 EVT_CHAR( wxGridRowLabelWindow::OnChar
)
3716 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid
*parent
,
3718 const wxPoint
&pos
, const wxSize
&size
)
3719 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
| wxBORDER_NONE
| wxFULL_REPAINT_ON_RESIZE
)
3724 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3728 // NO - don't do this because it will set both the x and y origin
3729 // coords to match the parent scrolled window and we just want to
3730 // set the y coord - MB
3732 // m_owner->PrepareDC( dc );
3735 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
3736 dc
.SetDeviceOrigin( 0, -y
);
3738 wxArrayInt rows
= m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
3739 m_owner
->DrawRowLabels( dc
, rows
);
3742 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3744 m_owner
->ProcessRowLabelMouseEvent( event
);
3747 void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3749 m_owner
->GetEventHandler()->ProcessEvent( event
);
3752 // This seems to be required for wxMotif otherwise the mouse
3753 // cursor must be in the cell edit control to get key events
3755 void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3757 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
3761 void wxGridRowLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3763 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
3767 void wxGridRowLabelWindow::OnChar( wxKeyEvent
& event
)
3769 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
3773 //////////////////////////////////////////////////////////////////////
3775 IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow
, wxWindow
)
3777 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxWindow
)
3778 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
3779 EVT_MOUSEWHEEL( wxGridColLabelWindow::OnMouseWheel
)
3780 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
3781 EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown
)
3782 EVT_KEY_UP( wxGridColLabelWindow::OnKeyUp
)
3783 EVT_CHAR( wxGridColLabelWindow::OnChar
)
3786 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid
*parent
,
3788 const wxPoint
&pos
, const wxSize
&size
)
3789 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
| wxBORDER_NONE
| wxFULL_REPAINT_ON_RESIZE
)
3794 void wxGridColLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3798 // NO - don't do this because it will set both the x and y origin
3799 // coords to match the parent scrolled window and we just want to
3800 // set the x coord - MB
3802 // m_owner->PrepareDC( dc );
3805 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
3806 dc
.SetDeviceOrigin( -x
, 0 );
3808 wxArrayInt cols
= m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
3809 m_owner
->DrawColLabels( dc
, cols
);
3812 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3814 m_owner
->ProcessColLabelMouseEvent( event
);
3817 void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3819 m_owner
->GetEventHandler()->ProcessEvent( event
);
3822 // This seems to be required for wxMotif otherwise the mouse
3823 // cursor must be in the cell edit control to get key events
3825 void wxGridColLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3827 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
3831 void wxGridColLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3833 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
3837 void wxGridColLabelWindow::OnChar( wxKeyEvent
& event
)
3839 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
3843 //////////////////////////////////////////////////////////////////////
3845 IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow
, wxWindow
)
3847 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxWindow
)
3848 EVT_MOUSEWHEEL( wxGridCornerLabelWindow::OnMouseWheel
)
3849 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
3850 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
3851 EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown
)
3852 EVT_KEY_UP( wxGridCornerLabelWindow::OnKeyUp
)
3853 EVT_CHAR( wxGridCornerLabelWindow::OnChar
)
3856 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid
*parent
,
3858 const wxPoint
&pos
, const wxSize
&size
)
3859 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
| wxBORDER_NONE
| wxFULL_REPAINT_ON_RESIZE
)
3864 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3868 int client_height
= 0;
3869 int client_width
= 0;
3870 GetClientSize( &client_width
, &client_height
);
3872 // VZ: any reason for this ifdef? (FIXME)
3877 rect
.SetWidth( client_width
- 2 );
3878 rect
.SetHeight( client_height
- 2 );
3880 wxRendererNative::Get().DrawHeaderButton( this, dc
, rect
, 0 );
3882 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
), 1, wxSOLID
) );
3883 dc
.DrawLine( client_width
- 1, client_height
- 1, client_width
- 1, 0 );
3884 dc
.DrawLine( client_width
- 1, client_height
- 1, 0, client_height
- 1 );
3885 dc
.DrawLine( 0, 0, client_width
, 0 );
3886 dc
.DrawLine( 0, 0, 0, client_height
);
3888 dc
.SetPen( *wxWHITE_PEN
);
3889 dc
.DrawLine( 1, 1, client_width
- 1, 1 );
3890 dc
.DrawLine( 1, 1, 1, client_height
- 1 );
3894 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3896 m_owner
->ProcessCornerLabelMouseEvent( event
);
3899 void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3901 m_owner
->GetEventHandler()->ProcessEvent(event
);
3904 // This seems to be required for wxMotif otherwise the mouse
3905 // cursor must be in the cell edit control to get key events
3907 void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3909 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
3913 void wxGridCornerLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3915 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
3919 void wxGridCornerLabelWindow::OnChar( wxKeyEvent
& event
)
3921 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
3925 //////////////////////////////////////////////////////////////////////
3927 IMPLEMENT_DYNAMIC_CLASS( wxGridWindow
, wxWindow
)
3929 BEGIN_EVENT_TABLE( wxGridWindow
, wxWindow
)
3930 EVT_PAINT( wxGridWindow::OnPaint
)
3931 EVT_MOUSEWHEEL( wxGridWindow::OnMouseWheel
)
3932 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
3933 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
3934 EVT_KEY_UP( wxGridWindow::OnKeyUp
)
3935 EVT_CHAR( wxGridWindow::OnChar
)
3936 EVT_SET_FOCUS( wxGridWindow::OnFocus
)
3937 EVT_KILL_FOCUS( wxGridWindow::OnFocus
)
3938 EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground
)
3941 wxGridWindow::wxGridWindow( wxGrid
*parent
,
3942 wxGridRowLabelWindow
*rowLblWin
,
3943 wxGridColLabelWindow
*colLblWin
,
3946 const wxSize
&size
)
3948 parent
, id
, pos
, size
,
3949 wxWANTS_CHARS
| wxBORDER_NONE
| wxCLIP_CHILDREN
| wxFULL_REPAINT_ON_RESIZE
,
3950 wxT("grid window") )
3953 m_rowLabelWin
= rowLblWin
;
3954 m_colLabelWin
= colLblWin
;
3957 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
3959 wxPaintDC
dc( this );
3960 m_owner
->PrepareDC( dc
);
3961 wxRegion reg
= GetUpdateRegion();
3962 wxGridCellCoordsArray dirtyCells
= m_owner
->CalcCellsExposed( reg
);
3963 m_owner
->DrawGridCellArea( dc
, dirtyCells
);
3965 #if WXGRID_DRAW_LINES
3966 m_owner
->DrawAllGridLines( dc
, reg
);
3969 m_owner
->DrawGridSpace( dc
);
3970 m_owner
->DrawHighlight( dc
, dirtyCells
);
3973 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
3975 wxWindow::ScrollWindow( dx
, dy
, rect
);
3976 m_rowLabelWin
->ScrollWindow( 0, dy
, rect
);
3977 m_colLabelWin
->ScrollWindow( dx
, 0, rect
);
3980 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
3982 if (event
.ButtonDown(wxMOUSE_BTN_LEFT
) && FindFocus() != this)
3985 m_owner
->ProcessGridCellMouseEvent( event
);
3988 void wxGridWindow::OnMouseWheel( wxMouseEvent
& event
)
3990 m_owner
->GetEventHandler()->ProcessEvent( event
);
3993 // This seems to be required for wxMotif/wxGTK otherwise the mouse
3994 // cursor must be in the cell edit control to get key events
3996 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
3998 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
4002 void wxGridWindow::OnKeyUp( wxKeyEvent
& event
)
4004 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
4008 void wxGridWindow::OnChar( wxKeyEvent
& event
)
4010 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
4014 void wxGridWindow::OnEraseBackground( wxEraseEvent
& WXUNUSED(event
) )
4018 void wxGridWindow::OnFocus(wxFocusEvent
& event
)
4020 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
4024 //////////////////////////////////////////////////////////////////////
4026 // Internal Helper function for computing row or column from some
4027 // (unscrolled) coordinate value, using either
4028 // m_defaultRowHeight/m_defaultColWidth or binary search on array
4029 // of m_rowBottoms/m_ColRights to speed up the search!
4031 // Internal helper macros for simpler use of that function
4033 static int CoordToRowOrCol(int coord
, int defaultDist
, int minDist
,
4034 const wxArrayInt
& BorderArray
, int nMax
,
4037 #define internalXToCol(x) XToCol(x, true)
4038 #define internalYToRow(y) CoordToRowOrCol(y, m_defaultRowHeight, \
4039 m_minAcceptableRowHeight, \
4040 m_rowBottoms, m_numRows, true)
4042 /////////////////////////////////////////////////////////////////////
4044 #if wxUSE_EXTENDED_RTTI
4045 WX_DEFINE_FLAGS( wxGridStyle
)
4047 wxBEGIN_FLAGS( wxGridStyle
)
4048 // new style border flags, we put them first to
4049 // use them for streaming out
4050 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
4051 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
4052 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
4053 wxFLAGS_MEMBER(wxBORDER_RAISED
)
4054 wxFLAGS_MEMBER(wxBORDER_STATIC
)
4055 wxFLAGS_MEMBER(wxBORDER_NONE
)
4057 // old style border flags
4058 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
4059 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
4060 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
4061 wxFLAGS_MEMBER(wxRAISED_BORDER
)
4062 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
4063 wxFLAGS_MEMBER(wxBORDER
)
4065 // standard window styles
4066 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
4067 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
4068 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
4069 wxFLAGS_MEMBER(wxWANTS_CHARS
)
4070 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
4071 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
4072 wxFLAGS_MEMBER(wxVSCROLL
)
4073 wxFLAGS_MEMBER(wxHSCROLL
)
4075 wxEND_FLAGS( wxGridStyle
)
4077 IMPLEMENT_DYNAMIC_CLASS_XTI(wxGrid
, wxScrolledWindow
,"wx/grid.h")
4079 wxBEGIN_PROPERTIES_TABLE(wxGrid
)
4080 wxHIDE_PROPERTY( Children
)
4081 wxPROPERTY_FLAGS( WindowStyle
, wxGridStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
4082 wxEND_PROPERTIES_TABLE()
4084 wxBEGIN_HANDLERS_TABLE(wxGrid
)
4085 wxEND_HANDLERS_TABLE()
4087 wxCONSTRUCTOR_5( wxGrid
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
4090 TODO : Expose more information of a list's layout, etc. via appropriate objects (e.g., NotebookPageInfo)
4093 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
4096 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
4097 EVT_PAINT( wxGrid::OnPaint
)
4098 EVT_SIZE( wxGrid::OnSize
)
4099 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
4100 EVT_KEY_UP( wxGrid::OnKeyUp
)
4101 EVT_CHAR ( wxGrid::OnChar
)
4102 EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground
)
4107 // in order to make sure that a size event is not
4108 // trigerred in a unfinished state
4109 m_cornerLabelWin
= NULL
;
4110 m_rowLabelWin
= NULL
;
4111 m_colLabelWin
= NULL
;
4115 wxGrid::wxGrid( wxWindow
*parent
,
4120 const wxString
& name
)
4121 : wxScrolledWindow( parent
, id
, pos
, size
, (style
| wxWANTS_CHARS
), name
),
4122 m_colMinWidths(GRID_HASH_SIZE
),
4123 m_rowMinHeights(GRID_HASH_SIZE
)
4126 SetBestFittingSize(size
);
4129 bool wxGrid::Create(wxWindow
*parent
, wxWindowID id
,
4130 const wxPoint
& pos
, const wxSize
& size
,
4131 long style
, const wxString
& name
)
4133 if (!wxScrolledWindow::Create(parent
, id
, pos
, size
,
4134 style
| wxWANTS_CHARS
, name
))
4137 m_colMinWidths
= wxLongToLongHashMap(GRID_HASH_SIZE
);
4138 m_rowMinHeights
= wxLongToLongHashMap(GRID_HASH_SIZE
);
4141 SetBestFittingSize(size
);
4148 // Must do this or ~wxScrollHelper will pop the wrong event handler
4149 SetTargetWindow(this);
4151 wxSafeDecRef(m_defaultCellAttr
);
4153 #ifdef DEBUG_ATTR_CACHE
4154 size_t total
= gs_nAttrCacheHits
+ gs_nAttrCacheMisses
;
4155 wxPrintf(_T("wxGrid attribute cache statistics: "
4156 "total: %u, hits: %u (%u%%)\n"),
4157 total
, gs_nAttrCacheHits
,
4158 total
? (gs_nAttrCacheHits
*100) / total
: 0);
4164 delete m_typeRegistry
;
4169 // ----- internal init and update functions
4172 // NOTE: If using the default visual attributes works everywhere then this can
4173 // be removed as well as the #else cases below.
4174 #define _USE_VISATTR 0
4176 void wxGrid::Create()
4178 // set to true by CreateGrid
4181 // create the type registry
4182 m_typeRegistry
= new wxGridTypeRegistry
;
4185 m_table
= (wxGridTableBase
*) NULL
;
4188 m_cellEditCtrlEnabled
= false;
4190 m_defaultCellAttr
= new wxGridCellAttr();
4192 // Set default cell attributes
4193 m_defaultCellAttr
->SetDefAttr(m_defaultCellAttr
);
4194 m_defaultCellAttr
->SetKind(wxGridCellAttr::Default
);
4195 m_defaultCellAttr
->SetFont(GetFont());
4196 m_defaultCellAttr
->SetAlignment(wxALIGN_LEFT
, wxALIGN_TOP
);
4197 m_defaultCellAttr
->SetRenderer(new wxGridCellStringRenderer
);
4198 m_defaultCellAttr
->SetEditor(new wxGridCellTextEditor
);
4201 wxVisualAttributes gva
= wxListBox::GetClassDefaultAttributes();
4202 wxVisualAttributes lva
= wxPanel::GetClassDefaultAttributes();
4204 m_defaultCellAttr
->SetTextColour(gva
.colFg
);
4205 m_defaultCellAttr
->SetBackgroundColour(gva
.colBg
);
4208 m_defaultCellAttr
->SetTextColour(
4209 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
4210 m_defaultCellAttr
->SetBackgroundColour(
4211 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
4216 m_currentCellCoords
= wxGridNoCellCoords
;
4218 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
4219 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
4221 // subwindow components that make up the wxGrid
4222 m_rowLabelWin
= new wxGridRowLabelWindow( this,
4227 m_colLabelWin
= new wxGridColLabelWindow( this,
4232 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
4237 m_gridWin
= new wxGridWindow( this,
4244 SetTargetWindow( m_gridWin
);
4247 wxColour gfg
= gva
.colFg
;
4248 wxColour gbg
= gva
.colBg
;
4249 wxColour lfg
= lva
.colFg
;
4250 wxColour lbg
= lva
.colBg
;
4252 wxColour gfg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
4253 wxColour gbg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
4254 wxColour lfg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
4255 wxColour lbg
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
4258 m_cornerLabelWin
->SetOwnForegroundColour(lfg
);
4259 m_cornerLabelWin
->SetOwnBackgroundColour(lbg
);
4260 m_rowLabelWin
->SetOwnForegroundColour(lfg
);
4261 m_rowLabelWin
->SetOwnBackgroundColour(lbg
);
4262 m_colLabelWin
->SetOwnForegroundColour(lfg
);
4263 m_colLabelWin
->SetOwnBackgroundColour(lbg
);
4265 m_gridWin
->SetOwnForegroundColour(gfg
);
4266 m_gridWin
->SetOwnBackgroundColour(gbg
);
4271 bool wxGrid::CreateGrid( int numRows
, int numCols
,
4272 wxGrid::wxGridSelectionModes selmode
)
4274 wxCHECK_MSG( !m_created
,
4276 wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
4278 m_numRows
= numRows
;
4279 m_numCols
= numCols
;
4281 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
4282 m_table
->SetView( this );
4284 m_selection
= new wxGridSelection( this, selmode
);
4293 void wxGrid::SetSelectionMode(wxGrid::wxGridSelectionModes selmode
)
4295 wxCHECK_RET( m_created
,
4296 wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") );
4298 m_selection
->SetSelectionMode( selmode
);
4301 wxGrid::wxGridSelectionModes
wxGrid::GetSelectionMode() const
4303 wxCHECK_MSG( m_created
, wxGrid::wxGridSelectCells
,
4304 wxT("Called wxGrid::GetSelectionMode() before calling CreateGrid()") );
4306 return m_selection
->GetSelectionMode();
4309 bool wxGrid::SetTable( wxGridTableBase
*table
, bool takeOwnership
,
4310 wxGrid::wxGridSelectionModes selmode
)
4314 // stop all processing
4319 wxGridTableBase
*t
= m_table
;
4334 m_numRows
= table
->GetNumberRows();
4335 m_numCols
= table
->GetNumberCols();
4338 m_table
->SetView( this );
4339 m_ownTable
= takeOwnership
;
4340 m_selection
= new wxGridSelection( this, selmode
);
4352 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
4353 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
4355 if ( m_rowLabelWin
)
4357 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
4361 m_labelBackgroundColour
= *wxWHITE
;
4364 m_labelTextColour
= *wxBLACK
;
4367 m_attrCache
.row
= -1;
4368 m_attrCache
.col
= -1;
4369 m_attrCache
.attr
= NULL
;
4371 // TODO: something better than this ?
4373 m_labelFont
= this->GetFont();
4374 m_labelFont
.SetWeight( wxBOLD
);
4376 m_rowLabelHorizAlign
= wxALIGN_CENTRE
;
4377 m_rowLabelVertAlign
= wxALIGN_CENTRE
;
4379 m_colLabelHorizAlign
= wxALIGN_CENTRE
;
4380 m_colLabelVertAlign
= wxALIGN_CENTRE
;
4381 m_colLabelTextOrientation
= wxHORIZONTAL
;
4383 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
4384 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
4386 m_minAcceptableColWidth
= WXGRID_MIN_COL_WIDTH
;
4387 m_minAcceptableRowHeight
= WXGRID_MIN_ROW_HEIGHT
;
4389 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
4390 m_defaultRowHeight
+= 8;
4392 m_defaultRowHeight
+= 4;
4395 m_gridLineColour
= wxColour( 192,192,192 );
4396 m_gridLinesEnabled
= true;
4397 m_cellHighlightColour
= *wxBLACK
;
4398 m_cellHighlightPenWidth
= 2;
4399 m_cellHighlightROPenWidth
= 1;
4401 m_canDragColMove
= false;
4403 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
4404 m_winCapture
= (wxWindow
*)NULL
;
4405 m_canDragRowSize
= true;
4406 m_canDragColSize
= true;
4407 m_canDragGridSize
= true;
4408 m_canDragCell
= false;
4410 m_dragRowOrCol
= -1;
4411 m_isDragging
= false;
4412 m_startDragPos
= wxDefaultPosition
;
4414 m_waitForSlowClick
= false;
4416 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
4417 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
4419 m_currentCellCoords
= wxGridNoCellCoords
;
4421 m_selectingTopLeft
= wxGridNoCellCoords
;
4422 m_selectingBottomRight
= wxGridNoCellCoords
;
4423 m_selectionBackground
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
4424 m_selectionForeground
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
4426 m_editable
= true; // default for whole grid
4428 m_inOnKeyDown
= false;
4434 m_scrollLineX
= GRID_SCROLL_LINE_X
;
4435 m_scrollLineY
= GRID_SCROLL_LINE_Y
;
4438 // ----------------------------------------------------------------------------
4439 // the idea is to call these functions only when necessary because they create
4440 // quite big arrays which eat memory mostly unnecessary - in particular, if
4441 // default widths/heights are used for all rows/columns, we may not use these
4444 // with some extra code, it should be possible to only store the
4445 // widths/heights different from default ones but this will be done later...
4446 // ----------------------------------------------------------------------------
4448 void wxGrid::InitRowHeights()
4450 m_rowHeights
.Empty();
4451 m_rowBottoms
.Empty();
4453 m_rowHeights
.Alloc( m_numRows
);
4454 m_rowBottoms
.Alloc( m_numRows
);
4458 m_rowHeights
.Add( m_defaultRowHeight
, m_numRows
);
4460 for ( int i
= 0; i
< m_numRows
; i
++ )
4462 rowBottom
+= m_defaultRowHeight
;
4463 m_rowBottoms
.Add( rowBottom
);
4467 void wxGrid::InitColWidths()
4469 m_colWidths
.Empty();
4470 m_colRights
.Empty();
4472 m_colWidths
.Alloc( m_numCols
);
4473 m_colRights
.Alloc( m_numCols
);
4476 m_colWidths
.Add( m_defaultColWidth
, m_numCols
);
4478 for ( int i
= 0; i
< m_numCols
; i
++ )
4480 colRight
= ( GetColPos( i
) + 1 ) * m_defaultColWidth
;
4481 m_colRights
.Add( colRight
);
4485 int wxGrid::GetColWidth(int col
) const
4487 return m_colWidths
.IsEmpty() ? m_defaultColWidth
: m_colWidths
[col
];
4490 int wxGrid::GetColLeft(int col
) const
4492 return m_colRights
.IsEmpty() ? GetColPos( col
) * m_defaultColWidth
4493 : m_colRights
[col
] - m_colWidths
[col
];
4496 int wxGrid::GetColRight(int col
) const
4498 return m_colRights
.IsEmpty() ? (GetColPos( col
) + 1) * m_defaultColWidth
4502 int wxGrid::GetRowHeight(int row
) const
4504 return m_rowHeights
.IsEmpty() ? m_defaultRowHeight
: m_rowHeights
[row
];
4507 int wxGrid::GetRowTop(int row
) const
4509 return m_rowBottoms
.IsEmpty() ? row
* m_defaultRowHeight
4510 : m_rowBottoms
[row
] - m_rowHeights
[row
];
4513 int wxGrid::GetRowBottom(int row
) const
4515 return m_rowBottoms
.IsEmpty() ? (row
+ 1) * m_defaultRowHeight
4516 : m_rowBottoms
[row
];
4519 void wxGrid::CalcDimensions()
4522 GetClientSize( &cw
, &ch
);
4524 if ( m_rowLabelWin
->IsShown() )
4525 cw
-= m_rowLabelWidth
;
4526 if ( m_colLabelWin
->IsShown() )
4527 ch
-= m_colLabelHeight
;
4530 int w
= m_numCols
> 0 ? GetColRight(GetColAt( m_numCols
- 1 )) + m_extraWidth
+ 1 : 0;
4531 int h
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) + m_extraHeight
+ 1 : 0;
4533 // take into account editor if shown
4534 if ( IsCellEditControlShown() )
4537 int r
= m_currentCellCoords
.GetRow();
4538 int c
= m_currentCellCoords
.GetCol();
4539 int x
= GetColLeft(c
);
4540 int y
= GetRowTop(r
);
4542 // how big is the editor
4543 wxGridCellAttr
* attr
= GetCellAttr(r
, c
);
4544 wxGridCellEditor
* editor
= attr
->GetEditor(this, r
, c
);
4545 editor
->GetControl()->GetSize(&w2
, &h2
);
4556 // preserve (more or less) the previous position
4558 GetViewStart( &x
, &y
);
4560 // ensure the position is valid for the new scroll ranges
4562 x
= wxMax( w
- 1, 0 );
4564 y
= wxMax( h
- 1, 0 );
4566 // do set scrollbar parameters
4567 SetScrollbars( m_scrollLineX
, m_scrollLineY
,
4568 GetScrollX(w
), GetScrollY(h
), x
, y
,
4569 GetBatchCount() != 0);
4571 // if our OnSize() hadn't been called (it would if we have scrollbars), we
4572 // still must reposition the children
4576 void wxGrid::CalcWindowSizes()
4578 // escape if the window is has not been fully created yet
4580 if ( m_cornerLabelWin
== NULL
)
4584 GetClientSize( &cw
, &ch
);
4586 if ( m_cornerLabelWin
&& m_cornerLabelWin
->IsShown() )
4587 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
4589 if ( m_colLabelWin
&& m_colLabelWin
->IsShown() )
4590 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
- m_rowLabelWidth
, m_colLabelHeight
);
4592 if ( m_rowLabelWin
&& m_rowLabelWin
->IsShown() )
4593 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
- m_colLabelHeight
);
4595 if ( m_gridWin
&& m_gridWin
->IsShown() )
4596 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
- m_rowLabelWidth
, ch
- m_colLabelHeight
);
4599 // this is called when the grid table sends a message
4600 // to indicate that it has been redimensioned
4602 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
4605 bool result
= false;
4607 // Clear the attribute cache as the attribute might refer to a different
4608 // cell than stored in the cache after adding/removing rows/columns.
4611 // By the same reasoning, the editor should be dismissed if columns are
4612 // added or removed. And for consistency, it should IMHO always be
4613 // removed, not only if the cell "underneath" it actually changes.
4614 // For now, I intentionally do not save the editor's content as the
4615 // cell it might want to save that stuff to might no longer exist.
4616 HideCellEditControl();
4619 // if we were using the default widths/heights so far, we must change them
4621 if ( m_colWidths
.IsEmpty() )
4626 if ( m_rowHeights
.IsEmpty() )
4632 switch ( msg
.GetId() )
4634 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
4636 size_t pos
= msg
.GetCommandInt();
4637 int numRows
= msg
.GetCommandInt2();
4639 m_numRows
+= numRows
;
4641 if ( !m_rowHeights
.IsEmpty() )
4643 m_rowHeights
.Insert( m_defaultRowHeight
, pos
, numRows
);
4644 m_rowBottoms
.Insert( 0, pos
, numRows
);
4648 bottom
= m_rowBottoms
[pos
- 1];
4650 for ( i
= pos
; i
< m_numRows
; i
++ )
4652 bottom
+= m_rowHeights
[i
];
4653 m_rowBottoms
[i
] = bottom
;
4657 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4659 // if we have just inserted cols into an empty grid the current
4660 // cell will be undefined...
4662 SetCurrentCell( 0, 0 );
4666 m_selection
->UpdateRows( pos
, numRows
);
4667 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4669 attrProvider
->UpdateAttrRows( pos
, numRows
);
4671 if ( !GetBatchCount() )
4674 m_rowLabelWin
->Refresh();
4680 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
4682 int numRows
= msg
.GetCommandInt();
4683 int oldNumRows
= m_numRows
;
4684 m_numRows
+= numRows
;
4686 if ( !m_rowHeights
.IsEmpty() )
4688 m_rowHeights
.Add( m_defaultRowHeight
, numRows
);
4689 m_rowBottoms
.Add( 0, numRows
);
4692 if ( oldNumRows
> 0 )
4693 bottom
= m_rowBottoms
[oldNumRows
- 1];
4695 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
4697 bottom
+= m_rowHeights
[i
];
4698 m_rowBottoms
[i
] = bottom
;
4702 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4704 // if we have just inserted cols into an empty grid the current
4705 // cell will be undefined...
4707 SetCurrentCell( 0, 0 );
4710 if ( !GetBatchCount() )
4713 m_rowLabelWin
->Refresh();
4719 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
4721 size_t pos
= msg
.GetCommandInt();
4722 int numRows
= msg
.GetCommandInt2();
4723 m_numRows
-= numRows
;
4725 if ( !m_rowHeights
.IsEmpty() )
4727 m_rowHeights
.RemoveAt( pos
, numRows
);
4728 m_rowBottoms
.RemoveAt( pos
, numRows
);
4731 for ( i
= 0; i
< m_numRows
; i
++ )
4733 h
+= m_rowHeights
[i
];
4734 m_rowBottoms
[i
] = h
;
4740 m_currentCellCoords
= wxGridNoCellCoords
;
4744 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
4745 m_currentCellCoords
.Set( 0, 0 );
4749 m_selection
->UpdateRows( pos
, -((int)numRows
) );
4750 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4753 attrProvider
->UpdateAttrRows( pos
, -((int)numRows
) );
4755 // ifdef'd out following patch from Paul Gammans
4757 // No need to touch column attributes, unless we
4758 // removed _all_ rows, in this case, we remove
4759 // all column attributes.
4760 // I hate to do this here, but the
4761 // needed data is not available inside UpdateAttrRows.
4762 if ( !GetNumberRows() )
4763 attrProvider
->UpdateAttrCols( 0, -GetNumberCols() );
4767 if ( !GetBatchCount() )
4770 m_rowLabelWin
->Refresh();
4776 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
4778 size_t pos
= msg
.GetCommandInt();
4779 int numCols
= msg
.GetCommandInt2();
4780 m_numCols
+= numCols
;
4782 if ( !m_colAt
.IsEmpty() )
4784 //Shift the column IDs
4786 for ( i
= 0; i
< m_numCols
- numCols
; i
++ )
4788 if ( m_colAt
[i
] >= (int)pos
)
4789 m_colAt
[i
] += numCols
;
4792 m_colAt
.Insert( pos
, pos
, numCols
);
4794 //Set the new columns' positions
4795 for ( i
= pos
+ 1; i
< (int)pos
+ numCols
; i
++ )
4801 if ( !m_colWidths
.IsEmpty() )
4803 m_colWidths
.Insert( m_defaultColWidth
, pos
, numCols
);
4804 m_colRights
.Insert( 0, pos
, numCols
);
4808 right
= m_colRights
[GetColAt( pos
- 1 )];
4811 for ( colPos
= pos
; colPos
< m_numCols
; colPos
++ )
4813 i
= GetColAt( colPos
);
4815 right
+= m_colWidths
[i
];
4816 m_colRights
[i
] = right
;
4820 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4822 // if we have just inserted cols into an empty grid the current
4823 // cell will be undefined...
4825 SetCurrentCell( 0, 0 );
4829 m_selection
->UpdateCols( pos
, numCols
);
4830 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4832 attrProvider
->UpdateAttrCols( pos
, numCols
);
4833 if ( !GetBatchCount() )
4836 m_colLabelWin
->Refresh();
4842 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
4844 int numCols
= msg
.GetCommandInt();
4845 int oldNumCols
= m_numCols
;
4846 m_numCols
+= numCols
;
4848 if ( !m_colAt
.IsEmpty() )
4850 m_colAt
.Add( 0, numCols
);
4852 //Set the new columns' positions
4854 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
4860 if ( !m_colWidths
.IsEmpty() )
4862 m_colWidths
.Add( m_defaultColWidth
, numCols
);
4863 m_colRights
.Add( 0, numCols
);
4866 if ( oldNumCols
> 0 )
4867 right
= m_colRights
[GetColAt( oldNumCols
- 1 )];
4870 for ( colPos
= oldNumCols
; colPos
< m_numCols
; colPos
++ )
4872 i
= GetColAt( colPos
);
4874 right
+= m_colWidths
[i
];
4875 m_colRights
[i
] = right
;
4879 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4881 // if we have just inserted cols into an empty grid the current
4882 // cell will be undefined...
4884 SetCurrentCell( 0, 0 );
4886 if ( !GetBatchCount() )
4889 m_colLabelWin
->Refresh();
4895 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
4897 size_t pos
= msg
.GetCommandInt();
4898 int numCols
= msg
.GetCommandInt2();
4899 m_numCols
-= numCols
;
4901 if ( !m_colAt
.IsEmpty() )
4903 int colID
= GetColAt( pos
);
4905 m_colAt
.RemoveAt( pos
, numCols
);
4907 //Shift the column IDs
4909 for ( colPos
= 0; colPos
< m_numCols
; colPos
++ )
4911 if ( m_colAt
[colPos
] > colID
)
4912 m_colAt
[colPos
] -= numCols
;
4916 if ( !m_colWidths
.IsEmpty() )
4918 m_colWidths
.RemoveAt( pos
, numCols
);
4919 m_colRights
.RemoveAt( pos
, numCols
);
4923 for ( colPos
= 0; colPos
< m_numCols
; colPos
++ )
4925 i
= GetColAt( colPos
);
4927 w
+= m_colWidths
[i
];
4934 m_currentCellCoords
= wxGridNoCellCoords
;
4938 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
4939 m_currentCellCoords
.Set( 0, 0 );
4943 m_selection
->UpdateCols( pos
, -((int)numCols
) );
4944 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4947 attrProvider
->UpdateAttrCols( pos
, -((int)numCols
) );
4949 // ifdef'd out following patch from Paul Gammans
4951 // No need to touch row attributes, unless we
4952 // removed _all_ columns, in this case, we remove
4953 // all row attributes.
4954 // I hate to do this here, but the
4955 // needed data is not available inside UpdateAttrCols.
4956 if ( !GetNumberCols() )
4957 attrProvider
->UpdateAttrRows( 0, -GetNumberRows() );
4961 if ( !GetBatchCount() )
4964 m_colLabelWin
->Refresh();
4971 if (result
&& !GetBatchCount() )
4972 m_gridWin
->Refresh();
4977 wxArrayInt
wxGrid::CalcRowLabelsExposed( const wxRegion
& reg
)
4979 wxRegionIterator
iter( reg
);
4982 wxArrayInt rowlabels
;
4989 // TODO: remove this when we can...
4990 // There is a bug in wxMotif that gives garbage update
4991 // rectangles if you jump-scroll a long way by clicking the
4992 // scrollbar with middle button. This is a work-around
4994 #if defined(__WXMOTIF__)
4996 m_gridWin
->GetClientSize( &cw
, &ch
);
4997 if ( r
.GetTop() > ch
)
4999 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
5002 // logical bounds of update region
5005 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
5006 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
5008 // find the row labels within these bounds
5011 for ( row
= internalYToRow(top
); row
< m_numRows
; row
++ )
5013 if ( GetRowBottom(row
) < top
)
5016 if ( GetRowTop(row
) > bottom
)
5019 rowlabels
.Add( row
);
5028 wxArrayInt
wxGrid::CalcColLabelsExposed( const wxRegion
& reg
)
5030 wxRegionIterator
iter( reg
);
5033 wxArrayInt colLabels
;
5040 // TODO: remove this when we can...
5041 // There is a bug in wxMotif that gives garbage update
5042 // rectangles if you jump-scroll a long way by clicking the
5043 // scrollbar with middle button. This is a work-around
5045 #if defined(__WXMOTIF__)
5047 m_gridWin
->GetClientSize( &cw
, &ch
);
5048 if ( r
.GetLeft() > cw
)
5050 r
.SetRight( wxMin( r
.GetRight(), cw
) );
5053 // logical bounds of update region
5056 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
5057 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
5059 // find the cells within these bounds
5063 for ( colPos
= GetColPos( internalXToCol(left
) ); colPos
< m_numCols
; colPos
++ )
5065 col
= GetColAt( colPos
);
5067 if ( GetColRight(col
) < left
)
5070 if ( GetColLeft(col
) > right
)
5073 colLabels
.Add( col
);
5082 wxGridCellCoordsArray
wxGrid::CalcCellsExposed( const wxRegion
& reg
)
5084 wxRegionIterator
iter( reg
);
5087 wxGridCellCoordsArray cellsExposed
;
5089 int left
, top
, right
, bottom
;
5094 // TODO: remove this when we can...
5095 // There is a bug in wxMotif that gives garbage update
5096 // rectangles if you jump-scroll a long way by clicking the
5097 // scrollbar with middle button. This is a work-around
5099 #if defined(__WXMOTIF__)
5101 m_gridWin
->GetClientSize( &cw
, &ch
);
5102 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
5103 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
5104 r
.SetRight( wxMin( r
.GetRight(), cw
) );
5105 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
5108 // logical bounds of update region
5110 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
5111 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
5113 // find the cells within these bounds
5116 for ( row
= internalYToRow(top
); row
< m_numRows
; row
++ )
5118 if ( GetRowBottom(row
) <= top
)
5121 if ( GetRowTop(row
) > bottom
)
5125 for ( colPos
= GetColPos( internalXToCol(left
) ); colPos
< m_numCols
; colPos
++ )
5127 col
= GetColAt( colPos
);
5129 if ( GetColRight(col
) <= left
)
5132 if ( GetColLeft(col
) > right
)
5135 cellsExposed
.Add( wxGridCellCoords( row
, col
) );
5142 return cellsExposed
;
5146 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
5149 wxPoint
pos( event
.GetPosition() );
5150 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
5152 if ( event
.Dragging() )
5156 m_isDragging
= true;
5157 m_rowLabelWin
->CaptureMouse();
5160 if ( event
.LeftIsDown() )
5162 switch ( m_cursorMode
)
5164 case WXGRID_CURSOR_RESIZE_ROW
:
5166 int cw
, ch
, left
, dummy
;
5167 m_gridWin
->GetClientSize( &cw
, &ch
);
5168 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
5170 wxClientDC
dc( m_gridWin
);
5173 GetRowTop(m_dragRowOrCol
) +
5174 GetRowMinimalHeight(m_dragRowOrCol
) );
5175 dc
.SetLogicalFunction(wxINVERT
);
5176 if ( m_dragLastPos
>= 0 )
5178 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
5180 dc
.DrawLine( left
, y
, left
+cw
, y
);
5185 case WXGRID_CURSOR_SELECT_ROW
:
5187 if ( (row
= YToRow( y
)) >= 0 )
5191 m_selection
->SelectRow( row
,
5192 event
.ControlDown(),
5201 // default label to suppress warnings about "enumeration value
5202 // 'xxx' not handled in switch
5210 if ( m_isDragging
&& (event
.Entering() || event
.Leaving()) )
5215 if (m_rowLabelWin
->HasCapture())
5216 m_rowLabelWin
->ReleaseMouse();
5217 m_isDragging
= false;
5220 // ------------ Entering or leaving the window
5222 if ( event
.Entering() || event
.Leaving() )
5224 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
5227 // ------------ Left button pressed
5229 else if ( event
.LeftDown() )
5231 // don't send a label click event for a hit on the
5232 // edge of the row label - this is probably the user
5233 // wanting to resize the row
5235 if ( YToEdgeOfRow(y
) < 0 )
5239 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
5241 if ( !event
.ShiftDown() && !event
.CmdDown() )
5245 if ( event
.ShiftDown() )
5247 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
5250 GetNumberCols() - 1,
5251 event
.ControlDown(),
5258 m_selection
->SelectRow( row
,
5259 event
.ControlDown(),
5266 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW
, m_rowLabelWin
);
5271 // starting to drag-resize a row
5272 if ( CanDragRowSize() )
5273 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
);
5277 // ------------ Left double click
5279 else if (event
.LeftDClick() )
5281 row
= YToEdgeOfRow(y
);
5286 !SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
) )
5288 // no default action at the moment
5293 // adjust row height depending on label text
5294 AutoSizeRowLabelSize( row
);
5296 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
5301 // ------------ Left button released
5303 else if ( event
.LeftUp() )
5305 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
5307 DoEndDragResizeRow();
5309 // Note: we are ending the event *after* doing
5310 // default processing in this case
5312 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
5315 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
5319 // ------------ Right button down
5321 else if ( event
.RightDown() )
5325 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
5327 // no default action at the moment
5331 // ------------ Right double click
5333 else if ( event
.RightDClick() )
5337 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
5339 // no default action at the moment
5343 // ------------ No buttons down and mouse moving
5345 else if ( event
.Moving() )
5347 m_dragRowOrCol
= YToEdgeOfRow( y
);
5348 if ( m_dragRowOrCol
>= 0 )
5350 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5352 // don't capture the mouse yet
5353 if ( CanDragRowSize() )
5354 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
, false);
5357 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
5359 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
, false);
5364 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
5367 wxPoint
pos( event
.GetPosition() );
5368 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
5370 if ( event
.Dragging() )
5374 m_isDragging
= true;
5375 m_colLabelWin
->CaptureMouse();
5377 if ( m_cursorMode
== WXGRID_CURSOR_MOVE_COL
)
5378 m_dragRowOrCol
= XToCol( x
);
5381 if ( event
.LeftIsDown() )
5383 switch ( m_cursorMode
)
5385 case WXGRID_CURSOR_RESIZE_COL
:
5387 int cw
, ch
, dummy
, top
;
5388 m_gridWin
->GetClientSize( &cw
, &ch
);
5389 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
5391 wxClientDC
dc( m_gridWin
);
5394 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
5395 GetColMinimalWidth(m_dragRowOrCol
));
5396 dc
.SetLogicalFunction(wxINVERT
);
5397 if ( m_dragLastPos
>= 0 )
5399 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ ch
);
5401 dc
.DrawLine( x
, top
, x
, top
+ ch
);
5406 case WXGRID_CURSOR_SELECT_COL
:
5408 if ( (col
= XToCol( x
)) >= 0 )
5412 m_selection
->SelectCol( col
,
5413 event
.ControlDown(),
5422 case WXGRID_CURSOR_MOVE_COL
:
5425 m_moveToCol
= GetColAt( 0 );
5427 m_moveToCol
= XToCol( x
);
5431 if ( m_moveToCol
< 0 )
5432 markerX
= GetColRight( GetColAt( m_numCols
- 1 ) );
5434 markerX
= GetColLeft( m_moveToCol
);
5436 if ( markerX
!= m_dragLastPos
)
5438 wxClientDC
dc( m_colLabelWin
);
5441 m_colLabelWin
->GetClientSize( &cw
, &ch
);
5445 //Clean up the last indicator
5446 if ( m_dragLastPos
>= 0 )
5448 wxPen
pen( m_colLabelWin
->GetBackgroundColour(), 2 );
5450 dc
.DrawLine( m_dragLastPos
+ 1, 0, m_dragLastPos
+ 1, ch
);
5451 dc
.SetPen(wxNullPen
);
5453 if ( XToCol( m_dragLastPos
) != -1 )
5454 DrawColLabel( dc
, XToCol( m_dragLastPos
) );
5457 //Moving to the same place? Don't draw a marker
5458 if ( (m_moveToCol
== m_dragRowOrCol
)
5459 || (GetColPos( m_moveToCol
) == GetColPos( m_dragRowOrCol
) + 1)
5460 || (m_moveToCol
< 0 && m_dragRowOrCol
== GetColAt( m_numCols
- 1 )))
5467 wxPen
pen( *wxBLUE
, 2 );
5470 dc
.DrawLine( markerX
, 0, markerX
, ch
);
5472 dc
.SetPen(wxNullPen
);
5474 m_dragLastPos
= markerX
- 1;
5479 // default label to suppress warnings about "enumeration value
5480 // 'xxx' not handled in switch
5488 if ( m_isDragging
&& (event
.Entering() || event
.Leaving()) )
5493 if (m_colLabelWin
->HasCapture())
5494 m_colLabelWin
->ReleaseMouse();
5495 m_isDragging
= false;
5498 // ------------ Entering or leaving the window
5500 if ( event
.Entering() || event
.Leaving() )
5502 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
5505 // ------------ Left button pressed
5507 else if ( event
.LeftDown() )
5509 // don't send a label click event for a hit on the
5510 // edge of the col label - this is probably the user
5511 // wanting to resize the col
5513 if ( XToEdgeOfCol(x
) < 0 )
5517 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
5519 if ( m_canDragColMove
)
5521 //Show button as pressed
5522 wxClientDC
dc( m_colLabelWin
);
5523 int colLeft
= GetColLeft( col
);
5524 int colRight
= GetColRight( col
) - 1;
5525 dc
.SetPen( wxPen( m_colLabelWin
->GetBackgroundColour(), 1 ) );
5526 dc
.DrawLine( colLeft
, 1, colLeft
, m_colLabelHeight
-1 );
5527 dc
.DrawLine( colLeft
, 1, colRight
, 1 );
5529 ChangeCursorMode(WXGRID_CURSOR_MOVE_COL
, m_colLabelWin
);
5533 if ( !event
.ShiftDown() && !event
.CmdDown() )
5537 if ( event
.ShiftDown() )
5539 m_selection
->SelectBlock( 0,
5540 m_currentCellCoords
.GetCol(),
5541 GetNumberRows() - 1, col
,
5542 event
.ControlDown(),
5549 m_selection
->SelectCol( col
,
5550 event
.ControlDown(),
5557 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL
, m_colLabelWin
);
5563 // starting to drag-resize a col
5565 if ( CanDragColSize() )
5566 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
);
5570 // ------------ Left double click
5572 if ( event
.LeftDClick() )
5574 col
= XToEdgeOfCol(x
);
5579 ! SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
) )
5581 // no default action at the moment
5586 // adjust column width depending on label text
5587 AutoSizeColLabelSize( col
);
5589 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
5594 // ------------ Left button released
5596 else if ( event
.LeftUp() )
5598 switch ( m_cursorMode
)
5600 case WXGRID_CURSOR_RESIZE_COL
:
5602 DoEndDragResizeCol();
5604 // Note: we are ending the event *after* doing
5605 // default processing in this case
5607 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
5611 case WXGRID_CURSOR_MOVE_COL
:
5615 SendEvent( wxEVT_GRID_COL_MOVE
, -1, m_dragRowOrCol
, event
);
5620 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
5624 // ------------ Right button down
5626 else if ( event
.RightDown() )
5630 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
5632 // no default action at the moment
5636 // ------------ Right double click
5638 else if ( event
.RightDClick() )
5642 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
5644 // no default action at the moment
5648 // ------------ No buttons down and mouse moving
5650 else if ( event
.Moving() )
5652 m_dragRowOrCol
= XToEdgeOfCol( x
);
5653 if ( m_dragRowOrCol
>= 0 )
5655 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5657 // don't capture the cursor yet
5658 if ( CanDragColSize() )
5659 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
, false);
5662 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
5664 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
, false);
5669 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
5671 if ( event
.LeftDown() )
5673 // indicate corner label by having both row and
5676 if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
5681 else if ( event
.LeftDClick() )
5683 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
5685 else if ( event
.RightDown() )
5687 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
5689 // no default action at the moment
5692 else if ( event
.RightDClick() )
5694 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
5696 // no default action at the moment
5701 void wxGrid::ChangeCursorMode(CursorMode mode
,
5706 static const wxChar
*cursorModes
[] =
5716 wxLogTrace(_T("grid"),
5717 _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
5718 win
== m_colLabelWin
? _T("colLabelWin")
5719 : win
? _T("rowLabelWin")
5721 cursorModes
[m_cursorMode
], cursorModes
[mode
]);
5724 if ( mode
== m_cursorMode
&&
5725 win
== m_winCapture
&&
5726 captureMouse
== (m_winCapture
!= NULL
))
5731 // by default use the grid itself
5737 if (m_winCapture
->HasCapture())
5738 m_winCapture
->ReleaseMouse();
5739 m_winCapture
= (wxWindow
*)NULL
;
5742 m_cursorMode
= mode
;
5744 switch ( m_cursorMode
)
5746 case WXGRID_CURSOR_RESIZE_ROW
:
5747 win
->SetCursor( m_rowResizeCursor
);
5750 case WXGRID_CURSOR_RESIZE_COL
:
5751 win
->SetCursor( m_colResizeCursor
);
5754 case WXGRID_CURSOR_MOVE_COL
:
5755 win
->SetCursor( wxCursor(wxCURSOR_HAND
) );
5759 win
->SetCursor( *wxSTANDARD_CURSOR
);
5763 // we need to capture mouse when resizing
5764 bool resize
= m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
||
5765 m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
;
5767 if ( captureMouse
&& resize
)
5769 win
->CaptureMouse();
5774 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
5777 wxPoint
pos( event
.GetPosition() );
5778 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
5780 wxGridCellCoords coords
;
5781 XYToCell( x
, y
, coords
);
5783 int cell_rows
, cell_cols
;
5784 bool isFirstDrag
= !m_isDragging
;
5785 GetCellSize( coords
.GetRow(), coords
.GetCol(), &cell_rows
, &cell_cols
);
5786 if ((cell_rows
< 0) || (cell_cols
< 0))
5788 coords
.SetRow(coords
.GetRow() + cell_rows
);
5789 coords
.SetCol(coords
.GetCol() + cell_cols
);
5792 if ( event
.Dragging() )
5794 //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
5796 // Don't start doing anything until the mouse has been dragged at
5797 // least 3 pixels in any direction...
5800 if (m_startDragPos
== wxDefaultPosition
)
5802 m_startDragPos
= pos
;
5805 if (abs(m_startDragPos
.x
- pos
.x
) < 4 && abs(m_startDragPos
.y
- pos
.y
) < 4)
5809 m_isDragging
= true;
5810 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5812 // Hide the edit control, so it
5813 // won't interfere with drag-shrinking.
5814 if ( IsCellEditControlShown() )
5816 HideCellEditControl();
5817 SaveEditControlValue();
5820 // Have we captured the mouse yet?
5823 m_winCapture
= m_gridWin
;
5824 m_winCapture
->CaptureMouse();
5827 if ( coords
!= wxGridNoCellCoords
)
5829 if ( event
.CmdDown() )
5831 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
5832 m_selectingKeyboard
= coords
;
5833 HighlightBlock( m_selectingKeyboard
, coords
);
5835 else if ( CanDragCell() )
5839 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
5840 m_selectingKeyboard
= coords
;
5842 SendEvent( wxEVT_GRID_CELL_BEGIN_DRAG
,
5850 if ( !IsSelection() )
5852 HighlightBlock( coords
, coords
);
5856 HighlightBlock( m_currentCellCoords
, coords
);
5860 if (! IsVisible(coords
))
5862 MakeCellVisible(coords
);
5863 // TODO: need to introduce a delay or something here. The
5864 // scrolling is way to fast, at least on MSW - also on GTK.
5868 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
5870 int cw
, ch
, left
, dummy
;
5871 m_gridWin
->GetClientSize( &cw
, &ch
);
5872 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
5874 wxClientDC
dc( m_gridWin
);
5876 y
= wxMax( y
, GetRowTop(m_dragRowOrCol
) +
5877 GetRowMinimalHeight(m_dragRowOrCol
) );
5878 dc
.SetLogicalFunction(wxINVERT
);
5879 if ( m_dragLastPos
>= 0 )
5881 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
5883 dc
.DrawLine( left
, y
, left
+cw
, y
);
5886 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
5888 int cw
, ch
, dummy
, top
;
5889 m_gridWin
->GetClientSize( &cw
, &ch
);
5890 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
5892 wxClientDC
dc( m_gridWin
);
5894 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
5895 GetColMinimalWidth(m_dragRowOrCol
) );
5896 dc
.SetLogicalFunction(wxINVERT
);
5897 if ( m_dragLastPos
>= 0 )
5899 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ ch
);
5901 dc
.DrawLine( x
, top
, x
, top
+ ch
);
5908 m_isDragging
= false;
5909 m_startDragPos
= wxDefaultPosition
;
5911 // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
5912 // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
5915 if ( event
.Entering() || event
.Leaving() )
5917 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5918 m_gridWin
->SetCursor( *wxSTANDARD_CURSOR
);
5923 // ------------ Left button pressed
5925 if ( event
.LeftDown() && coords
!= wxGridNoCellCoords
)
5927 if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK
,
5932 if ( !event
.CmdDown() )
5934 if ( event
.ShiftDown() )
5938 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
5939 m_currentCellCoords
.GetCol(),
5942 event
.ControlDown(),
5948 else if ( XToEdgeOfCol(x
) < 0 &&
5949 YToEdgeOfRow(y
) < 0 )
5951 DisableCellEditControl();
5952 MakeCellVisible( coords
);
5954 if ( event
.CmdDown() )
5958 m_selection
->ToggleCellSelection( coords
.GetRow(),
5960 event
.ControlDown(),
5965 m_selectingTopLeft
= wxGridNoCellCoords
;
5966 m_selectingBottomRight
= wxGridNoCellCoords
;
5967 m_selectingKeyboard
= coords
;
5971 m_waitForSlowClick
= m_currentCellCoords
== coords
&& coords
!= wxGridNoCellCoords
;
5972 SetCurrentCell( coords
);
5975 if ( m_selection
->GetSelectionMode() !=
5976 wxGrid::wxGridSelectCells
)
5978 HighlightBlock( coords
, coords
);
5986 // ------------ Left double click
5988 else if ( event
.LeftDClick() && coords
!= wxGridNoCellCoords
)
5990 DisableCellEditControl();
5992 if ( XToEdgeOfCol(x
) < 0 && YToEdgeOfRow(y
) < 0 )
5994 if ( !SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK
,
5999 // we want double click to select a cell and start editing
6000 // (i.e. to behave in same way as sequence of two slow clicks):
6001 m_waitForSlowClick
= true;
6006 // ------------ Left button released
6008 else if ( event
.LeftUp() )
6010 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
6014 if (m_winCapture
->HasCapture())
6015 m_winCapture
->ReleaseMouse();
6016 m_winCapture
= NULL
;
6019 if ( coords
== m_currentCellCoords
&& m_waitForSlowClick
&& CanEnableCellControl() )
6022 EnableCellEditControl();
6024 wxGridCellAttr
*attr
= GetCellAttr(coords
);
6025 wxGridCellEditor
*editor
= attr
->GetEditor(this, coords
.GetRow(), coords
.GetCol());
6026 editor
->StartingClick();
6030 m_waitForSlowClick
= false;
6032 else if ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
6033 m_selectingBottomRight
!= wxGridNoCellCoords
)
6037 m_selection
->SelectBlock( m_selectingTopLeft
.GetRow(),
6038 m_selectingTopLeft
.GetCol(),
6039 m_selectingBottomRight
.GetRow(),
6040 m_selectingBottomRight
.GetCol(),
6041 event
.ControlDown(),
6047 m_selectingTopLeft
= wxGridNoCellCoords
;
6048 m_selectingBottomRight
= wxGridNoCellCoords
;
6050 // Show the edit control, if it has been hidden for
6052 ShowCellEditControl();
6055 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
6057 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
6058 DoEndDragResizeRow();
6060 // Note: we are ending the event *after* doing
6061 // default processing in this case
6063 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
6065 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
6067 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
6068 DoEndDragResizeCol();
6070 // Note: we are ending the event *after* doing
6071 // default processing in this case
6073 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
6079 // ------------ Right button down
6081 else if ( event
.RightDown() && coords
!= wxGridNoCellCoords
)
6083 DisableCellEditControl();
6084 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK
,
6089 // no default action at the moment
6093 // ------------ Right double click
6095 else if ( event
.RightDClick() && coords
!= wxGridNoCellCoords
)
6097 DisableCellEditControl();
6098 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK
,
6103 // no default action at the moment
6107 // ------------ Moving and no button action
6109 else if ( event
.Moving() && !event
.IsButton() )
6111 if ( coords
.GetRow() < 0 || coords
.GetCol() < 0 )
6113 // out of grid cell area
6114 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
6118 int dragRow
= YToEdgeOfRow( y
);
6119 int dragCol
= XToEdgeOfCol( x
);
6121 // Dragging on the corner of a cell to resize in both
6122 // directions is not implemented yet...
6124 if ( dragRow
>= 0 && dragCol
>= 0 )
6126 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
6132 m_dragRowOrCol
= dragRow
;
6134 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
6136 if ( CanDragRowSize() && CanDragGridSize() )
6137 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
);
6140 else if ( dragCol
>= 0 )
6142 m_dragRowOrCol
= dragCol
;
6144 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
6146 if ( CanDragColSize() && CanDragGridSize() )
6147 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
);
6150 else // Neither on a row or col edge
6152 if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
6154 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
6160 void wxGrid::DoEndDragResizeRow()
6162 if ( m_dragLastPos
>= 0 )
6164 // erase the last line and resize the row
6166 int cw
, ch
, left
, dummy
;
6167 m_gridWin
->GetClientSize( &cw
, &ch
);
6168 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
6170 wxClientDC
dc( m_gridWin
);
6172 dc
.SetLogicalFunction( wxINVERT
);
6173 dc
.DrawLine( left
, m_dragLastPos
, left
+ cw
, m_dragLastPos
);
6174 HideCellEditControl();
6175 SaveEditControlValue();
6177 int rowTop
= GetRowTop(m_dragRowOrCol
);
6178 SetRowSize( m_dragRowOrCol
,
6179 wxMax( m_dragLastPos
- rowTop
, m_minAcceptableRowHeight
) );
6181 if ( !GetBatchCount() )
6183 // Only needed to get the correct rect.y:
6184 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
6186 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
6187 rect
.width
= m_rowLabelWidth
;
6188 rect
.height
= ch
- rect
.y
;
6189 m_rowLabelWin
->Refresh( true, &rect
);
6192 // if there is a multicell block, paint all of it
6195 int i
, cell_rows
, cell_cols
, subtract_rows
= 0;
6196 int leftCol
= XToCol(left
);
6197 int rightCol
= internalXToCol(left
+ cw
);
6200 for (i
=leftCol
; i
<rightCol
; i
++)
6202 GetCellSize(m_dragRowOrCol
, i
, &cell_rows
, &cell_cols
);
6203 if (cell_rows
< subtract_rows
)
6204 subtract_rows
= cell_rows
;
6206 rect
.y
= GetRowTop(m_dragRowOrCol
+ subtract_rows
);
6207 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
6208 rect
.height
= ch
- rect
.y
;
6211 m_gridWin
->Refresh( false, &rect
);
6214 ShowCellEditControl();
6219 void wxGrid::DoEndDragResizeCol()
6221 if ( m_dragLastPos
>= 0 )
6223 // erase the last line and resize the col
6225 int cw
, ch
, dummy
, top
;
6226 m_gridWin
->GetClientSize( &cw
, &ch
);
6227 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
6229 wxClientDC
dc( m_gridWin
);
6231 dc
.SetLogicalFunction( wxINVERT
);
6232 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ ch
);
6233 HideCellEditControl();
6234 SaveEditControlValue();
6236 int colLeft
= GetColLeft(m_dragRowOrCol
);
6237 SetColSize( m_dragRowOrCol
,
6238 wxMax( m_dragLastPos
- colLeft
,
6239 GetColMinimalWidth(m_dragRowOrCol
) ) );
6241 if ( !GetBatchCount() )
6243 // Only needed to get the correct rect.x:
6244 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
6246 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
6247 rect
.width
= cw
- rect
.x
;
6248 rect
.height
= m_colLabelHeight
;
6249 m_colLabelWin
->Refresh( true, &rect
);
6252 // if there is a multicell block, paint all of it
6255 int i
, cell_rows
, cell_cols
, subtract_cols
= 0;
6256 int topRow
= YToRow(top
);
6257 int bottomRow
= internalYToRow(top
+ cw
);
6260 for (i
=topRow
; i
<bottomRow
; i
++)
6262 GetCellSize(i
, m_dragRowOrCol
, &cell_rows
, &cell_cols
);
6263 if (cell_cols
< subtract_cols
)
6264 subtract_cols
= cell_cols
;
6267 rect
.x
= GetColLeft(m_dragRowOrCol
+ subtract_cols
);
6268 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
6269 rect
.width
= cw
- rect
.x
;
6273 m_gridWin
->Refresh( false, &rect
);
6276 ShowCellEditControl();
6280 void wxGrid::DoEndDragMoveCol()
6282 //The user clicked on the column but didn't actually drag
6283 if ( m_dragLastPos
< 0 )
6285 m_colLabelWin
->Refresh(); //Do this to "unpress" the column
6290 if ( m_moveToCol
== -1 )
6291 newPos
= m_numCols
- 1;
6294 newPos
= GetColPos( m_moveToCol
);
6295 if ( newPos
> GetColPos( m_dragRowOrCol
) )
6299 SetColPos( m_dragRowOrCol
, newPos
);
6302 void wxGrid::SetColPos( int colID
, int newPos
)
6304 if ( m_colAt
.IsEmpty() )
6306 m_colAt
.Alloc( m_numCols
);
6309 for ( i
= 0; i
< m_numCols
; i
++ )
6315 int oldPos
= GetColPos( colID
);
6317 //Reshuffle the m_colAt array
6318 if ( newPos
> oldPos
)
6321 for ( i
= oldPos
; i
< newPos
; i
++ )
6323 m_colAt
[i
] = m_colAt
[i
+1];
6329 for ( i
= oldPos
; i
> newPos
; i
-- )
6331 m_colAt
[i
] = m_colAt
[i
-1];
6335 m_colAt
[newPos
] = colID
;
6337 //Recalculate the column rights
6338 if ( !m_colWidths
.IsEmpty() )
6342 for ( colPos
= 0; colPos
< m_numCols
; colPos
++ )
6344 int colID
= GetColAt( colPos
);
6346 colRight
+= m_colWidths
[colID
];
6347 m_colRights
[colID
] = colRight
;
6351 m_colLabelWin
->Refresh();
6352 m_gridWin
->Refresh();
6357 void wxGrid::EnableDragColMove( bool enable
)
6359 if ( m_canDragColMove
== enable
)
6362 m_canDragColMove
= enable
;
6364 if ( !m_canDragColMove
)
6368 //Recalculate the column rights
6369 if ( !m_colWidths
.IsEmpty() )
6373 for ( colPos
= 0; colPos
< m_numCols
; colPos
++ )
6375 colRight
+= m_colWidths
[colPos
];
6376 m_colRights
[colPos
] = colRight
;
6380 m_colLabelWin
->Refresh();
6381 m_gridWin
->Refresh();
6387 // ------ interaction with data model
6389 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
6391 switch ( msg
.GetId() )
6393 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
6394 return GetModelValues();
6396 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
6397 return SetModelValues();
6399 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
6400 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
6401 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
6402 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
6403 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
6404 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
6405 return Redimension( msg
);
6412 // The behaviour of this function depends on the grid table class
6413 // Clear() function. For the default wxGridStringTable class the
6414 // behavious is to replace all cell contents with wxEmptyString but
6415 // not to change the number of rows or cols.
6417 void wxGrid::ClearGrid()
6421 if (IsCellEditControlEnabled())
6422 DisableCellEditControl();
6425 if (!GetBatchCount())
6426 m_gridWin
->Refresh();
6430 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
6432 // TODO: something with updateLabels flag
6436 wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
6442 if (IsCellEditControlEnabled())
6443 DisableCellEditControl();
6445 bool done
= m_table
->InsertRows( pos
, numRows
);
6448 // the table will have sent the results of the insert row
6449 // operation to this view object as a grid table message
6455 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
6457 // TODO: something with updateLabels flag
6461 wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
6467 bool done
= m_table
&& m_table
->AppendRows( numRows
);
6470 // the table will have sent the results of the append row
6471 // operation to this view object as a grid table message
6477 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
6479 // TODO: something with updateLabels flag
6483 wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
6489 if (IsCellEditControlEnabled())
6490 DisableCellEditControl();
6492 bool done
= m_table
->DeleteRows( pos
, numRows
);
6494 // the table will have sent the results of the delete row
6495 // operation to this view object as a grid table message
6501 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
6503 // TODO: something with updateLabels flag
6507 wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
6513 if (IsCellEditControlEnabled())
6514 DisableCellEditControl();
6516 bool done
= m_table
->InsertCols( pos
, numCols
);
6518 // the table will have sent the results of the insert col
6519 // operation to this view object as a grid table message
6525 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
6527 // TODO: something with updateLabels flag
6531 wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
6537 bool done
= m_table
->AppendCols( numCols
);
6539 // the table will have sent the results of the append col
6540 // operation to this view object as a grid table message
6546 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
6548 // TODO: something with updateLabels flag
6552 wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
6558 if (IsCellEditControlEnabled())
6559 DisableCellEditControl();
6561 bool done
= m_table
->DeleteCols( pos
, numCols
);
6563 // the table will have sent the results of the delete col
6564 // operation to this view object as a grid table message
6571 // ----- event handlers
6574 // Generate a grid event based on a mouse event and
6575 // return the result of ProcessEvent()
6577 int wxGrid::SendEvent( const wxEventType type
,
6579 wxMouseEvent
& mouseEv
)
6581 bool claimed
, vetoed
;
6583 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
6585 int rowOrCol
= (row
== -1 ? col
: row
);
6587 wxGridSizeEvent
gridEvt( GetId(),
6591 mouseEv
.GetX() + GetRowLabelSize(),
6592 mouseEv
.GetY() + GetColLabelSize(),
6593 mouseEv
.ControlDown(),
6594 mouseEv
.ShiftDown(),
6596 mouseEv
.MetaDown() );
6598 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
6599 vetoed
= !gridEvt
.IsAllowed();
6601 else if ( type
== wxEVT_GRID_RANGE_SELECT
)
6603 // Right now, it should _never_ end up here!
6604 wxGridRangeSelectEvent
gridEvt( GetId(),
6608 m_selectingBottomRight
,
6610 mouseEv
.ControlDown(),
6611 mouseEv
.ShiftDown(),
6613 mouseEv
.MetaDown() );
6615 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
6616 vetoed
= !gridEvt
.IsAllowed();
6620 wxGridEvent
gridEvt( GetId(),
6624 mouseEv
.GetX() + GetRowLabelSize(),
6625 mouseEv
.GetY() + GetColLabelSize(),
6627 mouseEv
.ControlDown(),
6628 mouseEv
.ShiftDown(),
6630 mouseEv
.MetaDown() );
6631 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
6632 vetoed
= !gridEvt
.IsAllowed();
6635 // A Veto'd event may not be `claimed' so test this first
6639 return claimed
? 1 : 0;
6642 // Generate a grid event of specified type and return the result
6643 // of ProcessEvent().
6645 int wxGrid::SendEvent( const wxEventType type
,
6648 bool claimed
, vetoed
;
6650 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
6652 int rowOrCol
= (row
== -1 ? col
: row
);
6654 wxGridSizeEvent
gridEvt( GetId(), type
, this, rowOrCol
);
6656 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
6657 vetoed
= !gridEvt
.IsAllowed();
6661 wxGridEvent
gridEvt( GetId(), type
, this, row
, col
);
6663 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
6664 vetoed
= !gridEvt
.IsAllowed();
6667 // A Veto'd event may not be `claimed' so test this first
6671 return claimed
? 1 : 0;
6674 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
6676 // needed to prevent zillions of paint events on MSW
6680 void wxGrid::Refresh(bool eraseb
, const wxRect
* rect
)
6682 // Don't do anything if between Begin/EndBatch...
6683 // EndBatch() will do all this on the last nested one anyway.
6684 if (! GetBatchCount())
6686 // Refresh to get correct scrolled position:
6687 wxScrolledWindow::Refresh(eraseb
, rect
);
6691 int rect_x
, rect_y
, rectWidth
, rectHeight
;
6692 int width_label
, width_cell
, height_label
, height_cell
;
6695 // Copy rectangle can get scroll offsets..
6696 rect_x
= rect
->GetX();
6697 rect_y
= rect
->GetY();
6698 rectWidth
= rect
->GetWidth();
6699 rectHeight
= rect
->GetHeight();
6701 width_label
= m_rowLabelWidth
- rect_x
;
6702 if (width_label
> rectWidth
)
6703 width_label
= rectWidth
;
6705 height_label
= m_colLabelHeight
- rect_y
;
6706 if (height_label
> rectHeight
)
6707 height_label
= rectHeight
;
6709 if (rect_x
> m_rowLabelWidth
)
6711 x
= rect_x
- m_rowLabelWidth
;
6712 width_cell
= rectWidth
;
6717 width_cell
= rectWidth
- (m_rowLabelWidth
- rect_x
);
6720 if (rect_y
> m_colLabelHeight
)
6722 y
= rect_y
- m_colLabelHeight
;
6723 height_cell
= rectHeight
;
6728 height_cell
= rectHeight
- (m_colLabelHeight
- rect_y
);
6731 // Paint corner label part intersecting rect.
6732 if ( width_label
> 0 && height_label
> 0 )
6734 wxRect
anotherrect(rect_x
, rect_y
, width_label
, height_label
);
6735 m_cornerLabelWin
->Refresh(eraseb
, &anotherrect
);
6738 // Paint col labels part intersecting rect.
6739 if ( width_cell
> 0 && height_label
> 0 )
6741 wxRect
anotherrect(x
, rect_y
, width_cell
, height_label
);
6742 m_colLabelWin
->Refresh(eraseb
, &anotherrect
);
6745 // Paint row labels part intersecting rect.
6746 if ( width_label
> 0 && height_cell
> 0 )
6748 wxRect
anotherrect(rect_x
, y
, width_label
, height_cell
);
6749 m_rowLabelWin
->Refresh(eraseb
, &anotherrect
);
6752 // Paint cell area part intersecting rect.
6753 if ( width_cell
> 0 && height_cell
> 0 )
6755 wxRect
anotherrect(x
, y
, width_cell
, height_cell
);
6756 m_gridWin
->Refresh(eraseb
, &anotherrect
);
6761 m_cornerLabelWin
->Refresh(eraseb
, NULL
);
6762 m_colLabelWin
->Refresh(eraseb
, NULL
);
6763 m_rowLabelWin
->Refresh(eraseb
, NULL
);
6764 m_gridWin
->Refresh(eraseb
, NULL
);
6769 void wxGrid::OnSize( wxSizeEvent
& event
)
6771 // position the child windows
6774 // don't call CalcDimensions() from here, the base class handles the size
6779 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
6781 if ( m_inOnKeyDown
)
6783 // shouldn't be here - we are going round in circles...
6785 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") );
6788 m_inOnKeyDown
= true;
6790 // propagate the event up and see if it gets processed
6791 wxWindow
*parent
= GetParent();
6792 wxKeyEvent
keyEvt( event
);
6793 keyEvt
.SetEventObject( parent
);
6795 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
6797 // try local handlers
6798 switch ( event
.GetKeyCode() )
6801 if ( event
.ControlDown() )
6802 MoveCursorUpBlock( event
.ShiftDown() );
6804 MoveCursorUp( event
.ShiftDown() );
6808 if ( event
.ControlDown() )
6809 MoveCursorDownBlock( event
.ShiftDown() );
6811 MoveCursorDown( event
.ShiftDown() );
6815 if ( event
.ControlDown() )
6816 MoveCursorLeftBlock( event
.ShiftDown() );
6818 MoveCursorLeft( event
.ShiftDown() );
6822 if ( event
.ControlDown() )
6823 MoveCursorRightBlock( event
.ShiftDown() );
6825 MoveCursorRight( event
.ShiftDown() );
6829 case WXK_NUMPAD_ENTER
:
6830 if ( event
.ControlDown() )
6832 event
.Skip(); // to let the edit control have the return
6836 if ( GetGridCursorRow() < GetNumberRows()-1 )
6838 MoveCursorDown( event
.ShiftDown() );
6842 // at the bottom of a column
6843 DisableCellEditControl();
6853 if (event
.ShiftDown())
6855 if ( GetGridCursorCol() > 0 )
6857 MoveCursorLeft( false );
6862 DisableCellEditControl();
6867 if ( GetGridCursorCol() < GetNumberCols() - 1 )
6869 MoveCursorRight( false );
6874 DisableCellEditControl();
6880 if ( event
.ControlDown() )
6882 MakeCellVisible( 0, 0 );
6883 SetCurrentCell( 0, 0 );
6892 if ( event
.ControlDown() )
6894 MakeCellVisible( m_numRows
- 1, m_numCols
- 1 );
6895 SetCurrentCell( m_numRows
- 1, m_numCols
- 1 );
6912 if ( event
.ControlDown() )
6916 m_selection
->ToggleCellSelection(
6917 m_currentCellCoords
.GetRow(),
6918 m_currentCellCoords
.GetCol(),
6919 event
.ControlDown(),
6927 if ( !IsEditable() )
6928 MoveCursorRight( false );
6939 m_inOnKeyDown
= false;
6942 void wxGrid::OnKeyUp( wxKeyEvent
& event
)
6944 // try local handlers
6946 if ( event
.GetKeyCode() == WXK_SHIFT
)
6948 if ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
6949 m_selectingBottomRight
!= wxGridNoCellCoords
)
6953 m_selection
->SelectBlock(
6954 m_selectingTopLeft
.GetRow(),
6955 m_selectingTopLeft
.GetCol(),
6956 m_selectingBottomRight
.GetRow(),
6957 m_selectingBottomRight
.GetCol(),
6958 event
.ControlDown(),
6965 m_selectingTopLeft
= wxGridNoCellCoords
;
6966 m_selectingBottomRight
= wxGridNoCellCoords
;
6967 m_selectingKeyboard
= wxGridNoCellCoords
;
6971 void wxGrid::OnChar( wxKeyEvent
& event
)
6973 // is it possible to edit the current cell at all?
6974 if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
6976 // yes, now check whether the cells editor accepts the key
6977 int row
= m_currentCellCoords
.GetRow();
6978 int col
= m_currentCellCoords
.GetCol();
6979 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
6980 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
6982 // <F2> is special and will always start editing, for
6983 // other keys - ask the editor itself
6984 if ( (event
.GetKeyCode() == WXK_F2
&& !event
.HasModifiers())
6985 || editor
->IsAcceptedKey(event
) )
6987 // ensure cell is visble
6988 MakeCellVisible(row
, col
);
6989 EnableCellEditControl();
6991 // a problem can arise if the cell is not completely
6992 // visible (even after calling MakeCellVisible the
6993 // control is not created and calling StartingKey will
6995 if ( event
.GetKeyCode() != WXK_F2
&& editor
->IsCreated() && m_cellEditCtrlEnabled
)
6996 editor
->StartingKey(event
);
7012 void wxGrid::OnEraseBackground(wxEraseEvent
&)
7016 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
7018 if ( SendEvent( wxEVT_GRID_SELECT_CELL
, coords
.GetRow(), coords
.GetCol() ) )
7020 // the event has been intercepted - do nothing
7024 wxClientDC
dc( m_gridWin
);
7027 if ( m_currentCellCoords
!= wxGridNoCellCoords
)
7029 DisableCellEditControl();
7031 if ( IsVisible( m_currentCellCoords
, false ) )
7034 r
= BlockToDeviceRect( m_currentCellCoords
, m_currentCellCoords
);
7035 if ( !m_gridLinesEnabled
)
7043 wxGridCellCoordsArray cells
= CalcCellsExposed( r
);
7045 // Otherwise refresh redraws the highlight!
7046 m_currentCellCoords
= coords
;
7048 DrawGridCellArea( dc
, cells
);
7049 DrawAllGridLines( dc
, r
);
7053 m_currentCellCoords
= coords
;
7055 wxGridCellAttr
*attr
= GetCellAttr( coords
);
7056 DrawCellHighlight( dc
, attr
);
7060 void wxGrid::HighlightBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
7063 wxGridCellCoords updateTopLeft
, updateBottomRight
;
7067 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectRows
)
7070 rightCol
= GetNumberCols() - 1;
7072 else if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectColumns
)
7075 bottomRow
= GetNumberRows() - 1;
7079 if ( topRow
> bottomRow
)
7086 if ( leftCol
> rightCol
)
7093 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
7094 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
7096 // First the case that we selected a completely new area
7097 if ( m_selectingTopLeft
== wxGridNoCellCoords
||
7098 m_selectingBottomRight
== wxGridNoCellCoords
)
7101 rect
= BlockToDeviceRect( wxGridCellCoords ( topRow
, leftCol
),
7102 wxGridCellCoords ( bottomRow
, rightCol
) );
7103 m_gridWin
->Refresh( false, &rect
);
7106 // Now handle changing an existing selection area.
7107 else if ( m_selectingTopLeft
!= updateTopLeft
||
7108 m_selectingBottomRight
!= updateBottomRight
)
7110 // Compute two optimal update rectangles:
7111 // Either one rectangle is a real subset of the
7112 // other, or they are (almost) disjoint!
7114 bool need_refresh
[4];
7118 need_refresh
[3] = false;
7121 // Store intermediate values
7122 wxCoord oldLeft
= m_selectingTopLeft
.GetCol();
7123 wxCoord oldTop
= m_selectingTopLeft
.GetRow();
7124 wxCoord oldRight
= m_selectingBottomRight
.GetCol();
7125 wxCoord oldBottom
= m_selectingBottomRight
.GetRow();
7127 // Determine the outer/inner coordinates.
7128 if (oldLeft
> leftCol
)
7134 if (oldTop
> topRow
)
7140 if (oldRight
< rightCol
)
7143 oldRight
= rightCol
;
7146 if (oldBottom
< bottomRow
)
7149 oldBottom
= bottomRow
;
7153 // Now, either the stuff marked old is the outer
7154 // rectangle or we don't have a situation where one
7155 // is contained in the other.
7157 if ( oldLeft
< leftCol
)
7159 // Refresh the newly selected or deselected
7160 // area to the left of the old or new selection.
7161 need_refresh
[0] = true;
7162 rect
[0] = BlockToDeviceRect(
7163 wxGridCellCoords( oldTop
, oldLeft
),
7164 wxGridCellCoords( oldBottom
, leftCol
- 1 ) );
7167 if ( oldTop
< topRow
)
7169 // Refresh the newly selected or deselected
7170 // area above the old or new selection.
7171 need_refresh
[1] = true;
7172 rect
[1] = BlockToDeviceRect(
7173 wxGridCellCoords( oldTop
, leftCol
),
7174 wxGridCellCoords( topRow
- 1, rightCol
) );
7177 if ( oldRight
> rightCol
)
7179 // Refresh the newly selected or deselected
7180 // area to the right of the old or new selection.
7181 need_refresh
[2] = true;
7182 rect
[2] = BlockToDeviceRect(
7183 wxGridCellCoords( oldTop
, rightCol
+ 1 ),
7184 wxGridCellCoords( oldBottom
, oldRight
) );
7187 if ( oldBottom
> bottomRow
)
7189 // Refresh the newly selected or deselected
7190 // area below the old or new selection.
7191 need_refresh
[3] = true;
7192 rect
[3] = BlockToDeviceRect(
7193 wxGridCellCoords( bottomRow
+ 1, leftCol
),
7194 wxGridCellCoords( oldBottom
, rightCol
) );
7197 // various Refresh() calls
7198 for (i
= 0; i
< 4; i
++ )
7199 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
7200 m_gridWin
->Refresh( false, &(rect
[i
]) );
7204 m_selectingTopLeft
= updateTopLeft
;
7205 m_selectingBottomRight
= updateBottomRight
;
7209 // ------ functions to get/send data (see also public functions)
7212 bool wxGrid::GetModelValues()
7214 // Hide the editor, so it won't hide a changed value.
7215 HideCellEditControl();
7219 // all we need to do is repaint the grid
7221 m_gridWin
->Refresh();
7228 bool wxGrid::SetModelValues()
7232 // Disable the editor, so it won't hide a changed value.
7233 // Do we also want to save the current value of the editor first?
7235 DisableCellEditControl();
7239 for ( row
= 0; row
< m_numRows
; row
++ )
7241 for ( col
= 0; col
< m_numCols
; col
++ )
7243 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
7253 // Note - this function only draws cells that are in the list of
7254 // exposed cells (usually set from the update region by
7255 // CalcExposedCells)
7257 void wxGrid::DrawGridCellArea( wxDC
& dc
, const wxGridCellCoordsArray
& cells
)
7259 if ( !m_numRows
|| !m_numCols
)
7262 int i
, numCells
= cells
.GetCount();
7263 int row
, col
, cell_rows
, cell_cols
;
7264 wxGridCellCoordsArray redrawCells
;
7266 for ( i
= numCells
- 1; i
>= 0; i
-- )
7268 row
= cells
[i
].GetRow();
7269 col
= cells
[i
].GetCol();
7270 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7272 // If this cell is part of a multicell block, find owner for repaint
7273 if ( cell_rows
<= 0 || cell_cols
<= 0 )
7275 wxGridCellCoords
cell( row
+ cell_rows
, col
+ cell_cols
);
7276 bool marked
= false;
7277 for ( int j
= 0; j
< numCells
; j
++ )
7279 if ( cell
== cells
[j
] )
7288 int count
= redrawCells
.GetCount();
7289 for (int j
= 0; j
< count
; j
++)
7291 if ( cell
== redrawCells
[j
] )
7299 redrawCells
.Add( cell
);
7302 // don't bother drawing this cell
7306 // If this cell is empty, find cell to left that might want to overflow
7307 if (m_table
&& m_table
->IsEmptyCell(row
, col
))
7309 for ( int l
= 0; l
< cell_rows
; l
++ )
7311 // find a cell in this row to leave already marked for repaint
7313 for (int k
= 0; k
< int(redrawCells
.GetCount()); k
++)
7314 if ((redrawCells
[k
].GetCol() < left
) &&
7315 (redrawCells
[k
].GetRow() == row
))
7317 left
= redrawCells
[k
].GetCol();
7321 left
= 0; // oh well
7323 for (int j
= col
- 1; j
>= left
; j
--)
7325 if (!m_table
->IsEmptyCell(row
+ l
, j
))
7327 if (GetCellOverflow(row
+ l
, j
))
7329 wxGridCellCoords
cell(row
+ l
, j
);
7330 bool marked
= false;
7332 for (int k
= 0; k
< numCells
; k
++)
7334 if ( cell
== cells
[k
] )
7343 int count
= redrawCells
.GetCount();
7344 for (int k
= 0; k
< count
; k
++)
7346 if ( cell
== redrawCells
[k
] )
7353 redrawCells
.Add( cell
);
7362 DrawCell( dc
, cells
[i
] );
7365 numCells
= redrawCells
.GetCount();
7367 for ( i
= numCells
- 1; i
>= 0; i
-- )
7369 DrawCell( dc
, redrawCells
[i
] );
7373 void wxGrid::DrawGridSpace( wxDC
& dc
)
7376 m_gridWin
->GetClientSize( &cw
, &ch
);
7379 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
7381 int rightCol
= m_numCols
> 0 ? GetColRight(GetColAt( m_numCols
- 1 )) : 0;
7382 int bottomRow
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) : 0;
7384 if ( right
> rightCol
|| bottom
> bottomRow
)
7387 CalcUnscrolledPosition( 0, 0, &left
, &top
);
7389 dc
.SetBrush( wxBrush(GetDefaultCellBackgroundColour(), wxSOLID
) );
7390 dc
.SetPen( *wxTRANSPARENT_PEN
);
7392 if ( right
> rightCol
)
7394 dc
.DrawRectangle( rightCol
, top
, right
- rightCol
, ch
);
7397 if ( bottom
> bottomRow
)
7399 dc
.DrawRectangle( left
, bottomRow
, cw
, bottom
- bottomRow
);
7404 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
7406 int row
= coords
.GetRow();
7407 int col
= coords
.GetCol();
7409 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
7412 // we draw the cell border ourselves
7413 #if !WXGRID_DRAW_LINES
7414 if ( m_gridLinesEnabled
)
7415 DrawCellBorder( dc
, coords
);
7418 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7420 bool isCurrent
= coords
== m_currentCellCoords
;
7422 wxRect rect
= CellToRect( row
, col
);
7424 // if the editor is shown, we should use it and not the renderer
7425 // Note: However, only if it is really _shown_, i.e. not hidden!
7426 if ( isCurrent
&& IsCellEditControlShown() )
7428 // NB: this "#if..." is temporary and fixes a problem where the
7429 // edit control is erased by this code after being rendered.
7430 // On wxMac (QD build only), the cell editor is a wxTextCntl and is rendered
7431 // implicitly, causing this out-of order render.
7432 #if !defined(__WXMAC__) || wxMAC_USE_CORE_GRAPHICS
7433 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
7434 editor
->PaintBackground(rect
, attr
);
7440 // but all the rest is drawn by the cell renderer and hence may be customized
7441 wxGridCellRenderer
*renderer
= attr
->GetRenderer(this, row
, col
);
7442 renderer
->Draw(*this, *attr
, dc
, rect
, row
, col
, IsInSelection(coords
));
7449 void wxGrid::DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
)
7451 int row
= m_currentCellCoords
.GetRow();
7452 int col
= m_currentCellCoords
.GetCol();
7454 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
7457 wxRect rect
= CellToRect(row
, col
);
7459 // hmmm... what could we do here to show that the cell is disabled?
7460 // for now, I just draw a thinner border than for the other ones, but
7461 // it doesn't look really good
7463 int penWidth
= attr
->IsReadOnly() ? m_cellHighlightROPenWidth
: m_cellHighlightPenWidth
;
7467 // The center of the drawn line is where the position/width/height of
7468 // the rectangle is actually at (on wxMSW at least), so the
7469 // size of the rectangle is reduced to compensate for the thickness of
7470 // the line. If this is too strange on non-wxMSW platforms then
7471 // please #ifdef this appropriately.
7472 rect
.x
+= penWidth
/ 2;
7473 rect
.y
+= penWidth
/ 2;
7474 rect
.width
-= penWidth
- 1;
7475 rect
.height
-= penWidth
- 1;
7477 // Now draw the rectangle
7478 // use the cellHighlightColour if the cell is inside a selection, this
7479 // will ensure the cell is always visible.
7480 dc
.SetPen(wxPen(IsInSelection(row
,col
) ? m_selectionForeground
: m_cellHighlightColour
, penWidth
, wxSOLID
));
7481 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
7482 dc
.DrawRectangle(rect
);
7486 // VZ: my experiments with 3D borders...
7488 // how to properly set colours for arbitrary bg?
7489 wxCoord x1
= rect
.x
,
7491 x2
= rect
.x
+ rect
.width
- 1,
7492 y2
= rect
.y
+ rect
.height
- 1;
7494 dc
.SetPen(*wxWHITE_PEN
);
7495 dc
.DrawLine(x1
, y1
, x2
, y1
);
7496 dc
.DrawLine(x1
, y1
, x1
, y2
);
7498 dc
.DrawLine(x1
+ 1, y2
- 1, x2
- 1, y2
- 1);
7499 dc
.DrawLine(x2
- 1, y1
+ 1, x2
- 1, y2
);
7501 dc
.SetPen(*wxBLACK_PEN
);
7502 dc
.DrawLine(x1
, y2
, x2
, y2
);
7503 dc
.DrawLine(x2
, y1
, x2
, y2
+ 1);
7507 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
7509 int row
= coords
.GetRow();
7510 int col
= coords
.GetCol();
7511 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
7514 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
7516 wxRect rect
= CellToRect( row
, col
);
7518 // right hand border
7519 dc
.DrawLine( rect
.x
+ rect
.width
, rect
.y
,
7520 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
+ 1 );
7523 dc
.DrawLine( rect
.x
, rect
.y
+ rect
.height
,
7524 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
7527 void wxGrid::DrawHighlight(wxDC
& dc
, const wxGridCellCoordsArray
& cells
)
7529 // This if block was previously in wxGrid::OnPaint but that doesn't
7530 // seem to get called under wxGTK - MB
7532 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
7533 m_numRows
&& m_numCols
)
7535 m_currentCellCoords
.Set(0, 0);
7538 if ( IsCellEditControlShown() )
7540 // don't show highlight when the edit control is shown
7544 // if the active cell was repainted, repaint its highlight too because it
7545 // might have been damaged by the grid lines
7546 size_t count
= cells
.GetCount();
7547 for ( size_t n
= 0; n
< count
; n
++ )
7549 if ( cells
[n
] == m_currentCellCoords
)
7551 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
7552 DrawCellHighlight(dc
, attr
);
7560 // TODO: remove this ???
7561 // This is used to redraw all grid lines e.g. when the grid line colour
7564 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& WXUNUSED(reg
) )
7566 #if !WXGRID_DRAW_LINES
7570 if ( !m_gridLinesEnabled
|| !m_numRows
|| !m_numCols
)
7573 int top
, bottom
, left
, right
;
7575 #if 0 //#ifndef __WXGTK__
7579 m_gridWin
->GetClientSize(&cw
, &ch
);
7581 // virtual coords of visible area
7583 CalcUnscrolledPosition( 0, 0, &left
, &top
);
7584 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
7589 reg
.GetBox(x
, y
, w
, h
);
7590 CalcUnscrolledPosition( x
, y
, &left
, &top
);
7591 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
7595 m_gridWin
->GetClientSize(&cw
, &ch
);
7596 CalcUnscrolledPosition( 0, 0, &left
, &top
);
7597 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
7600 // avoid drawing grid lines past the last row and col
7602 right
= wxMin( right
, GetColRight(GetColAt( m_numCols
- 1 )) );
7603 bottom
= wxMin( bottom
, GetRowBottom(m_numRows
- 1) );
7605 // no gridlines inside multicells, clip them out
7606 int leftCol
= GetColPos( internalXToCol(left
) );
7607 int topRow
= internalYToRow(top
);
7608 int rightCol
= GetColPos( internalXToCol(right
) );
7609 int bottomRow
= internalYToRow(bottom
);
7612 // CS: I don't know why suddenly unscrolled coordinates are used for clipping
7613 wxRegion
clippedcells(0, 0, cw
, ch
);
7615 int i
, j
, cell_rows
, cell_cols
;
7618 for (j
=topRow
; j
<bottomRow
; j
++)
7621 for (colPos
=leftCol
; colPos
<rightCol
; colPos
++)
7623 i
= GetColAt( colPos
);
7625 GetCellSize( j
, i
, &cell_rows
, &cell_cols
);
7626 if ((cell_rows
> 1) || (cell_cols
> 1))
7628 rect
= CellToRect(j
,i
);
7629 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
7630 clippedcells
.Subtract(rect
);
7632 else if ((cell_rows
< 0) || (cell_cols
< 0))
7634 rect
= CellToRect(j
+ cell_rows
, i
+ cell_cols
);
7635 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
7636 clippedcells
.Subtract(rect
);
7641 wxRegion
clippedcells( left
, top
, right
- left
, bottom
- top
);
7643 int i
, j
, cell_rows
, cell_cols
;
7646 for (j
=topRow
; j
<bottomRow
; j
++)
7648 for (i
=leftCol
; i
<rightCol
; i
++)
7650 GetCellSize( j
, i
, &cell_rows
, &cell_cols
);
7651 if ((cell_rows
> 1) || (cell_cols
> 1))
7653 rect
= CellToRect(j
, i
);
7654 clippedcells
.Subtract(rect
);
7656 else if ((cell_rows
< 0) || (cell_cols
< 0))
7658 rect
= CellToRect(j
+ cell_rows
, i
+ cell_cols
);
7659 clippedcells
.Subtract(rect
);
7665 dc
.SetClippingRegion( clippedcells
);
7667 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
7669 // horizontal grid lines
7671 // already declared above - int i;
7672 for ( i
= internalYToRow(top
); i
< m_numRows
; i
++ )
7674 int bot
= GetRowBottom(i
) - 1;
7683 dc
.DrawLine( left
, bot
, right
, bot
);
7687 // vertical grid lines
7690 for ( colPos
= leftCol
; colPos
< m_numCols
; colPos
++ )
7692 i
= GetColAt( colPos
);
7694 int colRight
= GetColRight(i
) - 1;
7695 if ( colRight
> right
)
7700 if ( colRight
>= left
)
7702 dc
.DrawLine( colRight
, top
, colRight
, bottom
);
7706 dc
.DestroyClippingRegion();
7709 void wxGrid::DrawRowLabels( wxDC
& dc
, const wxArrayInt
& rows
)
7715 size_t numLabels
= rows
.GetCount();
7717 for ( i
= 0; i
< numLabels
; i
++ )
7719 DrawRowLabel( dc
, rows
[i
] );
7723 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
7725 if ( GetRowHeight(row
) <= 0 || m_rowLabelWidth
<= 0 )
7732 rect
.SetY( GetRowTop(row
) + 1 );
7733 rect
.SetWidth( m_rowLabelWidth
- 2 );
7734 rect
.SetHeight( GetRowHeight(row
) - 2 );
7736 CalcScrolledPosition( 0, rect
.y
, NULL
, &rect
.y
);
7738 wxWindowDC
*win_dc
= (wxWindowDC
*) &dc
;
7740 wxRendererNative::Get().DrawHeaderButton( win_dc
->m_owner
, dc
, rect
, 0 );
7742 int rowTop
= GetRowTop(row
),
7743 rowBottom
= GetRowBottom(row
) - 1;
7745 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
), 1, wxSOLID
) );
7746 dc
.DrawLine( m_rowLabelWidth
- 1, rowTop
, m_rowLabelWidth
- 1, rowBottom
);
7747 dc
.DrawLine( 0, rowTop
, 0, rowBottom
);
7748 dc
.DrawLine( 0, rowBottom
, m_rowLabelWidth
, rowBottom
);
7750 dc
.SetPen( *wxWHITE_PEN
);
7751 dc
.DrawLine( 1, rowTop
, 1, rowBottom
);
7752 dc
.DrawLine( 1, rowTop
, m_rowLabelWidth
- 1, rowTop
);
7755 dc
.SetBackgroundMode( wxTRANSPARENT
);
7756 dc
.SetTextForeground( GetLabelTextColour() );
7757 dc
.SetFont( GetLabelFont() );
7760 GetRowLabelAlignment( &hAlign
, &vAlign
);
7763 rect
.SetY( GetRowTop(row
) + 2 );
7764 rect
.SetWidth( m_rowLabelWidth
- 4 );
7765 rect
.SetHeight( GetRowHeight(row
) - 4 );
7766 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
7769 void wxGrid::DrawColLabels( wxDC
& dc
,const wxArrayInt
& cols
)
7775 size_t numLabels
= cols
.GetCount();
7777 for ( i
= 0; i
< numLabels
; i
++ )
7779 DrawColLabel( dc
, cols
[i
] );
7783 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
7785 if ( GetColWidth(col
) <= 0 || m_colLabelHeight
<= 0 )
7788 int colLeft
= GetColLeft(col
);
7793 rect
.SetX( colLeft
+ 1 );
7795 rect
.SetWidth( GetColWidth(col
) - 2 );
7796 rect
.SetHeight( m_colLabelHeight
- 2 );
7798 wxWindowDC
*win_dc
= (wxWindowDC
*) &dc
;
7800 wxRendererNative::Get().DrawHeaderButton( win_dc
->m_owner
, dc
, rect
, 0 );
7802 int colRight
= GetColRight(col
) - 1;
7804 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
), 1, wxSOLID
) );
7805 dc
.DrawLine( colRight
, 0, colRight
, m_colLabelHeight
- 1 );
7806 dc
.DrawLine( colLeft
, 0, colRight
, 0 );
7807 dc
.DrawLine( colLeft
, m_colLabelHeight
- 1,
7808 colRight
+ 1, m_colLabelHeight
- 1 );
7810 dc
.SetPen( *wxWHITE_PEN
);
7811 dc
.DrawLine( colLeft
, 1, colLeft
, m_colLabelHeight
- 1 );
7812 dc
.DrawLine( colLeft
, 1, colRight
, 1 );
7815 dc
.SetBackgroundMode( wxTRANSPARENT
);
7816 dc
.SetTextForeground( GetLabelTextColour() );
7817 dc
.SetFont( GetLabelFont() );
7819 int hAlign
, vAlign
, orient
;
7820 GetColLabelAlignment( &hAlign
, &vAlign
);
7821 orient
= GetColLabelTextOrientation();
7823 rect
.SetX( colLeft
+ 2 );
7825 rect
.SetWidth( GetColWidth(col
) - 4 );
7826 rect
.SetHeight( m_colLabelHeight
- 4 );
7827 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
, orient
);
7830 void wxGrid::DrawTextRectangle( wxDC
& dc
,
7831 const wxString
& value
,
7835 int textOrientation
)
7837 wxArrayString lines
;
7839 StringToLines( value
, lines
);
7841 // Forward to new API.
7842 DrawTextRectangle( dc
,
7850 // VZ: this should be replaced with wxDC::DrawLabel() to which we just have to
7851 // add textOrientation support
7852 void wxGrid::DrawTextRectangle(wxDC
& dc
,
7853 const wxArrayString
& lines
,
7857 int textOrientation
)
7859 if ( lines
.empty() )
7862 wxDCClipper
clip(dc
, rect
);
7867 if ( textOrientation
== wxHORIZONTAL
)
7868 GetTextBoxSize( dc
, lines
, &textWidth
, &textHeight
);
7870 GetTextBoxSize( dc
, lines
, &textHeight
, &textWidth
);
7874 switch ( vertAlign
)
7876 case wxALIGN_BOTTOM
:
7877 if ( textOrientation
== wxHORIZONTAL
)
7878 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
7880 x
= rect
.x
+ rect
.width
- textWidth
;
7883 case wxALIGN_CENTRE
:
7884 if ( textOrientation
== wxHORIZONTAL
)
7885 y
= rect
.y
+ ((rect
.height
- textHeight
) / 2);
7887 x
= rect
.x
+ ((rect
.width
- textWidth
) / 2);
7892 if ( textOrientation
== wxHORIZONTAL
)
7899 // Align each line of a multi-line label
7900 size_t nLines
= lines
.GetCount();
7901 for ( size_t l
= 0; l
< nLines
; l
++ )
7903 const wxString
& line
= lines
[l
];
7907 *(textOrientation
== wxHORIZONTAL
? &y
: &x
) += dc
.GetCharHeight();
7913 dc
.GetTextExtent(line
, &lineWidth
, &lineHeight
);
7915 switch ( horizAlign
)
7918 if ( textOrientation
== wxHORIZONTAL
)
7919 x
= rect
.x
+ (rect
.width
- lineWidth
- 1);
7921 y
= rect
.y
+ lineWidth
+ 1;
7924 case wxALIGN_CENTRE
:
7925 if ( textOrientation
== wxHORIZONTAL
)
7926 x
= rect
.x
+ ((rect
.width
- lineWidth
) / 2);
7928 y
= rect
.y
+ rect
.height
- ((rect
.height
- lineWidth
) / 2);
7933 if ( textOrientation
== wxHORIZONTAL
)
7936 y
= rect
.y
+ rect
.height
- 1;
7940 if ( textOrientation
== wxHORIZONTAL
)
7942 dc
.DrawText( line
, x
, y
);
7947 dc
.DrawRotatedText( line
, x
, y
, 90.0 );
7953 // Split multi-line text up into an array of strings.
7954 // Any existing contents of the string array are preserved.
7956 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
7960 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
7961 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
7963 while ( startPos
< (int)tVal
.length() )
7965 pos
= tVal
.Mid(startPos
).Find( eol
);
7970 else if ( pos
== 0 )
7972 lines
.Add( wxEmptyString
);
7976 lines
.Add( value
.Mid(startPos
, pos
) );
7979 startPos
+= pos
+ 1;
7982 if ( startPos
< (int)value
.length() )
7984 lines
.Add( value
.Mid( startPos
) );
7988 void wxGrid::GetTextBoxSize( const wxDC
& dc
,
7989 const wxArrayString
& lines
,
7990 long *width
, long *height
)
7994 long lineW
= 0, lineH
= 0;
7997 for ( i
= 0; i
< lines
.GetCount(); i
++ )
7999 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
8000 w
= wxMax( w
, lineW
);
8009 // ------ Batch processing.
8011 void wxGrid::EndBatch()
8013 if ( m_batchCount
> 0 )
8016 if ( !m_batchCount
)
8019 m_rowLabelWin
->Refresh();
8020 m_colLabelWin
->Refresh();
8021 m_cornerLabelWin
->Refresh();
8022 m_gridWin
->Refresh();
8027 // Use this, rather than wxWindow::Refresh(), to force an immediate
8028 // repainting of the grid. Has no effect if you are already inside a
8029 // BeginBatch / EndBatch block.
8031 void wxGrid::ForceRefresh()
8037 bool wxGrid::Enable(bool enable
)
8039 if ( !wxScrolledWindow::Enable(enable
) )
8042 // redraw in the new state
8043 m_gridWin
->Refresh();
8049 // ------ Edit control functions
8052 void wxGrid::EnableEditing( bool edit
)
8054 // TODO: improve this ?
8056 if ( edit
!= m_editable
)
8059 EnableCellEditControl(edit
);
8064 void wxGrid::EnableCellEditControl( bool enable
)
8069 if ( enable
!= m_cellEditCtrlEnabled
)
8073 if (SendEvent( wxEVT_GRID_EDITOR_SHOWN
) <0)
8076 // this should be checked by the caller!
8077 wxASSERT_MSG( CanEnableCellControl(), _T("can't enable editing for this cell!") );
8079 // do it before ShowCellEditControl()
8080 m_cellEditCtrlEnabled
= enable
;
8082 ShowCellEditControl();
8086 //FIXME:add veto support
8087 SendEvent( wxEVT_GRID_EDITOR_HIDDEN
);
8089 HideCellEditControl();
8090 SaveEditControlValue();
8092 // do it after HideCellEditControl()
8093 m_cellEditCtrlEnabled
= enable
;
8098 bool wxGrid::IsCurrentCellReadOnly() const
8101 wxGridCellAttr
* attr
= ((wxGrid
*)this)->GetCellAttr(m_currentCellCoords
);
8102 bool readonly
= attr
->IsReadOnly();
8108 bool wxGrid::CanEnableCellControl() const
8110 return m_editable
&& (m_currentCellCoords
!= wxGridNoCellCoords
) &&
8111 !IsCurrentCellReadOnly();
8114 bool wxGrid::IsCellEditControlEnabled() const
8116 // the cell edit control might be disable for all cells or just for the
8117 // current one if it's read only
8118 return m_cellEditCtrlEnabled
? !IsCurrentCellReadOnly() : false;
8121 bool wxGrid::IsCellEditControlShown() const
8123 bool isShown
= false;
8125 if ( m_cellEditCtrlEnabled
)
8127 int row
= m_currentCellCoords
.GetRow();
8128 int col
= m_currentCellCoords
.GetCol();
8129 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8130 wxGridCellEditor
* editor
= attr
->GetEditor((wxGrid
*) this, row
, col
);
8135 if ( editor
->IsCreated() )
8137 isShown
= editor
->GetControl()->IsShown();
8147 void wxGrid::ShowCellEditControl()
8149 if ( IsCellEditControlEnabled() )
8151 if ( !IsVisible( m_currentCellCoords
, false ) )
8153 m_cellEditCtrlEnabled
= false;
8158 wxRect rect
= CellToRect( m_currentCellCoords
);
8159 int row
= m_currentCellCoords
.GetRow();
8160 int col
= m_currentCellCoords
.GetCol();
8162 // if this is part of a multicell, find owner (topleft)
8163 int cell_rows
, cell_cols
;
8164 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
8165 if ( cell_rows
<= 0 || cell_cols
<= 0 )
8169 m_currentCellCoords
.SetRow( row
);
8170 m_currentCellCoords
.SetCol( col
);
8173 // convert to scrolled coords
8174 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
8180 // erase the highlight and the cell contents because the editor
8181 // might not cover the entire cell
8182 wxClientDC
dc( m_gridWin
);
8184 dc
.SetBrush(wxBrush(GetCellAttr(row
, col
)->GetBackgroundColour(), wxSOLID
));
8185 dc
.SetPen(*wxTRANSPARENT_PEN
);
8186 dc
.DrawRectangle(rect
);
8188 // cell is shifted by one pixel
8189 // However, don't allow x or y to become negative
8190 // since the SetSize() method interprets that as
8197 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8198 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
8199 if ( !editor
->IsCreated() )
8201 editor
->Create(m_gridWin
, wxID_ANY
,
8202 new wxGridCellEditorEvtHandler(this, editor
));
8204 wxGridEditorCreatedEvent
evt(GetId(),
8205 wxEVT_GRID_EDITOR_CREATED
,
8209 editor
->GetControl());
8210 GetEventHandler()->ProcessEvent(evt
);
8213 // resize editor to overflow into righthand cells if allowed
8214 int maxWidth
= rect
.width
;
8215 wxString value
= GetCellValue(row
, col
);
8216 if ( (value
!= wxEmptyString
) && (attr
->GetOverflow()) )
8219 GetTextExtent(value
, &maxWidth
, &y
, NULL
, NULL
, &attr
->GetFont());
8220 if (maxWidth
< rect
.width
)
8221 maxWidth
= rect
.width
;
8224 int client_right
= m_gridWin
->GetClientSize().GetWidth();
8225 if (rect
.x
+ maxWidth
> client_right
)
8226 maxWidth
= client_right
- rect
.x
;
8228 if ((maxWidth
> rect
.width
) && (col
< m_numCols
) && m_table
)
8230 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
8231 // may have changed earlier
8232 for (int i
= col
+ cell_cols
; i
< m_numCols
; i
++)
8235 GetCellSize( row
, i
, &c_rows
, &c_cols
);
8237 // looks weird going over a multicell
8238 if (m_table
->IsEmptyCell( row
, i
) &&
8239 (rect
.width
< maxWidth
) && (c_rows
== 1))
8241 rect
.width
+= GetColWidth( i
);
8247 if (rect
.GetRight() > client_right
)
8248 rect
.SetRight( client_right
- 1 );
8251 editor
->SetCellAttr( attr
);
8252 editor
->SetSize( rect
);
8254 editor
->GetControl()->Move(
8255 editor
->GetControl()->GetPosition().x
+ nXMove
,
8256 editor
->GetControl()->GetPosition().y
);
8257 editor
->Show( true, attr
);
8259 // recalc dimensions in case we need to
8260 // expand the scrolled window to account for editor
8263 editor
->BeginEdit(row
, col
, this);
8264 editor
->SetCellAttr(NULL
);
8272 void wxGrid::HideCellEditControl()
8274 if ( IsCellEditControlEnabled() )
8276 int row
= m_currentCellCoords
.GetRow();
8277 int col
= m_currentCellCoords
.GetCol();
8279 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8280 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
8281 editor
->Show( false );
8285 m_gridWin
->SetFocus();
8287 // refresh whole row to the right
8288 wxRect
rect( CellToRect(row
, col
) );
8289 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
8290 rect
.width
= m_gridWin
->GetClientSize().GetWidth() - rect
.x
;
8293 // ensure that the pixels under the focus ring get refreshed as well
8294 rect
.Inflate(10, 10);
8297 m_gridWin
->Refresh( false, &rect
);
8301 void wxGrid::SaveEditControlValue()
8303 if ( IsCellEditControlEnabled() )
8305 int row
= m_currentCellCoords
.GetRow();
8306 int col
= m_currentCellCoords
.GetCol();
8308 wxString oldval
= GetCellValue(row
, col
);
8310 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8311 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
8312 bool changed
= editor
->EndEdit(row
, col
, this);
8319 if ( SendEvent( wxEVT_GRID_CELL_CHANGE
,
8320 m_currentCellCoords
.GetRow(),
8321 m_currentCellCoords
.GetCol() ) < 0 )
8323 // Event has been vetoed, set the data back.
8324 SetCellValue(row
, col
, oldval
);
8331 // ------ Grid location functions
8332 // Note that all of these functions work with the logical coordinates of
8333 // grid cells and labels so you will need to convert from device
8334 // coordinates for mouse events etc.
8337 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
8339 int row
= YToRow(y
);
8340 int col
= XToCol(x
);
8342 if ( row
== -1 || col
== -1 )
8344 coords
= wxGridNoCellCoords
;
8348 coords
.Set( row
, col
);
8352 // Internal Helper function for computing row or column from some
8353 // (unscrolled) coordinate value, using either
8354 // m_defaultRowHeight/m_defaultColWidth or binary search on array
8355 // of m_rowBottoms/m_ColRights to speed up the search!
8357 static int CoordToRowOrCol(int coord
, int defaultDist
, int minDist
,
8358 const wxArrayInt
& BorderArray
, int nMax
,
8362 return clipToMinMax
&& (nMax
> 0) ? 0 : -1;
8367 size_t i_max
= coord
/ defaultDist
,
8370 if (BorderArray
.IsEmpty())
8372 if ((int) i_max
< nMax
)
8374 return clipToMinMax
? nMax
- 1 : -1;
8377 if ( i_max
>= BorderArray
.GetCount())
8379 i_max
= BorderArray
.GetCount() - 1;
8383 if ( coord
>= BorderArray
[i_max
])
8387 i_max
= coord
/ minDist
;
8389 i_max
= BorderArray
.GetCount() - 1;
8392 if ( i_max
>= BorderArray
.GetCount())
8393 i_max
= BorderArray
.GetCount() - 1;
8396 if ( coord
>= BorderArray
[i_max
])
8397 return clipToMinMax
? (int)i_max
: -1;
8398 if ( coord
< BorderArray
[0] )
8401 while ( i_max
- i_min
> 0 )
8403 wxCHECK_MSG(BorderArray
[i_min
] <= coord
&& coord
< BorderArray
[i_max
],
8404 0, _T("wxGrid: internal error in CoordToRowOrCol"));
8405 if (coord
>= BorderArray
[ i_max
- 1])
8409 int median
= i_min
+ (i_max
- i_min
+ 1) / 2;
8410 if (coord
< BorderArray
[median
])
8419 int wxGrid::YToRow( int y
)
8421 return CoordToRowOrCol(y
, m_defaultRowHeight
,
8422 m_minAcceptableRowHeight
, m_rowBottoms
, m_numRows
, false);
8425 int wxGrid::XToCol( int x
, bool clipToMinMax
)
8428 return clipToMinMax
&& (m_numCols
> 0) ? GetColAt( 0 ) : -1;
8430 if (!m_defaultColWidth
)
8431 m_defaultColWidth
= 1;
8433 int maxPos
= x
/ m_defaultColWidth
;
8436 if (m_colRights
.IsEmpty())
8438 if(maxPos
< m_numCols
)
8439 return GetColAt( maxPos
);
8440 return clipToMinMax
? GetColAt( m_numCols
- 1 ) : -1;
8443 if ( maxPos
>= m_numCols
)
8444 maxPos
= m_numCols
- 1;
8447 if ( x
>= m_colRights
[GetColAt( maxPos
)])
8450 if (m_minAcceptableColWidth
)
8451 maxPos
= x
/ m_minAcceptableColWidth
;
8453 maxPos
= m_numCols
- 1;
8455 if ( maxPos
>= m_numCols
)
8456 maxPos
= m_numCols
- 1;
8459 //X is beyond the last column
8460 if ( x
>= m_colRights
[GetColAt( maxPos
)])
8461 return clipToMinMax
? GetColAt( maxPos
) : -1;
8463 //X is before the first column
8464 if ( x
< m_colRights
[GetColAt( 0 )] )
8465 return GetColAt( 0 );
8467 //Perform a binary search
8468 while ( maxPos
- minPos
> 0 )
8470 wxCHECK_MSG(m_colRights
[GetColAt( minPos
)] <= x
&& x
< m_colRights
[GetColAt( maxPos
)],
8471 0, _T("wxGrid: internal error in XToCol"));
8473 if (x
>= m_colRights
[GetColAt( maxPos
- 1 )])
8474 return GetColAt( maxPos
);
8477 int median
= minPos
+ (maxPos
- minPos
+ 1) / 2;
8478 if (x
< m_colRights
[GetColAt( median
)])
8483 return GetColAt( maxPos
);
8486 // return the row number that that the y coord is near the edge of, or
8487 // -1 if not near an edge
8489 int wxGrid::YToEdgeOfRow( int y
)
8492 i
= internalYToRow(y
);
8494 if ( GetRowHeight(i
) > WXGRID_LABEL_EDGE_ZONE
)
8496 // We know that we are in row i, test whether we are
8497 // close enough to lower or upper border, respectively.
8498 if ( abs(GetRowBottom(i
) - y
) < WXGRID_LABEL_EDGE_ZONE
)
8500 else if ( i
> 0 && y
- GetRowTop(i
) < WXGRID_LABEL_EDGE_ZONE
)
8507 // return the col number that that the x coord is near the edge of, or
8508 // -1 if not near an edge
8510 int wxGrid::XToEdgeOfCol( int x
)
8513 i
= internalXToCol(x
);
8515 if ( GetColWidth(i
) > WXGRID_LABEL_EDGE_ZONE
)
8517 // We know that we are in column i; test whether we are
8518 // close enough to right or left border, respectively.
8519 if ( abs(GetColRight(i
) - x
) < WXGRID_LABEL_EDGE_ZONE
)
8521 else if ( i
> 0 && x
- GetColLeft(i
) < WXGRID_LABEL_EDGE_ZONE
)
8528 wxRect
wxGrid::CellToRect( int row
, int col
)
8530 wxRect
rect( -1, -1, -1, -1 );
8532 if ( row
>= 0 && row
< m_numRows
&&
8533 col
>= 0 && col
< m_numCols
)
8535 int i
, cell_rows
, cell_cols
;
8536 rect
.width
= rect
.height
= 0;
8537 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
8538 // if negative then find multicell owner
8543 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
8545 rect
.x
= GetColLeft(col
);
8546 rect
.y
= GetRowTop(row
);
8547 for (i
=col
; i
< col
+ cell_cols
; i
++)
8548 rect
.width
+= GetColWidth(i
);
8549 for (i
=row
; i
< row
+ cell_rows
; i
++)
8550 rect
.height
+= GetRowHeight(i
);
8553 // if grid lines are enabled, then the area of the cell is a bit smaller
8554 if (m_gridLinesEnabled
)
8563 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
8565 // get the cell rectangle in logical coords
8567 wxRect
r( CellToRect( row
, col
) );
8569 // convert to device coords
8571 int left
, top
, right
, bottom
;
8572 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
8573 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
8575 // check against the client area of the grid window
8577 m_gridWin
->GetClientSize( &cw
, &ch
);
8579 if ( wholeCellVisible
)
8581 // is the cell wholly visible ?
8582 return ( left
>= 0 && right
<= cw
&&
8583 top
>= 0 && bottom
<= ch
);
8587 // is the cell partly visible ?
8589 return ( ((left
>= 0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
8590 ((top
>= 0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
8594 // make the specified cell location visible by doing a minimal amount
8597 void wxGrid::MakeCellVisible( int row
, int col
)
8600 int xpos
= -1, ypos
= -1;
8602 if ( row
>= 0 && row
< m_numRows
&&
8603 col
>= 0 && col
< m_numCols
)
8605 // get the cell rectangle in logical coords
8606 wxRect
r( CellToRect( row
, col
) );
8608 // convert to device coords
8609 int left
, top
, right
, bottom
;
8610 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
8611 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
8614 m_gridWin
->GetClientSize( &cw
, &ch
);
8620 else if ( bottom
> ch
)
8622 int h
= r
.GetHeight();
8624 for ( i
= row
- 1; i
>= 0; i
-- )
8626 int rowHeight
= GetRowHeight(i
);
8627 if ( h
+ rowHeight
> ch
)
8634 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
8635 // have rounding errors (this is important, because if we do,
8636 // we might not scroll at all and some cells won't be redrawn)
8638 // Sometimes GRID_SCROLL_LINE / 2 is not enough,
8639 // so just add a full scroll unit...
8640 ypos
+= m_scrollLineY
;
8643 // special handling for wide cells - show always left part of the cell!
8644 // Otherwise, e.g. when stepping from row to row, it would jump between
8645 // left and right part of the cell on every step!
8647 if ( left
< 0 || (right
- left
) >= cw
)
8651 else if ( right
> cw
)
8653 // position the view so that the cell is on the right
8655 CalcUnscrolledPosition(0, 0, &x0
, &y0
);
8656 xpos
= x0
+ (right
- cw
);
8658 // see comment for ypos above
8659 xpos
+= m_scrollLineX
;
8662 if ( xpos
!= -1 || ypos
!= -1 )
8665 xpos
/= m_scrollLineX
;
8667 ypos
/= m_scrollLineY
;
8668 Scroll( xpos
, ypos
);
8675 // ------ Grid cursor movement functions
8678 bool wxGrid::MoveCursorUp( bool expandSelection
)
8680 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
8681 m_currentCellCoords
.GetRow() >= 0 )
8683 if ( expandSelection
)
8685 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
8686 m_selectingKeyboard
= m_currentCellCoords
;
8687 if ( m_selectingKeyboard
.GetRow() > 0 )
8689 m_selectingKeyboard
.SetRow( m_selectingKeyboard
.GetRow() - 1 );
8690 MakeCellVisible( m_selectingKeyboard
.GetRow(),
8691 m_selectingKeyboard
.GetCol() );
8692 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8695 else if ( m_currentCellCoords
.GetRow() > 0 )
8697 int row
= m_currentCellCoords
.GetRow() - 1;
8698 int col
= m_currentCellCoords
.GetCol();
8700 MakeCellVisible( row
, col
);
8701 SetCurrentCell( row
, col
);
8712 bool wxGrid::MoveCursorDown( bool expandSelection
)
8714 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
8715 m_currentCellCoords
.GetRow() < m_numRows
)
8717 if ( expandSelection
)
8719 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
8720 m_selectingKeyboard
= m_currentCellCoords
;
8721 if ( m_selectingKeyboard
.GetRow() < m_numRows
- 1 )
8723 m_selectingKeyboard
.SetRow( m_selectingKeyboard
.GetRow() + 1 );
8724 MakeCellVisible( m_selectingKeyboard
.GetRow(),
8725 m_selectingKeyboard
.GetCol() );
8726 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8729 else if ( m_currentCellCoords
.GetRow() < m_numRows
- 1 )
8731 int row
= m_currentCellCoords
.GetRow() + 1;
8732 int col
= m_currentCellCoords
.GetCol();
8734 MakeCellVisible( row
, col
);
8735 SetCurrentCell( row
, col
);
8746 bool wxGrid::MoveCursorLeft( bool expandSelection
)
8748 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
8749 m_currentCellCoords
.GetCol() >= 0 )
8751 if ( expandSelection
)
8753 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
8754 m_selectingKeyboard
= m_currentCellCoords
;
8755 if ( m_selectingKeyboard
.GetCol() > 0 )
8757 m_selectingKeyboard
.SetCol( m_selectingKeyboard
.GetCol() - 1 );
8758 MakeCellVisible( m_selectingKeyboard
.GetRow(),
8759 m_selectingKeyboard
.GetCol() );
8760 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8763 else if ( GetColPos( m_currentCellCoords
.GetCol() ) > 0 )
8765 int row
= m_currentCellCoords
.GetRow();
8766 int col
= GetColAt( GetColPos( m_currentCellCoords
.GetCol() ) - 1 );
8769 MakeCellVisible( row
, col
);
8770 SetCurrentCell( row
, col
);
8781 bool wxGrid::MoveCursorRight( bool expandSelection
)
8783 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
8784 m_currentCellCoords
.GetCol() < m_numCols
)
8786 if ( expandSelection
)
8788 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
8789 m_selectingKeyboard
= m_currentCellCoords
;
8790 if ( m_selectingKeyboard
.GetCol() < m_numCols
- 1 )
8792 m_selectingKeyboard
.SetCol( m_selectingKeyboard
.GetCol() + 1 );
8793 MakeCellVisible( m_selectingKeyboard
.GetRow(),
8794 m_selectingKeyboard
.GetCol() );
8795 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8798 else if ( GetColPos( m_currentCellCoords
.GetCol() ) < m_numCols
- 1 )
8800 int row
= m_currentCellCoords
.GetRow();
8801 int col
= GetColAt( GetColPos( m_currentCellCoords
.GetCol() ) + 1 );
8804 MakeCellVisible( row
, col
);
8805 SetCurrentCell( row
, col
);
8816 bool wxGrid::MovePageUp()
8818 if ( m_currentCellCoords
== wxGridNoCellCoords
)
8821 int row
= m_currentCellCoords
.GetRow();
8825 m_gridWin
->GetClientSize( &cw
, &ch
);
8827 int y
= GetRowTop(row
);
8828 int newRow
= internalYToRow( y
- ch
+ 1 );
8830 if ( newRow
== row
)
8832 // row > 0, so newRow can never be less than 0 here.
8836 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
8837 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
8845 bool wxGrid::MovePageDown()
8847 if ( m_currentCellCoords
== wxGridNoCellCoords
)
8850 int row
= m_currentCellCoords
.GetRow();
8851 if ( (row
+ 1) < m_numRows
)
8854 m_gridWin
->GetClientSize( &cw
, &ch
);
8856 int y
= GetRowTop(row
);
8857 int newRow
= internalYToRow( y
+ ch
);
8858 if ( newRow
== row
)
8860 // row < m_numRows, so newRow can't overflow here.
8864 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
8865 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
8873 bool wxGrid::MoveCursorUpBlock( bool expandSelection
)
8876 m_currentCellCoords
!= wxGridNoCellCoords
&&
8877 m_currentCellCoords
.GetRow() > 0 )
8879 int row
= m_currentCellCoords
.GetRow();
8880 int col
= m_currentCellCoords
.GetCol();
8882 if ( m_table
->IsEmptyCell(row
, col
) )
8884 // starting in an empty cell: find the next block of
8890 if ( !(m_table
->IsEmptyCell(row
, col
)) )
8894 else if ( m_table
->IsEmptyCell(row
- 1, col
) )
8896 // starting at the top of a block: find the next block
8902 if ( !(m_table
->IsEmptyCell(row
, col
)) )
8908 // starting within a block: find the top of the block
8913 if ( m_table
->IsEmptyCell(row
, col
) )
8921 MakeCellVisible( row
, col
);
8922 if ( expandSelection
)
8924 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8925 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8930 SetCurrentCell( row
, col
);
8939 bool wxGrid::MoveCursorDownBlock( bool expandSelection
)
8942 m_currentCellCoords
!= wxGridNoCellCoords
&&
8943 m_currentCellCoords
.GetRow() < m_numRows
- 1 )
8945 int row
= m_currentCellCoords
.GetRow();
8946 int col
= m_currentCellCoords
.GetCol();
8948 if ( m_table
->IsEmptyCell(row
, col
) )
8950 // starting in an empty cell: find the next block of
8953 while ( row
< m_numRows
- 1 )
8956 if ( !(m_table
->IsEmptyCell(row
, col
)) )
8960 else if ( m_table
->IsEmptyCell(row
+ 1, col
) )
8962 // starting at the bottom of a block: find the next block
8965 while ( row
< m_numRows
- 1 )
8968 if ( !(m_table
->IsEmptyCell(row
, col
)) )
8974 // starting within a block: find the bottom of the block
8976 while ( row
< m_numRows
- 1 )
8979 if ( m_table
->IsEmptyCell(row
, col
) )
8987 MakeCellVisible( row
, col
);
8988 if ( expandSelection
)
8990 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8991 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8996 SetCurrentCell( row
, col
);
9005 bool wxGrid::MoveCursorLeftBlock( bool expandSelection
)
9008 m_currentCellCoords
!= wxGridNoCellCoords
&&
9009 m_currentCellCoords
.GetCol() > 0 )
9011 int row
= m_currentCellCoords
.GetRow();
9012 int col
= m_currentCellCoords
.GetCol();
9014 if ( m_table
->IsEmptyCell(row
, col
) )
9016 // starting in an empty cell: find the next block of
9022 if ( !(m_table
->IsEmptyCell(row
, col
)) )
9026 else if ( m_table
->IsEmptyCell(row
, col
- 1) )
9028 // starting at the left of a block: find the next block
9034 if ( !(m_table
->IsEmptyCell(row
, col
)) )
9040 // starting within a block: find the left of the block
9045 if ( m_table
->IsEmptyCell(row
, col
) )
9053 MakeCellVisible( row
, col
);
9054 if ( expandSelection
)
9056 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
9057 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
9062 SetCurrentCell( row
, col
);
9071 bool wxGrid::MoveCursorRightBlock( bool expandSelection
)
9074 m_currentCellCoords
!= wxGridNoCellCoords
&&
9075 m_currentCellCoords
.GetCol() < m_numCols
- 1 )
9077 int row
= m_currentCellCoords
.GetRow();
9078 int col
= m_currentCellCoords
.GetCol();
9080 if ( m_table
->IsEmptyCell(row
, col
) )
9082 // starting in an empty cell: find the next block of
9085 while ( col
< m_numCols
- 1 )
9088 if ( !(m_table
->IsEmptyCell(row
, col
)) )
9092 else if ( m_table
->IsEmptyCell(row
, col
+ 1) )
9094 // starting at the right of a block: find the next block
9097 while ( col
< m_numCols
- 1 )
9100 if ( !(m_table
->IsEmptyCell(row
, col
)) )
9106 // starting within a block: find the right of the block
9108 while ( col
< m_numCols
- 1 )
9111 if ( m_table
->IsEmptyCell(row
, col
) )
9119 MakeCellVisible( row
, col
);
9120 if ( expandSelection
)
9122 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
9123 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
9128 SetCurrentCell( row
, col
);
9138 // ------ Label values and formatting
9141 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
9144 *horiz
= m_rowLabelHorizAlign
;
9146 *vert
= m_rowLabelVertAlign
;
9149 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
9152 *horiz
= m_colLabelHorizAlign
;
9154 *vert
= m_colLabelVertAlign
;
9157 int wxGrid::GetColLabelTextOrientation()
9159 return m_colLabelTextOrientation
;
9162 wxString
wxGrid::GetRowLabelValue( int row
)
9166 return m_table
->GetRowLabelValue( row
);
9176 wxString
wxGrid::GetColLabelValue( int col
)
9180 return m_table
->GetColLabelValue( col
);
9190 void wxGrid::SetRowLabelSize( int width
)
9192 width
= wxMax( width
, 0 );
9193 if ( width
!= m_rowLabelWidth
)
9197 m_rowLabelWin
->Show( false );
9198 m_cornerLabelWin
->Show( false );
9200 else if ( m_rowLabelWidth
== 0 )
9202 m_rowLabelWin
->Show( true );
9203 if ( m_colLabelHeight
> 0 )
9204 m_cornerLabelWin
->Show( true );
9207 m_rowLabelWidth
= width
;
9209 wxScrolledWindow::Refresh( true );
9213 void wxGrid::SetColLabelSize( int height
)
9215 height
= wxMax( height
, 0 );
9216 if ( height
!= m_colLabelHeight
)
9220 m_colLabelWin
->Show( false );
9221 m_cornerLabelWin
->Show( false );
9223 else if ( m_colLabelHeight
== 0 )
9225 m_colLabelWin
->Show( true );
9226 if ( m_rowLabelWidth
> 0 )
9227 m_cornerLabelWin
->Show( true );
9230 m_colLabelHeight
= height
;
9232 wxScrolledWindow::Refresh( true );
9236 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
9238 if ( m_labelBackgroundColour
!= colour
)
9240 m_labelBackgroundColour
= colour
;
9241 m_rowLabelWin
->SetBackgroundColour( colour
);
9242 m_colLabelWin
->SetBackgroundColour( colour
);
9243 m_cornerLabelWin
->SetBackgroundColour( colour
);
9245 if ( !GetBatchCount() )
9247 m_rowLabelWin
->Refresh();
9248 m_colLabelWin
->Refresh();
9249 m_cornerLabelWin
->Refresh();
9254 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
9256 if ( m_labelTextColour
!= colour
)
9258 m_labelTextColour
= colour
;
9259 if ( !GetBatchCount() )
9261 m_rowLabelWin
->Refresh();
9262 m_colLabelWin
->Refresh();
9267 void wxGrid::SetLabelFont( const wxFont
& font
)
9270 if ( !GetBatchCount() )
9272 m_rowLabelWin
->Refresh();
9273 m_colLabelWin
->Refresh();
9277 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
9279 // allow old (incorrect) defs to be used
9282 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
9283 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
9284 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
9289 case wxTOP
: vert
= wxALIGN_TOP
; break;
9290 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
9291 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
9294 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
9296 m_rowLabelHorizAlign
= horiz
;
9299 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
9301 m_rowLabelVertAlign
= vert
;
9304 if ( !GetBatchCount() )
9306 m_rowLabelWin
->Refresh();
9310 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
9312 // allow old (incorrect) defs to be used
9315 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
9316 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
9317 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
9322 case wxTOP
: vert
= wxALIGN_TOP
; break;
9323 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
9324 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
9327 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
9329 m_colLabelHorizAlign
= horiz
;
9332 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
9334 m_colLabelVertAlign
= vert
;
9337 if ( !GetBatchCount() )
9339 m_colLabelWin
->Refresh();
9343 // Note: under MSW, the default column label font must be changed because it
9344 // does not support vertical printing
9346 // Example: wxFont font(9, wxSWISS, wxNORMAL, wxBOLD);
9347 // pGrid->SetLabelFont(font);
9348 // pGrid->SetColLabelTextOrientation(wxVERTICAL);
9350 void wxGrid::SetColLabelTextOrientation( int textOrientation
)
9352 if ( textOrientation
== wxHORIZONTAL
|| textOrientation
== wxVERTICAL
)
9353 m_colLabelTextOrientation
= textOrientation
;
9355 if ( !GetBatchCount() )
9356 m_colLabelWin
->Refresh();
9359 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
9363 m_table
->SetRowLabelValue( row
, s
);
9364 if ( !GetBatchCount() )
9366 wxRect rect
= CellToRect( row
, 0 );
9367 if ( rect
.height
> 0 )
9369 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
9371 rect
.width
= m_rowLabelWidth
;
9372 m_rowLabelWin
->Refresh( true, &rect
);
9378 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
9382 m_table
->SetColLabelValue( col
, s
);
9383 if ( !GetBatchCount() )
9385 wxRect rect
= CellToRect( 0, col
);
9386 if ( rect
.width
> 0 )
9388 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
9390 rect
.height
= m_colLabelHeight
;
9391 m_colLabelWin
->Refresh( true, &rect
);
9397 void wxGrid::SetGridLineColour( const wxColour
& colour
)
9399 if ( m_gridLineColour
!= colour
)
9401 m_gridLineColour
= colour
;
9403 wxClientDC
dc( m_gridWin
);
9405 DrawAllGridLines( dc
, wxRegion() );
9409 void wxGrid::SetCellHighlightColour( const wxColour
& colour
)
9411 if ( m_cellHighlightColour
!= colour
)
9413 m_cellHighlightColour
= colour
;
9415 wxClientDC
dc( m_gridWin
);
9417 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
9418 DrawCellHighlight(dc
, attr
);
9423 void wxGrid::SetCellHighlightPenWidth(int width
)
9425 if (m_cellHighlightPenWidth
!= width
)
9427 m_cellHighlightPenWidth
= width
;
9429 // Just redrawing the cell highlight is not enough since that won't
9430 // make any visible change if the the thickness is getting smaller.
9431 int row
= m_currentCellCoords
.GetRow();
9432 int col
= m_currentCellCoords
.GetCol();
9433 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
9436 wxRect rect
= CellToRect(row
, col
);
9437 m_gridWin
->Refresh(true, &rect
);
9441 void wxGrid::SetCellHighlightROPenWidth(int width
)
9443 if (m_cellHighlightROPenWidth
!= width
)
9445 m_cellHighlightROPenWidth
= width
;
9447 // Just redrawing the cell highlight is not enough since that won't
9448 // make any visible change if the the thickness is getting smaller.
9449 int row
= m_currentCellCoords
.GetRow();
9450 int col
= m_currentCellCoords
.GetCol();
9451 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
9454 wxRect rect
= CellToRect(row
, col
);
9455 m_gridWin
->Refresh(true, &rect
);
9459 void wxGrid::EnableGridLines( bool enable
)
9461 if ( enable
!= m_gridLinesEnabled
)
9463 m_gridLinesEnabled
= enable
;
9465 if ( !GetBatchCount() )
9469 wxClientDC
dc( m_gridWin
);
9471 DrawAllGridLines( dc
, wxRegion() );
9475 m_gridWin
->Refresh();
9481 int wxGrid::GetDefaultRowSize()
9483 return m_defaultRowHeight
;
9486 int wxGrid::GetRowSize( int row
)
9488 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
9490 return GetRowHeight(row
);
9493 int wxGrid::GetDefaultColSize()
9495 return m_defaultColWidth
;
9498 int wxGrid::GetColSize( int col
)
9500 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
9502 return GetColWidth(col
);
9505 // ============================================================================
9506 // access to the grid attributes: each of them has a default value in the grid
9507 // itself and may be overidden on a per-cell basis
9508 // ============================================================================
9510 // ----------------------------------------------------------------------------
9511 // setting default attributes
9512 // ----------------------------------------------------------------------------
9514 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
9516 m_defaultCellAttr
->SetBackgroundColour(col
);
9518 m_gridWin
->SetBackgroundColour(col
);
9522 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
9524 m_defaultCellAttr
->SetTextColour(col
);
9527 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
9529 m_defaultCellAttr
->SetAlignment(horiz
, vert
);
9532 void wxGrid::SetDefaultCellOverflow( bool allow
)
9534 m_defaultCellAttr
->SetOverflow(allow
);
9537 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
9539 m_defaultCellAttr
->SetFont(font
);
9542 // For editors and renderers the type registry takes precedence over the
9543 // default attr, so we need to register the new editor/renderer for the string
9544 // data type in order to make setting a default editor/renderer appear to
9547 void wxGrid::SetDefaultRenderer(wxGridCellRenderer
*renderer
)
9549 RegisterDataType(wxGRID_VALUE_STRING
,
9551 GetDefaultEditorForType(wxGRID_VALUE_STRING
));
9554 void wxGrid::SetDefaultEditor(wxGridCellEditor
*editor
)
9556 RegisterDataType(wxGRID_VALUE_STRING
,
9557 GetDefaultRendererForType(wxGRID_VALUE_STRING
),
9561 // ----------------------------------------------------------------------------
9562 // access to the default attrbiutes
9563 // ----------------------------------------------------------------------------
9565 wxColour
wxGrid::GetDefaultCellBackgroundColour()
9567 return m_defaultCellAttr
->GetBackgroundColour();
9570 wxColour
wxGrid::GetDefaultCellTextColour()
9572 return m_defaultCellAttr
->GetTextColour();
9575 wxFont
wxGrid::GetDefaultCellFont()
9577 return m_defaultCellAttr
->GetFont();
9580 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
9582 m_defaultCellAttr
->GetAlignment(horiz
, vert
);
9585 bool wxGrid::GetDefaultCellOverflow()
9587 return m_defaultCellAttr
->GetOverflow();
9590 wxGridCellRenderer
*wxGrid::GetDefaultRenderer() const
9592 return m_defaultCellAttr
->GetRenderer(NULL
, 0, 0);
9595 wxGridCellEditor
*wxGrid::GetDefaultEditor() const
9597 return m_defaultCellAttr
->GetEditor(NULL
, 0, 0);
9600 // ----------------------------------------------------------------------------
9601 // access to cell attributes
9602 // ----------------------------------------------------------------------------
9604 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
9606 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
9607 wxColour colour
= attr
->GetBackgroundColour();
9613 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
9615 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
9616 wxColour colour
= attr
->GetTextColour();
9622 wxFont
wxGrid::GetCellFont( int row
, int col
)
9624 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
9625 wxFont font
= attr
->GetFont();
9631 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
9633 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
9634 attr
->GetAlignment(horiz
, vert
);
9638 bool wxGrid::GetCellOverflow( int row
, int col
)
9640 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
9641 bool allow
= attr
->GetOverflow();
9647 void wxGrid::GetCellSize( int row
, int col
, int *num_rows
, int *num_cols
)
9649 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
9650 attr
->GetSize( num_rows
, num_cols
);
9654 wxGridCellRenderer
* wxGrid::GetCellRenderer(int row
, int col
)
9656 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
9657 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
9663 wxGridCellEditor
* wxGrid::GetCellEditor(int row
, int col
)
9665 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
9666 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
9672 bool wxGrid::IsReadOnly(int row
, int col
) const
9674 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
9675 bool isReadOnly
= attr
->IsReadOnly();
9681 // ----------------------------------------------------------------------------
9682 // attribute support: cache, automatic provider creation, ...
9683 // ----------------------------------------------------------------------------
9685 bool wxGrid::CanHaveAttributes()
9692 return m_table
->CanHaveAttributes();
9695 void wxGrid::ClearAttrCache()
9697 if ( m_attrCache
.row
!= -1 )
9699 wxSafeDecRef(m_attrCache
.attr
);
9700 m_attrCache
.attr
= NULL
;
9701 m_attrCache
.row
= -1;
9705 void wxGrid::CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const
9709 wxGrid
*self
= (wxGrid
*)this; // const_cast
9711 self
->ClearAttrCache();
9712 self
->m_attrCache
.row
= row
;
9713 self
->m_attrCache
.col
= col
;
9714 self
->m_attrCache
.attr
= attr
;
9719 bool wxGrid::LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const
9721 if ( row
== m_attrCache
.row
&& col
== m_attrCache
.col
)
9723 *attr
= m_attrCache
.attr
;
9724 wxSafeIncRef(m_attrCache
.attr
);
9726 #ifdef DEBUG_ATTR_CACHE
9727 gs_nAttrCacheHits
++;
9734 #ifdef DEBUG_ATTR_CACHE
9735 gs_nAttrCacheMisses
++;
9742 wxGridCellAttr
*wxGrid::GetCellAttr(int row
, int col
) const
9744 wxGridCellAttr
*attr
= NULL
;
9745 // Additional test to avoid looking at the cache e.g. for
9746 // wxNoCellCoords, as this will confuse memory management.
9749 if ( !LookupAttr(row
, col
, &attr
) )
9751 attr
= m_table
? m_table
->GetAttr(row
, col
, wxGridCellAttr::Any
)
9752 : (wxGridCellAttr
*)NULL
;
9753 CacheAttr(row
, col
, attr
);
9759 attr
->SetDefAttr(m_defaultCellAttr
);
9763 attr
= m_defaultCellAttr
;
9770 wxGridCellAttr
*wxGrid::GetOrCreateCellAttr(int row
, int col
) const
9772 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
9773 bool canHave
= ((wxGrid
*)this)->CanHaveAttributes();
9775 wxCHECK_MSG( canHave
, attr
, _T("Cell attributes not allowed"));
9776 wxCHECK_MSG( m_table
, attr
, _T("must have a table") );
9778 attr
= m_table
->GetAttr(row
, col
, wxGridCellAttr::Cell
);
9781 attr
= new wxGridCellAttr(m_defaultCellAttr
);
9783 // artificially inc the ref count to match DecRef() in caller
9785 m_table
->SetAttr(attr
, row
, col
);
9791 // ----------------------------------------------------------------------------
9792 // setting column attributes (wrappers around SetColAttr)
9793 // ----------------------------------------------------------------------------
9795 void wxGrid::SetColFormatBool(int col
)
9797 SetColFormatCustom(col
, wxGRID_VALUE_BOOL
);
9800 void wxGrid::SetColFormatNumber(int col
)
9802 SetColFormatCustom(col
, wxGRID_VALUE_NUMBER
);
9805 void wxGrid::SetColFormatFloat(int col
, int width
, int precision
)
9807 wxString typeName
= wxGRID_VALUE_FLOAT
;
9808 if ( (width
!= -1) || (precision
!= -1) )
9810 typeName
<< _T(':') << width
<< _T(',') << precision
;
9813 SetColFormatCustom(col
, typeName
);
9816 void wxGrid::SetColFormatCustom(int col
, const wxString
& typeName
)
9818 wxGridCellAttr
*attr
= m_table
->GetAttr(-1, col
, wxGridCellAttr::Col
);
9820 attr
= new wxGridCellAttr
;
9821 wxGridCellRenderer
*renderer
= GetDefaultRendererForType(typeName
);
9822 attr
->SetRenderer(renderer
);
9824 SetColAttr(col
, attr
);
9828 // ----------------------------------------------------------------------------
9829 // setting cell attributes: this is forwarded to the table
9830 // ----------------------------------------------------------------------------
9832 void wxGrid::SetAttr(int row
, int col
, wxGridCellAttr
*attr
)
9834 if ( CanHaveAttributes() )
9836 m_table
->SetAttr(attr
, row
, col
);
9845 void wxGrid::SetRowAttr(int row
, wxGridCellAttr
*attr
)
9847 if ( CanHaveAttributes() )
9849 m_table
->SetRowAttr(attr
, row
);
9858 void wxGrid::SetColAttr(int col
, wxGridCellAttr
*attr
)
9860 if ( CanHaveAttributes() )
9862 m_table
->SetColAttr(attr
, col
);
9871 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
9873 if ( CanHaveAttributes() )
9875 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9876 attr
->SetBackgroundColour(colour
);
9881 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
9883 if ( CanHaveAttributes() )
9885 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9886 attr
->SetTextColour(colour
);
9891 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
9893 if ( CanHaveAttributes() )
9895 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9896 attr
->SetFont(font
);
9901 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
9903 if ( CanHaveAttributes() )
9905 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9906 attr
->SetAlignment(horiz
, vert
);
9911 void wxGrid::SetCellOverflow( int row
, int col
, bool allow
)
9913 if ( CanHaveAttributes() )
9915 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9916 attr
->SetOverflow(allow
);
9921 void wxGrid::SetCellSize( int row
, int col
, int num_rows
, int num_cols
)
9923 if ( CanHaveAttributes() )
9925 int cell_rows
, cell_cols
;
9927 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9928 attr
->GetSize(&cell_rows
, &cell_cols
);
9929 attr
->SetSize(num_rows
, num_cols
);
9932 // Cannot set the size of a cell to 0 or negative values
9933 // While it is perfectly legal to do that, this function cannot
9934 // handle all the possibilies, do it by hand by getting the CellAttr.
9935 // You can only set the size of a cell to 1,1 or greater with this fn
9936 wxASSERT_MSG( !((cell_rows
< 1) || (cell_cols
< 1)),
9937 wxT("wxGrid::SetCellSize setting cell size that is already part of another cell"));
9938 wxASSERT_MSG( !((num_rows
< 1) || (num_cols
< 1)),
9939 wxT("wxGrid::SetCellSize setting cell size to < 1"));
9941 // if this was already a multicell then "turn off" the other cells first
9942 if ((cell_rows
> 1) || (cell_rows
> 1))
9945 for (j
=row
; j
< row
+ cell_rows
; j
++)
9947 for (i
=col
; i
< col
+ cell_cols
; i
++)
9949 if ((i
!= col
) || (j
!= row
))
9951 wxGridCellAttr
*attr_stub
= GetOrCreateCellAttr(j
, i
);
9952 attr_stub
->SetSize( 1, 1 );
9953 attr_stub
->DecRef();
9959 // mark the cells that will be covered by this cell to
9960 // negative or zero values to point back at this cell
9961 if (((num_rows
> 1) || (num_cols
> 1)) && (num_rows
>= 1) && (num_cols
>= 1))
9964 for (j
=row
; j
< row
+ num_rows
; j
++)
9966 for (i
=col
; i
< col
+ num_cols
; i
++)
9968 if ((i
!= col
) || (j
!= row
))
9970 wxGridCellAttr
*attr_stub
= GetOrCreateCellAttr(j
, i
);
9971 attr_stub
->SetSize( row
- j
, col
- i
);
9972 attr_stub
->DecRef();
9980 void wxGrid::SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
)
9982 if ( CanHaveAttributes() )
9984 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9985 attr
->SetRenderer(renderer
);
9990 void wxGrid::SetCellEditor(int row
, int col
, wxGridCellEditor
* editor
)
9992 if ( CanHaveAttributes() )
9994 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9995 attr
->SetEditor(editor
);
10000 void wxGrid::SetReadOnly(int row
, int col
, bool isReadOnly
)
10002 if ( CanHaveAttributes() )
10004 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
10005 attr
->SetReadOnly(isReadOnly
);
10010 // ----------------------------------------------------------------------------
10011 // Data type registration
10012 // ----------------------------------------------------------------------------
10014 void wxGrid::RegisterDataType(const wxString
& typeName
,
10015 wxGridCellRenderer
* renderer
,
10016 wxGridCellEditor
* editor
)
10018 m_typeRegistry
->RegisterDataType(typeName
, renderer
, editor
);
10022 wxGridCellEditor
* wxGrid::GetDefaultEditorForCell(int row
, int col
) const
10024 wxString typeName
= m_table
->GetTypeName(row
, col
);
10025 return GetDefaultEditorForType(typeName
);
10028 wxGridCellRenderer
* wxGrid::GetDefaultRendererForCell(int row
, int col
) const
10030 wxString typeName
= m_table
->GetTypeName(row
, col
);
10031 return GetDefaultRendererForType(typeName
);
10034 wxGridCellEditor
* wxGrid::GetDefaultEditorForType(const wxString
& typeName
) const
10036 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
10037 if ( index
== wxNOT_FOUND
)
10041 errStr
.Printf(wxT("Unknown data type name [%s]"), typeName
.c_str());
10042 wxFAIL_MSG(errStr
.c_str());
10047 return m_typeRegistry
->GetEditor(index
);
10050 wxGridCellRenderer
* wxGrid::GetDefaultRendererForType(const wxString
& typeName
) const
10052 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
10053 if ( index
== wxNOT_FOUND
)
10057 errStr
.Printf(wxT("Unknown data type name [%s]"), typeName
.c_str());
10058 wxFAIL_MSG(errStr
.c_str());
10063 return m_typeRegistry
->GetRenderer(index
);
10066 // ----------------------------------------------------------------------------
10068 // ----------------------------------------------------------------------------
10070 void wxGrid::EnableDragRowSize( bool enable
)
10072 m_canDragRowSize
= enable
;
10075 void wxGrid::EnableDragColSize( bool enable
)
10077 m_canDragColSize
= enable
;
10080 void wxGrid::EnableDragGridSize( bool enable
)
10082 m_canDragGridSize
= enable
;
10085 void wxGrid::EnableDragCell( bool enable
)
10087 m_canDragCell
= enable
;
10090 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
10092 m_defaultRowHeight
= wxMax( height
, m_minAcceptableRowHeight
);
10094 if ( resizeExistingRows
)
10096 // since we are resizing all rows to the default row size,
10097 // we can simply clear the row heights and row bottoms
10098 // arrays (which also allows us to take advantage of
10099 // some speed optimisations)
10100 m_rowHeights
.Empty();
10101 m_rowBottoms
.Empty();
10102 if ( !GetBatchCount() )
10107 void wxGrid::SetRowSize( int row
, int height
)
10109 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
10111 // See comment in SetColSize
10112 if ( height
< GetRowMinimalAcceptableHeight())
10115 if ( m_rowHeights
.IsEmpty() )
10117 // need to really create the array
10121 int h
= wxMax( 0, height
);
10122 int diff
= h
- m_rowHeights
[row
];
10124 m_rowHeights
[row
] = h
;
10126 for ( i
= row
; i
< m_numRows
; i
++ )
10128 m_rowBottoms
[i
] += diff
;
10131 if ( !GetBatchCount() )
10135 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
10137 m_defaultColWidth
= wxMax( width
, m_minAcceptableColWidth
);
10139 if ( resizeExistingCols
)
10141 // since we are resizing all columns to the default column size,
10142 // we can simply clear the col widths and col rights
10143 // arrays (which also allows us to take advantage of
10144 // some speed optimisations)
10145 m_colWidths
.Empty();
10146 m_colRights
.Empty();
10147 if ( !GetBatchCount() )
10152 void wxGrid::SetColSize( int col
, int width
)
10154 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
10156 // should we check that it's bigger than GetColMinimalWidth(col) here?
10158 // No, because it is reasonable to assume the library user know's
10159 // what he is doing. However we should test against the weaker
10160 // constraint of minimalAcceptableWidth, as this breaks rendering
10162 // This test then fixes sf.net bug #645734
10164 if ( width
< GetColMinimalAcceptableWidth() )
10167 if ( m_colWidths
.IsEmpty() )
10169 // need to really create the array
10173 // if < 0 then calculate new width from label
10177 wxArrayString lines
;
10178 wxClientDC
dc(m_colLabelWin
);
10179 dc
.SetFont(GetLabelFont());
10180 StringToLines(GetColLabelValue(col
), lines
);
10181 GetTextBoxSize(dc
, lines
, &w
, &h
);
10185 int w
= wxMax( 0, width
);
10186 int diff
= w
- m_colWidths
[col
];
10187 m_colWidths
[col
] = w
;
10191 for ( colPos
= GetColPos( col
); colPos
< m_numCols
; colPos
++ )
10193 i
= GetColAt( colPos
);
10194 m_colRights
[i
] += diff
;
10197 if ( !GetBatchCount() )
10201 void wxGrid::SetColMinimalWidth( int col
, int width
)
10203 if (width
> GetColMinimalAcceptableWidth())
10205 wxLongToLongHashMap::key_type key
= (wxLongToLongHashMap::key_type
)col
;
10206 m_colMinWidths
[key
] = width
;
10210 void wxGrid::SetRowMinimalHeight( int row
, int width
)
10212 if (width
> GetRowMinimalAcceptableHeight())
10214 wxLongToLongHashMap::key_type key
= (wxLongToLongHashMap::key_type
)row
;
10215 m_rowMinHeights
[key
] = width
;
10219 int wxGrid::GetColMinimalWidth(int col
) const
10221 wxLongToLongHashMap::key_type key
= (wxLongToLongHashMap::key_type
)col
;
10222 wxLongToLongHashMap::const_iterator it
= m_colMinWidths
.find(key
);
10224 return it
!= m_colMinWidths
.end() ? (int)it
->second
: m_minAcceptableColWidth
;
10227 int wxGrid::GetRowMinimalHeight(int row
) const
10229 wxLongToLongHashMap::key_type key
= (wxLongToLongHashMap::key_type
)row
;
10230 wxLongToLongHashMap::const_iterator it
= m_rowMinHeights
.find(key
);
10232 return it
!= m_rowMinHeights
.end() ? (int)it
->second
: m_minAcceptableRowHeight
;
10235 void wxGrid::SetColMinimalAcceptableWidth( int width
)
10237 // We do allow a width of 0 since this gives us
10238 // an easy way to temporarily hiding columns.
10240 m_minAcceptableColWidth
= width
;
10243 void wxGrid::SetRowMinimalAcceptableHeight( int height
)
10245 // We do allow a height of 0 since this gives us
10246 // an easy way to temporarily hiding rows.
10248 m_minAcceptableRowHeight
= height
;
10251 int wxGrid::GetColMinimalAcceptableWidth() const
10253 return m_minAcceptableColWidth
;
10256 int wxGrid::GetRowMinimalAcceptableHeight() const
10258 return m_minAcceptableRowHeight
;
10261 // ----------------------------------------------------------------------------
10263 // ----------------------------------------------------------------------------
10265 void wxGrid::AutoSizeColOrRow( int colOrRow
, bool setAsMin
, bool column
)
10267 wxClientDC
dc(m_gridWin
);
10269 // cancel editing of cell
10270 HideCellEditControl();
10271 SaveEditControlValue();
10273 // init both of them to avoid compiler warnings, even if we only need one
10281 wxCoord extent
, extentMax
= 0;
10282 int max
= column
? m_numRows
: m_numCols
;
10283 for ( int rowOrCol
= 0; rowOrCol
< max
; rowOrCol
++ )
10290 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
10291 wxGridCellRenderer
*renderer
= attr
->GetRenderer(this, row
, col
);
10294 wxSize size
= renderer
->GetBestSize(*this, *attr
, dc
, row
, col
);
10295 extent
= column
? size
.x
: size
.y
;
10296 if ( extent
> extentMax
)
10297 extentMax
= extent
;
10299 renderer
->DecRef();
10305 // now also compare with the column label extent
10307 dc
.SetFont( GetLabelFont() );
10311 dc
.GetTextExtent( GetColLabelValue(col
), &w
, &h
);
10312 if ( GetColLabelTextOrientation() == wxVERTICAL
)
10316 dc
.GetTextExtent( GetRowLabelValue(row
), &w
, &h
);
10318 extent
= column
? w
: h
;
10319 if ( extent
> extentMax
)
10320 extentMax
= extent
;
10324 // empty column - give default extent (notice that if extentMax is less
10325 // than default extent but != 0, it's OK)
10326 extentMax
= column
? m_defaultColWidth
: m_defaultRowHeight
;
10331 // leave some space around text
10339 SetColSize( col
, extentMax
);
10340 if ( !GetBatchCount() )
10343 m_gridWin
->GetClientSize( &cw
, &ch
);
10344 wxRect
rect ( CellToRect( 0, col
) );
10346 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
10347 rect
.width
= cw
- rect
.x
;
10348 rect
.height
= m_colLabelHeight
;
10349 m_colLabelWin
->Refresh( true, &rect
);
10354 SetRowSize(row
, extentMax
);
10355 if ( !GetBatchCount() )
10358 m_gridWin
->GetClientSize( &cw
, &ch
);
10359 wxRect
rect( CellToRect( row
, 0 ) );
10361 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
10362 rect
.width
= m_rowLabelWidth
;
10363 rect
.height
= ch
- rect
.y
;
10364 m_rowLabelWin
->Refresh( true, &rect
);
10371 SetColMinimalWidth(col
, extentMax
);
10373 SetRowMinimalHeight(row
, extentMax
);
10377 int wxGrid::SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
)
10379 int width
= m_rowLabelWidth
;
10384 for ( int col
= 0; col
< m_numCols
; col
++ )
10387 AutoSizeColumn(col
, setAsMin
);
10389 width
+= GetColWidth(col
);
10398 int wxGrid::SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
)
10400 int height
= m_colLabelHeight
;
10405 for ( int row
= 0; row
< m_numRows
; row
++ )
10408 AutoSizeRow(row
, setAsMin
);
10410 height
+= GetRowHeight(row
);
10419 void wxGrid::AutoSize()
10423 wxSize
size(SetOrCalcColumnSizes(false), SetOrCalcRowSizes(false));
10425 // round up the size to a multiple of scroll step - this ensures that we
10426 // won't get the scrollbars if we're sized exactly to this width
10427 // CalcDimension adds m_extraWidth + 1 etc. to calculate the necessary
10430 GetScrollX(size
.x
+ m_extraWidth
+ 1) * m_scrollLineX
,
10431 GetScrollY(size
.y
+ m_extraHeight
+ 1) * m_scrollLineY
);
10433 // distribute the extra space between the columns/rows to avoid having
10434 // extra white space
10436 // Remove the extra m_extraWidth + 1 added above
10437 wxCoord diff
= sizeFit
.x
- size
.x
+ (m_extraWidth
+ 1);
10438 if ( diff
&& m_numCols
)
10440 // try to resize the columns uniformly
10441 wxCoord diffPerCol
= diff
/ m_numCols
;
10444 for ( int col
= 0; col
< m_numCols
; col
++ )
10446 SetColSize(col
, GetColWidth(col
) + diffPerCol
);
10450 // add remaining amount to the last columns
10451 diff
-= diffPerCol
* m_numCols
;
10454 for ( int col
= m_numCols
- 1; col
>= m_numCols
- diff
; col
-- )
10456 SetColSize(col
, GetColWidth(col
) + 1);
10462 diff
= sizeFit
.y
- size
.y
- (m_extraHeight
+ 1);
10463 if ( diff
&& m_numRows
)
10465 // try to resize the columns uniformly
10466 wxCoord diffPerRow
= diff
/ m_numRows
;
10469 for ( int row
= 0; row
< m_numRows
; row
++ )
10471 SetRowSize(row
, GetRowHeight(row
) + diffPerRow
);
10475 // add remaining amount to the last rows
10476 diff
-= diffPerRow
* m_numRows
;
10479 for ( int row
= m_numRows
- 1; row
>= m_numRows
- diff
; row
-- )
10481 SetRowSize(row
, GetRowHeight(row
) + 1);
10488 SetClientSize(sizeFit
);
10491 void wxGrid::AutoSizeRowLabelSize( int row
)
10493 wxArrayString lines
;
10496 // Hide the edit control, so it
10497 // won't interfere with drag-shrinking.
10498 if ( IsCellEditControlShown() )
10500 HideCellEditControl();
10501 SaveEditControlValue();
10504 // autosize row height depending on label text
10505 StringToLines( GetRowLabelValue( row
), lines
);
10506 wxClientDC
dc( m_rowLabelWin
);
10507 GetTextBoxSize( dc
, lines
, &w
, &h
);
10508 if ( h
< m_defaultRowHeight
)
10509 h
= m_defaultRowHeight
;
10510 SetRowSize(row
, h
);
10514 void wxGrid::AutoSizeColLabelSize( int col
)
10516 wxArrayString lines
;
10519 // Hide the edit control, so it
10520 // won't interfere with drag-shrinking.
10521 if ( IsCellEditControlShown() )
10523 HideCellEditControl();
10524 SaveEditControlValue();
10527 // autosize column width depending on label text
10528 StringToLines( GetColLabelValue( col
), lines
);
10529 wxClientDC
dc( m_colLabelWin
);
10530 if ( GetColLabelTextOrientation() == wxHORIZONTAL
)
10531 GetTextBoxSize( dc
, lines
, &w
, &h
);
10533 GetTextBoxSize( dc
, lines
, &h
, &w
);
10534 if ( w
< m_defaultColWidth
)
10535 w
= m_defaultColWidth
;
10536 SetColSize(col
, w
);
10540 wxSize
wxGrid::DoGetBestSize() const
10542 // don't set sizes, only calculate them
10543 wxGrid
*self
= (wxGrid
*)this; // const_cast
10546 width
= self
->SetOrCalcColumnSizes(true);
10547 height
= self
->SetOrCalcRowSizes(true);
10554 // Round up to a multiple the scroll rate
10555 // NOTE: this still doesn't get rid of the scrollbars;
10556 // is there any magic incantation for that?
10558 GetScrollPixelsPerUnit(&xpu
, &ypu
);
10560 width
+= 1 + xpu
- (width
% xpu
);
10562 height
+= 1 + ypu
- (height
% ypu
);
10564 // limit to 1/4 of the screen size
10565 int maxwidth
, maxheight
;
10566 wxDisplaySize( &maxwidth
, &maxheight
);
10569 if ( width
> maxwidth
)
10571 if ( height
> maxheight
)
10572 height
= maxheight
;
10574 wxSize
best(width
, height
);
10576 // NOTE: This size should be cached, but first we need to add calls to
10577 // InvalidateBestSize everywhere that could change the results of this
10579 // CacheBestSize(size);
10589 wxPen
& wxGrid::GetDividerPen() const
10594 // ----------------------------------------------------------------------------
10595 // cell value accessor functions
10596 // ----------------------------------------------------------------------------
10598 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
10602 m_table
->SetValue( row
, col
, s
);
10603 if ( !GetBatchCount() )
10606 wxRect
rect( CellToRect( row
, col
) );
10608 rect
.width
= m_gridWin
->GetClientSize().GetWidth();
10609 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
10610 m_gridWin
->Refresh( false, &rect
);
10613 if ( m_currentCellCoords
.GetRow() == row
&&
10614 m_currentCellCoords
.GetCol() == col
&&
10615 IsCellEditControlShown())
10616 // Note: If we are using IsCellEditControlEnabled,
10617 // this interacts badly with calling SetCellValue from
10618 // an EVT_GRID_CELL_CHANGE handler.
10620 HideCellEditControl();
10621 ShowCellEditControl(); // will reread data from table
10626 // ----------------------------------------------------------------------------
10627 // block, row and column selection
10628 // ----------------------------------------------------------------------------
10630 void wxGrid::SelectRow( int row
, bool addToSelected
)
10632 if ( IsSelection() && !addToSelected
)
10636 m_selection
->SelectRow( row
, false, addToSelected
);
10639 void wxGrid::SelectCol( int col
, bool addToSelected
)
10641 if ( IsSelection() && !addToSelected
)
10645 m_selection
->SelectCol( col
, false, addToSelected
);
10648 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
,
10649 bool addToSelected
)
10651 if ( IsSelection() && !addToSelected
)
10655 m_selection
->SelectBlock( topRow
, leftCol
, bottomRow
, rightCol
,
10656 false, addToSelected
);
10659 void wxGrid::SelectAll()
10661 if ( m_numRows
> 0 && m_numCols
> 0 )
10664 m_selection
->SelectBlock( 0, 0, m_numRows
- 1, m_numCols
- 1 );
10668 // ----------------------------------------------------------------------------
10669 // cell, row and col deselection
10670 // ----------------------------------------------------------------------------
10672 void wxGrid::DeselectRow( int row
)
10674 if ( !m_selection
)
10677 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectRows
)
10679 if ( m_selection
->IsInSelection(row
, 0 ) )
10680 m_selection
->ToggleCellSelection(row
, 0);
10684 int nCols
= GetNumberCols();
10685 for ( int i
= 0; i
< nCols
; i
++ )
10687 if ( m_selection
->IsInSelection(row
, i
) )
10688 m_selection
->ToggleCellSelection(row
, i
);
10693 void wxGrid::DeselectCol( int col
)
10695 if ( !m_selection
)
10698 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectColumns
)
10700 if ( m_selection
->IsInSelection(0, col
) )
10701 m_selection
->ToggleCellSelection(0, col
);
10705 int nRows
= GetNumberRows();
10706 for ( int i
= 0; i
< nRows
; i
++ )
10708 if ( m_selection
->IsInSelection(i
, col
) )
10709 m_selection
->ToggleCellSelection(i
, col
);
10714 void wxGrid::DeselectCell( int row
, int col
)
10716 if ( m_selection
&& m_selection
->IsInSelection(row
, col
) )
10717 m_selection
->ToggleCellSelection(row
, col
);
10720 bool wxGrid::IsSelection()
10722 return ( m_selection
&& (m_selection
->IsSelection() ||
10723 ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
10724 m_selectingBottomRight
!= wxGridNoCellCoords
) ) );
10727 bool wxGrid::IsInSelection( int row
, int col
) const
10729 return ( m_selection
&& (m_selection
->IsInSelection( row
, col
) ||
10730 ( row
>= m_selectingTopLeft
.GetRow() &&
10731 col
>= m_selectingTopLeft
.GetCol() &&
10732 row
<= m_selectingBottomRight
.GetRow() &&
10733 col
<= m_selectingBottomRight
.GetCol() )) );
10736 wxGridCellCoordsArray
wxGrid::GetSelectedCells() const
10740 wxGridCellCoordsArray a
;
10744 return m_selection
->m_cellSelection
;
10747 wxGridCellCoordsArray
wxGrid::GetSelectionBlockTopLeft() const
10751 wxGridCellCoordsArray a
;
10755 return m_selection
->m_blockSelectionTopLeft
;
10758 wxGridCellCoordsArray
wxGrid::GetSelectionBlockBottomRight() const
10762 wxGridCellCoordsArray a
;
10766 return m_selection
->m_blockSelectionBottomRight
;
10769 wxArrayInt
wxGrid::GetSelectedRows() const
10777 return m_selection
->m_rowSelection
;
10780 wxArrayInt
wxGrid::GetSelectedCols() const
10788 return m_selection
->m_colSelection
;
10791 void wxGrid::ClearSelection()
10793 m_selectingTopLeft
= wxGridNoCellCoords
;
10794 m_selectingBottomRight
= wxGridNoCellCoords
;
10796 m_selection
->ClearSelection();
10799 // This function returns the rectangle that encloses the given block
10800 // in device coords clipped to the client size of the grid window.
10802 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
10803 const wxGridCellCoords
&bottomRight
)
10805 wxRect
rect( wxGridNoCellRect
);
10808 cellRect
= CellToRect( topLeft
);
10809 if ( cellRect
!= wxGridNoCellRect
)
10815 rect
= wxRect(0, 0, 0, 0);
10818 cellRect
= CellToRect( bottomRight
);
10819 if ( cellRect
!= wxGridNoCellRect
)
10825 return wxGridNoCellRect
;
10829 int left
= rect
.GetLeft();
10830 int top
= rect
.GetTop();
10831 int right
= rect
.GetRight();
10832 int bottom
= rect
.GetBottom();
10834 int leftCol
= topLeft
.GetCol();
10835 int topRow
= topLeft
.GetRow();
10836 int rightCol
= bottomRight
.GetCol();
10837 int bottomRow
= bottomRight
.GetRow();
10845 leftCol
= rightCol
;
10855 topRow
= bottomRow
;
10859 for ( j
= topRow
; j
<= bottomRow
; j
++ )
10861 for ( i
= leftCol
; i
<= rightCol
; i
++ )
10863 if ((j
== topRow
) || (j
== bottomRow
) || (i
== leftCol
) || (i
== rightCol
))
10865 cellRect
= CellToRect( j
, i
);
10867 if (cellRect
.x
< left
)
10869 if (cellRect
.y
< top
)
10871 if (cellRect
.x
+ cellRect
.width
> right
)
10872 right
= cellRect
.x
+ cellRect
.width
;
10873 if (cellRect
.y
+ cellRect
.height
> bottom
)
10874 bottom
= cellRect
.y
+ cellRect
.height
;
10878 i
= rightCol
; // jump over inner cells.
10883 // convert to scrolled coords
10885 CalcScrolledPosition( left
, top
, &left
, &top
);
10886 CalcScrolledPosition( right
, bottom
, &right
, &bottom
);
10889 m_gridWin
->GetClientSize( &cw
, &ch
);
10891 if (right
< 0 || bottom
< 0 || left
> cw
|| top
> ch
)
10892 return wxRect(0,0,0,0);
10894 rect
.SetLeft( wxMax(0, left
) );
10895 rect
.SetTop( wxMax(0, top
) );
10896 rect
.SetRight( wxMin(cw
, right
) );
10897 rect
.SetBottom( wxMin(ch
, bottom
) );
10902 // ----------------------------------------------------------------------------
10903 // grid event classes
10904 // ----------------------------------------------------------------------------
10906 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxNotifyEvent
)
10908 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
10909 int row
, int col
, int x
, int y
, bool sel
,
10910 bool control
, bool shift
, bool alt
, bool meta
)
10911 : wxNotifyEvent( type
, id
)
10918 m_control
= control
;
10923 SetEventObject(obj
);
10927 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxNotifyEvent
)
10929 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
10930 int rowOrCol
, int x
, int y
,
10931 bool control
, bool shift
, bool alt
, bool meta
)
10932 : wxNotifyEvent( type
, id
)
10934 m_rowOrCol
= rowOrCol
;
10937 m_control
= control
;
10942 SetEventObject(obj
);
10946 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxNotifyEvent
)
10948 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
10949 const wxGridCellCoords
& topLeft
,
10950 const wxGridCellCoords
& bottomRight
,
10951 bool sel
, bool control
,
10952 bool shift
, bool alt
, bool meta
)
10953 : wxNotifyEvent( type
, id
)
10955 m_topLeft
= topLeft
;
10956 m_bottomRight
= bottomRight
;
10958 m_control
= control
;
10963 SetEventObject(obj
);
10967 IMPLEMENT_DYNAMIC_CLASS(wxGridEditorCreatedEvent
, wxCommandEvent
)
10969 wxGridEditorCreatedEvent::wxGridEditorCreatedEvent(int id
, wxEventType type
,
10970 wxObject
* obj
, int row
,
10971 int col
, wxControl
* ctrl
)
10972 : wxCommandEvent(type
, id
)
10974 SetEventObject(obj
);
10980 #endif // wxUSE_GRID