Kaydet (Commit) 7295ca03 authored tarafından Kohei Yoshida's avatar Kohei Yoshida Kaydeden (comit) Kohei Yoshida

Use std::unique_ptr for pEditEngine.

And rename it to mpEditEngine.

Change-Id: Iacaad04ca476bfb5b5e35e6e29f372812c40b3bc
Reviewed-on: https://gerrit.libreoffice.org/30945Reviewed-by: 's avatarKohei Yoshida <libreoffice@kohei.us>
Tested-by: 's avatarKohei Yoshida <libreoffice@kohei.us>
üst f32da6e7
...@@ -1044,13 +1044,13 @@ void ScTextWnd::Resize() ...@@ -1044,13 +1044,13 @@ void ScTextWnd::Resize()
mpEditView->SetOutputArea( aOutputArea ); mpEditView->SetOutputArea( aOutputArea );
// Don't leave an empty area at the bottom if we can move the text down. // Don't leave an empty area at the bottom if we can move the text down.
long nMaxVisAreaTop = pEditEngine->GetTextHeight() - aOutputArea.GetHeight(); long nMaxVisAreaTop = mpEditEngine->GetTextHeight() - aOutputArea.GetHeight();
if (mpEditView->GetVisArea().Top() > nMaxVisAreaTop) if (mpEditView->GetVisArea().Top() > nMaxVisAreaTop)
{ {
mpEditView->Scroll(0, mpEditView->GetVisArea().Top() - nMaxVisAreaTop); mpEditView->Scroll(0, mpEditView->GetVisArea().Top() - nMaxVisAreaTop);
} }
pEditEngine->SetPaperSize( PixelToLogic( Size( aOutputSize.Width(), 10000 ) ) ); mpEditEngine->SetPaperSize( PixelToLogic( Size( aOutputSize.Width(), 10000 ) ) );
} }
SetScrollBarRange(); SetScrollBarRange();
...@@ -1092,7 +1092,7 @@ void ScTextWnd::StartEditEngine() ...@@ -1092,7 +1092,7 @@ void ScTextWnd::StartEditEngine()
if ( pObjSh && pObjSh->IsInModalMode() ) if ( pObjSh && pObjSh->IsInModalMode() )
return; return;
if ( !mpEditView || !pEditEngine ) if ( !mpEditView || !mpEditEngine )
{ {
InitEditEngine(); InitEditEngine();
} }
...@@ -1165,37 +1165,37 @@ static void lcl_ModifyRTLVisArea( EditView* pEditView ) ...@@ -1165,37 +1165,37 @@ static void lcl_ModifyRTLVisArea( EditView* pEditView )
void ScTextWnd::InitEditEngine() void ScTextWnd::InitEditEngine()
{ {
ScFieldEditEngine* pNew; std::unique_ptr<ScFieldEditEngine> pNew;
ScDocShell* pDocSh = nullptr; ScDocShell* pDocSh = nullptr;
if ( mpViewShell ) if ( mpViewShell )
{ {
pDocSh = mpViewShell->GetViewData().GetDocShell(); pDocSh = mpViewShell->GetViewData().GetDocShell();
ScDocument* pDoc = mpViewShell->GetViewData().GetDocument(); ScDocument* pDoc = mpViewShell->GetViewData().GetDocument();
pNew = new ScFieldEditEngine(pDoc, pDoc->GetEnginePool(), pDoc->GetEditPool()); pNew = o3tl::make_unique<ScFieldEditEngine>(pDoc, pDoc->GetEnginePool(), pDoc->GetEditPool());
} }
else else
pNew = new ScFieldEditEngine(nullptr, EditEngine::CreatePool(), nullptr, true); pNew = o3tl::make_unique<ScFieldEditEngine>(nullptr, EditEngine::CreatePool(), nullptr, true);
pNew->SetExecuteURL( false ); pNew->SetExecuteURL( false );
pEditEngine = pNew; mpEditEngine = std::move(pNew);
Size barSize=GetSizePixel(); Size barSize=GetSizePixel();
pEditEngine->SetUpdateMode( false ); mpEditEngine->SetUpdateMode( false );
pEditEngine->SetPaperSize( PixelToLogic(Size(barSize.Width(),10000)) ); mpEditEngine->SetPaperSize( PixelToLogic(Size(barSize.Width(),10000)) );
pEditEngine->SetWordDelimiters( mpEditEngine->SetWordDelimiters(
ScEditUtil::ModifyDelimiters( pEditEngine->GetWordDelimiters() ) ); ScEditUtil::ModifyDelimiters( mpEditEngine->GetWordDelimiters() ) );
pEditEngine->SetReplaceLeadingSingleQuotationMark( false ); mpEditEngine->SetReplaceLeadingSingleQuotationMark( false );
UpdateAutoCorrFlag(); UpdateAutoCorrFlag();
{ {
SfxItemSet* pSet = new SfxItemSet( pEditEngine->GetEmptyItemSet() ); SfxItemSet* pSet = new SfxItemSet( mpEditEngine->GetEmptyItemSet() );
EditEngine::SetFontInfoInItemSet( *pSet, aTextFont ); EditEngine::SetFontInfoInItemSet( *pSet, aTextFont );
lcl_ExtendEditFontAttribs( *pSet ); lcl_ExtendEditFontAttribs( *pSet );
// turn off script spacing to match DrawText output // turn off script spacing to match DrawText output
pSet->Put( SvxScriptSpaceItem( false, EE_PARA_ASIANCJKSPACING ) ); pSet->Put( SvxScriptSpaceItem( false, EE_PARA_ASIANCJKSPACING ) );
if ( bIsRTL ) if ( bIsRTL )
lcl_ModifyRTLDefaults( *pSet ); lcl_ModifyRTLDefaults( *pSet );
pEditEngine->SetDefaults( pSet ); mpEditEngine->SetDefaults( pSet );
} }
// If the Cell contains URLFields, they need to be taken over into the entry row, // If the Cell contains URLFields, they need to be taken over into the entry row,
...@@ -1203,32 +1203,32 @@ void ScTextWnd::InitEditEngine() ...@@ -1203,32 +1203,32 @@ void ScTextWnd::InitEditEngine()
bool bFilled = false; bool bFilled = false;
ScInputHandler* pHdl = SC_MOD()->GetInputHdl(); ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
if ( pHdl ) //! Test if it's the right InputHdl? if ( pHdl ) //! Test if it's the right InputHdl?
bFilled = pHdl->GetTextAndFields( *pEditEngine ); bFilled = pHdl->GetTextAndFields( *mpEditEngine );
pEditEngine->SetUpdateMode( true ); mpEditEngine->SetUpdateMode( true );
// aString is the truth ... // aString is the truth ...
if (bFilled && pEditEngine->GetText() == aString) if (bFilled && mpEditEngine->GetText() == aString)
Invalidate(); // Repaint for (filled) Field Invalidate(); // Repaint for (filled) Field
else else
pEditEngine->SetText(aString); // At least the right text then mpEditEngine->SetText(aString); // At least the right text then
mpEditView = o3tl::make_unique<EditView>(pEditEngine, this); mpEditView = o3tl::make_unique<EditView>(mpEditEngine.get(), this);
mpEditView->SetInsertMode(bIsInsertMode); mpEditView->SetInsertMode(bIsInsertMode);
// Text from Clipboard is taken over as ASCII in a single row // Text from Clipboard is taken over as ASCII in a single row
EVControlBits n = mpEditView->GetControlWord(); EVControlBits n = mpEditView->GetControlWord();
mpEditView->SetControlWord( n | EVControlBits::SINGLELINEPASTE ); mpEditView->SetControlWord( n | EVControlBits::SINGLELINEPASTE );
pEditEngine->InsertView( mpEditView.get(), EE_APPEND ); mpEditEngine->InsertView( mpEditView.get(), EE_APPEND );
Resize(); Resize();
if ( bIsRTL ) if ( bIsRTL )
lcl_ModifyRTLVisArea( mpEditView.get() ); lcl_ModifyRTLVisArea( mpEditView.get() );
pEditEngine->SetModifyHdl(LINK(this, ScTextWnd, ModifyHdl)); mpEditEngine->SetModifyHdl(LINK(this, ScTextWnd, ModifyHdl));
pEditEngine->SetNotifyHdl(LINK(this, ScTextWnd, NotifyHdl)); mpEditEngine->SetNotifyHdl(LINK(this, ScTextWnd, NotifyHdl));
if (!maAccTextDatas.empty()) if (!maAccTextDatas.empty())
maAccTextDatas.back()->StartEdit(); maAccTextDatas.back()->StartEdit();
...@@ -1247,7 +1247,7 @@ void ScTextWnd::InitEditEngine() ...@@ -1247,7 +1247,7 @@ void ScTextWnd::InitEditEngine()
ScTextWnd::ScTextWnd(ScInputBarGroup* pParent, ScTabViewShell* pViewSh) ScTextWnd::ScTextWnd(ScInputBarGroup* pParent, ScTabViewShell* pViewSh)
: ScTextWndBase(pParent, WinBits(WB_HIDE | WB_BORDER)), : ScTextWndBase(pParent, WinBits(WB_HIDE | WB_BORDER)),
DragSourceHelper(this), DragSourceHelper(this),
pEditEngine (nullptr), mpEditEngine (nullptr),
mpEditView (nullptr), mpEditView (nullptr),
bIsInsertMode(true), bIsInsertMode(true),
bFormulaMode (false), bFormulaMode (false),
...@@ -1305,8 +1305,7 @@ void ScTextWnd::dispose() ...@@ -1305,8 +1305,7 @@ void ScTextWnd::dispose()
maAccTextDatas.back()->Dispose(); maAccTextDatas.back()->Dispose();
} }
mpEditView.reset(); mpEditView.reset();
delete pEditEngine; mpEditEngine.reset();
pEditEngine = nullptr;
DragSourceHelper::dispose(); DragSourceHelper::dispose();
ScTextWndBase::dispose(); ScTextWndBase::dispose();
...@@ -1468,8 +1467,8 @@ void ScTextWnd::LoseFocus() ...@@ -1468,8 +1467,8 @@ void ScTextWnd::LoseFocus()
OUString ScTextWnd::GetText() const OUString ScTextWnd::GetText() const
{ {
// Override to get the text via the testtool // Override to get the text via the testtool
if ( pEditEngine ) if ( mpEditEngine )
return pEditEngine->GetText(); return mpEditEngine->GetText();
else else
return GetTextString(); return GetTextString();
} }
...@@ -1485,9 +1484,9 @@ void ScTextWnd::SetFormulaMode( bool bSet ) ...@@ -1485,9 +1484,9 @@ void ScTextWnd::SetFormulaMode( bool bSet )
void ScTextWnd::UpdateAutoCorrFlag() void ScTextWnd::UpdateAutoCorrFlag()
{ {
if ( pEditEngine ) if ( mpEditEngine )
{ {
EEControlBits nControl = pEditEngine->GetControlWord(); EEControlBits nControl = mpEditEngine->GetControlWord();
EEControlBits nOld = nControl; EEControlBits nOld = nControl;
if ( bFormulaMode ) if ( bFormulaMode )
nControl &= ~EEControlBits::AUTOCORRECT; // No AutoCorrect in Formulas nControl &= ~EEControlBits::AUTOCORRECT; // No AutoCorrect in Formulas
...@@ -1495,7 +1494,7 @@ void ScTextWnd::UpdateAutoCorrFlag() ...@@ -1495,7 +1494,7 @@ void ScTextWnd::UpdateAutoCorrFlag()
nControl |= EEControlBits::AUTOCORRECT; // Else do enable it nControl |= EEControlBits::AUTOCORRECT; // Else do enable it
if ( nControl != nOld ) if ( nControl != nOld )
pEditEngine->SetControlWord( nControl ); mpEditEngine->SetControlWord( nControl );
} }
} }
...@@ -1527,10 +1526,10 @@ IMPL_LINK_NOARG(ScTextWnd, ModifyHdl, LinkParamNone*, void) ...@@ -1527,10 +1526,10 @@ IMPL_LINK_NOARG(ScTextWnd, ModifyHdl, LinkParamNone*, void)
void ScTextWnd::StopEditEngine( bool bAll ) void ScTextWnd::StopEditEngine( bool bAll )
{ {
if (!pEditEngine) if (!mpEditEngine)
return; return;
pEditEngine->SetNotifyHdl(Link<EENotify&, void>()); mpEditEngine->SetNotifyHdl(Link<EENotify&, void>());
if (mpEditView) if (mpEditView)
{ {
...@@ -1541,12 +1540,12 @@ void ScTextWnd::StopEditEngine( bool bAll ) ...@@ -1541,12 +1540,12 @@ void ScTextWnd::StopEditEngine( bool bAll )
if (!bAll) if (!bAll)
pScMod->InputSelection( mpEditView.get() ); pScMod->InputSelection( mpEditView.get() );
aString = pEditEngine->GetText(); aString = mpEditEngine->GetText();
bIsInsertMode = mpEditView->IsInsertMode(); bIsInsertMode = mpEditView->IsInsertMode();
bool bSelection = mpEditView->HasSelection(); bool bSelection = mpEditView->HasSelection();
pEditEngine->SetModifyHdl(Link<LinkParamNone*,void>()); mpEditEngine->SetModifyHdl(Link<LinkParamNone*,void>());
mpEditView.reset(); mpEditView.reset();
DELETEZ(pEditEngine); mpEditEngine.reset();
if ( pScMod->IsEditMode() && !bAll ) if ( pScMod->IsEditMode() && !bAll )
pScMod->SetInputMode(SC_INPUT_TABLE); pScMod->SetInputMode(SC_INPUT_TABLE);
...@@ -1593,7 +1592,7 @@ void ScTextWnd::SetTextString( const OUString& rNewString ) ...@@ -1593,7 +1592,7 @@ void ScTextWnd::SetTextString( const OUString& rNewString )
bInputMode = true; bInputMode = true;
// Find position of the change, only paint the rest // Find position of the change, only paint the rest
if (!pEditEngine) if (!mpEditEngine)
{ {
bool bPaintAll; bool bPaintAll;
if ( bIsRTL ) if ( bIsRTL )
...@@ -1650,7 +1649,7 @@ void ScTextWnd::SetTextString( const OUString& rNewString ) ...@@ -1650,7 +1649,7 @@ void ScTextWnd::SetTextString( const OUString& rNewString )
} }
else else
{ {
pEditEngine->SetText(rNewString); mpEditEngine->SetText(rNewString);
} }
aString = rNewString; aString = rNewString;
...@@ -1679,32 +1678,32 @@ void ScTextWnd::MakeDialogEditView() ...@@ -1679,32 +1678,32 @@ void ScTextWnd::MakeDialogEditView()
{ {
if ( mpEditView ) return; if ( mpEditView ) return;
ScFieldEditEngine* pNew; std::unique_ptr<ScFieldEditEngine> pNew;
ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
if ( pViewSh ) if ( pViewSh )
{ {
ScDocument* pDoc = pViewSh->GetViewData().GetDocument(); ScDocument* pDoc = pViewSh->GetViewData().GetDocument();
pNew = new ScFieldEditEngine(pDoc, pDoc->GetEnginePool(), pDoc->GetEditPool()); pNew = o3tl::make_unique<ScFieldEditEngine>(pDoc, pDoc->GetEnginePool(), pDoc->GetEditPool());
} }
else else
pNew = new ScFieldEditEngine(nullptr, EditEngine::CreatePool(), nullptr, true); pNew = o3tl::make_unique<ScFieldEditEngine>(nullptr, EditEngine::CreatePool(), nullptr, true);
pNew->SetExecuteURL( false ); pNew->SetExecuteURL( false );
pEditEngine = pNew; mpEditEngine = std::move(pNew);
pEditEngine->SetUpdateMode( false ); mpEditEngine->SetUpdateMode( false );
pEditEngine->SetWordDelimiters( pEditEngine->GetWordDelimiters() + "=" ); mpEditEngine->SetWordDelimiters( mpEditEngine->GetWordDelimiters() + "=" );
pEditEngine->SetPaperSize( Size( bIsRTL ? USHRT_MAX : THESIZE, 300 ) ); mpEditEngine->SetPaperSize( Size( bIsRTL ? USHRT_MAX : THESIZE, 300 ) );
SfxItemSet* pSet = new SfxItemSet( pEditEngine->GetEmptyItemSet() ); SfxItemSet* pSet = new SfxItemSet( mpEditEngine->GetEmptyItemSet() );
EditEngine::SetFontInfoInItemSet( *pSet, aTextFont ); EditEngine::SetFontInfoInItemSet( *pSet, aTextFont );
lcl_ExtendEditFontAttribs( *pSet ); lcl_ExtendEditFontAttribs( *pSet );
if ( bIsRTL ) if ( bIsRTL )
lcl_ModifyRTLDefaults( *pSet ); lcl_ModifyRTLDefaults( *pSet );
pEditEngine->SetDefaults( pSet ); mpEditEngine->SetDefaults( pSet );
pEditEngine->SetUpdateMode( true ); mpEditEngine->SetUpdateMode( true );
mpEditView = o3tl::make_unique<EditView>(pEditEngine, this); mpEditView = o3tl::make_unique<EditView>(mpEditEngine.get(), this);
pEditEngine->InsertView( mpEditView.get(), EE_APPEND ); mpEditEngine->InsertView( mpEditView.get(), EE_APPEND );
Resize(); Resize();
......
...@@ -130,7 +130,7 @@ private: ...@@ -130,7 +130,7 @@ private:
OUString aString; OUString aString;
vcl::Font aTextFont; vcl::Font aTextFont;
ScEditEngineDefaulter* pEditEngine; // only created when needed std::unique_ptr<ScEditEngineDefaulter> mpEditEngine; // only created when needed
std::unique_ptr<EditView> mpEditView; std::unique_ptr<EditView> mpEditView;
AccTextDataVector maAccTextDatas; // #i105267# text datas may be cloned, remember all copies AccTextDataVector maAccTextDatas; // #i105267# text datas may be cloned, remember all copies
bool bIsRTL; bool bIsRTL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment