// Required for wxIs... functions
#include <ctype.h>
-WX_DECLARE_HASH_SET_WITH_DECL(int, wxIntegerHash, wxIntegerEqual,
- wxGridFixedIndicesSet, class WXDLLIMPEXP_ADV);
+WX_DECLARE_HASH_SET_WITH_DECL_PTR(int, ::wxIntegerHash, ::wxIntegerEqual,
+ wxGridFixedIndicesSet, class WXDLLIMPEXP_ADV);
// ----------------------------------------------------------------------------
wxDEFINE_EVENT( wxEVT_GRID_EDITOR_HIDDEN, wxGridEvent );
wxDEFINE_EVENT( wxEVT_GRID_EDITOR_CREATED, wxGridEditorCreatedEvent );
+// ----------------------------------------------------------------------------
+// private helpers
+// ----------------------------------------------------------------------------
+
+namespace
+{
+
+ // ensure that first is less or equal to second, swapping the values if
+ // necessary
+ void EnsureFirstLessThanSecond(int& first, int& second)
+ {
+ if ( first > second )
+ wxSwap(first, second);
+ }
+
+} // anonymous namespace
+
// ============================================================================
// implementation
// ============================================================================
wxASSERT_MSG( (!((num_rows > 0) && (num_cols <= 0)) ||
!((num_rows <= 0) && (num_cols > 0)) ||
!((num_rows == 0) && (num_cols == 0))),
- wxT("wxGridCellAttr::SetSize only takes two postive values or negative/zero values"));
+ wxT("wxGridCellAttr::SetSize only takes two positive values or negative/zero values"));
m_sizeRows = num_rows;
m_sizeCols = num_cols;
// m_colLabels stores just as many elements as it needs, e.g. if only
// the label of the first column had been set it would have only one
// element and not numCols, so account for it
- int nToRm = m_colLabels.size() - colID;
- if ( nToRm > 0 )
- m_colLabels.RemoveAt( colID, nToRm );
+ int numRemaining = m_colLabels.size() - colID;
+ if (numRemaining > 0)
+ m_colLabels.RemoveAt( colID, wxMin(numCols, numRemaining) );
}
if ( numCols >= curNumCols )
/////////////////////////////////////////////////////////////////////
-#if wxUSE_EXTENDED_RTTI
-WX_DEFINE_FLAGS( wxGridStyle )
-
-wxBEGIN_FLAGS( wxGridStyle )
- // new style border flags, we put them first to
- // use them for streaming out
- wxFLAGS_MEMBER(wxBORDER_SIMPLE)
- wxFLAGS_MEMBER(wxBORDER_SUNKEN)
- wxFLAGS_MEMBER(wxBORDER_DOUBLE)
- wxFLAGS_MEMBER(wxBORDER_RAISED)
- wxFLAGS_MEMBER(wxBORDER_STATIC)
- wxFLAGS_MEMBER(wxBORDER_NONE)
-
- // old style border flags
- wxFLAGS_MEMBER(wxSIMPLE_BORDER)
- wxFLAGS_MEMBER(wxSUNKEN_BORDER)
- wxFLAGS_MEMBER(wxDOUBLE_BORDER)
- wxFLAGS_MEMBER(wxRAISED_BORDER)
- wxFLAGS_MEMBER(wxSTATIC_BORDER)
- wxFLAGS_MEMBER(wxBORDER)
-
- // standard window styles
- wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
- wxFLAGS_MEMBER(wxCLIP_CHILDREN)
- wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
- wxFLAGS_MEMBER(wxWANTS_CHARS)
- wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
- wxFLAGS_MEMBER(wxALWAYS_SHOW_SB)
- wxFLAGS_MEMBER(wxVSCROLL)
- wxFLAGS_MEMBER(wxHSCROLL)
-
-wxEND_FLAGS( wxGridStyle )
-
-IMPLEMENT_DYNAMIC_CLASS_XTI(wxGrid, wxScrolledWindow,"wx/grid.h")
-
-wxBEGIN_PROPERTIES_TABLE(wxGrid)
- wxHIDE_PROPERTY( Children )
- wxPROPERTY_FLAGS( WindowStyle , wxGridStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
-wxEND_PROPERTIES_TABLE()
-
-wxBEGIN_HANDLERS_TABLE(wxGrid)
-wxEND_HANDLERS_TABLE()
-
-wxCONSTRUCTOR_5( wxGrid , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
-
-/*
- TODO : Expose more information of a list's layout, etc. via appropriate objects (e.g., NotebookPageInfo)
-*/
-#else
-IMPLEMENT_DYNAMIC_CLASS( wxGrid, wxScrolledWindow )
-#endif
-
BEGIN_EVENT_TABLE( wxGrid, wxScrolledWindow )
EVT_PAINT( wxGrid::OnPaint )
EVT_SIZE( wxGrid::OnSize )
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow());
m_dragLastPos = -1;
}
- else // not on row separator or it's not resizeable
+ else // not on row separator or it's not resizable
{
row = YToRow(y);
if ( row >=0 &&
// grid mouse event processing
// ----------------------------------------------------------------------------
-void
+bool
wxGrid::DoGridCellDrag(wxMouseEvent& event,
const wxGridCellCoords& coords,
bool isFirstDrag)
{
+ bool performDefault = true ;
+
if ( coords == wxGridNoCellCoords )
- return; // we're outside any valid cell
+ return performDefault; // we're outside any valid cell
// Hide the edit control, so it won't interfere with drag-shrinking.
if ( IsCellEditControlShown() )
switch ( event.GetModifiers() )
{
- case wxMOD_CMD:
+ case wxMOD_CONTROL:
if ( m_selectedBlockCorner == wxGridNoCellCoords)
m_selectedBlockCorner = coords;
UpdateBlockBeingSelected(m_selectedBlockCorner, coords);
if ( m_selectedBlockCorner == wxGridNoCellCoords)
m_selectedBlockCorner = coords;
- SendEvent(wxEVT_GRID_CELL_BEGIN_DRAG, coords, event);
- return;
+ // if event is handled by user code, no further processing
+ if ( SendEvent(wxEVT_GRID_CELL_BEGIN_DRAG, coords, event) != 0 )
+ performDefault = false;
+
+ return performDefault;
}
}
// we don't handle the other key modifiers
event.Skip();
}
+
+ return performDefault;
}
void wxGrid::DoGridLineDrag(wxMouseEvent& event, const wxGridOperations& oper)
switch ( m_cursorMode )
{
case WXGRID_CURSOR_SELECT_CELL:
- DoGridCellDrag(event, coords, isFirstDrag);
+ // no further handling if handled by user
+ if ( DoGridCellDrag(event, coords, isFirstDrag) == false )
+ return;
break;
case WXGRID_CURSOR_RESIZE_ROW:
mouseEv.GetY() + GetColLabelSize(),
false,
mouseEv);
+
+ if ( type == wxEVT_GRID_CELL_BEGIN_DRAG )
+ {
+ // by default the dragging is not supported, the user code must
+ // explicitly allow the event for it to take place
+ gridEvt.Veto();
+ }
+
claimed = GetEventHandler()->ProcessEvent(gridEvt);
vetoed = !gridEvt.IsAllowed();
}
wxGrid::UpdateBlockBeingSelected(int topRow, int leftCol,
int bottomRow, int rightCol)
{
+ MakeCellVisible(m_selectedBlockCorner);
+ m_selectedBlockCorner = wxGridCellCoords(bottomRow, rightCol);
+
if ( m_selection )
{
switch ( m_selection->GetSelectionMode() )
}
}
- m_selectedBlockCorner = wxGridCellCoords(bottomRow, rightCol);
- MakeCellVisible(m_selectedBlockCorner);
-
EnsureFirstLessThanSecond(topRow, bottomRow);
EnsureFirstLessThanSecond(leftCol, rightCol);
bool wxGrid::IsCurrentCellReadOnly() const
{
- // const_cast
- wxGridCellAttr* attr = ((wxGrid *)this)->GetCellAttr(m_currentCellCoords);
+ wxGridCellAttr*
+ attr = const_cast<wxGrid *>(this)->GetCellAttr(m_currentCellCoords);
bool readonly = attr->IsReadOnly();
attr->DecRef();
else if ( line > 0 &&
pos - oper.GetLineStartPos(this,
line) < WXGRID_LABEL_EDGE_ZONE )
- return line - 1;
+ {
+ return oper.GetLineBefore(this, line);
+ }
}
return -1;
m_cellHighlightPenWidth = width;
// Just redrawing the cell highlight is not enough since that won't
- // make any visible change if the the thickness is getting smaller.
+ // make any visible change if the thickness is getting smaller.
int row = m_currentCellCoords.GetRow();
int col = m_currentCellCoords.GetCol();
if ( row == -1 || col == -1 || GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 )
m_cellHighlightROPenWidth = width;
// Just redrawing the cell highlight is not enough since that won't
- // make any visible change if the the thickness is getting smaller.
+ // make any visible change if the thickness is getting smaller.
int row = m_currentCellCoords.GetRow();
int col = m_currentCellCoords.GetCol();
if ( row == -1 || col == -1 ||
{
if ( attr != NULL )
{
- wxGrid *self = (wxGrid *)this; // const_cast
+ wxGrid * const self = const_cast<wxGrid *>(this);
self->ClearAttrCache();
self->m_attrCache.row = row;
}
// See comment in SetColSize
- if ( height < GetRowMinimalAcceptableHeight())
+ if ( height > 0 && height < GetRowMinimalAcceptableHeight())
return;
if ( m_rowHeights.IsEmpty() )
}
if ( !GetBatchCount() )
+ {
CalcDimensions();
+ Refresh();
+ }
}
void wxGrid::SetDefaultColSize( int width, bool resizeExistingCols )
wxSize wxGrid::DoGetBestSize() const
{
- wxGrid *self = (wxGrid *)this; // const_cast
+ wxGrid * const self = const_cast<wxGrid *>(this);
// we do the same as in AutoSize() here with the exception that we don't
// change the column/row sizes, only calculate them
AutoSize();
}
+#if WXWIN_COMPATIBILITY_2_8
wxPen& wxGrid::GetDividerPen() const
{
return wxNullPen;
}
+#endif // WXWIN_COMPATIBILITY_2_8
// ----------------------------------------------------------------------------
// cell value accessor functions