1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: txtatr2.cxx,v $
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>
37 #include <sfx2/objsh.hxx>
38 #include <svx/xmlcnitm.hxx>
39 #include <svx/twolinesitem.hxx>
40 #include <txtinet.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 /*************************************************************************
65 *************************************************************************/
67 SwTxtCharFmt::SwTxtCharFmt( SwFmtCharFmt
& rAttr
,
68 xub_StrLen nStt
, xub_StrLen nEnde
)
69 : SwTxtAttrEnd( rAttr
, nStt
, nEnde
)
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");
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
)
104 static_cast<SwAutoFmtGetDocNode
&>(rInfo
).pCntntNode
= m_pTxtNode
;
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 );
125 SwTxtAttrNesting::~SwTxtAttrNesting()
130 /*************************************************************************
132 *************************************************************************/
134 SwTxtINetFmt::SwTxtINetFmt( SwFmtINetFmt
& rAttr
,
135 xub_StrLen nStart
, xub_StrLen nEnd
)
136 : SwTxtAttrNesting( rAttr
, nStart
, nEnd
)
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 );
164 const String
& rStr
= IsVisited() ? rFmt
.GetVisitedFmt()
167 nId
= IsVisited() ? rFmt
.GetVisitedFmtId() : rFmt
.GetINetFmtId();
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();
177 aOle2Lnk
= pDoc
->GetOle2Link();
178 ((SwDoc
*)pDoc
)->SetOle2Link( Link() );
181 pRet
= IsPoolUserFmt( nId
)
182 ? ((SwDoc
*)pDoc
)->FindCharFmtByName( rStr
)
183 : ((SwDoc
*)pDoc
)->GetCharFmtFromPool( nId
);
187 ((SwDoc
*)pDoc
)->ResetModified();
188 ((SwDoc
*)pDoc
)->SetOle2Link( aOle2Lnk
);
194 else if( GetRegisteredIn() )
195 pRegisteredIn
->Remove( this );
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");
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
)
223 static_cast<SwAutoFmtGetDocNode
&>(rInfo
).pCntntNode
= m_pTxtNode
;
227 BOOL
SwTxtINetFmt::IsProtect( ) const
229 return m_pTxtNode
&& m_pTxtNode
->IsProtect();
232 /*************************************************************************
234 *************************************************************************/
236 SwTxtRuby::SwTxtRuby( SwFmtRuby
& rAttr
,
237 xub_StrLen nStart
, xub_StrLen nEnd
)
238 : SwTxtAttrNesting( rAttr
, nStart
, nEnd
)
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");
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
)
271 static_cast<SwAutoFmtGetDocNode
&>(rInfo
).pCntntNode
= m_pTxtNode
;
275 SwCharFmt
* SwTxtRuby::GetCharFmt()
277 const SwFmtRuby
& rFmt
= SwTxtAttrEnd::GetRuby();
280 if( rFmt
.GetText().Len() )
282 const SwDoc
* pDoc
= GetTxtNode().GetDoc();
283 const String
& rStr
= rFmt
.GetCharFmtName();
284 USHORT nId
= RES_POOLCHR_RUBYTEXT
;
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();
294 aOle2Lnk
= pDoc
->GetOle2Link();
295 ((SwDoc
*)pDoc
)->SetOle2Link( Link() );
298 pRet
= IsPoolUserFmt( nId
)
299 ? ((SwDoc
*)pDoc
)->FindCharFmtByName( rStr
)
300 : ((SwDoc
*)pDoc
)->GetCharFmtFromPool( nId
);
304 ((SwDoc
*)pDoc
)->ResetModified();
305 ((SwDoc
*)pDoc
)->SetOle2Link( aOle2Lnk
);
311 else if( GetRegisteredIn() )
312 pRegisteredIn
->Remove( this );
318 /*************************************************************************
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
)
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);