xref: /trunk/main/sw/source/core/txtnode/txtatr2.cxx (revision 56b35d86)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #include <hintids.hxx>
28 #include <hints.hxx>
29 #include <sfx2/objsh.hxx>
30 #include <editeng/xmlcnitm.hxx>
31 #include <editeng/twolinesitem.hxx>
32 #include <txtinet.hxx>
33 #include <txtatr.hxx>
34 #include <fchrfmt.hxx>
35 #include <fmtinfmt.hxx>
36 #include <charfmt.hxx>
37 #include <ndtxt.hxx>        // SwCharFmt, SwTxtNode
38 #include <poolfmt.hxx>		// RES_POOLCHR_INET_...
39 #include <doc.hxx>			// SwDoc
40 #include <fmtruby.hxx>
41 #include <fmtmeta.hxx>
42 
43 
44 TYPEINIT1(SwTxtINetFmt,SwClient);
45 TYPEINIT1(SwTxtRuby,SwClient);
46 
47 
48 /*************************************************************************
49  *						class SwTxtCharFmt
50  *************************************************************************/
51 
SwTxtCharFmt(SwFmtCharFmt & rAttr,xub_StrLen nStt,xub_StrLen nEnde)52 SwTxtCharFmt::SwTxtCharFmt( SwFmtCharFmt& rAttr,
53                     xub_StrLen nStt, xub_StrLen nEnde )
54     : SwTxtAttrEnd( rAttr, nStt, nEnde )
55     , m_pTxtNode( 0 )
56     , m_nSortNumber( 0 )
57 {
58 	rAttr.pTxtAttr = this;
59 	SetCharFmtAttr( sal_True );
60 }
61 
~SwTxtCharFmt()62 SwTxtCharFmt::~SwTxtCharFmt( )
63 {
64 }
65 
ModifyNotification(const SfxPoolItem * pOld,const SfxPoolItem * pNew)66 void SwTxtCharFmt::ModifyNotification( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
67 {
68 	sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
69     ASSERT(  isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
70              || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
71         "SwTxtCharFmt::Modify(): unknown Modify");
72 
73     if ( m_pTxtNode )
74     {
75         SwUpdateAttr aUpdateAttr(
76             *GetStart(),
77             *GetEnd(),
78             nWhich);
79 
80         m_pTxtNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
81     }
82 }
83 
GetInfo(SfxPoolItem & rInfo) const84 bool SwTxtCharFmt::GetInfo( SfxPoolItem& rInfo ) const
85 {
86     if ( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
87         &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
88     {
89 		return true;
90     }
91 
92     static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
93 	return false;
94 }
95 
96 
97 /*************************************************************************
98  *                        class SwTxtAttrNesting
99  *************************************************************************/
100 
SwTxtAttrNesting(SfxPoolItem & i_rAttr,const xub_StrLen i_nStart,const xub_StrLen i_nEnd)101 SwTxtAttrNesting::SwTxtAttrNesting( SfxPoolItem & i_rAttr,
102             const xub_StrLen i_nStart, const xub_StrLen i_nEnd )
103     : SwTxtAttrEnd( i_rAttr, i_nStart, i_nEnd )
104 {
105     SetDontExpand( true );  // never expand this attribute
106     // lock the expand flag: simple guarantee that nesting will not be
107     // invalidated by expand operations
108     SetLockExpandFlag( true );
109     SetDontExpandStartAttr( true );
110     SetNesting( true );
111 }
112 
~SwTxtAttrNesting()113 SwTxtAttrNesting::~SwTxtAttrNesting()
114 {
115 }
116 
117 
118 /*************************************************************************
119  *						class SwTxtINetFmt
120  *************************************************************************/
121 
SwTxtINetFmt(SwFmtINetFmt & rAttr,xub_StrLen nStart,xub_StrLen nEnd)122 SwTxtINetFmt::SwTxtINetFmt( SwFmtINetFmt& rAttr,
123                             xub_StrLen nStart, xub_StrLen nEnd )
124     : SwTxtAttrNesting( rAttr, nStart, nEnd )
125     , SwClient( 0 )
126     , m_pTxtNode( 0 )
127     , m_bVisited( false )
128     , m_bVisitedValid( false )
129 {
130     rAttr.mpTxtAttr  = this;
131     SetCharFmtAttr( true );
132 }
133 
~SwTxtINetFmt()134 SwTxtINetFmt::~SwTxtINetFmt( )
135 {
136 }
137 
GetCharFmt()138 SwCharFmt* SwTxtINetFmt::GetCharFmt()
139 {
140     const SwFmtINetFmt& rFmt = SwTxtAttrEnd::GetINetFmt();
141     SwCharFmt* pRet = NULL;
142 
143     if ( rFmt.GetValue().Len() )
144     {
145         const SwDoc* pDoc = GetTxtNode().GetDoc();
146         if( !IsVisitedValid() )
147         {
148             SetVisited( pDoc->IsVisitedURL( rFmt.GetValue() ) );
149             SetVisitedValid( true );
150         }
151 
152         const sal_uInt16 nId = IsVisited() ? rFmt.GetVisitedFmtId() : rFmt.GetINetFmtId();
153         const String& rStr = IsVisited() ? rFmt.GetVisitedFmt() : rFmt.GetINetFmt();
154         if ( rStr.Len() == 0 )
155         {
156             ASSERT( false, "<SwTxtINetFmt::GetCharFmt()> - missing character format at hyperlink attribute");
157         }
158 
159         // JP 10.02.2000, Bug 72806: dont modify the doc for getting the
160         //		correct charstyle.
161         sal_Bool bResetMod = !pDoc->IsModified();
162         Link aOle2Lnk;
163         if ( bResetMod )
164         {
165             aOle2Lnk = pDoc->GetOle2Link();
166             ( (SwDoc*) pDoc )->SetOle2Link( Link() );
167         }
168 
169         pRet = IsPoolUserFmt( nId )
170                ? ( (SwDoc*) pDoc )->FindCharFmtByName( rStr )
171                : ( (SwDoc*) pDoc )->GetCharFmtFromPool( nId );
172 
173         if ( bResetMod )
174         {
175             ( (SwDoc*) pDoc )->ResetModified();
176             ( (SwDoc*) pDoc )->SetOle2Link( aOle2Lnk );
177         }
178     }
179 
180     if ( pRet )
181         pRet->Add( this );
182     else if ( GetRegisteredIn() )
183         GetRegisteredInNonConst()->Remove( this );
184 
185     return pRet;
186 }
187 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)188 void SwTxtINetFmt::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
189 {
190 	sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
191     ASSERT(  isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
192              || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
193         "SwTxtINetFmt::Modify(): unknown Modify");
194 
195     if ( m_pTxtNode )
196     {
197         SwUpdateAttr aUpdateAttr(
198             *GetStart(),
199             *GetEnd(),
200             nWhich);
201 
202         m_pTxtNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
203     }
204 }
205 
206 	// erfrage vom Modify Informationen
GetInfo(SfxPoolItem & rInfo) const207 sal_Bool SwTxtINetFmt::GetInfo( SfxPoolItem& rInfo ) const
208 {
209     if ( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
210         &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
211     {
212 		return sal_True;
213     }
214 
215     static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
216 	return sal_False;
217 }
218 
IsProtect() const219 sal_Bool SwTxtINetFmt::IsProtect( ) const
220 {
221     return m_pTxtNode && m_pTxtNode->IsProtect();
222 }
223 
224 /*************************************************************************
225  *						class SwTxtRuby
226  *************************************************************************/
227 
SwTxtRuby(SwFmtRuby & rAttr,xub_StrLen nStart,xub_StrLen nEnd)228 SwTxtRuby::SwTxtRuby( SwFmtRuby& rAttr,
229                       xub_StrLen nStart, xub_StrLen nEnd )
230     : SwTxtAttrNesting( rAttr, nStart, nEnd )
231     , SwClient( 0 )
232     , m_pTxtNode( 0 )
233 {
234     rAttr.pTxtAttr  = this;
235 }
236 
~SwTxtRuby()237 SwTxtRuby::~SwTxtRuby()
238 {
239 }
240 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)241 void SwTxtRuby::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
242 {
243 	sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
244     ASSERT(  isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
245              || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
246         "SwTxtRuby::Modify(): unknown Modify");
247 
248     if ( m_pTxtNode )
249     {
250         SwUpdateAttr aUpdateAttr(
251             *GetStart(),
252             *GetEnd(),
253             nWhich);
254 
255         m_pTxtNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
256     }
257 }
258 
GetInfo(SfxPoolItem & rInfo) const259 sal_Bool SwTxtRuby::GetInfo( SfxPoolItem& rInfo ) const
260 {
261     if( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
262         &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
263     {
264         return sal_True;
265     }
266 
267     static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
268     return sal_False;
269 }
270 
GetCharFmt()271 SwCharFmt* SwTxtRuby::GetCharFmt()
272 {
273 	const SwFmtRuby& rFmt = SwTxtAttrEnd::GetRuby();
274 	SwCharFmt* pRet = 0;
275 
276 	if( rFmt.GetText().Len() )
277 	{
278 		const SwDoc* pDoc = GetTxtNode().GetDoc();
279 		const String& rStr = rFmt.GetCharFmtName();
280         sal_uInt16 nId = RES_POOLCHR_RUBYTEXT;
281         if ( rStr.Len() )
282             nId = rFmt.GetCharFmtId();
283 
284 		// JP 10.02.2000, Bug 72806: dont modify the doc for getting the
285 		//				correct charstyle.
286 		sal_Bool bResetMod = !pDoc->IsModified();
287 		Link aOle2Lnk;
288 		if( bResetMod )
289 		{
290 			aOle2Lnk = pDoc->GetOle2Link();
291 			((SwDoc*)pDoc)->SetOle2Link( Link() );
292 		}
293 
294 		pRet = IsPoolUserFmt( nId )
295 				? ((SwDoc*)pDoc)->FindCharFmtByName( rStr )
296 				: ((SwDoc*)pDoc)->GetCharFmtFromPool( nId );
297 
298 		if( bResetMod )
299 		{
300 			((SwDoc*)pDoc)->ResetModified();
301 			((SwDoc*)pDoc)->SetOle2Link( aOle2Lnk );
302 		}
303 	}
304 
305 	if( pRet )
306 		pRet->Add( this );
307 	else if( GetRegisteredIn() )
308 		GetRegisteredInNonConst()->Remove( this );
309 
310 	return pRet;
311 }
312 
313 
314 /*************************************************************************
315  *                        class SwTxtMeta
316  *************************************************************************/
317 
318 SwTxtMeta *
CreateTxtMeta(::sw::MetaFieldManager & i_rTargetDocManager,SwTxtNode * const i_pTargetTxtNode,SwFmtMeta & i_rAttr,xub_StrLen const i_nStart,xub_StrLen const i_nEnd,bool const i_bIsCopy)319 SwTxtMeta::CreateTxtMeta(
320     ::sw::MetaFieldManager & i_rTargetDocManager,
321     SwTxtNode *const i_pTargetTxtNode,
322     SwFmtMeta & i_rAttr,
323     xub_StrLen const i_nStart,
324     xub_StrLen const i_nEnd,
325     bool const i_bIsCopy)
326 {
327     if (COPY == i_bIsCopy)
328     {   // i_rAttr is already cloned, now call DoCopy to copy the sw::Meta
329         OSL_ENSURE(i_pTargetTxtNode, "cannot copy Meta without target node");
330         i_rAttr.DoCopy(i_rTargetDocManager, *i_pTargetTxtNode);
331     }
332     SwTxtMeta *const pTxtMeta(new SwTxtMeta(i_rAttr, i_nStart, i_nEnd));
333     return pTxtMeta;
334 }
335 
SwTxtMeta(SwFmtMeta & i_rAttr,const xub_StrLen i_nStart,const xub_StrLen i_nEnd)336 SwTxtMeta::SwTxtMeta( SwFmtMeta & i_rAttr,
337         const xub_StrLen i_nStart, const xub_StrLen i_nEnd )
338     : SwTxtAttrNesting( i_rAttr, i_nStart, i_nEnd )
339 {
340     i_rAttr.SetTxtAttr( this );
341     SetHasDummyChar(true);
342 }
343 
~SwTxtMeta()344 SwTxtMeta::~SwTxtMeta()
345 {
346     SwFmtMeta & rFmtMeta( static_cast<SwFmtMeta &>(GetAttr()) );
347     if (rFmtMeta.GetTxtAttr() == this)
348     {
349         rFmtMeta.SetTxtAttr(0);
350     }
351 }
352 
ChgTxtNode(SwTxtNode * const pNode)353 void SwTxtMeta::ChgTxtNode(SwTxtNode * const pNode)
354 {
355     SwFmtMeta & rFmtMeta( static_cast<SwFmtMeta &>(GetAttr()) );
356     if (rFmtMeta.GetTxtAttr() == this)
357     {
358         rFmtMeta.NotifyChangeTxtNode(pNode);
359     }
360 }
361 
362