m_startValue = grid->GetTable()->GetValue(row, col);
- Combo()->SetValue(m_startValue);
- size_t count = m_choices.GetCount();
- for (size_t i=0; i<count; i++)
+ if (m_allowOthers)
+ Combo()->SetValue(m_startValue);
+ else
{
- if (m_startValue == m_choices[i])
- {
- Combo()->SetSelection(i);
- break;
- }
+ // find the right position, or default to the first if not found
+ int pos = Combo()->FindString(m_startValue);
+ if (pos == -1)
+ pos = 0;
+ Combo()->SetSelection(pos);
}
Combo()->SetInsertionPointEnd();
Combo()->SetFocus();
grid->GetTable()->SetValue(row, col, value);
m_startValue = wxEmptyString;
- Combo()->SetValue(m_startValue);
+ if (m_allowOthers)
+ Combo()->SetValue(m_startValue);
+ else
+ Combo()->SetSelection(0);
return changed;
}
int i, c_cols, c_rows;
for (i = col+cell_cols; i < cols; i++)
{
- bool is_empty = TRUE;
+ bool is_empty = TRUE;
for (int j=row; j<row+cell_rows; j++)
{
// check w/ anchor cell for multicell block
- grid.GetCellSize(row, i, &c_rows, &c_cols);
+ grid.GetCellSize(j, i, &c_rows, &c_cols);
if (c_rows > 0) c_rows = 0;
- if (grid.GetTable()->IsEmptyCell(row+c_rows, i))
+ if (!grid.GetTable()->IsEmptyCell(j+c_rows, i))
{
- is_empty = FALSE;
- break;
+ is_empty = FALSE;
+ break;
}
}
if (is_empty)
break;
}
if (rect.width >= best_width) break;
- }
+ }
overflowCols = i - col - cell_cols + 1;
- if (overflowCols >= cols) overflowCols = cols - 1;
+ if (overflowCols >= cols) overflowCols = cols - 1;
}
if (overflowCols > 0) // redraw overflow cells w/ proper hilight
{
hAlign = wxALIGN_LEFT; // if oveflowed then it's left aligned
- wxRect clip = rect;
+ wxRect clip = rect;
clip.x += rectCell.width;
// draw each overflow cell individually
int col_end = col+cell_cols+overflowCols;
if (col_end >= grid.GetNumberCols())
- col_end = grid.GetNumberCols() - 1;
+ col_end = grid.GetNumberCols() - 1;
for (int i = col+cell_cols; i <= col_end; i++)
{
clip.width = grid.GetColSize(i) - 1;
dc.SetClippingRegion(clip);
SetTextColoursAndFont(grid, attr, dc,
- grid.IsInSelection(row,i));
+ grid.IsInSelection(row,i));
grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
- rect, hAlign, vAlign);
+ rect, hAlign, vAlign);
clip.x += grid.GetColSize(i) - 1;
}
rect = rectCell;
- rect.Inflate(-1);
+ rect.Inflate(-1);
rect.width++;
dc.DestroyClippingRegion();
}
{
if ( m_precision == -1 )
{
- // default width/precision
- m_format = _T("%f");
- }
+ // default width/precision
+ m_format = _T("%f");
+ }
else
{
m_format.Printf(_T("%%.%df"), m_precision);
// init attr cache
m_attrCache.row = -1;
+ m_attrCache.col = -1;
+ m_attrCache.attr = NULL;
// TODO: something better than this ?
//
m_rowBottoms.Alloc( m_numRows );
int rowBottom = 0;
-
+
m_rowHeights.Add( m_defaultRowHeight, m_numRows );
for ( int i = 0; i < m_numRows; i++ )
else
{
m_cornerLabelWin->Refresh(eraseb, NULL);
- m_colLabelWin->Refresh(eraseb, NULL);
+ m_colLabelWin->Refresh(eraseb, NULL);
m_rowLabelWin->Refresh(eraseb, NULL);
m_gridWin->Refresh(eraseb, NULL);
}
wxRect rect;
rect = BlockToDeviceRect( wxGridCellCoords ( topRow, leftCol ),
wxGridCellCoords ( bottomRow, rightCol ) );
- m_gridWin->Refresh( FALSE, &rect );
+ m_gridWin->Refresh( FALSE, &rect );
}
// Now handle changing an existing selection area.
else if ( m_selectingTopLeft != updateTopLeft ||
{
int y;
GetTextExtent(value, &maxWidth, &y,
- NULL, NULL, &attr->GetFont());
+ NULL, NULL, &attr->GetFont());
if (maxWidth < rect.width) maxWidth = rect.width;
}
int client_right = m_gridWin->GetClientSize().GetWidth();
if (rect.x+maxWidth > client_right)
- maxWidth = client_right - rect.x;
+ maxWidth = client_right - rect.x;
- if ((maxWidth > rect.width) && (col < m_numCols) && m_table)
- {
+ if ((maxWidth > rect.width) && (col < m_numCols) && m_table)
+ {
GetCellSize( row, col, &cell_rows, &cell_cols );
- // may have changed earlier
- for (int i = col+cell_cols; i < m_numCols; i++)
- {
+ // may have changed earlier
+ for (int i = col+cell_cols; i < m_numCols; i++)
+ {
int c_rows, c_cols;
GetCellSize( row, i, &c_rows, &c_cols );
- // looks weird going over a multicell
- if (m_table->IsEmptyCell(row,i) &&
- (rect.width < maxWidth) && (c_rows == 1))
- rect.width += GetColWidth(i);
- else
- break;
- }
+ // looks weird going over a multicell
+ if (m_table->IsEmptyCell(row,i) &&
+ (rect.width < maxWidth) && (c_rows == 1))
+ rect.width += GetColWidth(i);
+ else
+ break;
+ }
if (rect.GetRight() > client_right)
- rect.SetRight(client_right-1);
+ rect.SetRight(client_right-1);
}
editor->SetSize( rect );
editor->DecRef();
attr->DecRef();
- }
+ }
}
}
void wxGrid::CacheAttr(int row, int col, wxGridCellAttr *attr) const
{
- wxGrid *self = (wxGrid *)this; // const_cast
+ if ( attr != NULL )
+ {
+ wxGrid *self = (wxGrid *)this; // const_cast
- self->ClearAttrCache();
- self->m_attrCache.row = row;
- self->m_attrCache.col = col;
- self->m_attrCache.attr = attr;
- wxSafeIncRef(attr);
+ self->ClearAttrCache();
+ self->m_attrCache.row = row;
+ self->m_attrCache.col = col;
+ self->m_attrCache.attr = attr;
+ wxSafeIncRef(attr);
+ }
}
bool wxGrid::LookupAttr(int row, int col, wxGridCellAttr **attr) const
// round up the size to a multiple of scroll step - this ensures that we
// won't get the scrollbars if we're sized exactly to this width
- wxSize sizeFit(GetScrollX(size.x) * GRID_SCROLL_LINE_X,
- GetScrollY(size.y) * GRID_SCROLL_LINE_Y);
+ // CalcDimension adds m_extraWidth + 1 etc. to calculate the necessary
+ // scrollbar steps
+ wxSize sizeFit(GetScrollX(size.x + m_extraWidth + 1) * GRID_SCROLL_LINE_X,
+ GetScrollY(size.y + m_extraHeight + 1) * GRID_SCROLL_LINE_Y);
- // distribute the extra space between teh columns/rows to avoid having
+ // distribute the extra space between the columns/rows to avoid having
// extra white space
- wxCoord diff = sizeFit.x - size.x;
- if ( diff )
+
+ // Remove the extra m_extraWidth + 1 added above
+ wxCoord diff = sizeFit.x - size.x + (m_extraWidth + 1);
+ if ( diff && m_numCols )
{
// try to resize the columns uniformly
wxCoord diffPerCol = diff / m_numCols;
}
// same for rows
- diff = sizeFit.y - size.y;
- if ( diff )
+ diff = sizeFit.y - size.y - (m_extraHeight + 1);
+ if ( diff && m_numRows )
{
// try to resize the columns uniformly
wxCoord diffPerRow = diff / m_numRows;