update dev300-m58
[ooovba.git] / sw / source / core / txtnode / txtatr2.cxx
blob0253beba8d167373c50dba2a217b1b7a02d6a47b
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 <fmthbsh.hxx>
51 TYPEINIT1(SwTxtINetFmt,SwClient);
52 TYPEINIT1(SwTxtRuby,SwClient);
54 /*************************************************************************
55 * class SwTxtHardBlank
56 *************************************************************************/
58 SwTxtHardBlank::SwTxtHardBlank( const SwFmtHardBlank& rAttr, xub_StrLen nStt )
59 : SwTxtAttr( rAttr, nStt )
60 , m_Char( rAttr.GetChar() )
62 ASSERT( ' ' != m_Char && '-' != m_Char,
63 "Invalid character for the HardBlank attribute - "
64 "must be a normal unicode character" );
68 /*************************************************************************
69 * class SwTxtCharFmt
70 *************************************************************************/
72 SwTxtCharFmt::SwTxtCharFmt( SwFmtCharFmt& rAttr,
73 xub_StrLen nStt, xub_StrLen nEnde )
74 : SwTxtAttrEnd( rAttr, nStt, nEnde )
75 , m_pTxtNode( 0 )
76 , m_nSortNumber( 0 )
78 rAttr.pTxtAttr = this;
79 SetCharFmtAttr( TRUE );
82 SwTxtCharFmt::~SwTxtCharFmt( )
86 void SwTxtCharFmt::Modify( SfxPoolItem* pOld, SfxPoolItem* pNew )
88 USHORT nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
89 ASSERT( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
90 || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
91 "SwTxtCharFmt::Modify(): unknown Modify");
93 if ( m_pTxtNode )
95 SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
96 m_pTxtNode->Modify( &aUpdateAttr, &aUpdateAttr );
100 // erfrage vom Modify Informationen
101 BOOL SwTxtCharFmt::GetInfo( SfxPoolItem& rInfo ) const
103 if ( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
104 &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
106 return TRUE;
109 static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
110 return FALSE;
113 /*************************************************************************
114 * class SwTxtINetFmt
115 *************************************************************************/
117 SwTxtINetFmt::SwTxtINetFmt( SwFmtINetFmt& rAttr,
118 xub_StrLen nStt, xub_StrLen nEnde )
119 : SwTxtAttrEnd( rAttr, nStt, nEnde )
120 , SwClient( 0 )
121 , m_pTxtNode( 0 )
122 , m_bVisited( false )
123 , m_bVisitedValid( false )
125 rAttr.pTxtAttr = this;
126 SetCharFmtAttr( TRUE );
129 SwTxtINetFmt::~SwTxtINetFmt( )
133 SwCharFmt* SwTxtINetFmt::GetCharFmt()
135 const SwFmtINetFmt& rFmt = SwTxtAttrEnd::GetINetFmt();
136 SwCharFmt* pRet = NULL;
138 if( rFmt.GetValue().Len() )
140 const SwDoc* pDoc = GetTxtNode().GetDoc();
141 if( !IsVisitedValid() )
143 SetVisited( pDoc->IsVisitedURL( rFmt.GetValue() ) );
144 SetVisitedValid( true );
146 USHORT nId;
147 const String& rStr = IsVisited() ? rFmt.GetVisitedFmt()
148 : rFmt.GetINetFmt();
149 if( rStr.Len() )
150 nId = IsVisited() ? rFmt.GetVisitedFmtId() : rFmt.GetINetFmtId();
151 else
152 nId = static_cast<USHORT>(IsVisited() ? RES_POOLCHR_INET_VISIT : RES_POOLCHR_INET_NORMAL);
154 // JP 10.02.2000, Bug 72806: dont modify the doc for getting the
155 // correct charstyle.
156 BOOL bResetMod = !pDoc->IsModified();
157 Link aOle2Lnk;
158 if( bResetMod )
160 aOle2Lnk = pDoc->GetOle2Link();
161 ((SwDoc*)pDoc)->SetOle2Link( Link() );
164 pRet = IsPoolUserFmt( nId )
165 ? ((SwDoc*)pDoc)->FindCharFmtByName( rStr )
166 : ((SwDoc*)pDoc)->GetCharFmtFromPool( nId );
168 if( bResetMod )
170 ((SwDoc*)pDoc)->ResetModified();
171 ((SwDoc*)pDoc)->SetOle2Link( aOle2Lnk );
175 if( pRet )
176 pRet->Add( this );
177 else if( GetRegisteredIn() )
178 pRegisteredIn->Remove( this );
180 return pRet;
183 void SwTxtINetFmt::Modify( SfxPoolItem* pOld, SfxPoolItem* pNew )
185 USHORT nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
186 ASSERT( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
187 || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
188 "SwTxtINetFmt::Modify(): unknown Modify");
190 if ( m_pTxtNode )
192 SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
193 m_pTxtNode->Modify( &aUpdateAttr, &aUpdateAttr );
197 // erfrage vom Modify Informationen
198 BOOL SwTxtINetFmt::GetInfo( SfxPoolItem& rInfo ) const
200 if ( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
201 &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
203 return TRUE;
206 static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
207 return FALSE;
210 BOOL SwTxtINetFmt::IsProtect( ) const
212 return m_pTxtNode && m_pTxtNode->IsProtect();
215 // ATT_XNLCONTAINERITEM ******************************
217 SwTxtXMLAttrContainer::SwTxtXMLAttrContainer(
218 const SvXMLAttrContainerItem& rAttr,
219 xub_StrLen nStt, xub_StrLen nEnde )
220 : SwTxtAttrEnd( rAttr, nStt, nEnde )
224 /*************************************************************************
225 * class SwTxtRuby
226 *************************************************************************/
228 SwTxtRuby::SwTxtRuby( SwFmtRuby& rAttr,
229 xub_StrLen nStart, xub_StrLen nEnd )
230 : SwTxtAttrEnd( rAttr, nStart, nEnd )
231 , SwClient( 0 )
232 , m_pTxtNode( 0 )
234 rAttr.pTxtAttr = this;
235 SetDontExpand( true ); // never expand this attribute
236 SetLockExpandFlag( true );
237 SetDontMergeAttr( true );
238 SetDontExpandStartAttr( true );
241 SwTxtRuby::~SwTxtRuby()
245 void SwTxtRuby::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew )
247 USHORT nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
248 ASSERT( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
249 || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
250 "SwTxtRuby::Modify(): unknown Modify");
252 if ( m_pTxtNode )
254 SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
255 m_pTxtNode->Modify( &aUpdateAttr, &aUpdateAttr );
259 BOOL SwTxtRuby::GetInfo( SfxPoolItem& rInfo ) const
261 if( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
262 &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
264 return TRUE;
267 static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
268 return FALSE;
271 SwCharFmt* SwTxtRuby::GetCharFmt()
273 const SwFmtRuby& rFmt = SwTxtAttrEnd::GetRuby();
274 SwCharFmt* pRet = 0;
276 if( rFmt.GetText().Len() )
278 const SwDoc* pDoc = GetTxtNode().GetDoc();
279 const String& rStr = rFmt.GetCharFmtName();
280 USHORT nId = RES_POOLCHR_RUBYTEXT;
281 if ( rStr.Len() )
282 nId = rFmt.GetCharFmtId();
284 // JP 10.02.2000, Bug 72806: dont modify the doc for getting the
285 // correct charstyle.
286 BOOL bResetMod = !pDoc->IsModified();
287 Link aOle2Lnk;
288 if( bResetMod )
290 aOle2Lnk = pDoc->GetOle2Link();
291 ((SwDoc*)pDoc)->SetOle2Link( Link() );
294 pRet = IsPoolUserFmt( nId )
295 ? ((SwDoc*)pDoc)->FindCharFmtByName( rStr )
296 : ((SwDoc*)pDoc)->GetCharFmtFromPool( nId );
298 if( bResetMod )
300 ((SwDoc*)pDoc)->ResetModified();
301 ((SwDoc*)pDoc)->SetOle2Link( aOle2Lnk );
305 if( pRet )
306 pRet->Add( this );
307 else if( GetRegisteredIn() )
308 pRegisteredIn->Remove( this );
310 return pRet;
313 // ******************************
315 SwTxt2Lines::SwTxt2Lines( const SvxTwoLinesItem& rAttr,
316 xub_StrLen nStt, xub_StrLen nEnde )
317 : SwTxtAttrEnd( rAttr, nStt, nEnde )