Files
odfstudio/editeng/source/outliner/outlobj.cxx
T
Noel Grandin fcf0bcc0f9 Hold EditTextObject by value in OutlinerParaObjData, not by pointer
OutlinerParaObjData is already ref-counted data, no need
for further indirection.

Unfortunately, this sets off a larger chain of changes
than I would have preferred, but we end up storing
EditTextObject on the stack much more than before, so
that worked out well.

Change-Id: Ie7d0ccfbfeec4e6935f2ed6b8ad48aadfe1bac20
Signed-off-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/10973
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
(cherry picked from commit fbf7d1bc7142d3f0e4e5f959983dea065afc5ea3)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/210927
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-09-14 16:27:02 +02:00

204 lines
5.2 KiB
C++

/* -*- 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 .
*/
#include <editeng/outliner.hxx>
#include <editeng/outlobj.hxx>
#include <editeng/editobj.hxx>
#include <sal/log.hxx>
#include <osl/diagnose.h>
#include <o3tl/cow_wrapper.hxx>
#include <o3tl/safeint.hxx>
#include <libxml/xmlwriter.h>
OutlinerParaObject::OutlinerParaObject( EditTextObject&& aTextObj ) :
mpImpl(std::move(aTextObj))
{
}
OutlinerParaObject::OutlinerParaObject( const OutlinerParaObject& r ) :
mpImpl(r.mpImpl)
{
}
OutlinerParaObject::OutlinerParaObject( OutlinerParaObject&& r ) noexcept :
mpImpl(std::move(r.mpImpl))
{
}
OutlinerParaObject::~OutlinerParaObject()
{
}
OutlinerParaObject& OutlinerParaObject::operator=( const OutlinerParaObject& r )
{
mpImpl = r.mpImpl;
return *this;
}
OutlinerParaObject& OutlinerParaObject::operator=( OutlinerParaObject&& r ) noexcept
{
mpImpl = std::move(r.mpImpl);
return *this;
}
bool OutlinerParaObject::operator==( const OutlinerParaObject& r ) const
{
return r.mpImpl == mpImpl;
}
// #i102062#
bool OutlinerParaObject::isWrongListEqual( const OutlinerParaObject& r ) const
{
if (r.mpImpl.same_object(mpImpl))
{
return true;
}
return mpImpl->isWrongListEqual(*r.mpImpl);
}
OutlinerMode OutlinerParaObject::GetOutlinerMode() const
{
return mpImpl->GetUserType();
}
void OutlinerParaObject::SetOutlinerMode(OutlinerMode nNew)
{
// create a const pointer to avoid an early call to
// make_unique() in the dereference of mpImpl
const ::o3tl::cow_wrapper< EditTextObject >* pImpl = &mpImpl;
if ( ( *pImpl )->GetUserType() != nNew )
{
mpImpl->SetUserType(nNew);
}
}
bool OutlinerParaObject::IsEffectivelyVertical() const
{
return mpImpl->IsEffectivelyVertical();
}
bool OutlinerParaObject::GetVertical() const
{
return mpImpl->GetVertical();
}
bool OutlinerParaObject::IsTopToBottom() const
{
return mpImpl->IsTopToBottom();
}
void OutlinerParaObject::SetVertical(bool bNew)
{
const ::o3tl::cow_wrapper< EditTextObject >* pImpl = &mpImpl;
if ( ( *pImpl )->IsEffectivelyVertical() != bNew)
{
mpImpl->SetVertical(bNew);
}
}
void OutlinerParaObject::SetRotation(TextRotation nRotation)
{
mpImpl->SetRotation(nRotation);
}
TextRotation OutlinerParaObject::GetRotation() const
{
return mpImpl->GetRotation();
}
sal_Int32 OutlinerParaObject::Count() const
{
size_t nSize = mpImpl->GetParagraphCount();
if (nSize > o3tl::make_unsigned(EE_PARA_MAX))
{
SAL_WARN( "editeng", "OutlinerParaObject::Count - overflow " << nSize);
return EE_PARA_MAX;
}
return static_cast<sal_Int32>(nSize);
}
sal_Int16 OutlinerParaObject::GetNumberingDepth(sal_Int32 nPara) const
{
return mpImpl->GetNumberingDepth(nPara);
}
sal_Int16 OutlinerParaObject::GetNumberingStartValue(sal_Int32 nPara) const
{
return mpImpl->GetNumberingStartValue(nPara);
}
bool OutlinerParaObject::IsNumberingRestart(sal_Int32 nPara) const
{
return mpImpl->IsNumberingRestart(nPara);
}
const EditTextObject& OutlinerParaObject::GetTextObject() const
{
return *mpImpl;
}
void OutlinerParaObject::ClearPortionInfo()
{
mpImpl->ClearPortionInfo();
}
bool OutlinerParaObject::ChangeStyleSheets(std::u16string_view rOldName,
SfxStyleFamily eOldFamily, const OUString& rNewName, SfxStyleFamily eNewFamily)
{
return mpImpl->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily);
}
void OutlinerParaObject::ChangeStyleSheetName(SfxStyleFamily eFamily,
std::u16string_view rOldName, const OUString& rNewName)
{
mpImpl->ChangeStyleSheetName(eFamily, rOldName, rNewName);
}
void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString& rNewName,
const SfxStyleFamily& rNewFamily)
{
const sal_Int32 nCount(Count());
if(nCount)
{
sal_Int32 nDecrementer(nCount);
while(nDecrementer > 0)
{
if(GetNumberingDepth(--nDecrementer) == nLevel)
{
mpImpl->SetStyleSheet(nDecrementer, rNewName, rNewFamily);
}
}
}
}
void OutlinerParaObject::dumpAsXml(xmlTextWriterPtr pWriter) const
{
(void)xmlTextWriterStartElement(pWriter, BAD_CAST("OutlinerParaObject"));
(void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
mpImpl->dumpAsXml(pWriter);
(void)xmlTextWriterEndElement(pWriter);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */