Update ooo320-m1
[ooovba.git] / sw / source / core / unocore / unorefmk.cxx
blob752022c76371225524cd7e60f13c36b3e7bf2539
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: unorefmk.cxx,v $
10 * $Revision: 1.17 $
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 <unoobj.hxx>
38 #include <unomap.hxx>
39 #include <unocrsr.hxx>
40 #include <doc.hxx>
41 #include <ndtxt.hxx>
42 #include <fmtrfmrk.hxx>
43 #include <txtrfmrk.hxx>
44 #include <hints.hxx>
46 using namespace ::com::sun::star;
47 using ::rtl::OUString;
49 /******************************************************************
50 * SwXReferenceMark
51 ******************************************************************/
53 /* -----------------------------13.03.00 12:15--------------------------------
55 ---------------------------------------------------------------------------*/
56 const uno::Sequence< sal_Int8 > & SwXReferenceMark::getUnoTunnelId()
58 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
59 return aSeq;
61 /* -----------------------------10.03.00 18:04--------------------------------
63 ---------------------------------------------------------------------------*/
64 sal_Int64 SAL_CALL SwXReferenceMark::getSomething( const uno::Sequence< sal_Int8 >& rId )
65 throw(uno::RuntimeException)
67 if( rId.getLength() == 16
68 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
69 rId.getConstArray(), 16 ) )
71 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
73 return 0;
75 /* -----------------------------06.04.00 16:41--------------------------------
77 ---------------------------------------------------------------------------*/
78 OUString SwXReferenceMark::getImplementationName(void) throw( uno::RuntimeException )
80 return C2U("SwXReferenceMark");
82 /* -----------------------------06.04.00 16:41--------------------------------
84 ---------------------------------------------------------------------------*/
85 BOOL SwXReferenceMark::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
87 return !rServiceName.compareToAscii("com.sun.star.text.ReferenceMark")||
88 !rServiceName.compareToAscii("com.sun.star.text.TextContent");
90 /* -----------------------------06.04.00 16:41--------------------------------
92 ---------------------------------------------------------------------------*/
93 uno::Sequence< OUString > SwXReferenceMark::getSupportedServiceNames(void) throw( uno::RuntimeException )
95 uno::Sequence< OUString > aRet(2);
96 OUString* pArray = aRet.getArray();
97 pArray[0] = C2U("com.sun.star.text.ReferenceMark");
98 pArray[1] = C2U("com.sun.star.text.TextContent");
99 return aRet;
101 /*-- 11.12.98 10:28:32---------------------------------------------------
103 -----------------------------------------------------------------------*/
104 TYPEINIT1(SwXReferenceMark, SwClient);
106 SwXReferenceMark::SwXReferenceMark(SwDoc* pDc, const SwFmtRefMark* pRefMark) :
107 aLstnrCntnr( (text::XTextContent*)this),
108 pDoc(pDc),
109 pMark(pRefMark),
110 m_bIsDescriptor(0 == pRefMark)
112 if(pRefMark)
113 sMarkName = pRefMark->GetRefName();
114 if(pDoc)
115 pDoc->GetUnoCallBack()->Add(this);
117 /*-- 11.12.98 10:28:33---------------------------------------------------
119 -----------------------------------------------------------------------*/
120 SwXReferenceMark::~SwXReferenceMark()
124 /* -----------------03.11.99 14:14-------------------
126 --------------------------------------------------*/
127 void SwXReferenceMark::InsertRefMark(SwPaM& rPam, SwXTextCursor * pCursor)
129 //! in some cases when this function is called the pDoc pointer member may have become
130 //! invalid/deleted thus we obtain the document pointer from rPaM where it should always
131 //! be valid.
132 SwDoc *pDoc2 = rPam.GetDoc();
134 UnoActionContext aCont(pDoc2);
135 SwTxtAttr* pTxtAttr = 0;
136 SwFmtRefMark aRefMark(sMarkName);
137 // SfxItemSet aSet(pDoc2->GetAttrPool(), RES_TXTATR_REFMARK, RES_TXTATR_REFMARK, 0L);
138 // aSet.Put(aRefMark);
139 sal_Bool bMark = *rPam.GetPoint() != *rPam.GetMark();
140 // SwXTextCursor::SetCrsrAttr(rPam, aSet, 0);
142 const bool bForceExpandHints( (!bMark && pCursor)
143 ? pCursor->IsAtEndOfMeta() : false );
144 const SetAttrMode nInsertFlags = (bForceExpandHints)
145 ? ( nsSetAttrMode::SETATTR_FORCEHINTEXPAND
146 | nsSetAttrMode::SETATTR_DONTEXPAND)
147 : nsSetAttrMode::SETATTR_DONTEXPAND;
149 pDoc2->InsertPoolItem( rPam, aRefMark, nInsertFlags );
151 if( bMark && *rPam.GetPoint() > *rPam.GetMark())
152 rPam.Exchange();
154 if( bMark )
155 pTxtAttr = rPam.GetNode()->GetTxtNode()->GetTxtAttr(
156 rPam.GetPoint()->nContent, RES_TXTATR_REFMARK );
157 else
159 pTxtAttr = rPam.GetNode()->GetTxtNode()->GetTxtAttrForCharAt(
160 rPam.GetPoint()->nContent.GetIndex()-1, RES_TXTATR_REFMARK );
163 if(pTxtAttr)
164 pMark = &pTxtAttr->GetRefMark();
166 pDoc2->GetUnoCallBack()->Add(this);
169 /* -----------------18.02.99 13:33-------------------
171 * --------------------------------------------------*/
172 void SwXReferenceMark::attachToRange(const uno::Reference< text::XTextRange > & xTextRange)
173 throw( lang::IllegalArgumentException, uno::RuntimeException )
175 if(!m_bIsDescriptor)
176 throw uno::RuntimeException();
177 uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
178 SwXTextRange* pRange = 0;
179 OTextCursorHelper* pCursor = 0;
180 if(xRangeTunnel.is())
182 pRange = reinterpret_cast< SwXTextRange * >(
183 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) ));
184 pCursor = reinterpret_cast< OTextCursorHelper * >(
185 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
187 SwDoc* pDocument = pRange ? (SwDoc*)pRange->GetDoc() : pCursor ? (SwDoc*)pCursor->GetDoc() : 0;
188 if(pDocument)
190 SwUnoInternalPaM aPam(*pDocument);
191 //das muss jetzt sal_True liefern
192 SwXTextRange::XTextRangeToSwPaM(aPam, xTextRange);
193 InsertRefMark(aPam, dynamic_cast<SwXTextCursor*>(pCursor));
194 m_bIsDescriptor = sal_False;
195 pDoc = pDocument;
196 pDoc->GetUnoCallBack()->Add(this);
198 else
199 throw lang::IllegalArgumentException();
201 /*-- 11.12.98 10:28:34---------------------------------------------------
203 -----------------------------------------------------------------------*/
204 void SwXReferenceMark::attach(const uno::Reference< text::XTextRange > & xTextRange)
205 throw( lang::IllegalArgumentException, uno::RuntimeException )
207 vos::OGuard aGuard(Application::GetSolarMutex());
208 attachToRange( xTextRange );
210 /*-- 11.12.98 10:28:34---------------------------------------------------
212 -----------------------------------------------------------------------*/
213 uno::Reference< text::XTextRange > SwXReferenceMark::getAnchor(void) throw( uno::RuntimeException )
215 vos::OGuard aGuard(Application::GetSolarMutex());
216 uno::Reference< text::XTextRange > xRet;
217 if(IsValid())
219 const SwFmtRefMark* pNewMark = pDoc->GetRefMark(sMarkName);
220 if(pNewMark && pNewMark == pMark)
222 const SwTxtRefMark* pTxtMark = pMark->GetTxtRefMark();
223 if(pTxtMark &&
224 &pTxtMark->GetTxtNode().GetNodes() == &pDoc->GetNodes())
226 SwTxtNode& rTxtNode = (SwTxtNode&)pTxtMark->GetTxtNode();
227 SwPaM* pPam = pTxtMark->GetEnd() ?
228 new SwPaM( rTxtNode, *pTxtMark->GetEnd(),
229 rTxtNode, *pTxtMark->GetStart()) :
230 new SwPaM( rTxtNode, *pTxtMark->GetStart());
233 xRet = SwXTextRange::CreateTextRangeFromPosition(pDoc,
234 *pPam->Start(), pPam->End());
235 delete pPam;
239 return xRet;
241 /*-- 11.12.98 10:28:35---------------------------------------------------
243 -----------------------------------------------------------------------*/
244 void SwXReferenceMark::dispose(void) throw( uno::RuntimeException )
246 vos::OGuard aGuard(Application::GetSolarMutex());
247 if(IsValid())
249 const SwFmtRefMark* pNewMark = pDoc->GetRefMark(sMarkName);
250 if(pNewMark && pNewMark == pMark)
252 const SwTxtRefMark* pTxtMark = pMark->GetTxtRefMark();
253 if(pTxtMark &&
254 &pTxtMark->GetTxtNode().GetNodes() == &pDoc->GetNodes())
256 SwTxtNode& rTxtNode = (SwTxtNode&)pTxtMark->GetTxtNode();
257 xub_StrLen nStt = *pTxtMark->GetStart(),
258 nEnd = pTxtMark->GetEnd() ? *pTxtMark->GetEnd()
259 : nStt + 1;
261 SwPaM aPam( rTxtNode, nStt, rTxtNode, nEnd );
262 pDoc->DeleteAndJoin( aPam );
266 else
267 throw uno::RuntimeException();
269 /*-- 11.12.98 10:28:35---------------------------------------------------
271 -----------------------------------------------------------------------*/
272 void SwXReferenceMark::addEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
274 if(!GetRegisteredIn())
275 throw uno::RuntimeException();
276 aLstnrCntnr.AddListener(aListener);
278 /*-- 11.12.98 10:28:35---------------------------------------------------
280 -----------------------------------------------------------------------*/
281 void SwXReferenceMark::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
283 if(!GetRegisteredIn() || !aLstnrCntnr.RemoveListener(aListener))
284 throw uno::RuntimeException();
286 /*-- 11.12.98 10:28:36---------------------------------------------------
288 -----------------------------------------------------------------------*/
289 OUString SwXReferenceMark::getName(void) throw( uno::RuntimeException )
291 vos::OGuard aGuard(Application::GetSolarMutex());
292 if(!IsValid() || !pDoc->GetRefMark(sMarkName))
294 throw uno::RuntimeException();
296 return sMarkName;
298 /*-- 11.12.98 10:28:36---------------------------------------------------
300 -----------------------------------------------------------------------*/
301 void SwXReferenceMark::setName(const OUString& Name_) throw( uno::RuntimeException )
303 vos::OGuard aGuard(Application::GetSolarMutex());
304 if(m_bIsDescriptor)
305 sMarkName = String(Name_);
306 else
308 String sNewName(Name_);
309 if(!IsValid() || !pDoc->GetRefMark(sMarkName) || pDoc->GetRefMark(sNewName))
311 throw uno::RuntimeException();
313 const SwFmtRefMark* pCurMark = pDoc->GetRefMark(sMarkName);
314 if(sNewName != sMarkName && pCurMark && pCurMark == pMark)
316 UnoActionContext aCont(pDoc);
317 const SwTxtRefMark* pTxtMark = pMark->GetTxtRefMark();
318 if(pTxtMark &&
319 &pTxtMark->GetTxtNode().GetNodes() == &pDoc->GetNodes())
321 SwTxtNode& rTxtNode = (SwTxtNode&)pTxtMark->GetTxtNode();
322 xub_StrLen nStt = *pTxtMark->GetStart(),
323 nEnd = pTxtMark->GetEnd() ? *pTxtMark->GetEnd()
324 : nStt + 1;
326 SwPaM aPam( rTxtNode, nStt, rTxtNode, nEnd );
327 pDoc->DeleteAndJoin( aPam ); //! deletes the pDoc member in the SwXReferenceMark
328 //! The aPam will keep the correct and functional doc though
330 sMarkName = sNewName;
331 //create a new one
332 InsertRefMark( aPam, 0 );
333 pDoc = aPam.GetDoc();
338 /* -----------------------------07.01.00 12:51--------------------------------
340 ---------------------------------------------------------------------------*/
341 void SwXReferenceMark::Invalidate()
343 if(GetRegisteredIn())
345 ((SwModify*)GetRegisteredIn())->Remove(this);
346 aLstnrCntnr.Disposing();
347 pDoc = 0;
348 pMark = 0;
351 /*-- 11.12.98 10:28:37---------------------------------------------------
353 -----------------------------------------------------------------------*/
354 void SwXReferenceMark::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew)
356 switch( pOld ? pOld->Which() : 0 )
358 case RES_REMOVE_UNO_OBJECT:
359 case RES_OBJECTDYING:
360 if( (void*)GetRegisteredIn() == ((SwPtrMsgPoolItem *)pOld)->pObject )
361 Invalidate();
362 break;
363 case RES_FMT_CHG:
364 // wurden wir an das neue umgehaengt und wird das alte geloscht?
365 if( ((SwFmtChg*)pNew)->pChangedFmt == GetRegisteredIn() &&
366 ((SwFmtChg*)pOld)->pChangedFmt->IsFmtInDTOR() )
367 Invalidate();
368 break;
369 case RES_REFMARK_DELETED:
370 if( (void*)pMark == ((SwPtrMsgPoolItem *)pOld)->pObject )
371 Invalidate();
372 break;
376 /*-- 12.09.00 12:58:20---------------------------------------------------
378 -----------------------------------------------------------------------*/
379 uno::Reference< beans::XPropertySetInfo > SwXReferenceMark::getPropertySetInfo( ) throw(uno::RuntimeException)
381 static uno::Reference< beans::XPropertySetInfo > xRef =
382 aSwMapProvider.GetPropertySet(PROPERTY_MAP_PARAGRAPH_EXTENSIONS)->getPropertySetInfo();
383 return xRef;
385 /*-- 12.09.00 12:58:20---------------------------------------------------
387 -----------------------------------------------------------------------*/
388 void SwXReferenceMark::setPropertyValue(
389 const OUString& /*rPropertyName*/, const uno::Any& /*rValue*/ )
390 throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
392 throw lang::IllegalArgumentException();
394 /*-- 12.09.00 12:58:20---------------------------------------------------
396 -----------------------------------------------------------------------*/
397 uno::Any SwXReferenceMark::getPropertyValue( const OUString& rPropertyName )
398 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
400 uno::Any aRet;
401 if(!SwXParagraph::getDefaultTextContentValue(aRet, rPropertyName))
402 throw beans::UnknownPropertyException();
403 return aRet;
405 /*-- 12.09.00 12:58:20---------------------------------------------------
407 -----------------------------------------------------------------------*/
408 void SwXReferenceMark::addPropertyChangeListener(
409 const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
410 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
413 /*-- 12.09.00 12:58:20---------------------------------------------------
415 -----------------------------------------------------------------------*/
416 void SwXReferenceMark::removePropertyChangeListener(
417 const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
418 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
421 /*-- 12.09.00 12:58:20---------------------------------------------------
423 -----------------------------------------------------------------------*/
424 void SwXReferenceMark::addVetoableChangeListener( const OUString& /*rPropertyName*/,
425 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/ )
426 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
429 /*-- 12.09.00 12:58:21---------------------------------------------------
431 -----------------------------------------------------------------------*/
432 void SwXReferenceMark::removeVetoableChangeListener(
433 const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/ )
434 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
438 #include <com/sun/star/lang/DisposedException.hpp>
439 #include <unometa.hxx>
440 #include <unoport.hxx>
441 #include <txtatr.hxx>
442 #include <fmtmeta.hxx>
443 #include <docsh.hxx>
445 //=============================================================================
447 /******************************************************************
448 * SwXMetaText
449 ******************************************************************/
451 class SwXMetaText
452 : public SwXText
454 private:
455 SwXMeta & m_rMeta;
457 virtual void PrepareForAttach(uno::Reference< text::XTextRange > & xRange,
458 const SwXTextRange* const pRange, const SwPaM * const pPam);
460 virtual bool CheckForOwnMemberMeta(const SwXTextRange* const pRange,
461 const SwPaM* const pPam, bool bAbsorb)
462 throw (::com::sun::star::lang::IllegalArgumentException,
463 ::com::sun::star::uno::RuntimeException);
465 protected:
466 virtual const SwStartNode *GetStartNode() const;
467 virtual uno::Reference< text::XTextCursor >
468 createCursor() throw (uno::RuntimeException);
470 public:
471 SwXMetaText(SwDoc & rDoc, SwXMeta & rMeta);
473 // XInterface
474 virtual void SAL_CALL acquire() throw()
475 { OSL_ENSURE(false, "ERROR: SwXMetaText::acquire"); }
476 virtual void SAL_CALL release() throw()
477 { OSL_ENSURE(false, "ERROR: SwXMetaText::release"); }
479 // XTypeProvider
480 virtual uno::Sequence< sal_Int8 > SAL_CALL
481 getImplementationId() throw (uno::RuntimeException);
483 // XText
484 virtual uno::Reference< text::XTextCursor > SAL_CALL
485 createTextCursor() throw (uno::RuntimeException);
486 virtual uno::Reference< text::XTextCursor > SAL_CALL
487 createTextCursorByRange(
488 const uno::Reference< text::XTextRange > & xTextPosition)
489 throw (uno::RuntimeException);
493 SwXMetaText::SwXMetaText(SwDoc & rDoc, SwXMeta & rMeta)
494 : SwXText(&rDoc, CURSOR_META)
495 , m_rMeta(rMeta)
499 const SwStartNode *SwXMetaText::GetStartNode() const
501 SwXText const * const pParent(
502 dynamic_cast<SwXText*>(m_rMeta.GetParentText().get()));
503 return (pParent) ? pParent->GetStartNode() : 0;
506 void SwXMetaText::PrepareForAttach( uno::Reference<text::XTextRange> & xRange,
507 const SwXTextRange* const pRange, const SwPaM * const pPam)
509 SwPosition const* pPoint(0);
510 SwPosition const* pMark (0);
511 if (pRange)
513 ::sw::mark::IMark const& rIMark(*pRange->GetBookmark());
514 pMark = &rIMark.GetMarkPos();
515 if (rIMark.IsExpanded())
517 pMark = &rIMark.GetOtherMarkPos();
520 else if (pPam)
522 pPoint = pPam->GetPoint();
523 if (pPam->HasMark())
525 pMark = pPam->GetMark();
528 // create a new cursor to prevent modifying SwXTextRange
529 if (pPoint)
531 xRange = static_cast<text::XWordCursor*>(
532 new SwXTextCursor(&m_rMeta, *pPoint, CURSOR_META, GetDoc(), pMark));
536 bool SwXMetaText::CheckForOwnMemberMeta(const SwXTextRange* const pRange,
537 const SwPaM* const pPam, bool bAbsorb)
538 throw (::com::sun::star::lang::IllegalArgumentException,
539 ::com::sun::star::uno::RuntimeException)
541 return m_rMeta.CheckForOwnMemberMeta(pRange, pPam, bAbsorb);
544 uno::Reference< text::XTextCursor > SwXMetaText::createCursor()
545 throw (uno::RuntimeException)
547 uno::Reference< text::XTextCursor > xRet;
548 if (IsValid())
550 SwTxtNode * pTxtNode;
551 xub_StrLen nMetaStart;
552 xub_StrLen nMetaEnd;
553 const bool bSuccess(
554 m_rMeta.SetContentRange(pTxtNode, nMetaStart, nMetaEnd) );
555 if (bSuccess)
557 SwPosition aPos(*pTxtNode, nMetaStart);
558 xRet = static_cast<text::XWordCursor*>(
559 new SwXTextCursor(&m_rMeta, aPos, CURSOR_META, GetDoc()));
562 return xRet;
565 uno::Sequence<sal_Int8> SAL_CALL
566 SwXMetaText::getImplementationId() throw (uno::RuntimeException)
568 return m_rMeta.getImplementationId();
571 // XText
572 uno::Reference< text::XTextCursor > SAL_CALL
573 SwXMetaText::createTextCursor() throw (uno::RuntimeException)
575 return createCursor();
578 uno::Reference< text::XTextCursor > SAL_CALL
579 SwXMetaText::createTextCursorByRange(
580 const uno::Reference<text::XTextRange> & xTextPosition)
581 throw (uno::RuntimeException)
583 const uno::Reference<text::XTextCursor> xCursor( createCursor() );
584 xCursor->gotoRange(xTextPosition, sal_False);
585 return xCursor;
588 /******************************************************************
589 * SwXMeta
590 ******************************************************************/
592 // the Meta has a cached list of text portions for its contents
593 // this list is created by SwXTextPortionEnumeration
594 // the Meta listens at the SwTxtNode and throws away the cache when it changes
596 struct SwXMeta::Impl
598 SwEventListenerContainer m_ListenerContainer;
599 ::std::auto_ptr<const TextRangeList_t> m_pTextPortions;
600 // 3 possible states: not attached, attached, disposed
601 bool m_bIsDisposed;
602 bool m_bIsDescriptor;
603 uno::Reference<text::XText> m_xParentText;
604 SwXMetaText m_Text;
606 Impl(SwXMeta & rThis, SwDoc & rDoc,
607 uno::Reference<text::XText> const& xParentText,
608 TextRangeList_t const * const pPortions,
609 SwTxtMeta const * const pHint)
610 : m_ListenerContainer(
611 static_cast< ::cppu::OWeakObject* >(&rThis))
612 , m_pTextPortions( pPortions )
613 , m_bIsDisposed( false )
614 , m_bIsDescriptor( 0 == pHint )
615 , m_xParentText(xParentText)
616 , m_Text(rDoc, rThis)
621 TYPEINIT1(SwXMeta, SwClient);
623 inline const ::sw::Meta * SwXMeta::GetMeta() const
625 return static_cast< const ::sw::Meta * >(GetRegisteredIn());
628 uno::Reference<text::XText> SwXMeta::GetParentText() const
630 return m_pImpl->m_xParentText;
633 bool SwXMeta::SetContentRange(
634 SwTxtNode *& rpNode, xub_StrLen & rStart, xub_StrLen & rEnd ) const
636 ::sw::Meta const * const pMeta( GetMeta() );
637 if (pMeta)
639 SwTxtMeta const * const pTxtAttr( pMeta->GetTxtAttr() );
640 if (pTxtAttr)
642 rpNode = pTxtAttr->GetTxtNode();
643 if (rpNode)
645 // rStart points at the first position _within_ the meta!
646 rStart = *pTxtAttr->GetStart() + 1;
647 rEnd = *pTxtAttr->GetEnd();
648 return true;
652 return false;
655 SwXMeta::SwXMeta(SwDoc *const pDoc,
656 uno::Reference<text::XText> const& xParentText,
657 TextRangeList_t * const pPortions, SwTxtMeta * const pHint)
658 : m_pImpl( new SwXMeta::Impl(*this, *pDoc, xParentText, pPortions, pHint) )
660 if (pHint)
662 ::sw::Meta * const pMeta(
663 static_cast<SwFmtMeta&>(pHint->GetAttr()).GetMeta() );
664 ASSERT(pMeta, "SwXMeta: no meta?")
665 if (pMeta)
667 pMeta->Add(this);
672 bool SwXMeta::CheckForOwnMemberMeta(const SwXTextRange* const pRange,
673 const SwPaM* const pPam, bool bAbsorb)
674 throw (lang::IllegalArgumentException, uno::RuntimeException)
676 ASSERT((pPam && !pRange) || (!pPam && pRange), "ERROR: pam xor range");
677 SwTxtNode * pTxtNode;
678 xub_StrLen nMetaStart;
679 xub_StrLen nMetaEnd;
680 const bool bSuccess( SetContentRange(pTxtNode, nMetaStart, nMetaEnd) );
681 ASSERT(bSuccess, "no pam?");
682 if (!bSuccess)
683 throw lang::DisposedException();
684 SwPosition const * const pStartPos( (pPam)
685 ? pPam->Start()
686 : &pRange->GetBookmark()->GetMarkStart() );
687 if (&pStartPos->nNode.GetNode() != pTxtNode)
689 throw lang::IllegalArgumentException(
690 C2U("trying to insert into a nesting text content, but start "
691 "of text range not in same paragraph as text content"),
692 0, 0);
694 bool bForceExpandHints(false);
695 const xub_StrLen nStartPos(pStartPos->nContent.GetIndex());
696 // not <= but < because nMetaStart is behind dummy char!
697 // not >= but > because == means insert at end!
698 if ((nStartPos < nMetaStart) || (nStartPos > nMetaEnd))
700 throw lang::IllegalArgumentException(
701 C2U("trying to insert into a nesting text content, but start "
702 "of text range not inside text content"),
703 0, 0);
705 else if (nStartPos == nMetaEnd)
707 bForceExpandHints = true;
709 const bool bHasEnd( (pPam)
710 ? pPam->HasMark()
711 : pRange->GetBookmark()->IsExpanded());
712 if (bHasEnd && bAbsorb)
714 SwPosition const * const pEndPos( (pPam)
715 ? pPam->End()
716 : &pRange->GetBookmark()->GetMarkEnd() );
717 if (&pEndPos->nNode.GetNode() != pTxtNode)
719 throw lang::IllegalArgumentException(
720 C2U("trying to insert into a nesting text content, but end "
721 "of text range not in same paragraph as text content"),
722 0, 0);
724 const xub_StrLen nEndPos(pEndPos->nContent.GetIndex());
725 // not <= but < because nMetaStart is behind dummy char!
726 // not >= but > because == means insert at end!
727 if ((nEndPos < nMetaStart) || (nEndPos > nMetaEnd))
729 throw lang::IllegalArgumentException(
730 C2U("trying to insert into a nesting text content, but end "
731 "of text range not inside text content"),
732 0, 0);
734 else if (nEndPos == nMetaEnd)
736 bForceExpandHints = true;
739 return bForceExpandHints;
743 SwXMeta::SwXMeta(SwDoc *const pDoc)
744 : m_pImpl( new SwXMeta::Impl(*this, *pDoc, 0, 0, 0) )
748 SwXMeta::~SwXMeta()
752 const uno::Sequence< sal_Int8 > & SwXMeta::getUnoTunnelId()
754 static uno::Sequence< sal_Int8 > aSeq( ::CreateUnoTunnelId() );
755 return aSeq;
758 // XUnoTunnel
759 sal_Int64 SAL_CALL
760 SwXMeta::getSomething( const uno::Sequence< sal_Int8 > & i_rId )
761 throw (uno::RuntimeException)
763 if ( i_rId.getLength() == 16 &&
764 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
765 i_rId.getConstArray(), 16 ) )
767 return sal::static_int_cast< sal_Int64 >(
768 reinterpret_cast< sal_IntPtr >(this) );
770 return 0;
773 // XServiceInfo
774 ::rtl::OUString SAL_CALL
775 SwXMeta::getImplementationName() throw (uno::RuntimeException)
777 return C2U("SwXMeta");
780 sal_Bool SAL_CALL
781 SwXMeta::supportsService(const ::rtl::OUString& rServiceName)
782 throw (uno::RuntimeException)
784 return rServiceName.equalsAscii("com.sun.star.text.TextContent")
785 || rServiceName.equalsAscii("com.sun.star.text.InContentMetadata");
788 uno::Sequence< ::rtl::OUString > SAL_CALL
789 SwXMeta::getSupportedServiceNames() throw (uno::RuntimeException)
791 uno::Sequence< ::rtl::OUString > aRet(2);
792 aRet[0] = C2U("com.sun.star.text.TextContent");
793 aRet[1] = C2U("com.sun.star.text.InContentMetadata");
794 return aRet;
798 // XComponent
799 void SAL_CALL
800 SwXMeta::addEventListener(
801 uno::Reference< lang::XEventListener> const & xListener )
802 throw (uno::RuntimeException)
804 vos::OGuard g(Application::GetSolarMutex());
806 m_pImpl->m_ListenerContainer.AddListener(xListener);
807 if (m_pImpl->m_bIsDisposed)
809 m_pImpl->m_ListenerContainer.Disposing();
813 void SAL_CALL
814 SwXMeta::removeEventListener(
815 uno::Reference< lang::XEventListener> const & xListener )
816 throw (uno::RuntimeException)
818 vos::OGuard g(Application::GetSolarMutex());
820 if (!m_pImpl->m_bIsDisposed)
822 m_pImpl->m_ListenerContainer.RemoveListener(xListener);
826 void SAL_CALL
827 SwXMeta::dispose() throw (uno::RuntimeException)
829 vos::OGuard g(Application::GetSolarMutex());
831 if (m_pImpl->m_bIsDescriptor)
833 m_pImpl->m_pTextPortions.reset();
834 m_pImpl->m_ListenerContainer.Disposing();
835 m_pImpl->m_bIsDisposed = true;
836 m_pImpl->m_Text.Invalidate();
838 else if (!m_pImpl->m_bIsDisposed)
840 SwTxtNode * pTxtNode;
841 xub_StrLen nMetaStart;
842 xub_StrLen nMetaEnd;
843 const bool bSuccess(SetContentRange(pTxtNode, nMetaStart, nMetaEnd));
844 ASSERT(bSuccess, "no pam?");
845 if (bSuccess)
847 // -1 because of CH_TXTATR
848 SwPaM aPam( *pTxtNode, nMetaStart - 1, *pTxtNode, nMetaEnd );
849 SwDoc * const pDoc( pTxtNode->GetDoc() );
850 pDoc->DeleteAndJoin( aPam );
852 // removal should call Modify and do the dispose
853 OSL_ENSURE(m_pImpl->m_bIsDisposed, "zombie meta");
859 void SAL_CALL
860 SwXMeta::AttachImpl(const uno::Reference< text::XTextRange > & i_xTextRange,
861 const USHORT i_nWhich)
862 throw (lang::IllegalArgumentException, uno::RuntimeException)
864 vos::OGuard g(Application::GetSolarMutex());
866 if (m_pImpl->m_bIsDisposed)
868 throw lang::DisposedException();
870 if (!m_pImpl->m_bIsDescriptor)
872 throw uno::RuntimeException(
873 C2S("SwXMeta::attach(): already attached"),
874 static_cast< ::cppu::OWeakObject* >(this));
877 uno::Reference<lang::XUnoTunnel> xRangeTunnel(i_xTextRange, uno::UNO_QUERY);
878 if (!xRangeTunnel.is())
880 throw lang::IllegalArgumentException(
881 C2S("SwXMeta::attach(): argument is no XUnoTunnel"),
882 static_cast< ::cppu::OWeakObject* >(this), 0);
884 SwXTextRange * const pRange(
885 reinterpret_cast< SwXTextRange * >(
886 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething(
887 SwXTextRange::getUnoTunnelId() ))) );
888 OTextCursorHelper * const pCursor( pRange ? 0 :
889 reinterpret_cast< OTextCursorHelper * >(
890 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething(
891 OTextCursorHelper::getUnoTunnelId() ))) );
892 if (!pRange && !pCursor)
894 throw lang::IllegalArgumentException(
895 C2S("SwXMeta::attach(): argument not supported type"),
896 static_cast< ::cppu::OWeakObject* >(this), 0);
899 SwDoc * const pDoc(
900 pRange ? pRange->GetDoc() : pCursor ? pCursor->GetDoc() : 0 );
901 if (!pDoc)
903 throw lang::IllegalArgumentException(
904 C2S("SwXMeta::attach(): argument has no SwDoc"),
905 static_cast< ::cppu::OWeakObject* >(this), 0);
908 SwUnoInternalPaM aPam(*pDoc);
909 SwXTextRange::XTextRangeToSwPaM(aPam, i_xTextRange);
911 UnoActionContext aContext(pDoc);
913 SwXTextCursor const*const pTextCursor(
914 dynamic_cast<SwXTextCursor*>(pCursor));
915 const bool bForceExpandHints((pTextCursor)
916 ? pTextCursor->IsAtEndOfMeta() : false);
917 const SetAttrMode nInsertFlags( (bForceExpandHints)
918 ? ( nsSetAttrMode::SETATTR_FORCEHINTEXPAND
919 | nsSetAttrMode::SETATTR_DONTEXPAND)
920 : nsSetAttrMode::SETATTR_DONTEXPAND );
922 const ::boost::shared_ptr< ::sw::Meta> pMeta( (RES_TXTATR_META == i_nWhich)
923 ? ::boost::shared_ptr< ::sw::Meta>( new ::sw::Meta() )
924 : ::boost::shared_ptr< ::sw::Meta>(
925 pDoc->GetMetaFieldManager().makeMetaField()) );
926 SwFmtMeta meta(pMeta, i_nWhich); // this is cloned by Insert!
927 const bool bSuccess( pDoc->InsertPoolItem( aPam, meta, nInsertFlags ) );
928 SwTxtAttr * const pTxtAttr( pMeta->GetTxtAttr() );
929 if (!bSuccess)
931 throw lang::IllegalArgumentException(
932 C2S("SwXMeta::attach(): cannot create meta: range invalid?"),
933 static_cast< ::cppu::OWeakObject* >(this), 1);
935 if (!pTxtAttr)
937 ASSERT(false, "meta inserted, but has no text attribute?");
938 throw uno::RuntimeException(
939 C2S("SwXMeta::attach(): cannot create meta"),
940 static_cast< ::cppu::OWeakObject* >(this));
943 pMeta->Add(this);
945 m_pImpl->m_xParentText =
946 SwXTextRange::CreateParentXText(pDoc, *aPam.GetPoint());
948 m_pImpl->m_bIsDescriptor = false;
951 // XTextContent
952 void SAL_CALL
953 SwXMeta::attach(const uno::Reference< text::XTextRange > & i_xTextRange)
954 throw (lang::IllegalArgumentException, uno::RuntimeException)
956 return SwXMeta::AttachImpl(i_xTextRange, RES_TXTATR_META);
959 uno::Reference< text::XTextRange > SAL_CALL
960 SwXMeta::getAnchor() throw (uno::RuntimeException)
962 vos::OGuard g(Application::GetSolarMutex());
964 if (m_pImpl->m_bIsDisposed)
966 throw lang::DisposedException();
968 if (m_pImpl->m_bIsDescriptor)
970 throw uno::RuntimeException(
971 C2S("SwXMeta::getAnchor(): not inserted"),
972 static_cast< ::cppu::OWeakObject* >(this));
975 SwTxtNode * pTxtNode;
976 xub_StrLen nMetaStart;
977 xub_StrLen nMetaEnd;
978 const bool bSuccess(SetContentRange(pTxtNode, nMetaStart, nMetaEnd));
979 ASSERT(bSuccess, "no pam?");
980 if (!bSuccess)
982 throw lang::DisposedException(
983 C2S("SwXMeta::getAnchor(): not attached"),
984 static_cast< ::cppu::OWeakObject* >(this));
987 const SwPosition start(*pTxtNode, nMetaStart - 1); // -1 due to CH_TXTATR
988 const SwPosition end(*pTxtNode, nMetaEnd);
989 return SwXTextRange::CreateTextRangeFromPosition(
990 pTxtNode->GetDoc(), start, &end);
993 // XTextRange
994 uno::Reference< text::XText > SAL_CALL
995 SwXMeta::getText() throw (uno::RuntimeException)
997 vos::OGuard g(Application::GetSolarMutex());
998 //TODO probably this should return outer meta in case there is nesting,
999 // but currently that is not done; would need to change at least
1000 // SwXTextPortionEnumeration and SwXMeta::attach and other places where
1001 // SwXMeta is constructed
1002 return GetParentText();
1005 uno::Reference< text::XTextRange > SAL_CALL
1006 SwXMeta::getStart() throw (uno::RuntimeException)
1008 vos::OGuard g(Application::GetSolarMutex());
1009 return m_pImpl->m_Text.getStart();
1012 uno::Reference< text::XTextRange > SAL_CALL
1013 SwXMeta::getEnd() throw (uno::RuntimeException)
1015 vos::OGuard g(Application::GetSolarMutex());
1016 return m_pImpl->m_Text.getEnd();
1019 rtl::OUString SAL_CALL
1020 SwXMeta::getString() throw (uno::RuntimeException)
1022 vos::OGuard g(Application::GetSolarMutex());
1023 return m_pImpl->m_Text.getString();
1026 void SAL_CALL
1027 SwXMeta::setString(const rtl::OUString& rString) throw (uno::RuntimeException)
1029 vos::OGuard g(Application::GetSolarMutex());
1030 return m_pImpl->m_Text.setString(rString);
1033 // XSimpleText
1034 uno::Reference< text::XTextCursor > SAL_CALL
1035 SwXMeta::createTextCursor() throw (uno::RuntimeException)
1037 vos::OGuard g(Application::GetSolarMutex());
1038 return m_pImpl->m_Text.createTextCursor();
1041 uno::Reference< text::XTextCursor > SAL_CALL
1042 SwXMeta::createTextCursorByRange(
1043 const uno::Reference<text::XTextRange> & xTextPosition)
1044 throw (uno::RuntimeException)
1046 vos::OGuard g(Application::GetSolarMutex());
1047 return m_pImpl->m_Text.createTextCursorByRange(xTextPosition);
1050 void SAL_CALL
1051 SwXMeta::insertString(const uno::Reference<text::XTextRange> & xRange,
1052 const rtl::OUString& rString, sal_Bool bAbsorb)
1053 throw (uno::RuntimeException)
1055 vos::OGuard g(Application::GetSolarMutex());
1056 return m_pImpl->m_Text.insertString(xRange, rString, bAbsorb);
1059 void SAL_CALL
1060 SwXMeta::insertControlCharacter(const uno::Reference<text::XTextRange> & xRange,
1061 sal_Int16 nControlCharacter, sal_Bool bAbsorb)
1062 throw (lang::IllegalArgumentException, uno::RuntimeException)
1064 vos::OGuard g(Application::GetSolarMutex());
1065 return m_pImpl->m_Text.insertControlCharacter(xRange, nControlCharacter,
1066 bAbsorb);
1069 // XText
1070 void SAL_CALL
1071 SwXMeta::insertTextContent( const uno::Reference<text::XTextRange> & xRange,
1072 const uno::Reference<text::XTextContent> & xContent, sal_Bool bAbsorb)
1073 throw (lang::IllegalArgumentException, uno::RuntimeException)
1075 vos::OGuard g(Application::GetSolarMutex());
1076 return m_pImpl->m_Text.insertTextContent(xRange, xContent, bAbsorb);
1079 void SAL_CALL
1080 SwXMeta::removeTextContent(
1081 const uno::Reference< text::XTextContent > & xContent)
1082 throw (container::NoSuchElementException, uno::RuntimeException)
1084 vos::OGuard g(Application::GetSolarMutex());
1085 return m_pImpl->m_Text.removeTextContent(xContent);
1088 // XElementAccess
1089 uno::Type SAL_CALL
1090 SwXMeta::getElementType() throw (uno::RuntimeException)
1092 return text::XTextRange::static_type();
1095 sal_Bool SAL_CALL
1096 SwXMeta::hasElements() throw (uno::RuntimeException)
1098 vos::OGuard g(Application::GetSolarMutex());
1100 return GetRegisteredIn() ? sal_True : sal_False;
1103 // XEnumerationAccess
1104 uno::Reference< container::XEnumeration > SAL_CALL
1105 SwXMeta::createEnumeration() throw (uno::RuntimeException)
1107 vos::OGuard g(Application::GetSolarMutex());
1109 if (m_pImpl->m_bIsDisposed)
1111 throw lang::DisposedException();
1113 if (m_pImpl->m_bIsDescriptor)
1115 throw uno::RuntimeException(
1116 C2S("getAnchor(): not inserted"),
1117 static_cast< ::cppu::OWeakObject* >(this));
1120 SwTxtNode * pTxtNode;
1121 xub_StrLen nMetaStart;
1122 xub_StrLen nMetaEnd;
1123 const bool bSuccess(SetContentRange(pTxtNode, nMetaStart, nMetaEnd));
1124 ASSERT(bSuccess, "no pam?");
1125 if (!bSuccess)
1126 throw lang::DisposedException();
1128 SwPaM aPam(*pTxtNode, nMetaStart);
1130 if (!m_pImpl->m_pTextPortions.get())
1132 return new SwXTextPortionEnumeration(
1133 aPam, GetParentText(), nMetaStart, nMetaEnd);
1135 else // cached!
1137 return new SwXTextPortionEnumeration(aPam, *m_pImpl->m_pTextPortions);
1142 // MetadatableMixin
1143 ::sfx2::Metadatable* SwXMeta::GetCoreObject()
1145 return const_cast< ::sw::Meta * >(GetMeta());
1148 uno::Reference<frame::XModel> SwXMeta::GetModel()
1150 ::sw::Meta const * const pMeta( GetMeta() );
1151 if (pMeta)
1153 SwTxtNode const * const pTxtNode( pMeta->GetTxtNode() );
1154 if (pTxtNode)
1156 SwDocShell const * const pShell(pTxtNode->GetDoc()->GetDocShell());
1157 return (pShell) ? pShell->GetModel() : 0;
1160 return 0;
1163 // SwModify
1164 void SwXMeta::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew )
1166 m_pImpl->m_pTextPortions.reset(); // throw away cache (SwTxtNode changed)
1168 ClientModify(this, pOld, pNew);
1170 if (!GetRegisteredIn()) // removed => dispose
1172 m_pImpl->m_ListenerContainer.Disposing();
1173 m_pImpl->m_bIsDisposed = true;
1174 m_pImpl->m_Text.Invalidate();
1179 /******************************************************************
1180 * SwXMetaField
1181 ******************************************************************/
1183 inline const ::sw::MetaField * SwXMetaField::GetMetaField() const
1185 return static_cast< const ::sw::MetaField * >(GetRegisteredIn());
1188 SwXMetaField::SwXMetaField(SwDoc *const pDoc,
1189 uno::Reference<text::XText> const& xParentText,
1190 TextRangeList_t * const pPortions, SwTxtMeta * const pHint)
1191 : SwXMetaFieldBaseClass(pDoc, xParentText, pPortions, pHint)
1193 ASSERT(!pHint || RES_TXTATR_METAFIELD == pHint->Which(),
1194 "SwXMetaField created for wrong hint!");
1197 SwXMetaField::SwXMetaField(SwDoc *const pDoc)
1198 : SwXMetaFieldBaseClass(pDoc)
1202 SwXMetaField::~SwXMetaField()
1206 // XServiceInfo
1207 ::rtl::OUString SAL_CALL
1208 SwXMetaField::getImplementationName() throw (uno::RuntimeException)
1210 return C2U("SwXMetaField");
1213 sal_Bool SAL_CALL
1214 SwXMetaField::supportsService(const ::rtl::OUString& rServiceName)
1215 throw (uno::RuntimeException)
1217 return rServiceName.equalsAscii("com.sun.star.text.TextContent")
1218 || rServiceName.equalsAscii("com.sun.star.text.TextField")
1219 || rServiceName.equalsAscii("com.sun.star.text.textfield.MetadataField");
1222 uno::Sequence< ::rtl::OUString > SAL_CALL
1223 SwXMetaField::getSupportedServiceNames() throw (uno::RuntimeException)
1225 uno::Sequence< ::rtl::OUString > aRet(3);
1226 aRet[0] = C2U("com.sun.star.text.TextContent");
1227 aRet[1] = C2U("com.sun.star.text.TextField");
1228 aRet[2] = C2U("com.sun.star.text.textfield.MetadataField");
1229 return aRet;
1232 // XComponent
1233 void SAL_CALL
1234 SwXMetaField::addEventListener(
1235 uno::Reference< lang::XEventListener> const & xListener )
1236 throw (uno::RuntimeException)
1238 return SwXMeta::addEventListener(xListener);
1241 void SAL_CALL
1242 SwXMetaField::removeEventListener(
1243 uno::Reference< lang::XEventListener> const & xListener )
1244 throw (uno::RuntimeException)
1246 return SwXMeta::removeEventListener(xListener);
1249 void SAL_CALL
1250 SwXMetaField::dispose() throw (uno::RuntimeException)
1252 return SwXMeta::dispose();
1255 // XTextContent
1256 void SAL_CALL
1257 SwXMetaField::attach(const uno::Reference< text::XTextRange > & i_xTextRange)
1258 throw (lang::IllegalArgumentException, uno::RuntimeException)
1260 return SwXMeta::AttachImpl(i_xTextRange, RES_TXTATR_METAFIELD);
1263 uno::Reference< text::XTextRange > SAL_CALL
1264 SwXMetaField::getAnchor() throw (uno::RuntimeException)
1266 return SwXMeta::getAnchor();
1269 // XPropertySet
1270 uno::Reference< beans::XPropertySetInfo > SAL_CALL
1271 SwXMetaField::getPropertySetInfo() throw (uno::RuntimeException)
1273 vos::OGuard g(Application::GetSolarMutex());
1275 static uno::Reference< beans::XPropertySetInfo > xRef(
1276 aSwMapProvider.GetPropertySet(PROPERTY_MAP_METAFIELD)
1277 ->getPropertySetInfo() );
1278 return xRef;
1281 void SAL_CALL
1282 SwXMetaField::setPropertyValue(
1283 const ::rtl::OUString& rPropertyName, const uno::Any& rValue)
1284 throw (beans::UnknownPropertyException, beans::PropertyVetoException,
1285 lang::IllegalArgumentException, lang::WrappedTargetException,
1286 uno::RuntimeException)
1288 vos::OGuard g(Application::GetSolarMutex());
1290 ::sw::MetaField * const pMeta(
1291 const_cast< ::sw::MetaField * >(GetMetaField()) );
1292 if (!pMeta)
1293 throw lang::DisposedException();
1295 if (rPropertyName.equalsAscii("NumberFormat"))
1297 sal_Int32 nNumberFormat(0);
1298 if (rValue >>= nNumberFormat)
1300 pMeta->SetNumberFormat(static_cast<sal_uInt32>(nNumberFormat));
1303 else if (rPropertyName.equalsAscii("IsFixedLanguage"))
1305 bool b(false);
1306 if (rValue >>= b)
1308 pMeta->SetIsFixedLanguage(b);
1311 else
1313 throw beans::UnknownPropertyException();
1317 uno::Any SAL_CALL
1318 SwXMetaField::getPropertyValue(const ::rtl::OUString& rPropertyName)
1319 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1320 uno::RuntimeException)
1322 vos::OGuard g(Application::GetSolarMutex());
1324 ::sw::MetaField const * const pMeta( GetMetaField() );
1325 if (!pMeta)
1326 throw lang::DisposedException();
1328 uno::Any any;
1330 if (rPropertyName.equalsAscii("NumberFormat"))
1332 const ::rtl::OUString text( getPresentation(sal_False) );
1333 any <<= static_cast<sal_Int32>(pMeta->GetNumberFormat(text));
1335 else if (rPropertyName.equalsAscii("IsFixedLanguage"))
1337 any <<= pMeta->IsFixedLanguage();
1339 else
1341 throw beans::UnknownPropertyException();
1344 return any;
1347 void SAL_CALL
1348 SwXMetaField::addPropertyChangeListener(
1349 const ::rtl::OUString& /*rPropertyName*/,
1350 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
1351 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1352 uno::RuntimeException)
1354 OSL_ENSURE(false,
1355 "SwXMetaField::addPropertyChangeListener(): not implemented");
1358 void SAL_CALL
1359 SwXMetaField::removePropertyChangeListener(
1360 const ::rtl::OUString& /*rPropertyName*/,
1361 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
1362 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1363 uno::RuntimeException)
1365 OSL_ENSURE(false,
1366 "SwXMetaField::removePropertyChangeListener(): not implemented");
1369 void SAL_CALL
1370 SwXMetaField::addVetoableChangeListener(
1371 const ::rtl::OUString& /*rPropertyName*/,
1372 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
1373 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1374 uno::RuntimeException)
1376 OSL_ENSURE(false,
1377 "SwXMetaField::addVetoableChangeListener(): not implemented");
1380 void SAL_CALL
1381 SwXMetaField::removeVetoableChangeListener(
1382 const ::rtl::OUString& /*rPropertyName*/,
1383 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
1384 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1385 uno::RuntimeException)
1387 OSL_ENSURE(false,
1388 "SwXMetaField::removeVetoableChangeListener(): not implemented");
1391 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
1392 #include <com/sun/star/rdf/Statement.hpp>
1393 #include <com/sun/star/rdf/URI.hpp>
1394 #include <com/sun/star/rdf/URIs.hpp>
1395 #include <com/sun/star/rdf/XLiteral.hpp>
1396 #include <com/sun/star/rdf/XRepositorySupplier.hpp>
1397 #include <comphelper/processfactory.hxx>
1399 static uno::Reference<rdf::XURI> const&
1400 lcl_getURI(const bool bPrefix)
1402 static uno::Reference< uno::XComponentContext > xContext(
1403 ::comphelper::getProcessComponentContext());
1404 static uno::Reference< rdf::XURI > xOdfPrefix(
1405 rdf::URI::createKnown(xContext, rdf::URIs::ODF_PREFIX),
1406 uno::UNO_SET_THROW);
1407 static uno::Reference< rdf::XURI > xOdfSuffix(
1408 rdf::URI::createKnown(xContext, rdf::URIs::ODF_SUFFIX),
1409 uno::UNO_SET_THROW);
1410 return (bPrefix) ? xOdfPrefix : xOdfSuffix;
1413 static ::rtl::OUString
1414 lcl_getPrefixOrSuffix(
1415 uno::Reference<rdf::XRepository> const & xRepository,
1416 uno::Reference<rdf::XResource> const & xMetaField,
1417 uno::Reference<rdf::XURI> const & xPredicate)
1419 const uno::Reference<container::XEnumeration> xEnum(
1420 xRepository->getStatements(xMetaField, xPredicate, 0),
1421 uno::UNO_SET_THROW);
1422 while (xEnum->hasMoreElements()) {
1423 rdf::Statement stmt;
1424 if (!(xEnum->nextElement() >>= stmt)) {
1425 throw uno::RuntimeException();
1427 const uno::Reference<rdf::XLiteral> xObject(stmt.Object,
1428 uno::UNO_QUERY);
1429 if (!xObject.is()) continue;
1430 if (xEnum->hasMoreElements()) {
1431 OSL_TRACE("ignoring other odf:Prefix/odf:Suffix statements");
1433 return xObject->getValue();
1435 return ::rtl::OUString();
1438 void
1439 getPrefixAndSuffix(
1440 const uno::Reference<frame::XModel>& xModel,
1441 const uno::Reference<rdf::XMetadatable>& xMetaField,
1442 ::rtl::OUString *const o_pPrefix, ::rtl::OUString *const o_pSuffix)
1444 try {
1445 const uno::Reference<rdf::XRepositorySupplier> xRS(
1446 xModel, uno::UNO_QUERY_THROW);
1447 const uno::Reference<rdf::XRepository> xRepo(
1448 xRS->getRDFRepository(), uno::UNO_SET_THROW);
1449 const uno::Reference<rdf::XResource> xMeta(
1450 xMetaField, uno::UNO_QUERY_THROW);
1451 if (o_pPrefix)
1453 *o_pPrefix = lcl_getPrefixOrSuffix(xRepo, xMeta, lcl_getURI(true));
1455 if (o_pSuffix)
1457 *o_pSuffix = lcl_getPrefixOrSuffix(xRepo, xMeta, lcl_getURI(false));
1459 } catch (uno::RuntimeException &) {
1460 throw;
1461 } catch (uno::Exception & e) {
1462 throw lang::WrappedTargetRuntimeException(
1463 ::rtl::OUString::createFromAscii("getPrefixAndSuffix: exception"),
1464 0, uno::makeAny(e));
1468 // XTextField
1469 ::rtl::OUString SAL_CALL
1470 SwXMetaField::getPresentation(sal_Bool bShowCommand)
1471 throw (uno::RuntimeException)
1473 vos::OGuard g(Application::GetSolarMutex());
1475 if (bShowCommand)
1477 //FIXME ?
1478 return ::rtl::OUString();
1480 else
1482 // getString should check if this is invalid
1483 const ::rtl::OUString content( this->getString() );
1484 ::rtl::OUString prefix;
1485 ::rtl::OUString suffix;
1486 getPrefixAndSuffix(GetModel(), this, &prefix, &suffix);
1487 return prefix + content + suffix;