// wxMotif needs a little extra help...
size_t pos = (size_t)( Text()->GetInsertionPoint() );
wxString s( Text()->GetValue() );
- s = s.Left(pos) + "\n" + s.Mid(pos);
+ s = s.Left(pos) + wxT("\n") + s.Mid(pos);
Text()->SetValue(s);
Text()->SetInsertionPoint( pos );
#else
return TRUE;
}
- else
- {
- return FALSE;
- }
+ return FALSE;
}
void wxGridCellFloatEditor::Reset()
else
{
wxString cellval( grid->GetTable()->GetValue(row, col) );
- m_startValue = !( !cellval || (cellval == "0") );
+ m_startValue = !( !cellval || (cellval == wxT("0")) );
}
CBox()->SetValue(m_startValue);
CBox()->SetFocus();
else
{
wxString cellval( grid.GetTable()->GetValue(row, col) );
- value = !( !cellval || (cellval == "0") );
+ value = !( !cellval || (cellval == wxT("0")) );
}
if ( value )
SetBackgroundColour(mergefrom->GetBackgroundColour());
if ( !HasFont() && mergefrom->HasFont() )
SetFont(mergefrom->GetFont());
- if ( !!HasAlignment() && mergefrom->HasAlignment() ){
+ if ( !HasAlignment() && mergefrom->HasAlignment() ){
int hAlign, vAlign;
mergefrom->GetAlignment( &hAlign, &vAlign);
SetAlignment(hAlign, vAlign);
if ( pos >= curNumRows )
{
- wxString errmsg;
- errmsg.Printf(wxT("Called wxGridStringTable::DeleteRows(pos=%d, N=%d)\nPos value is invalid for present table with %d rows"),
- pos, numRows, curNumRows );
- wxFAIL_MSG( errmsg );
+ wxFAIL_MSG( wxString::Format
+ (
+ wxT("Called wxGridStringTable::DeleteRows(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu rows"),
+ (unsigned long)pos,
+ (unsigned long)numRows,
+ (unsigned long)curNumRows
+ ) );
+
return FALSE;
}
if ( pos >= curNumCols )
{
- wxString errmsg;
- errmsg.Printf( wxT("Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\nPos value is invalid for present table with %d cols"),
- pos, numCols, curNumCols );
- wxFAIL_MSG( errmsg );
+ wxFAIL_MSG( wxString::Format
+ (
+ wxT("Called wxGridStringTable::DeleteCols(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu cols"),
+ (unsigned long)pos,
+ (unsigned long)numCols,
+ (unsigned long)curNumCols
+ ) );
return FALSE;
}
wxGridRowLabelWindow *rowLblWin,
wxGridColLabelWindow *colLblWin,
wxWindowID id, const wxPoint &pos, const wxSize &size )
- : wxWindow( parent, id, pos, size, wxWANTS_CHARS, "grid window" )
+ : wxWindow( parent, id, pos, size, wxWANTS_CHARS, wxT("grid window") )
{
m_owner = parent;
m_rowLabelWin = rowLblWin;
m_selection->SetSelectionMode( selmode );
}
+wxGrid::wxGridSelectionModes wxGrid::GetSelectionMode() const
+{
+ wxCHECK_MSG( m_created, wxGrid::wxGridSelectCells,
+ wxT("Called wxGrid::GetSelectionMode() before calling CreateGrid()") );
+
+ return m_selection->GetSelectionMode();
+}
+
bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership,
wxGrid::wxGridSelectionModes selmode )
{
int i;
bool result = FALSE;
+ // Clear the attribute cache as the attribute might refer to a different
+ // cell than stored in the cache after adding/removing rows/columns.
+ ClearAttrCache();
+ // By the same reasoning, the editor should be dismissed if columns are
+ // added or removed. And for consistency, it should IMHO always be
+ // removed, not only if the cell "underneath" it actually changes.
+ // For now, I intentionally do not save the editor's content as the
+ // cell it might want to save that stuff to might no longer exist.
+ HideCellEditControl();
#if 0
// if we were using the default widths/heights so far, we must change them
// now
wxPaintDC dc(this); // needed to prevent zillions of paint events on MSW
}
-void wxGrid::Refresh(bool eraseb, wxRect* rect)
+void wxGrid::Refresh(bool eraseb, const wxRect* rect)
{
// Don't do anything if between Begin/EndBatch...
// EndBatch() will do all this on the last nested one anyway.
if (! GetBatchCount())
{
+ // Refresh to get correct scrolled position:
wxScrolledWindow::Refresh(eraseb,rect);
- int off_x=0 ,off_y=0;
- wxRect * anotherrect = NULL ;
-
if (rect)
{
+ int rect_x, rect_y, rectWidth, rectHeight;
+ int width_label, width_cell, height_label, height_cell;
+ int x, y;
+
//Copy rectangle can get scroll offsets..
- anotherrect = new wxRect(*rect);
- CalcScrolledPosition( 0, 0, &off_x, &off_y );
- }
- //Corner label Doesn't move from the origin.
- m_cornerLabelWin->Refresh(eraseb,rect);
+ rect_x = rect->GetX();
+ rect_y = rect->GetY();
+ rectWidth = rect->GetWidth();
+ rectHeight = rect->GetHeight();
- //Move Rect down for row labels...
- if (rect)
- rect->Offset(0,off_y);
- m_rowLabelWin->Refresh(eraseb,rect);
+ width_label = m_rowLabelWidth - rect_x;
+ if (width_label > rectWidth) width_label = rectWidth;
- //Move rect copy along for col labels...
- if (anotherrect)
- anotherrect->Offset(off_x,0);
- m_colLabelWin->Refresh(eraseb,anotherrect);
+ height_label = m_colLabelHeight - rect_y;
+ if (height_label > rectHeight) height_label = rectHeight;
- //Move main rect along (so it's down and across!)
- // for cell window.
- if (rect)
- rect->Offset(off_x,0);
- m_gridWin->Refresh(eraseb,rect);
+ if (rect_x > m_rowLabelWidth)
+ {
+ x = rect_x - m_rowLabelWidth;
+ width_cell = rectWidth;
+ }
+ else
+ {
+ x = 0;
+ width_cell = rectWidth - (m_rowLabelWidth - rect_x);
+ }
+
+ if (rect_y > m_colLabelHeight)
+ {
+ y = rect_y - m_colLabelHeight;
+ height_cell = rectHeight;
+ }
+ else
+ {
+ y = 0;
+ height_cell = rectHeight - (m_colLabelHeight - rect_y);
+ }
+
+ // Paint corner label part intersecting rect.
+ if ( width_label > 0 && height_label > 0 )
+ {
+ wxRect anotherrect(rect_x, rect_y, width_label, height_label);
+ m_cornerLabelWin->Refresh(eraseb, &anotherrect);
+ }
+
+ // Paint col labels part intersecting rect.
+ if ( width_cell > 0 && height_label > 0 )
+ {
+ wxRect anotherrect(x, rect_y, width_cell, height_label);
+ m_colLabelWin->Refresh(eraseb, &anotherrect);
+ }
+
+ // Paint row labels part intersecting rect.
+ if ( width_label > 0 && height_cell > 0 )
+ {
+ wxRect anotherrect(rect_x, y, width_label, height_cell);
+ m_rowLabelWin->Refresh(eraseb, &anotherrect);
+ }
+
+ // Paint cell area part intersecting rect.
+ if ( width_cell > 0 && height_cell > 0 )
+ {
+ wxRect anotherrect(x, y, width_cell, height_cell);
+ m_gridWin->Refresh(eraseb, &anotherrect);
+ }
+ }
+ else
+ {
+ m_cornerLabelWin->Refresh(eraseb, NULL);
+ m_colLabelWin->Refresh(eraseb, NULL);
+ m_rowLabelWin->Refresh(eraseb, NULL);
+ m_gridWin->Refresh(eraseb, NULL);
+ }
}
}
if ( IsVisible( m_currentCellCoords, FALSE ) )
{
wxRect r;
- r = BlockToDeviceRect(m_currentCellCoords, coords);
+ r = BlockToDeviceRect(m_currentCellCoords, m_currentCellCoords);
if ( !m_gridLinesEnabled )
{
r.x--;
r.height++;
}
- wxGridCellCoordsArray cells = CalcCellsExposed( r );
+ wxGridCellCoordsArray cells = CalcCellsExposed( r );
// Otherwise refresh redraws the highlight!
m_currentCellCoords = coords;
updateTopLeft = wxGridCellCoords( topRow, leftCol );
updateBottomRight = wxGridCellCoords( bottomRow, rightCol );
- if ( m_selectingTopLeft != updateTopLeft ||
- m_selectingBottomRight != updateBottomRight )
+ // First the case that we selected a completely new area
+ if ( m_selectingTopLeft == wxGridNoCellCoords ||
+ m_selectingBottomRight == wxGridNoCellCoords )
+ {
+ wxRect rect;
+ rect = BlockToDeviceRect( wxGridCellCoords ( topRow, leftCol ),
+ wxGridCellCoords ( bottomRow, rightCol ) );
+ m_gridWin->Refresh( FALSE, &rect );
+ }
+ // Now handle changing an existing selection area.
+ else if ( m_selectingTopLeft != updateTopLeft ||
+ m_selectingBottomRight != updateBottomRight )
{
// Compute two optimal update rectangles:
// Either one rectangle is a real subset of the
if ( oldLeft < leftCol )
{
+ // Refresh the newly selected or deselected
+ // area to the left of the old or new selection.
need_refresh[0] = TRUE;
rect[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
oldLeft ),
if ( oldTop < topRow )
{
+ // Refresh the newly selected or deselected
+ // area above the old or new selection.
need_refresh[1] = TRUE;
rect[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
leftCol ),
if ( oldRight > rightCol )
{
+ // Refresh the newly selected or deselected
+ // area to the right of the old or new selection.
need_refresh[2] = TRUE;
rect[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
rightCol + 1 ),
if ( oldBottom > bottomRow )
{
+ // Refresh the newly selected or deselected
+ // area below the old or new selection.
need_refresh[3] = TRUE;
rect[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow + 1,
leftCol ),
rightCol ) );
}
-
- // Change Selection
- m_selectingTopLeft = updateTopLeft;
- m_selectingBottomRight = updateBottomRight;
-
// various Refresh() calls
for (i = 0; i < 4; i++ )
if ( need_refresh[i] && rect[i] != wxGridNoCellRect )
m_gridWin->Refresh( FALSE, &(rect[i]) );
}
-
- // never generate an event as it will be generated from
- // wxGridSelection::SelectBlock!
- // (old comment from when this was the body of SelectBlock)
+ // Change Selection
+ m_selectingTopLeft = updateTopLeft;
+ m_selectingBottomRight = updateBottomRight;
}
//
bool wxGrid::GetModelValues()
{
+ // Hide the editor, so it won't hide a changed value.
+ HideCellEditControl();
+
if ( m_table )
{
// all we need to do is repaint the grid
{
int row, col;
+ // Disable the editor, so it won't hide a changed value.
+ // Do we also want to save the current value of the editor first?
+ // I think so ...
+ DisableCellEditControl();
+
if ( m_table )
{
for ( row = 0; row < m_numRows; row++ )
if ( cell == cells[j] )
{
marked = TRUE;
- break;;
+ break;
}
}
if (!marked)
i_min = 0;
if (BorderArray.IsEmpty())
{
- return i_max;
+ return maxOnOverflow ? (int)i_max : -1;
}
if ( i_max >= BorderArray.GetCount())
// wxNoCellCoords, as this will confuse memory management.
if ( row >= 0 )
{
- if ( !LookupAttr(row, col, &attr) )
- {
- attr = m_table ? m_table->GetAttr(row, col , wxGridCellAttr::Any)
- : (wxGridCellAttr *)NULL;
- CacheAttr(row, col, attr);
- }
+ if ( !LookupAttr(row, col, &attr) )
+ {
+ attr = m_table ? m_table->GetAttr(row, col , wxGridCellAttr::Any)
+ : (wxGridCellAttr *)NULL;
+ CacheAttr(row, col, attr);
+ }
}
if (attr)
{
// don't set sizes, only calculate them
wxGrid *self = (wxGrid *)this; // const_cast
- return wxSize(self->SetOrCalcColumnSizes(TRUE),
- self->SetOrCalcRowSizes(TRUE));
+ int width, height;
+ width = self->SetOrCalcColumnSizes(TRUE);
+ height = self->SetOrCalcRowSizes(TRUE);
+
+ int maxwidth, maxheight;
+ wxDisplaySize( & maxwidth, & maxheight );
+
+ if ( width > maxwidth ) width = maxwidth;
+ if ( height > maxheight ) height = maxheight;
+
+ return wxSize( width, height );
}
void wxGrid::Fit()
m_selectingBottomRight != wxGridNoCellCoords) ) );
}
-bool wxGrid::IsInSelection( int row, int col )
+bool wxGrid::IsInSelection( int row, int col ) const
{
return ( m_selection && (m_selection->IsInSelection( row, col ) ||
( row >= m_selectingTopLeft.GetRow() &&
col <= m_selectingBottomRight.GetCol() )) );
}
+wxGridCellCoordsArray wxGrid::GetSelectedCells() const
+{
+ if (!m_selection) { wxGridCellCoordsArray a; return a; }
+ return m_selection->m_cellSelection;
+}
+wxGridCellCoordsArray wxGrid::GetSelectionBlockTopLeft() const
+{
+ if (!m_selection) { wxGridCellCoordsArray a; return a; }
+ return m_selection->m_blockSelectionTopLeft;
+}
+wxGridCellCoordsArray wxGrid::GetSelectionBlockBottomRight() const
+{
+ if (!m_selection) { wxGridCellCoordsArray a; return a; }
+ return m_selection->m_blockSelectionTopLeft;
+}
+wxArrayInt wxGrid::GetSelectedRows() const
+{
+ if (!m_selection) { wxArrayInt a; return a; }
+ return m_selection->m_rowSelection;
+}
+wxArrayInt wxGrid::GetSelectedCols() const
+{
+ if (!m_selection) { wxArrayInt a; return a; }
+ return m_selection->m_colSelection;
+}
+
+
void wxGrid::ClearSelection()
{
m_selectingTopLeft = wxGridNoCellCoords;
int rightCol = bottomRight.GetCol();
int bottomRow = bottomRight.GetRow();
+ if (left > right)
+ {
+ i = left;
+ left = right;
+ right = i;
+ i = leftCol;
+ leftCol=rightCol;
+ rightCol = i;
+ }
+
+ if (top > bottom)
+ {
+ i = top;
+ top = bottom;
+ bottom = i;
+ i = topRow;
+ topRow = bottomRow;
+ bottomRow = i;
+ }
+
+
for ( j = topRow; j <= bottomRow; j++ )
{
for ( i = leftCol; i <= rightCol; i++ )
if (cellRect.y + cellRect.height > bottom)
bottom = cellRect.y + cellRect.height;
}
+ else i = rightCol; // jump over inner cells.
}
}