1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <hintids.hxx>
22 #include <osl/diagnose.h>
23 #include <txtinet.hxx>
25 #include <fchrfmt.hxx>
26 #include <fmtinfmt.hxx>
27 #include <charfmt.hxx>
29 #include <poolfmt.hxx>
31 #include <fmtruby.hxx>
32 #include <fmtmeta.hxx>
33 #include <IDocumentState.hxx>
34 #include <IDocumentStylePoolAccess.hxx>
37 SwTextCharFormat::SwTextCharFormat( SwFormatCharFormat
& rAttr
,
38 sal_Int32 nStt
, sal_Int32 nEnd
)
39 : SwTextAttr( rAttr
, nStt
)
40 , SwTextAttrEnd( rAttr
, nStt
, nEnd
)
41 , m_pTextNode( nullptr )
44 rAttr
.m_pTextAttribute
= this;
45 SetCharFormatAttr( true );
48 SwTextCharFormat::~SwTextCharFormat( )
52 void SwTextCharFormat::TriggerNodeUpdate(const sw::LegacyModifyHint
& rHint
)
54 const auto nWhich
= rHint
.GetWhich();
57 RES_OBJECTDYING
!= nWhich
&&
58 RES_ATTRSET_CHG
!= nWhich
&&
59 RES_FMT_CHG
!= nWhich
, "sw.core", "SwTextCharFormat::TriggerNodeUpdate: unknown hint type");
63 SwUpdateAttr
aUpdateAttr(
67 m_pTextNode
->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr
, &aUpdateAttr
));
71 bool SwTextCharFormat::GetInfo( SfxPoolItem
const & rInfo
) const
73 return RES_AUTOFMT_DOCNODE
!= rInfo
.Which() || !m_pTextNode
||
74 &m_pTextNode
->GetNodes() != static_cast<SwAutoFormatGetDocNode
const &>(rInfo
).pNodes
;
77 SwTextAttrNesting::SwTextAttrNesting( SfxPoolItem
& i_rAttr
,
78 const sal_Int32 i_nStart
, const sal_Int32 i_nEnd
)
79 : SwTextAttr( i_rAttr
, i_nStart
)
80 , SwTextAttrEnd( i_rAttr
, i_nStart
, i_nEnd
)
82 SetDontExpand( true ); // never expand this attribute
83 // lock the expand flag: simple guarantee that nesting will not be
84 // invalidated by expand operations
85 SetLockExpandFlag( true );
86 SetDontExpandStartAttr( true );
90 SwTextAttrNesting::~SwTextAttrNesting()
94 SwTextINetFormat::SwTextINetFormat( SwFormatINetFormat
& rAttr
,
95 sal_Int32 nStart
, sal_Int32 nEnd
)
96 : SwTextAttr( rAttr
, nStart
)
97 , SwTextAttrNesting( rAttr
, nStart
, nEnd
)
99 , m_pTextNode( nullptr )
100 , m_bVisited( false )
101 , m_bVisitedValid( false )
103 rAttr
.mpTextAttr
= this;
104 SetCharFormatAttr( true );
107 SwTextINetFormat::~SwTextINetFormat( )
111 SwCharFormat
* SwTextINetFormat::GetCharFormat()
113 const SwFormatINetFormat
& rFormat
= SwTextAttrEnd::GetINetFormat();
114 SwCharFormat
* pRet
= nullptr;
116 if (!rFormat
.GetValue().isEmpty())
118 SwDoc
& rDoc
= GetTextNode().GetDoc();
119 if( !IsVisitedValid() )
121 SetVisited( rDoc
.IsVisitedURL( rFormat
.GetValue() ) );
122 SetVisitedValid( true );
125 const sal_uInt16 nId
= IsVisited() ? rFormat
.GetVisitedFormatId() : rFormat
.GetINetFormatId();
126 const OUString
& rStr
= IsVisited() ? rFormat
.GetVisitedFormat() : rFormat
.GetINetFormat();
129 OSL_ENSURE( false, "<SwTextINetFormat::GetCharFormat()> - missing character format at hyperlink attribute");
132 // JP 10.02.2000, Bug 72806: don't modify the doc for getting the
133 // correct charstyle.
134 bool bModifiedEnabled
= rDoc
.getIDocumentState().IsEnableSetModified();
135 rDoc
.getIDocumentState().SetEnableSetModified(false);
137 pRet
= IsPoolUserFormat( nId
)
138 ? rDoc
.FindCharFormatByName( rStr
)
139 : rDoc
.getIDocumentStylePoolAccess().GetCharFormatFromPool( nId
);
141 rDoc
.getIDocumentState().SetEnableSetModified(bModifiedEnabled
);
152 void SwTextINetFormat::SwClientNotify(const SwModify
&, const SfxHint
& rHint
)
154 if (rHint
.GetId() != SfxHintId::SwLegacyModify
)
156 auto pLegacy
= static_cast<const sw::LegacyModifyHint
*>(&rHint
);
157 const auto nWhich
= pLegacy
->GetWhich();
158 OSL_ENSURE(isCHRATR(nWhich
) || (RES_OBJECTDYING
== nWhich
)
159 || (RES_ATTRSET_CHG
== nWhich
) || (RES_FMT_CHG
== nWhich
),
160 "SwTextINetFormat::SwClientNotify: unknown hint.");
164 const SwUpdateAttr
aUpdateAttr(GetStart(), *GetEnd(), nWhich
);
165 m_pTextNode
->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr
, &aUpdateAttr
));
168 bool SwTextINetFormat::GetInfo( SfxPoolItem
& rInfo
) const
170 return RES_AUTOFMT_DOCNODE
!= rInfo
.Which() || !m_pTextNode
||
171 &m_pTextNode
->GetNodes() != static_cast<SwAutoFormatGetDocNode
&>(rInfo
).pNodes
;
174 bool SwTextINetFormat::IsProtect( ) const
176 return m_pTextNode
&& m_pTextNode
->IsProtect();
179 SwTextRuby::SwTextRuby( SwFormatRuby
& rAttr
,
180 sal_Int32 nStart
, sal_Int32 nEnd
)
181 : SwTextAttr( rAttr
, nStart
)
182 , SwTextAttrNesting( rAttr
, nStart
, nEnd
)
183 , SwClient( nullptr )
184 , m_pTextNode( nullptr )
186 rAttr
.m_pTextAttr
= this;
189 SwTextRuby::~SwTextRuby()
193 void SwTextRuby::SwClientNotify(const SwModify
&, const SfxHint
& rHint
)
195 if (rHint
.GetId() != SfxHintId::SwLegacyModify
)
197 auto pLegacy
= static_cast<const sw::LegacyModifyHint
*>(&rHint
);
198 const auto nWhich
= pLegacy
->GetWhich();
199 SAL_WARN_IF( !isCHRATR(nWhich
)
200 && (RES_OBJECTDYING
== nWhich
)
201 && (RES_ATTRSET_CHG
== nWhich
)
202 && (RES_FMT_CHG
== nWhich
), "sw.core", "SwTextRuby::SwClientNotify(): unknown legacy hint");
205 SwUpdateAttr
aUpdateAttr(GetStart(), *GetEnd(), nWhich
);
206 m_pTextNode
->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr
, &aUpdateAttr
));
209 bool SwTextRuby::GetInfo( SfxPoolItem
& rInfo
) const
211 return RES_AUTOFMT_DOCNODE
!= rInfo
.Which() || !m_pTextNode
||
212 &m_pTextNode
->GetNodes() != static_cast<SwAutoFormatGetDocNode
&>(rInfo
).pNodes
;
215 SwCharFormat
* SwTextRuby::GetCharFormat()
217 const SwFormatRuby
& rFormat
= SwTextAttrEnd::GetRuby();
218 SwCharFormat
* pRet
= nullptr;
220 if( !rFormat
.GetText().isEmpty() )
222 const SwDoc
& rDoc
= GetTextNode().GetDoc();
223 const OUString
& rStr
= rFormat
.GetCharFormatName();
224 const sal_uInt16 nId
= rStr
.isEmpty()
225 ? o3tl::narrowing
<sal_uInt16
>(RES_POOLCHR_RUBYTEXT
)
226 : rFormat
.GetCharFormatId();
228 // JP 10.02.2000, Bug 72806: don't modify the doc for getting the
229 // correct charstyle.
230 const bool bResetMod
= !rDoc
.getIDocumentState().IsModified();
231 Link
<bool,void> aOle2Lnk
;
234 aOle2Lnk
= rDoc
.GetOle2Link();
235 const_cast<SwDoc
&>(rDoc
).SetOle2Link( Link
<bool,void>() );
238 pRet
= IsPoolUserFormat( nId
)
239 ? rDoc
.FindCharFormatByName( rStr
)
240 : const_cast<SwDoc
&>(rDoc
).getIDocumentStylePoolAccess().GetCharFormatFromPool( nId
);
244 const_cast<SwDoc
&>(rDoc
).getIDocumentState().ResetModified();
245 const_cast<SwDoc
&>(rDoc
).SetOle2Link( aOle2Lnk
);
258 SwTextMeta::CreateTextMeta(
259 ::sw::MetaFieldManager
& i_rTargetDocManager
,
260 SwTextNode
*const i_pTargetTextNode
,
261 SwFormatMeta
& i_rAttr
,
262 sal_Int32
const i_nStart
,
263 sal_Int32
const i_nEnd
,
264 bool const i_bIsCopy
)
267 { // i_rAttr is already cloned, now call DoCopy to copy the sw::Meta
268 OSL_ENSURE(i_pTargetTextNode
, "cannot copy Meta without target node");
269 i_rAttr
.DoCopy(i_rTargetDocManager
, *i_pTargetTextNode
);
271 SwTextMeta
*const pTextMeta(new SwTextMeta(i_rAttr
, i_nStart
, i_nEnd
));
275 SwTextMeta::SwTextMeta( SwFormatMeta
& i_rAttr
,
276 const sal_Int32 i_nStart
, const sal_Int32 i_nEnd
)
277 : SwTextAttr( i_rAttr
, i_nStart
)
278 , SwTextAttrNesting( i_rAttr
, i_nStart
, i_nEnd
)
280 i_rAttr
.SetTextAttr( this );
281 SetHasDummyChar(true);
284 SwTextMeta::~SwTextMeta()
286 SwFormatMeta
& rFormatMeta( static_cast<SwFormatMeta
&>(GetAttr()) );
287 if (rFormatMeta
.GetTextAttr() == this)
289 rFormatMeta
.SetTextAttr(nullptr);
293 void SwTextMeta::ChgTextNode(SwTextNode
* const pNode
)
295 SwFormatMeta
& rFormatMeta( static_cast<SwFormatMeta
&>(GetAttr()) );
296 if (rFormatMeta
.GetTextAttr() == this)
298 rFormatMeta
.NotifyChangeTextNode(pNode
);
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */