Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / svdraw / svdtext.cxx
blob0fe4fa47d4050eafe85423f2f3ccb44d0bf4fcb8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/svdotext.hxx>
21 #include <svx/svdetc.hxx>
22 #include <editeng/outlobj.hxx>
23 #include <svx/svdoutl.hxx>
24 #include <svx/svdmodel.hxx>
25 #include <svl/itemset.hxx>
26 #include <osl/diagnose.h>
27 #include <libxml/xmlwriter.h>
28 #include <memory>
30 SdrText::SdrText( SdrTextObj& rObject )
31 : mrObject( rObject )
32 , mbPortionInfoChecked( false )
34 OSL_ENSURE(&mrObject, "SdrText created without SdrTextObj (!)");
37 SdrText::~SdrText()
41 void SdrText::CheckPortionInfo( const SdrOutliner& rOutliner )
43 if(mbPortionInfoChecked)
44 return;
46 // #i102062# no action when the Outliner is the HitTestOutliner,
47 // this will remove WrongList info at the OPO
48 if(&rOutliner == &mrObject.getSdrModelFromSdrObject().GetHitTestOutliner())
49 return;
51 // TODO: optimization: we could create a BigTextObject
52 mbPortionInfoChecked=true;
54 if(mpOutlinerParaObject && rOutliner.ShouldCreateBigTextObject())
56 // #i102062# MemoryLeak closed
57 mpOutlinerParaObject = rOutliner.CreateParaObject();
61 void SdrText::ReformatText()
63 mbPortionInfoChecked=false;
64 mpOutlinerParaObject->ClearPortionInfo();
67 const SfxItemSet& SdrText::GetItemSet() const
69 return const_cast< SdrText* >(this)->GetObjectItemSet();
72 void SdrText::SetOutlinerParaObject( std::optional<OutlinerParaObject> pTextObject )
74 mpOutlinerParaObject = std::move(pTextObject);
75 mbPortionInfoChecked = false;
78 OutlinerParaObject* SdrText::GetOutlinerParaObject()
80 return mpOutlinerParaObject ? &*mpOutlinerParaObject : nullptr;
83 const OutlinerParaObject* SdrText::GetOutlinerParaObject() const
85 return mpOutlinerParaObject ? &*mpOutlinerParaObject : nullptr;
88 /** returns the current OutlinerParaObject and removes it from this instance */
89 std::optional<OutlinerParaObject> SdrText::RemoveOutlinerParaObject()
91 std::optional<OutlinerParaObject> pOPO = std::move(mpOutlinerParaObject);
92 mbPortionInfoChecked = false;
93 return pOPO;
96 void SdrText::ForceOutlinerParaObject( OutlinerMode nOutlMode )
98 if(mpOutlinerParaObject)
99 return;
101 std::unique_ptr<Outliner> pOutliner(
102 SdrMakeOutliner(
103 nOutlMode,
104 mrObject.getSdrModelFromSdrObject()));
106 if(pOutliner)
108 Outliner& aDrawOutliner(mrObject.getSdrModelFromSdrObject().GetDrawOutliner());
109 pOutliner->SetCalcFieldValueHdl( aDrawOutliner.GetCalcFieldValueHdl() );
110 pOutliner->SetStyleSheet( 0, GetStyleSheet());
111 SetOutlinerParaObject( pOutliner->CreateParaObject() );
115 const SfxItemSet& SdrText::GetObjectItemSet()
117 return mrObject.GetObjectItemSet();
120 SfxStyleSheet* SdrText::GetStyleSheet() const
122 return mrObject.GetStyleSheet();
125 void SdrText::dumpAsXml(xmlTextWriterPtr pWriter) const
127 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SdrText"));
128 mpOutlinerParaObject->dumpAsXml(pWriter);
129 (void)xmlTextWriterEndElement(pWriter);
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */