/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// default font must be set, independently of document
ScDocShell* pDocSh(dynamic_cast<ScDocShell*>(SfxObjectShell::Current()));
std::unique_ptr<CellAttributeHelper> pTmp; const ScPatternAttr* pCellAttributeDefault(nullptr);
if (nullptr != pDocSh)
{ // we can use default CellAttribute from ScDocument
pCellAttributeDefault = &pDocSh->GetDocument().getCellAttributeHelper().getDefaultCellAttribute();
} else
{ // no access to ScDocument, use temporary default CellAttributeHelper // was: "use global pool from module" which is usually ScMessagePool // and gets set in ScTabViewObj::SelectionChanged() by // ScFormatShell::ScFormatShell which calls // SetPool( &pTabViewShell->GetPool() );
pTmp.reset(new CellAttributeHelper(ScModule::get()->GetPool()));
pCellAttributeDefault = &pTmp->getDefaultCellAttribute();
}
SfxItemSet aDefaults(pHdrEngine->GetEmptyItemSet());
pCellAttributeDefault->FillEditItemSet(&aDefaults); // FillEditItemSet adjusts font height to 1/100th mm, // but for header/footer twips is needed, as in the PatternAttr:
aDefaults.Put( pCellAttributeDefault->GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) );
aDefaults.Put( pCellAttributeDefault->GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) ) ;
aDefaults.Put( pCellAttributeDefault->GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) );
pHdrEngine->SetDefaults(std::move(aDefaults));
ScHeaderFooterTextObj::ScHeaderFooterTextObj( const unotools::WeakReference<ScHeaderFooterContentObj>& xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj) :
aTextData(xContent, nP, pTextObj)
{ // ScHeaderFooterTextData acquires rContent // pUnoText is created on demand (getString/setString work without it)
}
void ScHeaderFooterTextObj::CreateUnoText_Impl()
{ if (!mxUnoText.is())
{ // can't be aggregated because getString/setString is handled here
ScHeaderFooterEditSource aEditSrc(aTextData);
mxUnoText.set(new SvxUnoText(&aEditSrc, lcl_GetHdFtPropertySet(), uno::Reference<text::XText>()));
}
}
// for pure text, no font info is needed in pool defaults
ScHeaderEditEngine aEditEngine(EditEngine::CreatePool().get());
aEditEngine.SetTextCurrentDefaults( aText );
aTextData.UpdateData(aEditEngine);
}
// for bAbsorb=FALSE, the new selection must be behind the inserted content // (the xml filter relies on this) if (!bAbsorb)
aSelection.start.nIndex = aSelection.end.nIndex;
pTextRange->SetSelection( aSelection );
return;
}
}
if (!mxUnoText.is())
CreateUnoText_Impl();
mxUnoText->insertTextContent( xRange, xContent, bAbsorb );
}
void SAL_CALL ScHeaderFooterTextObj::removeTextContent( const uno::Reference<text::XTextContent>& xContent )
{
SolarMutexGuard aGuard; if ( xContent.is() )
{
ScEditFieldObj* pHeaderField = dynamic_cast<ScEditFieldObj*>(xContent.get()); if ( pHeaderField && pHeaderField->IsInserted() )
{ //! check if the field is in this cell
pHeaderField->DeleteField(); return;
}
} if (!mxUnoText.is())
CreateUnoText_Impl();
mxUnoText->removeTextContent( xContent );
}
ScRefCellValue aCell(rDoc, aCellPos); if (aCell.getType() == CELLTYPE_EDIT)
{ const EditTextObject* pObj = aCell.getEditText();
pEditEngine->SetTextNewDefaults(*pObj, std::move(aDefaults));
} else
{
sal_uInt32 nFormat = rDoc.GetNumberFormat(ScRange(aCellPos));
OUString aText = ScCellFormat::GetInputString(aCell, nFormat, nullptr, rDoc); // tdf#157568 check if edit engine already has text // If the input string is empty but the edit engine's existing // text is not empty, force update of the edit engine's text. // Otherwise, the edit engine will still to be set to its // existing text. // Note: CppunitTest_sc_macros_test testTdf116127 will fail if // pEditEngine->SetTextNewDefaults() is passed an empty string // and pEditEngine->GetText() is empty string. if (!aText.isEmpty() || pEditEngine->HasText())
pEditEngine->SetTextNewDefaults(aText, std::move(aDefaults)); else
pEditEngine->SetDefaults(std::move(aDefaults));
}
}
bDataValid = true; return pForwarder.get();
}
void ScCellTextData::UpdateData()
{ if ( bDoUpdate )
{
OSL_ENSURE(pEditEngine != nullptr, "no EditEngine for UpdateData()"); if ( pDocShell && pEditEngine )
{ // during the own UpdateData call, bDataValid must not be reset, // or things like attributes after the text would be lost // (are not stored in the cell)
bInUpdate = true; // prevents bDataValid from being reset
pDocShell->GetDocFunc().PutData(aCellPos, *pEditEngine, true); // always as text
void ScCellTextData::Notify( SfxBroadcaster&, const SfxHint& rHint )
{ const SfxHintId nId = rHint.GetId(); if ( nId == SfxHintId::Dying )
{
pDocShell = nullptr; // invalid now
pForwarder.reset();
pEditEngine.reset(); // EditEngine uses document's pool
} elseif ( nId == SfxHintId::DataChanged )
{ if (!bInUpdate) // not for own UpdateData calls
bDataValid = false; // text has to be read from the cell again
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.