virtual void StartingKey(wxKeyEvent& event);
virtual void HandleReturn(wxKeyEvent& event);
+protected:
+ wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
private:
wxString m_startValue;
bool IsEditable() { return m_editable; }
void EnableEditing( bool edit );
- void EnableCellEditControl( bool enable );
+ void EnableCellEditControl( bool enable = TRUE );
+ void DisableCellEditControl() { EnableCellEditControl(FALSE); }
+ bool CanEnableCellControl() const;
+ bool IsCellEditControlEnabled() const;
- bool IsCellEditControlEnabled();
+ bool IsCurrentCellReadOnly() const;
void ShowCellEditControl();
void HideCellEditControl();
wxCursor m_rowResizeCursor;
wxCursor m_colResizeCursor;
- bool m_editable; // applies to whole grid
- bool m_cellEditCtrlEnabled;
+ bool m_editable; // applies to whole grid
+ bool m_cellEditCtrlEnabled; // is in-place edit currently shown?
void Create();
bool Redimension( wxGridTableMessage& );
- bool SendEvent( const wxEventType,
- int row, int col,
- wxMouseEvent& );
-
- bool SendEvent( const wxEventType,
- int row, int col );
-
+ bool SendEvent( const wxEventType, int row, int col, wxMouseEvent& );
+ bool SendEvent( const wxEventType, int row, int col );
+ bool SendEvent( const wxEventType type)
+ {
+ return SendEvent(type,
+ m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol());
+ }
void OnPaint( wxPaintEvent& );
void OnSize( wxSizeEvent& );
DECLARE_DYNAMIC_CLASS(wxGridEvent)
};
-
class WXDLLEXPORT wxGridSizeEvent : public wxNotifyEvent
{
public:
DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent)
};
-
-const wxEventType EVT_GRID_CELL_LEFT_CLICK = wxEVT_FIRST + 1580;
-const wxEventType EVT_GRID_CELL_RIGHT_CLICK = wxEVT_FIRST + 1581;
-const wxEventType EVT_GRID_CELL_LEFT_DCLICK = wxEVT_FIRST + 1582;
-const wxEventType EVT_GRID_CELL_RIGHT_DCLICK = wxEVT_FIRST + 1583;
-const wxEventType EVT_GRID_LABEL_LEFT_CLICK = wxEVT_FIRST + 1584;
-const wxEventType EVT_GRID_LABEL_RIGHT_CLICK = wxEVT_FIRST + 1585;
-const wxEventType EVT_GRID_LABEL_LEFT_DCLICK = wxEVT_FIRST + 1586;
-const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK = wxEVT_FIRST + 1587;
-const wxEventType EVT_GRID_ROW_SIZE = wxEVT_FIRST + 1588;
-const wxEventType EVT_GRID_COL_SIZE = wxEVT_FIRST + 1589;
-const wxEventType EVT_GRID_RANGE_SELECT = wxEVT_FIRST + 1590;
-const wxEventType EVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1591;
-const wxEventType EVT_GRID_SELECT_CELL = wxEVT_FIRST + 1592;
+// TODO move to wx/event.h
+const wxEventType wxEVT_GRID_CELL_LEFT_CLICK = wxEVT_FIRST + 1580;
+const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK = wxEVT_FIRST + 1581;
+const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK = wxEVT_FIRST + 1582;
+const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK = wxEVT_FIRST + 1583;
+const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK = wxEVT_FIRST + 1584;
+const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK = wxEVT_FIRST + 1585;
+const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK = wxEVT_FIRST + 1586;
+const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK = wxEVT_FIRST + 1587;
+const wxEventType wxEVT_GRID_ROW_SIZE = wxEVT_FIRST + 1588;
+const wxEventType wxEVT_GRID_COL_SIZE = wxEVT_FIRST + 1589;
+const wxEventType wxEVT_GRID_RANGE_SELECT = wxEVT_FIRST + 1590;
+const wxEventType wxEVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1591;
+const wxEventType wxEVT_GRID_SELECT_CELL = wxEVT_FIRST + 1592;
+const wxEventType wxEVT_GRID_EDITOR_SHOWN = wxEVT_FIRST + 1593;
+const wxEventType wxEVT_GRID_EDITOR_HIDDEN = wxEVT_FIRST + 1594;
typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
-#define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
-#define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
-#define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
-#define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CELL_LEFT_CLICK(fn) { wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CELL_RIGHT_CLICK(fn) { wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CELL_LEFT_DCLICK(fn) { wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CELL_RIGHT_DCLICK(fn) { wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_LABEL_LEFT_CLICK(fn) { wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_LABEL_RIGHT_CLICK(fn) { wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_LABEL_LEFT_DCLICK(fn) { wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_ROW_SIZE(fn) { wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
+#define EVT_GRID_COL_SIZE(fn) { wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
+#define EVT_GRID_RANGE_SELECT(fn) { wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
+#define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_EDITOR_SHOWN(fn) { wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_EDITOR_HIDDEN(fn) { wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
#if 0 // TODO: implement these ? others ?
-const wxEventType EVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576;
-const wxEventType EVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577;
-const wxEventType EVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578;
+const wxEventType wxEVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576;
+const wxEventType wxEVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577;
+const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578;
-#define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CREATE_CELL(fn) { wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CHANGE_LABELS(fn) { wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CHANGE_SEL_LABEL(fn) { wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
#endif
// implementation
// ============================================================================
-
// ----------------------------------------------------------------------------
// wxGridCellEditor
// ----------------------------------------------------------------------------
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()
{
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();
}
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
//
{
case WXK_ESCAPE:
m_editor->Reset();
- m_grid->EnableCellEditControl(FALSE);
+ m_grid->DisableCellEditControl();
break;
case WXK_TAB:
{
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
}
//
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 );
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::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);
{
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::IsCellEditControlEnabled()
+bool wxGrid::IsCurrentCellReadOnly() const
{
- bool enabled;
+ // const_cast
+ wxGridCellAttr* attr = ((wxGrid *)this)->GetCellAttr(m_currentCellCoords);
+ bool readonly = attr->IsReadOnly();
+ attr->DecRef();
- if ( m_cellEditCtrlEnabled )
- {
- wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords);
- enabled = !attr->IsReadOnly();
- attr->DecRef();
- }
- else
- {
- enabled = FALSE;
- }
+ return readonly;
+}
- return enabled;
+bool wxGrid::CanEnableCellControl() const
+{
+ return m_editable && !IsCurrentCellReadOnly();
+}
+
+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;
}
void wxGrid::ShowCellEditControl()
if (changed)
{
- SendEvent( EVT_GRID_CELL_CHANGE,
+ SendEvent( wxEVT_GRID_CELL_CHANGE,
m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol() );
}
}
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 );