Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <hintids.hxx>
31 : : #include <hints.hxx>
32 : : #include <sfx2/objsh.hxx>
33 : : #include <editeng/xmlcnitm.hxx>
34 : : #include <editeng/twolinesitem.hxx>
35 : : #include <txtinet.hxx>
36 : : #include <txtatr.hxx>
37 : : #include <fchrfmt.hxx>
38 : : #include <fmtinfmt.hxx>
39 : : #include <charfmt.hxx>
40 : : #include <ndtxt.hxx> // SwCharFmt, SwTxtNode
41 : : #include <poolfmt.hxx> // RES_POOLCHR_INET_...
42 : : #include <doc.hxx> // SwDoc
43 : : #include <fmtruby.hxx>
44 : : #include <fmtmeta.hxx>
45 : :
46 : :
47 [ - + ][ + - ]: 225 : TYPEINIT1(SwTxtINetFmt,SwClient);
48 [ - + ][ + - ]: 432 : TYPEINIT1(SwTxtRuby,SwClient);
49 : :
50 : :
51 : : /*************************************************************************
52 : : * class SwTxtCharFmt
53 : : *************************************************************************/
54 : :
55 : 43 : SwTxtCharFmt::SwTxtCharFmt( SwFmtCharFmt& rAttr,
56 : : xub_StrLen nStt, xub_StrLen nEnde )
57 : : : SwTxtAttrEnd( rAttr, nStt, nEnde )
58 : : , m_pTxtNode( 0 )
59 : 43 : , m_nSortNumber( 0 )
60 : : {
61 : 43 : rAttr.pTxtAttr = this;
62 : 43 : SetCharFmtAttr( sal_True );
63 : 43 : }
64 : :
65 : 43 : SwTxtCharFmt::~SwTxtCharFmt( )
66 : : {
67 [ - + ]: 86 : }
68 : :
69 : 264 : void SwTxtCharFmt::ModifyNotification( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
70 : : {
71 [ + - ][ # # ]: 264 : sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
72 : : OSL_ENSURE( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
73 : : || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
74 : : "SwTxtCharFmt::Modify(): unknown Modify");
75 : :
76 [ + - ]: 264 : if ( m_pTxtNode )
77 : : {
78 [ + - ][ + - ]: 264 : SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
79 [ + - ][ + - ]: 264 : m_pTxtNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
80 : : }
81 : 264 : }
82 : :
83 : 4 : bool SwTxtCharFmt::GetInfo( SfxPoolItem& rInfo ) const
84 : : {
85 [ + - ]: 8 : if ( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
[ + - - + ]
[ - + ]
86 : 4 : &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
87 : : {
88 : 0 : return true;
89 : : }
90 : :
91 : 4 : static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
92 : 4 : return false;
93 : : }
94 : :
95 : :
96 : : /*************************************************************************
97 : : * class SwTxtAttrNesting
98 : : *************************************************************************/
99 : :
100 : 693 : SwTxtAttrNesting::SwTxtAttrNesting( SfxPoolItem & i_rAttr,
101 : : const xub_StrLen i_nStart, const xub_StrLen i_nEnd )
102 : 693 : : SwTxtAttrEnd( i_rAttr, i_nStart, i_nEnd )
103 : : {
104 : 693 : SetDontExpand( true ); // never expand this attribute
105 : : // lock the expand flag: simple guarantee that nesting will not be
106 : : // invalidated by expand operations
107 : 693 : SetLockExpandFlag( true );
108 : 693 : SetDontExpandStartAttr( true );
109 : 693 : SetNesting( true );
110 : 693 : }
111 : :
112 : 693 : SwTxtAttrNesting::~SwTxtAttrNesting()
113 : : {
114 [ - + ]: 693 : }
115 : :
116 : :
117 : : /*************************************************************************
118 : : * class SwTxtINetFmt
119 : : *************************************************************************/
120 : :
121 : 115 : SwTxtINetFmt::SwTxtINetFmt( SwFmtINetFmt& rAttr,
122 : : xub_StrLen nStart, xub_StrLen nEnd )
123 : : : SwTxtAttrNesting( rAttr, nStart, nEnd )
124 : : , SwClient( 0 )
125 : : , m_pTxtNode( 0 )
126 : : , m_bVisited( false )
127 [ + - ]: 115 : , m_bVisitedValid( false )
128 : : {
129 : 115 : rAttr.pTxtAttr = this;
130 : 115 : SetCharFmtAttr( true );
131 : 115 : }
132 : :
133 [ + - ]: 115 : SwTxtINetFmt::~SwTxtINetFmt( )
134 : : {
135 [ - + ]: 230 : }
136 : :
137 : 3760 : SwCharFmt* SwTxtINetFmt::GetCharFmt()
138 : : {
139 : 3760 : const SwFmtINetFmt& rFmt = SwTxtAttrEnd::GetINetFmt();
140 : 3760 : SwCharFmt* pRet = NULL;
141 : :
142 [ + - ]: 3760 : if( rFmt.GetValue().Len() )
143 : : {
144 : 3760 : const SwDoc* pDoc = GetTxtNode().GetDoc();
145 [ + + ]: 3760 : if( !IsVisitedValid() )
146 : : {
147 [ + - ]: 106 : SetVisited( pDoc->IsVisitedURL( rFmt.GetValue() ) );
148 : 106 : SetVisitedValid( true );
149 : : }
150 : : sal_uInt16 nId;
151 : 3760 : const String& rStr = IsVisited() ? rFmt.GetVisitedFmt()
152 [ - + ]: 3760 : : rFmt.GetINetFmt();
153 [ + + ]: 3760 : if( rStr.Len() )
154 [ - + ]: 403 : nId = IsVisited() ? rFmt.GetVisitedFmtId() : rFmt.GetINetFmtId();
155 : : else
156 [ - + ]: 3357 : nId = static_cast<sal_uInt16>(IsVisited() ? RES_POOLCHR_INET_VISIT : RES_POOLCHR_INET_NORMAL);
157 : :
158 : : // JP 10.02.2000, Bug 72806: dont modify the doc for getting the
159 : : // correct charstyle.
160 [ + - ]: 3760 : sal_Bool bResetMod = !pDoc->IsModified();
161 [ + - ]: 3760 : Link aOle2Lnk;
162 [ + + ]: 3760 : if( bResetMod )
163 : : {
164 : 42 : aOle2Lnk = pDoc->GetOle2Link();
165 [ + - ]: 42 : ((SwDoc*)pDoc)->SetOle2Link( Link() );
166 : : }
167 : :
168 : 3760 : pRet = IsPoolUserFmt( nId )
169 : : ? ((SwDoc*)pDoc)->FindCharFmtByName( rStr )
170 [ + - ][ + - ]: 3760 : : ((SwDoc*)pDoc)->GetCharFmtFromPool( nId );
[ + + ]
171 : :
172 [ + + ]: 3760 : if( bResetMod )
173 : : {
174 [ + - ]: 42 : ((SwDoc*)pDoc)->ResetModified();
175 : 3760 : ((SwDoc*)pDoc)->SetOle2Link( aOle2Lnk );
176 : : }
177 : : }
178 : :
179 [ + + ]: 3760 : if( pRet )
180 : 3357 : pRet->Add( this );
181 [ + + ]: 403 : else if( GetRegisteredIn() )
182 : 4 : GetRegisteredInNonConst()->Remove( this );
183 : :
184 : 3760 : return pRet;
185 : : }
186 : :
187 : 75 : void SwTxtINetFmt::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
188 : : {
189 [ + - ][ # # ]: 75 : sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
190 : : OSL_ENSURE( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
191 : : || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
192 : : "SwTxtINetFmt::Modify(): unknown Modify");
193 : :
194 [ + - ]: 75 : if ( m_pTxtNode )
195 : : {
196 [ + - ][ + - ]: 75 : SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
197 [ + - ][ + - ]: 75 : m_pTxtNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
198 : : }
199 : 75 : }
200 : :
201 : : // erfrage vom Modify Informationen
202 : 0 : sal_Bool SwTxtINetFmt::GetInfo( SfxPoolItem& rInfo ) const
203 : : {
204 [ # # ]: 0 : if ( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
[ # # # # ]
[ # # ]
205 : 0 : &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
206 : : {
207 : 0 : return sal_True;
208 : : }
209 : :
210 : 0 : static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
211 : 0 : return sal_False;
212 : : }
213 : :
214 : 0 : sal_Bool SwTxtINetFmt::IsProtect( ) const
215 : : {
216 [ # # ][ # # ]: 0 : return m_pTxtNode && m_pTxtNode->IsProtect();
217 : : }
218 : :
219 : : /*************************************************************************
220 : : * class SwTxtRuby
221 : : *************************************************************************/
222 : :
223 : 384 : SwTxtRuby::SwTxtRuby( SwFmtRuby& rAttr,
224 : : xub_StrLen nStart, xub_StrLen nEnd )
225 : : : SwTxtAttrNesting( rAttr, nStart, nEnd )
226 : : , SwClient( 0 )
227 [ + - ]: 384 : , m_pTxtNode( 0 )
228 : : {
229 : 384 : rAttr.pTxtAttr = this;
230 : 384 : }
231 : :
232 [ + - ]: 384 : SwTxtRuby::~SwTxtRuby()
233 : : {
234 [ - + ]: 768 : }
235 : :
236 : 144 : void SwTxtRuby::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
237 : : {
238 [ + - ][ # # ]: 144 : sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
239 : : OSL_ENSURE( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
240 : : || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
241 : : "SwTxtRuby::Modify(): unknown Modify");
242 : :
243 [ + - ]: 144 : if ( m_pTxtNode )
244 : : {
245 [ + - ][ + - ]: 144 : SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
246 [ + - ][ + - ]: 144 : m_pTxtNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
247 : : }
248 : 144 : }
249 : :
250 : 0 : sal_Bool SwTxtRuby::GetInfo( SfxPoolItem& rInfo ) const
251 : : {
252 [ # # ]: 0 : if( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
[ # # # # ]
[ # # ]
253 : 0 : &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
254 : : {
255 : 0 : return sal_True;
256 : : }
257 : :
258 : 0 : static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
259 : 0 : return sal_False;
260 : : }
261 : :
262 : 336 : SwCharFmt* SwTxtRuby::GetCharFmt()
263 : : {
264 : 336 : const SwFmtRuby& rFmt = SwTxtAttrEnd::GetRuby();
265 : 336 : SwCharFmt* pRet = 0;
266 : :
267 [ + - ]: 336 : if( rFmt.GetText().Len() )
268 : : {
269 : 336 : const SwDoc* pDoc = GetTxtNode().GetDoc();
270 : 336 : const String& rStr = rFmt.GetCharFmtName();
271 : 336 : sal_uInt16 nId = RES_POOLCHR_RUBYTEXT;
272 [ + + ]: 336 : if ( rStr.Len() )
273 : 60 : nId = rFmt.GetCharFmtId();
274 : :
275 : : // JP 10.02.2000, Bug 72806: dont modify the doc for getting the
276 : : // correct charstyle.
277 [ + - ]: 336 : sal_Bool bResetMod = !pDoc->IsModified();
278 [ + - ]: 336 : Link aOle2Lnk;
279 [ + + ]: 336 : if( bResetMod )
280 : : {
281 : 12 : aOle2Lnk = pDoc->GetOle2Link();
282 [ + - ]: 12 : ((SwDoc*)pDoc)->SetOle2Link( Link() );
283 : : }
284 : :
285 : 336 : pRet = IsPoolUserFmt( nId )
286 : : ? ((SwDoc*)pDoc)->FindCharFmtByName( rStr )
287 [ # # ][ + - ]: 336 : : ((SwDoc*)pDoc)->GetCharFmtFromPool( nId );
[ - + ]
288 : :
289 [ + + ]: 336 : if( bResetMod )
290 : : {
291 [ + - ]: 12 : ((SwDoc*)pDoc)->ResetModified();
292 : 336 : ((SwDoc*)pDoc)->SetOle2Link( aOle2Lnk );
293 : : }
294 : : }
295 : :
296 [ + - ]: 336 : if( pRet )
297 : 336 : pRet->Add( this );
298 [ # # ]: 0 : else if( GetRegisteredIn() )
299 : 0 : GetRegisteredInNonConst()->Remove( this );
300 : :
301 : 336 : return pRet;
302 : : }
303 : :
304 : :
305 : : /*************************************************************************
306 : : * class SwTxtMeta
307 : : *************************************************************************/
308 : :
309 : : SwTxtMeta *
310 : 194 : SwTxtMeta::CreateTxtMeta(
311 : : ::sw::MetaFieldManager & i_rTargetDocManager,
312 : : SwTxtNode *const i_pTargetTxtNode,
313 : : SwFmtMeta & i_rAttr,
314 : : xub_StrLen const i_nStart, xub_StrLen const i_nEnd, bool const i_bIsCopy)
315 : : {
316 [ - + ]: 194 : if (COPY == i_bIsCopy)
317 : : { // i_rAttr is already cloned, now call DoCopy to copy the sw::Meta
318 : : OSL_ENSURE(i_pTargetTxtNode, "cannot copy Meta without target node");
319 : 0 : i_rAttr.DoCopy(i_rTargetDocManager, *i_pTargetTxtNode);
320 : : }
321 [ + - ]: 194 : SwTxtMeta *const pTxtMeta(new SwTxtMeta(i_rAttr, i_nStart, i_nEnd));
322 : 194 : return pTxtMeta;
323 : : }
324 : :
325 : 194 : SwTxtMeta::SwTxtMeta( SwFmtMeta & i_rAttr,
326 : : const xub_StrLen i_nStart, const xub_StrLen i_nEnd )
327 : 194 : : SwTxtAttrNesting( i_rAttr, i_nStart, i_nEnd )
328 : : {
329 [ + - ]: 194 : i_rAttr.SetTxtAttr( this );
330 : 194 : SetHasDummyChar(true);
331 : 194 : }
332 : :
333 : 194 : SwTxtMeta::~SwTxtMeta()
334 : : {
335 : 194 : SwFmtMeta & rFmtMeta( static_cast<SwFmtMeta &>(GetAttr()) );
336 [ + - ]: 194 : if (rFmtMeta.GetTxtAttr() == this)
337 : : {
338 [ + - ]: 194 : rFmtMeta.SetTxtAttr(0);
339 : : }
340 [ - + ]: 388 : }
341 : :
342 : 388 : void SwTxtMeta::ChgTxtNode(SwTxtNode * const pNode)
343 : : {
344 : 388 : SwFmtMeta & rFmtMeta( static_cast<SwFmtMeta &>(GetAttr()) );
345 [ + - ]: 388 : if (rFmtMeta.GetTxtAttr() == this)
346 : : {
347 : 388 : rFmtMeta.NotifyChangeTxtNode(pNode);
348 : : }
349 : 388 : }
350 : :
351 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|