wxString wxGridCellFloatEditor::GetString() const
{
wxString fmt;
- if ( m_width == -1 )
- {
- // default width/precision
- fmt = _T("%f");
- }
- else if ( m_precision == -1 )
+ if ( m_precision == -1 && m_width != -1)
{
// default precision
fmt.Printf(_T("%%%d.f"), m_width);
}
- else
+ else if ( m_precision != -1 && m_width == -1)
+ {
+ // default width
+ fmt.Printf(_T("%%.%df"), m_precision);
+ }
+ else if ( m_precision != -1 && m_width != -1 )
{
fmt.Printf(_T("%%%d.%df"), m_width, m_precision);
}
+ else
+ {
+ // default width/precision
+ fmt = _T("%f");
+ }
return wxString::Format(fmt, m_valueOld);
}
Combo()->SetFocus();
if (evtHandler)
+ {
+ // When dropping down the menu, a kill focus event
+ // happens after this point, so we can't reset the flag yet.
+#if !defined(__WXGTK20__)
evtHandler->SetInSetFocus(false);
+#endif
+ }
}
bool wxGridCellChoiceEditor::EndEdit(int row, int col,
void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event)
{
+ int row = m_grid->GetGridCursorRow();
+ int col = m_grid->GetGridCursorCol();
+ wxRect rect = m_grid->CellToRect( row, col );
+ int cw, ch;
+ m_grid->GetGridWindow()->GetClientSize( &cw, &ch );
+ // if cell width is smaller than grid client area, cell is wholly visible
+ bool wholeCellVisible = (rect.GetWidth() < cw);
+
switch ( event.GetKeyCode() )
{
case WXK_ESCAPE:
case WXK_NUMPAD_ENTER:
break;
+ case WXK_HOME:
+ {
+ if( wholeCellVisible )
+ {
+ // no special processing needed...
+ event.Skip();
+ break;
+ }
+
+ // do special processing for partly visible cell...
+
+ // get the widths of all cells previous to this one
+ int colXPos = 0;
+ for ( int i = 0; i < col; i++ )
+ {
+ colXPos += m_grid->GetColSize(i);
+ }
+
+ int xUnit = 1, yUnit = 1;
+ m_grid->GetScrollPixelsPerUnit(&xUnit, &yUnit);
+ if (col != 0)
+ {
+ m_grid->Scroll(colXPos/xUnit-1, m_grid->GetScrollPos(wxVERTICAL));
+ }
+ else
+ {
+ m_grid->Scroll(colXPos/xUnit, m_grid->GetScrollPos(wxVERTICAL));
+ }
+ event.Skip();
+ break;
+ }
+ case WXK_END:
+ {
+ if( wholeCellVisible )
+ {
+ // no special processing needed...
+ event.Skip();
+ break;
+ }
+
+ // do special processing for partly visible cell...
+
+ int textWidth = 0;
+ wxString value = m_grid->GetCellValue(row, col);
+ if ( wxEmptyString != value )
+ {
+ // get width of cell CONTENTS (text)
+ int y;
+ wxFont font = m_grid->GetCellFont(row, col);
+ m_grid->GetTextExtent(value, &textWidth, &y, NULL, NULL, &font);
+ // try to RIGHT align the text by scrolling
+ int client_right = m_grid->GetGridWindow()->GetClientSize().GetWidth();
+ // (m_grid->GetScrollLineX()*2) is a factor for not scrolling to far,
+ // otherwise the last part of the cell content might be hidden below the scroll bar
+ // FIXME: maybe there is a more suitable correction?
+ textWidth -= (client_right - (m_grid->GetScrollLineX()*2));
+ if ( textWidth < 0 )
+ {
+ textWidth = 0;
+ }
+ }
+
+ // get the widths of all cells previous to this one
+ int colXPos = 0;
+ for ( int i = 0; i < col; i++ )
+ {
+ colXPos += m_grid->GetColSize(i);
+ }
+ // and add the (modified) text width of the cell contents
+ // as we'd like to see the last part of the cell contents
+ colXPos += textWidth;
+
+ int xUnit = 1, yUnit = 1;
+ m_grid->GetScrollPixelsPerUnit(&xUnit, &yUnit);
+ m_grid->Scroll(colXPos/xUnit-1, m_grid->GetScrollPos(wxVERTICAL));
+ event.Skip();
+ break;
+ }
+
default:
event.Skip();
}
wxGridCellAttr *attr = (wxGridCellAttr *)NULL;
if ( m_data )
{
- switch(kind)
+ switch (kind)
{
case (wxGridCellAttr::Any):
- //Get cached merge attributes.
- // Currenlty not used as no cache implemented as not mutiable
+ // Get cached merge attributes.
+ // Currently not used as no cache implemented as not mutable
// attr = m_data->m_mergeAttr.GetAttr(row, col);
if (!attr)
{
- //Basically implement old version.
- //Also check merge cache, so we don't have to re-merge every time..
+ // Basically implement old version.
+ // Also check merge cache, so we don't have to re-merge every time..
wxGridCellAttr *attrcell = m_data->m_cellAttrs.GetAttr(row, col);
wxGridCellAttr *attrrow = m_data->m_rowAttrs.GetAttr(row);
wxGridCellAttr *attrcol = m_data->m_colAttrs.GetAttr(col);
attr = new wxGridCellAttr;
attr->SetKind(wxGridCellAttr::Merged);
- //Order important..
+ // Order is important..
if (attrcell)
{
attr->MergeWith(attrcell);
attr->MergeWith(attrrow);
attrrow->DecRef();
}
- //store merge attr if cache implemented
+
+ // store merge attr if cache implemented
//attr->IncRef();
//m_data->m_mergeAttr.SetAttr(attr, row, col);
}
attr = attrrow;
if (attrcol)
{
- if(attr)
+ if (attr)
attr->DecRef();
attr = attrcol;
}
m_table = table;
m_table->SetView( this );
- if (takeOwnership)
- m_ownTable = true;
+ m_ownTable = takeOwnership;
m_selection = new wxGridSelection( this, selmode );
CalcDimensions();
if ( event.LeftIsDown() )
{
- switch( m_cursorMode )
+ switch ( m_cursorMode )
{
case WXGRID_CURSOR_RESIZE_ROW:
{
if ( event.LeftIsDown() )
{
- switch( m_cursorMode )
+ switch ( m_cursorMode )
{
case WXGRID_CURSOR_RESIZE_COL:
{
{
//wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
- // Don't start doing anything until the mouse has been drug at
+ // Don't start doing anything until the mouse has been dragged at
// least 3 pixels in any direction...
if (! m_isDragging)
{
// Dragging on the corner of a cell to resize in both
// directions is not implemented yet...
//
- if ( dragRow >= 0 && dragCol >= 0 )
+ if ( dragRow >= 0 && dragCol >= 0 )
{
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
return;
if ( CanDragRowSize() && CanDragGridSize() )
ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW);
}
-
- if ( dragCol >= 0 )
- {
- m_dragRowOrCol = dragCol;
- }
-
- return;
}
-
- if ( dragCol >= 0 )
+ else if ( dragCol >= 0 )
{
m_dragRowOrCol = dragCol;
if ( CanDragColSize() && CanDragGridSize() )
ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL);
}
-
- return;
}
-
- // Neither on a row or col edge
- //
- if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
+ else // Neither on a row or col edge
{
- ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
+ if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
+ {
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
+ }
}
}
}
// Note: However, only if it is really _shown_, i.e. not hidden!
if ( isCurrent && IsCellEditControlShown() )
{
+ // OSAF NB: this "#if..." is temporary and fixes a problem where the
+ // edit control is erased by this code after being rendered.
+ // On wxMac (QD build only), the cell editor is a wxTextCntl and is rendered
+ // implicitly, causing this out-of order render.
+#if !defined(__WXMAC__) || wxMAC_USE_CORE_GRAPHICS
wxGridCellEditor *editor = attr->GetEditor(this, row, col);
editor->PaintBackground(rect, attr);
editor->DecRef();
+#endif
}
else
{
int vertAlign,
int textOrientation )
{
- long textWidth, textHeight;
- long lineWidth, lineHeight;
+ long textWidth = 0, textHeight = 0;
+ long lineWidth = 0, lineHeight = 0;
int nLines;
dc.SetClippingRegion( rect );
else
GetTextBoxSize( dc, lines, &textHeight, &textWidth );
- switch( vertAlign )
+ switch ( vertAlign )
{
case wxALIGN_BOTTOM:
if ( textOrientation == wxHORIZONTAL )
{
dc.GetTextExtent(lines[l], &lineWidth, &lineHeight);
- switch( horizAlign )
+ switch ( horizAlign )
{
case wxALIGN_RIGHT:
if ( textOrientation == wxHORIZONTAL )
{
long w = 0;
long h = 0;
- long lineW, lineH;
+ long lineW = 0, lineH = 0;
size_t i;
for ( i = 0; i < lines.GetCount(); i++ )
if (! m_editable)
return;
- if ( m_currentCellCoords == wxGridNoCellCoords )
- SetCurrentCell( 0, 0 );
-
if ( enable != m_cellEditCtrlEnabled )
{
if ( enable )
{
if ( IsCellEditControlEnabled() )
{
- if ( !IsVisible( m_currentCellCoords ) )
+ if ( !IsVisible( m_currentCellCoords, false ) )
{
m_cellEditCtrlEnabled = false;
return;
//
CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+ int nXMove = 0;
+ if(rect.x < 0)
+ nXMove = rect.x;
+
// done in PaintBackground()
#if 0
// erase the highlight and the cell contents because the editor
editor->SetCellAttr(attr);
editor->SetSize( rect );
+ editor->GetControl()->Move(editor->GetControl()->GetPosition().x + nXMove, editor->GetControl()->GetPosition().y);
editor->Show( true, attr );
+ int colXPos = 0;
+ for (int i = 0; i < m_currentCellCoords.GetCol(); i++)
+ {
+ colXPos += GetColSize(i);
+ }
+ int xUnit=1, yUnit=1;
+ GetScrollPixelsPerUnit(&xUnit, &yUnit);
+ if (m_currentCellCoords.GetCol() != 0)
+ Scroll(colXPos/xUnit-1, GetScrollPos(wxVERTICAL));
+ else
+ Scroll(colXPos/xUnit, GetScrollPos(wxVERTICAL));
+
// recalc dimensions in case we need to
// expand the scrolled window to account for editor
CalcDimensions();
ypos += m_scrollLineY;
}
- if ( left < 0 )
+ // special handling for wide cells - show always left part of the cell!
+ // Otherwise, e.g. when stepping from row to row, it would jump between
+ // left and right part of the cell on every step!
+// if ( left < 0 )
+ if ( left < 0 || (right-left) >= cw )
{
xpos = r.GetLeft();
}
}
else if ( m_currentCellCoords.GetRow() > 0 )
{
+ int row = m_currentCellCoords.GetRow() - 1;
+ int col = m_currentCellCoords.GetCol();
ClearSelection();
- MakeCellVisible( m_currentCellCoords.GetRow() - 1,
- m_currentCellCoords.GetCol() );
- SetCurrentCell( m_currentCellCoords.GetRow() - 1,
- m_currentCellCoords.GetCol() );
+ MakeCellVisible( row, col );
+ SetCurrentCell( row, col );
}
else
return false;
}
else if ( m_currentCellCoords.GetRow() < m_numRows - 1 )
{
+ int row = m_currentCellCoords.GetRow() + 1;
+ int col = m_currentCellCoords.GetCol();
ClearSelection();
- MakeCellVisible( m_currentCellCoords.GetRow() + 1,
- m_currentCellCoords.GetCol() );
- SetCurrentCell( m_currentCellCoords.GetRow() + 1,
- m_currentCellCoords.GetCol() );
+ MakeCellVisible( row, col );
+ SetCurrentCell( row, col );
}
else
return false;
}
else if ( m_currentCellCoords.GetCol() > 0 )
{
+ int row = m_currentCellCoords.GetRow();
+ int col = m_currentCellCoords.GetCol() - 1;
ClearSelection();
- MakeCellVisible( m_currentCellCoords.GetRow(),
- m_currentCellCoords.GetCol() - 1 );
- SetCurrentCell( m_currentCellCoords.GetRow(),
- m_currentCellCoords.GetCol() - 1 );
+ MakeCellVisible( row, col );
+ SetCurrentCell( row, col );
}
else
return false;
}
else if ( m_currentCellCoords.GetCol() < m_numCols - 1 )
{
+ int row = m_currentCellCoords.GetRow();
+ int col = m_currentCellCoords.GetCol() + 1;
ClearSelection();
- MakeCellVisible( m_currentCellCoords.GetRow(),
- m_currentCellCoords.GetCol() + 1 );
- SetCurrentCell( m_currentCellCoords.GetRow(),
- m_currentCellCoords.GetCol() + 1 );
+ MakeCellVisible( row, col );
+ SetCurrentCell( row, col );
}
else
return false;
int index = m_typeRegistry->FindOrCloneDataType(typeName);
if ( index == wxNOT_FOUND )
{
- wxString errStr;
+ wxString errStr;
errStr.Printf(wxT("Unknown data type name [%s]"), typeName.c_str());
wxFAIL_MSG(errStr.c_str());
int index = m_typeRegistry->FindOrCloneDataType(typeName);
if ( index == wxNOT_FOUND )
{
- wxString errStr;
+ wxString errStr;
errStr.Printf(wxT("Unknown data type name [%s]"), typeName.c_str());
wxFAIL_MSG(errStr.c_str());
return m_typeRegistry->GetRenderer(index);
}
-
// ----------------------------------------------------------------------------
// row/col size
// ----------------------------------------------------------------------------
//
// This test then fixes sf.net bug #645734
- if ( width < GetColMinimalAcceptableWidth())
+ if ( width < GetColMinimalAcceptableWidth() )
return;
if ( m_colWidths.IsEmpty() )
GetTextBoxSize(dc, lines, &w, &h);
width = w + 6;
}
+
int w = wxMax( 0, width );
int diff = w - m_colWidths[col];
m_colWidths[col] = w;
{
m_colRights[i] += diff;
}
+
if ( !GetBatchCount() )
CalcDimensions();
}
{
wxLongToLongHashMap::key_type key = (wxLongToLongHashMap::key_type)col;
wxLongToLongHashMap::const_iterator it = m_colMinWidths.find(key);
+
return it != m_colMinWidths.end() ? (int)it->second : m_minAcceptableColWidth;
}
{
wxLongToLongHashMap::key_type key = (wxLongToLongHashMap::key_type)row;
wxLongToLongHashMap::const_iterator it = m_rowMinHeights.find(key);
+
return it != m_rowMinHeights.end() ? (int)it->second : m_minAcceptableRowHeight;
}
void wxGrid::SetColMinimalAcceptableWidth( int width )
{
// We do allow a width of 0 since this gives us
- // an easy way to temporarily hidding columns.
- if ( width < 0 )
- return;
- m_minAcceptableColWidth = width;
+ // an easy way to temporarily hiding columns.
+ if ( width >= 0 )
+ m_minAcceptableColWidth = width;
}
void wxGrid::SetRowMinimalAcceptableHeight( int height )
{
// We do allow a height of 0 since this gives us
- // an easy way to temporarily hidding rows.
- if ( height < 0 )
- return;
- m_minAcceptableRowHeight = height;
+ // an easy way to temporarily hiding rows.
+ if ( height >= 0 )
+ m_minAcceptableRowHeight = height;
}
int wxGrid::GetColMinimalAcceptableWidth() const
{
wxClientDC dc(m_gridWin);
- //Cancel editting of cell
+ // cancel editing of cell
HideCellEditControl();
SaveEditControlValue();
- // init both of them to avoid compiler warnings, even if weo nly need one
+ // init both of them to avoid compiler warnings, even if we only need one
int row = -1,
col = -1;
if ( column )
else
{
if ( column )
- {
// leave some space around text
extentMax += 10;
- }
else
- {
extentMax += 6;
- }
}
if ( column )
{
- SetColSize(col, extentMax);
+ SetColSize( col, extentMax );
if ( !GetBatchCount() )
{
int cw, ch, dummy;
for ( int row = 0; row < m_numRows; row++ )
{
if ( !calcOnly )
- {
AutoSizeRow(row, setAsMin);
- }
height += GetRowHeight(row);
}
height = maxheight;
wxSize best(width, height);
+
// NOTE: This size should be cached, but first we need to add calls to
// InvalidateBestSize everywhere that could change the results of this
// calculation.
// CacheBestSize(size);
+
return best;
}
}
-//
-// ------ Block, row and col selection
-//
+// ----------------------------------------------------------------------------
+// block, row and col selection
+// ----------------------------------------------------------------------------
void wxGrid::SelectRow( int row, bool addToSelected )
{
}
}
-//
-// ------ Cell, row and col deselection
-//
+// ----------------------------------------------------------------------------
+// cell, row and col deselection
+// ----------------------------------------------------------------------------
void wxGrid::DeselectRow( int row )
{
}
else
{
- rect = wxRect(0,0,0,0);
+ rect = wxRect(0, 0, 0, 0);
}
cellRect = CellToRect( bottomRight );
bottomRow = i;
}
-
for ( j = topRow; j <= bottomRow; j++ )
{
for ( i = leftCol; i <= rightCol; i++ )
return rect;
}
-//
-// ------ Grid event classes
-//
+// ----------------------------------------------------------------------------
+// grid event classes
+// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS( wxGridEvent, wxNotifyEvent )