update dev300-m58
[ooovba.git] / sc / source / ui / unoobj / fielduno.cxx
blobe303f2826e1d7422e9fea727a99856ff8909b7c5
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: fielduno.cxx,v $
10 * $Revision: 1.18.32.3 $
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_sc.hxx"
33 #include <svtools/smplhint.hxx>
36 #include <svx/eeitem.hxx>
38 #include <svx/editeng.hxx>
39 #include <svx/editobj.hxx>
40 #include <svx/flditem.hxx>
41 #include <rtl/uuid.h>
43 #include <com/sun/star/beans/PropertyAttribute.hpp>
44 #include <com/sun/star/text/TextContentAnchorType.hpp>
45 #include <com/sun/star/text/WrapTextMode.hpp>
46 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
48 #include "fielduno.hxx"
49 #include "textuno.hxx"
50 #include "miscuno.hxx"
51 #include "docsh.hxx"
52 #include "hints.hxx"
53 #include "editsrc.hxx"
54 #include "cellsuno.hxx"
55 #include "servuno.hxx" // fuer IDs
56 #include "unoguard.hxx"
57 #include "unonames.hxx"
58 #include "editutil.hxx"
60 using namespace com::sun::star;
62 //------------------------------------------------------------------------
64 // alles ohne Which-ID, Map nur fuer PropertySetInfo
66 const SfxItemPropertySet* lcl_GetURLPropertySet()
68 static SfxItemPropertyMapEntry aURLPropertyMap_Impl[] =
70 {MAP_CHAR_LEN(SC_UNONAME_ANCTYPE), 0, &getCppuType((text::TextContentAnchorType*)0), beans::PropertyAttribute::READONLY, 0 },
71 {MAP_CHAR_LEN(SC_UNONAME_ANCTYPES), 0, &getCppuType((uno::Sequence<text::TextContentAnchorType>*)0), beans::PropertyAttribute::READONLY, 0 },
72 {MAP_CHAR_LEN(SC_UNONAME_REPR), 0, &getCppuType((rtl::OUString*)0), 0, 0},
73 {MAP_CHAR_LEN(SC_UNONAME_TARGET), 0, &getCppuType((rtl::OUString*)0), 0, 0},
74 {MAP_CHAR_LEN(SC_UNONAME_TEXTWRAP), 0, &getCppuType((text::WrapTextMode*)0), beans::PropertyAttribute::READONLY, 0 },
75 {MAP_CHAR_LEN(SC_UNONAME_URL), 0, &getCppuType((rtl::OUString*)0), 0, 0},
76 {0,0,0,0,0,0}
78 static SfxItemPropertySet aURLPropertySet_Impl( aURLPropertyMap_Impl );
79 return &aURLPropertySet_Impl;
82 const SfxItemPropertySet* lcl_GetHeaderFieldPropertySet()
84 static SfxItemPropertyMapEntry aHeaderFieldPropertyMap_Impl[] =
86 {MAP_CHAR_LEN(SC_UNONAME_ANCTYPE), 0, &getCppuType((text::TextContentAnchorType*)0), beans::PropertyAttribute::READONLY, 0 },
87 {MAP_CHAR_LEN(SC_UNONAME_ANCTYPES), 0, &getCppuType((uno::Sequence<text::TextContentAnchorType>*)0), beans::PropertyAttribute::READONLY, 0 },
88 {MAP_CHAR_LEN(SC_UNONAME_TEXTWRAP), 0, &getCppuType((text::WrapTextMode*)0), beans::PropertyAttribute::READONLY, 0 },
89 {0,0,0,0,0,0}
91 static SfxItemPropertySet aHeaderFieldPropertySet_Impl( aHeaderFieldPropertyMap_Impl );
92 return &aHeaderFieldPropertySet_Impl;
95 const SfxItemPropertySet* lcl_GetFileFieldPropertySet()
97 static SfxItemPropertyMapEntry aFileFieldPropertyMap_Impl[] =
99 {MAP_CHAR_LEN(SC_UNONAME_ANCTYPE), 0, &getCppuType((text::TextContentAnchorType*)0), beans::PropertyAttribute::READONLY, 0 },
100 {MAP_CHAR_LEN(SC_UNONAME_ANCTYPES), 0, &getCppuType((uno::Sequence<text::TextContentAnchorType>*)0), beans::PropertyAttribute::READONLY, 0 },
101 {MAP_CHAR_LEN(SC_UNONAME_FILEFORM), 0, &getCppuType((sal_Int16*)0), 0, 0 },
102 {MAP_CHAR_LEN(SC_UNONAME_TEXTWRAP), 0, &getCppuType((text::WrapTextMode*)0), beans::PropertyAttribute::READONLY, 0 },
103 {0,0,0,0,0,0}
105 static SfxItemPropertySet aFileFieldPropertySet_Impl( aFileFieldPropertyMap_Impl );
106 return &aFileFieldPropertySet_Impl;
109 //------------------------------------------------------------------------
111 #define SCTEXTFIELD_SERVICE "com.sun.star.text.TextField"
112 #define SCTEXTCONTENT_SERVICE "com.sun.star.text.TextContent"
114 SC_SIMPLE_SERVICE_INFO( ScCellFieldsObj, "ScCellFieldsObj", "com.sun.star.text.TextFields" )
115 SC_SIMPLE_SERVICE_INFO( ScHeaderFieldsObj, "ScHeaderFieldsObj", "com.sun.star.text.TextFields" )
117 //------------------------------------------------------------------------
119 // ScUnoEditEngine nur um aus einer EditEngine die Felder herauszubekommen...
121 enum ScUnoCollectMode
123 SC_UNO_COLLECT_NONE,
124 SC_UNO_COLLECT_COUNT,
125 SC_UNO_COLLECT_FINDINDEX,
126 SC_UNO_COLLECT_FINDPOS
129 class ScUnoEditEngine : public ScEditEngineDefaulter
131 ScUnoCollectMode eMode;
132 USHORT nFieldCount;
133 TypeId aFieldType;
134 SvxFieldData* pFound; // lokale Kopie
135 USHORT nFieldPar;
136 xub_StrLen nFieldPos;
137 USHORT nFieldIndex;
139 public:
140 ScUnoEditEngine(ScEditEngineDefaulter* pSource);
141 ~ScUnoEditEngine();
143 //! nPos should be xub_StrLen
144 virtual String CalcFieldValue( const SvxFieldItem& rField, USHORT nPara, USHORT nPos,
145 Color*& rTxtColor, Color*& rFldColor );
147 USHORT CountFields(TypeId aType);
148 SvxFieldData* FindByIndex(USHORT nIndex, TypeId aType);
149 SvxFieldData* FindByPos(USHORT nPar, xub_StrLen nPos, TypeId aType);
151 USHORT GetFieldPar() const { return nFieldPar; }
152 xub_StrLen GetFieldPos() const { return nFieldPos; }
155 ScUnoEditEngine::ScUnoEditEngine(ScEditEngineDefaulter* pSource) :
156 ScEditEngineDefaulter( *pSource ),
157 eMode( SC_UNO_COLLECT_NONE ),
158 nFieldCount( 0 ),
159 aFieldType( NULL ),
160 pFound( NULL )
162 if (pSource)
164 EditTextObject* pData = pSource->CreateTextObject();
165 SetText( *pData );
166 delete pData;
170 ScUnoEditEngine::~ScUnoEditEngine()
172 delete pFound;
175 String ScUnoEditEngine::CalcFieldValue( const SvxFieldItem& rField,
176 USHORT nPara, USHORT nPos, Color*& rTxtColor, Color*& rFldColor )
178 String aRet(EditEngine::CalcFieldValue( rField, nPara, nPos, rTxtColor, rFldColor ));
179 if (eMode != SC_UNO_COLLECT_NONE)
181 const SvxFieldData* pFieldData = rField.GetField();
182 if ( pFieldData )
184 if ( !aFieldType || pFieldData->Type() == aFieldType )
186 if ( eMode == SC_UNO_COLLECT_FINDINDEX && !pFound && nFieldCount == nFieldIndex )
188 pFound = pFieldData->Clone();
189 nFieldPar = nPara;
190 nFieldPos = nPos;
192 if ( eMode == SC_UNO_COLLECT_FINDPOS && !pFound &&
193 nPara == nFieldPar && nPos == nFieldPos )
195 pFound = pFieldData->Clone();
196 nFieldIndex = nFieldCount;
198 ++nFieldCount;
202 return aRet;
205 USHORT ScUnoEditEngine::CountFields(TypeId aType)
207 eMode = SC_UNO_COLLECT_COUNT;
208 aFieldType = aType;
209 nFieldCount = 0;
210 UpdateFields();
211 aFieldType = NULL;
212 eMode = SC_UNO_COLLECT_NONE;
214 return nFieldCount;
217 SvxFieldData* ScUnoEditEngine::FindByIndex(USHORT nIndex, TypeId aType)
219 eMode = SC_UNO_COLLECT_FINDINDEX;
220 nFieldIndex = nIndex;
221 aFieldType = aType;
222 nFieldCount = 0;
223 UpdateFields();
224 aFieldType = NULL;
225 eMode = SC_UNO_COLLECT_NONE;
227 return pFound;
230 SvxFieldData* ScUnoEditEngine::FindByPos(USHORT nPar, xub_StrLen nPos, TypeId aType)
232 eMode = SC_UNO_COLLECT_FINDPOS;
233 nFieldPar = nPar;
234 nFieldPos = nPos;
235 aFieldType = aType;
236 nFieldCount = 0;
237 UpdateFields();
238 aFieldType = NULL;
239 eMode = SC_UNO_COLLECT_NONE;
241 return pFound;
244 //------------------------------------------------------------------------
246 ScCellFieldsObj::ScCellFieldsObj(ScDocShell* pDocSh, const ScAddress& rPos) :
247 pDocShell( pDocSh ),
248 aCellPos( rPos ),
249 mpRefreshListeners( NULL )
251 pDocShell->GetDocument()->AddUnoObject(*this);
253 pEditSource = new ScCellEditSource( pDocShell, aCellPos );
256 ScCellFieldsObj::~ScCellFieldsObj()
258 if (pDocShell)
259 pDocShell->GetDocument()->RemoveUnoObject(*this);
261 delete pEditSource;
263 // increment refcount to prevent double call off dtor
264 osl_incrementInterlockedCount( &m_refCount );
266 if (mpRefreshListeners)
268 lang::EventObject aEvent;
269 aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
270 if (mpRefreshListeners)
272 mpRefreshListeners->disposeAndClear(aEvent);
273 DELETEZ( mpRefreshListeners );
278 void ScCellFieldsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
280 if ( rHint.ISA( ScUpdateRefHint ) )
282 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
284 //! Ref-Update
286 else if ( rHint.ISA( SfxSimpleHint ) &&
287 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
289 pDocShell = NULL; // ungueltig geworden
292 // EditSource hat sich selber als Listener angemeldet
295 // XIndexAccess (via XTextFields)
297 ScCellFieldObj* ScCellFieldsObj::GetObjectByIndex_Impl(INT32 Index) const
299 //! Feld-Funktionen muessen an den Forwarder !!!
300 ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
301 ScUnoEditEngine aTempEngine(pEditEngine);
303 if ( aTempEngine.FindByIndex( (USHORT)Index, NULL ) ) // in der Zelle ist der Typ egal
305 USHORT nPar = aTempEngine.GetFieldPar();
306 xub_StrLen nPos = aTempEngine.GetFieldPos();
307 ESelection aSelection( nPar, nPos, nPar, nPos+1 ); // Feld ist 1 Zeichen
308 return new ScCellFieldObj( pDocShell, aCellPos, aSelection );
310 return NULL;
313 sal_Int32 SAL_CALL ScCellFieldsObj::getCount() throw(uno::RuntimeException)
315 ScUnoGuard aGuard;
317 //! Feld-Funktionen muessen an den Forwarder !!!
318 ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
319 ScUnoEditEngine aTempEngine(pEditEngine);
321 return aTempEngine.CountFields(NULL); // Felder zaehlen, in Zelle ist der Typ egal
324 uno::Any SAL_CALL ScCellFieldsObj::getByIndex( sal_Int32 nIndex )
325 throw(lang::IndexOutOfBoundsException,
326 lang::WrappedTargetException, uno::RuntimeException)
328 ScUnoGuard aGuard;
329 uno::Reference<text::XTextField> xField(GetObjectByIndex_Impl(nIndex));
330 if (xField.is())
331 return uno::makeAny(xField);
332 else
333 throw lang::IndexOutOfBoundsException();
334 // return uno::Any();
337 uno::Type SAL_CALL ScCellFieldsObj::getElementType() throw(uno::RuntimeException)
339 ScUnoGuard aGuard;
340 return getCppuType((uno::Reference<text::XTextField>*)0);
343 sal_Bool SAL_CALL ScCellFieldsObj::hasElements() throw(uno::RuntimeException)
345 ScUnoGuard aGuard;
346 return ( getCount() != 0 );
349 uno::Reference<container::XEnumeration> SAL_CALL ScCellFieldsObj::createEnumeration()
350 throw(uno::RuntimeException)
352 ScUnoGuard aGuard;
353 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFieldEnumeration")));
356 void SAL_CALL ScCellFieldsObj::addContainerListener(
357 const uno::Reference<container::XContainerListener>& /* xListener */ )
358 throw(uno::RuntimeException)
360 DBG_ERROR("not implemented");
363 void SAL_CALL ScCellFieldsObj::removeContainerListener(
364 const uno::Reference<container::XContainerListener>& /* xListener */ )
365 throw(uno::RuntimeException)
367 DBG_ERROR("not implemented");
370 // XRefreshable
371 void SAL_CALL ScCellFieldsObj::refresh( )
372 throw (uno::RuntimeException)
374 if (mpRefreshListeners)
376 // Call all listeners.
377 uno::Sequence< uno::Reference< uno::XInterface > > aListeners(mpRefreshListeners->getElements());
378 sal_uInt32 nLength(aListeners.getLength());
379 if (nLength)
381 const uno::Reference< uno::XInterface >* pInterfaces = aListeners.getConstArray();
382 if (pInterfaces)
384 lang::EventObject aEvent;
385 aEvent.Source.set(uno::Reference< util::XRefreshable >(const_cast<ScCellFieldsObj*>(this)));
386 sal_uInt32 i(0);
387 while (i < nLength)
391 while(i < nLength)
393 static_cast< util::XRefreshListener* >(pInterfaces->get())->refreshed(aEvent);
394 ++pInterfaces;
395 ++i;
398 catch(uno::RuntimeException&)
400 // DBG_ERROR("a object is gone without to remove from Broadcaster");
401 ++pInterfaces;
402 ++i;
410 void SAL_CALL ScCellFieldsObj::addRefreshListener( const uno::Reference< util::XRefreshListener >& xListener )
411 throw (uno::RuntimeException)
413 if (xListener.is())
415 ScUnoGuard aGuard;
416 if (!mpRefreshListeners)
417 mpRefreshListeners = new cppu::OInterfaceContainerHelper(aMutex);
418 mpRefreshListeners->addInterface(xListener);
422 void SAL_CALL ScCellFieldsObj::removeRefreshListener( const uno::Reference<util::XRefreshListener >& xListener )
423 throw (uno::RuntimeException)
425 if (xListener.is())
427 ScUnoGuard aGuard;
428 if (mpRefreshListeners)
429 mpRefreshListeners->removeInterface(xListener);
433 //------------------------------------------------------------------------
435 // Default-ctor wird fuer SMART_REFLECTION_IMPLEMENTATION gebraucht
438 //UNUSED2008-05 ScCellFieldObj::ScCellFieldObj() :
439 //UNUSED2008-05 OComponentHelper( getMutex() ),
440 //UNUSED2008-05 aPropSet( lcl_GetURLPropertyMap() ),
441 //UNUSED2008-05 pDocShell( NULL )
442 //UNUSED2008-05 {
443 //UNUSED2008-05 pEditSource = NULL;
444 //UNUSED2008-05 }
446 ScCellFieldObj::ScCellFieldObj(ScDocShell* pDocSh, const ScAddress& rPos,
447 const ESelection& rSel) :
448 OComponentHelper( getMutex() ),
449 pPropSet( lcl_GetURLPropertySet() ),
450 pDocShell( pDocSh ),
451 aCellPos( rPos ),
452 aSelection( rSel )
454 // pDocShell ist Null, wenn per ServiceProvider erzeugt
456 if (pDocShell)
458 pDocShell->GetDocument()->AddUnoObject(*this);
459 pEditSource = new ScCellEditSource( pDocShell, aCellPos );
461 else
462 pEditSource = NULL;
465 uno::Any SAL_CALL ScCellFieldObj::queryAggregation( const uno::Type& rType )
466 throw(uno::RuntimeException)
468 SC_QUERYINTERFACE( text::XTextField )
469 SC_QUERYINTERFACE( text::XTextContent ) // parent of XTextField
470 SC_QUERYINTERFACE( beans::XPropertySet )
471 SC_QUERYINTERFACE( lang::XUnoTunnel )
472 SC_QUERYINTERFACE( lang::XServiceInfo )
474 return OComponentHelper::queryAggregation( rType ); // XComponent
477 uno::Sequence<uno::Type> SAL_CALL ScCellFieldObj::getTypes() throw(uno::RuntimeException)
479 static uno::Sequence<uno::Type> aTypes;
480 if ( aTypes.getLength() == 0 )
482 uno::Sequence<uno::Type> aParentTypes(OComponentHelper::getTypes());
483 long nParentLen = aParentTypes.getLength();
484 const uno::Type* pParentPtr = aParentTypes.getConstArray();
486 aTypes.realloc( nParentLen + 4 );
487 uno::Type* pPtr = aTypes.getArray();
488 pPtr[nParentLen + 0] = getCppuType((const uno::Reference<text::XTextField>*)0);
489 pPtr[nParentLen + 1] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
490 pPtr[nParentLen + 2] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0);
491 pPtr[nParentLen + 3] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
493 for (long i=0; i<nParentLen; i++)
494 pPtr[i] = pParentPtr[i]; // parent types first
496 return aTypes;
499 uno::Sequence<sal_Int8> SAL_CALL ScCellFieldObj::getImplementationId()
500 throw(uno::RuntimeException)
502 static uno::Sequence< sal_Int8 > aId;
503 if( aId.getLength() == 0 )
505 aId.realloc( 16 );
506 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
508 return aId;
511 uno::Any SAL_CALL ScCellFieldObj::queryInterface( const uno::Type& rType )
512 throw(uno::RuntimeException)
514 return OComponentHelper::queryInterface( rType );
517 void SAL_CALL ScCellFieldObj::acquire() throw()
519 OComponentHelper::acquire();
522 void SAL_CALL ScCellFieldObj::release() throw()
524 OComponentHelper::release();
527 void ScCellFieldObj::InitDoc( ScDocShell* pDocSh, const ScAddress& rPos,
528 const ESelection& rSel )
530 if ( pDocSh && !pEditSource )
532 aCellPos = rPos;
533 aSelection = rSel;
534 pDocShell = pDocSh;
536 pDocShell->GetDocument()->AddUnoObject(*this);
537 pEditSource = new ScCellEditSource( pDocShell, aCellPos );
541 ScCellFieldObj::~ScCellFieldObj()
543 if (pDocShell)
544 pDocShell->GetDocument()->RemoveUnoObject(*this);
546 delete pEditSource;
549 void ScCellFieldObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
551 //! Updates fuer aSelection (muessen erst noch erzeugt werden) !!!!!!
553 if ( rHint.ISA( ScUpdateRefHint ) )
555 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
557 //! Ref-Update
559 else if ( rHint.ISA( SfxSimpleHint ) &&
560 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
562 pDocShell = NULL; // ungueltig geworden
565 // EditSource hat sich selber als Listener angemeldet
568 // per getImplementation gerufen:
570 SvxFieldItem ScCellFieldObj::CreateFieldItem()
572 DBG_ASSERT( !pEditSource, "CreateFieldItem mit eingefuegtem Feld" );
574 SvxURLField aField;
575 aField.SetFormat(SVXURLFORMAT_APPDEFAULT);
576 aField.SetURL( aUrl );
577 aField.SetRepresentation( aRepresentation );
578 aField.SetTargetFrame( aTarget );
579 return SvxFieldItem( aField, EE_FEATURE_FIELD );
582 void ScCellFieldObj::DeleteField()
584 if (pEditSource)
586 SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
587 // pEditEngine->QuickDelete( aSelection );
588 pForwarder->QuickInsertText( String(), aSelection );
589 pEditSource->UpdateData();
591 aSelection.nEndPara = aSelection.nStartPara;
592 aSelection.nEndPos = aSelection.nStartPos;
594 //! Broadcast, um Selektion in anderen Objekten anzupassen
595 //! (auch bei anderen Aktionen)
599 // XTextField
601 rtl::OUString SAL_CALL ScCellFieldObj::getPresentation( sal_Bool bShowCommand )
602 throw(uno::RuntimeException)
604 ScUnoGuard aGuard;
605 String aRet;
607 if (pEditSource)
609 //! Feld-Funktionen muessen an den Forwarder !!!
610 ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
611 ScUnoEditEngine aTempEngine(pEditEngine);
613 // Typ egal (in Zellen gibts nur URLs)
614 SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 );
615 DBG_ASSERT(pField,"getPresentation: Feld nicht gefunden");
616 if (pField)
618 SvxURLField* pURL = (SvxURLField*)pField;
619 if (bShowCommand)
620 aRet = pURL->GetURL();
621 else
622 aRet = pURL->GetRepresentation();
626 return aRet;
629 // XTextContent
631 void SAL_CALL ScCellFieldObj::attach( const uno::Reference<text::XTextRange>& xTextRange )
632 throw(lang::IllegalArgumentException, uno::RuntimeException)
634 ScUnoGuard aGuard;
635 if (xTextRange.is())
637 uno::Reference<text::XText> xText(xTextRange->getText());
638 if (xText.is())
640 xText->insertTextContent( xTextRange, this, TRUE );
645 uno::Reference<text::XTextRange> SAL_CALL ScCellFieldObj::getAnchor() throw(uno::RuntimeException)
647 ScUnoGuard aGuard;
648 if (pDocShell)
649 return new ScCellObj( pDocShell, aCellPos );
650 return NULL;
653 // XComponent
655 void SAL_CALL ScCellFieldObj::dispose() throw(uno::RuntimeException)
657 OComponentHelper::dispose();
660 void SAL_CALL ScCellFieldObj::addEventListener(
661 const uno::Reference<lang::XEventListener>& xListener )
662 throw(uno::RuntimeException)
664 OComponentHelper::addEventListener( xListener );
667 void SAL_CALL ScCellFieldObj::removeEventListener(
668 const uno::Reference<lang::XEventListener>& xListener )
669 throw(uno::RuntimeException)
671 OComponentHelper::removeEventListener( xListener );
674 // XPropertySet
676 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellFieldObj::getPropertySetInfo()
677 throw(uno::RuntimeException)
679 ScUnoGuard aGuard;
680 static uno::Reference<beans::XPropertySetInfo> aRef = pPropSet->getPropertySetInfo();
681 return aRef;
684 void SAL_CALL ScCellFieldObj::setPropertyValue(
685 const rtl::OUString& aPropertyName, const uno::Any& aValue )
686 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
687 lang::IllegalArgumentException, lang::WrappedTargetException,
688 uno::RuntimeException)
690 ScUnoGuard aGuard;
691 String aNameString(aPropertyName);
692 rtl::OUString aStrVal;
693 if (pEditSource)
695 //! Feld-Funktionen muessen an den Forwarder !!!
696 ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
697 ScUnoEditEngine aTempEngine(pEditEngine);
699 // Typ egal (in Zellen gibts nur URLs)
700 SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 );
701 DBG_ASSERT(pField,"setPropertyValue: Feld nicht gefunden");
702 if (pField)
704 SvxURLField* pURL = (SvxURLField*)pField; // ist eine Kopie in der ScUnoEditEngine
706 BOOL bOk = TRUE;
707 if ( aNameString.EqualsAscii( SC_UNONAME_URL ) )
709 if (aValue >>= aStrVal)
710 pURL->SetURL( aStrVal );
712 else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) )
714 if (aValue >>= aStrVal)
715 pURL->SetRepresentation( aStrVal );
717 else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) )
719 if (aValue >>= aStrVal)
720 pURL->SetTargetFrame( aStrVal );
722 else
723 bOk = FALSE;
725 if (bOk)
727 pEditEngine->QuickInsertField( SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection );
728 pEditSource->UpdateData();
732 else // noch nicht eingefuegt
734 if ( aNameString.EqualsAscii( SC_UNONAME_URL ) )
736 if (aValue >>= aStrVal)
737 aUrl = String( aStrVal );
739 else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) )
741 if (aValue >>= aStrVal)
742 aRepresentation = String( aStrVal );
744 else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) )
746 if (aValue >>= aStrVal)
747 aTarget = String( aStrVal );
752 uno::Any SAL_CALL ScCellFieldObj::getPropertyValue( const rtl::OUString& aPropertyName )
753 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
754 uno::RuntimeException)
756 ScUnoGuard aGuard;
757 uno::Any aRet;
758 String aNameString(aPropertyName);
760 // anchor type is always "as character", text wrap always "none"
762 if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPE ) )
763 aRet <<= text::TextContentAnchorType_AS_CHARACTER;
764 else if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPES ) )
766 uno::Sequence<text::TextContentAnchorType> aSeq(1);
767 aSeq[0] = text::TextContentAnchorType_AS_CHARACTER;
768 aRet <<= aSeq;
770 else if ( aNameString.EqualsAscii( SC_UNONAME_TEXTWRAP ) )
771 aRet <<= text::WrapTextMode_NONE;
772 else if (pEditSource)
774 //! Feld-Funktionen muessen an den Forwarder !!!
775 ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
776 ScUnoEditEngine aTempEngine(pEditEngine);
778 // Typ egal (in Zellen gibts nur URLs)
779 SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 );
780 DBG_ASSERT(pField,"getPropertyValue: Feld nicht gefunden");
781 if (pField)
783 SvxURLField* pURL = (SvxURLField*)pField;
785 if ( aNameString.EqualsAscii( SC_UNONAME_URL ) )
786 aRet <<= rtl::OUString( pURL->GetURL() );
787 else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) )
788 aRet <<= rtl::OUString( pURL->GetRepresentation() );
789 else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) )
790 aRet <<= rtl::OUString( pURL->GetTargetFrame() );
793 else // noch nicht eingefuegt
795 if ( aNameString.EqualsAscii( SC_UNONAME_URL ) )
796 aRet <<= rtl::OUString( aUrl );
797 else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) )
798 aRet <<= rtl::OUString( aRepresentation );
799 else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) )
800 aRet <<= rtl::OUString( aTarget );
802 return aRet;
805 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScCellFieldObj )
807 // XUnoTunnel
809 sal_Int64 SAL_CALL ScCellFieldObj::getSomething(
810 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
812 if ( rId.getLength() == 16 &&
813 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
814 rId.getConstArray(), 16 ) )
816 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
818 return 0;
821 // static
822 const uno::Sequence<sal_Int8>& ScCellFieldObj::getUnoTunnelId()
824 static uno::Sequence<sal_Int8> * pSeq = 0;
825 if( !pSeq )
827 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
828 if( !pSeq )
830 static uno::Sequence< sal_Int8 > aSeq( 16 );
831 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
832 pSeq = &aSeq;
835 return *pSeq;
838 // static
839 ScCellFieldObj* ScCellFieldObj::getImplementation(
840 const uno::Reference<text::XTextContent> xObj )
842 ScCellFieldObj* pRet = NULL;
843 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
844 if (xUT.is())
845 pRet = reinterpret_cast<ScCellFieldObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
846 return pRet;
849 // XServiceInfo
851 rtl::OUString SAL_CALL ScCellFieldObj::getImplementationName() throw(uno::RuntimeException)
853 return rtl::OUString::createFromAscii( "ScCellFieldObj" );
856 sal_Bool SAL_CALL ScCellFieldObj::supportsService( const rtl::OUString& rServiceName )
857 throw(uno::RuntimeException)
859 String aServiceStr( rServiceName );
860 return aServiceStr.EqualsAscii( SCTEXTFIELD_SERVICE ) ||
861 aServiceStr.EqualsAscii( SCTEXTCONTENT_SERVICE );
864 uno::Sequence<rtl::OUString> SAL_CALL ScCellFieldObj::getSupportedServiceNames()
865 throw(uno::RuntimeException)
867 uno::Sequence<rtl::OUString> aRet(2);
868 rtl::OUString* pArray = aRet.getArray();
869 pArray[0] = rtl::OUString::createFromAscii( SCTEXTFIELD_SERVICE );
870 pArray[1] = rtl::OUString::createFromAscii( SCTEXTCONTENT_SERVICE );
871 return aRet;
874 //------------------------------------------------------------------------
876 ScHeaderFieldsObj::ScHeaderFieldsObj(ScHeaderFooterContentObj* pContent, USHORT nP, USHORT nT) :
877 pContentObj( pContent ),
878 nPart( nP ),
879 nType( nT ),
880 mpRefreshListeners( NULL )
882 DBG_ASSERT( pContentObj, "ScHeaderFieldsObj ohne Objekt?" );
884 if (pContentObj)
886 pContentObj->acquire(); // darf nicht wegkommen
887 pEditSource = new ScHeaderFooterEditSource( pContentObj, nPart );
889 else
890 pEditSource = NULL;
893 ScHeaderFieldsObj::~ScHeaderFieldsObj()
895 delete pEditSource;
897 if (pContentObj)
898 pContentObj->release();
900 // increment refcount to prevent double call off dtor
901 osl_incrementInterlockedCount( &m_refCount );
903 if (mpRefreshListeners)
905 lang::EventObject aEvent;
906 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
907 if (mpRefreshListeners)
909 mpRefreshListeners->disposeAndClear(aEvent);
910 DELETEZ( mpRefreshListeners );
915 // XIndexAccess (via XTextFields)
917 ScHeaderFieldObj* ScHeaderFieldsObj::GetObjectByIndex_Impl(INT32 Index) const
919 //! Feld-Funktionen muessen an den Forwarder !!!
920 ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine();
921 ScUnoEditEngine aTempEngine(pEditEngine);
923 TypeId aTypeId = NULL;
924 switch (nType)
926 case SC_SERVICE_PAGEFIELD: aTypeId = TYPE(SvxPageField); break;
927 case SC_SERVICE_PAGESFIELD: aTypeId = TYPE(SvxPagesField); break;
928 case SC_SERVICE_DATEFIELD: aTypeId = TYPE(SvxDateField); break;
929 case SC_SERVICE_TIMEFIELD: aTypeId = TYPE(SvxTimeField); break;
930 case SC_SERVICE_TITLEFIELD: aTypeId = TYPE(SvxFileField); break;
931 case SC_SERVICE_FILEFIELD: aTypeId = TYPE(SvxExtFileField); break;
932 case SC_SERVICE_SHEETFIELD: aTypeId = TYPE(SvxTableField); break;
933 // bei SC_SERVICE_INVALID bleibt TypeId Null
935 SvxFieldData* pData = aTempEngine.FindByIndex( (USHORT)Index, aTypeId );
936 if ( pData )
938 USHORT nPar = aTempEngine.GetFieldPar();
939 xub_StrLen nPos = aTempEngine.GetFieldPos();
941 USHORT nFieldType = nType;
942 if ( nFieldType == SC_SERVICE_INVALID )
944 if ( pData->ISA( SvxPageField ) ) nFieldType = SC_SERVICE_PAGEFIELD;
945 else if ( pData->ISA( SvxPagesField ) ) nFieldType = SC_SERVICE_PAGESFIELD;
946 else if ( pData->ISA( SvxDateField ) ) nFieldType = SC_SERVICE_DATEFIELD;
947 else if ( pData->ISA( SvxTimeField ) ) nFieldType = SC_SERVICE_TIMEFIELD;
948 else if ( pData->ISA( SvxFileField ) ) nFieldType = SC_SERVICE_TITLEFIELD;
949 else if ( pData->ISA( SvxExtFileField ) ) nFieldType = SC_SERVICE_FILEFIELD;
950 else if ( pData->ISA( SvxTableField ) ) nFieldType = SC_SERVICE_SHEETFIELD;
953 ESelection aSelection( nPar, nPos, nPar, nPos+1 ); // Field is 1 character
954 return new ScHeaderFieldObj( pContentObj, nPart, nFieldType, aSelection );
956 return NULL;
959 sal_Int32 SAL_CALL ScHeaderFieldsObj::getCount() throw(uno::RuntimeException)
961 ScUnoGuard aGuard;
963 //! Feld-Funktionen muessen an den Forwarder !!!
964 ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine();
965 ScUnoEditEngine aTempEngine(pEditEngine);
967 TypeId aTypeId = NULL;
968 switch (nType)
970 case SC_SERVICE_PAGEFIELD: aTypeId = TYPE(SvxPageField); break;
971 case SC_SERVICE_PAGESFIELD: aTypeId = TYPE(SvxPagesField); break;
972 case SC_SERVICE_DATEFIELD: aTypeId = TYPE(SvxDateField); break;
973 case SC_SERVICE_TIMEFIELD: aTypeId = TYPE(SvxTimeField); break;
974 case SC_SERVICE_TITLEFIELD: aTypeId = TYPE(SvxFileField); break;
975 case SC_SERVICE_FILEFIELD: aTypeId = TYPE(SvxExtFileField); break;
976 case SC_SERVICE_SHEETFIELD: aTypeId = TYPE(SvxTableField); break;
978 return aTempEngine.CountFields(aTypeId); // Felder zaehlen
981 uno::Any SAL_CALL ScHeaderFieldsObj::getByIndex( sal_Int32 nIndex )
982 throw(lang::IndexOutOfBoundsException,
983 lang::WrappedTargetException, uno::RuntimeException)
985 ScUnoGuard aGuard;
986 uno::Reference<text::XTextField> xField(GetObjectByIndex_Impl(nIndex));
987 if (xField.is())
988 return uno::makeAny(xField);
989 else
990 throw lang::IndexOutOfBoundsException();
991 // return uno::Any();
994 uno::Type SAL_CALL ScHeaderFieldsObj::getElementType() throw(uno::RuntimeException)
996 ScUnoGuard aGuard;
997 return getCppuType((uno::Reference<text::XTextField>*)0);
1000 sal_Bool SAL_CALL ScHeaderFieldsObj::hasElements() throw(uno::RuntimeException)
1002 ScUnoGuard aGuard;
1003 return ( getCount() != 0 );
1006 uno::Reference<container::XEnumeration> SAL_CALL ScHeaderFieldsObj::createEnumeration()
1007 throw(uno::RuntimeException)
1009 ScUnoGuard aGuard;
1010 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFieldEnumeration")));
1013 void SAL_CALL ScHeaderFieldsObj::addContainerListener(
1014 const uno::Reference<container::XContainerListener>& /* xListener */ )
1015 throw(uno::RuntimeException)
1017 DBG_ERROR("not implemented");
1020 void SAL_CALL ScHeaderFieldsObj::removeContainerListener(
1021 const uno::Reference<container::XContainerListener>& /* xListener */ )
1022 throw(uno::RuntimeException)
1024 DBG_ERROR("not implemented");
1027 // XRefreshable
1028 void SAL_CALL ScHeaderFieldsObj::refresh( )
1029 throw (uno::RuntimeException)
1031 if (mpRefreshListeners)
1033 // Call all listeners.
1034 uno::Sequence< uno::Reference< uno::XInterface > > aListeners(mpRefreshListeners->getElements());
1035 sal_uInt32 nLength(aListeners.getLength());
1036 if (nLength)
1038 const uno::Reference< uno::XInterface >* pInterfaces = aListeners.getConstArray();
1039 if (pInterfaces)
1041 lang::EventObject aEvent;
1042 aEvent.Source.set(uno::Reference< util::XRefreshable >(const_cast<ScHeaderFieldsObj*>(this)));
1043 sal_uInt32 i(0);
1044 while (i < nLength)
1048 while(i < nLength)
1050 static_cast< util::XRefreshListener* >(pInterfaces->get())->refreshed(aEvent);
1051 ++pInterfaces;
1052 ++i;
1055 catch(uno::RuntimeException&)
1057 // DBG_ERROR("a object is gone without to remove from Broadcaster");
1058 ++pInterfaces;
1059 ++i;
1067 void SAL_CALL ScHeaderFieldsObj::addRefreshListener( const uno::Reference< util::XRefreshListener >& xListener )
1068 throw (uno::RuntimeException)
1070 if (xListener.is())
1072 ScUnoGuard aGuard;
1073 if (!mpRefreshListeners)
1074 mpRefreshListeners = new cppu::OInterfaceContainerHelper(aMutex);
1075 mpRefreshListeners->addInterface(xListener);
1079 void SAL_CALL ScHeaderFieldsObj::removeRefreshListener( const uno::Reference<util::XRefreshListener >& xListener )
1080 throw (uno::RuntimeException)
1082 if (xListener.is())
1084 ScUnoGuard aGuard;
1085 if (mpRefreshListeners)
1086 mpRefreshListeners->removeInterface(xListener);
1090 //------------------------------------------------------------------------
1092 SvxFileFormat lcl_UnoToSvxFileFormat( sal_Int16 nUnoValue )
1094 switch( nUnoValue )
1096 case text::FilenameDisplayFormat::FULL: return SVXFILEFORMAT_FULLPATH;
1097 case text::FilenameDisplayFormat::PATH: return SVXFILEFORMAT_PATH;
1098 case text::FilenameDisplayFormat::NAME: return SVXFILEFORMAT_NAME;
1099 // case text::FilenameDisplayFormat::NAME_AND_EXT:
1100 default:
1101 return SVXFILEFORMAT_NAME_EXT;
1105 sal_Int16 lcl_SvxToUnoFileFormat( SvxFileFormat nSvxValue )
1107 switch( nSvxValue )
1109 case SVXFILEFORMAT_NAME_EXT: return text::FilenameDisplayFormat::NAME_AND_EXT;
1110 case SVXFILEFORMAT_FULLPATH: return text::FilenameDisplayFormat::FULL;
1111 case SVXFILEFORMAT_PATH: return text::FilenameDisplayFormat::PATH;
1112 // case SVXFILEFORMAT_NAME:
1113 default:
1114 return text::FilenameDisplayFormat::NAME;
1119 // Default-ctor wird fuer SMART_REFLECTION_IMPLEMENTATION gebraucht
1120 //UNUSED2008-05 ScHeaderFieldObj::ScHeaderFieldObj() :
1121 //UNUSED2008-05 OComponentHelper( getMutex() ),
1122 //UNUSED2008-05 aPropSet( lcl_GetHeaderFieldPropertyMap() ),
1123 //UNUSED2008-05 pContentObj( NULL ),
1124 //UNUSED2008-05 nPart( 0 ),
1125 //UNUSED2008-05 nType( 0 ),
1126 //UNUSED2008-05 nFileFormat( SVXFILEFORMAT_NAME_EXT )
1127 //UNUSED2008-05 {
1128 //UNUSED2008-05 pEditSource = NULL;
1129 //UNUSED2008-05 }
1131 ScHeaderFieldObj::ScHeaderFieldObj(ScHeaderFooterContentObj* pContent, USHORT nP,
1132 USHORT nT, const ESelection& rSel) :
1133 OComponentHelper( getMutex() ),
1134 pPropSet( (nT == SC_SERVICE_FILEFIELD) ? lcl_GetFileFieldPropertySet() : lcl_GetHeaderFieldPropertySet() ),
1135 pContentObj( pContent ),
1136 nPart( nP ),
1137 nType( nT ),
1138 aSelection( rSel ),
1139 nFileFormat( SVXFILEFORMAT_NAME_EXT )
1141 // pContent ist Null, wenn per ServiceProvider erzeugt
1143 if (pContentObj)
1145 pContentObj->acquire(); // darf nicht wegkommen
1146 pEditSource = new ScHeaderFooterEditSource( pContentObj, nPart );
1148 else
1149 pEditSource = NULL;
1152 uno::Any SAL_CALL ScHeaderFieldObj::queryAggregation( const uno::Type& rType )
1153 throw(uno::RuntimeException)
1155 SC_QUERYINTERFACE( text::XTextField )
1156 SC_QUERYINTERFACE( text::XTextContent ) // parent of XTextField
1157 SC_QUERYINTERFACE( beans::XPropertySet )
1158 SC_QUERYINTERFACE( lang::XUnoTunnel )
1159 SC_QUERYINTERFACE( lang::XServiceInfo )
1161 return OComponentHelper::queryAggregation( rType ); // XComponent
1164 uno::Sequence<uno::Type> SAL_CALL ScHeaderFieldObj::getTypes() throw(uno::RuntimeException)
1166 static uno::Sequence<uno::Type> aTypes;
1167 if ( aTypes.getLength() == 0 )
1169 uno::Sequence<uno::Type> aParentTypes(OComponentHelper::getTypes());
1170 long nParentLen = aParentTypes.getLength();
1171 const uno::Type* pParentPtr = aParentTypes.getConstArray();
1173 aTypes.realloc( nParentLen + 4 );
1174 uno::Type* pPtr = aTypes.getArray();
1175 pPtr[nParentLen + 0] = getCppuType((const uno::Reference<text::XTextField>*)0);
1176 pPtr[nParentLen + 1] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
1177 pPtr[nParentLen + 2] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0);
1178 pPtr[nParentLen + 3] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
1180 for (long i=0; i<nParentLen; i++)
1181 pPtr[i] = pParentPtr[i]; // parent types first
1183 return aTypes;
1186 uno::Sequence<sal_Int8> SAL_CALL ScHeaderFieldObj::getImplementationId()
1187 throw(uno::RuntimeException)
1189 static uno::Sequence< sal_Int8 > aId;
1190 if( aId.getLength() == 0 )
1192 aId.realloc( 16 );
1193 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
1195 return aId;
1198 uno::Any SAL_CALL ScHeaderFieldObj::queryInterface( const uno::Type& rType )
1199 throw(uno::RuntimeException)
1201 return OComponentHelper::queryInterface( rType );
1204 void SAL_CALL ScHeaderFieldObj::acquire() throw()
1206 OComponentHelper::acquire();
1209 void SAL_CALL ScHeaderFieldObj::release() throw()
1211 OComponentHelper::release();
1214 void ScHeaderFieldObj::InitDoc( ScHeaderFooterContentObj* pContent, USHORT nP,
1215 const ESelection& rSel )
1217 if ( pContent && !pEditSource )
1219 DBG_ASSERT( !pContentObj, "ContentObj, aber kein EditSource?" );
1221 aSelection = rSel;
1222 nPart = nP;
1223 pContentObj = pContent;
1225 pContentObj->acquire(); // darf nicht wegkommen
1226 pEditSource = new ScHeaderFooterEditSource( pContentObj, nPart );
1230 ScHeaderFieldObj::~ScHeaderFieldObj()
1232 delete pEditSource;
1234 if (pContentObj)
1235 pContentObj->release();
1238 // per getImplementation gerufen:
1240 SvxFieldItem ScHeaderFieldObj::CreateFieldItem()
1242 DBG_ASSERT( !pEditSource, "CreateFieldItem mit eingefuegtem Feld" );
1244 switch (nType)
1246 case SC_SERVICE_PAGEFIELD:
1248 SvxPageField aField;
1249 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1251 case SC_SERVICE_PAGESFIELD:
1253 SvxPagesField aField;
1254 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1256 case SC_SERVICE_DATEFIELD:
1258 SvxDateField aField;
1259 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1261 case SC_SERVICE_TIMEFIELD:
1263 SvxTimeField aField;
1264 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1266 case SC_SERVICE_TITLEFIELD:
1268 SvxFileField aField;
1269 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1271 case SC_SERVICE_FILEFIELD:
1273 SvxExtFileField aField;
1274 aField.SetFormat( (SvxFileFormat) nFileFormat );
1275 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1277 case SC_SERVICE_SHEETFIELD:
1279 SvxTableField aField;
1280 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1284 return SvxFieldItem( SvxFieldData(), EE_FEATURE_FIELD );
1287 void ScHeaderFieldObj::DeleteField()
1289 if (pEditSource)
1291 SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
1292 // pEditEngine->QuickDelete( aSelection );
1293 pForwarder->QuickInsertText( String(), aSelection );
1294 pEditSource->UpdateData();
1296 aSelection.nEndPara = aSelection.nStartPara;
1297 aSelection.nEndPos = aSelection.nStartPos;
1299 //! Broadcast, um Selektion in anderen Objekten anzupassen
1300 //! (auch bei anderen Aktionen)
1304 // XTextField
1306 rtl::OUString SAL_CALL ScHeaderFieldObj::getPresentation( sal_Bool /* bShowCommand */ )
1307 throw(uno::RuntimeException)
1309 ScUnoGuard aGuard;
1310 String aRet;
1312 if (pEditSource)
1314 // Feld von der EditEngine formatieren lassen, bShowCommand gibt's nicht
1316 SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
1317 aRet = pForwarder->GetText( aSelection );
1320 return aRet;
1323 // XTextContent
1325 void SAL_CALL ScHeaderFieldObj::attach( const uno::Reference<text::XTextRange>& xTextRange )
1326 throw(lang::IllegalArgumentException, uno::RuntimeException)
1328 ScUnoGuard aGuard;
1329 if (xTextRange.is())
1331 uno::Reference<text::XText> xText(xTextRange->getText());
1332 if (xText.is())
1334 xText->insertTextContent( xTextRange, this, TRUE );
1339 uno::Reference<text::XTextRange> SAL_CALL ScHeaderFieldObj::getAnchor() throw(uno::RuntimeException)
1341 ScUnoGuard aGuard;
1342 if (pContentObj)
1344 uno::Reference<text::XText> xText;
1345 if ( nPart == SC_HDFT_LEFT )
1346 xText = pContentObj->getLeftText();
1347 else if (nPart == SC_HDFT_CENTER)
1348 xText = pContentObj->getCenterText();
1349 else
1350 xText = pContentObj->getRightText();
1351 return uno::Reference<text::XTextRange>( xText, uno::UNO_QUERY );
1353 return NULL;
1356 // XComponent
1358 void SAL_CALL ScHeaderFieldObj::dispose() throw(uno::RuntimeException)
1360 OComponentHelper::dispose();
1363 void SAL_CALL ScHeaderFieldObj::addEventListener(
1364 const uno::Reference<lang::XEventListener>& xListener )
1365 throw(uno::RuntimeException)
1367 OComponentHelper::addEventListener( xListener );
1370 void SAL_CALL ScHeaderFieldObj::removeEventListener(
1371 const uno::Reference<lang::XEventListener>& xListener )
1372 throw(uno::RuntimeException)
1374 OComponentHelper::removeEventListener( xListener );
1377 // XPropertySet
1379 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScHeaderFieldObj::getPropertySetInfo()
1380 throw(uno::RuntimeException)
1382 ScUnoGuard aGuard;
1383 if (nType == SC_SERVICE_FILEFIELD)
1385 // file field has different properties
1386 static uno::Reference<beans::XPropertySetInfo> aFileFieldInfo = pPropSet->getPropertySetInfo();
1387 return aFileFieldInfo;
1389 else
1391 static uno::Reference<beans::XPropertySetInfo> aRef = pPropSet->getPropertySetInfo();
1392 return aRef;
1396 void SAL_CALL ScHeaderFieldObj::setPropertyValue(
1397 const rtl::OUString& aPropertyName, const uno::Any& aValue )
1398 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1399 lang::IllegalArgumentException, lang::WrappedTargetException,
1400 uno::RuntimeException)
1402 ScUnoGuard aGuard;
1403 String aNameString(aPropertyName);
1404 if ( nType == SC_SERVICE_FILEFIELD && aNameString.EqualsAscii( SC_UNONAME_FILEFORM ) )
1406 sal_Int16 nIntVal = 0;
1407 if ( aValue >>= nIntVal )
1409 SvxFileFormat eFormat = lcl_UnoToSvxFileFormat( nIntVal );
1410 if (pEditSource)
1412 ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine();
1413 ScUnoEditEngine aTempEngine(pEditEngine);
1414 SvxFieldData* pField = aTempEngine.FindByPos(
1415 aSelection.nStartPara, aSelection.nStartPos, TYPE(SvxExtFileField) );
1416 DBG_ASSERT(pField,"setPropertyValue: Field not found");
1417 if (pField)
1419 SvxExtFileField* pExtFile = (SvxExtFileField*)pField; // local to the ScUnoEditEngine
1420 pExtFile->SetFormat( eFormat );
1421 pEditEngine->QuickInsertField( SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection );
1422 pEditSource->UpdateData();
1425 else
1426 nFileFormat = sal::static_int_cast<sal_Int16>(eFormat); // not inserted yet - store value
1431 uno::Any SAL_CALL ScHeaderFieldObj::getPropertyValue( const rtl::OUString& aPropertyName )
1432 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1433 uno::RuntimeException)
1435 ScUnoGuard aGuard;
1437 //! Properties?
1438 uno::Any aRet;
1439 String aNameString(aPropertyName);
1441 // anchor type is always "as character", text wrap always "none"
1443 if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPE ) )
1444 aRet <<= text::TextContentAnchorType_AS_CHARACTER;
1445 else if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPES ) )
1447 uno::Sequence<text::TextContentAnchorType> aSeq(1);
1448 aSeq[0] = text::TextContentAnchorType_AS_CHARACTER;
1449 aRet <<= aSeq;
1451 else if ( aNameString.EqualsAscii( SC_UNONAME_TEXTWRAP ) )
1452 aRet <<= text::WrapTextMode_NONE;
1453 else if ( nType == SC_SERVICE_FILEFIELD && aNameString.EqualsAscii( SC_UNONAME_FILEFORM ) )
1455 SvxFileFormat eFormat = SVXFILEFORMAT_NAME_EXT;
1456 if (pEditSource)
1458 ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine();
1459 ScUnoEditEngine aTempEngine(pEditEngine);
1460 SvxFieldData* pField = aTempEngine.FindByPos(
1461 aSelection.nStartPara, aSelection.nStartPos, TYPE(SvxExtFileField) );
1462 DBG_ASSERT(pField,"setPropertyValue: Field not found");
1463 if (pField)
1465 const SvxExtFileField* pExtFile = (const SvxExtFileField*)pField;
1466 eFormat = pExtFile->GetFormat();
1469 else
1470 eFormat = (SvxFileFormat) nFileFormat; // not inserted yet - use stored value
1472 sal_Int16 nIntVal = lcl_SvxToUnoFileFormat( eFormat );
1473 aRet <<= nIntVal;
1476 return aRet;
1479 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScHeaderFieldObj )
1481 // XUnoTunnel
1483 sal_Int64 SAL_CALL ScHeaderFieldObj::getSomething(
1484 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
1486 if ( rId.getLength() == 16 &&
1487 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
1488 rId.getConstArray(), 16 ) )
1490 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
1492 return 0;
1495 // static
1496 const uno::Sequence<sal_Int8>& ScHeaderFieldObj::getUnoTunnelId()
1498 static uno::Sequence<sal_Int8> * pSeq = 0;
1499 if( !pSeq )
1501 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
1502 if( !pSeq )
1504 static uno::Sequence< sal_Int8 > aSeq( 16 );
1505 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
1506 pSeq = &aSeq;
1509 return *pSeq;
1512 // static
1513 ScHeaderFieldObj* ScHeaderFieldObj::getImplementation(
1514 const uno::Reference<text::XTextContent> xObj )
1516 ScHeaderFieldObj* pRet = NULL;
1517 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
1518 if (xUT.is())
1519 pRet = reinterpret_cast<ScHeaderFieldObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
1520 return pRet;
1523 // XServiceInfo
1525 rtl::OUString SAL_CALL ScHeaderFieldObj::getImplementationName() throw(uno::RuntimeException)
1527 return rtl::OUString::createFromAscii( "ScHeaderFieldObj" );
1530 sal_Bool SAL_CALL ScHeaderFieldObj::supportsService( const rtl::OUString& rServiceName )
1531 throw(uno::RuntimeException)
1533 String aServiceStr( rServiceName );
1534 return aServiceStr.EqualsAscii( SCTEXTFIELD_SERVICE ) ||
1535 aServiceStr.EqualsAscii( SCTEXTCONTENT_SERVICE );
1538 uno::Sequence<rtl::OUString> SAL_CALL ScHeaderFieldObj::getSupportedServiceNames()
1539 throw(uno::RuntimeException)
1541 uno::Sequence<rtl::OUString> aRet(2);
1542 rtl::OUString* pArray = aRet.getArray();
1543 pArray[0] = rtl::OUString::createFromAscii( SCTEXTFIELD_SERVICE );
1544 pArray[1] = rtl::OUString::createFromAscii( SCTEXTCONTENT_SERVICE );
1545 return aRet;
1548 //------------------------------------------------------------------------