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 /////////////////////////////////////////////////////////////////////////////
15 - Replace use of wxINVERT with wxOverlay
16 - Make Begin/EndBatch() the same as the generic Freeze/Thaw()
17 - Review the column reordering code, it's a mess.
18 - Implement row reordering after dealing with the columns.
21 // For compilers that support precompilation, includes "wx/wx.h".
22 #include "wx/wxprec.h"
34 #include "wx/dcclient.h"
35 #include "wx/settings.h"
37 #include "wx/textctrl.h"
38 #include "wx/checkbox.h"
39 #include "wx/combobox.h"
40 #include "wx/valtext.h"
43 #include "wx/listbox.h"
46 #include "wx/textfile.h"
47 #include "wx/spinctrl.h"
48 #include "wx/tokenzr.h"
49 #include "wx/renderer.h"
50 #include "wx/headerctrl.h"
51 #include "wx/hashset.h"
53 #include "wx/generic/gridsel.h"
54 #include "wx/generic/gridctrl.h"
55 #include "wx/generic/grideditors.h"
56 #include "wx/generic/private/grid.h"
58 const char wxGridNameStr
[] = "grid";
60 #if defined(__WXMOTIF__)
61 #define WXUNUSED_MOTIF(identifier) WXUNUSED(identifier)
63 #define WXUNUSED_MOTIF(identifier) identifier
66 #if defined(__WXGTK__)
67 #define WXUNUSED_GTK(identifier) WXUNUSED(identifier)
69 #define WXUNUSED_GTK(identifier) identifier
72 // Required for wxIs... functions
75 WX_DECLARE_HASH_SET_WITH_DECL(int, wxIntegerHash
, wxIntegerEqual
,
76 wxGridFixedIndicesSet
, class WXDLLIMPEXP_ADV
);
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 //#define DEBUG_ATTR_CACHE
84 #ifdef DEBUG_ATTR_CACHE
85 static size_t gs_nAttrCacheHits
= 0;
86 static size_t gs_nAttrCacheMisses
= 0;
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 wxGridCellCoords
wxGridNoCellCoords( -1, -1 );
94 wxRect
wxGridNoCellRect( -1, -1, -1, -1 );
100 const size_t GRID_SCROLL_LINE_X
= 15;
101 const size_t GRID_SCROLL_LINE_Y
= GRID_SCROLL_LINE_X
;
103 // the size of hash tables used a bit everywhere (the max number of elements
104 // in these hash tables is the number of rows/columns)
105 const int GRID_HASH_SIZE
= 100;
107 // the minimal distance in pixels the mouse needs to move to start a drag
109 const int DRAG_SENSITIVITY
= 3;
111 } // anonymous namespace
113 #include "wx/arrimpl.cpp"
115 WX_DEFINE_OBJARRAY(wxGridCellCoordsArray
)
116 WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray
)
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
122 wxDEFINE_EVENT( wxEVT_GRID_CELL_LEFT_CLICK
, wxGridEvent
);
123 wxDEFINE_EVENT( wxEVT_GRID_CELL_RIGHT_CLICK
, wxGridEvent
);
124 wxDEFINE_EVENT( wxEVT_GRID_CELL_LEFT_DCLICK
, wxGridEvent
);
125 wxDEFINE_EVENT( wxEVT_GRID_CELL_RIGHT_DCLICK
, wxGridEvent
);
126 wxDEFINE_EVENT( wxEVT_GRID_CELL_BEGIN_DRAG
, wxGridEvent
);
127 wxDEFINE_EVENT( wxEVT_GRID_LABEL_LEFT_CLICK
, wxGridEvent
);
128 wxDEFINE_EVENT( wxEVT_GRID_LABEL_RIGHT_CLICK
, wxGridEvent
);
129 wxDEFINE_EVENT( wxEVT_GRID_LABEL_LEFT_DCLICK
, wxGridEvent
);
130 wxDEFINE_EVENT( wxEVT_GRID_LABEL_RIGHT_DCLICK
, wxGridEvent
);
131 wxDEFINE_EVENT( wxEVT_GRID_ROW_SIZE
, wxGridSizeEvent
);
132 wxDEFINE_EVENT( wxEVT_GRID_COL_SIZE
, wxGridSizeEvent
);
133 wxDEFINE_EVENT( wxEVT_GRID_COL_MOVE
, wxGridEvent
);
134 wxDEFINE_EVENT( wxEVT_GRID_COL_SORT
, wxGridEvent
);
135 wxDEFINE_EVENT( wxEVT_GRID_RANGE_SELECT
, wxGridRangeSelectEvent
);
136 wxDEFINE_EVENT( wxEVT_GRID_CELL_CHANGING
, wxGridEvent
);
137 wxDEFINE_EVENT( wxEVT_GRID_CELL_CHANGED
, wxGridEvent
);
138 wxDEFINE_EVENT( wxEVT_GRID_SELECT_CELL
, wxGridEvent
);
139 wxDEFINE_EVENT( wxEVT_GRID_EDITOR_SHOWN
, wxGridEvent
);
140 wxDEFINE_EVENT( wxEVT_GRID_EDITOR_HIDDEN
, wxGridEvent
);
141 wxDEFINE_EVENT( wxEVT_GRID_EDITOR_CREATED
, wxGridEditorCreatedEvent
);
143 // ============================================================================
145 // ============================================================================
147 IMPLEMENT_ABSTRACT_CLASS(wxGridCellEditorEvtHandler
, wxEvtHandler
)
149 BEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler
, wxEvtHandler
)
150 EVT_KILL_FOCUS( wxGridCellEditorEvtHandler::OnKillFocus
)
151 EVT_KEY_DOWN( wxGridCellEditorEvtHandler::OnKeyDown
)
152 EVT_CHAR( wxGridCellEditorEvtHandler::OnChar
)
155 BEGIN_EVENT_TABLE(wxGridHeaderCtrl
, wxHeaderCtrl
)
156 EVT_HEADER_CLICK(wxID_ANY
, wxGridHeaderCtrl::OnClick
)
158 EVT_HEADER_BEGIN_RESIZE(wxID_ANY
, wxGridHeaderCtrl::OnBeginResize
)
159 EVT_HEADER_RESIZING(wxID_ANY
, wxGridHeaderCtrl::OnResizing
)
160 EVT_HEADER_END_RESIZE(wxID_ANY
, wxGridHeaderCtrl::OnEndResize
)
162 EVT_HEADER_BEGIN_REORDER(wxID_ANY
, wxGridHeaderCtrl::OnBeginReorder
)
163 EVT_HEADER_END_REORDER(wxID_ANY
, wxGridHeaderCtrl::OnEndReorder
)
166 wxGridOperations
& wxGridRowOperations::Dual() const
168 static wxGridColumnOperations s_colOper
;
173 wxGridOperations
& wxGridColumnOperations::Dual() const
175 static wxGridRowOperations s_rowOper
;
180 // ----------------------------------------------------------------------------
181 // wxGridCellWorker is an (almost) empty common base class for
182 // wxGridCellRenderer and wxGridCellEditor managing ref counting
183 // ----------------------------------------------------------------------------
185 void wxGridCellWorker::SetParameters(const wxString
& WXUNUSED(params
))
190 wxGridCellWorker::~wxGridCellWorker()
194 // ----------------------------------------------------------------------------
195 // wxGridHeaderLabelsRenderer and related classes
196 // ----------------------------------------------------------------------------
198 void wxGridHeaderLabelsRenderer::DrawLabel(const wxGrid
& grid
,
200 const wxString
& value
,
204 int textOrientation
) const
206 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
207 dc
.SetTextForeground(grid
.GetLabelTextColour());
208 dc
.SetFont(grid
.GetLabelFont());
209 grid
.DrawTextRectangle(dc
, value
, rect
, horizAlign
, vertAlign
, textOrientation
);
213 void wxGridRowHeaderRendererDefault::DrawBorder(const wxGrid
& WXUNUSED(grid
),
217 dc
.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
)));
218 dc
.DrawLine(rect
.GetRight(), rect
.GetTop(),
219 rect
.GetRight(), rect
.GetBottom());
220 dc
.DrawLine(rect
.GetLeft(), rect
.GetTop(),
221 rect
.GetLeft(), rect
.GetBottom());
222 dc
.DrawLine(rect
.GetLeft(), rect
.GetBottom(),
223 rect
.GetRight() + 1, rect
.GetBottom());
225 dc
.SetPen(*wxWHITE_PEN
);
226 dc
.DrawLine(rect
.GetLeft() + 1, rect
.GetTop(),
227 rect
.GetLeft() + 1, rect
.GetBottom());
228 dc
.DrawLine(rect
.GetLeft() + 1, rect
.GetTop(),
229 rect
.GetRight(), rect
.GetTop());
234 void wxGridColumnHeaderRendererDefault::DrawBorder(const wxGrid
& WXUNUSED(grid
),
238 dc
.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
)));
239 dc
.DrawLine(rect
.GetRight(), rect
.GetTop(),
240 rect
.GetRight(), rect
.GetBottom());
241 dc
.DrawLine(rect
.GetLeft(), rect
.GetTop(),
242 rect
.GetRight(), rect
.GetTop());
243 dc
.DrawLine(rect
.GetLeft(), rect
.GetBottom(),
244 rect
.GetRight() + 1, rect
.GetBottom());
246 dc
.SetPen(*wxWHITE_PEN
);
247 dc
.DrawLine(rect
.GetLeft(), rect
.GetTop() + 1,
248 rect
.GetLeft(), rect
.GetBottom());
249 dc
.DrawLine(rect
.GetLeft(), rect
.GetTop() + 1,
250 rect
.GetRight(), rect
.GetTop() + 1);
255 void wxGridCornerHeaderRendererDefault::DrawBorder(const wxGrid
& WXUNUSED(grid
),
259 dc
.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
)));
260 dc
.DrawLine(rect
.GetRight() - 1, rect
.GetBottom() - 1,
261 rect
.GetRight() - 1, rect
.GetTop());
262 dc
.DrawLine(rect
.GetRight() - 1, rect
.GetBottom() - 1,
263 rect
.GetLeft(), rect
.GetBottom() - 1);
264 dc
.DrawLine(rect
.GetLeft(), rect
.GetTop(),
265 rect
.GetRight(), rect
.GetTop());
266 dc
.DrawLine(rect
.GetLeft(), rect
.GetTop(),
267 rect
.GetLeft(), rect
.GetBottom());
269 dc
.SetPen(*wxWHITE_PEN
);
270 dc
.DrawLine(rect
.GetLeft() + 1, rect
.GetTop() + 1,
271 rect
.GetRight() - 1, rect
.GetTop() + 1);
272 dc
.DrawLine(rect
.GetLeft() + 1, rect
.GetTop() + 1,
273 rect
.GetLeft() + 1, rect
.GetBottom() - 1);
278 // ----------------------------------------------------------------------------
280 // ----------------------------------------------------------------------------
282 void wxGridCellAttr::Init(wxGridCellAttr
*attrDefault
)
284 m_isReadOnly
= Unset
;
289 m_attrkind
= wxGridCellAttr::Cell
;
291 m_sizeRows
= m_sizeCols
= 1;
292 m_overflow
= UnsetOverflow
;
294 SetDefAttr(attrDefault
);
297 wxGridCellAttr
*wxGridCellAttr::Clone() const
299 wxGridCellAttr
*attr
= new wxGridCellAttr(m_defGridAttr
);
301 if ( HasTextColour() )
302 attr
->SetTextColour(GetTextColour());
303 if ( HasBackgroundColour() )
304 attr
->SetBackgroundColour(GetBackgroundColour());
306 attr
->SetFont(GetFont());
307 if ( HasAlignment() )
308 attr
->SetAlignment(m_hAlign
, m_vAlign
);
310 attr
->SetSize( m_sizeRows
, m_sizeCols
);
314 attr
->SetRenderer(m_renderer
);
315 m_renderer
->IncRef();
319 attr
->SetEditor(m_editor
);
326 attr
->SetOverflow( m_overflow
== Overflow
);
327 attr
->SetKind( m_attrkind
);
332 void wxGridCellAttr::MergeWith(wxGridCellAttr
*mergefrom
)
334 if ( !HasTextColour() && mergefrom
->HasTextColour() )
335 SetTextColour(mergefrom
->GetTextColour());
336 if ( !HasBackgroundColour() && mergefrom
->HasBackgroundColour() )
337 SetBackgroundColour(mergefrom
->GetBackgroundColour());
338 if ( !HasFont() && mergefrom
->HasFont() )
339 SetFont(mergefrom
->GetFont());
340 if ( !HasAlignment() && mergefrom
->HasAlignment() )
343 mergefrom
->GetAlignment( &hAlign
, &vAlign
);
344 SetAlignment(hAlign
, vAlign
);
346 if ( !HasSize() && mergefrom
->HasSize() )
347 mergefrom
->GetSize( &m_sizeRows
, &m_sizeCols
);
349 // Directly access member functions as GetRender/Editor don't just return
350 // m_renderer/m_editor
352 // Maybe add support for merge of Render and Editor?
353 if (!HasRenderer() && mergefrom
->HasRenderer() )
355 m_renderer
= mergefrom
->m_renderer
;
356 m_renderer
->IncRef();
358 if ( !HasEditor() && mergefrom
->HasEditor() )
360 m_editor
= mergefrom
->m_editor
;
363 if ( !HasReadWriteMode() && mergefrom
->HasReadWriteMode() )
364 SetReadOnly(mergefrom
->IsReadOnly());
366 if (!HasOverflowMode() && mergefrom
->HasOverflowMode() )
367 SetOverflow(mergefrom
->GetOverflow());
369 SetDefAttr(mergefrom
->m_defGridAttr
);
372 void wxGridCellAttr::SetSize(int num_rows
, int num_cols
)
374 // The size of a cell is normally 1,1
376 // If this cell is larger (2,2) then this is the top left cell
377 // the other cells that will be covered (lower right cells) must be
378 // set to negative or zero values such that
379 // row + num_rows of the covered cell points to the larger cell (this cell)
380 // same goes for the col + num_cols.
382 // Size of 0,0 is NOT valid, neither is <=0 and any positive value
384 wxASSERT_MSG( (!((num_rows
> 0) && (num_cols
<= 0)) ||
385 !((num_rows
<= 0) && (num_cols
> 0)) ||
386 !((num_rows
== 0) && (num_cols
== 0))),
387 wxT("wxGridCellAttr::SetSize only takes two postive values or negative/zero values"));
389 m_sizeRows
= num_rows
;
390 m_sizeCols
= num_cols
;
393 const wxColour
& wxGridCellAttr::GetTextColour() const
399 else if (m_defGridAttr
&& m_defGridAttr
!= this)
401 return m_defGridAttr
->GetTextColour();
405 wxFAIL_MSG(wxT("Missing default cell attribute"));
410 const wxColour
& wxGridCellAttr::GetBackgroundColour() const
412 if (HasBackgroundColour())
416 else if (m_defGridAttr
&& m_defGridAttr
!= this)
418 return m_defGridAttr
->GetBackgroundColour();
422 wxFAIL_MSG(wxT("Missing default cell attribute"));
427 const wxFont
& wxGridCellAttr::GetFont() const
433 else if (m_defGridAttr
&& m_defGridAttr
!= this)
435 return m_defGridAttr
->GetFont();
439 wxFAIL_MSG(wxT("Missing default cell attribute"));
444 void wxGridCellAttr::GetAlignment(int *hAlign
, int *vAlign
) const
453 else if (m_defGridAttr
&& m_defGridAttr
!= this)
455 m_defGridAttr
->GetAlignment(hAlign
, vAlign
);
459 wxFAIL_MSG(wxT("Missing default cell attribute"));
463 void wxGridCellAttr::GetSize( int *num_rows
, int *num_cols
) const
466 *num_rows
= m_sizeRows
;
468 *num_cols
= m_sizeCols
;
471 // GetRenderer and GetEditor use a slightly different decision path about
472 // which attribute to use. If a non-default attr object has one then it is
473 // used, otherwise the default editor or renderer is fetched from the grid and
474 // used. It should be the default for the data type of the cell. If it is
475 // NULL (because the table has a type that the grid does not have in its
476 // registry), then the grid's default editor or renderer is used.
478 wxGridCellRenderer
* wxGridCellAttr::GetRenderer(const wxGrid
* grid
, int row
, int col
) const
480 wxGridCellRenderer
*renderer
= NULL
;
482 if ( m_renderer
&& this != m_defGridAttr
)
484 // use the cells renderer if it has one
485 renderer
= m_renderer
;
488 else // no non-default cell renderer
490 // get default renderer for the data type
493 // GetDefaultRendererForCell() will do IncRef() for us
494 renderer
= grid
->GetDefaultRendererForCell(row
, col
);
497 if ( renderer
== NULL
)
499 if ( (m_defGridAttr
!= NULL
) && (m_defGridAttr
!= this) )
501 // if we still don't have one then use the grid default
502 // (no need for IncRef() here neither)
503 renderer
= m_defGridAttr
->GetRenderer(NULL
, 0, 0);
505 else // default grid attr
507 // use m_renderer which we had decided not to use initially
508 renderer
= m_renderer
;
515 // we're supposed to always find something
516 wxASSERT_MSG(renderer
, wxT("Missing default cell renderer"));
521 // same as above, except for s/renderer/editor/g
522 wxGridCellEditor
* wxGridCellAttr::GetEditor(const wxGrid
* grid
, int row
, int col
) const
524 wxGridCellEditor
*editor
= NULL
;
526 if ( m_editor
&& this != m_defGridAttr
)
528 // use the cells editor if it has one
532 else // no non default cell editor
534 // get default editor for the data type
537 // GetDefaultEditorForCell() will do IncRef() for us
538 editor
= grid
->GetDefaultEditorForCell(row
, col
);
541 if ( editor
== NULL
)
543 if ( (m_defGridAttr
!= NULL
) && (m_defGridAttr
!= this) )
545 // if we still don't have one then use the grid default
546 // (no need for IncRef() here neither)
547 editor
= m_defGridAttr
->GetEditor(NULL
, 0, 0);
549 else // default grid attr
551 // use m_editor which we had decided not to use initially
559 // we're supposed to always find something
560 wxASSERT_MSG(editor
, wxT("Missing default cell editor"));
565 // ----------------------------------------------------------------------------
566 // wxGridCellAttrData
567 // ----------------------------------------------------------------------------
569 void wxGridCellAttrData::SetAttr(wxGridCellAttr
*attr
, int row
, int col
)
571 // Note: contrary to wxGridRowOrColAttrData::SetAttr, we must not
572 // touch attribute's reference counting explicitly, since this
573 // is managed by class wxGridCellWithAttr
574 int n
= FindIndex(row
, col
);
575 if ( n
== wxNOT_FOUND
)
580 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
582 //else: nothing to do
584 else // we already have an attribute for this cell
588 // change the attribute
589 m_attrs
[(size_t)n
].ChangeAttr(attr
);
593 // remove this attribute
594 m_attrs
.RemoveAt((size_t)n
);
599 wxGridCellAttr
*wxGridCellAttrData::GetAttr(int row
, int col
) const
601 wxGridCellAttr
*attr
= NULL
;
603 int n
= FindIndex(row
, col
);
604 if ( n
!= wxNOT_FOUND
)
606 attr
= m_attrs
[(size_t)n
].attr
;
613 void wxGridCellAttrData::UpdateAttrRows( size_t pos
, int numRows
)
615 size_t count
= m_attrs
.GetCount();
616 for ( size_t n
= 0; n
< count
; n
++ )
618 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
619 wxCoord row
= coords
.GetRow();
620 if ((size_t)row
>= pos
)
624 // If rows inserted, include row counter where necessary
625 coords
.SetRow(row
+ numRows
);
627 else if (numRows
< 0)
629 // If rows deleted ...
630 if ((size_t)row
>= pos
- numRows
)
632 // ...either decrement row counter (if row still exists)...
633 coords
.SetRow(row
+ numRows
);
637 // ...or remove the attribute
647 void wxGridCellAttrData::UpdateAttrCols( size_t pos
, int numCols
)
649 size_t count
= m_attrs
.GetCount();
650 for ( size_t n
= 0; n
< count
; n
++ )
652 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
653 wxCoord col
= coords
.GetCol();
654 if ( (size_t)col
>= pos
)
658 // If rows inserted, include row counter where necessary
659 coords
.SetCol(col
+ numCols
);
661 else if (numCols
< 0)
663 // If rows deleted ...
664 if ((size_t)col
>= pos
- numCols
)
666 // ...either decrement row counter (if row still exists)...
667 coords
.SetCol(col
+ numCols
);
671 // ...or remove the attribute
681 int wxGridCellAttrData::FindIndex(int row
, int col
) const
683 size_t count
= m_attrs
.GetCount();
684 for ( size_t n
= 0; n
< count
; n
++ )
686 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
687 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
696 // ----------------------------------------------------------------------------
697 // wxGridRowOrColAttrData
698 // ----------------------------------------------------------------------------
700 wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
702 size_t count
= m_attrs
.GetCount();
703 for ( size_t n
= 0; n
< count
; n
++ )
705 m_attrs
[n
]->DecRef();
709 wxGridCellAttr
*wxGridRowOrColAttrData::GetAttr(int rowOrCol
) const
711 wxGridCellAttr
*attr
= NULL
;
713 int n
= m_rowsOrCols
.Index(rowOrCol
);
714 if ( n
!= wxNOT_FOUND
)
716 attr
= m_attrs
[(size_t)n
];
723 void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr
*attr
, int rowOrCol
)
725 int i
= m_rowsOrCols
.Index(rowOrCol
);
726 if ( i
== wxNOT_FOUND
)
730 // store the new attribute, taking its ownership
731 m_rowsOrCols
.Add(rowOrCol
);
736 else // we have an attribute for this row or column
738 size_t n
= (size_t)i
;
740 // notice that this code works correctly even when the old attribute is
741 // the same as the new one: as we own of it, we must call DecRef() on
742 // it in any case and this won't result in destruction of the new
743 // attribute if it's the same as old one because it must have ref count
744 // of at least 2 to be passed to us while we keep a reference to it too
745 m_attrs
[n
]->DecRef();
749 // replace the attribute with the new one
752 else // remove the attribute
754 m_rowsOrCols
.RemoveAt(n
);
760 void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
)
762 size_t count
= m_attrs
.GetCount();
763 for ( size_t n
= 0; n
< count
; n
++ )
765 int & rowOrCol
= m_rowsOrCols
[n
];
766 if ( (size_t)rowOrCol
>= pos
)
768 if ( numRowsOrCols
> 0 )
770 // If rows inserted, include row counter where necessary
771 rowOrCol
+= numRowsOrCols
;
773 else if ( numRowsOrCols
< 0)
775 // If rows deleted, either decrement row counter (if row still exists)
776 if ((size_t)rowOrCol
>= pos
- numRowsOrCols
)
777 rowOrCol
+= numRowsOrCols
;
780 m_rowsOrCols
.RemoveAt(n
);
781 m_attrs
[n
]->DecRef();
791 // ----------------------------------------------------------------------------
792 // wxGridCellAttrProvider
793 // ----------------------------------------------------------------------------
795 wxGridCellAttrProvider::wxGridCellAttrProvider()
800 wxGridCellAttrProvider::~wxGridCellAttrProvider()
805 void wxGridCellAttrProvider::InitData()
807 m_data
= new wxGridCellAttrProviderData
;
810 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
,
811 wxGridCellAttr::wxAttrKind kind
) const
813 wxGridCellAttr
*attr
= NULL
;
818 case (wxGridCellAttr::Any
):
819 // Get cached merge attributes.
820 // Currently not used as no cache implemented as not mutable
821 // attr = m_data->m_mergeAttr.GetAttr(row, col);
824 // Basically implement old version.
825 // Also check merge cache, so we don't have to re-merge every time..
826 wxGridCellAttr
*attrcell
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
827 wxGridCellAttr
*attrrow
= m_data
->m_rowAttrs
.GetAttr(row
);
828 wxGridCellAttr
*attrcol
= m_data
->m_colAttrs
.GetAttr(col
);
830 if ((attrcell
!= attrrow
) && (attrrow
!= attrcol
) && (attrcell
!= attrcol
))
832 // Two or more are non NULL
833 attr
= new wxGridCellAttr
;
834 attr
->SetKind(wxGridCellAttr::Merged
);
836 // Order is important..
839 attr
->MergeWith(attrcell
);
844 attr
->MergeWith(attrcol
);
849 attr
->MergeWith(attrrow
);
853 // store merge attr if cache implemented
855 //m_data->m_mergeAttr.SetAttr(attr, row, col);
859 // one or none is non null return it or null.
878 case (wxGridCellAttr::Cell
):
879 attr
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
882 case (wxGridCellAttr::Col
):
883 attr
= m_data
->m_colAttrs
.GetAttr(col
);
886 case (wxGridCellAttr::Row
):
887 attr
= m_data
->m_rowAttrs
.GetAttr(row
);
892 // (wxGridCellAttr::Default):
893 // (wxGridCellAttr::Merged):
901 void wxGridCellAttrProvider::SetAttr(wxGridCellAttr
*attr
,
907 m_data
->m_cellAttrs
.SetAttr(attr
, row
, col
);
910 void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr
*attr
, int row
)
915 m_data
->m_rowAttrs
.SetAttr(attr
, row
);
918 void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr
*attr
, int col
)
923 m_data
->m_colAttrs
.SetAttr(attr
, col
);
926 void wxGridCellAttrProvider::UpdateAttrRows( size_t pos
, int numRows
)
930 m_data
->m_cellAttrs
.UpdateAttrRows( pos
, numRows
);
932 m_data
->m_rowAttrs
.UpdateAttrRowsOrCols( pos
, numRows
);
936 void wxGridCellAttrProvider::UpdateAttrCols( size_t pos
, int numCols
)
940 m_data
->m_cellAttrs
.UpdateAttrCols( pos
, numCols
);
942 m_data
->m_colAttrs
.UpdateAttrRowsOrCols( pos
, numCols
);
946 // ----------------------------------------------------------------------------
948 // ----------------------------------------------------------------------------
950 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
952 wxGridTableBase::wxGridTableBase()
955 m_attrProvider
= NULL
;
958 wxGridTableBase::~wxGridTableBase()
960 delete m_attrProvider
;
963 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
965 delete m_attrProvider
;
966 m_attrProvider
= attrProvider
;
969 bool wxGridTableBase::CanHaveAttributes()
971 if ( ! GetAttrProvider() )
973 // use the default attr provider by default
974 SetAttrProvider(new wxGridCellAttrProvider
);
980 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
, wxGridCellAttr::wxAttrKind kind
)
982 if ( m_attrProvider
)
983 return m_attrProvider
->GetAttr(row
, col
, kind
);
988 void wxGridTableBase::SetAttr(wxGridCellAttr
* attr
, int row
, int col
)
990 if ( m_attrProvider
)
993 attr
->SetKind(wxGridCellAttr::Cell
);
994 m_attrProvider
->SetAttr(attr
, row
, col
);
998 // as we take ownership of the pointer and don't store it, we must
1004 void wxGridTableBase::SetRowAttr(wxGridCellAttr
*attr
, int row
)
1006 if ( m_attrProvider
)
1008 attr
->SetKind(wxGridCellAttr::Row
);
1009 m_attrProvider
->SetRowAttr(attr
, row
);
1013 // as we take ownership of the pointer and don't store it, we must
1019 void wxGridTableBase::SetColAttr(wxGridCellAttr
*attr
, int col
)
1021 if ( m_attrProvider
)
1023 attr
->SetKind(wxGridCellAttr::Col
);
1024 m_attrProvider
->SetColAttr(attr
, col
);
1028 // as we take ownership of the pointer and don't store it, we must
1034 bool wxGridTableBase::InsertRows( size_t WXUNUSED(pos
),
1035 size_t WXUNUSED(numRows
) )
1037 wxFAIL_MSG( wxT("Called grid table class function InsertRows\nbut your derived table class does not override this function") );
1042 bool wxGridTableBase::AppendRows( size_t WXUNUSED(numRows
) )
1044 wxFAIL_MSG( wxT("Called grid table class function AppendRows\nbut your derived table class does not override this function"));
1049 bool wxGridTableBase::DeleteRows( size_t WXUNUSED(pos
),
1050 size_t WXUNUSED(numRows
) )
1052 wxFAIL_MSG( wxT("Called grid table class function DeleteRows\nbut your derived table class does not override this function"));
1057 bool wxGridTableBase::InsertCols( size_t WXUNUSED(pos
),
1058 size_t WXUNUSED(numCols
) )
1060 wxFAIL_MSG( wxT("Called grid table class function InsertCols\nbut your derived table class does not override this function"));
1065 bool wxGridTableBase::AppendCols( size_t WXUNUSED(numCols
) )
1067 wxFAIL_MSG(wxT("Called grid table class function AppendCols\nbut your derived table class does not override this function"));
1072 bool wxGridTableBase::DeleteCols( size_t WXUNUSED(pos
),
1073 size_t WXUNUSED(numCols
) )
1075 wxFAIL_MSG( wxT("Called grid table class function DeleteCols\nbut your derived table class does not override this function"));
1080 wxString
wxGridTableBase::GetRowLabelValue( int row
)
1084 // RD: Starting the rows at zero confuses users,
1085 // no matter how much it makes sense to us geeks.
1091 wxString
wxGridTableBase::GetColLabelValue( int col
)
1093 // default col labels are:
1094 // cols 0 to 25 : A-Z
1095 // cols 26 to 675 : AA-ZZ
1100 for ( n
= 1; ; n
++ )
1102 s
+= (wxChar
) (wxT('A') + (wxChar
)(col
% 26));
1108 // reverse the string...
1110 for ( i
= 0; i
< n
; i
++ )
1118 wxString
wxGridTableBase::GetTypeName( int WXUNUSED(row
), int WXUNUSED(col
) )
1120 return wxGRID_VALUE_STRING
;
1123 bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row
), int WXUNUSED(col
),
1124 const wxString
& typeName
)
1126 return typeName
== wxGRID_VALUE_STRING
;
1129 bool wxGridTableBase::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
1131 return CanGetValueAs(row
, col
, typeName
);
1134 long wxGridTableBase::GetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
) )
1139 double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
) )
1144 bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
) )
1149 void wxGridTableBase::SetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
),
1150 long WXUNUSED(value
) )
1154 void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
),
1155 double WXUNUSED(value
) )
1159 void wxGridTableBase::SetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
),
1160 bool WXUNUSED(value
) )
1164 void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
1165 const wxString
& WXUNUSED(typeName
) )
1170 void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
1171 const wxString
& WXUNUSED(typeName
),
1172 void* WXUNUSED(value
) )
1176 //////////////////////////////////////////////////////////////////////
1178 // Message class for the grid table to send requests and notifications
1182 wxGridTableMessage::wxGridTableMessage()
1190 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
1191 int commandInt1
, int commandInt2
)
1195 m_comInt1
= commandInt1
;
1196 m_comInt2
= commandInt2
;
1199 //////////////////////////////////////////////////////////////////////
1201 // A basic grid table for string data. An object of this class will
1202 // created by wxGrid if you don't specify an alternative table class.
1205 WX_DEFINE_OBJARRAY(wxGridStringArray
)
1207 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
1209 wxGridStringTable::wxGridStringTable()
1215 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
1218 m_numCols
= numCols
;
1220 m_data
.Alloc( numRows
);
1223 sa
.Alloc( numCols
);
1224 sa
.Add( wxEmptyString
, numCols
);
1226 m_data
.Add( sa
, numRows
);
1229 wxString
wxGridStringTable::GetValue( int row
, int col
)
1231 wxCHECK_MSG( (row
>= 0 && row
< GetNumberRows()) &&
1232 (col
>= 0 && col
< GetNumberCols()),
1234 wxT("invalid row or column index in wxGridStringTable") );
1236 return m_data
[row
][col
];
1239 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& value
)
1241 wxCHECK_RET( (row
>= 0 && row
< GetNumberRows()) &&
1242 (col
>= 0 && col
< GetNumberCols()),
1243 wxT("invalid row or column index in wxGridStringTable") );
1245 m_data
[row
][col
] = value
;
1248 void wxGridStringTable::Clear()
1251 int numRows
, numCols
;
1253 numRows
= m_data
.GetCount();
1256 numCols
= m_data
[0].GetCount();
1258 for ( row
= 0; row
< numRows
; row
++ )
1260 for ( col
= 0; col
< numCols
; col
++ )
1262 m_data
[row
][col
] = wxEmptyString
;
1268 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
1270 size_t curNumRows
= m_data
.GetCount();
1271 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
1272 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
1274 if ( pos
>= curNumRows
)
1276 return AppendRows( numRows
);
1280 sa
.Alloc( curNumCols
);
1281 sa
.Add( wxEmptyString
, curNumCols
);
1282 m_data
.Insert( sa
, pos
, numRows
);
1286 wxGridTableMessage
msg( this,
1287 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
1291 GetView()->ProcessTableMessage( msg
);
1297 bool wxGridStringTable::AppendRows( size_t numRows
)
1299 size_t curNumRows
= m_data
.GetCount();
1300 size_t curNumCols
= ( curNumRows
> 0
1301 ? m_data
[0].GetCount()
1302 : ( GetView() ? GetView()->GetNumberCols() : 0 ) );
1305 if ( curNumCols
> 0 )
1307 sa
.Alloc( curNumCols
);
1308 sa
.Add( wxEmptyString
, curNumCols
);
1311 m_data
.Add( sa
, numRows
);
1315 wxGridTableMessage
msg( this,
1316 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
1319 GetView()->ProcessTableMessage( msg
);
1325 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
1327 size_t curNumRows
= m_data
.GetCount();
1329 if ( pos
>= curNumRows
)
1331 wxFAIL_MSG( wxString::Format
1333 wxT("Called wxGridStringTable::DeleteRows(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu rows"),
1335 (unsigned long)numRows
,
1336 (unsigned long)curNumRows
1342 if ( numRows
> curNumRows
- pos
)
1344 numRows
= curNumRows
- pos
;
1347 if ( numRows
>= curNumRows
)
1353 m_data
.RemoveAt( pos
, numRows
);
1358 wxGridTableMessage
msg( this,
1359 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
1363 GetView()->ProcessTableMessage( msg
);
1369 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
1373 size_t curNumRows
= m_data
.GetCount();
1374 size_t curNumCols
= ( curNumRows
> 0
1375 ? m_data
[0].GetCount()
1376 : ( GetView() ? GetView()->GetNumberCols() : 0 ) );
1378 if ( pos
>= curNumCols
)
1380 return AppendCols( numCols
);
1383 if ( !m_colLabels
.IsEmpty() )
1385 m_colLabels
.Insert( wxEmptyString
, pos
, numCols
);
1388 for ( i
= pos
; i
< pos
+ numCols
; i
++ )
1389 m_colLabels
[i
] = wxGridTableBase::GetColLabelValue( i
);
1392 for ( row
= 0; row
< curNumRows
; row
++ )
1394 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
1396 m_data
[row
].Insert( wxEmptyString
, col
);
1400 m_numCols
+= numCols
;
1404 wxGridTableMessage
msg( this,
1405 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
1409 GetView()->ProcessTableMessage( msg
);
1415 bool wxGridStringTable::AppendCols( size_t numCols
)
1419 size_t curNumRows
= m_data
.GetCount();
1421 for ( row
= 0; row
< curNumRows
; row
++ )
1423 m_data
[row
].Add( wxEmptyString
, numCols
);
1426 m_numCols
+= numCols
;
1430 wxGridTableMessage
msg( this,
1431 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
1434 GetView()->ProcessTableMessage( msg
);
1440 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
1444 size_t curNumRows
= m_data
.GetCount();
1445 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
1446 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
1448 if ( pos
>= curNumCols
)
1450 wxFAIL_MSG( wxString::Format
1452 wxT("Called wxGridStringTable::DeleteCols(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu cols"),
1454 (unsigned long)numCols
,
1455 (unsigned long)curNumCols
1462 colID
= GetView()->GetColAt( pos
);
1466 if ( numCols
> curNumCols
- colID
)
1468 numCols
= curNumCols
- colID
;
1471 if ( !m_colLabels
.IsEmpty() )
1473 // m_colLabels stores just as many elements as it needs, e.g. if only
1474 // the label of the first column had been set it would have only one
1475 // element and not numCols, so account for it
1476 int nToRm
= m_colLabels
.size() - colID
;
1478 m_colLabels
.RemoveAt( colID
, nToRm
);
1481 if ( numCols
>= curNumCols
)
1483 for ( row
= 0; row
< curNumRows
; row
++ )
1485 m_data
[row
].Clear();
1490 else // something will be left
1492 for ( row
= 0; row
< curNumRows
; row
++ )
1494 m_data
[row
].RemoveAt( colID
, numCols
);
1497 m_numCols
-= numCols
;
1502 wxGridTableMessage
msg( this,
1503 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
1507 GetView()->ProcessTableMessage( msg
);
1513 wxString
wxGridStringTable::GetRowLabelValue( int row
)
1515 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
1517 // using default label
1519 return wxGridTableBase::GetRowLabelValue( row
);
1523 return m_rowLabels
[row
];
1527 wxString
wxGridStringTable::GetColLabelValue( int col
)
1529 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
1531 // using default label
1533 return wxGridTableBase::GetColLabelValue( col
);
1537 return m_colLabels
[col
];
1541 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
1543 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
1545 int n
= m_rowLabels
.GetCount();
1548 for ( i
= n
; i
<= row
; i
++ )
1550 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
1554 m_rowLabels
[row
] = value
;
1557 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
1559 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
1561 int n
= m_colLabels
.GetCount();
1564 for ( i
= n
; i
<= col
; i
++ )
1566 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
1570 m_colLabels
[col
] = value
;
1574 //////////////////////////////////////////////////////////////////////
1575 //////////////////////////////////////////////////////////////////////
1577 BEGIN_EVENT_TABLE(wxGridSubwindow
, wxWindow
)
1578 EVT_MOUSE_CAPTURE_LOST(wxGridSubwindow::OnMouseCaptureLost
)
1581 void wxGridSubwindow::OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
1583 m_owner
->CancelMouseCapture();
1586 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxGridSubwindow
)
1587 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
1588 EVT_MOUSEWHEEL( wxGridRowLabelWindow::OnMouseWheel
)
1589 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
1592 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1596 // NO - don't do this because it will set both the x and y origin
1597 // coords to match the parent scrolled window and we just want to
1598 // set the y coord - MB
1600 // m_owner->PrepareDC( dc );
1603 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
1604 wxPoint pt
= dc
.GetDeviceOrigin();
1605 dc
.SetDeviceOrigin( pt
.x
, pt
.y
-y
);
1607 wxArrayInt rows
= m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
1608 m_owner
->DrawRowLabels( dc
, rows
);
1611 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1613 m_owner
->ProcessRowLabelMouseEvent( event
);
1616 void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
1618 if (!m_owner
->GetEventHandler()->ProcessEvent( event
))
1622 //////////////////////////////////////////////////////////////////////
1624 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxGridSubwindow
)
1625 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
1626 EVT_MOUSEWHEEL( wxGridColLabelWindow::OnMouseWheel
)
1627 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
1630 void wxGridColLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1634 // NO - don't do this because it will set both the x and y origin
1635 // coords to match the parent scrolled window and we just want to
1636 // set the x coord - MB
1638 // m_owner->PrepareDC( dc );
1641 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
1642 wxPoint pt
= dc
.GetDeviceOrigin();
1643 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1644 dc
.SetDeviceOrigin( pt
.x
+x
, pt
.y
);
1646 dc
.SetDeviceOrigin( pt
.x
-x
, pt
.y
);
1648 wxArrayInt cols
= m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
1649 m_owner
->DrawColLabels( dc
, cols
);
1652 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1654 m_owner
->ProcessColLabelMouseEvent( event
);
1657 void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
1659 if (!m_owner
->GetEventHandler()->ProcessEvent( event
))
1663 //////////////////////////////////////////////////////////////////////
1665 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxGridSubwindow
)
1666 EVT_MOUSEWHEEL( wxGridCornerLabelWindow::OnMouseWheel
)
1667 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
1668 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
1671 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1675 m_owner
->DrawCornerLabel(dc
);
1678 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1680 m_owner
->ProcessCornerLabelMouseEvent( event
);
1683 void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
1685 if (!m_owner
->GetEventHandler()->ProcessEvent(event
))
1689 //////////////////////////////////////////////////////////////////////
1691 BEGIN_EVENT_TABLE( wxGridWindow
, wxGridSubwindow
)
1692 EVT_PAINT( wxGridWindow::OnPaint
)
1693 EVT_MOUSEWHEEL( wxGridWindow::OnMouseWheel
)
1694 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
1695 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
1696 EVT_KEY_UP( wxGridWindow::OnKeyUp
)
1697 EVT_CHAR( wxGridWindow::OnChar
)
1698 EVT_SET_FOCUS( wxGridWindow::OnFocus
)
1699 EVT_KILL_FOCUS( wxGridWindow::OnFocus
)
1700 EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground
)
1703 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1705 wxPaintDC
dc( this );
1706 m_owner
->PrepareDC( dc
);
1707 wxRegion reg
= GetUpdateRegion();
1708 wxGridCellCoordsArray dirtyCells
= m_owner
->CalcCellsExposed( reg
);
1709 m_owner
->DrawGridCellArea( dc
, dirtyCells
);
1711 m_owner
->DrawGridSpace( dc
);
1713 m_owner
->DrawAllGridLines( dc
, reg
);
1715 m_owner
->DrawHighlight( dc
, dirtyCells
);
1718 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
1720 wxWindow::ScrollWindow( dx
, dy
, rect
);
1721 m_owner
->GetGridRowLabelWindow()->ScrollWindow( 0, dy
, rect
);
1722 m_owner
->GetGridColLabelWindow()->ScrollWindow( dx
, 0, rect
);
1725 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
1727 if (event
.ButtonDown(wxMOUSE_BTN_LEFT
) && FindFocus() != this)
1730 m_owner
->ProcessGridCellMouseEvent( event
);
1733 void wxGridWindow::OnMouseWheel( wxMouseEvent
& event
)
1735 if (!m_owner
->GetEventHandler()->ProcessEvent( event
))
1739 // This seems to be required for wxMotif/wxGTK otherwise the mouse
1740 // cursor must be in the cell edit control to get key events
1742 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
1744 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
1748 void wxGridWindow::OnKeyUp( wxKeyEvent
& event
)
1750 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
1754 void wxGridWindow::OnChar( wxKeyEvent
& event
)
1756 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
1760 void wxGridWindow::OnEraseBackground( wxEraseEvent
& WXUNUSED(event
) )
1764 void wxGridWindow::OnFocus(wxFocusEvent
& event
)
1766 // and if we have any selection, it has to be repainted, because it
1767 // uses different colour when the grid is not focused:
1768 if ( m_owner
->IsSelection() )
1774 // NB: Note that this code is in "else" branch only because the other
1775 // branch refreshes everything and so there's no point in calling
1776 // Refresh() again, *not* because it should only be done if
1777 // !IsSelection(). If the above code is ever optimized to refresh
1778 // only selected area, this needs to be moved out of the "else"
1779 // branch so that it's always executed.
1781 // current cell cursor {dis,re}appears on focus change:
1782 const wxGridCellCoords
cursorCoords(m_owner
->GetGridCursorRow(),
1783 m_owner
->GetGridCursorCol());
1784 const wxRect cursor
=
1785 m_owner
->BlockToDeviceRect(cursorCoords
, cursorCoords
);
1786 Refresh(true, &cursor
);
1789 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) )
1793 #define internalXToCol(x) XToCol(x, true)
1794 #define internalYToRow(y) YToRow(y, true)
1796 /////////////////////////////////////////////////////////////////////
1798 #if wxUSE_EXTENDED_RTTI
1799 WX_DEFINE_FLAGS( wxGridStyle
)
1801 wxBEGIN_FLAGS( wxGridStyle
)
1802 // new style border flags, we put them first to
1803 // use them for streaming out
1804 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
1805 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
1806 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
1807 wxFLAGS_MEMBER(wxBORDER_RAISED
)
1808 wxFLAGS_MEMBER(wxBORDER_STATIC
)
1809 wxFLAGS_MEMBER(wxBORDER_NONE
)
1811 // old style border flags
1812 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
1813 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
1814 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
1815 wxFLAGS_MEMBER(wxRAISED_BORDER
)
1816 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
1817 wxFLAGS_MEMBER(wxBORDER
)
1819 // standard window styles
1820 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
1821 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
1822 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
1823 wxFLAGS_MEMBER(wxWANTS_CHARS
)
1824 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
1825 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
1826 wxFLAGS_MEMBER(wxVSCROLL
)
1827 wxFLAGS_MEMBER(wxHSCROLL
)
1829 wxEND_FLAGS( wxGridStyle
)
1831 IMPLEMENT_DYNAMIC_CLASS_XTI(wxGrid
, wxScrolledWindow
,"wx/grid.h")
1833 wxBEGIN_PROPERTIES_TABLE(wxGrid
)
1834 wxHIDE_PROPERTY( Children
)
1835 wxPROPERTY_FLAGS( WindowStyle
, wxGridStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
1836 wxEND_PROPERTIES_TABLE()
1838 wxBEGIN_HANDLERS_TABLE(wxGrid
)
1839 wxEND_HANDLERS_TABLE()
1841 wxCONSTRUCTOR_5( wxGrid
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
1844 TODO : Expose more information of a list's layout, etc. via appropriate objects (e.g., NotebookPageInfo)
1847 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
1850 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
1851 EVT_PAINT( wxGrid::OnPaint
)
1852 EVT_SIZE( wxGrid::OnSize
)
1853 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
1854 EVT_KEY_UP( wxGrid::OnKeyUp
)
1855 EVT_CHAR ( wxGrid::OnChar
)
1856 EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground
)
1859 bool wxGrid::Create(wxWindow
*parent
, wxWindowID id
,
1860 const wxPoint
& pos
, const wxSize
& size
,
1861 long style
, const wxString
& name
)
1863 if (!wxScrolledWindow::Create(parent
, id
, pos
, size
,
1864 style
| wxWANTS_CHARS
, name
))
1867 m_colMinWidths
= wxLongToLongHashMap(GRID_HASH_SIZE
);
1868 m_rowMinHeights
= wxLongToLongHashMap(GRID_HASH_SIZE
);
1871 SetInitialSize(size
);
1872 SetScrollRate(m_scrollLineX
, m_scrollLineY
);
1881 m_winCapture
->ReleaseMouse();
1883 // Ensure that the editor control is destroyed before the grid is,
1884 // otherwise we crash later when the editor tries to do something with the
1885 // half destroyed grid
1886 HideCellEditControl();
1888 // Must do this or ~wxScrollHelper will pop the wrong event handler
1889 SetTargetWindow(this);
1891 wxSafeDecRef(m_defaultCellAttr
);
1893 #ifdef DEBUG_ATTR_CACHE
1894 size_t total
= gs_nAttrCacheHits
+ gs_nAttrCacheMisses
;
1895 wxPrintf(wxT("wxGrid attribute cache statistics: "
1896 "total: %u, hits: %u (%u%%)\n"),
1897 total
, gs_nAttrCacheHits
,
1898 total
? (gs_nAttrCacheHits
*100) / total
: 0);
1901 // if we own the table, just delete it, otherwise at least don't leave it
1902 // with dangling view pointer
1905 else if ( m_table
&& m_table
->GetView() == this )
1906 m_table
->SetView(NULL
);
1908 delete m_typeRegistry
;
1911 delete m_setFixedRows
;
1912 delete m_setFixedCols
;
1916 // ----- internal init and update functions
1919 // NOTE: If using the default visual attributes works everywhere then this can
1920 // be removed as well as the #else cases below.
1921 #define _USE_VISATTR 0
1923 void wxGrid::Create()
1925 // create the type registry
1926 m_typeRegistry
= new wxGridTypeRegistry
;
1928 m_cellEditCtrlEnabled
= false;
1930 m_defaultCellAttr
= new wxGridCellAttr();
1932 // Set default cell attributes
1933 m_defaultCellAttr
->SetDefAttr(m_defaultCellAttr
);
1934 m_defaultCellAttr
->SetKind(wxGridCellAttr::Default
);
1935 m_defaultCellAttr
->SetFont(GetFont());
1936 m_defaultCellAttr
->SetAlignment(wxALIGN_LEFT
, wxALIGN_TOP
);
1937 m_defaultCellAttr
->SetRenderer(new wxGridCellStringRenderer
);
1938 m_defaultCellAttr
->SetEditor(new wxGridCellTextEditor
);
1941 wxVisualAttributes gva
= wxListBox::GetClassDefaultAttributes();
1942 wxVisualAttributes lva
= wxPanel::GetClassDefaultAttributes();
1944 m_defaultCellAttr
->SetTextColour(gva
.colFg
);
1945 m_defaultCellAttr
->SetBackgroundColour(gva
.colBg
);
1948 m_defaultCellAttr
->SetTextColour(
1949 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1950 m_defaultCellAttr
->SetBackgroundColour(
1951 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
1956 m_currentCellCoords
= wxGridNoCellCoords
;
1958 // subwindow components that make up the wxGrid
1959 m_rowLabelWin
= new wxGridRowLabelWindow(this);
1960 CreateColumnWindow();
1961 m_cornerLabelWin
= new wxGridCornerLabelWindow(this);
1962 m_gridWin
= new wxGridWindow( this );
1964 SetTargetWindow( m_gridWin
);
1967 wxColour gfg
= gva
.colFg
;
1968 wxColour gbg
= gva
.colBg
;
1969 wxColour lfg
= lva
.colFg
;
1970 wxColour lbg
= lva
.colBg
;
1972 wxColour gfg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1973 wxColour gbg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
);
1974 wxColour lfg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1975 wxColour lbg
= wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
);
1978 m_cornerLabelWin
->SetOwnForegroundColour(lfg
);
1979 m_cornerLabelWin
->SetOwnBackgroundColour(lbg
);
1980 m_rowLabelWin
->SetOwnForegroundColour(lfg
);
1981 m_rowLabelWin
->SetOwnBackgroundColour(lbg
);
1982 m_colWindow
->SetOwnForegroundColour(lfg
);
1983 m_colWindow
->SetOwnBackgroundColour(lbg
);
1985 m_gridWin
->SetOwnForegroundColour(gfg
);
1986 m_gridWin
->SetOwnBackgroundColour(gbg
);
1988 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
1989 m_labelTextColour
= m_rowLabelWin
->GetForegroundColour();
1991 // now that we have the grid window, use its font to compute the default
1993 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
1994 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
1995 m_defaultRowHeight
+= 8;
1997 m_defaultRowHeight
+= 4;
2002 void wxGrid::CreateColumnWindow()
2004 if ( m_useNativeHeader
)
2006 m_colWindow
= new wxGridHeaderCtrl(this);
2007 m_colLabelHeight
= m_colWindow
->GetBestSize().y
;
2009 else // draw labels ourselves
2011 m_colWindow
= new wxGridColLabelWindow(this);
2012 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
2016 bool wxGrid::CreateGrid( int numRows
, int numCols
,
2017 wxGridSelectionModes selmode
)
2019 wxCHECK_MSG( !m_created
,
2021 wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
2023 return SetTable(new wxGridStringTable(numRows
, numCols
), true, selmode
);
2026 void wxGrid::SetSelectionMode(wxGridSelectionModes selmode
)
2028 wxCHECK_RET( m_created
,
2029 wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") );
2031 m_selection
->SetSelectionMode( selmode
);
2034 wxGrid::wxGridSelectionModes
wxGrid::GetSelectionMode() const
2036 wxCHECK_MSG( m_created
, wxGridSelectCells
,
2037 wxT("Called wxGrid::GetSelectionMode() before calling CreateGrid()") );
2039 return m_selection
->GetSelectionMode();
2043 wxGrid::SetTable(wxGridTableBase
*table
,
2045 wxGrid::wxGridSelectionModes selmode
)
2047 bool checkSelection
= false;
2050 // stop all processing
2055 m_table
->SetView(0);
2067 checkSelection
= true;
2069 // kill row and column size arrays
2070 m_colWidths
.Empty();
2071 m_colRights
.Empty();
2072 m_rowHeights
.Empty();
2073 m_rowBottoms
.Empty();
2078 m_numRows
= table
->GetNumberRows();
2079 m_numCols
= table
->GetNumberCols();
2081 if ( m_useNativeHeader
)
2082 GetGridColHeader()->SetColumnCount(m_numCols
);
2085 m_table
->SetView( this );
2086 m_ownTable
= takeOwnership
;
2087 m_selection
= new wxGridSelection( this, selmode
);
2090 // If the newly set table is smaller than the
2091 // original one current cell and selection regions
2092 // might be invalid,
2093 m_selectedBlockCorner
= wxGridNoCellCoords
;
2094 m_currentCellCoords
=
2095 wxGridCellCoords(wxMin(m_numRows
, m_currentCellCoords
.GetRow()),
2096 wxMin(m_numCols
, m_currentCellCoords
.GetCol()));
2097 if (m_selectedBlockTopLeft
.GetRow() >= m_numRows
||
2098 m_selectedBlockTopLeft
.GetCol() >= m_numCols
)
2100 m_selectedBlockTopLeft
= wxGridNoCellCoords
;
2101 m_selectedBlockBottomRight
= wxGridNoCellCoords
;
2104 m_selectedBlockBottomRight
=
2105 wxGridCellCoords(wxMin(m_numRows
,
2106 m_selectedBlockBottomRight
.GetRow()),
2108 m_selectedBlockBottomRight
.GetCol()));
2122 m_cornerLabelWin
= NULL
;
2123 m_rowLabelWin
= NULL
;
2131 m_defaultCellAttr
= NULL
;
2132 m_typeRegistry
= NULL
;
2133 m_winCapture
= NULL
;
2135 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
2136 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
2139 m_setFixedCols
= NULL
;
2142 m_attrCache
.row
= -1;
2143 m_attrCache
.col
= -1;
2144 m_attrCache
.attr
= NULL
;
2146 m_labelFont
= GetFont();
2147 m_labelFont
.SetWeight( wxBOLD
);
2149 m_rowLabelHorizAlign
= wxALIGN_CENTRE
;
2150 m_rowLabelVertAlign
= wxALIGN_CENTRE
;
2152 m_colLabelHorizAlign
= wxALIGN_CENTRE
;
2153 m_colLabelVertAlign
= wxALIGN_CENTRE
;
2154 m_colLabelTextOrientation
= wxHORIZONTAL
;
2156 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
2157 m_defaultRowHeight
= 0; // this will be initialized after creation
2159 m_minAcceptableColWidth
= WXGRID_MIN_COL_WIDTH
;
2160 m_minAcceptableRowHeight
= WXGRID_MIN_ROW_HEIGHT
;
2162 m_gridLineColour
= wxColour( 192,192,192 );
2163 m_gridLinesEnabled
= true;
2164 m_gridLinesClipHorz
=
2165 m_gridLinesClipVert
= true;
2166 m_cellHighlightColour
= *wxBLACK
;
2167 m_cellHighlightPenWidth
= 2;
2168 m_cellHighlightROPenWidth
= 1;
2170 m_canDragColMove
= false;
2172 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
2173 m_winCapture
= NULL
;
2174 m_canDragRowSize
= true;
2175 m_canDragColSize
= true;
2176 m_canDragGridSize
= true;
2177 m_canDragCell
= false;
2179 m_dragRowOrCol
= -1;
2180 m_isDragging
= false;
2181 m_startDragPos
= wxDefaultPosition
;
2183 m_sortCol
= wxNOT_FOUND
;
2184 m_sortIsAscending
= true;
2187 m_nativeColumnLabels
= false;
2189 m_waitForSlowClick
= false;
2191 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
2192 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
2194 m_currentCellCoords
= wxGridNoCellCoords
;
2196 m_selectedBlockTopLeft
=
2197 m_selectedBlockBottomRight
=
2198 m_selectedBlockCorner
= wxGridNoCellCoords
;
2200 m_selectionBackground
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
2201 m_selectionForeground
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
2203 m_editable
= true; // default for whole grid
2205 m_inOnKeyDown
= false;
2211 m_scrollLineX
= GRID_SCROLL_LINE_X
;
2212 m_scrollLineY
= GRID_SCROLL_LINE_Y
;
2215 // ----------------------------------------------------------------------------
2216 // the idea is to call these functions only when necessary because they create
2217 // quite big arrays which eat memory mostly unnecessary - in particular, if
2218 // default widths/heights are used for all rows/columns, we may not use these
2221 // with some extra code, it should be possible to only store the widths/heights
2222 // different from default ones (resulting in space savings for huge grids) but
2223 // this is not done currently
2224 // ----------------------------------------------------------------------------
2226 void wxGrid::InitRowHeights()
2228 m_rowHeights
.Empty();
2229 m_rowBottoms
.Empty();
2231 m_rowHeights
.Alloc( m_numRows
);
2232 m_rowBottoms
.Alloc( m_numRows
);
2234 m_rowHeights
.Add( m_defaultRowHeight
, m_numRows
);
2237 for ( int i
= 0; i
< m_numRows
; i
++ )
2239 rowBottom
+= m_defaultRowHeight
;
2240 m_rowBottoms
.Add( rowBottom
);
2244 void wxGrid::InitColWidths()
2246 m_colWidths
.Empty();
2247 m_colRights
.Empty();
2249 m_colWidths
.Alloc( m_numCols
);
2250 m_colRights
.Alloc( m_numCols
);
2252 m_colWidths
.Add( m_defaultColWidth
, m_numCols
);
2254 for ( int i
= 0; i
< m_numCols
; i
++ )
2256 int colRight
= ( GetColPos( i
) + 1 ) * m_defaultColWidth
;
2257 m_colRights
.Add( colRight
);
2261 int wxGrid::GetColWidth(int col
) const
2263 return m_colWidths
.IsEmpty() ? m_defaultColWidth
: m_colWidths
[col
];
2266 int wxGrid::GetColLeft(int col
) const
2268 return m_colRights
.IsEmpty() ? GetColPos( col
) * m_defaultColWidth
2269 : m_colRights
[col
] - m_colWidths
[col
];
2272 int wxGrid::GetColRight(int col
) const
2274 return m_colRights
.IsEmpty() ? (GetColPos( col
) + 1) * m_defaultColWidth
2278 int wxGrid::GetRowHeight(int row
) const
2280 return m_rowHeights
.IsEmpty() ? m_defaultRowHeight
: m_rowHeights
[row
];
2283 int wxGrid::GetRowTop(int row
) const
2285 return m_rowBottoms
.IsEmpty() ? row
* m_defaultRowHeight
2286 : m_rowBottoms
[row
] - m_rowHeights
[row
];
2289 int wxGrid::GetRowBottom(int row
) const
2291 return m_rowBottoms
.IsEmpty() ? (row
+ 1) * m_defaultRowHeight
2292 : m_rowBottoms
[row
];
2295 void wxGrid::CalcDimensions()
2297 // compute the size of the scrollable area
2298 int w
= m_numCols
> 0 ? GetColRight(GetColAt(m_numCols
- 1)) : 0;
2299 int h
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) : 0;
2304 // take into account editor if shown
2305 if ( IsCellEditControlShown() )
2308 int r
= m_currentCellCoords
.GetRow();
2309 int c
= m_currentCellCoords
.GetCol();
2310 int x
= GetColLeft(c
);
2311 int y
= GetRowTop(r
);
2313 // how big is the editor
2314 wxGridCellAttr
* attr
= GetCellAttr(r
, c
);
2315 wxGridCellEditor
* editor
= attr
->GetEditor(this, r
, c
);
2316 editor
->GetControl()->GetSize(&w2
, &h2
);
2327 // preserve (more or less) the previous position
2329 GetViewStart( &x
, &y
);
2331 // ensure the position is valid for the new scroll ranges
2333 x
= wxMax( w
- 1, 0 );
2335 y
= wxMax( h
- 1, 0 );
2337 // update the virtual size and refresh the scrollbars to reflect it
2338 m_gridWin
->SetVirtualSize(w
, h
);
2342 // if our OnSize() hadn't been called (it would if we have scrollbars), we
2343 // still must reposition the children
2347 wxSize
wxGrid::GetSizeAvailableForScrollTarget(const wxSize
& size
)
2349 wxSize
sizeGridWin(size
);
2350 sizeGridWin
.x
-= m_rowLabelWidth
;
2351 sizeGridWin
.y
-= m_colLabelHeight
;
2356 void wxGrid::CalcWindowSizes()
2358 // escape if the window is has not been fully created yet
2360 if ( m_cornerLabelWin
== NULL
)
2364 GetClientSize( &cw
, &ch
);
2366 // the grid may be too small to have enough space for the labels yet, don't
2367 // size the windows to negative sizes in this case
2368 int gw
= cw
- m_rowLabelWidth
;
2369 int gh
= ch
- m_colLabelHeight
;
2375 if ( m_cornerLabelWin
&& m_cornerLabelWin
->IsShown() )
2376 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
2378 if ( m_colWindow
&& m_colWindow
->IsShown() )
2379 m_colWindow
->SetSize( m_rowLabelWidth
, 0, gw
, m_colLabelHeight
);
2381 if ( m_rowLabelWin
&& m_rowLabelWin
->IsShown() )
2382 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, gh
);
2384 if ( m_gridWin
&& m_gridWin
->IsShown() )
2385 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, gw
, gh
);
2388 // this is called when the grid table sends a message
2389 // to indicate that it has been redimensioned
2391 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
2394 bool result
= false;
2396 // Clear the attribute cache as the attribute might refer to a different
2397 // cell than stored in the cache after adding/removing rows/columns.
2400 // By the same reasoning, the editor should be dismissed if columns are
2401 // added or removed. And for consistency, it should IMHO always be
2402 // removed, not only if the cell "underneath" it actually changes.
2403 // For now, I intentionally do not save the editor's content as the
2404 // cell it might want to save that stuff to might no longer exist.
2405 HideCellEditControl();
2407 switch ( msg
.GetId() )
2409 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
2411 size_t pos
= msg
.GetCommandInt();
2412 int numRows
= msg
.GetCommandInt2();
2414 m_numRows
+= numRows
;
2416 if ( !m_rowHeights
.IsEmpty() )
2418 m_rowHeights
.Insert( m_defaultRowHeight
, pos
, numRows
);
2419 m_rowBottoms
.Insert( 0, pos
, numRows
);
2423 bottom
= m_rowBottoms
[pos
- 1];
2425 for ( i
= pos
; i
< m_numRows
; i
++ )
2427 bottom
+= m_rowHeights
[i
];
2428 m_rowBottoms
[i
] = bottom
;
2432 if ( m_currentCellCoords
== wxGridNoCellCoords
)
2434 // if we have just inserted cols into an empty grid the current
2435 // cell will be undefined...
2437 SetCurrentCell( 0, 0 );
2441 m_selection
->UpdateRows( pos
, numRows
);
2442 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
2444 attrProvider
->UpdateAttrRows( pos
, numRows
);
2446 if ( !GetBatchCount() )
2449 m_rowLabelWin
->Refresh();
2455 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
2457 int numRows
= msg
.GetCommandInt();
2458 int oldNumRows
= m_numRows
;
2459 m_numRows
+= numRows
;
2461 if ( !m_rowHeights
.IsEmpty() )
2463 m_rowHeights
.Add( m_defaultRowHeight
, numRows
);
2464 m_rowBottoms
.Add( 0, numRows
);
2467 if ( oldNumRows
> 0 )
2468 bottom
= m_rowBottoms
[oldNumRows
- 1];
2470 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
2472 bottom
+= m_rowHeights
[i
];
2473 m_rowBottoms
[i
] = bottom
;
2477 if ( m_currentCellCoords
== wxGridNoCellCoords
)
2479 // if we have just inserted cols into an empty grid the current
2480 // cell will be undefined...
2482 SetCurrentCell( 0, 0 );
2485 if ( !GetBatchCount() )
2488 m_rowLabelWin
->Refresh();
2494 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
2496 size_t pos
= msg
.GetCommandInt();
2497 int numRows
= msg
.GetCommandInt2();
2498 m_numRows
-= numRows
;
2500 if ( !m_rowHeights
.IsEmpty() )
2502 m_rowHeights
.RemoveAt( pos
, numRows
);
2503 m_rowBottoms
.RemoveAt( pos
, numRows
);
2506 for ( i
= 0; i
< m_numRows
; i
++ )
2508 h
+= m_rowHeights
[i
];
2509 m_rowBottoms
[i
] = h
;
2515 m_currentCellCoords
= wxGridNoCellCoords
;
2519 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
2520 m_currentCellCoords
.Set( 0, 0 );
2524 m_selection
->UpdateRows( pos
, -((int)numRows
) );
2525 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
2528 attrProvider
->UpdateAttrRows( pos
, -((int)numRows
) );
2530 // ifdef'd out following patch from Paul Gammans
2532 // No need to touch column attributes, unless we
2533 // removed _all_ rows, in this case, we remove
2534 // all column attributes.
2535 // I hate to do this here, but the
2536 // needed data is not available inside UpdateAttrRows.
2537 if ( !GetNumberRows() )
2538 attrProvider
->UpdateAttrCols( 0, -GetNumberCols() );
2542 if ( !GetBatchCount() )
2545 m_rowLabelWin
->Refresh();
2551 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
2553 size_t pos
= msg
.GetCommandInt();
2554 int numCols
= msg
.GetCommandInt2();
2555 m_numCols
+= numCols
;
2557 if ( m_useNativeHeader
)
2558 GetGridColHeader()->SetColumnCount(m_numCols
);
2560 if ( !m_colAt
.IsEmpty() )
2562 //Shift the column IDs
2564 for ( i
= 0; i
< m_numCols
- numCols
; i
++ )
2566 if ( m_colAt
[i
] >= (int)pos
)
2567 m_colAt
[i
] += numCols
;
2570 m_colAt
.Insert( pos
, pos
, numCols
);
2572 //Set the new columns' positions
2573 for ( i
= pos
+ 1; i
< (int)pos
+ numCols
; i
++ )
2579 if ( !m_colWidths
.IsEmpty() )
2581 m_colWidths
.Insert( m_defaultColWidth
, pos
, numCols
);
2582 m_colRights
.Insert( 0, pos
, numCols
);
2586 right
= m_colRights
[GetColAt( pos
- 1 )];
2589 for ( colPos
= pos
; colPos
< m_numCols
; colPos
++ )
2591 i
= GetColAt( colPos
);
2593 right
+= m_colWidths
[i
];
2594 m_colRights
[i
] = right
;
2598 if ( m_currentCellCoords
== wxGridNoCellCoords
)
2600 // if we have just inserted cols into an empty grid the current
2601 // cell will be undefined...
2603 SetCurrentCell( 0, 0 );
2607 m_selection
->UpdateCols( pos
, numCols
);
2608 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
2610 attrProvider
->UpdateAttrCols( pos
, numCols
);
2611 if ( !GetBatchCount() )
2614 m_colWindow
->Refresh();
2620 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
2622 int numCols
= msg
.GetCommandInt();
2623 int oldNumCols
= m_numCols
;
2624 m_numCols
+= numCols
;
2625 if ( m_useNativeHeader
)
2626 GetGridColHeader()->SetColumnCount(m_numCols
);
2628 if ( !m_colAt
.IsEmpty() )
2630 m_colAt
.Add( 0, numCols
);
2632 //Set the new columns' positions
2634 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
2640 if ( !m_colWidths
.IsEmpty() )
2642 m_colWidths
.Add( m_defaultColWidth
, numCols
);
2643 m_colRights
.Add( 0, numCols
);
2646 if ( oldNumCols
> 0 )
2647 right
= m_colRights
[GetColAt( oldNumCols
- 1 )];
2650 for ( colPos
= oldNumCols
; colPos
< m_numCols
; colPos
++ )
2652 i
= GetColAt( colPos
);
2654 right
+= m_colWidths
[i
];
2655 m_colRights
[i
] = right
;
2659 if ( m_currentCellCoords
== wxGridNoCellCoords
)
2661 // if we have just inserted cols into an empty grid the current
2662 // cell will be undefined...
2664 SetCurrentCell( 0, 0 );
2666 if ( !GetBatchCount() )
2669 m_colWindow
->Refresh();
2675 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
2677 size_t pos
= msg
.GetCommandInt();
2678 int numCols
= msg
.GetCommandInt2();
2679 m_numCols
-= numCols
;
2680 if ( m_useNativeHeader
)
2681 GetGridColHeader()->SetColumnCount(m_numCols
);
2683 if ( !m_colAt
.IsEmpty() )
2685 int colID
= GetColAt( pos
);
2687 m_colAt
.RemoveAt( pos
, numCols
);
2689 //Shift the column IDs
2691 for ( colPos
= 0; colPos
< m_numCols
; colPos
++ )
2693 if ( m_colAt
[colPos
] > colID
)
2694 m_colAt
[colPos
] -= numCols
;
2698 if ( !m_colWidths
.IsEmpty() )
2700 m_colWidths
.RemoveAt( pos
, numCols
);
2701 m_colRights
.RemoveAt( pos
, numCols
);
2705 for ( colPos
= 0; colPos
< m_numCols
; colPos
++ )
2707 i
= GetColAt( colPos
);
2709 w
+= m_colWidths
[i
];
2716 m_currentCellCoords
= wxGridNoCellCoords
;
2720 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
2721 m_currentCellCoords
.Set( 0, 0 );
2725 m_selection
->UpdateCols( pos
, -((int)numCols
) );
2726 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
2729 attrProvider
->UpdateAttrCols( pos
, -((int)numCols
) );
2731 // ifdef'd out following patch from Paul Gammans
2733 // No need to touch row attributes, unless we
2734 // removed _all_ columns, in this case, we remove
2735 // all row attributes.
2736 // I hate to do this here, but the
2737 // needed data is not available inside UpdateAttrCols.
2738 if ( !GetNumberCols() )
2739 attrProvider
->UpdateAttrRows( 0, -GetNumberRows() );
2743 if ( !GetBatchCount() )
2746 m_colWindow
->Refresh();
2753 if (result
&& !GetBatchCount() )
2754 m_gridWin
->Refresh();
2759 wxArrayInt
wxGrid::CalcRowLabelsExposed( const wxRegion
& reg
) const
2761 wxRegionIterator
iter( reg
);
2764 wxArrayInt rowlabels
;
2771 // TODO: remove this when we can...
2772 // There is a bug in wxMotif that gives garbage update
2773 // rectangles if you jump-scroll a long way by clicking the
2774 // scrollbar with middle button. This is a work-around
2776 #if defined(__WXMOTIF__)
2778 m_gridWin
->GetClientSize( &cw
, &ch
);
2779 if ( r
.GetTop() > ch
)
2781 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
2784 // logical bounds of update region
2787 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
2788 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
2790 // find the row labels within these bounds
2793 for ( row
= internalYToRow(top
); row
< m_numRows
; row
++ )
2795 if ( GetRowBottom(row
) < top
)
2798 if ( GetRowTop(row
) > bottom
)
2801 rowlabels
.Add( row
);
2810 wxArrayInt
wxGrid::CalcColLabelsExposed( const wxRegion
& reg
) const
2812 wxRegionIterator
iter( reg
);
2815 wxArrayInt colLabels
;
2822 // TODO: remove this when we can...
2823 // There is a bug in wxMotif that gives garbage update
2824 // rectangles if you jump-scroll a long way by clicking the
2825 // scrollbar with middle button. This is a work-around
2827 #if defined(__WXMOTIF__)
2829 m_gridWin
->GetClientSize( &cw
, &ch
);
2830 if ( r
.GetLeft() > cw
)
2832 r
.SetRight( wxMin( r
.GetRight(), cw
) );
2835 // logical bounds of update region
2838 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
2839 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
2841 // find the cells within these bounds
2845 for ( colPos
= GetColPos( internalXToCol(left
) ); colPos
< m_numCols
; colPos
++ )
2847 col
= GetColAt( colPos
);
2849 if ( GetColRight(col
) < left
)
2852 if ( GetColLeft(col
) > right
)
2855 colLabels
.Add( col
);
2864 wxGridCellCoordsArray
wxGrid::CalcCellsExposed( const wxRegion
& reg
) const
2866 wxRegionIterator
iter( reg
);
2869 wxGridCellCoordsArray cellsExposed
;
2871 int left
, top
, right
, bottom
;
2876 // TODO: remove this when we can...
2877 // There is a bug in wxMotif that gives garbage update
2878 // rectangles if you jump-scroll a long way by clicking the
2879 // scrollbar with middle button. This is a work-around
2881 #if defined(__WXMOTIF__)
2883 m_gridWin
->GetClientSize( &cw
, &ch
);
2884 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
2885 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
2886 r
.SetRight( wxMin( r
.GetRight(), cw
) );
2887 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
2890 // logical bounds of update region
2892 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
2893 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
2895 // find the cells within these bounds
2897 for ( int row
= internalYToRow(top
); row
< m_numRows
; row
++ )
2899 if ( GetRowBottom(row
) <= top
)
2902 if ( GetRowTop(row
) > bottom
)
2905 // add all dirty cells in this row: notice that the columns which
2906 // are dirty don't depend on the row so we compute them only once
2907 // for the first dirty row and then reuse for all the next ones
2910 // do determine the dirty columns
2911 for ( int pos
= XToPos(left
); pos
<= XToPos(right
); pos
++ )
2912 cols
.push_back(GetColAt(pos
));
2914 // if there are no dirty columns at all, nothing to do
2919 const size_t count
= cols
.size();
2920 for ( size_t n
= 0; n
< count
; n
++ )
2921 cellsExposed
.Add(wxGridCellCoords(row
, cols
[n
]));
2927 return cellsExposed
;
2931 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
2934 wxPoint
pos( event
.GetPosition() );
2935 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2937 if ( event
.Dragging() )
2941 m_isDragging
= true;
2942 m_rowLabelWin
->CaptureMouse();
2945 if ( event
.LeftIsDown() )
2947 switch ( m_cursorMode
)
2949 case WXGRID_CURSOR_RESIZE_ROW
:
2951 int cw
, ch
, left
, dummy
;
2952 m_gridWin
->GetClientSize( &cw
, &ch
);
2953 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
2955 wxClientDC
dc( m_gridWin
);
2958 GetRowTop(m_dragRowOrCol
) +
2959 GetRowMinimalHeight(m_dragRowOrCol
) );
2960 dc
.SetLogicalFunction(wxINVERT
);
2961 if ( m_dragLastPos
>= 0 )
2963 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
2965 dc
.DrawLine( left
, y
, left
+cw
, y
);
2970 case WXGRID_CURSOR_SELECT_ROW
:
2972 if ( (row
= YToRow( y
)) >= 0 )
2975 m_selection
->SelectRow(row
, event
);
2980 // default label to suppress warnings about "enumeration value
2981 // 'xxx' not handled in switch
2989 if ( m_isDragging
&& (event
.Entering() || event
.Leaving()) )
2994 if (m_rowLabelWin
->HasCapture())
2995 m_rowLabelWin
->ReleaseMouse();
2996 m_isDragging
= false;
2999 // ------------ Entering or leaving the window
3001 if ( event
.Entering() || event
.Leaving() )
3003 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
3006 // ------------ Left button pressed
3008 else if ( event
.LeftDown() )
3010 row
= YToEdgeOfRow(y
);
3011 if ( row
!= wxNOT_FOUND
&& CanDragRowSize(row
) )
3013 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
);
3015 else // not a request to start resizing
3019 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
3021 if ( !event
.ShiftDown() && !event
.CmdDown() )
3025 if ( event
.ShiftDown() )
3027 m_selection
->SelectBlock
3029 m_currentCellCoords
.GetRow(), 0,
3030 row
, GetNumberCols() - 1,
3036 m_selection
->SelectRow(row
, event
);
3040 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW
, m_rowLabelWin
);
3045 // ------------ Left double click
3047 else if (event
.LeftDClick() )
3049 row
= YToEdgeOfRow(y
);
3050 if ( row
!= wxNOT_FOUND
&& CanDragRowSize(row
) )
3052 // adjust row height depending on label text
3054 // TODO: generate RESIZING event, see #10754
3055 AutoSizeRowLabelSize( row
);
3057 SendGridSizeEvent(wxEVT_GRID_ROW_SIZE
, row
, -1, event
);
3059 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, GetColLabelWindow());
3062 else // not on row separator or it's not resizeable
3066 !SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
) )
3068 // no default action at the moment
3073 // ------------ Left button released
3075 else if ( event
.LeftUp() )
3077 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
3078 DoEndDragResizeRow(event
);
3080 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
3084 // ------------ Right button down
3086 else if ( event
.RightDown() )
3090 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
3092 // no default action at the moment
3096 // ------------ Right double click
3098 else if ( event
.RightDClick() )
3102 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
3104 // no default action at the moment
3108 // ------------ No buttons down and mouse moving
3110 else if ( event
.Moving() )
3112 m_dragRowOrCol
= YToEdgeOfRow( y
);
3113 if ( m_dragRowOrCol
!= wxNOT_FOUND
)
3115 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3117 if ( CanDragRowSize(m_dragRowOrCol
) )
3118 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
, false);
3121 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
3123 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
, false);
3128 void wxGrid::UpdateColumnSortingIndicator(int col
)
3130 wxCHECK_RET( col
!= wxNOT_FOUND
, "invalid column index" );
3132 if ( m_useNativeHeader
)
3133 GetGridColHeader()->UpdateColumn(col
);
3134 else if ( m_nativeColumnLabels
)
3135 m_colWindow
->Refresh();
3136 //else: sorting indicator display not yet implemented in grid version
3139 void wxGrid::SetSortingColumn(int col
, bool ascending
)
3141 if ( col
== m_sortCol
)
3143 // we are already using this column for sorting (or not sorting at all)
3144 // but we might still change the sorting order, check for it
3145 if ( m_sortCol
!= wxNOT_FOUND
&& ascending
!= m_sortIsAscending
)
3147 m_sortIsAscending
= ascending
;
3149 UpdateColumnSortingIndicator(m_sortCol
);
3152 else // we're changing the column used for sorting
3154 const int sortColOld
= m_sortCol
;
3156 // change it before updating the column as we want GetSortingColumn()
3157 // to return the correct new value
3160 if ( sortColOld
!= wxNOT_FOUND
)
3161 UpdateColumnSortingIndicator(sortColOld
);
3163 if ( m_sortCol
!= wxNOT_FOUND
)
3165 m_sortIsAscending
= ascending
;
3166 UpdateColumnSortingIndicator(m_sortCol
);
3171 void wxGrid::DoColHeaderClick(int col
)
3173 // we consider that the grid was resorted if this event is processed and
3175 if ( SendEvent(wxEVT_GRID_COL_SORT
, -1, col
) == 1 )
3177 SetSortingColumn(col
, IsSortingBy(col
) ? !m_sortIsAscending
: true);
3182 void wxGrid::DoStartResizeCol(int col
)
3184 m_dragRowOrCol
= col
;
3186 DoUpdateResizeColWidth(GetColWidth(m_dragRowOrCol
));
3189 void wxGrid::DoUpdateResizeCol(int x
)
3191 int cw
, ch
, dummy
, top
;
3192 m_gridWin
->GetClientSize( &cw
, &ch
);
3193 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
3195 wxClientDC
dc( m_gridWin
);
3198 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) + GetColMinimalWidth(m_dragRowOrCol
));
3199 dc
.SetLogicalFunction(wxINVERT
);
3200 if ( m_dragLastPos
>= 0 )
3202 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ ch
);
3204 dc
.DrawLine( x
, top
, x
, top
+ ch
);
3208 void wxGrid::DoUpdateResizeColWidth(int w
)
3210 DoUpdateResizeCol(GetColLeft(m_dragRowOrCol
) + w
);
3213 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
3216 wxPoint
pos( event
.GetPosition() );
3217 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
3219 int col
= XToCol(x
);
3220 if ( event
.Dragging() )
3224 m_isDragging
= true;
3225 GetColLabelWindow()->CaptureMouse();
3227 if ( m_cursorMode
== WXGRID_CURSOR_MOVE_COL
&& col
!= -1 )
3228 DoStartMoveCol(col
);
3231 if ( event
.LeftIsDown() )
3233 switch ( m_cursorMode
)
3235 case WXGRID_CURSOR_RESIZE_COL
:
3236 DoUpdateResizeCol(x
);
3239 case WXGRID_CURSOR_SELECT_COL
:
3244 m_selection
->SelectCol(col
, event
);
3249 case WXGRID_CURSOR_MOVE_COL
:
3251 int posNew
= XToPos(x
);
3252 int colNew
= GetColAt(posNew
);
3254 // determine the position of the drop marker
3256 if ( x
>= GetColLeft(colNew
) + (GetColWidth(colNew
) / 2) )
3257 markerX
= GetColRight(colNew
);
3259 markerX
= GetColLeft(colNew
);
3261 if ( markerX
!= m_dragLastPos
)
3263 wxClientDC
dc( GetColLabelWindow() );
3267 GetColLabelWindow()->GetClientSize( &cw
, &ch
);
3271 //Clean up the last indicator
3272 if ( m_dragLastPos
>= 0 )
3274 wxPen
pen( GetColLabelWindow()->GetBackgroundColour(), 2 );
3276 dc
.DrawLine( m_dragLastPos
+ 1, 0, m_dragLastPos
+ 1, ch
);
3277 dc
.SetPen(wxNullPen
);
3279 if ( XToCol( m_dragLastPos
) != -1 )
3280 DrawColLabel( dc
, XToCol( m_dragLastPos
) );
3283 const wxColour
*color
;
3284 //Moving to the same place? Don't draw a marker
3285 if ( colNew
== m_dragRowOrCol
)
3286 color
= wxLIGHT_GREY
;
3291 wxPen
pen( *color
, 2 );
3294 dc
.DrawLine( markerX
, 0, markerX
, ch
);
3296 dc
.SetPen(wxNullPen
);
3298 m_dragLastPos
= markerX
- 1;
3303 // default label to suppress warnings about "enumeration value
3304 // 'xxx' not handled in switch
3312 if ( m_isDragging
&& (event
.Entering() || event
.Leaving()) )
3317 if (GetColLabelWindow()->HasCapture())
3318 GetColLabelWindow()->ReleaseMouse();
3319 m_isDragging
= false;
3322 // ------------ Entering or leaving the window
3324 if ( event
.Entering() || event
.Leaving() )
3326 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, GetColLabelWindow());
3329 // ------------ Left button pressed
3331 else if ( event
.LeftDown() )
3333 int col
= XToEdgeOfCol(x
);
3334 if ( col
!= wxNOT_FOUND
&& CanDragColSize(col
) )
3336 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, GetColLabelWindow());
3338 else // not a request to start resizing
3342 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
3344 if ( m_canDragColMove
)
3346 //Show button as pressed
3347 wxClientDC
dc( GetColLabelWindow() );
3348 int colLeft
= GetColLeft( col
);
3349 int colRight
= GetColRight( col
) - 1;
3350 dc
.SetPen( wxPen( GetColLabelWindow()->GetBackgroundColour(), 1 ) );
3351 dc
.DrawLine( colLeft
, 1, colLeft
, m_colLabelHeight
-1 );
3352 dc
.DrawLine( colLeft
, 1, colRight
, 1 );
3354 ChangeCursorMode(WXGRID_CURSOR_MOVE_COL
, GetColLabelWindow());
3358 if ( !event
.ShiftDown() && !event
.CmdDown() )
3362 if ( event
.ShiftDown() )
3364 m_selection
->SelectBlock
3366 0, m_currentCellCoords
.GetCol(),
3367 GetNumberRows() - 1, col
,
3373 m_selection
->SelectCol(col
, event
);
3377 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL
, GetColLabelWindow());
3383 // ------------ Left double click
3385 if ( event
.LeftDClick() )
3387 const int colEdge
= XToEdgeOfCol(x
);
3388 if ( colEdge
== -1 )
3391 ! SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
) )
3393 // no default action at the moment
3398 // adjust column width depending on label text
3400 // TODO: generate RESIZING event, see #10754
3401 AutoSizeColLabelSize( colEdge
);
3403 SendGridSizeEvent(wxEVT_GRID_COL_SIZE
, -1, colEdge
, event
);
3405 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, GetColLabelWindow());
3410 // ------------ Left button released
3412 else if ( event
.LeftUp() )
3414 switch ( m_cursorMode
)
3416 case WXGRID_CURSOR_RESIZE_COL
:
3417 DoEndDragResizeCol(event
);
3420 case WXGRID_CURSOR_MOVE_COL
:
3421 if ( m_dragLastPos
== -1 || col
== m_dragRowOrCol
)
3423 // the column didn't actually move anywhere
3425 DoColHeaderClick(col
);
3426 m_colWindow
->Refresh(); // "unpress" the column
3430 DoEndMoveCol(XToPos(x
));
3434 case WXGRID_CURSOR_SELECT_COL
:
3435 case WXGRID_CURSOR_SELECT_CELL
:
3436 case WXGRID_CURSOR_RESIZE_ROW
:
3437 case WXGRID_CURSOR_SELECT_ROW
:
3439 DoColHeaderClick(col
);
3443 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, GetColLabelWindow());
3447 // ------------ Right button down
3449 else if ( event
.RightDown() )
3452 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
3454 // no default action at the moment
3458 // ------------ Right double click
3460 else if ( event
.RightDClick() )
3463 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
3465 // no default action at the moment
3469 // ------------ No buttons down and mouse moving
3471 else if ( event
.Moving() )
3473 m_dragRowOrCol
= XToEdgeOfCol( x
);
3474 if ( m_dragRowOrCol
>= 0 )
3476 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3478 if ( CanDragColSize(m_dragRowOrCol
) )
3479 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, GetColLabelWindow(), false);
3482 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
3484 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, GetColLabelWindow(), false);
3489 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
3491 if ( event
.LeftDown() )
3493 // indicate corner label by having both row and
3496 if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
3501 else if ( event
.LeftDClick() )
3503 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
3505 else if ( event
.RightDown() )
3507 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
3509 // no default action at the moment
3512 else if ( event
.RightDClick() )
3514 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
3516 // no default action at the moment
3521 void wxGrid::CancelMouseCapture()
3523 // cancel operation currently in progress, whatever it is
3526 m_isDragging
= false;
3527 m_startDragPos
= wxDefaultPosition
;
3529 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
3530 m_winCapture
->SetCursor( *wxSTANDARD_CURSOR
);
3531 m_winCapture
= NULL
;
3533 // remove traces of whatever we drew on screen
3538 void wxGrid::ChangeCursorMode(CursorMode mode
,
3543 static const wxChar
*cursorModes
[] =
3553 wxLogTrace(wxT("grid"),
3554 wxT("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
3555 win
== m_colWindow
? wxT("colLabelWin")
3556 : win
? wxT("rowLabelWin")
3558 cursorModes
[m_cursorMode
], cursorModes
[mode
]);
3559 #endif // wxUSE_LOG_TRACE
3561 if ( mode
== m_cursorMode
&&
3562 win
== m_winCapture
&&
3563 captureMouse
== (m_winCapture
!= NULL
))
3568 // by default use the grid itself
3574 m_winCapture
->ReleaseMouse();
3575 m_winCapture
= NULL
;
3578 m_cursorMode
= mode
;
3580 switch ( m_cursorMode
)
3582 case WXGRID_CURSOR_RESIZE_ROW
:
3583 win
->SetCursor( m_rowResizeCursor
);
3586 case WXGRID_CURSOR_RESIZE_COL
:
3587 win
->SetCursor( m_colResizeCursor
);
3590 case WXGRID_CURSOR_MOVE_COL
:
3591 win
->SetCursor( wxCursor(wxCURSOR_HAND
) );
3595 win
->SetCursor( *wxSTANDARD_CURSOR
);
3599 // we need to capture mouse when resizing
3600 bool resize
= m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
||
3601 m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
;
3603 if ( captureMouse
&& resize
)
3605 win
->CaptureMouse();
3610 // ----------------------------------------------------------------------------
3611 // grid mouse event processing
3612 // ----------------------------------------------------------------------------
3615 wxGrid::DoGridCellDrag(wxMouseEvent
& event
,
3616 const wxGridCellCoords
& coords
,
3619 if ( coords
== wxGridNoCellCoords
)
3620 return; // we're outside any valid cell
3622 // Hide the edit control, so it won't interfere with drag-shrinking.
3623 if ( IsCellEditControlShown() )
3625 HideCellEditControl();
3626 SaveEditControlValue();
3629 switch ( event
.GetModifiers() )
3632 if ( m_selectedBlockCorner
== wxGridNoCellCoords
)
3633 m_selectedBlockCorner
= coords
;
3634 UpdateBlockBeingSelected(m_selectedBlockCorner
, coords
);
3638 if ( CanDragCell() )
3642 if ( m_selectedBlockCorner
== wxGridNoCellCoords
)
3643 m_selectedBlockCorner
= coords
;
3645 SendEvent(wxEVT_GRID_CELL_BEGIN_DRAG
, coords
, event
);
3650 UpdateBlockBeingSelected(m_currentCellCoords
, coords
);
3654 // we don't handle the other key modifiers
3659 void wxGrid::DoGridLineDrag(wxMouseEvent
& event
, const wxGridOperations
& oper
)
3661 wxClientDC
dc(m_gridWin
);
3663 dc
.SetLogicalFunction(wxINVERT
);
3665 const wxRect
rectWin(CalcUnscrolledPosition(wxPoint(0, 0)),
3666 m_gridWin
->GetClientSize());
3668 // erase the previously drawn line, if any
3669 if ( m_dragLastPos
>= 0 )
3670 oper
.DrawParallelLineInRect(dc
, rectWin
, m_dragLastPos
);
3672 // we need the vertical position for rows and horizontal for columns here
3673 m_dragLastPos
= oper
.Dual().Select(CalcUnscrolledPosition(event
.GetPosition()));
3675 // don't allow resizing beneath the minimal size
3676 const int posMin
= oper
.GetLineStartPos(this, m_dragRowOrCol
) +
3677 oper
.GetMinimalLineSize(this, m_dragRowOrCol
);
3678 if ( m_dragLastPos
< posMin
)
3679 m_dragLastPos
= posMin
;
3681 // and draw it at the new position
3682 oper
.DrawParallelLineInRect(dc
, rectWin
, m_dragLastPos
);
3685 void wxGrid::DoGridDragEvent(wxMouseEvent
& event
, const wxGridCellCoords
& coords
)
3687 if ( !m_isDragging
)
3689 // Don't start doing anything until the mouse has been dragged far
3691 const wxPoint
& pt
= event
.GetPosition();
3692 if ( m_startDragPos
== wxDefaultPosition
)
3694 m_startDragPos
= pt
;
3698 if ( abs(m_startDragPos
.x
- pt
.x
) <= DRAG_SENSITIVITY
&&
3699 abs(m_startDragPos
.y
- pt
.y
) <= DRAG_SENSITIVITY
)
3703 const bool isFirstDrag
= !m_isDragging
;
3704 m_isDragging
= true;
3706 switch ( m_cursorMode
)
3708 case WXGRID_CURSOR_SELECT_CELL
:
3709 DoGridCellDrag(event
, coords
, isFirstDrag
);
3712 case WXGRID_CURSOR_RESIZE_ROW
:
3713 DoGridLineDrag(event
, wxGridRowOperations());
3716 case WXGRID_CURSOR_RESIZE_COL
:
3717 DoGridLineDrag(event
, wxGridColumnOperations());
3726 m_winCapture
= m_gridWin
;
3727 m_winCapture
->CaptureMouse();
3732 wxGrid::DoGridCellLeftDown(wxMouseEvent
& event
,
3733 const wxGridCellCoords
& coords
,
3736 if ( SendEvent(wxEVT_GRID_CELL_LEFT_CLICK
, coords
, event
) )
3738 // event handled by user code, no need to do anything here
3742 if ( !event
.CmdDown() )
3745 if ( event
.ShiftDown() )
3749 m_selection
->SelectBlock(m_currentCellCoords
, coords
, event
);
3750 m_selectedBlockCorner
= coords
;
3753 else if ( XToEdgeOfCol(pos
.x
) < 0 && YToEdgeOfRow(pos
.y
) < 0 )
3755 DisableCellEditControl();
3756 MakeCellVisible( coords
);
3758 if ( event
.CmdDown() )
3762 m_selection
->ToggleCellSelection(coords
, event
);
3765 m_selectedBlockTopLeft
= wxGridNoCellCoords
;
3766 m_selectedBlockBottomRight
= wxGridNoCellCoords
;
3767 m_selectedBlockCorner
= coords
;
3771 m_waitForSlowClick
= m_currentCellCoords
== coords
&&
3772 coords
!= wxGridNoCellCoords
;
3773 SetCurrentCell( coords
);
3779 wxGrid::DoGridCellLeftDClick(wxMouseEvent
& event
,
3780 const wxGridCellCoords
& coords
,
3783 if ( XToEdgeOfCol(pos
.x
) < 0 && YToEdgeOfRow(pos
.y
) < 0 )
3785 if ( !SendEvent(wxEVT_GRID_CELL_LEFT_DCLICK
, coords
, event
) )
3787 // we want double click to select a cell and start editing
3788 // (i.e. to behave in same way as sequence of two slow clicks):
3789 m_waitForSlowClick
= true;
3795 wxGrid::DoGridCellLeftUp(wxMouseEvent
& event
, const wxGridCellCoords
& coords
)
3797 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3801 m_winCapture
->ReleaseMouse();
3802 m_winCapture
= NULL
;
3805 if ( coords
== m_currentCellCoords
&& m_waitForSlowClick
&& CanEnableCellControl() )
3808 EnableCellEditControl();
3810 wxGridCellAttr
*attr
= GetCellAttr(coords
);
3811 wxGridCellEditor
*editor
= attr
->GetEditor(this, coords
.GetRow(), coords
.GetCol());
3812 editor
->StartingClick();
3816 m_waitForSlowClick
= false;
3818 else if ( m_selectedBlockTopLeft
!= wxGridNoCellCoords
&&
3819 m_selectedBlockBottomRight
!= wxGridNoCellCoords
)
3823 m_selection
->SelectBlock( m_selectedBlockTopLeft
,
3824 m_selectedBlockBottomRight
,
3828 m_selectedBlockTopLeft
= wxGridNoCellCoords
;
3829 m_selectedBlockBottomRight
= wxGridNoCellCoords
;
3831 // Show the edit control, if it has been hidden for
3833 ShowCellEditControl();
3836 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
3838 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3839 DoEndDragResizeRow(event
);
3841 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
3843 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3844 DoEndDragResizeCol(event
);
3851 wxGrid::DoGridMouseMoveEvent(wxMouseEvent
& WXUNUSED(event
),
3852 const wxGridCellCoords
& coords
,
3855 if ( coords
.GetRow() < 0 || coords
.GetCol() < 0 )
3857 // out of grid cell area
3858 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3862 int dragRow
= YToEdgeOfRow( pos
.y
);
3863 int dragCol
= XToEdgeOfCol( pos
.x
);
3865 // Dragging on the corner of a cell to resize in both
3866 // directions is not implemented yet...
3868 if ( dragRow
>= 0 && dragCol
>= 0 )
3870 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3874 if ( dragRow
>= 0 && CanDragGridSize() && CanDragRowSize(dragRow
) )
3876 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3878 m_dragRowOrCol
= dragRow
;
3879 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, NULL
, false);
3882 // When using the native header window we can only resize the columns by
3883 // dragging the dividers in it because we can't make it enter into the
3884 // column resizing mode programmatically
3885 else if ( dragCol
>= 0 && !m_useNativeHeader
&&
3886 CanDragGridSize() && CanDragColSize(dragCol
) )
3888 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3890 m_dragRowOrCol
= dragCol
;
3891 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, NULL
, false);
3894 else // Neither on a row or col edge
3896 if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
3898 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3903 void wxGrid::ProcessGridCellMouseEvent(wxMouseEvent
& event
)
3905 const wxPoint pos
= CalcUnscrolledPosition(event
.GetPosition());
3907 // coordinates of the cell under mouse
3908 wxGridCellCoords coords
= XYToCell(pos
);
3910 int cell_rows
, cell_cols
;
3911 GetCellSize( coords
.GetRow(), coords
.GetCol(), &cell_rows
, &cell_cols
);
3912 if ( (cell_rows
< 0) || (cell_cols
< 0) )
3914 coords
.SetRow(coords
.GetRow() + cell_rows
);
3915 coords
.SetCol(coords
.GetCol() + cell_cols
);
3918 if ( event
.Dragging() )
3920 if ( event
.LeftIsDown() )
3921 DoGridDragEvent(event
, coords
);
3927 m_isDragging
= false;
3928 m_startDragPos
= wxDefaultPosition
;
3930 // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
3931 // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
3934 if ( event
.Entering() || event
.Leaving() )
3936 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3937 m_gridWin
->SetCursor( *wxSTANDARD_CURSOR
);
3941 // deal with various button presses
3942 if ( event
.IsButton() )
3944 if ( coords
!= wxGridNoCellCoords
)
3946 DisableCellEditControl();
3948 if ( event
.LeftDown() )
3949 DoGridCellLeftDown(event
, coords
, pos
);
3950 else if ( event
.LeftDClick() )
3951 DoGridCellLeftDClick(event
, coords
, pos
);
3952 else if ( event
.RightDown() )
3953 SendEvent(wxEVT_GRID_CELL_RIGHT_CLICK
, coords
, event
);
3954 else if ( event
.RightDClick() )
3955 SendEvent(wxEVT_GRID_CELL_RIGHT_DCLICK
, coords
, event
);
3958 // this one should be called even if we're not over any cell
3959 if ( event
.LeftUp() )
3961 DoGridCellLeftUp(event
, coords
);
3964 else if ( event
.Moving() )
3966 DoGridMouseMoveEvent(event
, coords
, pos
);
3968 else // unknown mouse event?
3974 // this function returns true only if the size really changed
3975 bool wxGrid::DoEndDragResizeLine(const wxGridOperations
& oper
)
3977 if ( m_dragLastPos
== -1 )
3980 const wxGridOperations
& doper
= oper
.Dual();
3982 const wxSize size
= m_gridWin
->GetClientSize();
3984 const wxPoint ptOrigin
= CalcUnscrolledPosition(wxPoint(0, 0));
3986 // erase the last line we drew
3987 wxClientDC
dc(m_gridWin
);
3989 dc
.SetLogicalFunction(wxINVERT
);
3991 const int posLineStart
= oper
.Select(ptOrigin
);
3992 const int posLineEnd
= oper
.Select(ptOrigin
) + oper
.Select(size
);
3994 oper
.DrawParallelLine(dc
, posLineStart
, posLineEnd
, m_dragLastPos
);
3996 // temporarily hide the edit control before resizing
3997 HideCellEditControl();
3998 SaveEditControlValue();
4000 // do resize the line
4001 const int lineStart
= oper
.GetLineStartPos(this, m_dragRowOrCol
);
4002 const int lineSizeOld
= oper
.GetLineSize(this, m_dragRowOrCol
);
4003 oper
.SetLineSize(this, m_dragRowOrCol
,
4004 wxMax(m_dragLastPos
- lineStart
,
4005 oper
.GetMinimalLineSize(this, m_dragRowOrCol
)));
4007 sizeChanged
= oper
.GetLineSize(this, m_dragRowOrCol
) != lineSizeOld
;
4011 // refresh now if we're not frozen
4012 if ( !GetBatchCount() )
4014 // we need to refresh everything beyond the resized line in the header
4017 // get the position from which to refresh in the other direction
4018 wxRect
rect(CellToRect(oper
.MakeCoords(m_dragRowOrCol
, 0)));
4019 rect
.SetPosition(CalcScrolledPosition(rect
.GetPosition()));
4021 // we only need the ordinate (for rows) or abscissa (for columns) here,
4022 // and need to cover the entire window in the other direction
4023 oper
.Select(rect
) = 0;
4025 wxRect
rectHeader(rect
.GetPosition(),
4028 oper
.GetHeaderWindowSize(this),
4029 doper
.Select(size
) - doper
.Select(rect
)
4032 oper
.GetHeaderWindow(this)->Refresh(true, &rectHeader
);
4035 // also refresh the grid window: extend the rectangle
4038 oper
.SelectSize(rect
) = oper
.Select(size
);
4040 int subtractLines
= 0;
4041 const int lineStart
= oper
.PosToLine(this, posLineStart
);
4042 if ( lineStart
>= 0 )
4044 // ensure that if we have a multi-cell block we redraw all of
4045 // it by increasing the refresh area to cover it entirely if a
4046 // part of it is affected
4047 const int lineEnd
= oper
.PosToLine(this, posLineEnd
, true);
4048 for ( int line
= lineStart
; line
< lineEnd
; line
++ )
4050 int cellLines
= oper
.Select(
4051 GetCellSize(oper
.MakeCoords(m_dragRowOrCol
, line
)));
4052 if ( cellLines
< subtractLines
)
4053 subtractLines
= cellLines
;
4058 oper
.GetLineStartPos(this, m_dragRowOrCol
+ subtractLines
);
4059 startPos
= doper
.CalcScrolledPosition(this, startPos
);
4061 doper
.Select(rect
) = startPos
;
4062 doper
.SelectSize(rect
) = doper
.Select(size
) - startPos
;
4064 m_gridWin
->Refresh(false, &rect
);
4068 // show the edit control back again
4069 ShowCellEditControl();
4074 void wxGrid::DoEndDragResizeRow(const wxMouseEvent
& event
)
4076 // TODO: generate RESIZING event, see #10754
4078 if ( DoEndDragResizeLine(wxGridRowOperations()) )
4079 SendGridSizeEvent(wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
4082 void wxGrid::DoEndDragResizeCol(const wxMouseEvent
& event
)
4084 // TODO: generate RESIZING event, see #10754
4086 if ( DoEndDragResizeLine(wxGridColumnOperations()) )
4087 SendGridSizeEvent(wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
4090 void wxGrid::DoStartMoveCol(int col
)
4092 m_dragRowOrCol
= col
;
4095 void wxGrid::DoEndMoveCol(int pos
)
4097 wxASSERT_MSG( m_dragRowOrCol
!= -1, "no matching DoStartMoveCol?" );
4099 if ( SendEvent(wxEVT_GRID_COL_MOVE
, -1, m_dragRowOrCol
) != -1 )
4100 SetColPos(m_dragRowOrCol
, pos
);
4101 //else: vetoed by user
4103 m_dragRowOrCol
= -1;
4106 void wxGrid::RefreshAfterColPosChange()
4108 // recalculate the column rights as the column positions have changed,
4109 // unless we calculate them dynamically because all columns widths are the
4110 // same and it's easy to do
4111 if ( !m_colWidths
.empty() )
4114 for ( int colPos
= 0; colPos
< m_numCols
; colPos
++ )
4116 int colID
= GetColAt( colPos
);
4118 colRight
+= m_colWidths
[colID
];
4119 m_colRights
[colID
] = colRight
;
4123 // and make the changes visible
4124 if ( m_useNativeHeader
)
4126 if ( m_colAt
.empty() )
4127 GetGridColHeader()->ResetColumnsOrder();
4129 GetGridColHeader()->SetColumnsOrder(m_colAt
);
4133 m_colWindow
->Refresh();
4135 m_gridWin
->Refresh();
4138 void wxGrid::SetColumnsOrder(const wxArrayInt
& order
)
4142 RefreshAfterColPosChange();
4145 void wxGrid::SetColPos(int idx
, int pos
)
4147 // we're going to need m_colAt now, initialize it if needed
4148 if ( m_colAt
.empty() )
4150 m_colAt
.reserve(m_numCols
);
4151 for ( int i
= 0; i
< m_numCols
; i
++ )
4152 m_colAt
.push_back(i
);
4155 wxHeaderCtrl::MoveColumnInOrderArray(m_colAt
, idx
, pos
);
4157 RefreshAfterColPosChange();
4160 void wxGrid::ResetColPos()
4164 RefreshAfterColPosChange();
4167 void wxGrid::EnableDragColMove( bool enable
)
4169 if ( m_canDragColMove
== enable
)
4172 if ( m_useNativeHeader
)
4174 // update all columns to make them [not] reorderable
4175 GetGridColHeader()->SetColumnCount(m_numCols
);
4178 m_canDragColMove
= enable
;
4180 // we use to call ResetColPos() from here if !enable but this doesn't seem
4181 // right as it would mean there would be no way to "freeze" the current
4182 // columns order by disabling moving them after putting them in the desired
4183 // order, whereas now you can always call ResetColPos() manually if needed
4188 // ------ interaction with data model
4190 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
4192 switch ( msg
.GetId() )
4194 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
4195 return GetModelValues();
4197 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
4198 return SetModelValues();
4200 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
4201 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
4202 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
4203 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
4204 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
4205 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
4206 return Redimension( msg
);
4213 // The behaviour of this function depends on the grid table class
4214 // Clear() function. For the default wxGridStringTable class the
4215 // behaviour is to replace all cell contents with wxEmptyString but
4216 // not to change the number of rows or cols.
4218 void wxGrid::ClearGrid()
4222 if (IsCellEditControlEnabled())
4223 DisableCellEditControl();
4226 if (!GetBatchCount())
4227 m_gridWin
->Refresh();
4232 wxGrid::DoModifyLines(bool (wxGridTableBase::*funcModify
)(size_t, size_t),
4233 int pos
, int num
, bool WXUNUSED(updateLabels
) )
4235 wxCHECK_MSG( m_created
, false, "must finish creating the grid first" );
4240 if ( IsCellEditControlEnabled() )
4241 DisableCellEditControl();
4243 return (m_table
->*funcModify
)(pos
, num
);
4245 // the table will have sent the results of the insert row
4246 // operation to this view object as a grid table message
4250 wxGrid::DoAppendLines(bool (wxGridTableBase::*funcAppend
)(size_t),
4251 int num
, bool WXUNUSED(updateLabels
))
4253 wxCHECK_MSG( m_created
, false, "must finish creating the grid first" );
4258 return (m_table
->*funcAppend
)(num
);
4261 // ----------------------------------------------------------------------------
4262 // event generation helpers
4263 // ----------------------------------------------------------------------------
4266 wxGrid::SendGridSizeEvent(wxEventType type
,
4268 const wxMouseEvent
& mouseEv
)
4270 int rowOrCol
= row
== -1 ? col
: row
;
4272 wxGridSizeEvent
gridEvt( GetId(),
4276 mouseEv
.GetX() + GetRowLabelSize(),
4277 mouseEv
.GetY() + GetColLabelSize(),
4280 GetEventHandler()->ProcessEvent(gridEvt
);
4283 // Generate a grid event based on a mouse event and return:
4284 // -1 if the event was vetoed
4285 // +1 if the event was processed (but not vetoed)
4286 // 0 if the event wasn't handled
4288 wxGrid::SendEvent(const wxEventType type
,
4290 const wxMouseEvent
& mouseEv
)
4292 bool claimed
, vetoed
;
4294 if ( type
== wxEVT_GRID_RANGE_SELECT
)
4296 // Right now, it should _never_ end up here!
4297 wxGridRangeSelectEvent
gridEvt( GetId(),
4300 m_selectedBlockTopLeft
,
4301 m_selectedBlockBottomRight
,
4305 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
4306 vetoed
= !gridEvt
.IsAllowed();
4308 else if ( type
== wxEVT_GRID_LABEL_LEFT_CLICK
||
4309 type
== wxEVT_GRID_LABEL_LEFT_DCLICK
||
4310 type
== wxEVT_GRID_LABEL_RIGHT_CLICK
||
4311 type
== wxEVT_GRID_LABEL_RIGHT_DCLICK
)
4313 wxPoint pos
= mouseEv
.GetPosition();
4315 if ( mouseEv
.GetEventObject() == GetGridRowLabelWindow() )
4316 pos
.y
+= GetColLabelSize();
4317 if ( mouseEv
.GetEventObject() == GetGridColLabelWindow() )
4318 pos
.x
+= GetRowLabelSize();
4320 wxGridEvent
gridEvt( GetId(),
4328 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
4329 vetoed
= !gridEvt
.IsAllowed();
4333 wxGridEvent
gridEvt( GetId(),
4337 mouseEv
.GetX() + GetRowLabelSize(),
4338 mouseEv
.GetY() + GetColLabelSize(),
4341 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
4342 vetoed
= !gridEvt
.IsAllowed();
4345 // A Veto'd event may not be `claimed' so test this first
4349 return claimed
? 1 : 0;
4352 // Generate a grid event of specified type, return value same as above
4355 wxGrid::SendEvent(const wxEventType type
, int row
, int col
, const wxString
& s
)
4357 wxGridEvent
gridEvt( GetId(), type
, this, row
, col
);
4358 gridEvt
.SetString(s
);
4360 const bool claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
4362 // A Veto'd event may not be `claimed' so test this first
4363 if ( !gridEvt
.IsAllowed() )
4366 return claimed
? 1 : 0;
4369 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
4371 // needed to prevent zillions of paint events on MSW
4375 void wxGrid::Refresh(bool eraseb
, const wxRect
* rect
)
4377 // Don't do anything if between Begin/EndBatch...
4378 // EndBatch() will do all this on the last nested one anyway.
4379 if ( m_created
&& !GetBatchCount() )
4381 // Refresh to get correct scrolled position:
4382 wxScrolledWindow::Refresh(eraseb
, rect
);
4386 int rect_x
, rect_y
, rectWidth
, rectHeight
;
4387 int width_label
, width_cell
, height_label
, height_cell
;
4390 // Copy rectangle can get scroll offsets..
4391 rect_x
= rect
->GetX();
4392 rect_y
= rect
->GetY();
4393 rectWidth
= rect
->GetWidth();
4394 rectHeight
= rect
->GetHeight();
4396 width_label
= m_rowLabelWidth
- rect_x
;
4397 if (width_label
> rectWidth
)
4398 width_label
= rectWidth
;
4400 height_label
= m_colLabelHeight
- rect_y
;
4401 if (height_label
> rectHeight
)
4402 height_label
= rectHeight
;
4404 if (rect_x
> m_rowLabelWidth
)
4406 x
= rect_x
- m_rowLabelWidth
;
4407 width_cell
= rectWidth
;
4412 width_cell
= rectWidth
- (m_rowLabelWidth
- rect_x
);
4415 if (rect_y
> m_colLabelHeight
)
4417 y
= rect_y
- m_colLabelHeight
;
4418 height_cell
= rectHeight
;
4423 height_cell
= rectHeight
- (m_colLabelHeight
- rect_y
);
4426 // Paint corner label part intersecting rect.
4427 if ( width_label
> 0 && height_label
> 0 )
4429 wxRect
anotherrect(rect_x
, rect_y
, width_label
, height_label
);
4430 m_cornerLabelWin
->Refresh(eraseb
, &anotherrect
);
4433 // Paint col labels part intersecting rect.
4434 if ( width_cell
> 0 && height_label
> 0 )
4436 wxRect
anotherrect(x
, rect_y
, width_cell
, height_label
);
4437 m_colWindow
->Refresh(eraseb
, &anotherrect
);
4440 // Paint row labels part intersecting rect.
4441 if ( width_label
> 0 && height_cell
> 0 )
4443 wxRect
anotherrect(rect_x
, y
, width_label
, height_cell
);
4444 m_rowLabelWin
->Refresh(eraseb
, &anotherrect
);
4447 // Paint cell area part intersecting rect.
4448 if ( width_cell
> 0 && height_cell
> 0 )
4450 wxRect
anotherrect(x
, y
, width_cell
, height_cell
);
4451 m_gridWin
->Refresh(eraseb
, &anotherrect
);
4456 m_cornerLabelWin
->Refresh(eraseb
, NULL
);
4457 m_colWindow
->Refresh(eraseb
, NULL
);
4458 m_rowLabelWin
->Refresh(eraseb
, NULL
);
4459 m_gridWin
->Refresh(eraseb
, NULL
);
4464 void wxGrid::OnSize(wxSizeEvent
& WXUNUSED(event
))
4466 if (m_targetWindow
!= this) // check whether initialisation has been done
4468 // reposition our children windows
4473 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
4475 if ( m_inOnKeyDown
)
4477 // shouldn't be here - we are going round in circles...
4479 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") );
4482 m_inOnKeyDown
= true;
4484 // propagate the event up and see if it gets processed
4485 wxWindow
*parent
= GetParent();
4486 wxKeyEvent
keyEvt( event
);
4487 keyEvt
.SetEventObject( parent
);
4489 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
4491 if (GetLayoutDirection() == wxLayout_RightToLeft
)
4493 if (event
.GetKeyCode() == WXK_RIGHT
)
4494 event
.m_keyCode
= WXK_LEFT
;
4495 else if (event
.GetKeyCode() == WXK_LEFT
)
4496 event
.m_keyCode
= WXK_RIGHT
;
4499 // try local handlers
4500 switch ( event
.GetKeyCode() )
4503 if ( event
.ControlDown() )
4504 MoveCursorUpBlock( event
.ShiftDown() );
4506 MoveCursorUp( event
.ShiftDown() );
4510 if ( event
.ControlDown() )
4511 MoveCursorDownBlock( event
.ShiftDown() );
4513 MoveCursorDown( event
.ShiftDown() );
4517 if ( event
.ControlDown() )
4518 MoveCursorLeftBlock( event
.ShiftDown() );
4520 MoveCursorLeft( event
.ShiftDown() );
4524 if ( event
.ControlDown() )
4525 MoveCursorRightBlock( event
.ShiftDown() );
4527 MoveCursorRight( event
.ShiftDown() );
4531 case WXK_NUMPAD_ENTER
:
4532 if ( event
.ControlDown() )
4534 event
.Skip(); // to let the edit control have the return
4538 if ( GetGridCursorRow() < GetNumberRows()-1 )
4540 MoveCursorDown( event
.ShiftDown() );
4544 // at the bottom of a column
4545 DisableCellEditControl();
4555 if (event
.ShiftDown())
4557 if ( GetGridCursorCol() > 0 )
4559 MoveCursorLeft( false );
4564 DisableCellEditControl();
4569 if ( GetGridCursorCol() < GetNumberCols() - 1 )
4571 MoveCursorRight( false );
4576 DisableCellEditControl();
4582 if ( event
.ControlDown() )
4593 if ( event
.ControlDown() )
4595 GoToCell(m_numRows
- 1, m_numCols
- 1);
4612 // Ctrl-Space selects the current column, Shift-Space -- the
4613 // current row and Ctrl-Shift-Space -- everything
4614 switch ( m_selection
? event
.GetModifiers() : wxMOD_NONE
)
4617 m_selection
->SelectCol(m_currentCellCoords
.GetCol());
4621 m_selection
->SelectRow(m_currentCellCoords
.GetRow());
4624 case wxMOD_CONTROL
| wxMOD_SHIFT
:
4625 m_selection
->SelectBlock(0, 0,
4626 m_numRows
- 1, m_numCols
- 1);
4630 if ( !IsEditable() )
4632 MoveCursorRight(false);
4635 //else: fall through
4648 m_inOnKeyDown
= false;
4651 void wxGrid::OnKeyUp( wxKeyEvent
& event
)
4653 // try local handlers
4655 if ( event
.GetKeyCode() == WXK_SHIFT
)
4657 if ( m_selectedBlockTopLeft
!= wxGridNoCellCoords
&&
4658 m_selectedBlockBottomRight
!= wxGridNoCellCoords
)
4662 m_selection
->SelectBlock(
4663 m_selectedBlockTopLeft
,
4664 m_selectedBlockBottomRight
,
4669 m_selectedBlockTopLeft
= wxGridNoCellCoords
;
4670 m_selectedBlockBottomRight
= wxGridNoCellCoords
;
4671 m_selectedBlockCorner
= wxGridNoCellCoords
;
4675 void wxGrid::OnChar( wxKeyEvent
& event
)
4677 // is it possible to edit the current cell at all?
4678 if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
4680 // yes, now check whether the cells editor accepts the key
4681 int row
= m_currentCellCoords
.GetRow();
4682 int col
= m_currentCellCoords
.GetCol();
4683 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
4684 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
4686 // <F2> is special and will always start editing, for
4687 // other keys - ask the editor itself
4688 if ( (event
.GetKeyCode() == WXK_F2
&& !event
.HasModifiers())
4689 || editor
->IsAcceptedKey(event
) )
4691 // ensure cell is visble
4692 MakeCellVisible(row
, col
);
4693 EnableCellEditControl();
4695 // a problem can arise if the cell is not completely
4696 // visible (even after calling MakeCellVisible the
4697 // control is not created and calling StartingKey will
4699 if ( event
.GetKeyCode() != WXK_F2
&& editor
->IsCreated() && m_cellEditCtrlEnabled
)
4700 editor
->StartingKey(event
);
4716 void wxGrid::OnEraseBackground(wxEraseEvent
&)
4720 bool wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
4722 if ( SendEvent(wxEVT_GRID_SELECT_CELL
, coords
) == -1 )
4724 // the event has been vetoed - do nothing
4728 #if !defined(__WXMAC__)
4729 wxClientDC
dc( m_gridWin
);
4733 if ( m_currentCellCoords
!= wxGridNoCellCoords
)
4735 DisableCellEditControl();
4737 if ( IsVisible( m_currentCellCoords
, false ) )
4740 r
= BlockToDeviceRect( m_currentCellCoords
, m_currentCellCoords
);
4741 if ( !m_gridLinesEnabled
)
4749 wxGridCellCoordsArray cells
= CalcCellsExposed( r
);
4751 // Otherwise refresh redraws the highlight!
4752 m_currentCellCoords
= coords
;
4754 #if defined(__WXMAC__)
4755 m_gridWin
->Refresh(true /*, & r */);
4757 DrawGridCellArea( dc
, cells
);
4758 DrawAllGridLines( dc
, r
);
4763 m_currentCellCoords
= coords
;
4765 wxGridCellAttr
*attr
= GetCellAttr( coords
);
4766 #if !defined(__WXMAC__)
4767 DrawCellHighlight( dc
, attr
);
4775 wxGrid::UpdateBlockBeingSelected(int topRow
, int leftCol
,
4776 int bottomRow
, int rightCol
)
4780 switch ( m_selection
->GetSelectionMode() )
4783 wxFAIL_MSG( "unknown selection mode" );
4786 case wxGridSelectCells
:
4787 // arbitrary blocks selection allowed so just use the cell
4788 // coordinates as is
4791 case wxGridSelectRows
:
4792 // only full rows selection allowd, ensure that we do select
4795 rightCol
= GetNumberCols() - 1;
4798 case wxGridSelectColumns
:
4799 // same as above but for columns
4801 bottomRow
= GetNumberRows() - 1;
4804 case wxGridSelectRowsOrColumns
:
4805 // in this mode we can select only full rows or full columns so
4806 // it doesn't make sense to select blocks at all (and we can't
4807 // extend the block because there is no preferred direction, we
4808 // could only extend it to cover the entire grid but this is
4814 m_selectedBlockCorner
= wxGridCellCoords(bottomRow
, rightCol
);
4815 MakeCellVisible(m_selectedBlockCorner
);
4817 EnsureFirstLessThanSecond(topRow
, bottomRow
);
4818 EnsureFirstLessThanSecond(leftCol
, rightCol
);
4820 wxGridCellCoords updateTopLeft
= wxGridCellCoords(topRow
, leftCol
),
4821 updateBottomRight
= wxGridCellCoords(bottomRow
, rightCol
);
4823 // First the case that we selected a completely new area
4824 if ( m_selectedBlockTopLeft
== wxGridNoCellCoords
||
4825 m_selectedBlockBottomRight
== wxGridNoCellCoords
)
4828 rect
= BlockToDeviceRect( wxGridCellCoords ( topRow
, leftCol
),
4829 wxGridCellCoords ( bottomRow
, rightCol
) );
4830 m_gridWin
->Refresh( false, &rect
);
4833 // Now handle changing an existing selection area.
4834 else if ( m_selectedBlockTopLeft
!= updateTopLeft
||
4835 m_selectedBlockBottomRight
!= updateBottomRight
)
4837 // Compute two optimal update rectangles:
4838 // Either one rectangle is a real subset of the
4839 // other, or they are (almost) disjoint!
4841 bool need_refresh
[4];
4845 need_refresh
[3] = false;
4848 // Store intermediate values
4849 wxCoord oldLeft
= m_selectedBlockTopLeft
.GetCol();
4850 wxCoord oldTop
= m_selectedBlockTopLeft
.GetRow();
4851 wxCoord oldRight
= m_selectedBlockBottomRight
.GetCol();
4852 wxCoord oldBottom
= m_selectedBlockBottomRight
.GetRow();
4854 // Determine the outer/inner coordinates.
4855 EnsureFirstLessThanSecond(oldLeft
, leftCol
);
4856 EnsureFirstLessThanSecond(oldTop
, topRow
);
4857 EnsureFirstLessThanSecond(rightCol
, oldRight
);
4858 EnsureFirstLessThanSecond(bottomRow
, oldBottom
);
4860 // Now, either the stuff marked old is the outer
4861 // rectangle or we don't have a situation where one
4862 // is contained in the other.
4864 if ( oldLeft
< leftCol
)
4866 // Refresh the newly selected or deselected
4867 // area to the left of the old or new selection.
4868 need_refresh
[0] = true;
4869 rect
[0] = BlockToDeviceRect(
4870 wxGridCellCoords( oldTop
, oldLeft
),
4871 wxGridCellCoords( oldBottom
, leftCol
- 1 ) );
4874 if ( oldTop
< topRow
)
4876 // Refresh the newly selected or deselected
4877 // area above the old or new selection.
4878 need_refresh
[1] = true;
4879 rect
[1] = BlockToDeviceRect(
4880 wxGridCellCoords( oldTop
, leftCol
),
4881 wxGridCellCoords( topRow
- 1, rightCol
) );
4884 if ( oldRight
> rightCol
)
4886 // Refresh the newly selected or deselected
4887 // area to the right of the old or new selection.
4888 need_refresh
[2] = true;
4889 rect
[2] = BlockToDeviceRect(
4890 wxGridCellCoords( oldTop
, rightCol
+ 1 ),
4891 wxGridCellCoords( oldBottom
, oldRight
) );
4894 if ( oldBottom
> bottomRow
)
4896 // Refresh the newly selected or deselected
4897 // area below the old or new selection.
4898 need_refresh
[3] = true;
4899 rect
[3] = BlockToDeviceRect(
4900 wxGridCellCoords( bottomRow
+ 1, leftCol
),
4901 wxGridCellCoords( oldBottom
, rightCol
) );
4904 // various Refresh() calls
4905 for (i
= 0; i
< 4; i
++ )
4906 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
4907 m_gridWin
->Refresh( false, &(rect
[i
]) );
4911 m_selectedBlockTopLeft
= updateTopLeft
;
4912 m_selectedBlockBottomRight
= updateBottomRight
;
4916 // ------ functions to get/send data (see also public functions)
4919 bool wxGrid::GetModelValues()
4921 // Hide the editor, so it won't hide a changed value.
4922 HideCellEditControl();
4926 // all we need to do is repaint the grid
4928 m_gridWin
->Refresh();
4935 bool wxGrid::SetModelValues()
4939 // Disable the editor, so it won't hide a changed value.
4940 // Do we also want to save the current value of the editor first?
4942 DisableCellEditControl();
4946 for ( row
= 0; row
< m_numRows
; row
++ )
4948 for ( col
= 0; col
< m_numCols
; col
++ )
4950 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
4960 // Note - this function only draws cells that are in the list of
4961 // exposed cells (usually set from the update region by
4962 // CalcExposedCells)
4964 void wxGrid::DrawGridCellArea( wxDC
& dc
, const wxGridCellCoordsArray
& cells
)
4966 if ( !m_numRows
|| !m_numCols
)
4969 int i
, numCells
= cells
.GetCount();
4970 int row
, col
, cell_rows
, cell_cols
;
4971 wxGridCellCoordsArray redrawCells
;
4973 for ( i
= numCells
- 1; i
>= 0; i
-- )
4975 row
= cells
[i
].GetRow();
4976 col
= cells
[i
].GetCol();
4977 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
4979 // If this cell is part of a multicell block, find owner for repaint
4980 if ( cell_rows
<= 0 || cell_cols
<= 0 )
4982 wxGridCellCoords
cell( row
+ cell_rows
, col
+ cell_cols
);
4983 bool marked
= false;
4984 for ( int j
= 0; j
< numCells
; j
++ )
4986 if ( cell
== cells
[j
] )
4995 int count
= redrawCells
.GetCount();
4996 for (int j
= 0; j
< count
; j
++)
4998 if ( cell
== redrawCells
[j
] )
5006 redrawCells
.Add( cell
);
5009 // don't bother drawing this cell
5013 // If this cell is empty, find cell to left that might want to overflow
5014 if (m_table
&& m_table
->IsEmptyCell(row
, col
))
5016 for ( int l
= 0; l
< cell_rows
; l
++ )
5018 // find a cell in this row to leave already marked for repaint
5020 for (int k
= 0; k
< int(redrawCells
.GetCount()); k
++)
5021 if ((redrawCells
[k
].GetCol() < left
) &&
5022 (redrawCells
[k
].GetRow() == row
))
5024 left
= redrawCells
[k
].GetCol();
5028 left
= 0; // oh well
5030 for (int j
= col
- 1; j
>= left
; j
--)
5032 if (!m_table
->IsEmptyCell(row
+ l
, j
))
5034 if (GetCellOverflow(row
+ l
, j
))
5036 wxGridCellCoords
cell(row
+ l
, j
);
5037 bool marked
= false;
5039 for (int k
= 0; k
< numCells
; k
++)
5041 if ( cell
== cells
[k
] )
5050 int count
= redrawCells
.GetCount();
5051 for (int k
= 0; k
< count
; k
++)
5053 if ( cell
== redrawCells
[k
] )
5060 redrawCells
.Add( cell
);
5069 DrawCell( dc
, cells
[i
] );
5072 numCells
= redrawCells
.GetCount();
5074 for ( i
= numCells
- 1; i
>= 0; i
-- )
5076 DrawCell( dc
, redrawCells
[i
] );
5080 void wxGrid::DrawGridSpace( wxDC
& dc
)
5083 m_gridWin
->GetClientSize( &cw
, &ch
);
5086 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
5088 int rightCol
= m_numCols
> 0 ? GetColRight(GetColAt( m_numCols
- 1 )) : 0;
5089 int bottomRow
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) : 0;
5091 if ( right
> rightCol
|| bottom
> bottomRow
)
5094 CalcUnscrolledPosition( 0, 0, &left
, &top
);
5096 dc
.SetBrush(GetDefaultCellBackgroundColour());
5097 dc
.SetPen( *wxTRANSPARENT_PEN
);
5099 if ( right
> rightCol
)
5101 dc
.DrawRectangle( rightCol
, top
, right
- rightCol
, ch
);
5104 if ( bottom
> bottomRow
)
5106 dc
.DrawRectangle( left
, bottomRow
, cw
, bottom
- bottomRow
);
5111 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
5113 int row
= coords
.GetRow();
5114 int col
= coords
.GetCol();
5116 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
5119 // we draw the cell border ourselves
5120 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5122 bool isCurrent
= coords
== m_currentCellCoords
;
5124 wxRect rect
= CellToRect( row
, col
);
5126 // if the editor is shown, we should use it and not the renderer
5127 // Note: However, only if it is really _shown_, i.e. not hidden!
5128 if ( isCurrent
&& IsCellEditControlShown() )
5130 // NB: this "#if..." is temporary and fixes a problem where the
5131 // edit control is erased by this code after being rendered.
5132 // On wxMac (QD build only), the cell editor is a wxTextCntl and is rendered
5133 // implicitly, causing this out-of order render.
5134 #if !defined(__WXMAC__)
5135 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
5136 editor
->PaintBackground(rect
, attr
);
5142 // but all the rest is drawn by the cell renderer and hence may be customized
5143 wxGridCellRenderer
*renderer
= attr
->GetRenderer(this, row
, col
);
5144 renderer
->Draw(*this, *attr
, dc
, rect
, row
, col
, IsInSelection(coords
));
5151 void wxGrid::DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
)
5153 // don't show highlight when the grid doesn't have focus
5157 int row
= m_currentCellCoords
.GetRow();
5158 int col
= m_currentCellCoords
.GetCol();
5160 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
5163 wxRect rect
= CellToRect(row
, col
);
5165 // hmmm... what could we do here to show that the cell is disabled?
5166 // for now, I just draw a thinner border than for the other ones, but
5167 // it doesn't look really good
5169 int penWidth
= attr
->IsReadOnly() ? m_cellHighlightROPenWidth
: m_cellHighlightPenWidth
;
5173 // The center of the drawn line is where the position/width/height of
5174 // the rectangle is actually at (on wxMSW at least), so the
5175 // size of the rectangle is reduced to compensate for the thickness of
5176 // the line. If this is too strange on non-wxMSW platforms then
5177 // please #ifdef this appropriately.
5178 rect
.x
+= penWidth
/ 2;
5179 rect
.y
+= penWidth
/ 2;
5180 rect
.width
-= penWidth
- 1;
5181 rect
.height
-= penWidth
- 1;
5183 // Now draw the rectangle
5184 // use the cellHighlightColour if the cell is inside a selection, this
5185 // will ensure the cell is always visible.
5186 dc
.SetPen(wxPen(IsInSelection(row
,col
) ? m_selectionForeground
5187 : m_cellHighlightColour
,
5189 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
5190 dc
.DrawRectangle(rect
);
5194 wxPen
wxGrid::GetDefaultGridLinePen()
5196 return wxPen(GetGridLineColour());
5199 wxPen
wxGrid::GetRowGridLinePen(int WXUNUSED(row
))
5201 return GetDefaultGridLinePen();
5204 wxPen
wxGrid::GetColGridLinePen(int WXUNUSED(col
))
5206 return GetDefaultGridLinePen();
5209 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
5211 int row
= coords
.GetRow();
5212 int col
= coords
.GetCol();
5213 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
5217 wxRect rect
= CellToRect( row
, col
);
5219 // right hand border
5220 dc
.SetPen( GetColGridLinePen(col
) );
5221 dc
.DrawLine( rect
.x
+ rect
.width
, rect
.y
,
5222 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
+ 1 );
5225 dc
.SetPen( GetRowGridLinePen(row
) );
5226 dc
.DrawLine( rect
.x
, rect
.y
+ rect
.height
,
5227 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
5230 void wxGrid::DrawHighlight(wxDC
& dc
, const wxGridCellCoordsArray
& cells
)
5232 // This if block was previously in wxGrid::OnPaint but that doesn't
5233 // seem to get called under wxGTK - MB
5235 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
5236 m_numRows
&& m_numCols
)
5238 m_currentCellCoords
.Set(0, 0);
5241 if ( IsCellEditControlShown() )
5243 // don't show highlight when the edit control is shown
5247 // if the active cell was repainted, repaint its highlight too because it
5248 // might have been damaged by the grid lines
5249 size_t count
= cells
.GetCount();
5250 for ( size_t n
= 0; n
< count
; n
++ )
5252 wxGridCellCoords cell
= cells
[n
];
5254 // If we are using attributes, then we may have just exposed another
5255 // cell in a partially-visible merged cluster of cells. If the "anchor"
5256 // (upper left) cell of this merged cluster is the cell indicated by
5257 // m_currentCellCoords, then we need to refresh the cell highlight even
5258 // though the "anchor" itself is not part of our update segment.
5259 if ( CanHaveAttributes() )
5263 GetCellSize(cell
.GetRow(), cell
.GetCol(), &rows
, &cols
);
5266 cell
.SetRow(cell
.GetRow() + rows
);
5269 cell
.SetCol(cell
.GetCol() + cols
);
5272 if ( cell
== m_currentCellCoords
)
5274 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
5275 DrawCellHighlight(dc
, attr
);
5283 // This is used to redraw all grid lines e.g. when the grid line colour
5286 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& WXUNUSED(reg
) )
5288 if ( !m_gridLinesEnabled
)
5291 int top
, bottom
, left
, right
;
5294 m_gridWin
->GetClientSize(&cw
, &ch
);
5295 CalcUnscrolledPosition( 0, 0, &left
, &top
);
5296 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
5298 // avoid drawing grid lines past the last row and col
5299 if ( m_gridLinesClipHorz
)
5304 const int lastColRight
= GetColRight(GetColAt(m_numCols
- 1));
5305 if ( right
> lastColRight
)
5306 right
= lastColRight
;
5309 if ( m_gridLinesClipVert
)
5314 const int lastRowBottom
= GetRowBottom(m_numRows
- 1);
5315 if ( bottom
> lastRowBottom
)
5316 bottom
= lastRowBottom
;
5319 // no gridlines inside multicells, clip them out
5320 int leftCol
= GetColPos( internalXToCol(left
) );
5321 int topRow
= internalYToRow(top
);
5322 int rightCol
= GetColPos( internalXToCol(right
) );
5323 int bottomRow
= internalYToRow(bottom
);
5325 wxRegion
clippedcells(0, 0, cw
, ch
);
5327 int cell_rows
, cell_cols
;
5330 for ( int j
= topRow
; j
<= bottomRow
; j
++ )
5332 for ( int colPos
= leftCol
; colPos
<= rightCol
; colPos
++ )
5334 int i
= GetColAt( colPos
);
5336 GetCellSize( j
, i
, &cell_rows
, &cell_cols
);
5337 if ((cell_rows
> 1) || (cell_cols
> 1))
5339 rect
= CellToRect(j
,i
);
5340 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
5341 clippedcells
.Subtract(rect
);
5343 else if ((cell_rows
< 0) || (cell_cols
< 0))
5345 rect
= CellToRect(j
+ cell_rows
, i
+ cell_cols
);
5346 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
5347 clippedcells
.Subtract(rect
);
5352 dc
.SetDeviceClippingRegion( clippedcells
);
5355 // horizontal grid lines
5356 for ( int i
= internalYToRow(top
); i
< m_numRows
; i
++ )
5358 int bot
= GetRowBottom(i
) - 1;
5365 dc
.SetPen( GetRowGridLinePen(i
) );
5366 dc
.DrawLine( left
, bot
, right
, bot
);
5370 // vertical grid lines
5371 for ( int colPos
= leftCol
; colPos
< m_numCols
; colPos
++ )
5373 int i
= GetColAt( colPos
);
5375 int colRight
= GetColRight(i
);
5377 if (GetLayoutDirection() != wxLayout_RightToLeft
)
5381 if ( colRight
> right
)
5384 if ( colRight
>= left
)
5386 dc
.SetPen( GetColGridLinePen(i
) );
5387 dc
.DrawLine( colRight
, top
, colRight
, bottom
);
5391 dc
.DestroyClippingRegion();
5394 void wxGrid::DrawRowLabels( wxDC
& dc
, const wxArrayInt
& rows
)
5399 const size_t numLabels
= rows
.GetCount();
5400 for ( size_t i
= 0; i
< numLabels
; i
++ )
5402 DrawRowLabel( dc
, rows
[i
] );
5406 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
5408 if ( GetRowHeight(row
) <= 0 || m_rowLabelWidth
<= 0 )
5411 const wxGridRowHeaderRenderer
&
5412 rend
= m_table
->GetAttrProvider()->GetRowHeaderRenderer(row
);
5413 wxRect
rect(0, GetRowTop(row
), m_rowLabelWidth
, GetRowHeight(row
));
5414 rend
.DrawBorder(*this, dc
, rect
);
5417 GetRowLabelAlignment(&hAlign
, &vAlign
);
5419 rend
.DrawLabel(*this, dc
, GetRowLabelValue(row
),
5420 rect
, hAlign
, vAlign
, wxHORIZONTAL
);
5423 void wxGrid::UseNativeColHeader(bool native
)
5425 if ( native
== m_useNativeHeader
)
5429 m_useNativeHeader
= native
;
5431 CreateColumnWindow();
5433 if ( m_useNativeHeader
)
5434 GetGridColHeader()->SetColumnCount(m_numCols
);
5438 void wxGrid::SetUseNativeColLabels( bool native
)
5440 wxASSERT_MSG( !m_useNativeHeader
,
5441 "doesn't make sense when using native header" );
5443 m_nativeColumnLabels
= native
;
5446 int height
= wxRendererNative::Get().GetHeaderButtonHeight( this );
5447 SetColLabelSize( height
);
5450 GetColLabelWindow()->Refresh();
5451 m_cornerLabelWin
->Refresh();
5454 void wxGrid::DrawColLabels( wxDC
& dc
,const wxArrayInt
& cols
)
5459 const size_t numLabels
= cols
.GetCount();
5460 for ( size_t i
= 0; i
< numLabels
; i
++ )
5462 DrawColLabel( dc
, cols
[i
] );
5466 void wxGrid::DrawCornerLabel(wxDC
& dc
)
5468 wxRect
rect(wxSize(m_rowLabelWidth
, m_colLabelHeight
));
5470 if ( m_nativeColumnLabels
)
5474 wxRendererNative::Get().DrawHeaderButton(m_cornerLabelWin
, dc
, rect
, 0);
5481 const wxGridCornerHeaderRenderer
&
5482 rend
= m_table
->GetAttrProvider()->GetCornerRenderer();
5484 rend
.DrawBorder(*this, dc
, rect
);
5488 void wxGrid::DrawColLabel(wxDC
& dc
, int col
)
5490 if ( GetColWidth(col
) <= 0 || m_colLabelHeight
<= 0 )
5493 int colLeft
= GetColLeft(col
);
5495 wxRect
rect(colLeft
, 0, GetColWidth(col
), m_colLabelHeight
);
5496 const wxGridColumnHeaderRenderer
&
5497 rend
= m_table
->GetAttrProvider()->GetColumnHeaderRenderer(col
);
5499 if ( m_nativeColumnLabels
)
5501 wxRendererNative::Get().DrawHeaderButton
5503 GetColLabelWindow(),
5508 ? IsSortOrderAscending()
5509 ? wxHDR_SORT_ICON_UP
5510 : wxHDR_SORT_ICON_DOWN
5511 : wxHDR_SORT_ICON_NONE
5517 rend
.DrawBorder(*this, dc
, rect
);
5521 GetColLabelAlignment(&hAlign
, &vAlign
);
5522 const int orient
= GetColLabelTextOrientation();
5524 rend
.DrawLabel(*this, dc
, GetColLabelValue(col
), rect
, hAlign
, vAlign
, orient
);
5527 // TODO: these 2 functions should be replaced with wxDC::DrawLabel() to which
5528 // we just have to add textOrientation support
5529 void wxGrid::DrawTextRectangle( wxDC
& dc
,
5530 const wxString
& value
,
5534 int textOrientation
) const
5536 wxArrayString lines
;
5538 StringToLines( value
, lines
);
5540 DrawTextRectangle(dc
, lines
, rect
, horizAlign
, vertAlign
, textOrientation
);
5543 void wxGrid::DrawTextRectangle(wxDC
& dc
,
5544 const wxArrayString
& lines
,
5548 int textOrientation
) const
5550 if ( lines
.empty() )
5553 wxDCClipper
clip(dc
, rect
);
5558 if ( textOrientation
== wxHORIZONTAL
)
5559 GetTextBoxSize( dc
, lines
, &textWidth
, &textHeight
);
5561 GetTextBoxSize( dc
, lines
, &textHeight
, &textWidth
);
5565 switch ( vertAlign
)
5567 case wxALIGN_BOTTOM
:
5568 if ( textOrientation
== wxHORIZONTAL
)
5569 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
5571 x
= rect
.x
+ rect
.width
- textWidth
;
5574 case wxALIGN_CENTRE
:
5575 if ( textOrientation
== wxHORIZONTAL
)
5576 y
= rect
.y
+ ((rect
.height
- textHeight
) / 2);
5578 x
= rect
.x
+ ((rect
.width
- textWidth
) / 2);
5583 if ( textOrientation
== wxHORIZONTAL
)
5590 // Align each line of a multi-line label
5591 size_t nLines
= lines
.GetCount();
5592 for ( size_t l
= 0; l
< nLines
; l
++ )
5594 const wxString
& line
= lines
[l
];
5598 *(textOrientation
== wxHORIZONTAL
? &y
: &x
) += dc
.GetCharHeight();
5602 wxCoord lineWidth
= 0,
5604 dc
.GetTextExtent(line
, &lineWidth
, &lineHeight
);
5606 switch ( horizAlign
)
5609 if ( textOrientation
== wxHORIZONTAL
)
5610 x
= rect
.x
+ (rect
.width
- lineWidth
- 1);
5612 y
= rect
.y
+ lineWidth
+ 1;
5615 case wxALIGN_CENTRE
:
5616 if ( textOrientation
== wxHORIZONTAL
)
5617 x
= rect
.x
+ ((rect
.width
- lineWidth
) / 2);
5619 y
= rect
.y
+ rect
.height
- ((rect
.height
- lineWidth
) / 2);
5624 if ( textOrientation
== wxHORIZONTAL
)
5627 y
= rect
.y
+ rect
.height
- 1;
5631 if ( textOrientation
== wxHORIZONTAL
)
5633 dc
.DrawText( line
, x
, y
);
5638 dc
.DrawRotatedText( line
, x
, y
, 90.0 );
5644 // Split multi-line text up into an array of strings.
5645 // Any existing contents of the string array are preserved.
5647 // TODO: refactor wxTextFile::Read() and reuse the same code from here
5648 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
) const
5652 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
5653 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
5655 while ( startPos
< (int)tVal
.length() )
5657 pos
= tVal
.Mid(startPos
).Find( eol
);
5662 else if ( pos
== 0 )
5664 lines
.Add( wxEmptyString
);
5668 lines
.Add( tVal
.Mid(startPos
, pos
) );
5671 startPos
+= pos
+ 1;
5674 if ( startPos
< (int)tVal
.length() )
5676 lines
.Add( tVal
.Mid( startPos
) );
5680 void wxGrid::GetTextBoxSize( const wxDC
& dc
,
5681 const wxArrayString
& lines
,
5682 long *width
, long *height
) const
5686 wxCoord lineW
= 0, lineH
= 0;
5689 for ( i
= 0; i
< lines
.GetCount(); i
++ )
5691 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
5692 w
= wxMax( w
, lineW
);
5701 // ------ Batch processing.
5703 void wxGrid::EndBatch()
5705 if ( m_batchCount
> 0 )
5708 if ( !m_batchCount
)
5711 m_rowLabelWin
->Refresh();
5712 m_colWindow
->Refresh();
5713 m_cornerLabelWin
->Refresh();
5714 m_gridWin
->Refresh();
5719 // Use this, rather than wxWindow::Refresh(), to force an immediate
5720 // repainting of the grid. Has no effect if you are already inside a
5721 // BeginBatch / EndBatch block.
5723 void wxGrid::ForceRefresh()
5729 bool wxGrid::Enable(bool enable
)
5731 if ( !wxScrolledWindow::Enable(enable
) )
5734 // redraw in the new state
5735 m_gridWin
->Refresh();
5741 // ------ Edit control functions
5744 void wxGrid::EnableEditing( bool edit
)
5746 if ( edit
!= m_editable
)
5749 EnableCellEditControl(edit
);
5754 void wxGrid::EnableCellEditControl( bool enable
)
5759 if ( enable
!= m_cellEditCtrlEnabled
)
5763 if ( SendEvent(wxEVT_GRID_EDITOR_SHOWN
) == -1 )
5766 // this should be checked by the caller!
5767 wxASSERT_MSG( CanEnableCellControl(), wxT("can't enable editing for this cell!") );
5769 // do it before ShowCellEditControl()
5770 m_cellEditCtrlEnabled
= enable
;
5772 ShowCellEditControl();
5776 SendEvent(wxEVT_GRID_EDITOR_HIDDEN
);
5778 HideCellEditControl();
5779 SaveEditControlValue();
5781 // do it after HideCellEditControl()
5782 m_cellEditCtrlEnabled
= enable
;
5787 bool wxGrid::IsCurrentCellReadOnly() const
5790 wxGridCellAttr
* attr
= ((wxGrid
*)this)->GetCellAttr(m_currentCellCoords
);
5791 bool readonly
= attr
->IsReadOnly();
5797 bool wxGrid::CanEnableCellControl() const
5799 return m_editable
&& (m_currentCellCoords
!= wxGridNoCellCoords
) &&
5800 !IsCurrentCellReadOnly();
5803 bool wxGrid::IsCellEditControlEnabled() const
5805 // the cell edit control might be disable for all cells or just for the
5806 // current one if it's read only
5807 return m_cellEditCtrlEnabled
? !IsCurrentCellReadOnly() : false;
5810 bool wxGrid::IsCellEditControlShown() const
5812 bool isShown
= false;
5814 if ( m_cellEditCtrlEnabled
)
5816 int row
= m_currentCellCoords
.GetRow();
5817 int col
= m_currentCellCoords
.GetCol();
5818 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5819 wxGridCellEditor
* editor
= attr
->GetEditor((wxGrid
*) this, row
, col
);
5824 if ( editor
->IsCreated() )
5826 isShown
= editor
->GetControl()->IsShown();
5836 void wxGrid::ShowCellEditControl()
5838 if ( IsCellEditControlEnabled() )
5840 if ( !IsVisible( m_currentCellCoords
, false ) )
5842 m_cellEditCtrlEnabled
= false;
5847 wxRect rect
= CellToRect( m_currentCellCoords
);
5848 int row
= m_currentCellCoords
.GetRow();
5849 int col
= m_currentCellCoords
.GetCol();
5851 // if this is part of a multicell, find owner (topleft)
5852 int cell_rows
, cell_cols
;
5853 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
5854 if ( cell_rows
<= 0 || cell_cols
<= 0 )
5858 m_currentCellCoords
.SetRow( row
);
5859 m_currentCellCoords
.SetCol( col
);
5862 // erase the highlight and the cell contents because the editor
5863 // might not cover the entire cell
5864 wxClientDC
dc( m_gridWin
);
5866 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5867 dc
.SetBrush(wxBrush(attr
->GetBackgroundColour()));
5868 dc
.SetPen(*wxTRANSPARENT_PEN
);
5869 dc
.DrawRectangle(rect
);
5871 // convert to scrolled coords
5872 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
5878 // cell is shifted by one pixel
5879 // However, don't allow x or y to become negative
5880 // since the SetSize() method interprets that as
5887 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
5888 if ( !editor
->IsCreated() )
5890 editor
->Create(m_gridWin
, wxID_ANY
,
5891 new wxGridCellEditorEvtHandler(this, editor
));
5893 wxGridEditorCreatedEvent
evt(GetId(),
5894 wxEVT_GRID_EDITOR_CREATED
,
5898 editor
->GetControl());
5899 GetEventHandler()->ProcessEvent(evt
);
5902 // resize editor to overflow into righthand cells if allowed
5903 int maxWidth
= rect
.width
;
5904 wxString value
= GetCellValue(row
, col
);
5905 if ( (value
!= wxEmptyString
) && (attr
->GetOverflow()) )
5908 GetTextExtent(value
, &maxWidth
, &y
, NULL
, NULL
, &attr
->GetFont());
5909 if (maxWidth
< rect
.width
)
5910 maxWidth
= rect
.width
;
5913 int client_right
= m_gridWin
->GetClientSize().GetWidth();
5914 if (rect
.x
+ maxWidth
> client_right
)
5915 maxWidth
= client_right
- rect
.x
;
5917 if ((maxWidth
> rect
.width
) && (col
< m_numCols
) && m_table
)
5919 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
5920 // may have changed earlier
5921 for (int i
= col
+ cell_cols
; i
< m_numCols
; i
++)
5924 GetCellSize( row
, i
, &c_rows
, &c_cols
);
5926 // looks weird going over a multicell
5927 if (m_table
->IsEmptyCell( row
, i
) &&
5928 (rect
.width
< maxWidth
) && (c_rows
== 1))
5930 rect
.width
+= GetColWidth( i
);
5936 if (rect
.GetRight() > client_right
)
5937 rect
.SetRight( client_right
- 1 );
5940 editor
->SetCellAttr( attr
);
5941 editor
->SetSize( rect
);
5943 editor
->GetControl()->Move(
5944 editor
->GetControl()->GetPosition().x
+ nXMove
,
5945 editor
->GetControl()->GetPosition().y
);
5946 editor
->Show( true, attr
);
5948 // recalc dimensions in case we need to
5949 // expand the scrolled window to account for editor
5952 editor
->BeginEdit(row
, col
, this);
5953 editor
->SetCellAttr(NULL
);
5961 void wxGrid::HideCellEditControl()
5963 if ( IsCellEditControlEnabled() )
5965 int row
= m_currentCellCoords
.GetRow();
5966 int col
= m_currentCellCoords
.GetCol();
5968 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5969 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
5970 const bool editorHadFocus
= editor
->GetControl()->HasFocus();
5971 editor
->Show( false );
5975 // return the focus to the grid itself if the editor had it
5977 // note that we must not do this unconditionally to avoid stealing
5978 // focus from the window which just received it if we are hiding the
5979 // editor precisely because we lost focus
5980 if ( editorHadFocus
)
5981 m_gridWin
->SetFocus();
5983 // refresh whole row to the right
5984 wxRect
rect( CellToRect(row
, col
) );
5985 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
5986 rect
.width
= m_gridWin
->GetClientSize().GetWidth() - rect
.x
;
5989 // ensure that the pixels under the focus ring get refreshed as well
5990 rect
.Inflate(10, 10);
5993 m_gridWin
->Refresh( false, &rect
);
5997 void wxGrid::SaveEditControlValue()
5999 if ( IsCellEditControlEnabled() )
6001 int row
= m_currentCellCoords
.GetRow();
6002 int col
= m_currentCellCoords
.GetCol();
6004 wxString oldval
= GetCellValue(row
, col
);
6006 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6007 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
6010 bool changed
= editor
->EndEdit(row
, col
, this, oldval
, &newval
);
6012 if ( changed
&& SendEvent(wxEVT_GRID_CELL_CHANGING
, newval
) != -1 )
6014 editor
->ApplyEdit(row
, col
, this);
6016 // for compatibility reasons dating back to wx 2.8 when this event
6017 // was called wxEVT_GRID_CELL_CHANGE and wxEVT_GRID_CELL_CHANGING
6018 // didn't exist we allow vetoing this one too
6019 if ( SendEvent(wxEVT_GRID_CELL_CHANGED
, oldval
) == -1 )
6021 // Event has been vetoed, set the data back.
6022 SetCellValue(row
, col
, oldval
);
6032 // ------ Grid location functions
6033 // Note that all of these functions work with the logical coordinates of
6034 // grid cells and labels so you will need to convert from device
6035 // coordinates for mouse events etc.
6038 wxGridCellCoords
wxGrid::XYToCell(int x
, int y
) const
6040 int row
= YToRow(y
);
6041 int col
= XToCol(x
);
6043 return row
== -1 || col
== -1 ? wxGridNoCellCoords
6044 : wxGridCellCoords(row
, col
);
6047 // compute row or column from some (unscrolled) coordinate value, using either
6048 // m_defaultRowHeight/m_defaultColWidth or binary search on array of
6049 // m_rowBottoms/m_colRights to do it quickly (linear search shouldn't be used
6051 int wxGrid::PosToLinePos(int coord
,
6053 const wxGridOperations
& oper
) const
6055 const int numLines
= oper
.GetNumberOfLines(this);
6058 return clipToMinMax
&& numLines
> 0 ? 0 : wxNOT_FOUND
;
6060 const int defaultLineSize
= oper
.GetDefaultLineSize(this);
6061 wxCHECK_MSG( defaultLineSize
, -1, "can't have 0 default line size" );
6063 int maxPos
= coord
/ defaultLineSize
,
6066 // check for the simplest case: if we have no explicit line sizes
6067 // configured, then we already know the line this position falls in
6068 const wxArrayInt
& lineEnds
= oper
.GetLineEnds(this);
6069 if ( lineEnds
.empty() )
6071 if ( maxPos
< numLines
)
6074 return clipToMinMax
? numLines
- 1 : -1;
6078 // adjust maxPos before starting the binary search
6079 if ( maxPos
>= numLines
)
6081 maxPos
= numLines
- 1;
6085 if ( coord
>= lineEnds
[oper
.GetLineAt(this, maxPos
)])
6088 const int minDist
= oper
.GetMinimalAcceptableLineSize(this);
6090 maxPos
= coord
/ minDist
;
6092 maxPos
= numLines
- 1;
6095 if ( maxPos
>= numLines
)
6096 maxPos
= numLines
- 1;
6099 // check if the position is beyond the last column
6100 const int lineAtMaxPos
= oper
.GetLineAt(this, maxPos
);
6101 if ( coord
>= lineEnds
[lineAtMaxPos
] )
6102 return clipToMinMax
? maxPos
: -1;
6104 // or before the first one
6105 const int lineAt0
= oper
.GetLineAt(this, 0);
6106 if ( coord
< lineEnds
[lineAt0
] )
6110 // finally do perform the binary search
6111 while ( minPos
< maxPos
)
6113 wxCHECK_MSG( lineEnds
[oper
.GetLineAt(this, minPos
)] <= coord
&&
6114 coord
< lineEnds
[oper
.GetLineAt(this, maxPos
)],
6116 "wxGrid: internal error in PosToLinePos()" );
6118 if ( coord
>= lineEnds
[oper
.GetLineAt(this, maxPos
- 1)] )
6123 const int median
= minPos
+ (maxPos
- minPos
+ 1) / 2;
6124 if ( coord
< lineEnds
[oper
.GetLineAt(this, median
)] )
6134 wxGrid::PosToLine(int coord
,
6136 const wxGridOperations
& oper
) const
6138 int pos
= PosToLinePos(coord
, clipToMinMax
, oper
);
6140 return pos
== wxNOT_FOUND
? wxNOT_FOUND
: oper
.GetLineAt(this, pos
);
6143 int wxGrid::YToRow(int y
, bool clipToMinMax
) const
6145 return PosToLine(y
, clipToMinMax
, wxGridRowOperations());
6148 int wxGrid::XToCol(int x
, bool clipToMinMax
) const
6150 return PosToLine(x
, clipToMinMax
, wxGridColumnOperations());
6153 int wxGrid::XToPos(int x
) const
6155 return PosToLinePos(x
, true /* clip */, wxGridColumnOperations());
6158 // return the row number such that the y coord is near the edge of, or -1 if
6159 // not near an edge.
6161 // notice that position can only possibly be near an edge if the row/column is
6162 // large enough to still allow for an "inner" area that is _not_ near the edge
6163 // (i.e., if the height/width is smaller than WXGRID_LABEL_EDGE_ZONE, pos will
6164 // _never_ be considered to be near the edge).
6165 int wxGrid::PosToEdgeOfLine(int pos
, const wxGridOperations
& oper
) const
6167 const int line
= oper
.PosToLine(this, pos
, true);
6169 if ( oper
.GetLineSize(this, line
) > WXGRID_LABEL_EDGE_ZONE
)
6171 // We know that we are in this line, test whether we are close enough
6172 // to start or end border, respectively.
6173 if ( abs(oper
.GetLineEndPos(this, line
) - pos
) < WXGRID_LABEL_EDGE_ZONE
)
6175 else if ( line
> 0 &&
6176 pos
- oper
.GetLineStartPos(this,
6177 line
) < WXGRID_LABEL_EDGE_ZONE
)
6184 int wxGrid::YToEdgeOfRow(int y
) const
6186 return PosToEdgeOfLine(y
, wxGridRowOperations());
6189 int wxGrid::XToEdgeOfCol(int x
) const
6191 return PosToEdgeOfLine(x
, wxGridColumnOperations());
6194 wxRect
wxGrid::CellToRect( int row
, int col
) const
6196 wxRect
rect( -1, -1, -1, -1 );
6198 if ( row
>= 0 && row
< m_numRows
&&
6199 col
>= 0 && col
< m_numCols
)
6201 int i
, cell_rows
, cell_cols
;
6202 rect
.width
= rect
.height
= 0;
6203 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
6204 // if negative then find multicell owner
6209 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
6211 rect
.x
= GetColLeft(col
);
6212 rect
.y
= GetRowTop(row
);
6213 for (i
=col
; i
< col
+ cell_cols
; i
++)
6214 rect
.width
+= GetColWidth(i
);
6215 for (i
=row
; i
< row
+ cell_rows
; i
++)
6216 rect
.height
+= GetRowHeight(i
);
6218 // if grid lines are enabled, then the area of the cell is a bit smaller
6219 if (m_gridLinesEnabled
)
6229 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
) const
6231 // get the cell rectangle in logical coords
6233 wxRect
r( CellToRect( row
, col
) );
6235 // convert to device coords
6237 int left
, top
, right
, bottom
;
6238 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
6239 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
6241 // check against the client area of the grid window
6243 m_gridWin
->GetClientSize( &cw
, &ch
);
6245 if ( wholeCellVisible
)
6247 // is the cell wholly visible ?
6248 return ( left
>= 0 && right
<= cw
&&
6249 top
>= 0 && bottom
<= ch
);
6253 // is the cell partly visible ?
6255 return ( ((left
>= 0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
6256 ((top
>= 0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
6260 // make the specified cell location visible by doing a minimal amount
6263 void wxGrid::MakeCellVisible( int row
, int col
)
6266 int xpos
= -1, ypos
= -1;
6268 if ( row
>= 0 && row
< m_numRows
&&
6269 col
>= 0 && col
< m_numCols
)
6271 // get the cell rectangle in logical coords
6272 wxRect
r( CellToRect( row
, col
) );
6274 // convert to device coords
6275 int left
, top
, right
, bottom
;
6276 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
6277 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
6280 m_gridWin
->GetClientSize( &cw
, &ch
);
6286 else if ( bottom
> ch
)
6288 int h
= r
.GetHeight();
6290 for ( i
= row
- 1; i
>= 0; i
-- )
6292 int rowHeight
= GetRowHeight(i
);
6293 if ( h
+ rowHeight
> ch
)
6300 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
6301 // have rounding errors (this is important, because if we do,
6302 // we might not scroll at all and some cells won't be redrawn)
6304 // Sometimes GRID_SCROLL_LINE / 2 is not enough,
6305 // so just add a full scroll unit...
6306 ypos
+= m_scrollLineY
;
6309 // special handling for wide cells - show always left part of the cell!
6310 // Otherwise, e.g. when stepping from row to row, it would jump between
6311 // left and right part of the cell on every step!
6313 if ( left
< 0 || (right
- left
) >= cw
)
6317 else if ( right
> cw
)
6319 // position the view so that the cell is on the right
6321 CalcUnscrolledPosition(0, 0, &x0
, &y0
);
6322 xpos
= x0
+ (right
- cw
);
6324 // see comment for ypos above
6325 xpos
+= m_scrollLineX
;
6328 if ( xpos
!= -1 || ypos
!= -1 )
6331 xpos
/= m_scrollLineX
;
6333 ypos
/= m_scrollLineY
;
6334 Scroll( xpos
, ypos
);
6341 // ------ Grid cursor movement functions
6345 wxGrid::DoMoveCursor(bool expandSelection
,
6346 const wxGridDirectionOperations
& diroper
)
6348 if ( m_currentCellCoords
== wxGridNoCellCoords
)
6351 if ( expandSelection
)
6353 wxGridCellCoords coords
= m_selectedBlockCorner
;
6354 if ( coords
== wxGridNoCellCoords
)
6355 coords
= m_currentCellCoords
;
6357 if ( diroper
.IsAtBoundary(coords
) )
6360 diroper
.Advance(coords
);
6362 UpdateBlockBeingSelected(m_currentCellCoords
, coords
);
6364 else // don't expand selection
6368 if ( diroper
.IsAtBoundary(m_currentCellCoords
) )
6371 wxGridCellCoords coords
= m_currentCellCoords
;
6372 diroper
.Advance(coords
);
6380 bool wxGrid::MoveCursorUp(bool expandSelection
)
6382 return DoMoveCursor(expandSelection
,
6383 wxGridBackwardOperations(this, wxGridRowOperations()));
6386 bool wxGrid::MoveCursorDown(bool expandSelection
)
6388 return DoMoveCursor(expandSelection
,
6389 wxGridForwardOperations(this, wxGridRowOperations()));
6392 bool wxGrid::MoveCursorLeft(bool expandSelection
)
6394 return DoMoveCursor(expandSelection
,
6395 wxGridBackwardOperations(this, wxGridColumnOperations()));
6398 bool wxGrid::MoveCursorRight(bool expandSelection
)
6400 return DoMoveCursor(expandSelection
,
6401 wxGridForwardOperations(this, wxGridColumnOperations()));
6404 bool wxGrid::DoMoveCursorByPage(const wxGridDirectionOperations
& diroper
)
6406 if ( m_currentCellCoords
== wxGridNoCellCoords
)
6409 if ( diroper
.IsAtBoundary(m_currentCellCoords
) )
6412 const int oldRow
= m_currentCellCoords
.GetRow();
6413 int newRow
= diroper
.MoveByPixelDistance(oldRow
, m_gridWin
->GetClientSize().y
);
6414 if ( newRow
== oldRow
)
6416 wxGridCellCoords
coords(m_currentCellCoords
);
6417 diroper
.Advance(coords
);
6418 newRow
= coords
.GetRow();
6421 GoToCell(newRow
, m_currentCellCoords
.GetCol());
6426 bool wxGrid::MovePageUp()
6428 return DoMoveCursorByPage(
6429 wxGridBackwardOperations(this, wxGridRowOperations()));
6432 bool wxGrid::MovePageDown()
6434 return DoMoveCursorByPage(
6435 wxGridForwardOperations(this, wxGridRowOperations()));
6438 // helper of DoMoveCursorByBlock(): advance the cell coordinates using diroper
6439 // until we find a non-empty cell or reach the grid end
6441 wxGrid::AdvanceToNextNonEmpty(wxGridCellCoords
& coords
,
6442 const wxGridDirectionOperations
& diroper
)
6444 while ( !diroper
.IsAtBoundary(coords
) )
6446 diroper
.Advance(coords
);
6447 if ( !m_table
->IsEmpty(coords
) )
6453 wxGrid::DoMoveCursorByBlock(bool expandSelection
,
6454 const wxGridDirectionOperations
& diroper
)
6456 if ( !m_table
|| m_currentCellCoords
== wxGridNoCellCoords
)
6459 if ( diroper
.IsAtBoundary(m_currentCellCoords
) )
6462 wxGridCellCoords
coords(m_currentCellCoords
);
6463 if ( m_table
->IsEmpty(coords
) )
6465 // we are in an empty cell: find the next block of non-empty cells
6466 AdvanceToNextNonEmpty(coords
, diroper
);
6468 else // current cell is not empty
6470 diroper
.Advance(coords
);
6471 if ( m_table
->IsEmpty(coords
) )
6473 // we started at the end of a block, find the next one
6474 AdvanceToNextNonEmpty(coords
, diroper
);
6476 else // we're in a middle of a block
6478 // go to the end of it, i.e. find the last cell before the next
6480 while ( !diroper
.IsAtBoundary(coords
) )
6482 wxGridCellCoords
coordsNext(coords
);
6483 diroper
.Advance(coordsNext
);
6484 if ( m_table
->IsEmpty(coordsNext
) )
6487 coords
= coordsNext
;
6492 if ( expandSelection
)
6494 UpdateBlockBeingSelected(m_currentCellCoords
, coords
);
6505 bool wxGrid::MoveCursorUpBlock(bool expandSelection
)
6507 return DoMoveCursorByBlock(
6509 wxGridBackwardOperations(this, wxGridRowOperations())
6513 bool wxGrid::MoveCursorDownBlock( bool expandSelection
)
6515 return DoMoveCursorByBlock(
6517 wxGridForwardOperations(this, wxGridRowOperations())
6521 bool wxGrid::MoveCursorLeftBlock( bool expandSelection
)
6523 return DoMoveCursorByBlock(
6525 wxGridBackwardOperations(this, wxGridColumnOperations())
6529 bool wxGrid::MoveCursorRightBlock( bool expandSelection
)
6531 return DoMoveCursorByBlock(
6533 wxGridForwardOperations(this, wxGridColumnOperations())
6538 // ------ Label values and formatting
6541 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
) const
6544 *horiz
= m_rowLabelHorizAlign
;
6546 *vert
= m_rowLabelVertAlign
;
6549 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
) const
6552 *horiz
= m_colLabelHorizAlign
;
6554 *vert
= m_colLabelVertAlign
;
6557 int wxGrid::GetColLabelTextOrientation() const
6559 return m_colLabelTextOrientation
;
6562 wxString
wxGrid::GetRowLabelValue( int row
) const
6566 return m_table
->GetRowLabelValue( row
);
6576 wxString
wxGrid::GetColLabelValue( int col
) const
6580 return m_table
->GetColLabelValue( col
);
6590 void wxGrid::SetRowLabelSize( int width
)
6592 wxASSERT( width
>= 0 || width
== wxGRID_AUTOSIZE
);
6594 if ( width
== wxGRID_AUTOSIZE
)
6596 width
= CalcColOrRowLabelAreaMinSize(wxGRID_ROW
);
6599 if ( width
!= m_rowLabelWidth
)
6603 m_rowLabelWin
->Show( false );
6604 m_cornerLabelWin
->Show( false );
6606 else if ( m_rowLabelWidth
== 0 )
6608 m_rowLabelWin
->Show( true );
6609 if ( m_colLabelHeight
> 0 )
6610 m_cornerLabelWin
->Show( true );
6613 m_rowLabelWidth
= width
;
6615 wxScrolledWindow::Refresh( true );
6619 void wxGrid::SetColLabelSize( int height
)
6621 wxASSERT( height
>=0 || height
== wxGRID_AUTOSIZE
);
6623 if ( height
== wxGRID_AUTOSIZE
)
6625 height
= CalcColOrRowLabelAreaMinSize(wxGRID_COLUMN
);
6628 if ( height
!= m_colLabelHeight
)
6632 m_colWindow
->Show( false );
6633 m_cornerLabelWin
->Show( false );
6635 else if ( m_colLabelHeight
== 0 )
6637 m_colWindow
->Show( true );
6638 if ( m_rowLabelWidth
> 0 )
6639 m_cornerLabelWin
->Show( true );
6642 m_colLabelHeight
= height
;
6644 wxScrolledWindow::Refresh( true );
6648 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
6650 if ( m_labelBackgroundColour
!= colour
)
6652 m_labelBackgroundColour
= colour
;
6653 m_rowLabelWin
->SetBackgroundColour( colour
);
6654 m_colWindow
->SetBackgroundColour( colour
);
6655 m_cornerLabelWin
->SetBackgroundColour( colour
);
6657 if ( !GetBatchCount() )
6659 m_rowLabelWin
->Refresh();
6660 m_colWindow
->Refresh();
6661 m_cornerLabelWin
->Refresh();
6666 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
6668 if ( m_labelTextColour
!= colour
)
6670 m_labelTextColour
= colour
;
6671 if ( !GetBatchCount() )
6673 m_rowLabelWin
->Refresh();
6674 m_colWindow
->Refresh();
6679 void wxGrid::SetLabelFont( const wxFont
& font
)
6682 if ( !GetBatchCount() )
6684 m_rowLabelWin
->Refresh();
6685 m_colWindow
->Refresh();
6689 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
6691 // allow old (incorrect) defs to be used
6694 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
6695 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
6696 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
6701 case wxTOP
: vert
= wxALIGN_TOP
; break;
6702 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
6703 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
6706 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
6708 m_rowLabelHorizAlign
= horiz
;
6711 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
6713 m_rowLabelVertAlign
= vert
;
6716 if ( !GetBatchCount() )
6718 m_rowLabelWin
->Refresh();
6722 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
6724 // allow old (incorrect) defs to be used
6727 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
6728 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
6729 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
6734 case wxTOP
: vert
= wxALIGN_TOP
; break;
6735 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
6736 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
6739 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
6741 m_colLabelHorizAlign
= horiz
;
6744 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
6746 m_colLabelVertAlign
= vert
;
6749 if ( !GetBatchCount() )
6751 m_colWindow
->Refresh();
6755 // Note: under MSW, the default column label font must be changed because it
6756 // does not support vertical printing
6758 // Example: wxFont font(9, wxSWISS, wxNORMAL, wxBOLD);
6759 // pGrid->SetLabelFont(font);
6760 // pGrid->SetColLabelTextOrientation(wxVERTICAL);
6762 void wxGrid::SetColLabelTextOrientation( int textOrientation
)
6764 if ( textOrientation
== wxHORIZONTAL
|| textOrientation
== wxVERTICAL
)
6765 m_colLabelTextOrientation
= textOrientation
;
6767 if ( !GetBatchCount() )
6768 m_colWindow
->Refresh();
6771 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
6775 m_table
->SetRowLabelValue( row
, s
);
6776 if ( !GetBatchCount() )
6778 wxRect rect
= CellToRect( row
, 0 );
6779 if ( rect
.height
> 0 )
6781 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
6783 rect
.width
= m_rowLabelWidth
;
6784 m_rowLabelWin
->Refresh( true, &rect
);
6790 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
6794 m_table
->SetColLabelValue( col
, s
);
6795 if ( !GetBatchCount() )
6797 if ( m_useNativeHeader
)
6799 GetGridColHeader()->UpdateColumn(col
);
6803 wxRect rect
= CellToRect( 0, col
);
6804 if ( rect
.width
> 0 )
6806 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
6808 rect
.height
= m_colLabelHeight
;
6809 GetColLabelWindow()->Refresh( true, &rect
);
6816 void wxGrid::SetGridLineColour( const wxColour
& colour
)
6818 if ( m_gridLineColour
!= colour
)
6820 m_gridLineColour
= colour
;
6822 if ( GridLinesEnabled() )
6827 void wxGrid::SetCellHighlightColour( const wxColour
& colour
)
6829 if ( m_cellHighlightColour
!= colour
)
6831 m_cellHighlightColour
= colour
;
6833 wxClientDC
dc( m_gridWin
);
6835 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
6836 DrawCellHighlight(dc
, attr
);
6841 void wxGrid::SetCellHighlightPenWidth(int width
)
6843 if (m_cellHighlightPenWidth
!= width
)
6845 m_cellHighlightPenWidth
= width
;
6847 // Just redrawing the cell highlight is not enough since that won't
6848 // make any visible change if the the thickness is getting smaller.
6849 int row
= m_currentCellCoords
.GetRow();
6850 int col
= m_currentCellCoords
.GetCol();
6851 if ( row
== -1 || col
== -1 || GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6854 wxRect rect
= CellToRect(row
, col
);
6855 m_gridWin
->Refresh(true, &rect
);
6859 void wxGrid::SetCellHighlightROPenWidth(int width
)
6861 if (m_cellHighlightROPenWidth
!= width
)
6863 m_cellHighlightROPenWidth
= width
;
6865 // Just redrawing the cell highlight is not enough since that won't
6866 // make any visible change if the the thickness is getting smaller.
6867 int row
= m_currentCellCoords
.GetRow();
6868 int col
= m_currentCellCoords
.GetCol();
6869 if ( row
== -1 || col
== -1 ||
6870 GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6873 wxRect rect
= CellToRect(row
, col
);
6874 m_gridWin
->Refresh(true, &rect
);
6878 void wxGrid::RedrawGridLines()
6880 // the lines will be redrawn when the window is thawn
6881 if ( GetBatchCount() )
6884 if ( GridLinesEnabled() )
6886 wxClientDC
dc( m_gridWin
);
6888 DrawAllGridLines( dc
, wxRegion() );
6890 else // remove the grid lines
6892 m_gridWin
->Refresh();
6896 void wxGrid::EnableGridLines( bool enable
)
6898 if ( enable
!= m_gridLinesEnabled
)
6900 m_gridLinesEnabled
= enable
;
6906 void wxGrid::DoClipGridLines(bool& var
, bool clip
)
6912 if ( GridLinesEnabled() )
6917 int wxGrid::GetDefaultRowSize() const
6919 return m_defaultRowHeight
;
6922 int wxGrid::GetRowSize( int row
) const
6924 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, wxT("invalid row index") );
6926 return GetRowHeight(row
);
6929 int wxGrid::GetDefaultColSize() const
6931 return m_defaultColWidth
;
6934 int wxGrid::GetColSize( int col
) const
6936 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, wxT("invalid column index") );
6938 return GetColWidth(col
);
6941 // ============================================================================
6942 // access to the grid attributes: each of them has a default value in the grid
6943 // itself and may be overidden on a per-cell basis
6944 // ============================================================================
6946 // ----------------------------------------------------------------------------
6947 // setting default attributes
6948 // ----------------------------------------------------------------------------
6950 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
6952 m_defaultCellAttr
->SetBackgroundColour(col
);
6954 m_gridWin
->SetBackgroundColour(col
);
6958 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
6960 m_defaultCellAttr
->SetTextColour(col
);
6963 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
6965 m_defaultCellAttr
->SetAlignment(horiz
, vert
);
6968 void wxGrid::SetDefaultCellOverflow( bool allow
)
6970 m_defaultCellAttr
->SetOverflow(allow
);
6973 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
6975 m_defaultCellAttr
->SetFont(font
);
6978 // For editors and renderers the type registry takes precedence over the
6979 // default attr, so we need to register the new editor/renderer for the string
6980 // data type in order to make setting a default editor/renderer appear to
6983 void wxGrid::SetDefaultRenderer(wxGridCellRenderer
*renderer
)
6985 RegisterDataType(wxGRID_VALUE_STRING
,
6987 GetDefaultEditorForType(wxGRID_VALUE_STRING
));
6990 void wxGrid::SetDefaultEditor(wxGridCellEditor
*editor
)
6992 RegisterDataType(wxGRID_VALUE_STRING
,
6993 GetDefaultRendererForType(wxGRID_VALUE_STRING
),
6997 // ----------------------------------------------------------------------------
6998 // access to the default attributes
6999 // ----------------------------------------------------------------------------
7001 wxColour
wxGrid::GetDefaultCellBackgroundColour() const
7003 return m_defaultCellAttr
->GetBackgroundColour();
7006 wxColour
wxGrid::GetDefaultCellTextColour() const
7008 return m_defaultCellAttr
->GetTextColour();
7011 wxFont
wxGrid::GetDefaultCellFont() const
7013 return m_defaultCellAttr
->GetFont();
7016 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
) const
7018 m_defaultCellAttr
->GetAlignment(horiz
, vert
);
7021 bool wxGrid::GetDefaultCellOverflow() const
7023 return m_defaultCellAttr
->GetOverflow();
7026 wxGridCellRenderer
*wxGrid::GetDefaultRenderer() const
7028 return m_defaultCellAttr
->GetRenderer(NULL
, 0, 0);
7031 wxGridCellEditor
*wxGrid::GetDefaultEditor() const
7033 return m_defaultCellAttr
->GetEditor(NULL
, 0, 0);
7036 // ----------------------------------------------------------------------------
7037 // access to cell attributes
7038 // ----------------------------------------------------------------------------
7040 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
) const
7042 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
7043 wxColour colour
= attr
->GetBackgroundColour();
7049 wxColour
wxGrid::GetCellTextColour( int row
, int col
) const
7051 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
7052 wxColour colour
= attr
->GetTextColour();
7058 wxFont
wxGrid::GetCellFont( int row
, int col
) const
7060 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
7061 wxFont font
= attr
->GetFont();
7067 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
) const
7069 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
7070 attr
->GetAlignment(horiz
, vert
);
7074 bool wxGrid::GetCellOverflow( int row
, int col
) const
7076 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
7077 bool allow
= attr
->GetOverflow();
7083 void wxGrid::GetCellSize( int row
, int col
, int *num_rows
, int *num_cols
) const
7085 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
7086 attr
->GetSize( num_rows
, num_cols
);
7090 wxGridCellRenderer
* wxGrid::GetCellRenderer(int row
, int col
) const
7092 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7093 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
7099 wxGridCellEditor
* wxGrid::GetCellEditor(int row
, int col
) const
7101 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7102 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
7108 bool wxGrid::IsReadOnly(int row
, int col
) const
7110 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7111 bool isReadOnly
= attr
->IsReadOnly();
7117 // ----------------------------------------------------------------------------
7118 // attribute support: cache, automatic provider creation, ...
7119 // ----------------------------------------------------------------------------
7121 bool wxGrid::CanHaveAttributes() const
7128 return m_table
->CanHaveAttributes();
7131 void wxGrid::ClearAttrCache()
7133 if ( m_attrCache
.row
!= -1 )
7135 wxGridCellAttr
*oldAttr
= m_attrCache
.attr
;
7136 m_attrCache
.attr
= NULL
;
7137 m_attrCache
.row
= -1;
7138 // wxSafeDecRec(...) might cause event processing that accesses
7139 // the cached attribute, if one exists (e.g. by deleting the
7140 // editor stored within the attribute). Therefore it is important
7141 // to invalidate the cache before calling wxSafeDecRef!
7142 wxSafeDecRef(oldAttr
);
7146 void wxGrid::CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const
7150 wxGrid
*self
= (wxGrid
*)this; // const_cast
7152 self
->ClearAttrCache();
7153 self
->m_attrCache
.row
= row
;
7154 self
->m_attrCache
.col
= col
;
7155 self
->m_attrCache
.attr
= attr
;
7160 bool wxGrid::LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const
7162 if ( row
== m_attrCache
.row
&& col
== m_attrCache
.col
)
7164 *attr
= m_attrCache
.attr
;
7165 wxSafeIncRef(m_attrCache
.attr
);
7167 #ifdef DEBUG_ATTR_CACHE
7168 gs_nAttrCacheHits
++;
7175 #ifdef DEBUG_ATTR_CACHE
7176 gs_nAttrCacheMisses
++;
7183 wxGridCellAttr
*wxGrid::GetCellAttr(int row
, int col
) const
7185 wxGridCellAttr
*attr
= NULL
;
7186 // Additional test to avoid looking at the cache e.g. for
7187 // wxNoCellCoords, as this will confuse memory management.
7190 if ( !LookupAttr(row
, col
, &attr
) )
7192 attr
= m_table
? m_table
->GetAttr(row
, col
, wxGridCellAttr::Any
)
7194 CacheAttr(row
, col
, attr
);
7200 attr
->SetDefAttr(m_defaultCellAttr
);
7204 attr
= m_defaultCellAttr
;
7211 wxGridCellAttr
*wxGrid::GetOrCreateCellAttr(int row
, int col
) const
7213 wxGridCellAttr
*attr
= NULL
;
7214 bool canHave
= ((wxGrid
*)this)->CanHaveAttributes();
7216 wxCHECK_MSG( canHave
, attr
, wxT("Cell attributes not allowed"));
7217 wxCHECK_MSG( m_table
, attr
, wxT("must have a table") );
7219 attr
= m_table
->GetAttr(row
, col
, wxGridCellAttr::Cell
);
7222 attr
= new wxGridCellAttr(m_defaultCellAttr
);
7224 // artificially inc the ref count to match DecRef() in caller
7226 m_table
->SetAttr(attr
, row
, col
);
7232 // ----------------------------------------------------------------------------
7233 // setting column attributes (wrappers around SetColAttr)
7234 // ----------------------------------------------------------------------------
7236 void wxGrid::SetColFormatBool(int col
)
7238 SetColFormatCustom(col
, wxGRID_VALUE_BOOL
);
7241 void wxGrid::SetColFormatNumber(int col
)
7243 SetColFormatCustom(col
, wxGRID_VALUE_NUMBER
);
7246 void wxGrid::SetColFormatFloat(int col
, int width
, int precision
)
7248 wxString typeName
= wxGRID_VALUE_FLOAT
;
7249 if ( (width
!= -1) || (precision
!= -1) )
7251 typeName
<< wxT(':') << width
<< wxT(',') << precision
;
7254 SetColFormatCustom(col
, typeName
);
7257 void wxGrid::SetColFormatCustom(int col
, const wxString
& typeName
)
7259 wxGridCellAttr
*attr
= m_table
->GetAttr(-1, col
, wxGridCellAttr::Col
);
7261 attr
= new wxGridCellAttr
;
7262 wxGridCellRenderer
*renderer
= GetDefaultRendererForType(typeName
);
7263 attr
->SetRenderer(renderer
);
7264 wxGridCellEditor
*editor
= GetDefaultEditorForType(typeName
);
7265 attr
->SetEditor(editor
);
7267 SetColAttr(col
, attr
);
7271 // ----------------------------------------------------------------------------
7272 // setting cell attributes: this is forwarded to the table
7273 // ----------------------------------------------------------------------------
7275 void wxGrid::SetAttr(int row
, int col
, wxGridCellAttr
*attr
)
7277 if ( CanHaveAttributes() )
7279 m_table
->SetAttr(attr
, row
, col
);
7288 void wxGrid::SetRowAttr(int row
, wxGridCellAttr
*attr
)
7290 if ( CanHaveAttributes() )
7292 m_table
->SetRowAttr(attr
, row
);
7301 void wxGrid::SetColAttr(int col
, wxGridCellAttr
*attr
)
7303 if ( CanHaveAttributes() )
7305 m_table
->SetColAttr(attr
, col
);
7314 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
7316 if ( CanHaveAttributes() )
7318 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7319 attr
->SetBackgroundColour(colour
);
7324 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
7326 if ( CanHaveAttributes() )
7328 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7329 attr
->SetTextColour(colour
);
7334 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
7336 if ( CanHaveAttributes() )
7338 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7339 attr
->SetFont(font
);
7344 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
7346 if ( CanHaveAttributes() )
7348 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7349 attr
->SetAlignment(horiz
, vert
);
7354 void wxGrid::SetCellOverflow( int row
, int col
, bool allow
)
7356 if ( CanHaveAttributes() )
7358 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7359 attr
->SetOverflow(allow
);
7364 void wxGrid::SetCellSize( int row
, int col
, int num_rows
, int num_cols
)
7366 if ( CanHaveAttributes() )
7368 int cell_rows
, cell_cols
;
7370 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7371 attr
->GetSize(&cell_rows
, &cell_cols
);
7372 attr
->SetSize(num_rows
, num_cols
);
7375 // Cannot set the size of a cell to 0 or negative values
7376 // While it is perfectly legal to do that, this function cannot
7377 // handle all the possibilies, do it by hand by getting the CellAttr.
7378 // You can only set the size of a cell to 1,1 or greater with this fn
7379 wxASSERT_MSG( !((cell_rows
< 1) || (cell_cols
< 1)),
7380 wxT("wxGrid::SetCellSize setting cell size that is already part of another cell"));
7381 wxASSERT_MSG( !((num_rows
< 1) || (num_cols
< 1)),
7382 wxT("wxGrid::SetCellSize setting cell size to < 1"));
7384 // if this was already a multicell then "turn off" the other cells first
7385 if ((cell_rows
> 1) || (cell_cols
> 1))
7388 for (j
=row
; j
< row
+ cell_rows
; j
++)
7390 for (i
=col
; i
< col
+ cell_cols
; i
++)
7392 if ((i
!= col
) || (j
!= row
))
7394 wxGridCellAttr
*attr_stub
= GetOrCreateCellAttr(j
, i
);
7395 attr_stub
->SetSize( 1, 1 );
7396 attr_stub
->DecRef();
7402 // mark the cells that will be covered by this cell to
7403 // negative or zero values to point back at this cell
7404 if (((num_rows
> 1) || (num_cols
> 1)) && (num_rows
>= 1) && (num_cols
>= 1))
7407 for (j
=row
; j
< row
+ num_rows
; j
++)
7409 for (i
=col
; i
< col
+ num_cols
; i
++)
7411 if ((i
!= col
) || (j
!= row
))
7413 wxGridCellAttr
*attr_stub
= GetOrCreateCellAttr(j
, i
);
7414 attr_stub
->SetSize( row
- j
, col
- i
);
7415 attr_stub
->DecRef();
7423 void wxGrid::SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
)
7425 if ( CanHaveAttributes() )
7427 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7428 attr
->SetRenderer(renderer
);
7433 void wxGrid::SetCellEditor(int row
, int col
, wxGridCellEditor
* editor
)
7435 if ( CanHaveAttributes() )
7437 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7438 attr
->SetEditor(editor
);
7443 void wxGrid::SetReadOnly(int row
, int col
, bool isReadOnly
)
7445 if ( CanHaveAttributes() )
7447 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7448 attr
->SetReadOnly(isReadOnly
);
7453 // ----------------------------------------------------------------------------
7454 // Data type registration
7455 // ----------------------------------------------------------------------------
7457 void wxGrid::RegisterDataType(const wxString
& typeName
,
7458 wxGridCellRenderer
* renderer
,
7459 wxGridCellEditor
* editor
)
7461 m_typeRegistry
->RegisterDataType(typeName
, renderer
, editor
);
7465 wxGridCellEditor
* wxGrid::GetDefaultEditorForCell(int row
, int col
) const
7467 wxString typeName
= m_table
->GetTypeName(row
, col
);
7468 return GetDefaultEditorForType(typeName
);
7471 wxGridCellRenderer
* wxGrid::GetDefaultRendererForCell(int row
, int col
) const
7473 wxString typeName
= m_table
->GetTypeName(row
, col
);
7474 return GetDefaultRendererForType(typeName
);
7477 wxGridCellEditor
* wxGrid::GetDefaultEditorForType(const wxString
& typeName
) const
7479 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
7480 if ( index
== wxNOT_FOUND
)
7482 wxFAIL_MSG(wxString::Format(wxT("Unknown data type name [%s]"), typeName
.c_str()));
7487 return m_typeRegistry
->GetEditor(index
);
7490 wxGridCellRenderer
* wxGrid::GetDefaultRendererForType(const wxString
& typeName
) const
7492 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
7493 if ( index
== wxNOT_FOUND
)
7495 wxFAIL_MSG(wxString::Format(wxT("Unknown data type name [%s]"), typeName
.c_str()));
7500 return m_typeRegistry
->GetRenderer(index
);
7503 // ----------------------------------------------------------------------------
7505 // ----------------------------------------------------------------------------
7507 void wxGrid::DoDisableLineResize(int line
, wxGridFixedIndicesSet
*& setFixed
)
7511 setFixed
= new wxGridFixedIndicesSet
;
7514 setFixed
->insert(line
);
7518 wxGrid::DoCanResizeLine(int line
, const wxGridFixedIndicesSet
*setFixed
) const
7520 return !setFixed
|| !setFixed
->count(line
);
7523 void wxGrid::EnableDragRowSize( bool enable
)
7525 m_canDragRowSize
= enable
;
7528 void wxGrid::EnableDragColSize( bool enable
)
7530 m_canDragColSize
= enable
;
7533 void wxGrid::EnableDragGridSize( bool enable
)
7535 m_canDragGridSize
= enable
;
7538 void wxGrid::EnableDragCell( bool enable
)
7540 m_canDragCell
= enable
;
7543 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
7545 m_defaultRowHeight
= wxMax( height
, m_minAcceptableRowHeight
);
7547 if ( resizeExistingRows
)
7549 // since we are resizing all rows to the default row size,
7550 // we can simply clear the row heights and row bottoms
7551 // arrays (which also allows us to take advantage of
7552 // some speed optimisations)
7553 m_rowHeights
.Empty();
7554 m_rowBottoms
.Empty();
7555 if ( !GetBatchCount() )
7560 void wxGrid::SetRowSize( int row
, int height
)
7562 wxCHECK_RET( row
>= 0 && row
< m_numRows
, wxT("invalid row index") );
7564 // if < 0 then calculate new height from label
7568 wxArrayString lines
;
7569 wxClientDC
dc(m_rowLabelWin
);
7570 dc
.SetFont(GetLabelFont());
7571 StringToLines(GetRowLabelValue( row
), lines
);
7572 GetTextBoxSize( dc
, lines
, &w
, &h
);
7573 //check that it is not less than the minimal height
7574 height
= wxMax(h
, GetRowMinimalAcceptableHeight());
7577 // See comment in SetColSize
7578 if ( height
< GetRowMinimalAcceptableHeight())
7581 if ( m_rowHeights
.IsEmpty() )
7583 // need to really create the array
7587 int h
= wxMax( 0, height
);
7588 int diff
= h
- m_rowHeights
[row
];
7590 m_rowHeights
[row
] = h
;
7591 for ( int i
= row
; i
< m_numRows
; i
++ )
7593 m_rowBottoms
[i
] += diff
;
7596 if ( !GetBatchCount() )
7600 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
7602 // we dont allow zero default column width
7603 m_defaultColWidth
= wxMax( wxMax( width
, m_minAcceptableColWidth
), 1 );
7605 if ( resizeExistingCols
)
7607 // since we are resizing all columns to the default column size,
7608 // we can simply clear the col widths and col rights
7609 // arrays (which also allows us to take advantage of
7610 // some speed optimisations)
7611 m_colWidths
.Empty();
7612 m_colRights
.Empty();
7613 if ( !GetBatchCount() )
7618 void wxGrid::SetColSize( int col
, int width
)
7620 wxCHECK_RET( col
>= 0 && col
< m_numCols
, wxT("invalid column index") );
7622 // if < 0 then calculate new width from label
7626 wxArrayString lines
;
7627 wxClientDC
dc(m_colWindow
);
7628 dc
.SetFont(GetLabelFont());
7629 StringToLines(GetColLabelValue(col
), lines
);
7630 if ( GetColLabelTextOrientation() == wxHORIZONTAL
)
7631 GetTextBoxSize( dc
, lines
, &w
, &h
);
7633 GetTextBoxSize( dc
, lines
, &h
, &w
);
7635 //check that it is not less than the minimal width
7636 width
= wxMax(width
, GetColMinimalAcceptableWidth());
7639 // we intentionally don't test whether the width is less than
7640 // GetColMinimalWidth() here but we do compare it with
7641 // GetColMinimalAcceptableWidth() as otherwise things currently break (see
7642 // #651) -- and we also always allow the width of 0 as it has the special
7643 // sense of hiding the column
7644 if ( width
> 0 && width
< GetColMinimalAcceptableWidth() )
7647 if ( m_colWidths
.IsEmpty() )
7649 // need to really create the array
7653 const int diff
= width
- m_colWidths
[col
];
7654 m_colWidths
[col
] = width
;
7655 if ( m_useNativeHeader
)
7656 GetGridColHeader()->UpdateColumn(col
);
7657 //else: will be refreshed when the header is redrawn
7659 for ( int colPos
= GetColPos(col
); colPos
< m_numCols
; colPos
++ )
7661 m_colRights
[GetColAt(colPos
)] += diff
;
7664 if ( !GetBatchCount() )
7671 void wxGrid::SetColMinimalWidth( int col
, int width
)
7673 if (width
> GetColMinimalAcceptableWidth())
7675 wxLongToLongHashMap::key_type key
= (wxLongToLongHashMap::key_type
)col
;
7676 m_colMinWidths
[key
] = width
;
7680 void wxGrid::SetRowMinimalHeight( int row
, int width
)
7682 if (width
> GetRowMinimalAcceptableHeight())
7684 wxLongToLongHashMap::key_type key
= (wxLongToLongHashMap::key_type
)row
;
7685 m_rowMinHeights
[key
] = width
;
7689 int wxGrid::GetColMinimalWidth(int col
) const
7691 wxLongToLongHashMap::key_type key
= (wxLongToLongHashMap::key_type
)col
;
7692 wxLongToLongHashMap::const_iterator it
= m_colMinWidths
.find(key
);
7694 return it
!= m_colMinWidths
.end() ? (int)it
->second
: m_minAcceptableColWidth
;
7697 int wxGrid::GetRowMinimalHeight(int row
) const
7699 wxLongToLongHashMap::key_type key
= (wxLongToLongHashMap::key_type
)row
;
7700 wxLongToLongHashMap::const_iterator it
= m_rowMinHeights
.find(key
);
7702 return it
!= m_rowMinHeights
.end() ? (int)it
->second
: m_minAcceptableRowHeight
;
7705 void wxGrid::SetColMinimalAcceptableWidth( int width
)
7707 // We do allow a width of 0 since this gives us
7708 // an easy way to temporarily hiding columns.
7710 m_minAcceptableColWidth
= width
;
7713 void wxGrid::SetRowMinimalAcceptableHeight( int height
)
7715 // We do allow a height of 0 since this gives us
7716 // an easy way to temporarily hiding rows.
7718 m_minAcceptableRowHeight
= height
;
7721 int wxGrid::GetColMinimalAcceptableWidth() const
7723 return m_minAcceptableColWidth
;
7726 int wxGrid::GetRowMinimalAcceptableHeight() const
7728 return m_minAcceptableRowHeight
;
7731 // ----------------------------------------------------------------------------
7733 // ----------------------------------------------------------------------------
7736 wxGrid::AutoSizeColOrRow(int colOrRow
, bool setAsMin
, wxGridDirection direction
)
7738 const bool column
= direction
== wxGRID_COLUMN
;
7740 wxClientDC
dc(m_gridWin
);
7742 // cancel editing of cell
7743 HideCellEditControl();
7744 SaveEditControlValue();
7746 // init both of them to avoid compiler warnings, even if we only need one
7754 wxCoord extent
, extentMax
= 0;
7755 int max
= column
? m_numRows
: m_numCols
;
7756 for ( int rowOrCol
= 0; rowOrCol
< max
; rowOrCol
++ )
7763 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
7764 wxGridCellRenderer
*renderer
= attr
->GetRenderer(this, row
, col
);
7767 wxSize size
= renderer
->GetBestSize(*this, *attr
, dc
, row
, col
);
7768 extent
= column
? size
.x
: size
.y
;
7769 if ( extent
> extentMax
)
7778 // now also compare with the column label extent
7780 dc
.SetFont( GetLabelFont() );
7784 dc
.GetMultiLineTextExtent( GetColLabelValue(col
), &w
, &h
);
7785 if ( GetColLabelTextOrientation() == wxVERTICAL
)
7789 dc
.GetMultiLineTextExtent( GetRowLabelValue(row
), &w
, &h
);
7791 extent
= column
? w
: h
;
7792 if ( extent
> extentMax
)
7797 // empty column - give default extent (notice that if extentMax is less
7798 // than default extent but != 0, it's OK)
7799 extentMax
= column
? m_defaultColWidth
: m_defaultRowHeight
;
7804 // leave some space around text
7812 // Ensure automatic width is not less than minimal width. See the
7813 // comment in SetColSize() for explanation of why this isn't done
7816 extentMax
= wxMax(extentMax
, GetColMinimalWidth(col
));
7818 SetColSize( col
, extentMax
);
7819 if ( !GetBatchCount() )
7821 if ( m_useNativeHeader
)
7823 GetGridColHeader()->UpdateColumn(col
);
7828 m_gridWin
->GetClientSize( &cw
, &ch
);
7829 wxRect
rect ( CellToRect( 0, col
) );
7831 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
7832 rect
.width
= cw
- rect
.x
;
7833 rect
.height
= m_colLabelHeight
;
7834 GetColLabelWindow()->Refresh( true, &rect
);
7840 // Ensure automatic width is not less than minimal height. See the
7841 // comment in SetColSize() for explanation of why this isn't done
7844 extentMax
= wxMax(extentMax
, GetRowMinimalHeight(row
));
7846 SetRowSize(row
, extentMax
);
7847 if ( !GetBatchCount() )
7850 m_gridWin
->GetClientSize( &cw
, &ch
);
7851 wxRect
rect( CellToRect( row
, 0 ) );
7853 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
7854 rect
.width
= m_rowLabelWidth
;
7855 rect
.height
= ch
- rect
.y
;
7856 m_rowLabelWin
->Refresh( true, &rect
);
7863 SetColMinimalWidth(col
, extentMax
);
7865 SetRowMinimalHeight(row
, extentMax
);
7869 wxCoord
wxGrid::CalcColOrRowLabelAreaMinSize(wxGridDirection direction
)
7871 // calculate size for the rows or columns?
7872 const bool calcRows
= direction
== wxGRID_ROW
;
7874 wxClientDC
dc(calcRows
? GetGridRowLabelWindow()
7875 : GetGridColLabelWindow());
7876 dc
.SetFont(GetLabelFont());
7878 // which dimension should we take into account for calculations?
7880 // for columns, the text can be only horizontal so it's easy but for rows
7881 // we also have to take into account the text orientation
7883 useWidth
= calcRows
|| (GetColLabelTextOrientation() == wxVERTICAL
);
7885 wxArrayString lines
;
7886 wxCoord extentMax
= 0;
7888 const int numRowsOrCols
= calcRows
? m_numRows
: m_numCols
;
7889 for ( int rowOrCol
= 0; rowOrCol
< numRowsOrCols
; rowOrCol
++ )
7893 wxString label
= calcRows
? GetRowLabelValue(rowOrCol
)
7894 : GetColLabelValue(rowOrCol
);
7895 StringToLines(label
, lines
);
7898 GetTextBoxSize(dc
, lines
, &w
, &h
);
7900 const wxCoord extent
= useWidth
? w
: h
;
7901 if ( extent
> extentMax
)
7907 // empty column - give default extent (notice that if extentMax is less
7908 // than default extent but != 0, it's OK)
7909 extentMax
= calcRows
? GetDefaultRowLabelSize()
7910 : GetDefaultColLabelSize();
7913 // leave some space around text (taken from AutoSizeColOrRow)
7922 int wxGrid::SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
)
7924 int width
= m_rowLabelWidth
;
7926 wxGridUpdateLocker locker
;
7928 locker
.Create(this);
7930 for ( int col
= 0; col
< m_numCols
; col
++ )
7933 AutoSizeColumn(col
, setAsMin
);
7935 width
+= GetColWidth(col
);
7941 int wxGrid::SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
)
7943 int height
= m_colLabelHeight
;
7945 wxGridUpdateLocker locker
;
7947 locker
.Create(this);
7949 for ( int row
= 0; row
< m_numRows
; row
++ )
7952 AutoSizeRow(row
, setAsMin
);
7954 height
+= GetRowHeight(row
);
7960 void wxGrid::AutoSize()
7962 wxGridUpdateLocker
locker(this);
7964 wxSize
size(SetOrCalcColumnSizes(false) - m_rowLabelWidth
+ m_extraWidth
,
7965 SetOrCalcRowSizes(false) - m_colLabelHeight
+ m_extraHeight
);
7967 // we know that we're not going to have scrollbars so disable them now to
7968 // avoid trouble in SetClientSize() which can otherwise set the correct
7969 // client size but also leave space for (not needed any more) scrollbars
7970 SetScrollbars(0, 0, 0, 0, 0, 0, true);
7972 // restore the scroll rate parameters overwritten by SetScrollbars()
7973 SetScrollRate(m_scrollLineX
, m_scrollLineY
);
7975 SetClientSize(size
.x
+ m_rowLabelWidth
, size
.y
+ m_colLabelHeight
);
7978 void wxGrid::AutoSizeRowLabelSize( int row
)
7980 // Hide the edit control, so it
7981 // won't interfere with drag-shrinking.
7982 if ( IsCellEditControlShown() )
7984 HideCellEditControl();
7985 SaveEditControlValue();
7988 // autosize row height depending on label text
7989 SetRowSize(row
, -1);
7993 void wxGrid::AutoSizeColLabelSize( int col
)
7995 // Hide the edit control, so it
7996 // won't interfere with drag-shrinking.
7997 if ( IsCellEditControlShown() )
7999 HideCellEditControl();
8000 SaveEditControlValue();
8003 // autosize column width depending on label text
8004 SetColSize(col
, -1);
8008 wxSize
wxGrid::DoGetBestSize() const
8010 wxGrid
*self
= (wxGrid
*)this; // const_cast
8012 // we do the same as in AutoSize() here with the exception that we don't
8013 // change the column/row sizes, only calculate them
8014 wxSize
size(self
->SetOrCalcColumnSizes(true) - m_rowLabelWidth
+ m_extraWidth
,
8015 self
->SetOrCalcRowSizes(true) - m_colLabelHeight
+ m_extraHeight
);
8017 // NOTE: This size should be cached, but first we need to add calls to
8018 // InvalidateBestSize everywhere that could change the results of this
8020 // CacheBestSize(size);
8022 return wxSize(size
.x
+ m_rowLabelWidth
, size
.y
+ m_colLabelHeight
)
8023 + GetWindowBorderSize();
8031 wxPen
& wxGrid::GetDividerPen() const
8036 // ----------------------------------------------------------------------------
8037 // cell value accessor functions
8038 // ----------------------------------------------------------------------------
8040 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
8044 m_table
->SetValue( row
, col
, s
);
8045 if ( !GetBatchCount() )
8048 wxRect
rect( CellToRect( row
, col
) );
8050 rect
.width
= m_gridWin
->GetClientSize().GetWidth();
8051 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
8052 m_gridWin
->Refresh( false, &rect
);
8055 if ( m_currentCellCoords
.GetRow() == row
&&
8056 m_currentCellCoords
.GetCol() == col
&&
8057 IsCellEditControlShown())
8058 // Note: If we are using IsCellEditControlEnabled,
8059 // this interacts badly with calling SetCellValue from
8060 // an EVT_GRID_CELL_CHANGE handler.
8062 HideCellEditControl();
8063 ShowCellEditControl(); // will reread data from table
8068 // ----------------------------------------------------------------------------
8069 // block, row and column selection
8070 // ----------------------------------------------------------------------------
8072 void wxGrid::SelectRow( int row
, bool addToSelected
)
8077 if ( !addToSelected
)
8080 m_selection
->SelectRow(row
);
8083 void wxGrid::SelectCol( int col
, bool addToSelected
)
8088 if ( !addToSelected
)
8091 m_selection
->SelectCol(col
);
8094 void wxGrid::SelectBlock(int topRow
, int leftCol
, int bottomRow
, int rightCol
,
8100 if ( !addToSelected
)
8103 m_selection
->SelectBlock(topRow
, leftCol
, bottomRow
, rightCol
);
8106 void wxGrid::SelectAll()
8108 if ( m_numRows
> 0 && m_numCols
> 0 )
8111 m_selection
->SelectBlock( 0, 0, m_numRows
- 1, m_numCols
- 1 );
8115 // ----------------------------------------------------------------------------
8116 // cell, row and col deselection
8117 // ----------------------------------------------------------------------------
8119 void wxGrid::DeselectLine(int line
, const wxGridOperations
& oper
)
8124 const wxGridSelectionModes mode
= m_selection
->GetSelectionMode();
8125 if ( mode
== oper
.GetSelectionMode() ||
8126 mode
== wxGrid::wxGridSelectRowsOrColumns
)
8128 const wxGridCellCoords
c(oper
.MakeCoords(line
, 0));
8129 if ( m_selection
->IsInSelection(c
) )
8130 m_selection
->ToggleCellSelection(c
);
8132 else if ( mode
!= oper
.Dual().GetSelectionMode() )
8134 const int nOther
= oper
.Dual().GetNumberOfLines(this);
8135 for ( int i
= 0; i
< nOther
; i
++ )
8137 const wxGridCellCoords
c(oper
.MakeCoords(line
, i
));
8138 if ( m_selection
->IsInSelection(c
) )
8139 m_selection
->ToggleCellSelection(c
);
8142 //else: can only select orthogonal lines so no lines in this direction
8143 // could have been selected anyhow
8146 void wxGrid::DeselectRow(int row
)
8148 DeselectLine(row
, wxGridRowOperations());
8151 void wxGrid::DeselectCol(int col
)
8153 DeselectLine(col
, wxGridColumnOperations());
8156 void wxGrid::DeselectCell( int row
, int col
)
8158 if ( m_selection
&& m_selection
->IsInSelection(row
, col
) )
8159 m_selection
->ToggleCellSelection(row
, col
);
8162 bool wxGrid::IsSelection() const
8164 return ( m_selection
&& (m_selection
->IsSelection() ||
8165 ( m_selectedBlockTopLeft
!= wxGridNoCellCoords
&&
8166 m_selectedBlockBottomRight
!= wxGridNoCellCoords
) ) );
8169 bool wxGrid::IsInSelection( int row
, int col
) const
8171 return ( m_selection
&& (m_selection
->IsInSelection( row
, col
) ||
8172 ( row
>= m_selectedBlockTopLeft
.GetRow() &&
8173 col
>= m_selectedBlockTopLeft
.GetCol() &&
8174 row
<= m_selectedBlockBottomRight
.GetRow() &&
8175 col
<= m_selectedBlockBottomRight
.GetCol() )) );
8178 wxGridCellCoordsArray
wxGrid::GetSelectedCells() const
8182 wxGridCellCoordsArray a
;
8186 return m_selection
->m_cellSelection
;
8189 wxGridCellCoordsArray
wxGrid::GetSelectionBlockTopLeft() const
8193 wxGridCellCoordsArray a
;
8197 return m_selection
->m_blockSelectionTopLeft
;
8200 wxGridCellCoordsArray
wxGrid::GetSelectionBlockBottomRight() const
8204 wxGridCellCoordsArray a
;
8208 return m_selection
->m_blockSelectionBottomRight
;
8211 wxArrayInt
wxGrid::GetSelectedRows() const
8219 return m_selection
->m_rowSelection
;
8222 wxArrayInt
wxGrid::GetSelectedCols() const
8230 return m_selection
->m_colSelection
;
8233 void wxGrid::ClearSelection()
8235 wxRect r1
= BlockToDeviceRect(m_selectedBlockTopLeft
,
8236 m_selectedBlockBottomRight
);
8237 wxRect r2
= BlockToDeviceRect(m_currentCellCoords
,
8238 m_selectedBlockCorner
);
8240 m_selectedBlockTopLeft
=
8241 m_selectedBlockBottomRight
=
8242 m_selectedBlockCorner
= wxGridNoCellCoords
;
8244 if ( !r1
.IsEmpty() )
8245 RefreshRect(r1
, false);
8246 if ( !r2
.IsEmpty() )
8247 RefreshRect(r2
, false);
8250 m_selection
->ClearSelection();
8253 // This function returns the rectangle that encloses the given block
8254 // in device coords clipped to the client size of the grid window.
8256 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
8257 const wxGridCellCoords
& bottomRight
) const
8260 wxRect tempCellRect
= CellToRect(topLeft
);
8261 if ( tempCellRect
!= wxGridNoCellRect
)
8263 resultRect
= tempCellRect
;
8267 resultRect
= wxRect(0, 0, 0, 0);
8270 tempCellRect
= CellToRect(bottomRight
);
8271 if ( tempCellRect
!= wxGridNoCellRect
)
8273 resultRect
+= tempCellRect
;
8277 // If both inputs were "wxGridNoCellRect," then there's nothing to do.
8278 return wxGridNoCellRect
;
8281 // Ensure that left/right and top/bottom pairs are in order.
8282 int left
= resultRect
.GetLeft();
8283 int top
= resultRect
.GetTop();
8284 int right
= resultRect
.GetRight();
8285 int bottom
= resultRect
.GetBottom();
8287 int leftCol
= topLeft
.GetCol();
8288 int topRow
= topLeft
.GetRow();
8289 int rightCol
= bottomRight
.GetCol();
8290 int bottomRow
= bottomRight
.GetRow();
8314 // The following loop is ONLY necessary to detect and handle merged cells.
8316 m_gridWin
->GetClientSize( &cw
, &ch
);
8318 // Get the origin coordinates: notice that they will be negative if the
8319 // grid is scrolled downwards/to the right.
8320 int gridOriginX
= 0;
8321 int gridOriginY
= 0;
8322 CalcScrolledPosition(gridOriginX
, gridOriginY
, &gridOriginX
, &gridOriginY
);
8324 int onScreenLeftmostCol
= internalXToCol(-gridOriginX
);
8325 int onScreenUppermostRow
= internalYToRow(-gridOriginY
);
8327 int onScreenRightmostCol
= internalXToCol(-gridOriginX
+ cw
);
8328 int onScreenBottommostRow
= internalYToRow(-gridOriginY
+ ch
);
8330 // Bound our loop so that we only examine the portion of the selected block
8331 // that is shown on screen. Therefore, we compare the Top-Left block values
8332 // to the Top-Left screen values, and the Bottom-Right block values to the
8333 // Bottom-Right screen values, choosing appropriately.
8334 const int visibleTopRow
= wxMax(topRow
, onScreenUppermostRow
);
8335 const int visibleBottomRow
= wxMin(bottomRow
, onScreenBottommostRow
);
8336 const int visibleLeftCol
= wxMax(leftCol
, onScreenLeftmostCol
);
8337 const int visibleRightCol
= wxMin(rightCol
, onScreenRightmostCol
);
8339 for ( int j
= visibleTopRow
; j
<= visibleBottomRow
; j
++ )
8341 for ( int i
= visibleLeftCol
; i
<= visibleRightCol
; i
++ )
8343 if ( (j
== visibleTopRow
) || (j
== visibleBottomRow
) ||
8344 (i
== visibleLeftCol
) || (i
== visibleRightCol
) )
8346 tempCellRect
= CellToRect( j
, i
);
8348 if (tempCellRect
.x
< left
)
8349 left
= tempCellRect
.x
;
8350 if (tempCellRect
.y
< top
)
8351 top
= tempCellRect
.y
;
8352 if (tempCellRect
.x
+ tempCellRect
.width
> right
)
8353 right
= tempCellRect
.x
+ tempCellRect
.width
;
8354 if (tempCellRect
.y
+ tempCellRect
.height
> bottom
)
8355 bottom
= tempCellRect
.y
+ tempCellRect
.height
;
8359 i
= visibleRightCol
; // jump over inner cells.
8364 // Convert to scrolled coords
8365 CalcScrolledPosition( left
, top
, &left
, &top
);
8366 CalcScrolledPosition( right
, bottom
, &right
, &bottom
);
8368 if (right
< 0 || bottom
< 0 || left
> cw
|| top
> ch
)
8369 return wxRect(0,0,0,0);
8371 resultRect
.SetLeft( wxMax(0, left
) );
8372 resultRect
.SetTop( wxMax(0, top
) );
8373 resultRect
.SetRight( wxMin(cw
, right
) );
8374 resultRect
.SetBottom( wxMin(ch
, bottom
) );
8379 void wxGrid::DoSetSizes(const wxGridSizesInfo
& sizeInfo
,
8380 const wxGridOperations
& oper
)
8383 oper
.SetDefaultLineSize(this, sizeInfo
.m_sizeDefault
, true);
8384 const int numLines
= oper
.GetNumberOfLines(this);
8385 for ( int i
= 0; i
< numLines
; i
++ )
8387 int size
= sizeInfo
.GetSize(i
);
8388 if ( size
!= sizeInfo
.m_sizeDefault
)
8389 oper
.SetLineSize(this, i
, size
);
8394 void wxGrid::SetColSizes(const wxGridSizesInfo
& sizeInfo
)
8396 DoSetSizes(sizeInfo
, wxGridColumnOperations());
8399 void wxGrid::SetRowSizes(const wxGridSizesInfo
& sizeInfo
)
8401 DoSetSizes(sizeInfo
, wxGridRowOperations());
8404 wxGridSizesInfo::wxGridSizesInfo(int defSize
, const wxArrayInt
& allSizes
)
8406 m_sizeDefault
= defSize
;
8407 for ( size_t i
= 0; i
< allSizes
.size(); i
++ )
8409 if ( allSizes
[i
] != defSize
)
8410 m_customSizes
[i
] = allSizes
[i
];
8414 int wxGridSizesInfo::GetSize(unsigned pos
) const
8416 wxUnsignedToIntHashMap::const_iterator it
= m_customSizes
.find(pos
);
8418 return it
== m_customSizes
.end() ? m_sizeDefault
: it
->second
;
8421 // ----------------------------------------------------------------------------
8423 // ----------------------------------------------------------------------------
8425 #if wxUSE_DRAG_AND_DROP
8427 // this allow setting drop target directly on wxGrid
8428 void wxGrid::SetDropTarget(wxDropTarget
*dropTarget
)
8430 GetGridWindow()->SetDropTarget(dropTarget
);
8433 #endif // wxUSE_DRAG_AND_DROP
8435 // ----------------------------------------------------------------------------
8436 // grid event classes
8437 // ----------------------------------------------------------------------------
8439 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxNotifyEvent
)
8441 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
8442 int row
, int col
, int x
, int y
, bool sel
,
8443 bool control
, bool shift
, bool alt
, bool meta
)
8444 : wxNotifyEvent( type
, id
),
8445 wxKeyboardState(control
, shift
, alt
, meta
)
8447 Init(row
, col
, x
, y
, sel
);
8449 SetEventObject(obj
);
8452 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxNotifyEvent
)
8454 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
8455 int rowOrCol
, int x
, int y
,
8456 bool control
, bool shift
, bool alt
, bool meta
)
8457 : wxNotifyEvent( type
, id
),
8458 wxKeyboardState(control
, shift
, alt
, meta
)
8460 Init(rowOrCol
, x
, y
);
8462 SetEventObject(obj
);
8466 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxNotifyEvent
)
8468 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
8469 const wxGridCellCoords
& topLeft
,
8470 const wxGridCellCoords
& bottomRight
,
8471 bool sel
, bool control
,
8472 bool shift
, bool alt
, bool meta
)
8473 : wxNotifyEvent( type
, id
),
8474 wxKeyboardState(control
, shift
, alt
, meta
)
8476 Init(topLeft
, bottomRight
, sel
);
8478 SetEventObject(obj
);
8482 IMPLEMENT_DYNAMIC_CLASS(wxGridEditorCreatedEvent
, wxCommandEvent
)
8484 wxGridEditorCreatedEvent::wxGridEditorCreatedEvent(int id
, wxEventType type
,
8485 wxObject
* obj
, int row
,
8486 int col
, wxControl
* ctrl
)
8487 : wxCommandEvent(type
, id
)
8489 SetEventObject(obj
);
8496 // ----------------------------------------------------------------------------
8497 // wxGridTypeRegistry
8498 // ----------------------------------------------------------------------------
8500 wxGridTypeRegistry::~wxGridTypeRegistry()
8502 size_t count
= m_typeinfo
.GetCount();
8503 for ( size_t i
= 0; i
< count
; i
++ )
8504 delete m_typeinfo
[i
];
8507 void wxGridTypeRegistry::RegisterDataType(const wxString
& typeName
,
8508 wxGridCellRenderer
* renderer
,
8509 wxGridCellEditor
* editor
)
8511 wxGridDataTypeInfo
* info
= new wxGridDataTypeInfo(typeName
, renderer
, editor
);
8513 // is it already registered?
8514 int loc
= FindRegisteredDataType(typeName
);
8515 if ( loc
!= wxNOT_FOUND
)
8517 delete m_typeinfo
[loc
];
8518 m_typeinfo
[loc
] = info
;
8522 m_typeinfo
.Add(info
);
8526 int wxGridTypeRegistry::FindRegisteredDataType(const wxString
& typeName
)
8528 size_t count
= m_typeinfo
.GetCount();
8529 for ( size_t i
= 0; i
< count
; i
++ )
8531 if ( typeName
== m_typeinfo
[i
]->m_typeName
)
8540 int wxGridTypeRegistry::FindDataType(const wxString
& typeName
)
8542 int index
= FindRegisteredDataType(typeName
);
8543 if ( index
== wxNOT_FOUND
)
8545 // check whether this is one of the standard ones, in which case
8546 // register it "on the fly"
8548 if ( typeName
== wxGRID_VALUE_STRING
)
8550 RegisterDataType(wxGRID_VALUE_STRING
,
8551 new wxGridCellStringRenderer
,
8552 new wxGridCellTextEditor
);
8555 #endif // wxUSE_TEXTCTRL
8557 if ( typeName
== wxGRID_VALUE_BOOL
)
8559 RegisterDataType(wxGRID_VALUE_BOOL
,
8560 new wxGridCellBoolRenderer
,
8561 new wxGridCellBoolEditor
);
8564 #endif // wxUSE_CHECKBOX
8566 if ( typeName
== wxGRID_VALUE_NUMBER
)
8568 RegisterDataType(wxGRID_VALUE_NUMBER
,
8569 new wxGridCellNumberRenderer
,
8570 new wxGridCellNumberEditor
);
8572 else if ( typeName
== wxGRID_VALUE_FLOAT
)
8574 RegisterDataType(wxGRID_VALUE_FLOAT
,
8575 new wxGridCellFloatRenderer
,
8576 new wxGridCellFloatEditor
);
8579 #endif // wxUSE_TEXTCTRL
8581 if ( typeName
== wxGRID_VALUE_CHOICE
)
8583 RegisterDataType(wxGRID_VALUE_CHOICE
,
8584 new wxGridCellStringRenderer
,
8585 new wxGridCellChoiceEditor
);
8588 #endif // wxUSE_COMBOBOX
8593 // we get here only if just added the entry for this type, so return
8595 index
= m_typeinfo
.GetCount() - 1;
8601 int wxGridTypeRegistry::FindOrCloneDataType(const wxString
& typeName
)
8603 int index
= FindDataType(typeName
);
8604 if ( index
== wxNOT_FOUND
)
8606 // the first part of the typename is the "real" type, anything after ':'
8607 // are the parameters for the renderer
8608 index
= FindDataType(typeName
.BeforeFirst(wxT(':')));
8609 if ( index
== wxNOT_FOUND
)
8614 wxGridCellRenderer
*renderer
= GetRenderer(index
);
8615 wxGridCellRenderer
*rendererOld
= renderer
;
8616 renderer
= renderer
->Clone();
8617 rendererOld
->DecRef();
8619 wxGridCellEditor
*editor
= GetEditor(index
);
8620 wxGridCellEditor
*editorOld
= editor
;
8621 editor
= editor
->Clone();
8622 editorOld
->DecRef();
8624 // do it even if there are no parameters to reset them to defaults
8625 wxString params
= typeName
.AfterFirst(wxT(':'));
8626 renderer
->SetParameters(params
);
8627 editor
->SetParameters(params
);
8629 // register the new typename
8630 RegisterDataType(typeName
, renderer
, editor
);
8632 // we just registered it, it's the last one
8633 index
= m_typeinfo
.GetCount() - 1;
8639 wxGridCellRenderer
* wxGridTypeRegistry::GetRenderer(int index
)
8641 wxGridCellRenderer
* renderer
= m_typeinfo
[index
]->m_renderer
;
8648 wxGridCellEditor
* wxGridTypeRegistry::GetEditor(int index
)
8650 wxGridCellEditor
* editor
= m_typeinfo
[index
]->m_editor
;
8657 #endif // wxUSE_GRID