merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / txtnode / txtatr2.cxx
blobf500d285960b382e44cef8f73e8bc86bb5e8e30a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: txtatr2.cxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
36 #include <hints.hxx>
37 #include <sfx2/objsh.hxx>
38 #include <svx/xmlcnitm.hxx>
39 #include <svx/twolinesitem.hxx>
40 #include <txtinet.hxx>
41 #include <txtatr.hxx>
42 #include <fchrfmt.hxx>
43 #include <fmtinfmt.hxx>
44 #include <charfmt.hxx>
45 #include <ndtxt.hxx> // SwCharFmt, SwTxtNode
46 #include <poolfmt.hxx> // RES_POOLCHR_INET_...
47 #include <doc.hxx> // SwDoc
48 #include <fmtruby.hxx>
49 #include <fmtmeta.hxx>
52 TYPEINIT1(SwTxtINetFmt,SwClient);
53 TYPEINIT1(SwTxtRuby,SwClient);
55 // ATT_XMLCONTAINERITEM ******************************
57 SwTxtXMLAttrContainer::SwTxtXMLAttrContainer(
58 SvXMLAttrContainerItem& rAttr,
59 xub_StrLen nStt, xub_StrLen nEnde )
60 : SwTxtAttrEnd( rAttr, nStt, nEnde )
63 /*************************************************************************
64 * class SwTxtCharFmt
65 *************************************************************************/
67 SwTxtCharFmt::SwTxtCharFmt( SwFmtCharFmt& rAttr,
68 xub_StrLen nStt, xub_StrLen nEnde )
69 : SwTxtAttrEnd( rAttr, nStt, nEnde )
70 , m_pTxtNode( 0 )
71 , m_nSortNumber( 0 )
73 rAttr.pTxtAttr = this;
74 SetCharFmtAttr( TRUE );
77 SwTxtCharFmt::~SwTxtCharFmt( )
81 void SwTxtCharFmt::Modify( SfxPoolItem* pOld, SfxPoolItem* pNew )
83 USHORT nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
84 ASSERT( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
85 || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
86 "SwTxtCharFmt::Modify(): unknown Modify");
88 if ( m_pTxtNode )
90 SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
91 m_pTxtNode->Modify( &aUpdateAttr, &aUpdateAttr );
95 // erfrage vom Modify Informationen
96 BOOL SwTxtCharFmt::GetInfo( SfxPoolItem& rInfo ) const
98 if ( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
99 &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
101 return TRUE;
104 static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
105 return FALSE;
109 /*************************************************************************
110 * class SwTxtAttrNesting
111 *************************************************************************/
113 SwTxtAttrNesting::SwTxtAttrNesting( SfxPoolItem & i_rAttr,
114 const xub_StrLen i_nStart, const xub_StrLen i_nEnd )
115 : SwTxtAttrEnd( i_rAttr, i_nStart, i_nEnd )
117 SetDontExpand( true ); // never expand this attribute
118 // lock the expand flag: simple guarantee that nesting will not be
119 // invalidated by expand operations
120 SetLockExpandFlag( true );
121 SetDontExpandStartAttr( true );
122 SetNesting( true );
125 SwTxtAttrNesting::~SwTxtAttrNesting()
130 /*************************************************************************
131 * class SwTxtINetFmt
132 *************************************************************************/
134 SwTxtINetFmt::SwTxtINetFmt( SwFmtINetFmt& rAttr,
135 xub_StrLen nStart, xub_StrLen nEnd )
136 : SwTxtAttrNesting( rAttr, nStart, nEnd )
137 , SwClient( 0 )
138 , m_pTxtNode( 0 )
139 , m_bVisited( false )
140 , m_bVisitedValid( false )
142 rAttr.pTxtAttr = this;
143 SetCharFmtAttr( true );
146 SwTxtINetFmt::~SwTxtINetFmt( )
150 SwCharFmt* SwTxtINetFmt::GetCharFmt()
152 const SwFmtINetFmt& rFmt = SwTxtAttrEnd::GetINetFmt();
153 SwCharFmt* pRet = NULL;
155 if( rFmt.GetValue().Len() )
157 const SwDoc* pDoc = GetTxtNode().GetDoc();
158 if( !IsVisitedValid() )
160 SetVisited( pDoc->IsVisitedURL( rFmt.GetValue() ) );
161 SetVisitedValid( true );
163 USHORT nId;
164 const String& rStr = IsVisited() ? rFmt.GetVisitedFmt()
165 : rFmt.GetINetFmt();
166 if( rStr.Len() )
167 nId = IsVisited() ? rFmt.GetVisitedFmtId() : rFmt.GetINetFmtId();
168 else
169 nId = static_cast<USHORT>(IsVisited() ? RES_POOLCHR_INET_VISIT : RES_POOLCHR_INET_NORMAL);
171 // JP 10.02.2000, Bug 72806: dont modify the doc for getting the
172 // correct charstyle.
173 BOOL bResetMod = !pDoc->IsModified();
174 Link aOle2Lnk;
175 if( bResetMod )
177 aOle2Lnk = pDoc->GetOle2Link();
178 ((SwDoc*)pDoc)->SetOle2Link( Link() );
181 pRet = IsPoolUserFmt( nId )
182 ? ((SwDoc*)pDoc)->FindCharFmtByName( rStr )
183 : ((SwDoc*)pDoc)->GetCharFmtFromPool( nId );
185 if( bResetMod )
187 ((SwDoc*)pDoc)->ResetModified();
188 ((SwDoc*)pDoc)->SetOle2Link( aOle2Lnk );
192 if( pRet )
193 pRet->Add( this );
194 else if( GetRegisteredIn() )
195 pRegisteredIn->Remove( this );
197 return pRet;
200 void SwTxtINetFmt::Modify( SfxPoolItem* pOld, SfxPoolItem* pNew )
202 USHORT nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
203 ASSERT( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
204 || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
205 "SwTxtINetFmt::Modify(): unknown Modify");
207 if ( m_pTxtNode )
209 SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
210 m_pTxtNode->Modify( &aUpdateAttr, &aUpdateAttr );
214 // erfrage vom Modify Informationen
215 BOOL SwTxtINetFmt::GetInfo( SfxPoolItem& rInfo ) const
217 if ( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
218 &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
220 return TRUE;
223 static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
224 return FALSE;
227 BOOL SwTxtINetFmt::IsProtect( ) const
229 return m_pTxtNode && m_pTxtNode->IsProtect();
232 /*************************************************************************
233 * class SwTxtRuby
234 *************************************************************************/
236 SwTxtRuby::SwTxtRuby( SwFmtRuby& rAttr,
237 xub_StrLen nStart, xub_StrLen nEnd )
238 : SwTxtAttrNesting( rAttr, nStart, nEnd )
239 , SwClient( 0 )
240 , m_pTxtNode( 0 )
242 rAttr.pTxtAttr = this;
245 SwTxtRuby::~SwTxtRuby()
249 void SwTxtRuby::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew )
251 USHORT nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
252 ASSERT( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
253 || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
254 "SwTxtRuby::Modify(): unknown Modify");
256 if ( m_pTxtNode )
258 SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
259 m_pTxtNode->Modify( &aUpdateAttr, &aUpdateAttr );
263 BOOL SwTxtRuby::GetInfo( SfxPoolItem& rInfo ) const
265 if( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
266 &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
268 return TRUE;
271 static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
272 return FALSE;
275 SwCharFmt* SwTxtRuby::GetCharFmt()
277 const SwFmtRuby& rFmt = SwTxtAttrEnd::GetRuby();
278 SwCharFmt* pRet = 0;
280 if( rFmt.GetText().Len() )
282 const SwDoc* pDoc = GetTxtNode().GetDoc();
283 const String& rStr = rFmt.GetCharFmtName();
284 USHORT nId = RES_POOLCHR_RUBYTEXT;
285 if ( rStr.Len() )
286 nId = rFmt.GetCharFmtId();
288 // JP 10.02.2000, Bug 72806: dont modify the doc for getting the
289 // correct charstyle.
290 BOOL bResetMod = !pDoc->IsModified();
291 Link aOle2Lnk;
292 if( bResetMod )
294 aOle2Lnk = pDoc->GetOle2Link();
295 ((SwDoc*)pDoc)->SetOle2Link( Link() );
298 pRet = IsPoolUserFmt( nId )
299 ? ((SwDoc*)pDoc)->FindCharFmtByName( rStr )
300 : ((SwDoc*)pDoc)->GetCharFmtFromPool( nId );
302 if( bResetMod )
304 ((SwDoc*)pDoc)->ResetModified();
305 ((SwDoc*)pDoc)->SetOle2Link( aOle2Lnk );
309 if( pRet )
310 pRet->Add( this );
311 else if( GetRegisteredIn() )
312 pRegisteredIn->Remove( this );
314 return pRet;
318 /*************************************************************************
319 * class SwTxtMeta
320 *************************************************************************/
322 SwTxtMeta::SwTxtMeta( SwFmtMeta & i_rAttr,
323 const xub_StrLen i_nStart, const xub_StrLen i_nEnd )
324 : SwTxtAttrNesting( i_rAttr, i_nStart, i_nEnd )
325 , m_pTxtNode( 0 )
327 i_rAttr.SetTxtAttr( this );
328 SetHasDummyChar(true);
331 SwTxtMeta::~SwTxtMeta()
333 SwFmtMeta & rFmtMeta( static_cast<SwFmtMeta &>(GetAttr()) );
334 if (rFmtMeta.GetTxtAttr() == this)
336 rFmtMeta.SetTxtAttr(0);