- return value == ms_stringValues[true];
-}
-
-#endif // wxUSE_CHECKBOX
-
-#if wxUSE_COMBOBOX
-
-// ----------------------------------------------------------------------------
-// wxGridCellChoiceEditor
-// ----------------------------------------------------------------------------
-
-wxGridCellChoiceEditor::wxGridCellChoiceEditor(const wxArrayString& choices,
- bool allowOthers)
- : m_choices(choices),
- m_allowOthers(allowOthers) { }
-
-wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count,
- const wxString choices[],
- bool allowOthers)
- : m_allowOthers(allowOthers)
-{
- if ( count )
- {
- m_choices.Alloc(count);
- for ( size_t n = 0; n < count; n++ )
- {
- m_choices.Add(choices[n]);
- }
- }
-}
-
-wxGridCellEditor *wxGridCellChoiceEditor::Clone() const
-{
- wxGridCellChoiceEditor *editor = new wxGridCellChoiceEditor;
- editor->m_allowOthers = m_allowOthers;
- editor->m_choices = m_choices;
-
- return editor;
-}
-
-void wxGridCellChoiceEditor::Create(wxWindow* parent,
- wxWindowID id,
- wxEvtHandler* evtHandler)
-{
- m_control = new wxComboBox(parent, id, wxEmptyString,
- wxDefaultPosition, wxDefaultSize,
- m_choices,
- m_allowOthers ? 0 : wxCB_READONLY);
-
- wxGridCellEditor::Create(parent, id, evtHandler);
-}
-
-void wxGridCellChoiceEditor::PaintBackground(const wxRect& rectCell,
- wxGridCellAttr * attr)
-{
- // as we fill the entire client area, don't do anything here to minimize
- // flicker
-
- // TODO: It doesn't actually fill the client area since the height of a
- // combo always defaults to the standard. Until someone has time to
- // figure out the right rectangle to paint, just do it the normal way.
- wxGridCellEditor::PaintBackground(rectCell, attr);
-}
-
-void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
-{
- wxASSERT_MSG(m_control,
- wxT("The wxGridCellEditor must be created first!"));
-
- wxGridCellEditorEvtHandler* evtHandler = NULL;
- if (m_control)
- evtHandler = wxDynamicCast(m_control->GetEventHandler(), wxGridCellEditorEvtHandler);
-
- // Don't immediately end if we get a kill focus event within BeginEdit
- if (evtHandler)
- evtHandler->SetInSetFocus(true);
-
- m_startValue = grid->GetTable()->GetValue(row, col);
-
- if (m_allowOthers)
- {
- Combo()->SetValue(m_startValue);
- }
- else
- {
- // find the right position, or default to the first if not found
- int pos = Combo()->FindString(m_startValue);
- if (pos == wxNOT_FOUND)
- pos = 0;
- Combo()->SetSelection(pos);
- }
-
- Combo()->SetInsertionPointEnd();
- 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,
- wxGrid* grid)
-{
- wxString value = Combo()->GetValue();
- if ( value == m_startValue )
- return false;
-
- grid->GetTable()->SetValue(row, col, value);
-
- return true;
-}
-
-void wxGridCellChoiceEditor::Reset()
-{
- Combo()->SetValue(m_startValue);
- Combo()->SetInsertionPointEnd();
-}
-
-void wxGridCellChoiceEditor::SetParameters(const wxString& params)
-{
- if ( !params )
- {
- // what can we do?
- return;
- }
-
- m_choices.Empty();
-
- wxStringTokenizer tk(params, _T(','));
- while ( tk.HasMoreTokens() )
- {
- m_choices.Add(tk.GetNextToken());
- }
-}
-
-// return the value in the text control
-wxString wxGridCellChoiceEditor::GetValue() const
-{
- return Combo()->GetValue();
-}
-
-#endif // wxUSE_COMBOBOX
-
-// ----------------------------------------------------------------------------
-// wxGridCellEditorEvtHandler
-// ----------------------------------------------------------------------------
-
-void wxGridCellEditorEvtHandler::OnKillFocus(wxFocusEvent& event)
-{
- // Don't disable the cell if we're just starting to edit it
- if (m_inSetFocus)
- return;
-
- // accept changes
- m_grid->DisableCellEditControl();
-
- event.Skip();
-}
-
-void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event)
-{
- switch ( event.GetKeyCode() )
- {
- case WXK_ESCAPE:
- m_editor->Reset();
- m_grid->DisableCellEditControl();
- break;
-
- case WXK_TAB:
- m_grid->GetEventHandler()->ProcessEvent( event );
- break;
-
- case WXK_RETURN:
- case WXK_NUMPAD_ENTER:
- if (!m_grid->GetEventHandler()->ProcessEvent(event))
- m_editor->HandleReturn(event);
- break;
-
- default:
- event.Skip();
- break;
- }
-}
-
-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_TAB:
- case WXK_RETURN:
- 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();
- break;
- }
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellWorker is an (almost) empty common base class for
-// wxGridCellRenderer and wxGridCellEditor managing ref counting
-// ----------------------------------------------------------------------------
-
-void wxGridCellWorker::SetParameters(const wxString& WXUNUSED(params))
-{
- // nothing to do
-}
-
-wxGridCellWorker::~wxGridCellWorker()
-{
-}
-
-// ============================================================================
-// renderer classes
-// ============================================================================
-
-// ----------------------------------------------------------------------------
-// wxGridCellRenderer
-// ----------------------------------------------------------------------------
-
-void wxGridCellRenderer::Draw(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- const wxRect& rect,
- int WXUNUSED(row), int WXUNUSED(col),
- bool isSelected)
-{
- dc.SetBackgroundMode( wxSOLID );
-
- // grey out fields if the grid is disabled
- if ( grid.IsEnabled() )
- {
- if ( isSelected )
- {
- dc.SetBrush( wxBrush(grid.GetSelectionBackground(), wxSOLID) );
- }
- else
- {
- dc.SetBrush( wxBrush(attr.GetBackgroundColour(), wxSOLID) );
- }
- }
- else
- {
- dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE), wxSOLID));
- }
-
- dc.SetPen( *wxTRANSPARENT_PEN );
- dc.DrawRectangle(rect);
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellStringRenderer
-// ----------------------------------------------------------------------------
-
-void wxGridCellStringRenderer::SetTextColoursAndFont(const wxGrid& grid,
- const wxGridCellAttr& attr,
- wxDC& dc,
- bool isSelected)
-{
- dc.SetBackgroundMode( wxTRANSPARENT );
-
- // TODO some special colours for attr.IsReadOnly() case?
-
- // different coloured text when the grid is disabled
- if ( grid.IsEnabled() )
- {
- if ( isSelected )
- {
- dc.SetTextBackground( grid.GetSelectionBackground() );
- dc.SetTextForeground( grid.GetSelectionForeground() );
- }
- else
- {
- dc.SetTextBackground( attr.GetBackgroundColour() );
- dc.SetTextForeground( attr.GetTextColour() );
- }
- }
- else
- {
- dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
- dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
- }
-
- dc.SetFont( attr.GetFont() );
-}
-
-wxSize wxGridCellStringRenderer::DoGetBestSize(const wxGridCellAttr& attr,
- wxDC& dc,
- const wxString& text)
-{
- wxCoord x = 0, y = 0, max_x = 0;
- dc.SetFont(attr.GetFont());
- wxStringTokenizer tk(text, _T('\n'));
- while ( tk.HasMoreTokens() )
- {
- dc.GetTextExtent(tk.GetNextToken(), &x, &y);
- max_x = wxMax(max_x, x);
- }
-
- y *= 1 + text.Freq(wxT('\n')); // multiply by the number of lines.
-
- return wxSize(max_x, y);
-}
-
-wxSize wxGridCellStringRenderer::GetBestSize(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- int row, int col)
-{
- return DoGetBestSize(attr, dc, grid.GetCellValue(row, col));
-}
-
-void wxGridCellStringRenderer::Draw(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- const wxRect& rectCell,
- int row, int col,
- bool isSelected)
-{
- wxRect rect = rectCell;
- rect.Inflate(-1);
-
- // erase only this cells background, overflow cells should have been erased
- wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
-
- 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 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++)
- {
- bool is_empty = true;
- for (int j=row; j < row + cell_rows; j++)
- {
- // 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 + 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;
- 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.width = grid.GetColSize(i) - 1;
- dc.DestroyClippingRegion();
- dc.SetClippingRegion(clip);
-
- SetTextColoursAndFont(grid, attr, dc,
- grid.IsInSelection(row,i));
-
- grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
- rect, hAlign, vAlign);
- clip.x += grid.GetColSize(i) - 1;
- }
-
- rect = rectCell;
- rect.Inflate(-1);
- rect.width++;
- 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);
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellNumberRenderer
-// ----------------------------------------------------------------------------
-
-wxString wxGridCellNumberRenderer::GetString(const wxGrid& grid, int row, int col)
-{
- wxGridTableBase *table = grid.GetTable();
- wxString text;
- if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
- {
- text.Printf(_T("%ld"), table->GetValueAsLong(row, col));
- }
- else
- {
- text = table->GetValue(row, col);
- }
-
- return text;
-}
-
-void wxGridCellNumberRenderer::Draw(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- const wxRect& rectCell,
- int row, int col,
- bool isSelected)
-{
- wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
-
- SetTextColoursAndFont(grid, attr, dc, isSelected);
-
- // draw the text right aligned by default
- int hAlign, vAlign;
- attr.GetAlignment(&hAlign, &vAlign);
- hAlign = wxALIGN_RIGHT;
-
- wxRect rect = rectCell;
- rect.Inflate(-1);
-
- grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign);
-}
-
-wxSize wxGridCellNumberRenderer::GetBestSize(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- int row, int col)
-{
- return DoGetBestSize(attr, dc, GetString(grid, row, col));
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellFloatRenderer
-// ----------------------------------------------------------------------------
-
-wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width, int precision)
-{
- SetWidth(width);
- SetPrecision(precision);
-}
-
-wxGridCellRenderer *wxGridCellFloatRenderer::Clone() const
-{
- wxGridCellFloatRenderer *renderer = new wxGridCellFloatRenderer;
- renderer->m_width = m_width;
- renderer->m_precision = m_precision;
- renderer->m_format = m_format;
-
- return renderer;
-}
-
-wxString wxGridCellFloatRenderer::GetString(const wxGrid& grid, int row, int col)
-{
- wxGridTableBase *table = grid.GetTable();
-
- bool hasDouble;
- double val;
- wxString text;
- if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) )
- {
- val = table->GetValueAsDouble(row, col);
- hasDouble = true;
- }
- else
- {
- text = table->GetValue(row, col);
- hasDouble = text.ToDouble(&val);
- }
-
- if ( hasDouble )
- {
- if ( !m_format )
- {
- if ( m_width == -1 )
- {
- if ( m_precision == -1 )
- {
- // default width/precision
- m_format = _T("%f");
- }
- else
- {
- m_format.Printf(_T("%%.%df"), m_precision);
- }
- }
- else if ( m_precision == -1 )
- {
- // default precision
- m_format.Printf(_T("%%%d.f"), m_width);
- }
- else
- {
- m_format.Printf(_T("%%%d.%df"), m_width, m_precision);
- }
- }
-
- text.Printf(m_format, val);
-
- }
- //else: text already contains the string
-
- return text;
-}
-
-void wxGridCellFloatRenderer::Draw(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- const wxRect& rectCell,
- int row, int col,
- bool isSelected)
-{
- wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
-
- SetTextColoursAndFont(grid, attr, dc, isSelected);
-
- // draw the text right aligned by default
- int hAlign, vAlign;
- attr.GetAlignment(&hAlign, &vAlign);
- hAlign = wxALIGN_RIGHT;
-
- wxRect rect = rectCell;
- rect.Inflate(-1);
-
- grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign);
-}
-
-wxSize wxGridCellFloatRenderer::GetBestSize(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- int row, int col)
-{
- return DoGetBestSize(attr, dc, GetString(grid, row, col));
-}
-
-void wxGridCellFloatRenderer::SetParameters(const wxString& params)
-{
- if ( !params )
- {
- // reset to defaults
- SetWidth(-1);
- SetPrecision(-1);
- }
- else
- {
- wxString tmp = params.BeforeFirst(_T(','));
- if ( !tmp.empty() )
- {
- long width;
- if ( tmp.ToLong(&width) )
- {
- SetWidth((int)width);
- }
- else
- {
- wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params.c_str());
- }
- }
-
- tmp = params.AfterFirst(_T(','));
- if ( !tmp.empty() )
- {
- long precision;
- if ( tmp.ToLong(&precision) )
- {
- SetPrecision((int)precision);
- }
- else
- {
- wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params.c_str());
- }
- }
- }
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellBoolRenderer
-// ----------------------------------------------------------------------------
-
-wxSize wxGridCellBoolRenderer::ms_sizeCheckMark;
-
-// FIXME these checkbox size calculations are really ugly...
-
-// between checkmark and box
-static const wxCoord wxGRID_CHECKMARK_MARGIN = 2;
-
-wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid,
- wxGridCellAttr& WXUNUSED(attr),
- wxDC& WXUNUSED(dc),
- int WXUNUSED(row),
- int WXUNUSED(col))
-{
- // compute it only once (no locks for MT safeness in GUI thread...)
- if ( !ms_sizeCheckMark.x )
- {
- // get checkbox size
- wxCheckBox *checkbox = new wxCheckBox(&grid, wxID_ANY, wxEmptyString);
- wxSize size = checkbox->GetBestSize();
- wxCoord checkSize = size.y + 2 * wxGRID_CHECKMARK_MARGIN;
-
- // FIXME wxGTK::wxCheckBox::GetBestSize() gives "wrong" result
-#if defined(__WXGTK__) || defined(__WXMOTIF__)
- checkSize -= size.y / 2;
-#endif
-
- delete checkbox;
-
- ms_sizeCheckMark.x = ms_sizeCheckMark.y = checkSize;
- }
-
- return ms_sizeCheckMark;
-}
-
-void wxGridCellBoolRenderer::Draw(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- const wxRect& rect,
- int row, int col,
- bool isSelected)
-{
- wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
-
- // draw a check mark in the centre (ignoring alignment - TODO)
- wxSize size = GetBestSize(grid, attr, dc, row, col);
-
- // don't draw outside the cell
- wxCoord minSize = wxMin(rect.width, rect.height);
- if ( size.x >= minSize || size.y >= minSize )
- {
- // and even leave (at least) 1 pixel margin
- size.x = size.y = minSize - 2;
- }
-
- // draw a border around checkmark
- int vAlign, hAlign;
- attr.GetAlignment(&hAlign, &vAlign);
-
- wxRect rectBorder;
- if (hAlign == wxALIGN_CENTRE)
- {
- rectBorder.x = rect.x + rect.width / 2 - size.x / 2;
- rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
- rectBorder.width = size.x;
- rectBorder.height = size.y;
- }
- else if (hAlign == wxALIGN_LEFT)
- {
- rectBorder.x = rect.x + 2;
- rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
- rectBorder.width = size.x;
- rectBorder.height = size.y;
- }
- else if (hAlign == wxALIGN_RIGHT)
- {
- rectBorder.x = rect.x + rect.width - size.x - 2;
- rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
- rectBorder.width = size.x;
- rectBorder.height = size.y;
- }
-
- bool value;
- if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) )
- {
- value = grid.GetTable()->GetValueAsBool(row, col);
- }
- else
- {
- wxString cellval( grid.GetTable()->GetValue(row, col) );
- value = wxGridCellBoolEditor::IsTrueValue(cellval);
- }
-
- if ( value )
- {
- wxRect rectMark = rectBorder;
-
-#ifdef __WXMSW__
- // MSW DrawCheckMark() is weird (and should probably be changed...)
- rectMark.Inflate(-wxGRID_CHECKMARK_MARGIN / 2);
- rectMark.x++;
- rectMark.y++;
-#else
- rectMark.Inflate(-wxGRID_CHECKMARK_MARGIN);
-#endif
-
- dc.SetTextForeground(attr.GetTextColour());
- dc.DrawCheckMark(rectMark);
- }
-
- dc.SetBrush(*wxTRANSPARENT_BRUSH);
- dc.SetPen(wxPen(attr.GetTextColour(), 1, wxSOLID));
- dc.DrawRectangle(rectBorder);
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellAttr
-// ----------------------------------------------------------------------------
-
-void wxGridCellAttr::Init(wxGridCellAttr *attrDefault)
-{
- m_nRef = 1;
-
- m_isReadOnly = Unset;
-
- m_renderer = NULL;
- m_editor = NULL;
-
- m_attrkind = wxGridCellAttr::Cell;
-
- m_sizeRows = m_sizeCols = 1;
- m_overflow = UnsetOverflow;
-
- SetDefAttr(attrDefault);
-}
-
-wxGridCellAttr *wxGridCellAttr::Clone() const
-{
- wxGridCellAttr *attr = new wxGridCellAttr(m_defGridAttr);
-
- if ( HasTextColour() )
- attr->SetTextColour(GetTextColour());
- if ( HasBackgroundColour() )
- attr->SetBackgroundColour(GetBackgroundColour());
- if ( HasFont() )
- attr->SetFont(GetFont());
- if ( HasAlignment() )
- attr->SetAlignment(m_hAlign, m_vAlign);
-
- attr->SetSize( m_sizeRows, m_sizeCols );
-
- if ( m_renderer )
- {
- attr->SetRenderer(m_renderer);
- m_renderer->IncRef();
- }
- if ( m_editor )
- {
- attr->SetEditor(m_editor);
- m_editor->IncRef();
- }
-
- if ( IsReadOnly() )
- attr->SetReadOnly();
-
- attr->SetOverflow( m_overflow == Overflow );
- attr->SetKind( m_attrkind );
-
- return attr;
-}
-
-void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom)
-{
- if ( !HasTextColour() && mergefrom->HasTextColour() )
- SetTextColour(mergefrom->GetTextColour());
- if ( !HasBackgroundColour() && mergefrom->HasBackgroundColour() )
- SetBackgroundColour(mergefrom->GetBackgroundColour());
- if ( !HasFont() && mergefrom->HasFont() )
- SetFont(mergefrom->GetFont());
- if ( !HasAlignment() && mergefrom->HasAlignment() )
- {
- int hAlign, vAlign;
- mergefrom->GetAlignment( &hAlign, &vAlign);
- SetAlignment(hAlign, vAlign);
- }
- if ( !HasSize() && mergefrom->HasSize() )
- mergefrom->GetSize( &m_sizeRows, &m_sizeCols );
-
- // Directly access member functions as GetRender/Editor don't just return
- // m_renderer/m_editor
- //
- // Maybe add support for merge of Render and Editor?
- if (!HasRenderer() && mergefrom->HasRenderer() )
- {
- m_renderer = mergefrom->m_renderer;
- m_renderer->IncRef();
- }
- if ( !HasEditor() && mergefrom->HasEditor() )
- {
- m_editor = mergefrom->m_editor;
- m_editor->IncRef();
- }
- if ( !HasReadWriteMode() && mergefrom->HasReadWriteMode() )
- SetReadOnly(mergefrom->IsReadOnly());
-
- if (!HasOverflowMode() && mergefrom->HasOverflowMode() )
- SetOverflow(mergefrom->GetOverflow());
-
- SetDefAttr(mergefrom->m_defGridAttr);
-}
-
-void wxGridCellAttr::SetSize(int num_rows, int num_cols)
-{
- // The size of a cell is normally 1,1
-
- // If this cell is larger (2,2) then this is the top left cell
- // the other cells that will be covered (lower right cells) must be
- // set to negative or zero values such that
- // row + num_rows of the covered cell points to the larger cell (this cell)
- // same goes for the col + num_cols.
-
- // Size of 0,0 is NOT valid, neither is <=0 and any positive value
-
- 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"));
-
- m_sizeRows = num_rows;
- m_sizeCols = num_cols;
-}
-
-const wxColour& wxGridCellAttr::GetTextColour() const
-{
- if (HasTextColour())
- {
- return m_colText;
- }
- else if (m_defGridAttr && m_defGridAttr != this)
- {
- return m_defGridAttr->GetTextColour();
- }
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- return wxNullColour;
- }
-}
-
-const wxColour& wxGridCellAttr::GetBackgroundColour() const
-{
- if (HasBackgroundColour())
- {
- return m_colBack;
- }
- else if (m_defGridAttr && m_defGridAttr != this)
- {
- return m_defGridAttr->GetBackgroundColour();
- }
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- return wxNullColour;
- }
-}
-
-const wxFont& wxGridCellAttr::GetFont() const
-{
- if (HasFont())
- {
- return m_font;
- }
- else if (m_defGridAttr && m_defGridAttr != this)
- {
- return m_defGridAttr->GetFont();
- }
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- return wxNullFont;
- }
-}
-
-void wxGridCellAttr::GetAlignment(int *hAlign, int *vAlign) const
-{
- if (HasAlignment())
- {
- if ( hAlign )
- *hAlign = m_hAlign;
- if ( vAlign )
- *vAlign = m_vAlign;
- }
- else if (m_defGridAttr && m_defGridAttr != this)
- {
- m_defGridAttr->GetAlignment(hAlign, vAlign);
- }
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- }
-}
-
-void wxGridCellAttr::GetSize( int *num_rows, int *num_cols ) const
-{
- if ( num_rows )
- *num_rows = m_sizeRows;
- if ( num_cols )
- *num_cols = m_sizeCols;
-}
-
-// GetRenderer and GetEditor use a slightly different decision path about
-// which attribute to use. If a non-default attr object has one then it is
-// used, otherwise the default editor or renderer is fetched from the grid and
-// used. It should be the default for the data type of the cell. If it is
-// NULL (because the table has a type that the grid does not have in its
-// registry), then the grid's default editor or renderer is used.
-
-wxGridCellRenderer* wxGridCellAttr::GetRenderer(wxGrid* grid, int row, int col) const
-{
- wxGridCellRenderer *renderer = NULL;
-
- if ( m_renderer && this != m_defGridAttr )
- {
- // use the cells renderer if it has one
- renderer = m_renderer;
- renderer->IncRef();
- }
- else // no non-default cell renderer
- {
- // get default renderer for the data type
- if ( grid )
- {
- // GetDefaultRendererForCell() will do IncRef() for us
- renderer = grid->GetDefaultRendererForCell(row, col);
- }
-
- if ( renderer == NULL )
- {
- if ( (m_defGridAttr != NULL) && (m_defGridAttr != this) )
- {
- // if we still don't have one then use the grid default
- // (no need for IncRef() here neither)
- renderer = m_defGridAttr->GetRenderer(NULL, 0, 0);
- }
- else // default grid attr
- {
- // use m_renderer which we had decided not to use initially
- renderer = m_renderer;
- if ( renderer )
- renderer->IncRef();
- }
- }
- }
-
- // we're supposed to always find something
- wxASSERT_MSG(renderer, wxT("Missing default cell renderer"));
-
- return renderer;
-}
-
-// same as above, except for s/renderer/editor/g
-wxGridCellEditor* wxGridCellAttr::GetEditor(wxGrid* grid, int row, int col) const
-{
- wxGridCellEditor *editor = NULL;
-
- if ( m_editor && this != m_defGridAttr )
- {
- // use the cells editor if it has one
- editor = m_editor;
- editor->IncRef();
- }
- else // no non default cell editor
- {
- // get default editor for the data type
- if ( grid )
- {
- // GetDefaultEditorForCell() will do IncRef() for us
- editor = grid->GetDefaultEditorForCell(row, col);
- }
-
- if ( editor == NULL )
- {
- if ( (m_defGridAttr != NULL) && (m_defGridAttr != this) )
- {
- // if we still don't have one then use the grid default
- // (no need for IncRef() here neither)
- editor = m_defGridAttr->GetEditor(NULL, 0, 0);
- }
- else // default grid attr
- {
- // use m_editor which we had decided not to use initially
- editor = m_editor;
- if ( editor )
- editor->IncRef();
- }
- }
- }
-
- // we're supposed to always find something
- wxASSERT_MSG(editor, wxT("Missing default cell editor"));
-
- return editor;
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellAttrData
-// ----------------------------------------------------------------------------
-
-void wxGridCellAttrData::SetAttr(wxGridCellAttr *attr, int row, int col)
-{
- int n = FindIndex(row, col);
- if ( n == wxNOT_FOUND )
- {
- // add the attribute
- m_attrs.Add(new wxGridCellWithAttr(row, col, attr));
- }
- else
- {
- // free the old attribute
- m_attrs[(size_t)n].attr->DecRef();
-
- if ( attr )
- {
- // change the attribute
- m_attrs[(size_t)n].attr = attr;
- }
- else
- {
- // remove this attribute
- m_attrs.RemoveAt((size_t)n);
- }
- }
-}
-
-wxGridCellAttr *wxGridCellAttrData::GetAttr(int row, int col) const
-{
- wxGridCellAttr *attr = (wxGridCellAttr *)NULL;
-
- int n = FindIndex(row, col);
- if ( n != wxNOT_FOUND )
- {
- attr = m_attrs[(size_t)n].attr;
- attr->IncRef();
- }
-
- return attr;
-}
-
-void wxGridCellAttrData::UpdateAttrRows( size_t pos, int numRows )
-{
- size_t count = m_attrs.GetCount();
- for ( size_t n = 0; n < count; n++ )
- {
- wxGridCellCoords& coords = m_attrs[n].coords;
- wxCoord row = coords.GetRow();
- if ((size_t)row >= pos)
- {
- if (numRows > 0)
- {
- // If rows inserted, include row counter where necessary
- coords.SetRow(row + numRows);
- }
- else if (numRows < 0)
- {
- // If rows deleted ...
- if ((size_t)row >= pos - numRows)
- {
- // ...either decrement row counter (if row still exists)...
- coords.SetRow(row + numRows);
- }
- else
- {
- // ...or remove the attribute
- // No need to DecRef the attribute itself since this is
- // done be wxGridCellWithAttr's destructor!
- m_attrs.RemoveAt(n);
- n--;
- count--;
- }
- }
- }
- }
-}
-
-void wxGridCellAttrData::UpdateAttrCols( size_t pos, int numCols )
-{
- size_t count = m_attrs.GetCount();
- for ( size_t n = 0; n < count; n++ )
- {
- wxGridCellCoords& coords = m_attrs[n].coords;
- wxCoord col = coords.GetCol();
- if ( (size_t)col >= pos )
- {
- if ( numCols > 0 )
- {
- // If rows inserted, include row counter where necessary
- coords.SetCol(col + numCols);
- }
- else if (numCols < 0)
- {
- // If rows deleted ...
- if ((size_t)col >= pos - numCols)
- {
- // ...either decrement row counter (if row still exists)...
- coords.SetCol(col + numCols);
- }
- else
- {
- // ...or remove the attribute
- // No need to DecRef the attribute itself since this is
- // done be wxGridCellWithAttr's destructor!
- m_attrs.RemoveAt(n);
- n--;
- count--;
- }
- }
- }
- }
-}
-
-int wxGridCellAttrData::FindIndex(int row, int col) const
-{
- size_t count = m_attrs.GetCount();
- for ( size_t n = 0; n < count; n++ )
- {
- const wxGridCellCoords& coords = m_attrs[n].coords;
- if ( (coords.GetRow() == row) && (coords.GetCol() == col) )
- {
- return n;
- }
- }
-
- return wxNOT_FOUND;
-}
-
-// ----------------------------------------------------------------------------
-// wxGridRowOrColAttrData
-// ----------------------------------------------------------------------------
-
-wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
-{
- size_t count = m_attrs.Count();
- for ( size_t n = 0; n < count; n++ )
- {
- m_attrs[n]->DecRef();
- }
-}
-
-wxGridCellAttr *wxGridRowOrColAttrData::GetAttr(int rowOrCol) const
-{
- wxGridCellAttr *attr = (wxGridCellAttr *)NULL;
-
- int n = m_rowsOrCols.Index(rowOrCol);
- if ( n != wxNOT_FOUND )
- {
- attr = m_attrs[(size_t)n];
- attr->IncRef();
- }
-
- return attr;
-}
-
-void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr *attr, int rowOrCol)
-{
- int i = m_rowsOrCols.Index(rowOrCol);
- if ( i == wxNOT_FOUND )
- {
- // add the attribute
- m_rowsOrCols.Add(rowOrCol);
- m_attrs.Add(attr);
- }
- else
- {
- size_t n = (size_t)i;
- if ( attr )
- {
- // change the attribute
- m_attrs[n]->DecRef();
- m_attrs[n] = attr;
- }
- else
- {
- // remove this attribute
- m_attrs[n]->DecRef();
- m_rowsOrCols.RemoveAt(n);
- m_attrs.RemoveAt(n);
- }
- }
-}
-
-void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos, int numRowsOrCols )
-{
- size_t count = m_attrs.GetCount();
- for ( size_t n = 0; n < count; n++ )
- {
- int & rowOrCol = m_rowsOrCols[n];
- if ( (size_t)rowOrCol >= pos )
- {
- if ( numRowsOrCols > 0 )
- {
- // If rows inserted, include row counter where necessary
- rowOrCol += numRowsOrCols;
- }
- else if ( numRowsOrCols < 0)
- {
- // If rows deleted, either decrement row counter (if row still exists)
- if ((size_t)rowOrCol >= pos - numRowsOrCols)
- rowOrCol += numRowsOrCols;
- else
- {
- m_rowsOrCols.RemoveAt(n);
- m_attrs[n]->DecRef();
- m_attrs.RemoveAt(n);
- n--;
- count--;
- }
- }
- }
- }
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellAttrProvider
-// ----------------------------------------------------------------------------
-
-wxGridCellAttrProvider::wxGridCellAttrProvider()
-{
- m_data = (wxGridCellAttrProviderData *)NULL;
-}
-
-wxGridCellAttrProvider::~wxGridCellAttrProvider()
-{
- delete m_data;
-}
-
-void wxGridCellAttrProvider::InitData()
-{
- m_data = new wxGridCellAttrProviderData;