update dev300-m58
[ooovba.git] / sw / source / core / unocore / unoftn.cxx
blob11b004dd362ee4e76818bf98807d1b190b710364
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: unoftn.cxx,v $
10 * $Revision: 1.31 $
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 <vos/mutex.hxx>
36 #include <vcl/svapp.hxx>
37 #include <rtl/uuid.h>
38 #include <unoobj.hxx>
39 #include <unomap.hxx>
40 #include <unoprnms.hxx>
41 #include <doc.hxx>
42 #include <ftnidx.hxx>
43 #include <fmtftn.hxx>
44 #include <txtftn.hxx>
45 #include <ndtxt.hxx>
46 #include <unocrsr.hxx>
47 #include <hints.hxx>
49 using namespace ::com::sun::star;
50 using ::rtl::OUString;
52 /******************************************************************
54 ******************************************************************/
55 /* -----------------------------13.03.00 12:15--------------------------------
57 ---------------------------------------------------------------------------*/
58 const uno::Sequence< sal_Int8 > & SwXFootnote::getUnoTunnelId()
60 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
61 return aSeq;
63 /* -----------------------------10.03.00 18:04--------------------------------
65 ---------------------------------------------------------------------------*/
66 sal_Int64 SAL_CALL SwXFootnote::getSomething( const uno::Sequence< sal_Int8 >& rId )
67 throw(uno::RuntimeException)
69 if( rId.getLength() == 16
70 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
71 rId.getConstArray(), 16 ) )
73 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
75 return SwXText::getSomething( rId );
77 /* -----------------------------06.04.00 16:36--------------------------------
79 ---------------------------------------------------------------------------*/
80 OUString SwXFootnote::getImplementationName(void) throw( uno::RuntimeException )
82 return C2U("SwXFootnote");
84 /* -----------------------------06.04.00 16:36--------------------------------
86 ---------------------------------------------------------------------------*/
87 BOOL SwXFootnote::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
89 return !rServiceName.compareToAscii("com.sun.star.text.Footnote") ||
90 !rServiceName.compareToAscii("com.sun.star.text.TextContent") ||
91 !rServiceName.compareToAscii("com.sun.star.text.Text") ||
92 (m_bIsEndnote && !rServiceName.compareToAscii("com.sun.star.text.Endnote"));
95 /* -----------------------------06.04.00 16:36--------------------------------
97 ---------------------------------------------------------------------------*/
98 uno::Sequence< OUString > SwXFootnote::getSupportedServiceNames(void) throw( uno::RuntimeException )
100 uno::Sequence< OUString > aRet(m_bIsEndnote ? 4 : 3);
101 OUString* pArray = aRet.getArray();
102 pArray[0] = C2U("com.sun.star.text.Footnote");
103 pArray[1] = C2U("com.sun.star.text.TextContent");
104 pArray[2] = C2U("com.sun.star.text.Text");
105 if(m_bIsEndnote)
106 pArray[3] = C2U("com.sun.star.text.Endnote");
107 return aRet;
109 /*-- 10.12.98 15:31:44---------------------------------------------------
111 -----------------------------------------------------------------------*/
112 TYPEINIT1(SwXFootnote, SwClient);
114 SwXFootnote::SwXFootnote(sal_Bool bEndnote) :
115 SwXText(0, CURSOR_FOOTNOTE),
116 aLstnrCntnr( (text::XTextContent*)this),
117 pFmtFtn(0),
118 m_bIsDescriptor(sal_True),
119 m_bIsEndnote(bEndnote)
123 /*-- 10.12.98 15:31:45---------------------------------------------------
125 -----------------------------------------------------------------------*/
126 SwXFootnote::SwXFootnote(SwDoc* _pDoc, const SwFmtFtn& rFmt) :
127 SwXText(_pDoc, CURSOR_FOOTNOTE),
128 aLstnrCntnr( (text::XTextContent*)this),
129 pFmtFtn(&rFmt),
130 m_bIsDescriptor(sal_False),
131 m_bIsEndnote(rFmt.IsEndNote())
133 GetDoc()->GetUnoCallBack()->Add(this);
135 /*-- 10.12.98 15:31:45---------------------------------------------------
137 -----------------------------------------------------------------------*/
138 SwXFootnote::~SwXFootnote()
142 /* -----------------------------21.03.00 15:39--------------------------------
144 ---------------------------------------------------------------------------*/
145 uno::Sequence< uno::Type > SAL_CALL SwXFootnote::getTypes( ) throw(uno::RuntimeException)
147 uno::Sequence< uno::Type > aFtnTypes = SwXFootnoteBaseClass::getTypes();
148 uno::Sequence< uno::Type > aTextTypes = SwXText::getTypes();
150 long nIndex = aFtnTypes.getLength();
151 aFtnTypes.realloc( aFtnTypes.getLength() + aTextTypes.getLength());
153 uno::Type* pFtnTypes = aFtnTypes.getArray();
154 const uno::Type* pTextTypes = aTextTypes.getConstArray();
155 for(long nPos = 0; nPos < aTextTypes.getLength(); nPos++)
156 pFtnTypes[nIndex++] = pTextTypes[nPos];
158 return aFtnTypes;
161 /* -----------------------------21.03.00 15:39--------------------------------
163 ---------------------------------------------------------------------------*/
164 uno::Sequence< sal_Int8 > SAL_CALL SwXFootnote::getImplementationId( ) throw(uno::RuntimeException)
166 vos::OGuard aGuard(Application::GetSolarMutex());
167 static uno::Sequence< sal_Int8 > aId( 16 );
168 static sal_Bool bInit = sal_False;
169 if(!bInit)
171 rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
172 bInit = sal_True;
174 return aId;
176 /* -----------------------------21.03.00 15:46--------------------------------
178 ---------------------------------------------------------------------------*/
179 uno::Any SAL_CALL SwXFootnote::queryInterface( const uno::Type& aType ) throw(uno::RuntimeException)
181 uno::Any aRet = SwXFootnoteBaseClass::queryInterface(aType);
182 if(aRet.getValueType() == ::getCppuVoidType() )
183 aRet = SwXText::queryInterface(aType);
184 return aRet;
187 /*-- 10.12.98 15:31:47---------------------------------------------------
189 -----------------------------------------------------------------------*/
190 OUString SwXFootnote::getLabel(void) throw( uno::RuntimeException )
192 vos::OGuard aGuard(Application::GetSolarMutex());
193 String sRet;
194 const SwFmtFtn* pFmt = SwXFootnote::FindFmt();
195 if(pFmt)
196 sRet = pFmt->GetNumStr();
197 else if(m_bIsDescriptor)
198 return m_sLabel;
199 else
200 throw uno::RuntimeException();
201 return sRet;
203 /*-- 10.12.98 15:31:48---------------------------------------------------
205 -----------------------------------------------------------------------*/
206 void SwXFootnote::setLabel(const OUString& aLabel) throw( uno::RuntimeException )
208 vos::OGuard aGuard(Application::GetSolarMutex());
209 const SwFmtFtn* pFmt = FindFmt();
210 if(pFmt)
212 const SwTxtFtn* pTxtFtn = pFmt->GetTxtFtn();
213 DBG_ASSERT(pTxtFtn, "kein TextNode?");
214 SwTxtNode& rTxtNode = (SwTxtNode&)pTxtFtn->GetTxtNode();
216 SwPaM aPam(rTxtNode, *pTxtFtn->GetStart());
217 GetDoc()->SetCurFtn(aPam, aLabel, pFmt->GetNumber(), pFmt->IsEndNote());
219 else if(m_bIsDescriptor)
220 m_sLabel = String(aLabel);
221 else
222 throw uno::RuntimeException();
225 /* -----------------18.02.99 13:32-------------------
227 * --------------------------------------------------*/
228 void SwXFootnote::attachToRange(const uno::Reference< text::XTextRange > & xTextRange)
229 throw( lang::IllegalArgumentException, uno::RuntimeException )
231 if(!m_bIsDescriptor)
232 throw uno::RuntimeException();
233 uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
234 SwXTextRange* pRange = 0;
235 OTextCursorHelper* pCursor = 0;
236 if(xRangeTunnel.is())
238 pRange = reinterpret_cast< SwXTextRange * >(
239 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) ));
240 pCursor = reinterpret_cast< OTextCursorHelper * >(
241 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
243 SwDoc* pNewDoc = pRange ? (SwDoc*)pRange->GetDoc() : pCursor ? (SwDoc*)pCursor->GetDoc() : 0;
244 if(pNewDoc)
246 SwUnoInternalPaM aPam(*pNewDoc);
247 //das muss jetzt sal_True liefern
248 SwXTextRange::XTextRangeToSwPaM(aPam, xTextRange);
250 UnoActionContext aCont(pNewDoc);
251 SwTxtAttr* pTxtAttr = 0;
252 pNewDoc->DeleteAndJoin(aPam);
253 aPam.DeleteMark();
254 SwFmtFtn aFootNote(m_bIsEndnote);
255 if(m_sLabel.Len())
256 aFootNote.SetNumStr(m_sLabel);
257 SfxItemSet aSet(pNewDoc->GetAttrPool(), RES_TXTATR_FTN, RES_TXTATR_FTN, 0L);
258 aSet.Put(aFootNote);
259 SwXTextCursor::SetCrsrAttr(aPam, aSet, 0);
261 pTxtAttr = aPam.GetNode()->GetTxtNode()->GetTxtAttr(
262 aPam.GetPoint()->nContent.GetIndex()-1, RES_TXTATR_FTN );
264 if(pTxtAttr)
266 const SwFmtFtn& rFtn = pTxtAttr->GetFtn();
267 pFmtFtn = &rFtn;
268 pNewDoc->GetUnoCallBack()->Add(this);
269 //force creation of sequence id - is used for references
270 if(pNewDoc->IsInReading())
271 ((SwTxtFtn*)pTxtAttr)->SetSeqNo(pNewDoc->GetFtnIdxs().Count());
272 else
273 ((SwTxtFtn*)pTxtAttr)->SetSeqRefNo();
275 m_bIsDescriptor = sal_False;
276 SetDoc(pNewDoc);
278 else
279 throw lang::IllegalArgumentException();
281 /*-- 10.12.98 15:31:48---------------------------------------------------
283 -----------------------------------------------------------------------*/
284 void SwXFootnote::attach(const uno::Reference< text::XTextRange > & xTextRange)
285 throw( lang::IllegalArgumentException, uno::RuntimeException )
287 vos::OGuard aGuard(Application::GetSolarMutex());
288 attachToRange( xTextRange );
290 /*-- 10.12.98 15:31:48---------------------------------------------------
292 -----------------------------------------------------------------------*/
293 uno::Reference< text::XTextRange > SwXFootnote::getAnchor(void) throw( uno::RuntimeException )
295 vos::OGuard aGuard(Application::GetSolarMutex());
296 uno::Reference< text::XTextRange > aRef;
297 const SwFmtFtn* pFmt = FindFmt();
298 if(pFmt)
300 const SwTxtFtn* pTxtFtn = pFmt->GetTxtFtn();
301 SwPaM aPam( pTxtFtn->GetTxtNode(), *pTxtFtn->GetStart() );
302 SwPosition aMark( *aPam.Start() );
303 aPam.SetMark();
304 aPam.GetMark()->nContent++;
305 aRef = SwXTextRange::CreateTextRangeFromPosition((SwDoc*)GetDoc(), *aPam.Start(), aPam.End());
307 else
308 throw uno::RuntimeException();
309 return aRef;
311 /*-- 10.12.98 15:31:49---------------------------------------------------
313 -----------------------------------------------------------------------*/
314 void SwXFootnote::dispose(void) throw( uno::RuntimeException )
316 vos::OGuard aGuard(Application::GetSolarMutex());
317 const SwFmtFtn* pFmt = FindFmt();
318 if(pFmt)
320 const SwTxtFtn* pTxtFtn = pFmt->GetTxtFtn();
321 DBG_ASSERT(pTxtFtn, "kein TextNode?");
322 SwTxtNode& rTxtNode = (SwTxtNode&)pTxtFtn->GetTxtNode();
323 xub_StrLen nPos = *pTxtFtn->GetStart();
324 SwPaM aPam(rTxtNode, nPos, rTxtNode, nPos+1 );
325 GetDoc()->DeleteAndJoin( aPam );
327 else
328 throw uno::RuntimeException();
331 /*-- 10.12.98 15:31:49---------------------------------------------------
333 -----------------------------------------------------------------------*/
334 void SwXFootnote::addEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
336 if(!GetRegisteredIn())
337 throw uno::RuntimeException();
338 aLstnrCntnr.AddListener(aListener);
340 /*-- 10.12.98 15:31:50---------------------------------------------------
342 -----------------------------------------------------------------------*/
343 void SwXFootnote::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
345 if(!GetRegisteredIn() || !aLstnrCntnr.RemoveListener(aListener))
346 throw uno::RuntimeException();
348 /* -----------------06.05.99 15:31-------------------
350 * --------------------------------------------------*/
351 const SwStartNode *SwXFootnote::GetStartNode() const
353 const SwStartNode *pSttNd = 0;
354 const SwFmtFtn* pFmt = FindFmt();
355 if(pFmt)
357 const SwTxtFtn* pTxtFtn = pFmt->GetTxtFtn();
358 if( pTxtFtn )
359 pSttNd = pTxtFtn->GetStartNode()->GetNode().GetStartNode();
361 return pSttNd;
364 uno::Reference< text::XTextCursor > SwXFootnote::createCursor() throw ( uno::RuntimeException)
366 return createTextCursor();
368 /*-- 10.12.98 15:31:50---------------------------------------------------
370 -----------------------------------------------------------------------*/
371 uno::Reference< text::XTextCursor > SwXFootnote::createTextCursor(void) throw( uno::RuntimeException )
373 vos::OGuard aGuard(Application::GetSolarMutex());
374 uno::Reference< text::XTextCursor > aRef;
375 const SwFmtFtn* pFmt = FindFmt();
376 if(pFmt)
378 const SwTxtFtn* pTxtFtn = pFmt->GetTxtFtn();
379 SwPosition aPos( *pTxtFtn->GetStartNode() );
380 SwXTextCursor* pXCrsr = new SwXTextCursor(this, aPos, CURSOR_FOOTNOTE, GetDoc());
381 aRef = (text::XWordCursor*)pXCrsr;
382 SwUnoCrsr* pUnoCrsr = pXCrsr->GetCrsr();
383 pUnoCrsr->Move(fnMoveForward, fnGoNode);
385 else
386 throw uno::RuntimeException();
387 return aRef;
389 /*-- 10.12.98 15:31:51---------------------------------------------------
391 -----------------------------------------------------------------------*/
392 uno::Reference< text::XTextCursor > SwXFootnote::createTextCursorByRange(
393 const uno::Reference< text::XTextRange > & aTextPosition)
394 throw( uno::RuntimeException )
396 vos::OGuard aGuard(Application::GetSolarMutex());
397 const SwFmtFtn* pFmt = FindFmt();
398 if( !pFmt )
399 throw uno::RuntimeException();
400 uno::Reference< text::XTextCursor > aRef;
401 SwUnoInternalPaM aPam(*GetDoc());
402 if(SwXTextRange::XTextRangeToSwPaM(aPam, aTextPosition))
404 const SwTxtFtn* pTxtFtn = pFmt->GetTxtFtn();
405 const SwNode* pFtnStartNode = &pTxtFtn->GetStartNode()->GetNode();
407 const SwNode* pStart = aPam.GetNode()->FindFootnoteStartNode();
408 if( pStart != pFtnStartNode )
409 throw uno::RuntimeException();
411 aRef = (text::XWordCursor*)new SwXTextCursor(this , *aPam.GetPoint(), CURSOR_FOOTNOTE, GetDoc(), aPam.GetMark());
413 else
414 throw uno::RuntimeException();
415 return aRef;
417 /*-- 13.06.00 14:28:23---------------------------------------------------
419 -----------------------------------------------------------------------*/
420 uno::Reference< container::XEnumeration > SwXFootnote::createEnumeration() throw( uno::RuntimeException )
422 vos::OGuard aGuard(Application::GetSolarMutex());
423 uno::Reference< container::XEnumeration > aRef;
424 const SwFmtFtn* pFmt = FindFmt();
425 if(pFmt)
427 const SwTxtFtn* pTxtFtn = pFmt->GetTxtFtn();
428 SwPosition aPos( *pTxtFtn->GetStartNode() );
429 SwXTextCursor* pXCrsr = new SwXTextCursor(this, aPos, CURSOR_FOOTNOTE, GetDoc());
430 SwUnoCrsr* pUnoCrsr = pXCrsr->GetCrsr();
431 pUnoCrsr->Move(fnMoveForward, fnGoNode);
432 aRef = new SwXParagraphEnumeration(this, pUnoCrsr, CURSOR_FOOTNOTE);
434 return aRef;
436 /*-- 13.06.00 14:28:24---------------------------------------------------
438 -----------------------------------------------------------------------*/
439 uno::Type SwXFootnote::getElementType( ) throw(uno::RuntimeException)
441 return ::getCppuType(static_cast<uno::Reference<XTextRange>*>(0));
443 /*-- 13.06.00 14:28:24---------------------------------------------------
445 -----------------------------------------------------------------------*/
446 sal_Bool SwXFootnote::hasElements( ) throw(uno::RuntimeException)
448 return sal_True;
450 /* -----------------------------07.01.00 12:39--------------------------------
452 ---------------------------------------------------------------------------*/
453 void SwXFootnote::Invalidate()
455 if(GetRegisteredIn())
457 ((SwModify*)GetRegisteredIn())->Remove(this);
458 pFmtFtn = 0;
459 aLstnrCntnr.Disposing();
460 SetDoc(0);
463 /* -----------------18.01.99 09:12-------------------
465 * --------------------------------------------------*/
466 void SwXFootnote::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew)
468 switch( pOld ? pOld->Which() : 0 )
470 case RES_REMOVE_UNO_OBJECT:
471 case RES_OBJECTDYING:
472 if( (void*)GetRegisteredIn() == ((SwPtrMsgPoolItem *)pOld)->pObject )
473 Invalidate();
474 break;
475 case RES_FMT_CHG:
476 // wurden wir an das neue umgehaengt und wird das alte geloscht?
477 if( ((SwFmtChg*)pNew)->pChangedFmt == GetRegisteredIn() &&
478 ((SwFmtChg*)pOld)->pChangedFmt->IsFmtInDTOR() )
479 Invalidate();
480 break;
481 case RES_FOOTNOTE_DELETED:
482 if( (void*)pFmtFtn == ((SwPtrMsgPoolItem *)pOld)->pObject )
483 Invalidate();
484 break;
487 /*-- 11.09.00 13:12:03---------------------------------------------------
489 -----------------------------------------------------------------------*/
490 uno::Reference< beans::XPropertySetInfo > SwXFootnote::getPropertySetInfo( )
491 throw(uno::RuntimeException)
493 static uno::Reference< beans::XPropertySetInfo > xRef = aSwMapProvider.GetPropertySet(PROPERTY_MAP_FOOTNOTE)->getPropertySetInfo();
494 return xRef;
496 /*-- 11.09.00 13:12:04---------------------------------------------------
498 -----------------------------------------------------------------------*/
499 void SwXFootnote::setPropertyValue( const ::rtl::OUString&,
500 const uno::Any& )
501 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
502 lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
504 //no values to be set
505 throw lang::IllegalArgumentException();
507 /*-- 11.09.00 13:12:04---------------------------------------------------
509 -----------------------------------------------------------------------*/
510 uno::Any SwXFootnote::getPropertyValue( const OUString& rPropertyName )
511 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
513 vos::OGuard aGuard(Application::GetSolarMutex());
514 uno::Any aRet;
515 if(!SwXParagraph::getDefaultTextContentValue(aRet, rPropertyName))
517 if(rPropertyName.equalsAsciiL(SW_PROP_NAME(UNO_NAME_START_REDLINE))||
518 rPropertyName.equalsAsciiL(SW_PROP_NAME(UNO_NAME_END_REDLINE)))
520 //redline can only be returned if it's a living object
521 if(!m_bIsDescriptor)
522 aRet = SwXText::getPropertyValue(rPropertyName);
524 else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_REFERENCE_ID)))
526 const SwFmtFtn* pFmt = FindFmt();
527 if(pFmt)
529 const SwTxtFtn* pTxtFtn = pFmt->GetTxtFtn();
530 DBG_ASSERT(pTxtFtn, "no TextNode?");
531 aRet <<= (sal_Int16)pTxtFtn->GetSeqRefNo();
534 else
536 beans::UnknownPropertyException aExcept;
537 aExcept.Message = rPropertyName;
538 throw aExcept;
541 return aRet;
543 /*-- 11.09.00 13:12:04---------------------------------------------------
545 -----------------------------------------------------------------------*/
546 void SwXFootnote::addPropertyChangeListener( const OUString& /*aPropertyName*/,
547 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
548 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
551 /*-- 11.09.00 13:12:04---------------------------------------------------
553 -----------------------------------------------------------------------*/
554 void SwXFootnote::removePropertyChangeListener( const OUString& /*aPropertyName*/,
555 const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
556 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
559 /*-- 11.09.00 13:12:04---------------------------------------------------
561 -----------------------------------------------------------------------*/
562 void SwXFootnote::addVetoableChangeListener( const OUString& /*PropertyName*/,
563 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
564 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
567 /*-- 11.09.00 13:12:05---------------------------------------------------
569 -----------------------------------------------------------------------*/
570 void SwXFootnote::removeVetoableChangeListener( const OUString& /*PropertyName*/,
571 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
572 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)