the in-place control uses the attr for colours/font info too
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6089 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
4ed0aceb92
commit
3da93aae50
@ -127,20 +127,19 @@ public:
|
|||||||
// Size and position the edit control
|
// Size and position the edit control
|
||||||
virtual void SetSize(const wxRect& rect);
|
virtual void SetSize(const wxRect& rect);
|
||||||
|
|
||||||
// Show or hide the edit control
|
// Show or hide the edit control, use the specified attributes to set
|
||||||
virtual void Show(bool show);
|
// colours/fonts for it
|
||||||
|
virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);
|
||||||
|
|
||||||
// Fetch the value from the table and prepare the edit control
|
// Fetch the value from the table and prepare the edit control
|
||||||
// to begin editing. Set the focus to the edit control.
|
// to begin editing. Set the focus to the edit control.
|
||||||
virtual void BeginEdit(int row, int col, wxGrid* grid,
|
virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
|
||||||
wxGridCellAttr* attr) = 0;
|
|
||||||
|
|
||||||
// Complete the editing of the current cell. If saveValue is
|
// Complete the editing of the current cell. If saveValue is
|
||||||
// true then send the new value back to the table. Returns true
|
// true then send the new value back to the table. Returns true
|
||||||
// if the value has changed. If necessary, the control may be
|
// if the value has changed. If necessary, the control may be
|
||||||
// destroyed.
|
// destroyed.
|
||||||
virtual bool EndEdit(int row, int col, bool saveValue,
|
virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid) = 0;
|
||||||
wxGrid* grid, wxGridCellAttr* attr) = 0;
|
|
||||||
|
|
||||||
// Reset the value in the control back to its starting value
|
// Reset the value in the control back to its starting value
|
||||||
virtual void Reset() = 0;
|
virtual void Reset() = 0;
|
||||||
@ -158,7 +157,15 @@ public:
|
|||||||
virtual void Destroy();
|
virtual void Destroy();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// the control we show on screen
|
||||||
wxControl* m_control;
|
wxControl* m_control;
|
||||||
|
|
||||||
|
// if we change the colours/font of the control from the default ones, we
|
||||||
|
// must restore the default later and we save them here between calls to
|
||||||
|
// Show(TRUE) and Show(FALSE)
|
||||||
|
wxColour m_colFgOld,
|
||||||
|
m_colBgOld;
|
||||||
|
wxFont m_fontOld;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -171,11 +178,8 @@ public:
|
|||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
wxEvtHandler* evtHandler);
|
wxEvtHandler* evtHandler);
|
||||||
|
|
||||||
virtual void BeginEdit(int row, int col, wxGrid* grid,
|
virtual void BeginEdit(int row, int col, wxGrid* grid);
|
||||||
wxGridCellAttr* attr);
|
virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid);
|
||||||
|
|
||||||
virtual bool EndEdit(int row, int col, bool saveValue,
|
|
||||||
wxGrid* grid, wxGridCellAttr* attr);
|
|
||||||
|
|
||||||
virtual void Reset();
|
virtual void Reset();
|
||||||
virtual void StartingKey(wxKeyEvent& event);
|
virtual void StartingKey(wxKeyEvent& event);
|
||||||
|
@ -297,11 +297,60 @@ void wxGridCellEditor::Destroy()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGridCellEditor::Show(bool show)
|
void wxGridCellEditor::Show(bool show, wxGridCellAttr *attr)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG(m_control,
|
wxASSERT_MSG(m_control,
|
||||||
wxT("The wxGridCellEditor must be Created first!"));
|
wxT("The wxGridCellEditor must be Created first!"));
|
||||||
m_control->Show(show);
|
m_control->Show(show);
|
||||||
|
|
||||||
|
if ( show )
|
||||||
|
{
|
||||||
|
// set the colours/fonts if we have any
|
||||||
|
if ( attr )
|
||||||
|
{
|
||||||
|
if ( attr->HasTextColour() )
|
||||||
|
{
|
||||||
|
m_colFgOld = m_control->GetForegroundColour();
|
||||||
|
m_control->SetForegroundColour(attr->GetTextColour());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( attr->HasBackgroundColour() )
|
||||||
|
{
|
||||||
|
m_colBgOld = m_control->GetBackgroundColour();
|
||||||
|
m_control->SetBackgroundColour(attr->GetBackgroundColour());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( attr->HasFont() )
|
||||||
|
{
|
||||||
|
m_fontOld = m_control->GetFont();
|
||||||
|
m_control->SetFont(attr->GetFont());
|
||||||
|
}
|
||||||
|
|
||||||
|
// can't do anything more in the base class version, the other
|
||||||
|
// attributes may only be used by the derived classes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// restore the standard colours fonts
|
||||||
|
if ( m_colFgOld.Ok() )
|
||||||
|
{
|
||||||
|
m_control->SetForegroundColour(m_colFgOld);
|
||||||
|
m_colFgOld = wxNullColour;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( m_colBgOld.Ok() )
|
||||||
|
{
|
||||||
|
m_control->SetBackgroundColour(m_colBgOld);
|
||||||
|
m_colBgOld = wxNullColour;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( m_fontOld.Ok() )
|
||||||
|
{
|
||||||
|
m_control->SetFont(m_fontOld);
|
||||||
|
m_fontOld = wxNullFont;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGridCellEditor::SetSize(const wxRect& rect)
|
void wxGridCellEditor::SetSize(const wxRect& rect)
|
||||||
@ -343,8 +392,7 @@ void wxGridCellTextEditor::Create(wxWindow* parent,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid,
|
void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid)
|
||||||
wxGridCellAttr* attr)
|
|
||||||
{
|
{
|
||||||
wxASSERT_MSG(m_control,
|
wxASSERT_MSG(m_control,
|
||||||
wxT("The wxGridCellEditor must be Created first!"));
|
wxT("The wxGridCellEditor must be Created first!"));
|
||||||
@ -353,14 +401,12 @@ void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid,
|
|||||||
((wxTextCtrl*)m_control)->SetValue(m_startValue);
|
((wxTextCtrl*)m_control)->SetValue(m_startValue);
|
||||||
((wxTextCtrl*)m_control)->SetInsertionPointEnd();
|
((wxTextCtrl*)m_control)->SetInsertionPointEnd();
|
||||||
((wxTextCtrl*)m_control)->SetFocus();
|
((wxTextCtrl*)m_control)->SetFocus();
|
||||||
|
|
||||||
// ??? Should we use attr and try to set colours and font?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool wxGridCellTextEditor::EndEdit(int row, int col, bool saveValue,
|
bool wxGridCellTextEditor::EndEdit(int row, int col, bool saveValue,
|
||||||
wxGrid* grid, wxGridCellAttr* attr)
|
wxGrid* grid)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG(m_control,
|
wxASSERT_MSG(m_control,
|
||||||
wxT("The wxGridCellEditor must be Created first!"));
|
wxT("The wxGridCellEditor must be Created first!"));
|
||||||
@ -373,7 +419,7 @@ bool wxGridCellTextEditor::EndEdit(int row, int col, bool saveValue,
|
|||||||
if (changed)
|
if (changed)
|
||||||
grid->GetTable()->SetValue(row, col, value);
|
grid->GetTable()->SetValue(row, col, value);
|
||||||
|
|
||||||
m_startValue = "";
|
m_startValue = wxEmptyString;
|
||||||
((wxTextCtrl*)m_control)->SetValue(m_startValue);
|
((wxTextCtrl*)m_control)->SetValue(m_startValue);
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
@ -2908,7 +2954,9 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
|||||||
// the edit control
|
// the edit control
|
||||||
if (m_waitForSlowClick && coords == m_currentCellCoords) {
|
if (m_waitForSlowClick && coords == m_currentCellCoords) {
|
||||||
EnableCellEditControl(TRUE);
|
EnableCellEditControl(TRUE);
|
||||||
ShowCellEditControl();
|
// VZ: this is done by the call above, so why do it
|
||||||
|
// again? please remove this line if it's ok
|
||||||
|
//ShowCellEditControl();
|
||||||
m_waitForSlowClick = FALSE;
|
m_waitForSlowClick = FALSE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -2950,10 +2998,9 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
|||||||
SendEvent( EVT_GRID_RANGE_SELECT, -1, -1, event );
|
SendEvent( EVT_GRID_RANGE_SELECT, -1, -1, event );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the edit control, if it has
|
// Show the edit control, if it has been hidden for
|
||||||
// been hidden for drag-shrinking.
|
// drag-shrinking.
|
||||||
if ( IsCellEditControlEnabled() )
|
ShowCellEditControl();
|
||||||
ShowCellEditControl();
|
|
||||||
}
|
}
|
||||||
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
|
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
|
||||||
{
|
{
|
||||||
@ -4205,8 +4252,11 @@ void wxGrid::ShowCellEditControl()
|
|||||||
int cw, ch;
|
int cw, ch;
|
||||||
m_gridWin->GetClientSize( &cw, &ch );
|
m_gridWin->GetClientSize( &cw, &ch );
|
||||||
|
|
||||||
// Make the edit control large enough to allow for internal margins
|
// Make the edit control large enough to allow for internal
|
||||||
// TODO: remove this if the text ctrl sizing is improved esp. for unix
|
// margins
|
||||||
|
//
|
||||||
|
// TODO: remove this if the text ctrl sizing is improved esp. for
|
||||||
|
// unix
|
||||||
//
|
//
|
||||||
int extra;
|
int extra;
|
||||||
#if defined(__WXMOTIF__)
|
#if defined(__WXMOTIF__)
|
||||||
@ -4247,14 +4297,15 @@ void wxGrid::ShowCellEditControl()
|
|||||||
|
|
||||||
wxGridCellAttr* attr = GetCellAttr(row, col);
|
wxGridCellAttr* attr = GetCellAttr(row, col);
|
||||||
wxGridCellEditor* editor = attr->GetEditor();
|
wxGridCellEditor* editor = attr->GetEditor();
|
||||||
if (! editor->IsCreated()) {
|
if ( !editor->IsCreated() )
|
||||||
|
{
|
||||||
editor->Create(m_gridWin, -1,
|
editor->Create(m_gridWin, -1,
|
||||||
new wxGridCellEditorEvtHandler(this, editor));
|
new wxGridCellEditorEvtHandler(this, editor));
|
||||||
}
|
}
|
||||||
|
|
||||||
editor->SetSize( rect );
|
editor->SetSize( rect );
|
||||||
editor->Show( TRUE );
|
editor->Show( TRUE, attr );
|
||||||
editor->BeginEdit(row, col, this, attr);
|
editor->BeginEdit(row, col, this);
|
||||||
attr->DecRef();
|
attr->DecRef();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4268,7 +4319,7 @@ void wxGrid::HideCellEditControl()
|
|||||||
int row = m_currentCellCoords.GetRow();
|
int row = m_currentCellCoords.GetRow();
|
||||||
int col = m_currentCellCoords.GetCol();
|
int col = m_currentCellCoords.GetCol();
|
||||||
|
|
||||||
wxGridCellAttr* attr = GetCellAttr(row, col);
|
wxGridCellAttr* attr = GetCellAttr(row, col);
|
||||||
attr->GetEditor()->Show( FALSE );
|
attr->GetEditor()->Show( FALSE );
|
||||||
attr->DecRef();
|
attr->DecRef();
|
||||||
m_gridWin->SetFocus();
|
m_gridWin->SetFocus();
|
||||||
@ -4285,16 +4336,18 @@ void wxGrid::SetEditControlValue( const wxString& value )
|
|||||||
|
|
||||||
void wxGrid::SaveEditControlValue()
|
void wxGrid::SaveEditControlValue()
|
||||||
{
|
{
|
||||||
if (IsCellEditControlEnabled()) {
|
if ( IsCellEditControlEnabled() )
|
||||||
|
{
|
||||||
int row = m_currentCellCoords.GetRow();
|
int row = m_currentCellCoords.GetRow();
|
||||||
int col = m_currentCellCoords.GetCol();
|
int col = m_currentCellCoords.GetCol();
|
||||||
|
|
||||||
wxGridCellAttr* attr = GetCellAttr(row, col);
|
wxGridCellAttr* attr = GetCellAttr(row, col);
|
||||||
bool changed = attr->GetEditor()->EndEdit(row, col, TRUE, this, attr);
|
bool changed = attr->GetEditor()->EndEdit(row, col, TRUE, this);
|
||||||
|
|
||||||
attr->DecRef();
|
attr->DecRef();
|
||||||
|
|
||||||
if (changed) {
|
if (changed)
|
||||||
|
{
|
||||||
SendEvent( EVT_GRID_CELL_CHANGE,
|
SendEvent( EVT_GRID_CELL_CHANGE,
|
||||||
m_currentCellCoords.GetRow(),
|
m_currentCellCoords.GetRow(),
|
||||||
m_currentCellCoords.GetCol() );
|
m_currentCellCoords.GetCol() );
|
||||||
|
Loading…
Reference in New Issue
Block a user