From 3da93aae505563c359f58b357e6c79cd117c5320 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 16 Feb 2000 20:18:53 +0000 Subject: [PATCH] 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 --- include/wx/generic/grid.h | 26 ++++++----- src/generic/grid.cpp | 97 ++++++++++++++++++++++++++++++--------- 2 files changed, 90 insertions(+), 33 deletions(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 7d5e8f02d0..1ab8e0d265 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -127,20 +127,19 @@ public: // Size and position the edit control virtual void SetSize(const wxRect& rect); - // Show or hide the edit control - virtual void Show(bool show); + // Show or hide the edit control, use the specified attributes to set + // colours/fonts for it + virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL); // Fetch the value from the table and prepare the edit control // to begin editing. Set the focus to the edit control. - virtual void BeginEdit(int row, int col, wxGrid* grid, - wxGridCellAttr* attr) = 0; + virtual void BeginEdit(int row, int col, wxGrid* grid) = 0; // Complete the editing of the current cell. If saveValue is // true then send the new value back to the table. Returns true // if the value has changed. If necessary, the control may be // destroyed. - virtual bool EndEdit(int row, int col, bool saveValue, - wxGrid* grid, wxGridCellAttr* attr) = 0; + virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid) = 0; // Reset the value in the control back to its starting value virtual void Reset() = 0; @@ -158,7 +157,15 @@ public: virtual void Destroy(); protected: + // the control we show on screen 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, wxEvtHandler* evtHandler); - virtual void BeginEdit(int row, int col, wxGrid* grid, - wxGridCellAttr* attr); - - virtual bool EndEdit(int row, int col, bool saveValue, - wxGrid* grid, wxGridCellAttr* attr); + virtual void BeginEdit(int row, int col, wxGrid* grid); + virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid); virtual void Reset(); virtual void StartingKey(wxKeyEvent& event); diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 2b687e5ac1..0037328fa8 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -297,11 +297,60 @@ void wxGridCellEditor::Destroy() } } -void wxGridCellEditor::Show(bool show) +void wxGridCellEditor::Show(bool show, wxGridCellAttr *attr) { wxASSERT_MSG(m_control, wxT("The wxGridCellEditor must be Created first!")); 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) @@ -343,8 +392,7 @@ void wxGridCellTextEditor::Create(wxWindow* parent, } -void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid, - wxGridCellAttr* attr) +void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid) { wxASSERT_MSG(m_control, 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)->SetInsertionPointEnd(); ((wxTextCtrl*)m_control)->SetFocus(); - - // ??? Should we use attr and try to set colours and font? } bool wxGridCellTextEditor::EndEdit(int row, int col, bool saveValue, - wxGrid* grid, wxGridCellAttr* attr) + wxGrid* grid) { wxASSERT_MSG(m_control, wxT("The wxGridCellEditor must be Created first!")); @@ -373,7 +419,7 @@ bool wxGridCellTextEditor::EndEdit(int row, int col, bool saveValue, if (changed) grid->GetTable()->SetValue(row, col, value); - m_startValue = ""; + m_startValue = wxEmptyString; ((wxTextCtrl*)m_control)->SetValue(m_startValue); return changed; @@ -2908,7 +2954,9 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event ) // the edit control if (m_waitForSlowClick && coords == m_currentCellCoords) { 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; } else { @@ -2950,10 +2998,9 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event ) SendEvent( EVT_GRID_RANGE_SELECT, -1, -1, event ); } - // Show the edit control, if it has - // been hidden for drag-shrinking. - if ( IsCellEditControlEnabled() ) - ShowCellEditControl(); + // Show the edit control, if it has been hidden for + // drag-shrinking. + ShowCellEditControl(); } else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW ) { @@ -4205,8 +4252,11 @@ void wxGrid::ShowCellEditControl() int cw, ch; m_gridWin->GetClientSize( &cw, &ch ); - // Make the edit control large enough to allow for internal margins - // TODO: remove this if the text ctrl sizing is improved esp. for unix + // 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__) @@ -4247,14 +4297,15 @@ void wxGrid::ShowCellEditControl() wxGridCellAttr* attr = GetCellAttr(row, col); wxGridCellEditor* editor = attr->GetEditor(); - if (! editor->IsCreated()) { + if ( !editor->IsCreated() ) + { editor->Create(m_gridWin, -1, new wxGridCellEditorEvtHandler(this, editor)); } editor->SetSize( rect ); - editor->Show( TRUE ); - editor->BeginEdit(row, col, this, attr); + editor->Show( TRUE, attr ); + editor->BeginEdit(row, col, this); attr->DecRef(); } } @@ -4268,7 +4319,7 @@ void wxGrid::HideCellEditControl() int row = m_currentCellCoords.GetRow(); int col = m_currentCellCoords.GetCol(); - wxGridCellAttr* attr = GetCellAttr(row, col); + wxGridCellAttr* attr = GetCellAttr(row, col); attr->GetEditor()->Show( FALSE ); attr->DecRef(); m_gridWin->SetFocus(); @@ -4285,16 +4336,18 @@ void wxGrid::SetEditControlValue( const wxString& value ) void wxGrid::SaveEditControlValue() { - if (IsCellEditControlEnabled()) { + if ( IsCellEditControlEnabled() ) + { int row = m_currentCellCoords.GetRow(); int col = m_currentCellCoords.GetCol(); - wxGridCellAttr* attr = GetCellAttr(row, col); - bool changed = attr->GetEditor()->EndEdit(row, col, TRUE, this, attr); + wxGridCellAttr* attr = GetCellAttr(row, col); + bool changed = attr->GetEditor()->EndEdit(row, col, TRUE, this); attr->DecRef(); - if (changed) { + if (changed) + { SendEvent( EVT_GRID_CELL_CHANGE, m_currentCellCoords.GetRow(), m_currentCellCoords.GetCol() ); -- 2.45.2