#include "wx/dcclient.h"
#include "wx/settings.h"
#include "wx/log.h"
+ #include "wx/textctrl.h"
+ #include "wx/checkbox.h"
#endif
// this include needs to be outside precomp for BCC
// implementation
// ============================================================================
-
// ----------------------------------------------------------------------------
// wxGridCellEditor
// ----------------------------------------------------------------------------
Destroy();
}
+void wxGridCellEditor::Create(wxWindow* WXUNUSED(parent),
+ wxWindowID WXUNUSED(id),
+ wxEvtHandler* evtHandler)
+{
+ if (evtHandler)
+ m_control->PushEventHandler(evtHandler);
+}
void wxGridCellEditor::Destroy()
{
- if (m_control) {
+ if (m_control)
+ {
m_control->Destroy();
m_control = NULL;
}
void wxGridCellEditor::StartingKey(wxKeyEvent& event)
{
-}
+ wxASSERT_MSG(m_control,
+ wxT("The wxGridCellEditor must be Created first!"));
+ // pass the event to the control
+ m_control->GetEventHandler()->ProcessEvent(event);
+}
+// ----------------------------------------------------------------------------
+// wxGridCellTextEditor
+// ----------------------------------------------------------------------------
wxGridCellTextEditor::wxGridCellTextEditor()
{
wxWindowID id,
wxEvtHandler* evtHandler)
{
- m_control = new wxTextCtrl(parent, -1, "",
+ m_control = new wxTextCtrl(parent, id, wxEmptyString,
wxDefaultPosition, wxDefaultSize
#if defined(__WXMSW__)
, wxTE_MULTILINE | wxTE_NO_VSCROLL // necessary ???
#endif
- );
+ );
- if (evtHandler)
- m_control->PushEventHandler(evtHandler);
+ wxGridCellEditor::Create(parent, id, evtHandler);
}
wxT("The wxGridCellEditor must be Created first!"));
m_startValue = grid->GetTable()->GetValue(row, col);
- ((wxTextCtrl*)m_control)->SetValue(m_startValue);
- ((wxTextCtrl*)m_control)->SetInsertionPointEnd();
- ((wxTextCtrl*)m_control)->SetFocus();
+ Text()->SetValue(m_startValue);
+ Text()->SetInsertionPointEnd();
+ Text()->SetFocus();
}
-
bool wxGridCellTextEditor::EndEdit(int row, int col, bool saveValue,
wxGrid* grid)
{
wxT("The wxGridCellEditor must be Created first!"));
bool changed = FALSE;
- wxString value = ((wxTextCtrl*)m_control)->GetValue();
+ wxString value = Text()->GetValue();
if (value != m_startValue)
changed = TRUE;
grid->GetTable()->SetValue(row, col, value);
m_startValue = wxEmptyString;
- ((wxTextCtrl*)m_control)->SetValue(m_startValue);
+ Text()->SetValue(m_startValue);
return changed;
}
wxASSERT_MSG(m_control,
wxT("The wxGridCellEditor must be Created first!"));
- ((wxTextCtrl*)m_control)->SetValue(m_startValue);
- ((wxTextCtrl*)m_control)->SetInsertionPointEnd();
+ Text()->SetValue(m_startValue);
+ Text()->SetInsertionPointEnd();
}
-
void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
{
- wxASSERT_MSG(m_control,
- wxT("The wxGridCellEditor must be Created first!"));
+ if ( !event.AltDown() && !event.MetaDown() && !event.ControlDown() )
+ {
+ // insert the key in the control
+ long keycode = event.KeyCode();
+ if ( isprint(keycode) )
+ {
+ // FIXME this is not going to work for non letters...
+ if ( !event.ShiftDown() )
+ {
+ keycode = tolower(keycode);
+ }
+
+ Text()->AppendText((wxChar)keycode);
+
+ return;
+ }
- int code = event.KeyCode();
- if (code >= 32 && code < 255) {
- wxString st((char)code);
- if (! event.ShiftDown())
- st.LowerCase();
- ((wxTextCtrl*)m_control)->AppendText(st);
}
-}
+ event.Skip();
+}
void wxGridCellTextEditor::HandleReturn(wxKeyEvent& event)
{
#if defined(__WXMOTIF__) || defined(__WXGTK__)
// wxMotif needs a little extra help...
- int pos = ((wxTextCtrl*)m_control)->GetInsertionPoint();
- wxString s( ((wxTextCtrl*)m_control)->GetValue() );
+ int pos = Text()->GetInsertionPoint();
+ wxString s( Text()->GetValue() );
s = s.Left(pos) + "\n" + s.Mid(pos);
- ((wxTextCtrl*)m_control)->SetValue(s);
- ((wxTextCtrl*)m_control)->SetInsertionPoint( pos );
+ Text()->SetValue(s);
+ Text()->SetInsertionPoint( pos );
#else
// the other ports can handle a Return key press
//
#endif
}
+// ----------------------------------------------------------------------------
+// wxGridCellBoolEditor
+// ----------------------------------------------------------------------------
+
+void wxGridCellBoolEditor::Create(wxWindow* parent,
+ wxWindowID id,
+ wxEvtHandler* evtHandler)
+{
+ m_control = new wxCheckBox(parent, id, wxEmptyString,
+ wxDefaultPosition, wxDefaultSize,
+ wxNO_BORDER);
+
+ wxGridCellEditor::Create(parent, id, evtHandler);
+}
+
+void wxGridCellBoolEditor::SetSize(const wxRect& r)
+{
+ m_rectCell = r;
+ // position it in the centre of the rectangle (TODO: support alignment?)
+ wxCoord w, h;
+ m_control->GetSize(&w, &h);
+
+ // the checkbox without label still has some space to the right in wxGTK,
+ // so shift it to the right
+#ifdef __WXGTK__
+ w += 8;
+#endif // GTK
+
+ m_control->Move(r.x + r.width/2 - w/2, r.y + r.height/2 - h/2);
+}
+
+void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr)
+{
+ wxGridCellEditor::Show(show, attr);
+ if ( !show )
+ return;
+
+ // get the bg colour to use
+ wxColour colBg = attr ? attr->GetBackgroundColour() : *wxLIGHT_GREY;
+
+ // erase the background because we don't fill the cell
+ if ( m_rectCell.width > 0 )
+ {
+ wxClientDC dc(m_control->GetParent());
+ dc.SetPen(*wxTRANSPARENT_PEN);
+ dc.SetBrush(wxBrush(colBg, wxSOLID));
+ dc.DrawRectangle(m_rectCell);
+
+ m_rectCell.width = 0;
+ }
+
+ CBox()->SetBackgroundColour(colBg);
+}
+
+void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid)
+{
+ wxASSERT_MSG(m_control,
+ wxT("The wxGridCellEditor must be Created first!"));
+
+ m_startValue = !!grid->GetTable()->GetValue(row, col); // FIXME-DATA
+ CBox()->SetValue(m_startValue);
+ CBox()->SetFocus();
+}
+
+bool wxGridCellBoolEditor::EndEdit(int row, int col,
+ bool saveValue,
+ wxGrid* grid)
+{
+ wxASSERT_MSG(m_control,
+ wxT("The wxGridCellEditor must be Created first!"));
+
+ bool changed = FALSE;
+ bool value = CBox()->GetValue();
+ if ( value != m_startValue )
+ changed = TRUE;
+
+ if ( changed )
+ {
+ // FIXME-DATA
+ grid->GetTable()->SetValue(row, col, value ? _T("1") : wxEmptyString);
+ }
+
+ return changed;
+}
+
+void wxGridCellBoolEditor::Reset()
+{
+ wxASSERT_MSG(m_control,
+ wxT("The wxGridCellEditor must be Created first!"));
+
+ CBox()->SetValue(m_startValue);
+}
+
+void wxGridCellBoolEditor::StartingKey(wxKeyEvent& event)
+{
+ event.Skip();
+}
+
+// ----------------------------------------------------------------------------
+// wxGridCellEditorEvtHandler
+// ----------------------------------------------------------------------------
void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event)
{
{
case WXK_ESCAPE:
m_editor->Reset();
- m_grid->EnableCellEditControl(FALSE);
+ m_grid->DisableCellEditControl();
break;
case WXK_TAB:
}
}
+// ============================================================================
+// renderer classes
+// ============================================================================
+
// ----------------------------------------------------------------------------
// wxGridCellRenderer
// ----------------------------------------------------------------------------
dc.DrawRectangle(rect);
}
+// ----------------------------------------------------------------------------
+// wxGridCellStringRenderer
+// ----------------------------------------------------------------------------
+
void wxGridCellStringRenderer::Draw(wxGrid& grid,
wxGridCellAttr& attr,
wxDC& dc,
rect, hAlign, vAlign);
}
+// ----------------------------------------------------------------------------
+// wxGridCellBoolRenderer
+// ----------------------------------------------------------------------------
+
+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);
+
+ // position it in the centre (ignoring alignment - TODO)
+ static const wxCoord checkSize = 16;
+
+ wxRect rectMark;
+ rectMark.x = rect.x + rect.width/2 - checkSize/2;
+ rectMark.y = rect.y + rect.height/2 - checkSize/2;
+ rectMark.width = rectMark.height = checkSize;
+
+ dc.SetBrush(*wxTRANSPARENT_BRUSH);
+ dc.SetPen(wxPen(attr.GetTextColour(), 1, wxSOLID));
+ dc.DrawRectangle(rectMark);
+
+ rectMark.Inflate(-4);
+
+ if ( !!grid.GetTable()->GetValue(row, col) ) // FIXME-DATA
+ {
+ dc.SetTextForeground(attr.GetTextColour());
+ dc.DrawCheckMark(rectMark);
+ }
+}
+
// ----------------------------------------------------------------------------
// wxGridCellAttr
// ----------------------------------------------------------------------------
const wxColour& wxGridCellAttr::GetTextColour() const
{
if (HasTextColour())
+ {
return m_colText;
+ }
else if (m_defGridAttr != this)
+ {
return m_defGridAttr->GetTextColour();
- else {
+ }
+ else
+ {
wxFAIL_MSG(wxT("Missing default cell attribute"));
return wxNullColour;
}
return m_colBack;
else if (m_defGridAttr != this)
return m_defGridAttr->GetBackgroundColour();
- else {
+ else
+ {
wxFAIL_MSG(wxT("Missing default cell attribute"));
return wxNullColour;
}
return m_font;
else if (m_defGridAttr != this)
return m_defGridAttr->GetFont();
- else {
+ else
+ {
wxFAIL_MSG(wxT("Missing default cell attribute"));
return wxNullFont;
}
void wxGridCellAttr::GetAlignment(int *hAlign, int *vAlign) const
{
- if (HasAlignment()) {
+ if (HasAlignment())
+ {
if ( hAlign ) *hAlign = m_hAlign;
if ( vAlign ) *vAlign = m_vAlign;
}
else if (m_defGridAttr != this)
m_defGridAttr->GetAlignment(hAlign, vAlign);
- else {
+ else
+ {
wxFAIL_MSG(wxT("Missing default cell attribute"));
}
}
return m_renderer;
else if (m_defGridAttr != this)
return m_defGridAttr->GetRenderer();
- else {
+ else
+ {
wxFAIL_MSG(wxT("Missing default cell attribute"));
return NULL;
}
return m_editor;
else if (m_defGridAttr != this)
return m_defGridAttr->GetEditor();
- else {
+ else
+ {
wxFAIL_MSG(wxT("Missing default cell attribute"));
return NULL;
}
{
row = YToRow(y);
if ( row >= 0 &&
- !SendEvent( EVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) )
+ !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) )
{
SelectRow( row, event.ShiftDown() );
ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW, m_rowLabelWin);
if ( YToEdgeOfRow(y) < 0 )
{
row = YToRow(y);
- SendEvent( EVT_GRID_LABEL_LEFT_DCLICK, row, -1, event );
+ SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event );
}
}
// Note: we are ending the event *after* doing
// default processing in this case
//
- SendEvent( EVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
+ SendEvent( wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
}
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin);
else if ( event.RightDown() )
{
row = YToRow(y);
- if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) )
+ if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) )
{
// no default action at the moment
}
else if ( event.RightDClick() )
{
row = YToRow(y);
- if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) )
+ if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) )
{
// no default action at the moment
}
{
col = XToCol(x);
if ( col >= 0 &&
- !SendEvent( EVT_GRID_LABEL_LEFT_CLICK, -1, col, event ) )
+ !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, -1, col, event ) )
{
SelectCol( col, event.ShiftDown() );
ChangeCursorMode(WXGRID_CURSOR_SELECT_COL, m_colLabelWin);
if ( XToEdgeOfCol(x) < 0 )
{
col = XToCol(x);
- SendEvent( EVT_GRID_LABEL_LEFT_DCLICK, -1, col, event );
+ SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event );
}
}
// Note: we are ending the event *after* doing
// default processing in this case
//
- SendEvent( EVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event );
+ SendEvent( wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event );
}
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin);
else if ( event.RightDown() )
{
col = XToCol(x);
- if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) )
+ if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) )
{
// no default action at the moment
}
else if ( event.RightDClick() )
{
col = XToCol(x);
- if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) )
+ if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) )
{
// no default action at the moment
}
// indicate corner label by having both row and
// col args == -1
//
- if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK, -1, -1, event ) )
+ if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, event ) )
{
SelectAll();
}
else if ( event.LeftDClick() )
{
- SendEvent( EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, event );
+ SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, event );
}
else if ( event.RightDown() )
{
- if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, event ) )
+ if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, event ) )
{
// no default action at the moment
}
else if ( event.RightDClick() )
{
- if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, event ) )
+ if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, event ) )
{
// no default action at the moment
}
// Don't start doing anything until the mouse has been drug at
// least 3 pixels in any direction...
- if (! m_isDragging) {
- if (m_startDragPos == wxDefaultPosition) {
+ if (! m_isDragging)
+ {
+ if (m_startDragPos == wxDefaultPosition)
+ {
m_startDragPos = pos;
return;
}
HideCellEditControl();
// Have we captured the mouse yet?
- if (! m_winCapture) {
+ if (! m_winCapture)
+ {
m_winCapture = m_gridWin;
m_winCapture->CaptureMouse();
}
SelectBlock( m_currentCellCoords, coords );
}
- if (! IsVisible(coords)) {
+ if (! IsVisible(coords))
+ {
MakeCellVisible(coords);
// TODO: need to introduce a delay or something here. The
// scrolling is way to fast, at least on MSW.
//
if ( event.LeftDown() )
{
- EnableCellEditControl( FALSE );
+ DisableCellEditControl();
if ( event.ShiftDown() )
{
SelectBlock( m_currentCellCoords, coords );
else if ( XToEdgeOfCol(x) < 0 &&
YToEdgeOfRow(y) < 0 )
{
- if ( !SendEvent( EVT_GRID_CELL_LEFT_CLICK,
+ if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK,
coords.GetRow(),
coords.GetCol(),
event ) )
// if this is the second click on this cell then start
// the edit control
- if (m_waitForSlowClick && coords == m_currentCellCoords) {
- EnableCellEditControl(TRUE);
- // VZ: this is done by the call above, so why do it
- // again? please remove this line if it's ok
- //ShowCellEditControl();
+ if ( m_waitForSlowClick &&
+ (coords == m_currentCellCoords) &&
+ CanEnableCellControl())
+ {
+ EnableCellEditControl();
m_waitForSlowClick = FALSE;
}
- else {
+ else
+ {
SetCurrentCell( coords );
m_waitForSlowClick = TRUE;
}
//
else if ( event.LeftDClick() )
{
- EnableCellEditControl( FALSE );
+ DisableCellEditControl();
if ( XToEdgeOfCol(x) < 0 && YToEdgeOfRow(y) < 0 )
{
- SendEvent( EVT_GRID_CELL_LEFT_DCLICK,
+ SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK,
coords.GetRow(),
coords.GetCol(),
event );
{
if ( IsSelection() )
{
- if (m_winCapture) {
+ if (m_winCapture)
+ {
m_winCapture->ReleaseMouse();
m_winCapture = NULL;
}
- SendEvent( EVT_GRID_RANGE_SELECT, -1, -1, event );
+ SendEvent( wxEVT_GRID_RANGE_SELECT, -1, -1, event );
}
// Show the edit control, if it has been hidden for
// Note: we are ending the event *after* doing
// default processing in this case
//
- SendEvent( EVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
+ SendEvent( wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
}
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
{
// Note: we are ending the event *after* doing
// default processing in this case
//
- SendEvent( EVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event );
+ SendEvent( wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event );
}
m_dragLastPos = -1;
//
else if ( event.RightDown() )
{
- EnableCellEditControl( FALSE );
- if ( !SendEvent( EVT_GRID_CELL_RIGHT_CLICK,
+ DisableCellEditControl();
+ if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK,
coords.GetRow(),
coords.GetCol(),
event ) )
//
else if ( event.RightDClick() )
{
- EnableCellEditControl( FALSE );
- if ( !SendEvent( EVT_GRID_CELL_RIGHT_DCLICK,
+ DisableCellEditControl();
+ if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK,
coords.GetRow(),
coords.GetCol(),
event ) )
if ( m_table )
{
if (IsCellEditControlEnabled())
- EnableCellEditControl(FALSE);
+ DisableCellEditControl();
bool ok = m_table->InsertRows( pos, numRows );
if ( m_table )
{
if (IsCellEditControlEnabled())
- EnableCellEditControl(FALSE);
+ DisableCellEditControl();
if (m_table->DeleteRows( pos, numRows ))
{
if ( m_table )
{
if (IsCellEditControlEnabled())
- EnableCellEditControl(FALSE);
+ DisableCellEditControl();
bool ok = m_table->InsertCols( pos, numCols );
if ( m_table )
{
if (IsCellEditControlEnabled())
- EnableCellEditControl(FALSE);
+ DisableCellEditControl();
if ( m_table->DeleteCols( pos, numCols ) )
{
int row, int col,
wxMouseEvent& mouseEv )
{
- if ( type == EVT_GRID_ROW_SIZE ||
- type == EVT_GRID_COL_SIZE )
+ if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
{
int rowOrCol = (row == -1 ? col : row);
return GetEventHandler()->ProcessEvent(gridEvt);
}
- else if ( type == EVT_GRID_RANGE_SELECT )
+ else if ( type == wxEVT_GRID_RANGE_SELECT )
{
wxGridRangeSelectEvent gridEvt( GetId(),
type,
bool wxGrid::SendEvent( const wxEventType type,
int row, int col )
{
- if ( type == EVT_GRID_ROW_SIZE ||
- type == EVT_GRID_COL_SIZE )
+ if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
{
int rowOrCol = (row == -1 ? col : row);
default:
// now try the cell edit control
//
- if ( !IsCellEditControlEnabled() )
- EnableCellEditControl( TRUE );
- if (IsCellEditControlEnabled()) {
+ if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
+ {
+ EnableCellEditControl();
wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords);
attr->GetEditor()->StartingKey(event);
attr->DecRef();
void wxGrid::OnEraseBackground(wxEraseEvent&)
-{ }
-
-
-
+{
+}
void wxGrid::SetCurrentCell( const wxGridCellCoords& coords )
{
- if ( SendEvent( EVT_GRID_SELECT_CELL, coords.GetRow(), coords.GetCol() ) )
+ if ( SendEvent( wxEVT_GRID_SELECT_CELL, coords.GetRow(), coords.GetCol() ) )
{
// the event has been intercepted - do nothing
return;
{
HideCellEditControl();
SaveEditControlValue();
- EnableCellEditControl(FALSE);
+ DisableCellEditControl();
// Clear the old current cell highlight
wxRect r = BlockToDeviceRect(m_currentCellCoords, m_currentCellCoords);
DrawCellBorder( dc, coords );
#endif
+ // don't draw the cell over the active edit control!
+ if ( (coords == m_currentCellCoords) && IsCellEditControlEnabled() )
+ return;
+
// but all the rest is drawn by the cell renderer and hence may be
// customized
wxRect rect;
int top, bottom, left, right;
- if (reg.IsEmpty()){
+ if (reg.IsEmpty())
+ {
int cw, ch;
m_gridWin->GetClientSize(&cw, &ch);
CalcUnscrolledPosition( 0, 0, &left, &top );
CalcUnscrolledPosition( cw, ch, &right, &bottom );
}
- else{
+ else
+ {
wxCoord x, y, w, h;
reg.GetBox(x, y, w, h);
CalcUnscrolledPosition( x, y, &left, &top );
{
m_editable = edit;
+ // FIXME IMHO this won't disable the edit control if edit == FALSE
+ // because of the check in the beginning of
+ // EnableCellEditControl() just below (VZ)
EnableCellEditControl(m_editable);
}
}
if ( enable != m_cellEditCtrlEnabled )
{
+ // TODO allow the app to Veto() this event?
+ SendEvent(enable ? wxEVT_GRID_EDITOR_SHOWN : wxEVT_GRID_EDITOR_HIDDEN);
+
if ( enable )
{
+ // this should be checked by the caller!
+ wxASSERT_MSG( CanEnableCellControl(),
+ _T("can't enable editing for this cell!") );
+
+ // do it before ShowCellEditControl()
m_cellEditCtrlEnabled = enable;
+
SetEditControlValue();
ShowCellEditControl();
}
{
HideCellEditControl();
SaveEditControlValue();
+
+ // do it after HideCellEditControl()
m_cellEditCtrlEnabled = enable;
}
}
}
+bool wxGrid::IsCurrentCellReadOnly() const
+{
+ // const_cast
+ wxGridCellAttr* attr = ((wxGrid *)this)->GetCellAttr(m_currentCellCoords);
+ bool readonly = attr->IsReadOnly();
+ attr->DecRef();
-bool wxGrid::IsCellEditControlEnabled()
+ return readonly;
+}
+
+bool wxGrid::CanEnableCellControl() const
{
- bool enabled;
+ return m_editable && !IsCurrentCellReadOnly();
+}
- if ( m_cellEditCtrlEnabled )
- {
- wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords);
- enabled = !attr->IsReadOnly();
- attr->DecRef();
- }
- else
- {
- enabled = FALSE;
- }
+bool wxGrid::IsCellEditControlEnabled() const
+{
+ // the cell edit control might be disable for all cells or just for the
+ // current one if it's read only
+ return m_cellEditCtrlEnabled ? !IsCurrentCellReadOnly() : FALSE;
+}
- return enabled;
+wxWindow *wxGrid::GetGridWindow() const
+{
+ return m_gridWin;
}
void wxGrid::ShowCellEditControl()
int left, top, right, bottom;
CalcScrolledPosition( rect.GetLeft(), rect.GetTop(), &left, &top );
CalcScrolledPosition( rect.GetRight(), rect.GetBottom(), &right, &bottom );
- left--; top--; right--; bottom--; // cell is shifted by one pixel
- int cw, ch;
- m_gridWin->GetClientSize( &cw, &ch );
+
+ // cell is shifted by one pixel
+ left--;
+ top--;
+ right--;
+ bottom--;
// Make the edit control large enough to allow for internal
// margins
rect.SetBottom( rect.GetBottom() + 2*extra );
#endif
- wxGridCellAttr* attr = GetCellAttr(row, col);
+ wxGridCellAttr* attr = GetCellAttr(row, col);
wxGridCellEditor* editor = attr->GetEditor();
if ( !editor->IsCreated() )
{
if (changed)
{
- SendEvent( EVT_GRID_CELL_CHANGE,
+ SendEvent( wxEVT_GRID_CELL_CHANGE,
m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol() );
}
attr = m_table ? m_table->GetAttr(row, col) : (wxGridCellAttr *)NULL;
CacheAttr(row, col, attr);
}
- if (attr) {
+ if (attr)
+ {
attr->SetDefAttr(m_defaultCellAttr);
- } else {
+ }
+ else
+ {
attr = m_defaultCellAttr;
attr->IncRef();
}
}
wxGridRangeSelectEvent gridEvt( GetId(),
- EVT_GRID_RANGE_SELECT,
+ wxEVT_GRID_RANGE_SELECT,
this,
m_selectedTopLeft,
m_selectedBottomRight );
}
wxGridRangeSelectEvent gridEvt( GetId(),
- EVT_GRID_RANGE_SELECT,
+ wxEVT_GRID_RANGE_SELECT,
this,
m_selectedTopLeft,
m_selectedBottomRight );
if ( !m_isDragging )
{
wxGridRangeSelectEvent gridEvt( GetId(),
- EVT_GRID_RANGE_SELECT,
+ wxEVT_GRID_RANGE_SELECT,
this,
m_selectedTopLeft,
m_selectedBottomRight );