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 hAlign, vAlign;
attr.GetAlignment(&hAlign, &vAlign);
+ int overflowCols = 0;
+
if (attr.GetOverflow())
{
int cols = grid.GetNumberCols();
int best_width = GetBestSize(grid,attr,dc,row,col).GetWidth();
- int overflowCols = 0;
int cell_rows, cell_cols;
attr.GetSize( &cell_rows, &cell_cols ); // shouldn't get here if <=0
if ((best_width > rectCell.width) && (col < cols) && grid.GetTable())
int i, c_cols, c_rows;
for (i = col+cell_cols; i < cols; i++)
{
- // check w/ anchor cell for multicell block
- grid.GetCellSize(row, i, &c_rows, &c_cols);
- if (c_rows > 0) c_rows = 0;
- if (grid.GetTable()->IsEmptyCell(row+c_rows, i))
+ bool is_empty = TRUE;
+ for (int j=row; j<row+cell_rows; j++)
{
- rect.width += grid.GetColSize(i);
- if (rect.width >= best_width) break;
+ // check w/ anchor cell for multicell block
+ grid.GetCellSize(j, i, &c_rows, &c_cols);
+ if (c_rows > 0) c_rows = 0;
+ if (!grid.GetTable()->IsEmptyCell(j+c_rows, i))
+ {
+ is_empty = FALSE;
+ break;
+ }
}
+ if (is_empty)
+ rect.width += grid.GetColSize(i);
else
{
i--;
break;
}
+ if (rect.width >= best_width) break;
}
- overflowCols = i - col - cell_cols;
+ overflowCols = i - col - cell_cols + 1;
if (overflowCols >= cols) overflowCols = cols - 1;
- }
+ }
if (overflowCols > 0) // redraw overflow cells w/ proper hilight
{
- wxRect clip = rect;
-
+ hAlign = wxALIGN_LEFT; // if oveflowed then it's left aligned
+ 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;
-
for (int i = col+cell_cols; i <= col_end; i++)
{
- clip.x += grid.GetColSize(i-1) - 1;
clip.width = grid.GetColSize(i) - 1;
dc.DestroyClippingRegion();
dc.SetClippingRegion(clip);
-
- SetTextColoursAndFont(grid, attr, dc, grid.IsInSelection(row,i));
+
+ SetTextColoursAndFont(grid, attr, dc,
+ 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 = rectCell;
rect.Inflate(-1);
rect.width++;
- dc.DestroyClippingRegion(); // DrawTextRectangle sets it again
+ dc.DestroyClippingRegion();
}
- }
+ }
// now we only have to draw the text
SetTextColoursAndFont(grid, attr, dc, isSelected);
+
grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
rect, hAlign, vAlign);
}
{
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 ||
editor->Show( TRUE, attr );
// resize editor to overflow into righthand cells if allowed
- wxCoord maxRight = rect.width;
+ int maxWidth = rect.width;
wxString value = GetCellValue(row, col);
if ( (value != wxEmptyString) && (attr->GetOverflow()) )
{
- wxClientDC dc(m_gridWin);
- wxCoord y = 0;
- dc.SetFont(attr->GetFont());
- dc.GetTextExtent(value, &maxRight, &y);
- if (maxRight > m_gridWin->GetClientSize().GetWidth())
- maxRight = m_gridWin->GetClientSize().GetWidth();
-
- int cell_rows, cell_cols;
- attr->GetSize( &cell_rows, &cell_cols );
+ int y;
+ GetTextExtent(value, &maxWidth, &y,
+ 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;
- if ((maxRight > 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++)
{
- int i;
- for (i = col+cell_cols; i < m_numCols; i++)
- {
- int c_rows, c_cols;
- // looks weird going over a multicell
- GetCellSize( row, i, &c_rows, &c_cols );
- if (m_table->IsEmptyCell(row,i) && (rect.GetRight() < maxRight) && (c_rows == 1))
- rect.width += GetColWidth(i);
- else
- break;
- }
- if (rect.GetRight() > maxRight) rect.SetRight(maxRight-1);
+ 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;
}
+ if (rect.GetRight() > client_right)
+ 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;