virtual void Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler);
+ virtual void SetSize(const wxRect& rect);
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
void RegisterDataType(const wxString& typeName,
wxGridCellRenderer* renderer,
wxGridCellEditor* editor);
- wxGridCellEditor* GetDefaultEditorForCell(int row, int col);
- wxGridCellRenderer* GetDefaultRendererForCell(int row, int col);
- wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName);
- wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName);
+ wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
+ wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
+ { return GetDefaultEditorForCell(c.GetRow(), c.GetCol()); }
+ wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
+ wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
+ wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
wxGRID_CHOICE,
wxGRID_COMBOBOX };
- // for wxGridCellBoolEditor
- wxWindow *GetGridWindow() const;
-
protected:
bool m_created;
bool m_displayed;
// flicker
}
+void wxGridCellTextEditor::SetSize(const wxRect& rectOrig)
+{
+ wxRect rect(rectOrig);
+
+ // Make the edit control large enough to allow for internal
+ // margins
+ //
+ // TODO: remove this if the text ctrl sizing is improved esp. for
+ // unix
+ //
+#if defined(__WXGTK__)
+ rect.Inflate(rect.x ? 1 : 0, rect.y ? 1 : 0);
+#else // !GTK
+ int extra = row && col ? 2 : 1;
+#if defined(__WXMOTIF__)
+ extra *= 2;
+#endif
+ rect.SetLeft( wxMax(0, rect.x - extra) );
+ rect.SetTop( wxMax(0, rect.y - extra) );
+ rect.SetRight( rect.GetRight() + 2*extra );
+ rect.SetBottom( rect.GetBottom() + 2*extra );
+#endif // GTK/!GTK
+
+ wxGridCellEditor::SetSize(rect);
+}
+
void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid)
{
wxASSERT_MSG(m_control,
void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr)
{
- wxGridCellEditor::Show(show, attr);
+ m_control->Show(show);
+
if ( show )
{
- // VZ: normally base class already does it, but it doesn't work (FIXME)
wxColour colBg = attr ? attr->GetBackgroundColour() : *wxLIGHT_GREY;
CBox()->SetBackgroundColour(colBg);
}
void wxGrid::DrawHighlight(wxDC& dc)
{
+ if ( IsCellEditControlEnabled() )
+ {
+ // don't show highlight when the edit control is shown
+ return;
+ }
+
// if the active cell was repainted, repaint its highlight too because it
// might have been damaged by the grid lines
size_t count = m_cellsExposed.GetCount();
return m_cellEditCtrlEnabled ? !IsCurrentCellReadOnly() : FALSE;
}
-wxWindow *wxGrid::GetGridWindow() const
-{
- return m_gridWin;
-}
-
void wxGrid::ShowCellEditControl()
{
if ( IsCellEditControlEnabled() )
// convert to scrolled coords
//
- int left, top, right, bottom;
- CalcScrolledPosition( rect.GetLeft(), rect.GetTop(), &left, &top );
- CalcScrolledPosition( rect.GetRight(), rect.GetBottom(), &right, &bottom );
+ CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
- // cell is shifted by one pixel
- left--;
- top--;
- right--;
- bottom--;
-
- // Make the edit control large enough to allow for internal
- // margins
- //
- // TODO: remove this if the text ctrl sizing is improved esp. for
- // unix
- //
- int extra;
-#if defined(__WXMOTIF__)
- if ( row == 0 || col == 0 )
- {
- extra = 2;
- }
- else
- {
- extra = 4;
- }
-#else
- if ( row == 0 || col == 0 )
- {
- extra = 1;
- }
- else
- {
- extra = 2;
- }
-#endif
+ // done in PaintBackground()
+#if 0
+ // erase the highlight and the cell contents because the editor
+ // might not cover the entire cell
+ wxClientDC dc( m_gridWin );
+ PrepareDC( dc );
+ dc.SetBrush(*wxLIGHT_GREY_BRUSH); //wxBrush(attr->GetBackgroundColour(), wxSOLID));
+ dc.SetPen(*wxTRANSPARENT_PEN);
+ dc.DrawRectangle(rect);
+#endif // 0
-#if defined(__WXGTK__)
- int top_diff = 0;
- int left_diff = 0;
- if (left != 0) left_diff++;
- if (top != 0) top_diff++;
- rect.SetLeft( left + left_diff );
- rect.SetTop( top + top_diff );
- rect.SetRight( rect.GetRight() - left_diff );
- rect.SetBottom( rect.GetBottom() - top_diff );
-#else
- rect.SetLeft( wxMax(0, left - extra) );
- rect.SetTop( wxMax(0, top - extra) );
- rect.SetRight( rect.GetRight() + 2*extra );
- rect.SetBottom( rect.GetBottom() + 2*extra );
-#endif
+ // cell is shifted by one pixel
+ rect.x--;
+ rect.y--;
wxGridCellAttr* attr = GetCellAttr(row, col);
wxGridCellEditor* editor = attr->GetEditor(GetDefaultEditorForCell(row, col));
}
editor->SetSize( rect );
+
editor->Show( TRUE, attr );
editor->BeginEdit(row, col, this);
attr->DecRef();
}
-wxGridCellEditor* wxGrid::GetDefaultEditorForCell(int row, int col)
+wxGridCellEditor* wxGrid::GetDefaultEditorForCell(int row, int col) const
{
wxString typeName = m_table->GetTypeName(row, col);
return GetDefaultEditorForType(typeName);
}
-wxGridCellRenderer* wxGrid::GetDefaultRendererForCell(int row, int col)
+wxGridCellRenderer* wxGrid::GetDefaultRendererForCell(int row, int col) const
{
wxString typeName = m_table->GetTypeName(row, col);
return GetDefaultRendererForType(typeName);
}
-wxGridCellEditor* wxGrid::GetDefaultEditorForType(const wxString& typeName)
+wxGridCellEditor*
+wxGrid::GetDefaultEditorForType(const wxString& typeName) const
{
int index = m_typeRegistry->FindDataType(typeName);
if (index == -1) {
return m_typeRegistry->GetEditor(index);
}
-wxGridCellRenderer* wxGrid::GetDefaultRendererForType(const wxString& typeName)
+wxGridCellRenderer*
+wxGrid::GetDefaultRendererForType(const wxString& typeName) const
{
int index = m_typeRegistry->FindDataType(typeName);
if (index == -1) {