xref: /aoo41x/main/sc/source/ui/unoobj/fielduno.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir #include <svl/smplhint.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <editeng/eeitem.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <editeng/editeng.hxx>
32cdf0e10cSrcweir #include <editeng/editobj.hxx>
33cdf0e10cSrcweir #include <editeng/flditem.hxx>
34cdf0e10cSrcweir #include <rtl/uuid.h>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
37cdf0e10cSrcweir #include <com/sun/star/text/TextContentAnchorType.hpp>
38cdf0e10cSrcweir #include <com/sun/star/text/WrapTextMode.hpp>
39cdf0e10cSrcweir #include <com/sun/star/text/FilenameDisplayFormat.hpp>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include "fielduno.hxx"
42cdf0e10cSrcweir #include "textuno.hxx"
43cdf0e10cSrcweir #include "miscuno.hxx"
44cdf0e10cSrcweir #include "docsh.hxx"
45cdf0e10cSrcweir #include "hints.hxx"
46cdf0e10cSrcweir #include "editsrc.hxx"
47cdf0e10cSrcweir #include "cellsuno.hxx"
48cdf0e10cSrcweir #include "servuno.hxx"		// fuer IDs
49cdf0e10cSrcweir #include "unoguard.hxx"
50cdf0e10cSrcweir #include "unonames.hxx"
51cdf0e10cSrcweir #include "editutil.hxx"
52cdf0e10cSrcweir 
53cdf0e10cSrcweir using namespace com::sun::star;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir //------------------------------------------------------------------------
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //	alles ohne Which-ID, Map nur fuer PropertySetInfo
58cdf0e10cSrcweir 
lcl_GetURLPropertySet()59cdf0e10cSrcweir const SfxItemPropertySet* lcl_GetURLPropertySet()
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     static SfxItemPropertyMapEntry aURLPropertyMap_Impl[] =
62cdf0e10cSrcweir 	{
63cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ANCTYPE),  0,  &getCppuType((text::TextContentAnchorType*)0), beans::PropertyAttribute::READONLY, 0 },
64cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ANCTYPES), 0,  &getCppuType((uno::Sequence<text::TextContentAnchorType>*)0), beans::PropertyAttribute::READONLY, 0 },
65cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_REPR),     0,  &getCppuType((rtl::OUString*)0),    0, 0},
66cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_TARGET),   0,  &getCppuType((rtl::OUString*)0),    0, 0},
67cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_TEXTWRAP), 0,  &getCppuType((text::WrapTextMode*)0), beans::PropertyAttribute::READONLY, 0 },
68cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_URL),      0,  &getCppuType((rtl::OUString*)0),    0, 0},
69cdf0e10cSrcweir         {0,0,0,0,0,0}
70cdf0e10cSrcweir 	};
71cdf0e10cSrcweir     static SfxItemPropertySet aURLPropertySet_Impl( aURLPropertyMap_Impl );
72cdf0e10cSrcweir 	return &aURLPropertySet_Impl;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
lcl_GetHeaderFieldPropertySet()75cdf0e10cSrcweir const SfxItemPropertySet* lcl_GetHeaderFieldPropertySet()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     static SfxItemPropertyMapEntry aHeaderFieldPropertyMap_Impl[] =
78cdf0e10cSrcweir 	{
79cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ANCTYPE),  0,  &getCppuType((text::TextContentAnchorType*)0), beans::PropertyAttribute::READONLY, 0 },
80cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ANCTYPES), 0,  &getCppuType((uno::Sequence<text::TextContentAnchorType>*)0), beans::PropertyAttribute::READONLY, 0 },
81cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_TEXTWRAP), 0,  &getCppuType((text::WrapTextMode*)0), beans::PropertyAttribute::READONLY, 0 },
82cdf0e10cSrcweir         {0,0,0,0,0,0}
83cdf0e10cSrcweir 	};
84cdf0e10cSrcweir     static SfxItemPropertySet aHeaderFieldPropertySet_Impl( aHeaderFieldPropertyMap_Impl );
85cdf0e10cSrcweir 	return &aHeaderFieldPropertySet_Impl;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
lcl_GetFileFieldPropertySet()88cdf0e10cSrcweir const SfxItemPropertySet* lcl_GetFileFieldPropertySet()
89cdf0e10cSrcweir {
90cdf0e10cSrcweir     static SfxItemPropertyMapEntry aFileFieldPropertyMap_Impl[] =
91cdf0e10cSrcweir 	{
92cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ANCTYPE),  0,  &getCppuType((text::TextContentAnchorType*)0), beans::PropertyAttribute::READONLY, 0 },
93cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ANCTYPES), 0,  &getCppuType((uno::Sequence<text::TextContentAnchorType>*)0), beans::PropertyAttribute::READONLY, 0 },
94cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_FILEFORM), 0,  &getCppuType((sal_Int16*)0),        0, 0 },
95cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_TEXTWRAP), 0,  &getCppuType((text::WrapTextMode*)0), beans::PropertyAttribute::READONLY, 0 },
96cdf0e10cSrcweir         {0,0,0,0,0,0}
97cdf0e10cSrcweir 	};
98cdf0e10cSrcweir     static SfxItemPropertySet aFileFieldPropertySet_Impl( aFileFieldPropertyMap_Impl );
99cdf0e10cSrcweir     return &aFileFieldPropertySet_Impl;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir //------------------------------------------------------------------------
103cdf0e10cSrcweir 
104cdf0e10cSrcweir #define SCTEXTFIELD_SERVICE			"com.sun.star.text.TextField"
105cdf0e10cSrcweir #define SCTEXTCONTENT_SERVICE		"com.sun.star.text.TextContent"
106cdf0e10cSrcweir 
107cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScCellFieldsObj, "ScCellFieldsObj", "com.sun.star.text.TextFields" )
108cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScHeaderFieldsObj, "ScHeaderFieldsObj", "com.sun.star.text.TextFields" )
109cdf0e10cSrcweir 
110cdf0e10cSrcweir //------------------------------------------------------------------------
111cdf0e10cSrcweir 
112cdf0e10cSrcweir //	ScUnoEditEngine nur um aus einer EditEngine die Felder herauszubekommen...
113cdf0e10cSrcweir 
114cdf0e10cSrcweir enum ScUnoCollectMode
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	SC_UNO_COLLECT_NONE,
117cdf0e10cSrcweir 	SC_UNO_COLLECT_COUNT,
118cdf0e10cSrcweir 	SC_UNO_COLLECT_FINDINDEX,
119cdf0e10cSrcweir 	SC_UNO_COLLECT_FINDPOS
120cdf0e10cSrcweir };
121cdf0e10cSrcweir 
122cdf0e10cSrcweir class ScUnoEditEngine : public ScEditEngineDefaulter
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	ScUnoCollectMode	eMode;
125cdf0e10cSrcweir 	sal_uInt16				nFieldCount;
126cdf0e10cSrcweir 	TypeId				aFieldType;
127cdf0e10cSrcweir 	SvxFieldData*		pFound;			// lokale Kopie
128cdf0e10cSrcweir 	sal_uInt16				nFieldPar;
129cdf0e10cSrcweir 	xub_StrLen			nFieldPos;
130cdf0e10cSrcweir 	sal_uInt16				nFieldIndex;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir public:
133cdf0e10cSrcweir 				ScUnoEditEngine(ScEditEngineDefaulter* pSource);
134cdf0e10cSrcweir 				~ScUnoEditEngine();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 					//!	nPos should be xub_StrLen
137cdf0e10cSrcweir 	virtual String	CalcFieldValue( const SvxFieldItem& rField, sal_uInt16 nPara, sal_uInt16 nPos,
138cdf0e10cSrcweir 									Color*& rTxtColor, Color*& rFldColor );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	sal_uInt16			CountFields(TypeId aType);
141cdf0e10cSrcweir 	SvxFieldData*	FindByIndex(sal_uInt16 nIndex, TypeId aType);
142cdf0e10cSrcweir 	SvxFieldData*	FindByPos(sal_uInt16 nPar, xub_StrLen nPos, TypeId aType);
143cdf0e10cSrcweir 
GetFieldPar() const144cdf0e10cSrcweir 	sal_uInt16			GetFieldPar() const		{ return nFieldPar; }
GetFieldPos() const145cdf0e10cSrcweir 	xub_StrLen		GetFieldPos() const		{ return nFieldPos; }
146cdf0e10cSrcweir };
147cdf0e10cSrcweir 
ScUnoEditEngine(ScEditEngineDefaulter * pSource)148cdf0e10cSrcweir ScUnoEditEngine::ScUnoEditEngine(ScEditEngineDefaulter* pSource) :
149cdf0e10cSrcweir 	ScEditEngineDefaulter( *pSource ),
150cdf0e10cSrcweir 	eMode( SC_UNO_COLLECT_NONE ),
151cdf0e10cSrcweir 	nFieldCount( 0 ),
152cdf0e10cSrcweir 	aFieldType( NULL ),
153cdf0e10cSrcweir 	pFound( NULL )
154cdf0e10cSrcweir {
155cdf0e10cSrcweir 	if (pSource)
156cdf0e10cSrcweir 	{
157cdf0e10cSrcweir 		EditTextObject* pData = pSource->CreateTextObject();
158cdf0e10cSrcweir 		SetText( *pData );
159cdf0e10cSrcweir 		delete pData;
160cdf0e10cSrcweir 	}
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
~ScUnoEditEngine()163cdf0e10cSrcweir ScUnoEditEngine::~ScUnoEditEngine()
164cdf0e10cSrcweir {
165cdf0e10cSrcweir 	delete pFound;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
CalcFieldValue(const SvxFieldItem & rField,sal_uInt16 nPara,sal_uInt16 nPos,Color * & rTxtColor,Color * & rFldColor)168cdf0e10cSrcweir String ScUnoEditEngine::CalcFieldValue( const SvxFieldItem& rField,
169cdf0e10cSrcweir 			sal_uInt16 nPara, sal_uInt16 nPos, Color*& rTxtColor, Color*& rFldColor )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir 	String aRet(EditEngine::CalcFieldValue( rField, nPara, nPos, rTxtColor, rFldColor ));
172cdf0e10cSrcweir 	if (eMode != SC_UNO_COLLECT_NONE)
173cdf0e10cSrcweir 	{
174cdf0e10cSrcweir 		const SvxFieldData*	pFieldData = rField.GetField();
175cdf0e10cSrcweir 		if ( pFieldData )
176cdf0e10cSrcweir 		{
177cdf0e10cSrcweir 			if ( !aFieldType || pFieldData->Type() == aFieldType )
178cdf0e10cSrcweir 			{
179cdf0e10cSrcweir 				if ( eMode == SC_UNO_COLLECT_FINDINDEX && !pFound && nFieldCount == nFieldIndex )
180cdf0e10cSrcweir 				{
181cdf0e10cSrcweir 					pFound = pFieldData->Clone();
182cdf0e10cSrcweir 					nFieldPar = nPara;
183cdf0e10cSrcweir 					nFieldPos = nPos;
184cdf0e10cSrcweir 				}
185cdf0e10cSrcweir 				if ( eMode == SC_UNO_COLLECT_FINDPOS && !pFound &&
186cdf0e10cSrcweir 						nPara == nFieldPar && nPos == nFieldPos )
187cdf0e10cSrcweir 				{
188cdf0e10cSrcweir 					pFound = pFieldData->Clone();
189cdf0e10cSrcweir 					nFieldIndex = nFieldCount;
190cdf0e10cSrcweir 				}
191cdf0e10cSrcweir 				++nFieldCount;
192cdf0e10cSrcweir 			}
193cdf0e10cSrcweir 		}
194cdf0e10cSrcweir 	}
195cdf0e10cSrcweir 	return aRet;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
CountFields(TypeId aType)198cdf0e10cSrcweir sal_uInt16 ScUnoEditEngine::CountFields(TypeId aType)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	eMode = SC_UNO_COLLECT_COUNT;
201cdf0e10cSrcweir 	aFieldType = aType;
202cdf0e10cSrcweir 	nFieldCount = 0;
203cdf0e10cSrcweir 	UpdateFields();
204cdf0e10cSrcweir 	aFieldType = NULL;
205cdf0e10cSrcweir 	eMode = SC_UNO_COLLECT_NONE;
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 	return nFieldCount;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
FindByIndex(sal_uInt16 nIndex,TypeId aType)210cdf0e10cSrcweir SvxFieldData* ScUnoEditEngine::FindByIndex(sal_uInt16 nIndex, TypeId aType)
211cdf0e10cSrcweir {
212cdf0e10cSrcweir 	eMode = SC_UNO_COLLECT_FINDINDEX;
213cdf0e10cSrcweir 	nFieldIndex = nIndex;
214cdf0e10cSrcweir 	aFieldType = aType;
215cdf0e10cSrcweir 	nFieldCount = 0;
216cdf0e10cSrcweir 	UpdateFields();
217cdf0e10cSrcweir 	aFieldType = NULL;
218cdf0e10cSrcweir 	eMode = SC_UNO_COLLECT_NONE;
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 	return pFound;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
FindByPos(sal_uInt16 nPar,xub_StrLen nPos,TypeId aType)223cdf0e10cSrcweir SvxFieldData* ScUnoEditEngine::FindByPos(sal_uInt16 nPar, xub_StrLen nPos, TypeId aType)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir 	eMode = SC_UNO_COLLECT_FINDPOS;
226cdf0e10cSrcweir 	nFieldPar = nPar;
227cdf0e10cSrcweir 	nFieldPos = nPos;
228cdf0e10cSrcweir 	aFieldType = aType;
229cdf0e10cSrcweir 	nFieldCount = 0;
230cdf0e10cSrcweir 	UpdateFields();
231cdf0e10cSrcweir 	aFieldType = NULL;
232cdf0e10cSrcweir 	eMode = SC_UNO_COLLECT_NONE;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 	return pFound;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir //------------------------------------------------------------------------
238cdf0e10cSrcweir 
ScCellFieldsObj(ScDocShell * pDocSh,const ScAddress & rPos)239cdf0e10cSrcweir ScCellFieldsObj::ScCellFieldsObj(ScDocShell* pDocSh, const ScAddress& rPos) :
240cdf0e10cSrcweir 	pDocShell( pDocSh ),
241cdf0e10cSrcweir 	aCellPos( rPos ),
242cdf0e10cSrcweir     mpRefreshListeners( NULL )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir 	pDocShell->GetDocument()->AddUnoObject(*this);
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 	pEditSource = new ScCellEditSource( pDocShell, aCellPos );
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
~ScCellFieldsObj()249cdf0e10cSrcweir ScCellFieldsObj::~ScCellFieldsObj()
250cdf0e10cSrcweir {
251cdf0e10cSrcweir     if (pDocShell)
252cdf0e10cSrcweir 		pDocShell->GetDocument()->RemoveUnoObject(*this);
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	delete pEditSource;
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	// increment refcount to prevent double call off dtor
257cdf0e10cSrcweir 	osl_incrementInterlockedCount( &m_refCount );
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     if (mpRefreshListeners)
260cdf0e10cSrcweir 	{
261cdf0e10cSrcweir 		lang::EventObject aEvent;
262cdf0e10cSrcweir 		aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
263cdf0e10cSrcweir 		if (mpRefreshListeners)
264cdf0e10cSrcweir 		{
265cdf0e10cSrcweir 			mpRefreshListeners->disposeAndClear(aEvent);
266cdf0e10cSrcweir 			DELETEZ( mpRefreshListeners );
267cdf0e10cSrcweir 		}
268cdf0e10cSrcweir 	}
269cdf0e10cSrcweir }
270cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)271cdf0e10cSrcweir void ScCellFieldsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
272cdf0e10cSrcweir {
273cdf0e10cSrcweir 	if ( rHint.ISA( ScUpdateRefHint ) )
274cdf0e10cSrcweir 	{
275cdf0e10cSrcweir //        const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 		//!	Ref-Update
278cdf0e10cSrcweir 	}
279cdf0e10cSrcweir 	else if ( rHint.ISA( SfxSimpleHint ) &&
280cdf0e10cSrcweir 			((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
281cdf0e10cSrcweir 	{
282cdf0e10cSrcweir 		pDocShell = NULL;		// ungueltig geworden
283cdf0e10cSrcweir 	}
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 	//	EditSource hat sich selber als Listener angemeldet
286cdf0e10cSrcweir }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir // XIndexAccess (via XTextFields)
289cdf0e10cSrcweir 
GetObjectByIndex_Impl(sal_Int32 Index) const290cdf0e10cSrcweir ScCellFieldObj* ScCellFieldsObj::GetObjectByIndex_Impl(sal_Int32 Index) const
291cdf0e10cSrcweir {
292cdf0e10cSrcweir 	//!	Feld-Funktionen muessen an den Forwarder !!!
293cdf0e10cSrcweir 	ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
294cdf0e10cSrcweir 	ScUnoEditEngine aTempEngine(pEditEngine);
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	if ( aTempEngine.FindByIndex( (sal_uInt16)Index, NULL ) )	// in der Zelle ist der Typ egal
297cdf0e10cSrcweir 	{
298cdf0e10cSrcweir 		sal_uInt16 nPar = aTempEngine.GetFieldPar();
299cdf0e10cSrcweir 		xub_StrLen nPos = aTempEngine.GetFieldPos();
300cdf0e10cSrcweir 		ESelection aSelection( nPar, nPos, nPar, nPos+1 );		// Feld ist 1 Zeichen
301cdf0e10cSrcweir 		return new ScCellFieldObj( pDocShell, aCellPos, aSelection );
302cdf0e10cSrcweir 	}
303cdf0e10cSrcweir 	return NULL;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
getCount()306cdf0e10cSrcweir sal_Int32 SAL_CALL ScCellFieldsObj::getCount() throw(uno::RuntimeException)
307cdf0e10cSrcweir {
308cdf0e10cSrcweir 	ScUnoGuard aGuard;
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 	//!	Feld-Funktionen muessen an den Forwarder !!!
311cdf0e10cSrcweir 	ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
312cdf0e10cSrcweir 	ScUnoEditEngine aTempEngine(pEditEngine);
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 	return aTempEngine.CountFields(NULL);		// Felder zaehlen, in Zelle ist der Typ egal
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
getByIndex(sal_Int32 nIndex)317cdf0e10cSrcweir uno::Any SAL_CALL ScCellFieldsObj::getByIndex( sal_Int32 nIndex )
318cdf0e10cSrcweir 							throw(lang::IndexOutOfBoundsException,
319cdf0e10cSrcweir 									lang::WrappedTargetException, uno::RuntimeException)
320cdf0e10cSrcweir {
321cdf0e10cSrcweir 	ScUnoGuard aGuard;
322cdf0e10cSrcweir 	uno::Reference<text::XTextField> xField(GetObjectByIndex_Impl(nIndex));
323cdf0e10cSrcweir 	if (xField.is())
324cdf0e10cSrcweir         return uno::makeAny(xField);
325cdf0e10cSrcweir 	else
326cdf0e10cSrcweir 		throw lang::IndexOutOfBoundsException();
327cdf0e10cSrcweir //    return uno::Any();
328cdf0e10cSrcweir }
329cdf0e10cSrcweir 
getElementType()330cdf0e10cSrcweir uno::Type SAL_CALL ScCellFieldsObj::getElementType() throw(uno::RuntimeException)
331cdf0e10cSrcweir {
332cdf0e10cSrcweir 	ScUnoGuard aGuard;
333cdf0e10cSrcweir 	return getCppuType((uno::Reference<text::XTextField>*)0);
334cdf0e10cSrcweir }
335cdf0e10cSrcweir 
hasElements()336cdf0e10cSrcweir sal_Bool SAL_CALL ScCellFieldsObj::hasElements() throw(uno::RuntimeException)
337cdf0e10cSrcweir {
338cdf0e10cSrcweir 	ScUnoGuard aGuard;
339cdf0e10cSrcweir 	return ( getCount() != 0 );
340cdf0e10cSrcweir }
341cdf0e10cSrcweir 
createEnumeration()342cdf0e10cSrcweir uno::Reference<container::XEnumeration> SAL_CALL ScCellFieldsObj::createEnumeration()
343cdf0e10cSrcweir 													throw(uno::RuntimeException)
344cdf0e10cSrcweir {
345cdf0e10cSrcweir 	ScUnoGuard aGuard;
346cdf0e10cSrcweir 	return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFieldEnumeration")));
347cdf0e10cSrcweir }
348cdf0e10cSrcweir 
addContainerListener(const uno::Reference<container::XContainerListener> &)349cdf0e10cSrcweir void SAL_CALL ScCellFieldsObj::addContainerListener(
350cdf0e10cSrcweir                                 const uno::Reference<container::XContainerListener>& /* xListener */ )
351cdf0e10cSrcweir 									throw(uno::RuntimeException)
352cdf0e10cSrcweir {
353cdf0e10cSrcweir 	DBG_ERROR("not implemented");
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
removeContainerListener(const uno::Reference<container::XContainerListener> &)356cdf0e10cSrcweir void SAL_CALL ScCellFieldsObj::removeContainerListener(
357cdf0e10cSrcweir                                 const uno::Reference<container::XContainerListener>& /* xListener */ )
358cdf0e10cSrcweir 									throw(uno::RuntimeException)
359cdf0e10cSrcweir {
360cdf0e10cSrcweir 	DBG_ERROR("not implemented");
361cdf0e10cSrcweir }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir // XRefreshable
refresh()364cdf0e10cSrcweir void SAL_CALL ScCellFieldsObj::refresh(  )
365cdf0e10cSrcweir                                     throw (uno::RuntimeException)
366cdf0e10cSrcweir {
367cdf0e10cSrcweir 	if (mpRefreshListeners)
368cdf0e10cSrcweir 	{
369cdf0e10cSrcweir     	//  Call all listeners.
370cdf0e10cSrcweir 		uno::Sequence< uno::Reference< uno::XInterface > > aListeners(mpRefreshListeners->getElements());
371cdf0e10cSrcweir 		sal_uInt32 nLength(aListeners.getLength());
372cdf0e10cSrcweir 		if (nLength)
373cdf0e10cSrcweir 		{
374cdf0e10cSrcweir 			const uno::Reference< uno::XInterface >* pInterfaces = aListeners.getConstArray();
375cdf0e10cSrcweir 			if (pInterfaces)
376cdf0e10cSrcweir 			{
377cdf0e10cSrcweir                 lang::EventObject aEvent;
378cdf0e10cSrcweir                 aEvent.Source.set(uno::Reference< util::XRefreshable >(const_cast<ScCellFieldsObj*>(this)));
379cdf0e10cSrcweir 				sal_uInt32 i(0);
380cdf0e10cSrcweir 				while (i < nLength)
381cdf0e10cSrcweir 				{
382cdf0e10cSrcweir 					try
383cdf0e10cSrcweir 					{
384cdf0e10cSrcweir 						while(i < nLength)
385cdf0e10cSrcweir 						{
386cdf0e10cSrcweir 							static_cast< util::XRefreshListener* >(pInterfaces->get())->refreshed(aEvent);
387cdf0e10cSrcweir 							++pInterfaces;
388cdf0e10cSrcweir 							++i;
389cdf0e10cSrcweir 						}
390cdf0e10cSrcweir 					}
391cdf0e10cSrcweir 					catch(uno::RuntimeException&)
392cdf0e10cSrcweir 					{
393cdf0e10cSrcweir //						DBG_ERROR("a object is gone without to remove from Broadcaster");
394cdf0e10cSrcweir 						++pInterfaces;
395cdf0e10cSrcweir 						++i;
396cdf0e10cSrcweir 					}
397cdf0e10cSrcweir 				}
398cdf0e10cSrcweir 			}
399cdf0e10cSrcweir 		}
400cdf0e10cSrcweir 	}
401cdf0e10cSrcweir }
402cdf0e10cSrcweir 
addRefreshListener(const uno::Reference<util::XRefreshListener> & xListener)403cdf0e10cSrcweir void SAL_CALL ScCellFieldsObj::addRefreshListener( const uno::Reference< util::XRefreshListener >& xListener )
404cdf0e10cSrcweir                                     throw (uno::RuntimeException)
405cdf0e10cSrcweir {
406cdf0e10cSrcweir 	if (xListener.is())
407cdf0e10cSrcweir     {
408cdf0e10cSrcweir 		ScUnoGuard aGuard;
409cdf0e10cSrcweir 		if (!mpRefreshListeners)
410cdf0e10cSrcweir 			mpRefreshListeners = new cppu::OInterfaceContainerHelper(aMutex);
411cdf0e10cSrcweir 		mpRefreshListeners->addInterface(xListener);
412cdf0e10cSrcweir     }
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
removeRefreshListener(const uno::Reference<util::XRefreshListener> & xListener)415cdf0e10cSrcweir void SAL_CALL ScCellFieldsObj::removeRefreshListener( const uno::Reference<util::XRefreshListener >& xListener )
416cdf0e10cSrcweir                                     throw (uno::RuntimeException)
417cdf0e10cSrcweir {
418cdf0e10cSrcweir 	if (xListener.is())
419cdf0e10cSrcweir 	{
420cdf0e10cSrcweir 		ScUnoGuard aGuard;
421cdf0e10cSrcweir 		if (mpRefreshListeners)
422cdf0e10cSrcweir 			mpRefreshListeners->removeInterface(xListener);
423cdf0e10cSrcweir 	}
424cdf0e10cSrcweir }
425cdf0e10cSrcweir 
426cdf0e10cSrcweir //------------------------------------------------------------------------
427cdf0e10cSrcweir 
428cdf0e10cSrcweir //	Default-ctor wird fuer SMART_REFLECTION_IMPLEMENTATION gebraucht
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 
431cdf0e10cSrcweir //UNUSED2008-05  ScCellFieldObj::ScCellFieldObj() :
432cdf0e10cSrcweir //UNUSED2008-05      OComponentHelper( getMutex() ),
433cdf0e10cSrcweir //UNUSED2008-05      aPropSet( lcl_GetURLPropertyMap() ),
434cdf0e10cSrcweir //UNUSED2008-05      pDocShell( NULL )
435cdf0e10cSrcweir //UNUSED2008-05  {
436cdf0e10cSrcweir //UNUSED2008-05      pEditSource = NULL;
437cdf0e10cSrcweir //UNUSED2008-05  }
438cdf0e10cSrcweir 
ScCellFieldObj(ScDocShell * pDocSh,const ScAddress & rPos,const ESelection & rSel)439cdf0e10cSrcweir ScCellFieldObj::ScCellFieldObj(ScDocShell* pDocSh, const ScAddress& rPos,
440cdf0e10cSrcweir 											const ESelection& rSel) :
441cdf0e10cSrcweir 	OComponentHelper( getMutex() ),
442cdf0e10cSrcweir 	pPropSet( lcl_GetURLPropertySet() ),
443cdf0e10cSrcweir 	pDocShell( pDocSh ),
444cdf0e10cSrcweir 	aCellPos( rPos ),
445cdf0e10cSrcweir 	aSelection( rSel )
446cdf0e10cSrcweir {
447cdf0e10cSrcweir 	//	pDocShell ist Null, wenn per ServiceProvider erzeugt
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 	if (pDocShell)
450cdf0e10cSrcweir 	{
451cdf0e10cSrcweir 		pDocShell->GetDocument()->AddUnoObject(*this);
452cdf0e10cSrcweir 		pEditSource = new ScCellEditSource( pDocShell, aCellPos );
453cdf0e10cSrcweir 	}
454cdf0e10cSrcweir 	else
455cdf0e10cSrcweir 		pEditSource = NULL;
456cdf0e10cSrcweir }
457cdf0e10cSrcweir 
queryAggregation(const uno::Type & rType)458cdf0e10cSrcweir uno::Any SAL_CALL ScCellFieldObj::queryAggregation( const uno::Type& rType )
459cdf0e10cSrcweir 												throw(uno::RuntimeException)
460cdf0e10cSrcweir {
461cdf0e10cSrcweir 	SC_QUERYINTERFACE( text::XTextField )
462cdf0e10cSrcweir 	SC_QUERYINTERFACE( text::XTextContent )			// parent of XTextField
463cdf0e10cSrcweir 	SC_QUERYINTERFACE( beans::XPropertySet )
464cdf0e10cSrcweir 	SC_QUERYINTERFACE( lang::XUnoTunnel )
465cdf0e10cSrcweir 	SC_QUERYINTERFACE( lang::XServiceInfo )
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 	return OComponentHelper::queryAggregation( rType );		// XComponent
468cdf0e10cSrcweir }
469cdf0e10cSrcweir 
getTypes()470cdf0e10cSrcweir uno::Sequence<uno::Type> SAL_CALL ScCellFieldObj::getTypes() throw(uno::RuntimeException)
471cdf0e10cSrcweir {
472cdf0e10cSrcweir 	static uno::Sequence<uno::Type> aTypes;
473cdf0e10cSrcweir 	if ( aTypes.getLength() == 0 )
474cdf0e10cSrcweir 	{
475cdf0e10cSrcweir 		uno::Sequence<uno::Type> aParentTypes(OComponentHelper::getTypes());
476cdf0e10cSrcweir 		long nParentLen = aParentTypes.getLength();
477cdf0e10cSrcweir 		const uno::Type* pParentPtr = aParentTypes.getConstArray();
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 		aTypes.realloc( nParentLen + 4 );
480cdf0e10cSrcweir 		uno::Type* pPtr = aTypes.getArray();
481cdf0e10cSrcweir 		pPtr[nParentLen + 0] = getCppuType((const uno::Reference<text::XTextField>*)0);
482cdf0e10cSrcweir 		pPtr[nParentLen + 1] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
483cdf0e10cSrcweir 		pPtr[nParentLen + 2] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0);
484cdf0e10cSrcweir 		pPtr[nParentLen + 3] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 		for (long i=0; i<nParentLen; i++)
487cdf0e10cSrcweir 			pPtr[i] = pParentPtr[i];				// parent types first
488cdf0e10cSrcweir 	}
489cdf0e10cSrcweir 	return aTypes;
490cdf0e10cSrcweir }
491cdf0e10cSrcweir 
getImplementationId()492cdf0e10cSrcweir uno::Sequence<sal_Int8> SAL_CALL ScCellFieldObj::getImplementationId()
493cdf0e10cSrcweir 													throw(uno::RuntimeException)
494cdf0e10cSrcweir {
495cdf0e10cSrcweir 	static uno::Sequence< sal_Int8 > aId;
496cdf0e10cSrcweir 	if( aId.getLength() == 0 )
497cdf0e10cSrcweir 	{
498cdf0e10cSrcweir 		aId.realloc( 16 );
499cdf0e10cSrcweir 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
500cdf0e10cSrcweir 	}
501cdf0e10cSrcweir 	return aId;
502cdf0e10cSrcweir }
503cdf0e10cSrcweir 
queryInterface(const uno::Type & rType)504cdf0e10cSrcweir uno::Any SAL_CALL ScCellFieldObj::queryInterface( const uno::Type& rType )
505cdf0e10cSrcweir 												throw(uno::RuntimeException)
506cdf0e10cSrcweir {
507cdf0e10cSrcweir 	return OComponentHelper::queryInterface( rType );
508cdf0e10cSrcweir }
509cdf0e10cSrcweir 
acquire()510cdf0e10cSrcweir void SAL_CALL ScCellFieldObj::acquire() throw()
511cdf0e10cSrcweir {
512cdf0e10cSrcweir 	OComponentHelper::acquire();
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
release()515cdf0e10cSrcweir void SAL_CALL ScCellFieldObj::release() throw()
516cdf0e10cSrcweir {
517cdf0e10cSrcweir 	OComponentHelper::release();
518cdf0e10cSrcweir }
519cdf0e10cSrcweir 
InitDoc(ScDocShell * pDocSh,const ScAddress & rPos,const ESelection & rSel)520cdf0e10cSrcweir void ScCellFieldObj::InitDoc( ScDocShell* pDocSh, const ScAddress& rPos,
521cdf0e10cSrcweir 										const ESelection& rSel )
522cdf0e10cSrcweir {
523cdf0e10cSrcweir 	if ( pDocSh && !pEditSource )
524cdf0e10cSrcweir 	{
525cdf0e10cSrcweir 		aCellPos = rPos;
526cdf0e10cSrcweir 		aSelection = rSel;
527cdf0e10cSrcweir 		pDocShell = pDocSh;
528cdf0e10cSrcweir 
529cdf0e10cSrcweir 		pDocShell->GetDocument()->AddUnoObject(*this);
530cdf0e10cSrcweir 		pEditSource = new ScCellEditSource( pDocShell, aCellPos );
531cdf0e10cSrcweir 	}
532cdf0e10cSrcweir }
533cdf0e10cSrcweir 
~ScCellFieldObj()534cdf0e10cSrcweir ScCellFieldObj::~ScCellFieldObj()
535cdf0e10cSrcweir {
536cdf0e10cSrcweir 	if (pDocShell)
537cdf0e10cSrcweir 		pDocShell->GetDocument()->RemoveUnoObject(*this);
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 	delete pEditSource;
540cdf0e10cSrcweir }
541cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)542cdf0e10cSrcweir void ScCellFieldObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
543cdf0e10cSrcweir {
544cdf0e10cSrcweir 	//!	Updates fuer aSelection (muessen erst noch erzeugt werden) !!!!!!
545cdf0e10cSrcweir 
546cdf0e10cSrcweir 	if ( rHint.ISA( ScUpdateRefHint ) )
547cdf0e10cSrcweir 	{
548cdf0e10cSrcweir //        const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
549cdf0e10cSrcweir 
550cdf0e10cSrcweir 		//!	Ref-Update
551cdf0e10cSrcweir 	}
552cdf0e10cSrcweir 	else if ( rHint.ISA( SfxSimpleHint ) &&
553cdf0e10cSrcweir 			((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
554cdf0e10cSrcweir 	{
555cdf0e10cSrcweir 		pDocShell = NULL;		// ungueltig geworden
556cdf0e10cSrcweir 	}
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 	//	EditSource hat sich selber als Listener angemeldet
559cdf0e10cSrcweir }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir // per getImplementation gerufen:
562cdf0e10cSrcweir 
CreateFieldItem()563cdf0e10cSrcweir SvxFieldItem ScCellFieldObj::CreateFieldItem()
564cdf0e10cSrcweir {
565cdf0e10cSrcweir 	DBG_ASSERT( !pEditSource, "CreateFieldItem mit eingefuegtem Feld" );
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 	SvxURLField aField;
568cdf0e10cSrcweir 	aField.SetFormat(SVXURLFORMAT_APPDEFAULT);
569cdf0e10cSrcweir 	aField.SetURL( aUrl );
570cdf0e10cSrcweir 	aField.SetRepresentation( aRepresentation );
571cdf0e10cSrcweir 	aField.SetTargetFrame( aTarget );
572cdf0e10cSrcweir     return SvxFieldItem( aField, EE_FEATURE_FIELD );
573cdf0e10cSrcweir }
574cdf0e10cSrcweir 
DeleteField()575cdf0e10cSrcweir void ScCellFieldObj::DeleteField()
576cdf0e10cSrcweir {
577cdf0e10cSrcweir 	if (pEditSource)
578cdf0e10cSrcweir 	{
579cdf0e10cSrcweir 		SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
580cdf0e10cSrcweir //		pEditEngine->QuickDelete( aSelection );
581cdf0e10cSrcweir 		pForwarder->QuickInsertText( String(), aSelection );
582cdf0e10cSrcweir 		pEditSource->UpdateData();
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 		aSelection.nEndPara = aSelection.nStartPara;
585cdf0e10cSrcweir 		aSelection.nEndPos  = aSelection.nStartPos;
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 		//! Broadcast, um Selektion in anderen Objekten anzupassen
588cdf0e10cSrcweir 		//!	(auch bei anderen Aktionen)
589cdf0e10cSrcweir 	}
590cdf0e10cSrcweir }
591cdf0e10cSrcweir 
592cdf0e10cSrcweir // XTextField
593cdf0e10cSrcweir 
getPresentation(sal_Bool bShowCommand)594cdf0e10cSrcweir rtl::OUString SAL_CALL ScCellFieldObj::getPresentation( sal_Bool bShowCommand )
595cdf0e10cSrcweir 													throw(uno::RuntimeException)
596cdf0e10cSrcweir {
597cdf0e10cSrcweir 	ScUnoGuard aGuard;
598cdf0e10cSrcweir 	String aRet;
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 	if (pEditSource)
601cdf0e10cSrcweir 	{
602cdf0e10cSrcweir 		//!	Feld-Funktionen muessen an den Forwarder !!!
603cdf0e10cSrcweir 		ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
604cdf0e10cSrcweir 		ScUnoEditEngine aTempEngine(pEditEngine);
605cdf0e10cSrcweir 
606cdf0e10cSrcweir 		//	Typ egal (in Zellen gibts nur URLs)
607cdf0e10cSrcweir 		SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 );
608cdf0e10cSrcweir 		DBG_ASSERT(pField,"getPresentation: Feld nicht gefunden");
609cdf0e10cSrcweir 		if (pField)
610cdf0e10cSrcweir 		{
611cdf0e10cSrcweir 			SvxURLField* pURL = (SvxURLField*)pField;
612cdf0e10cSrcweir 			if (bShowCommand)
613cdf0e10cSrcweir 				aRet = pURL->GetURL();
614cdf0e10cSrcweir 			else
615cdf0e10cSrcweir 				aRet = pURL->GetRepresentation();
616cdf0e10cSrcweir 		}
617cdf0e10cSrcweir 	}
618cdf0e10cSrcweir 
619cdf0e10cSrcweir 	return aRet;
620cdf0e10cSrcweir }
621cdf0e10cSrcweir 
622cdf0e10cSrcweir // XTextContent
623cdf0e10cSrcweir 
attach(const uno::Reference<text::XTextRange> & xTextRange)624cdf0e10cSrcweir void SAL_CALL ScCellFieldObj::attach( const uno::Reference<text::XTextRange>& xTextRange )
625cdf0e10cSrcweir 								throw(lang::IllegalArgumentException, uno::RuntimeException)
626cdf0e10cSrcweir {
627cdf0e10cSrcweir 	ScUnoGuard aGuard;
628cdf0e10cSrcweir 	if (xTextRange.is())
629cdf0e10cSrcweir 	{
630cdf0e10cSrcweir 		uno::Reference<text::XText> xText(xTextRange->getText());
631cdf0e10cSrcweir 		if (xText.is())
632cdf0e10cSrcweir 		{
633cdf0e10cSrcweir 			xText->insertTextContent( xTextRange, this, sal_True );
634cdf0e10cSrcweir 		}
635cdf0e10cSrcweir 	}
636cdf0e10cSrcweir }
637cdf0e10cSrcweir 
getAnchor()638cdf0e10cSrcweir uno::Reference<text::XTextRange> SAL_CALL ScCellFieldObj::getAnchor() throw(uno::RuntimeException)
639cdf0e10cSrcweir {
640cdf0e10cSrcweir 	ScUnoGuard aGuard;
641cdf0e10cSrcweir 	if (pDocShell)
642cdf0e10cSrcweir 		return new ScCellObj( pDocShell, aCellPos );
643cdf0e10cSrcweir 	return NULL;
644cdf0e10cSrcweir }
645cdf0e10cSrcweir 
646cdf0e10cSrcweir // XComponent
647cdf0e10cSrcweir 
dispose()648cdf0e10cSrcweir void SAL_CALL ScCellFieldObj::dispose() throw(uno::RuntimeException)
649cdf0e10cSrcweir {
650cdf0e10cSrcweir 	OComponentHelper::dispose();
651cdf0e10cSrcweir }
652cdf0e10cSrcweir 
addEventListener(const uno::Reference<lang::XEventListener> & xListener)653cdf0e10cSrcweir void SAL_CALL ScCellFieldObj::addEventListener(
654cdf0e10cSrcweir 						const uno::Reference<lang::XEventListener>& xListener )
655cdf0e10cSrcweir 													throw(uno::RuntimeException)
656cdf0e10cSrcweir {
657cdf0e10cSrcweir 	OComponentHelper::addEventListener( xListener );
658cdf0e10cSrcweir }
659cdf0e10cSrcweir 
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)660cdf0e10cSrcweir void SAL_CALL ScCellFieldObj::removeEventListener(
661cdf0e10cSrcweir 						const uno::Reference<lang::XEventListener>& xListener )
662cdf0e10cSrcweir 													throw(uno::RuntimeException)
663cdf0e10cSrcweir {
664cdf0e10cSrcweir 	OComponentHelper::removeEventListener( xListener );
665cdf0e10cSrcweir }
666cdf0e10cSrcweir 
667cdf0e10cSrcweir // XPropertySet
668cdf0e10cSrcweir 
getPropertySetInfo()669cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellFieldObj::getPropertySetInfo()
670cdf0e10cSrcweir 														throw(uno::RuntimeException)
671cdf0e10cSrcweir {
672cdf0e10cSrcweir 	ScUnoGuard aGuard;
673cdf0e10cSrcweir 	static uno::Reference<beans::XPropertySetInfo> aRef = pPropSet->getPropertySetInfo();
674cdf0e10cSrcweir 	return aRef;
675cdf0e10cSrcweir }
676cdf0e10cSrcweir 
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)677cdf0e10cSrcweir void SAL_CALL ScCellFieldObj::setPropertyValue(
678cdf0e10cSrcweir 						const rtl::OUString& aPropertyName, const uno::Any& aValue )
679cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, beans::PropertyVetoException,
680cdf0e10cSrcweir 						lang::IllegalArgumentException, lang::WrappedTargetException,
681cdf0e10cSrcweir 						uno::RuntimeException)
682cdf0e10cSrcweir {
683cdf0e10cSrcweir 	ScUnoGuard aGuard;
684cdf0e10cSrcweir 	String aNameString(aPropertyName);
685cdf0e10cSrcweir 	rtl::OUString aStrVal;
686cdf0e10cSrcweir 	if (pEditSource)
687cdf0e10cSrcweir 	{
688cdf0e10cSrcweir 		//!	Feld-Funktionen muessen an den Forwarder !!!
689cdf0e10cSrcweir 		ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
690cdf0e10cSrcweir 		ScUnoEditEngine aTempEngine(pEditEngine);
691cdf0e10cSrcweir 
692cdf0e10cSrcweir 		//	Typ egal (in Zellen gibts nur URLs)
693cdf0e10cSrcweir 		SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 );
694cdf0e10cSrcweir 		DBG_ASSERT(pField,"setPropertyValue: Feld nicht gefunden");
695cdf0e10cSrcweir 		if (pField)
696cdf0e10cSrcweir 		{
697cdf0e10cSrcweir 			SvxURLField* pURL = (SvxURLField*)pField;	// ist eine Kopie in der ScUnoEditEngine
698cdf0e10cSrcweir 
699cdf0e10cSrcweir 			sal_Bool bOk = sal_True;
700cdf0e10cSrcweir 			if ( aNameString.EqualsAscii( SC_UNONAME_URL ) )
701cdf0e10cSrcweir 			{
702cdf0e10cSrcweir 				if (aValue >>= aStrVal)
703cdf0e10cSrcweir 					pURL->SetURL( aStrVal );
704cdf0e10cSrcweir 			}
705cdf0e10cSrcweir 			else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) )
706cdf0e10cSrcweir 			{
707cdf0e10cSrcweir 				if (aValue >>= aStrVal)
708cdf0e10cSrcweir 					pURL->SetRepresentation( aStrVal );
709cdf0e10cSrcweir 			}
710cdf0e10cSrcweir 			else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) )
711cdf0e10cSrcweir 			{
712cdf0e10cSrcweir 				if (aValue >>= aStrVal)
713cdf0e10cSrcweir 					pURL->SetTargetFrame( aStrVal );
714cdf0e10cSrcweir 			}
715cdf0e10cSrcweir 			else
716cdf0e10cSrcweir 				bOk = sal_False;
717cdf0e10cSrcweir 
718cdf0e10cSrcweir 			if (bOk)
719cdf0e10cSrcweir 			{
720cdf0e10cSrcweir                 pEditEngine->QuickInsertField( SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection );
721cdf0e10cSrcweir 				pEditSource->UpdateData();
722cdf0e10cSrcweir 			}
723cdf0e10cSrcweir 		}
724cdf0e10cSrcweir 	}
725cdf0e10cSrcweir 	else		// noch nicht eingefuegt
726cdf0e10cSrcweir 	{
727cdf0e10cSrcweir 		if ( aNameString.EqualsAscii( SC_UNONAME_URL ) )
728cdf0e10cSrcweir 		{
729cdf0e10cSrcweir 			if (aValue >>= aStrVal)
730cdf0e10cSrcweir 				aUrl = String( aStrVal );
731cdf0e10cSrcweir 		}
732cdf0e10cSrcweir 		else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) )
733cdf0e10cSrcweir 		{
734cdf0e10cSrcweir 			if (aValue >>= aStrVal)
735cdf0e10cSrcweir 				aRepresentation = String( aStrVal );
736cdf0e10cSrcweir 		}
737cdf0e10cSrcweir 		else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) )
738cdf0e10cSrcweir 		{
739cdf0e10cSrcweir 			if (aValue >>= aStrVal)
740cdf0e10cSrcweir 				aTarget = String( aStrVal );
741cdf0e10cSrcweir 		}
742cdf0e10cSrcweir 	}
743cdf0e10cSrcweir }
744cdf0e10cSrcweir 
getPropertyValue(const rtl::OUString & aPropertyName)745cdf0e10cSrcweir uno::Any SAL_CALL ScCellFieldObj::getPropertyValue( const rtl::OUString& aPropertyName )
746cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, lang::WrappedTargetException,
747cdf0e10cSrcweir 						uno::RuntimeException)
748cdf0e10cSrcweir {
749cdf0e10cSrcweir 	ScUnoGuard aGuard;
750cdf0e10cSrcweir 	uno::Any aRet;
751cdf0e10cSrcweir 	String aNameString(aPropertyName);
752cdf0e10cSrcweir 
753cdf0e10cSrcweir 	// anchor type is always "as character", text wrap always "none"
754cdf0e10cSrcweir 
755cdf0e10cSrcweir 	if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPE ) )
756cdf0e10cSrcweir 		aRet <<= text::TextContentAnchorType_AS_CHARACTER;
757cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPES ) )
758cdf0e10cSrcweir 	{
759cdf0e10cSrcweir 		uno::Sequence<text::TextContentAnchorType> aSeq(1);
760cdf0e10cSrcweir 		aSeq[0] = text::TextContentAnchorType_AS_CHARACTER;
761cdf0e10cSrcweir 		aRet <<= aSeq;
762cdf0e10cSrcweir 	}
763cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_TEXTWRAP ) )
764cdf0e10cSrcweir 		aRet <<= text::WrapTextMode_NONE;
765cdf0e10cSrcweir 	else if (pEditSource)
766cdf0e10cSrcweir 	{
767cdf0e10cSrcweir 		//!	Feld-Funktionen muessen an den Forwarder !!!
768cdf0e10cSrcweir 		ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine();
769cdf0e10cSrcweir 		ScUnoEditEngine aTempEngine(pEditEngine);
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 		//	Typ egal (in Zellen gibts nur URLs)
772cdf0e10cSrcweir 		SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 );
773cdf0e10cSrcweir 		DBG_ASSERT(pField,"getPropertyValue: Feld nicht gefunden");
774cdf0e10cSrcweir 		if (pField)
775cdf0e10cSrcweir 		{
776cdf0e10cSrcweir 			SvxURLField* pURL = (SvxURLField*)pField;
777cdf0e10cSrcweir 
778cdf0e10cSrcweir 			if ( aNameString.EqualsAscii( SC_UNONAME_URL ) )
779cdf0e10cSrcweir 				aRet <<= rtl::OUString( pURL->GetURL() );
780cdf0e10cSrcweir 			else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) )
781cdf0e10cSrcweir 				aRet <<= rtl::OUString( pURL->GetRepresentation() );
782cdf0e10cSrcweir 			else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) )
783cdf0e10cSrcweir 				aRet <<= rtl::OUString( pURL->GetTargetFrame() );
784cdf0e10cSrcweir 		}
785cdf0e10cSrcweir 	}
786cdf0e10cSrcweir 	else		// noch nicht eingefuegt
787cdf0e10cSrcweir 	{
788cdf0e10cSrcweir 		if ( aNameString.EqualsAscii( SC_UNONAME_URL ) )
789cdf0e10cSrcweir 			aRet <<= rtl::OUString( aUrl );
790cdf0e10cSrcweir 		else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) )
791cdf0e10cSrcweir 			aRet <<= rtl::OUString( aRepresentation );
792cdf0e10cSrcweir 		else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) )
793cdf0e10cSrcweir 			aRet <<= rtl::OUString( aTarget );
794cdf0e10cSrcweir 	}
795cdf0e10cSrcweir 	return aRet;
796cdf0e10cSrcweir }
797cdf0e10cSrcweir 
SC_IMPL_DUMMY_PROPERTY_LISTENER(ScCellFieldObj)798cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScCellFieldObj )
799cdf0e10cSrcweir 
800cdf0e10cSrcweir // XUnoTunnel
801cdf0e10cSrcweir 
802cdf0e10cSrcweir sal_Int64 SAL_CALL ScCellFieldObj::getSomething(
803cdf0e10cSrcweir 				const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
804cdf0e10cSrcweir {
805cdf0e10cSrcweir 	if ( rId.getLength() == 16 &&
806cdf0e10cSrcweir           0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
807cdf0e10cSrcweir 									rId.getConstArray(), 16 ) )
808cdf0e10cSrcweir 	{
809cdf0e10cSrcweir         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
810cdf0e10cSrcweir 	}
811cdf0e10cSrcweir 	return 0;
812cdf0e10cSrcweir }
813cdf0e10cSrcweir 
814cdf0e10cSrcweir // static
getUnoTunnelId()815cdf0e10cSrcweir const uno::Sequence<sal_Int8>& ScCellFieldObj::getUnoTunnelId()
816cdf0e10cSrcweir {
817cdf0e10cSrcweir 	static uno::Sequence<sal_Int8> * pSeq = 0;
818cdf0e10cSrcweir 	if( !pSeq )
819cdf0e10cSrcweir 	{
820cdf0e10cSrcweir 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
821cdf0e10cSrcweir 		if( !pSeq )
822cdf0e10cSrcweir 		{
823cdf0e10cSrcweir 			static uno::Sequence< sal_Int8 > aSeq( 16 );
824cdf0e10cSrcweir 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
825cdf0e10cSrcweir 			pSeq = &aSeq;
826cdf0e10cSrcweir 		}
827cdf0e10cSrcweir 	}
828cdf0e10cSrcweir 	return *pSeq;
829cdf0e10cSrcweir }
830cdf0e10cSrcweir 
831cdf0e10cSrcweir // static
getImplementation(const uno::Reference<text::XTextContent> xObj)832cdf0e10cSrcweir ScCellFieldObj* ScCellFieldObj::getImplementation(
833cdf0e10cSrcweir 								const uno::Reference<text::XTextContent> xObj )
834cdf0e10cSrcweir {
835cdf0e10cSrcweir 	ScCellFieldObj* pRet = NULL;
836cdf0e10cSrcweir 	uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
837cdf0e10cSrcweir 	if (xUT.is())
838cdf0e10cSrcweir         pRet = reinterpret_cast<ScCellFieldObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
839cdf0e10cSrcweir 	return pRet;
840cdf0e10cSrcweir }
841cdf0e10cSrcweir 
842cdf0e10cSrcweir // XServiceInfo
843cdf0e10cSrcweir 
getImplementationName()844cdf0e10cSrcweir rtl::OUString SAL_CALL ScCellFieldObj::getImplementationName() throw(uno::RuntimeException)
845cdf0e10cSrcweir {
846cdf0e10cSrcweir 	return rtl::OUString::createFromAscii( "ScCellFieldObj" );
847cdf0e10cSrcweir }
848cdf0e10cSrcweir 
supportsService(const rtl::OUString & rServiceName)849cdf0e10cSrcweir sal_Bool SAL_CALL ScCellFieldObj::supportsService( const rtl::OUString& rServiceName )
850cdf0e10cSrcweir 													throw(uno::RuntimeException)
851cdf0e10cSrcweir {
852cdf0e10cSrcweir 	String aServiceStr( rServiceName );
853cdf0e10cSrcweir 	return aServiceStr.EqualsAscii( SCTEXTFIELD_SERVICE ) ||
854cdf0e10cSrcweir 		   aServiceStr.EqualsAscii( SCTEXTCONTENT_SERVICE );
855cdf0e10cSrcweir }
856cdf0e10cSrcweir 
getSupportedServiceNames()857cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScCellFieldObj::getSupportedServiceNames()
858cdf0e10cSrcweir 													throw(uno::RuntimeException)
859cdf0e10cSrcweir {
860cdf0e10cSrcweir 	uno::Sequence<rtl::OUString> aRet(2);
861cdf0e10cSrcweir 	rtl::OUString* pArray = aRet.getArray();
862cdf0e10cSrcweir 	pArray[0] = rtl::OUString::createFromAscii( SCTEXTFIELD_SERVICE );
863cdf0e10cSrcweir 	pArray[1] = rtl::OUString::createFromAscii( SCTEXTCONTENT_SERVICE );
864cdf0e10cSrcweir 	return aRet;
865cdf0e10cSrcweir }
866cdf0e10cSrcweir 
867cdf0e10cSrcweir //------------------------------------------------------------------------
868cdf0e10cSrcweir 
ScHeaderFieldsObj(ScHeaderFooterContentObj * pContent,sal_uInt16 nP,sal_uInt16 nT)869cdf0e10cSrcweir ScHeaderFieldsObj::ScHeaderFieldsObj(ScHeaderFooterContentObj* pContent, sal_uInt16 nP, sal_uInt16 nT) :
870cdf0e10cSrcweir 	pContentObj( pContent ),
871cdf0e10cSrcweir 	nPart( nP ),
872cdf0e10cSrcweir 	nType( nT ),
873cdf0e10cSrcweir     mpRefreshListeners( NULL )
874cdf0e10cSrcweir {
875cdf0e10cSrcweir 	DBG_ASSERT( pContentObj, "ScHeaderFieldsObj ohne Objekt?" );
876cdf0e10cSrcweir 
877cdf0e10cSrcweir 	if (pContentObj)
878cdf0e10cSrcweir 	{
879cdf0e10cSrcweir 		pContentObj->acquire();		// darf nicht wegkommen
880cdf0e10cSrcweir 		pEditSource = new ScHeaderFooterEditSource( pContentObj, nPart );
881cdf0e10cSrcweir 	}
882cdf0e10cSrcweir 	else
883cdf0e10cSrcweir 		pEditSource = NULL;
884cdf0e10cSrcweir }
885cdf0e10cSrcweir 
~ScHeaderFieldsObj()886cdf0e10cSrcweir ScHeaderFieldsObj::~ScHeaderFieldsObj()
887cdf0e10cSrcweir {
888cdf0e10cSrcweir     delete pEditSource;
889cdf0e10cSrcweir 
890cdf0e10cSrcweir 	if (pContentObj)
891cdf0e10cSrcweir 		pContentObj->release();
892cdf0e10cSrcweir 
893cdf0e10cSrcweir 	// increment refcount to prevent double call off dtor
894cdf0e10cSrcweir 	osl_incrementInterlockedCount( &m_refCount );
895cdf0e10cSrcweir 
896cdf0e10cSrcweir     if (mpRefreshListeners)
897cdf0e10cSrcweir 	{
898cdf0e10cSrcweir 		lang::EventObject aEvent;
899cdf0e10cSrcweir 		aEvent.Source = static_cast<cppu::OWeakObject*>(this);
900cdf0e10cSrcweir 		if (mpRefreshListeners)
901cdf0e10cSrcweir 		{
902cdf0e10cSrcweir 			mpRefreshListeners->disposeAndClear(aEvent);
903cdf0e10cSrcweir 			DELETEZ( mpRefreshListeners );
904cdf0e10cSrcweir 		}
905cdf0e10cSrcweir 	}
906cdf0e10cSrcweir }
907cdf0e10cSrcweir 
908cdf0e10cSrcweir // XIndexAccess (via XTextFields)
909cdf0e10cSrcweir 
GetObjectByIndex_Impl(sal_Int32 Index) const910cdf0e10cSrcweir ScHeaderFieldObj* ScHeaderFieldsObj::GetObjectByIndex_Impl(sal_Int32 Index) const
911cdf0e10cSrcweir {
912cdf0e10cSrcweir 	//!	Feld-Funktionen muessen an den Forwarder !!!
913cdf0e10cSrcweir 	ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine();
914cdf0e10cSrcweir 	ScUnoEditEngine aTempEngine(pEditEngine);
915cdf0e10cSrcweir 
916cdf0e10cSrcweir 	TypeId aTypeId = NULL;
917cdf0e10cSrcweir 	switch (nType)
918cdf0e10cSrcweir 	{
919cdf0e10cSrcweir 		case SC_SERVICE_PAGEFIELD:	aTypeId = TYPE(SvxPageField);	 break;
920cdf0e10cSrcweir 		case SC_SERVICE_PAGESFIELD:	aTypeId = TYPE(SvxPagesField);	 break;
921cdf0e10cSrcweir 		case SC_SERVICE_DATEFIELD:	aTypeId = TYPE(SvxDateField);	 break;
922cdf0e10cSrcweir 		case SC_SERVICE_TIMEFIELD:	aTypeId = TYPE(SvxTimeField);	 break;
923cdf0e10cSrcweir 		case SC_SERVICE_TITLEFIELD:	aTypeId = TYPE(SvxFileField);	 break;
924cdf0e10cSrcweir 		case SC_SERVICE_FILEFIELD:	aTypeId = TYPE(SvxExtFileField); break;
925cdf0e10cSrcweir 		case SC_SERVICE_SHEETFIELD:	aTypeId = TYPE(SvxTableField);	 break;
926cdf0e10cSrcweir 		// bei SC_SERVICE_INVALID bleibt TypeId Null
927cdf0e10cSrcweir 	}
928cdf0e10cSrcweir 	SvxFieldData* pData = aTempEngine.FindByIndex( (sal_uInt16)Index, aTypeId );
929cdf0e10cSrcweir 	if ( pData )
930cdf0e10cSrcweir 	{
931cdf0e10cSrcweir 		sal_uInt16 nPar = aTempEngine.GetFieldPar();
932cdf0e10cSrcweir 		xub_StrLen nPos = aTempEngine.GetFieldPos();
933cdf0e10cSrcweir 
934cdf0e10cSrcweir 		sal_uInt16 nFieldType = nType;
935cdf0e10cSrcweir 		if ( nFieldType == SC_SERVICE_INVALID )
936cdf0e10cSrcweir 		{
937cdf0e10cSrcweir 			if ( pData->ISA( SvxPageField ) )		  nFieldType = SC_SERVICE_PAGEFIELD;
938cdf0e10cSrcweir 			else if ( pData->ISA( SvxPagesField ) )	  nFieldType = SC_SERVICE_PAGESFIELD;
939cdf0e10cSrcweir 			else if ( pData->ISA( SvxDateField ) )	  nFieldType = SC_SERVICE_DATEFIELD;
940cdf0e10cSrcweir 			else if ( pData->ISA( SvxTimeField ) )	  nFieldType = SC_SERVICE_TIMEFIELD;
941cdf0e10cSrcweir 			else if ( pData->ISA( SvxFileField ) )	  nFieldType = SC_SERVICE_TITLEFIELD;
942cdf0e10cSrcweir 			else if ( pData->ISA( SvxExtFileField ) ) nFieldType = SC_SERVICE_FILEFIELD;
943cdf0e10cSrcweir 			else if ( pData->ISA( SvxTableField ) )	  nFieldType = SC_SERVICE_SHEETFIELD;
944cdf0e10cSrcweir 		}
945cdf0e10cSrcweir 
946cdf0e10cSrcweir 		ESelection aSelection( nPar, nPos, nPar, nPos+1 );		// Field is 1 character
947cdf0e10cSrcweir 		return new ScHeaderFieldObj( pContentObj, nPart, nFieldType, aSelection );
948cdf0e10cSrcweir 	}
949cdf0e10cSrcweir 	return NULL;
950cdf0e10cSrcweir }
951cdf0e10cSrcweir 
getCount()952cdf0e10cSrcweir sal_Int32 SAL_CALL ScHeaderFieldsObj::getCount() throw(uno::RuntimeException)
953cdf0e10cSrcweir {
954cdf0e10cSrcweir 	ScUnoGuard aGuard;
955cdf0e10cSrcweir 
956cdf0e10cSrcweir 	//!	Feld-Funktionen muessen an den Forwarder !!!
957cdf0e10cSrcweir 	ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine();
958cdf0e10cSrcweir 	ScUnoEditEngine aTempEngine(pEditEngine);
959cdf0e10cSrcweir 
960cdf0e10cSrcweir 	TypeId aTypeId = NULL;
961cdf0e10cSrcweir 	switch (nType)
962cdf0e10cSrcweir 	{
963cdf0e10cSrcweir 		case SC_SERVICE_PAGEFIELD:	aTypeId = TYPE(SvxPageField);	 break;
964cdf0e10cSrcweir 		case SC_SERVICE_PAGESFIELD:	aTypeId = TYPE(SvxPagesField);	 break;
965cdf0e10cSrcweir 		case SC_SERVICE_DATEFIELD:	aTypeId = TYPE(SvxDateField);	 break;
966cdf0e10cSrcweir 		case SC_SERVICE_TIMEFIELD:	aTypeId = TYPE(SvxTimeField);	 break;
967cdf0e10cSrcweir 		case SC_SERVICE_TITLEFIELD:	aTypeId = TYPE(SvxFileField);	 break;
968cdf0e10cSrcweir 		case SC_SERVICE_FILEFIELD:	aTypeId = TYPE(SvxExtFileField); break;
969cdf0e10cSrcweir 		case SC_SERVICE_SHEETFIELD:	aTypeId = TYPE(SvxTableField);	 break;
970cdf0e10cSrcweir 	}
971cdf0e10cSrcweir 	return aTempEngine.CountFields(aTypeId);		// Felder zaehlen
972cdf0e10cSrcweir }
973cdf0e10cSrcweir 
getByIndex(sal_Int32 nIndex)974cdf0e10cSrcweir uno::Any SAL_CALL ScHeaderFieldsObj::getByIndex( sal_Int32 nIndex )
975cdf0e10cSrcweir 							throw(lang::IndexOutOfBoundsException,
976cdf0e10cSrcweir 									lang::WrappedTargetException, uno::RuntimeException)
977cdf0e10cSrcweir {
978cdf0e10cSrcweir 	ScUnoGuard aGuard;
979cdf0e10cSrcweir 	uno::Reference<text::XTextField> xField(GetObjectByIndex_Impl(nIndex));
980cdf0e10cSrcweir 	if (xField.is())
981cdf0e10cSrcweir         return uno::makeAny(xField);
982cdf0e10cSrcweir 	else
983cdf0e10cSrcweir 		throw lang::IndexOutOfBoundsException();
984cdf0e10cSrcweir //    return uno::Any();
985cdf0e10cSrcweir }
986cdf0e10cSrcweir 
getElementType()987cdf0e10cSrcweir uno::Type SAL_CALL ScHeaderFieldsObj::getElementType() throw(uno::RuntimeException)
988cdf0e10cSrcweir {
989cdf0e10cSrcweir 	ScUnoGuard aGuard;
990cdf0e10cSrcweir 	return getCppuType((uno::Reference<text::XTextField>*)0);
991cdf0e10cSrcweir }
992cdf0e10cSrcweir 
hasElements()993cdf0e10cSrcweir sal_Bool SAL_CALL ScHeaderFieldsObj::hasElements() throw(uno::RuntimeException)
994cdf0e10cSrcweir {
995cdf0e10cSrcweir 	ScUnoGuard aGuard;
996cdf0e10cSrcweir 	return ( getCount() != 0 );
997cdf0e10cSrcweir }
998cdf0e10cSrcweir 
createEnumeration()999cdf0e10cSrcweir uno::Reference<container::XEnumeration> SAL_CALL ScHeaderFieldsObj::createEnumeration()
1000cdf0e10cSrcweir 													throw(uno::RuntimeException)
1001cdf0e10cSrcweir {
1002cdf0e10cSrcweir 	ScUnoGuard aGuard;
1003cdf0e10cSrcweir     return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFieldEnumeration")));
1004cdf0e10cSrcweir }
1005cdf0e10cSrcweir 
addContainerListener(const uno::Reference<container::XContainerListener> &)1006cdf0e10cSrcweir void SAL_CALL ScHeaderFieldsObj::addContainerListener(
1007cdf0e10cSrcweir                                 const uno::Reference<container::XContainerListener>& /* xListener */ )
1008cdf0e10cSrcweir 									throw(uno::RuntimeException)
1009cdf0e10cSrcweir {
1010cdf0e10cSrcweir 	DBG_ERROR("not implemented");
1011cdf0e10cSrcweir }
1012cdf0e10cSrcweir 
removeContainerListener(const uno::Reference<container::XContainerListener> &)1013cdf0e10cSrcweir void SAL_CALL ScHeaderFieldsObj::removeContainerListener(
1014cdf0e10cSrcweir                                 const uno::Reference<container::XContainerListener>& /* xListener */ )
1015cdf0e10cSrcweir 									throw(uno::RuntimeException)
1016cdf0e10cSrcweir {
1017cdf0e10cSrcweir 	DBG_ERROR("not implemented");
1018cdf0e10cSrcweir }
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir // XRefreshable
refresh()1021cdf0e10cSrcweir void SAL_CALL ScHeaderFieldsObj::refresh(  )
1022cdf0e10cSrcweir                                     throw (uno::RuntimeException)
1023cdf0e10cSrcweir {
1024cdf0e10cSrcweir 	if (mpRefreshListeners)
1025cdf0e10cSrcweir 	{
1026cdf0e10cSrcweir     	//  Call all listeners.
1027cdf0e10cSrcweir 		uno::Sequence< uno::Reference< uno::XInterface > > aListeners(mpRefreshListeners->getElements());
1028cdf0e10cSrcweir 		sal_uInt32 nLength(aListeners.getLength());
1029cdf0e10cSrcweir 		if (nLength)
1030cdf0e10cSrcweir 		{
1031cdf0e10cSrcweir 			const uno::Reference< uno::XInterface >* pInterfaces = aListeners.getConstArray();
1032cdf0e10cSrcweir 			if (pInterfaces)
1033cdf0e10cSrcweir 			{
1034cdf0e10cSrcweir                 lang::EventObject aEvent;
1035cdf0e10cSrcweir                 aEvent.Source.set(uno::Reference< util::XRefreshable >(const_cast<ScHeaderFieldsObj*>(this)));
1036cdf0e10cSrcweir 				sal_uInt32 i(0);
1037cdf0e10cSrcweir 				while (i < nLength)
1038cdf0e10cSrcweir 				{
1039cdf0e10cSrcweir 					try
1040cdf0e10cSrcweir 					{
1041cdf0e10cSrcweir 						while(i < nLength)
1042cdf0e10cSrcweir 						{
1043cdf0e10cSrcweir 							static_cast< util::XRefreshListener* >(pInterfaces->get())->refreshed(aEvent);
1044cdf0e10cSrcweir 							++pInterfaces;
1045cdf0e10cSrcweir 							++i;
1046cdf0e10cSrcweir 						}
1047cdf0e10cSrcweir 					}
1048cdf0e10cSrcweir 					catch(uno::RuntimeException&)
1049cdf0e10cSrcweir 					{
1050cdf0e10cSrcweir //						DBG_ERROR("a object is gone without to remove from Broadcaster");
1051cdf0e10cSrcweir 						++pInterfaces;
1052cdf0e10cSrcweir 						++i;
1053cdf0e10cSrcweir 					}
1054cdf0e10cSrcweir 				}
1055cdf0e10cSrcweir 			}
1056cdf0e10cSrcweir 		}
1057cdf0e10cSrcweir 	}
1058cdf0e10cSrcweir }
1059cdf0e10cSrcweir 
addRefreshListener(const uno::Reference<util::XRefreshListener> & xListener)1060cdf0e10cSrcweir void SAL_CALL ScHeaderFieldsObj::addRefreshListener( const uno::Reference< util::XRefreshListener >& xListener )
1061cdf0e10cSrcweir                                     throw (uno::RuntimeException)
1062cdf0e10cSrcweir {
1063cdf0e10cSrcweir 	if (xListener.is())
1064cdf0e10cSrcweir     {
1065cdf0e10cSrcweir 		ScUnoGuard aGuard;
1066cdf0e10cSrcweir 		if (!mpRefreshListeners)
1067cdf0e10cSrcweir 			mpRefreshListeners = new cppu::OInterfaceContainerHelper(aMutex);
1068cdf0e10cSrcweir 		mpRefreshListeners->addInterface(xListener);
1069cdf0e10cSrcweir     }
1070cdf0e10cSrcweir }
1071cdf0e10cSrcweir 
removeRefreshListener(const uno::Reference<util::XRefreshListener> & xListener)1072cdf0e10cSrcweir void SAL_CALL ScHeaderFieldsObj::removeRefreshListener( const uno::Reference<util::XRefreshListener >& xListener )
1073cdf0e10cSrcweir                                     throw (uno::RuntimeException)
1074cdf0e10cSrcweir {
1075cdf0e10cSrcweir 	if (xListener.is())
1076cdf0e10cSrcweir 	{
1077cdf0e10cSrcweir 		ScUnoGuard aGuard;
1078cdf0e10cSrcweir 		if (mpRefreshListeners)
1079cdf0e10cSrcweir 			mpRefreshListeners->removeInterface(xListener);
1080cdf0e10cSrcweir 	}
1081cdf0e10cSrcweir }
1082cdf0e10cSrcweir 
1083cdf0e10cSrcweir //------------------------------------------------------------------------
1084cdf0e10cSrcweir 
lcl_UnoToSvxFileFormat(sal_Int16 nUnoValue)1085cdf0e10cSrcweir SvxFileFormat lcl_UnoToSvxFileFormat( sal_Int16 nUnoValue )
1086cdf0e10cSrcweir {
1087cdf0e10cSrcweir 	switch( nUnoValue )
1088cdf0e10cSrcweir 	{
1089cdf0e10cSrcweir 		case text::FilenameDisplayFormat::FULL:	return SVXFILEFORMAT_FULLPATH;
1090cdf0e10cSrcweir 		case text::FilenameDisplayFormat::PATH:	return SVXFILEFORMAT_PATH;
1091cdf0e10cSrcweir 		case text::FilenameDisplayFormat::NAME:	return SVXFILEFORMAT_NAME;
1092cdf0e10cSrcweir //		case text::FilenameDisplayFormat::NAME_AND_EXT:
1093cdf0e10cSrcweir 		default:
1094cdf0e10cSrcweir 			return SVXFILEFORMAT_NAME_EXT;
1095cdf0e10cSrcweir 	}
1096cdf0e10cSrcweir }
1097cdf0e10cSrcweir 
lcl_SvxToUnoFileFormat(SvxFileFormat nSvxValue)1098cdf0e10cSrcweir sal_Int16 lcl_SvxToUnoFileFormat( SvxFileFormat nSvxValue )
1099cdf0e10cSrcweir {
1100cdf0e10cSrcweir 	switch( nSvxValue )
1101cdf0e10cSrcweir 	{
1102cdf0e10cSrcweir 		case SVXFILEFORMAT_NAME_EXT:	return text::FilenameDisplayFormat::NAME_AND_EXT;
1103cdf0e10cSrcweir 		case SVXFILEFORMAT_FULLPATH:	return text::FilenameDisplayFormat::FULL;
1104cdf0e10cSrcweir 		case SVXFILEFORMAT_PATH:		return text::FilenameDisplayFormat::PATH;
1105cdf0e10cSrcweir //		case SVXFILEFORMAT_NAME:
1106cdf0e10cSrcweir 		default:
1107cdf0e10cSrcweir 			return text::FilenameDisplayFormat::NAME;
1108cdf0e10cSrcweir 	}
1109cdf0e10cSrcweir }
1110cdf0e10cSrcweir 
1111cdf0e10cSrcweir 
1112cdf0e10cSrcweir //	Default-ctor wird fuer SMART_REFLECTION_IMPLEMENTATION gebraucht
1113cdf0e10cSrcweir //UNUSED2008-05  ScHeaderFieldObj::ScHeaderFieldObj() :
1114cdf0e10cSrcweir //UNUSED2008-05      OComponentHelper( getMutex() ),
1115cdf0e10cSrcweir //UNUSED2008-05      aPropSet( lcl_GetHeaderFieldPropertyMap() ),
1116cdf0e10cSrcweir //UNUSED2008-05      pContentObj( NULL ),
1117cdf0e10cSrcweir //UNUSED2008-05      nPart( 0 ),
1118cdf0e10cSrcweir //UNUSED2008-05      nType( 0 ),
1119cdf0e10cSrcweir //UNUSED2008-05      nFileFormat( SVXFILEFORMAT_NAME_EXT )
1120cdf0e10cSrcweir //UNUSED2008-05  {
1121cdf0e10cSrcweir //UNUSED2008-05      pEditSource = NULL;
1122cdf0e10cSrcweir //UNUSED2008-05  }
1123cdf0e10cSrcweir 
ScHeaderFieldObj(ScHeaderFooterContentObj * pContent,sal_uInt16 nP,sal_uInt16 nT,const ESelection & rSel)1124cdf0e10cSrcweir ScHeaderFieldObj::ScHeaderFieldObj(ScHeaderFooterContentObj* pContent, sal_uInt16 nP,
1125cdf0e10cSrcweir 											sal_uInt16 nT, const ESelection& rSel) :
1126cdf0e10cSrcweir 	OComponentHelper( getMutex() ),
1127cdf0e10cSrcweir 	pPropSet( (nT == SC_SERVICE_FILEFIELD) ? lcl_GetFileFieldPropertySet() : lcl_GetHeaderFieldPropertySet() ),
1128cdf0e10cSrcweir 	pContentObj( pContent ),
1129cdf0e10cSrcweir 	nPart( nP ),
1130cdf0e10cSrcweir 	nType( nT ),
1131cdf0e10cSrcweir 	aSelection( rSel ),
1132cdf0e10cSrcweir 	nFileFormat( SVXFILEFORMAT_NAME_EXT )
1133cdf0e10cSrcweir {
1134cdf0e10cSrcweir 	//	pContent ist Null, wenn per ServiceProvider erzeugt
1135cdf0e10cSrcweir 
1136cdf0e10cSrcweir 	if (pContentObj)
1137cdf0e10cSrcweir 	{
1138cdf0e10cSrcweir 		pContentObj->acquire();		// darf nicht wegkommen
1139cdf0e10cSrcweir 		pEditSource = new ScHeaderFooterEditSource( pContentObj, nPart );
1140cdf0e10cSrcweir 	}
1141cdf0e10cSrcweir 	else
1142cdf0e10cSrcweir 		pEditSource = NULL;
1143cdf0e10cSrcweir }
1144cdf0e10cSrcweir 
queryAggregation(const uno::Type & rType)1145cdf0e10cSrcweir uno::Any SAL_CALL ScHeaderFieldObj::queryAggregation( const uno::Type& rType )
1146cdf0e10cSrcweir 												throw(uno::RuntimeException)
1147cdf0e10cSrcweir {
1148cdf0e10cSrcweir 	SC_QUERYINTERFACE( text::XTextField )
1149cdf0e10cSrcweir 	SC_QUERYINTERFACE( text::XTextContent )			// parent of XTextField
1150cdf0e10cSrcweir 	SC_QUERYINTERFACE( beans::XPropertySet )
1151cdf0e10cSrcweir 	SC_QUERYINTERFACE( lang::XUnoTunnel )
1152cdf0e10cSrcweir 	SC_QUERYINTERFACE( lang::XServiceInfo )
1153cdf0e10cSrcweir 
1154cdf0e10cSrcweir 	return OComponentHelper::queryAggregation( rType );		// XComponent
1155cdf0e10cSrcweir }
1156cdf0e10cSrcweir 
getTypes()1157cdf0e10cSrcweir uno::Sequence<uno::Type> SAL_CALL ScHeaderFieldObj::getTypes() throw(uno::RuntimeException)
1158cdf0e10cSrcweir {
1159cdf0e10cSrcweir 	static uno::Sequence<uno::Type> aTypes;
1160cdf0e10cSrcweir 	if ( aTypes.getLength() == 0 )
1161cdf0e10cSrcweir 	{
1162cdf0e10cSrcweir 		uno::Sequence<uno::Type> aParentTypes(OComponentHelper::getTypes());
1163cdf0e10cSrcweir 		long nParentLen = aParentTypes.getLength();
1164cdf0e10cSrcweir 		const uno::Type* pParentPtr = aParentTypes.getConstArray();
1165cdf0e10cSrcweir 
1166cdf0e10cSrcweir 		aTypes.realloc( nParentLen + 4 );
1167cdf0e10cSrcweir 		uno::Type* pPtr = aTypes.getArray();
1168cdf0e10cSrcweir 		pPtr[nParentLen + 0] = getCppuType((const uno::Reference<text::XTextField>*)0);
1169cdf0e10cSrcweir 		pPtr[nParentLen + 1] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
1170cdf0e10cSrcweir 		pPtr[nParentLen + 2] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0);
1171cdf0e10cSrcweir 		pPtr[nParentLen + 3] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir 		for (long i=0; i<nParentLen; i++)
1174cdf0e10cSrcweir 			pPtr[i] = pParentPtr[i];				// parent types first
1175cdf0e10cSrcweir 	}
1176cdf0e10cSrcweir 	return aTypes;
1177cdf0e10cSrcweir }
1178cdf0e10cSrcweir 
getImplementationId()1179cdf0e10cSrcweir uno::Sequence<sal_Int8> SAL_CALL ScHeaderFieldObj::getImplementationId()
1180cdf0e10cSrcweir 													throw(uno::RuntimeException)
1181cdf0e10cSrcweir {
1182cdf0e10cSrcweir 	static uno::Sequence< sal_Int8 > aId;
1183cdf0e10cSrcweir 	if( aId.getLength() == 0 )
1184cdf0e10cSrcweir 	{
1185cdf0e10cSrcweir 		aId.realloc( 16 );
1186cdf0e10cSrcweir 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
1187cdf0e10cSrcweir 	}
1188cdf0e10cSrcweir 	return aId;
1189cdf0e10cSrcweir }
1190cdf0e10cSrcweir 
queryInterface(const uno::Type & rType)1191cdf0e10cSrcweir uno::Any SAL_CALL ScHeaderFieldObj::queryInterface( const uno::Type& rType )
1192cdf0e10cSrcweir 												throw(uno::RuntimeException)
1193cdf0e10cSrcweir {
1194cdf0e10cSrcweir 	return OComponentHelper::queryInterface( rType );
1195cdf0e10cSrcweir }
1196cdf0e10cSrcweir 
acquire()1197cdf0e10cSrcweir void SAL_CALL ScHeaderFieldObj::acquire() throw()
1198cdf0e10cSrcweir {
1199cdf0e10cSrcweir 	OComponentHelper::acquire();
1200cdf0e10cSrcweir }
1201cdf0e10cSrcweir 
release()1202cdf0e10cSrcweir void SAL_CALL ScHeaderFieldObj::release() throw()
1203cdf0e10cSrcweir {
1204cdf0e10cSrcweir 	OComponentHelper::release();
1205cdf0e10cSrcweir }
1206cdf0e10cSrcweir 
InitDoc(ScHeaderFooterContentObj * pContent,sal_uInt16 nP,const ESelection & rSel)1207cdf0e10cSrcweir void ScHeaderFieldObj::InitDoc( ScHeaderFooterContentObj* pContent, sal_uInt16 nP,
1208cdf0e10cSrcweir 										const ESelection& rSel )
1209cdf0e10cSrcweir {
1210cdf0e10cSrcweir 	if ( pContent && !pEditSource )
1211cdf0e10cSrcweir 	{
1212cdf0e10cSrcweir 		DBG_ASSERT( !pContentObj, "ContentObj, aber kein EditSource?" );
1213cdf0e10cSrcweir 
1214cdf0e10cSrcweir 		aSelection = rSel;
1215cdf0e10cSrcweir 		nPart = nP;
1216cdf0e10cSrcweir 		pContentObj = pContent;
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir 		pContentObj->acquire();		// darf nicht wegkommen
1219cdf0e10cSrcweir 		pEditSource = new ScHeaderFooterEditSource( pContentObj, nPart );
1220cdf0e10cSrcweir 	}
1221cdf0e10cSrcweir }
1222cdf0e10cSrcweir 
~ScHeaderFieldObj()1223cdf0e10cSrcweir ScHeaderFieldObj::~ScHeaderFieldObj()
1224cdf0e10cSrcweir {
1225cdf0e10cSrcweir 	delete pEditSource;
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir 	if (pContentObj)
1228cdf0e10cSrcweir 		pContentObj->release();
1229cdf0e10cSrcweir }
1230cdf0e10cSrcweir 
1231cdf0e10cSrcweir // per getImplementation gerufen:
1232cdf0e10cSrcweir 
CreateFieldItem()1233cdf0e10cSrcweir SvxFieldItem ScHeaderFieldObj::CreateFieldItem()
1234cdf0e10cSrcweir {
1235cdf0e10cSrcweir 	DBG_ASSERT( !pEditSource, "CreateFieldItem mit eingefuegtem Feld" );
1236cdf0e10cSrcweir 
1237cdf0e10cSrcweir 	switch (nType)
1238cdf0e10cSrcweir 	{
1239cdf0e10cSrcweir 		case SC_SERVICE_PAGEFIELD:
1240cdf0e10cSrcweir 			{
1241cdf0e10cSrcweir 				SvxPageField aField;
1242cdf0e10cSrcweir                 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1243cdf0e10cSrcweir 			}
1244cdf0e10cSrcweir 		case SC_SERVICE_PAGESFIELD:
1245cdf0e10cSrcweir 			{
1246cdf0e10cSrcweir 				SvxPagesField aField;
1247cdf0e10cSrcweir                 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1248cdf0e10cSrcweir 			}
1249cdf0e10cSrcweir 		case SC_SERVICE_DATEFIELD:
1250cdf0e10cSrcweir 			{
1251cdf0e10cSrcweir 				SvxDateField aField;
1252cdf0e10cSrcweir                 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1253cdf0e10cSrcweir 			}
1254cdf0e10cSrcweir 		case SC_SERVICE_TIMEFIELD:
1255cdf0e10cSrcweir 			{
1256cdf0e10cSrcweir 				SvxTimeField aField;
1257cdf0e10cSrcweir                 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1258cdf0e10cSrcweir 			}
1259cdf0e10cSrcweir 		case SC_SERVICE_TITLEFIELD:
1260cdf0e10cSrcweir 			{
1261cdf0e10cSrcweir 				SvxFileField aField;
1262cdf0e10cSrcweir                 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1263cdf0e10cSrcweir 			}
1264cdf0e10cSrcweir 		case SC_SERVICE_FILEFIELD:
1265cdf0e10cSrcweir 			{
1266cdf0e10cSrcweir 				SvxExtFileField aField;
1267cdf0e10cSrcweir 				aField.SetFormat( (SvxFileFormat) nFileFormat );
1268cdf0e10cSrcweir                 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1269cdf0e10cSrcweir 			}
1270cdf0e10cSrcweir 		case SC_SERVICE_SHEETFIELD:
1271cdf0e10cSrcweir 			{
1272cdf0e10cSrcweir 				SvxTableField aField;
1273cdf0e10cSrcweir                 return SvxFieldItem( aField, EE_FEATURE_FIELD );
1274cdf0e10cSrcweir 			}
1275cdf0e10cSrcweir 	}
1276cdf0e10cSrcweir 
1277cdf0e10cSrcweir     return SvxFieldItem( SvxFieldData(), EE_FEATURE_FIELD );
1278cdf0e10cSrcweir }
1279cdf0e10cSrcweir 
DeleteField()1280cdf0e10cSrcweir void ScHeaderFieldObj::DeleteField()
1281cdf0e10cSrcweir {
1282cdf0e10cSrcweir 	if (pEditSource)
1283cdf0e10cSrcweir 	{
1284cdf0e10cSrcweir 		SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
1285cdf0e10cSrcweir //		pEditEngine->QuickDelete( aSelection );
1286cdf0e10cSrcweir 		pForwarder->QuickInsertText( String(), aSelection );
1287cdf0e10cSrcweir 		pEditSource->UpdateData();
1288cdf0e10cSrcweir 
1289cdf0e10cSrcweir 		aSelection.nEndPara = aSelection.nStartPara;
1290cdf0e10cSrcweir 		aSelection.nEndPos  = aSelection.nStartPos;
1291cdf0e10cSrcweir 
1292cdf0e10cSrcweir 		//! Broadcast, um Selektion in anderen Objekten anzupassen
1293cdf0e10cSrcweir 		//!	(auch bei anderen Aktionen)
1294cdf0e10cSrcweir 	}
1295cdf0e10cSrcweir }
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir // XTextField
1298cdf0e10cSrcweir 
getPresentation(sal_Bool)1299cdf0e10cSrcweir rtl::OUString SAL_CALL ScHeaderFieldObj::getPresentation( sal_Bool /* bShowCommand */ )
1300cdf0e10cSrcweir 													throw(uno::RuntimeException)
1301cdf0e10cSrcweir {
1302cdf0e10cSrcweir 	ScUnoGuard aGuard;
1303cdf0e10cSrcweir 	String aRet;
1304cdf0e10cSrcweir 
1305cdf0e10cSrcweir 	if (pEditSource)
1306cdf0e10cSrcweir 	{
1307cdf0e10cSrcweir 		// Feld von der EditEngine formatieren lassen, bShowCommand gibt's nicht
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir 		SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
1310cdf0e10cSrcweir 		aRet = pForwarder->GetText( aSelection );
1311cdf0e10cSrcweir 	}
1312cdf0e10cSrcweir 
1313cdf0e10cSrcweir 	return aRet;
1314cdf0e10cSrcweir }
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir // XTextContent
1317cdf0e10cSrcweir 
attach(const uno::Reference<text::XTextRange> & xTextRange)1318cdf0e10cSrcweir void SAL_CALL ScHeaderFieldObj::attach( const uno::Reference<text::XTextRange>& xTextRange )
1319cdf0e10cSrcweir 								throw(lang::IllegalArgumentException, uno::RuntimeException)
1320cdf0e10cSrcweir {
1321cdf0e10cSrcweir 	ScUnoGuard aGuard;
1322cdf0e10cSrcweir 	if (xTextRange.is())
1323cdf0e10cSrcweir 	{
1324cdf0e10cSrcweir 		uno::Reference<text::XText> xText(xTextRange->getText());
1325cdf0e10cSrcweir 		if (xText.is())
1326cdf0e10cSrcweir 		{
1327cdf0e10cSrcweir 			xText->insertTextContent( xTextRange, this, sal_True );
1328cdf0e10cSrcweir 		}
1329cdf0e10cSrcweir 	}
1330cdf0e10cSrcweir }
1331cdf0e10cSrcweir 
getAnchor()1332cdf0e10cSrcweir uno::Reference<text::XTextRange> SAL_CALL ScHeaderFieldObj::getAnchor() throw(uno::RuntimeException)
1333cdf0e10cSrcweir {
1334cdf0e10cSrcweir 	ScUnoGuard aGuard;
1335cdf0e10cSrcweir 	if (pContentObj)
1336cdf0e10cSrcweir 	{
1337cdf0e10cSrcweir 		uno::Reference<text::XText> xText;
1338cdf0e10cSrcweir 		if ( nPart == SC_HDFT_LEFT )
1339cdf0e10cSrcweir 			xText = pContentObj->getLeftText();
1340cdf0e10cSrcweir 		else if (nPart == SC_HDFT_CENTER)
1341cdf0e10cSrcweir 			xText = pContentObj->getCenterText();
1342cdf0e10cSrcweir 		else
1343cdf0e10cSrcweir 			xText = pContentObj->getRightText();
1344cdf0e10cSrcweir 		return uno::Reference<text::XTextRange>( xText, uno::UNO_QUERY );
1345cdf0e10cSrcweir 	}
1346cdf0e10cSrcweir 	return NULL;
1347cdf0e10cSrcweir }
1348cdf0e10cSrcweir 
1349cdf0e10cSrcweir // XComponent
1350cdf0e10cSrcweir 
dispose()1351cdf0e10cSrcweir void SAL_CALL ScHeaderFieldObj::dispose() throw(uno::RuntimeException)
1352cdf0e10cSrcweir {
1353cdf0e10cSrcweir 	OComponentHelper::dispose();
1354cdf0e10cSrcweir }
1355cdf0e10cSrcweir 
addEventListener(const uno::Reference<lang::XEventListener> & xListener)1356cdf0e10cSrcweir void SAL_CALL ScHeaderFieldObj::addEventListener(
1357cdf0e10cSrcweir 						const uno::Reference<lang::XEventListener>& xListener )
1358cdf0e10cSrcweir 													throw(uno::RuntimeException)
1359cdf0e10cSrcweir {
1360cdf0e10cSrcweir 	OComponentHelper::addEventListener( xListener );
1361cdf0e10cSrcweir }
1362cdf0e10cSrcweir 
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)1363cdf0e10cSrcweir void SAL_CALL ScHeaderFieldObj::removeEventListener(
1364cdf0e10cSrcweir 						const uno::Reference<lang::XEventListener>& xListener )
1365cdf0e10cSrcweir 													throw(uno::RuntimeException)
1366cdf0e10cSrcweir {
1367cdf0e10cSrcweir 	OComponentHelper::removeEventListener( xListener );
1368cdf0e10cSrcweir }
1369cdf0e10cSrcweir 
1370cdf0e10cSrcweir // XPropertySet
1371cdf0e10cSrcweir 
getPropertySetInfo()1372cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScHeaderFieldObj::getPropertySetInfo()
1373cdf0e10cSrcweir 														throw(uno::RuntimeException)
1374cdf0e10cSrcweir {
1375cdf0e10cSrcweir 	ScUnoGuard aGuard;
1376cdf0e10cSrcweir 	if (nType == SC_SERVICE_FILEFIELD)
1377cdf0e10cSrcweir 	{
1378cdf0e10cSrcweir 		//	file field has different properties
1379cdf0e10cSrcweir 		static uno::Reference<beans::XPropertySetInfo> aFileFieldInfo = pPropSet->getPropertySetInfo();
1380cdf0e10cSrcweir 		return aFileFieldInfo;
1381cdf0e10cSrcweir 	}
1382cdf0e10cSrcweir 	else
1383cdf0e10cSrcweir 	{
1384cdf0e10cSrcweir 		static uno::Reference<beans::XPropertySetInfo> aRef = pPropSet->getPropertySetInfo();
1385cdf0e10cSrcweir 		return aRef;
1386cdf0e10cSrcweir 	}
1387cdf0e10cSrcweir }
1388cdf0e10cSrcweir 
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)1389cdf0e10cSrcweir void SAL_CALL ScHeaderFieldObj::setPropertyValue(
1390cdf0e10cSrcweir 						const rtl::OUString& aPropertyName, const uno::Any& aValue )
1391cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1392cdf0e10cSrcweir 						lang::IllegalArgumentException, lang::WrappedTargetException,
1393cdf0e10cSrcweir 						uno::RuntimeException)
1394cdf0e10cSrcweir {
1395cdf0e10cSrcweir 	ScUnoGuard aGuard;
1396cdf0e10cSrcweir 	String aNameString(aPropertyName);
1397cdf0e10cSrcweir 	if ( nType == SC_SERVICE_FILEFIELD && aNameString.EqualsAscii( SC_UNONAME_FILEFORM ) )
1398cdf0e10cSrcweir 	{
1399cdf0e10cSrcweir 		sal_Int16 nIntVal = 0;
1400cdf0e10cSrcweir 		if ( aValue >>= nIntVal )
1401cdf0e10cSrcweir 		{
1402cdf0e10cSrcweir 			SvxFileFormat eFormat = lcl_UnoToSvxFileFormat( nIntVal );
1403cdf0e10cSrcweir 			if (pEditSource)
1404cdf0e10cSrcweir 			{
1405cdf0e10cSrcweir 				ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine();
1406cdf0e10cSrcweir 				ScUnoEditEngine aTempEngine(pEditEngine);
1407cdf0e10cSrcweir 				SvxFieldData* pField = aTempEngine.FindByPos(
1408cdf0e10cSrcweir 						aSelection.nStartPara, aSelection.nStartPos, TYPE(SvxExtFileField) );
1409cdf0e10cSrcweir 				DBG_ASSERT(pField,"setPropertyValue: Field not found");
1410cdf0e10cSrcweir 				if (pField)
1411cdf0e10cSrcweir 				{
1412cdf0e10cSrcweir 					SvxExtFileField* pExtFile = (SvxExtFileField*)pField;	// local to the ScUnoEditEngine
1413cdf0e10cSrcweir 					pExtFile->SetFormat( eFormat );
1414cdf0e10cSrcweir                     pEditEngine->QuickInsertField( SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection );
1415cdf0e10cSrcweir 					pEditSource->UpdateData();
1416cdf0e10cSrcweir 				}
1417cdf0e10cSrcweir 			}
1418cdf0e10cSrcweir 			else
1419cdf0e10cSrcweir                 nFileFormat = sal::static_int_cast<sal_Int16>(eFormat);     // not inserted yet - store value
1420cdf0e10cSrcweir 		}
1421cdf0e10cSrcweir 	}
1422cdf0e10cSrcweir }
1423cdf0e10cSrcweir 
getPropertyValue(const rtl::OUString & aPropertyName)1424cdf0e10cSrcweir uno::Any SAL_CALL ScHeaderFieldObj::getPropertyValue( const rtl::OUString& aPropertyName )
1425cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1426cdf0e10cSrcweir 						uno::RuntimeException)
1427cdf0e10cSrcweir {
1428cdf0e10cSrcweir 	ScUnoGuard aGuard;
1429cdf0e10cSrcweir 
1430cdf0e10cSrcweir 	//!	Properties?
1431cdf0e10cSrcweir 	uno::Any aRet;
1432cdf0e10cSrcweir 	String aNameString(aPropertyName);
1433cdf0e10cSrcweir 
1434cdf0e10cSrcweir 	// anchor type is always "as character", text wrap always "none"
1435cdf0e10cSrcweir 
1436cdf0e10cSrcweir 	if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPE ) )
1437cdf0e10cSrcweir 		aRet <<= text::TextContentAnchorType_AS_CHARACTER;
1438cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPES ) )
1439cdf0e10cSrcweir 	{
1440cdf0e10cSrcweir 		uno::Sequence<text::TextContentAnchorType> aSeq(1);
1441cdf0e10cSrcweir 		aSeq[0] = text::TextContentAnchorType_AS_CHARACTER;
1442cdf0e10cSrcweir 		aRet <<= aSeq;
1443cdf0e10cSrcweir 	}
1444cdf0e10cSrcweir 	else if ( aNameString.EqualsAscii( SC_UNONAME_TEXTWRAP ) )
1445cdf0e10cSrcweir 		aRet <<= text::WrapTextMode_NONE;
1446cdf0e10cSrcweir 	else if ( nType == SC_SERVICE_FILEFIELD && aNameString.EqualsAscii( SC_UNONAME_FILEFORM ) )
1447cdf0e10cSrcweir 	{
1448cdf0e10cSrcweir 		SvxFileFormat eFormat = SVXFILEFORMAT_NAME_EXT;
1449cdf0e10cSrcweir 		if (pEditSource)
1450cdf0e10cSrcweir 		{
1451cdf0e10cSrcweir 			ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine();
1452cdf0e10cSrcweir 			ScUnoEditEngine aTempEngine(pEditEngine);
1453cdf0e10cSrcweir 			SvxFieldData* pField = aTempEngine.FindByPos(
1454cdf0e10cSrcweir 					aSelection.nStartPara, aSelection.nStartPos, TYPE(SvxExtFileField) );
1455cdf0e10cSrcweir 			DBG_ASSERT(pField,"setPropertyValue: Field not found");
1456cdf0e10cSrcweir 			if (pField)
1457cdf0e10cSrcweir 			{
1458cdf0e10cSrcweir 				const SvxExtFileField* pExtFile = (const SvxExtFileField*)pField;
1459cdf0e10cSrcweir 				eFormat = pExtFile->GetFormat();
1460cdf0e10cSrcweir 			}
1461cdf0e10cSrcweir 		}
1462cdf0e10cSrcweir 		else
1463cdf0e10cSrcweir 			eFormat = (SvxFileFormat) nFileFormat;		// not inserted yet - use stored value
1464cdf0e10cSrcweir 
1465cdf0e10cSrcweir 		sal_Int16 nIntVal = lcl_SvxToUnoFileFormat( eFormat );
1466cdf0e10cSrcweir 		aRet <<= nIntVal;
1467cdf0e10cSrcweir 	}
1468cdf0e10cSrcweir 
1469cdf0e10cSrcweir 	return aRet;
1470cdf0e10cSrcweir }
1471cdf0e10cSrcweir 
SC_IMPL_DUMMY_PROPERTY_LISTENER(ScHeaderFieldObj)1472cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScHeaderFieldObj )
1473cdf0e10cSrcweir 
1474cdf0e10cSrcweir // XUnoTunnel
1475cdf0e10cSrcweir 
1476cdf0e10cSrcweir sal_Int64 SAL_CALL ScHeaderFieldObj::getSomething(
1477cdf0e10cSrcweir 				const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
1478cdf0e10cSrcweir {
1479cdf0e10cSrcweir 	if ( rId.getLength() == 16 &&
1480cdf0e10cSrcweir           0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
1481cdf0e10cSrcweir 									rId.getConstArray(), 16 ) )
1482cdf0e10cSrcweir 	{
1483cdf0e10cSrcweir         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
1484cdf0e10cSrcweir 	}
1485cdf0e10cSrcweir 	return 0;
1486cdf0e10cSrcweir }
1487cdf0e10cSrcweir 
1488cdf0e10cSrcweir // static
getUnoTunnelId()1489cdf0e10cSrcweir const uno::Sequence<sal_Int8>& ScHeaderFieldObj::getUnoTunnelId()
1490cdf0e10cSrcweir {
1491cdf0e10cSrcweir 	static uno::Sequence<sal_Int8> * pSeq = 0;
1492cdf0e10cSrcweir 	if( !pSeq )
1493cdf0e10cSrcweir 	{
1494cdf0e10cSrcweir 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
1495cdf0e10cSrcweir 		if( !pSeq )
1496cdf0e10cSrcweir 		{
1497cdf0e10cSrcweir 			static uno::Sequence< sal_Int8 > aSeq( 16 );
1498cdf0e10cSrcweir 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
1499cdf0e10cSrcweir 			pSeq = &aSeq;
1500cdf0e10cSrcweir 		}
1501cdf0e10cSrcweir 	}
1502cdf0e10cSrcweir 	return *pSeq;
1503cdf0e10cSrcweir }
1504cdf0e10cSrcweir 
1505cdf0e10cSrcweir // static
getImplementation(const uno::Reference<text::XTextContent> xObj)1506cdf0e10cSrcweir ScHeaderFieldObj* ScHeaderFieldObj::getImplementation(
1507cdf0e10cSrcweir 								const uno::Reference<text::XTextContent> xObj )
1508cdf0e10cSrcweir {
1509cdf0e10cSrcweir 	ScHeaderFieldObj* pRet = NULL;
1510cdf0e10cSrcweir 	uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
1511cdf0e10cSrcweir 	if (xUT.is())
1512cdf0e10cSrcweir         pRet = reinterpret_cast<ScHeaderFieldObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
1513cdf0e10cSrcweir 	return pRet;
1514cdf0e10cSrcweir }
1515cdf0e10cSrcweir 
1516cdf0e10cSrcweir // XServiceInfo
1517cdf0e10cSrcweir 
getImplementationName()1518cdf0e10cSrcweir rtl::OUString SAL_CALL ScHeaderFieldObj::getImplementationName() throw(uno::RuntimeException)
1519cdf0e10cSrcweir {
1520cdf0e10cSrcweir 	return rtl::OUString::createFromAscii( "ScHeaderFieldObj" );
1521cdf0e10cSrcweir }
1522cdf0e10cSrcweir 
supportsService(const rtl::OUString & rServiceName)1523cdf0e10cSrcweir sal_Bool SAL_CALL ScHeaderFieldObj::supportsService( const rtl::OUString& rServiceName )
1524cdf0e10cSrcweir 													throw(uno::RuntimeException)
1525cdf0e10cSrcweir {
1526cdf0e10cSrcweir 	String aServiceStr( rServiceName );
1527cdf0e10cSrcweir 	return aServiceStr.EqualsAscii( SCTEXTFIELD_SERVICE ) ||
1528cdf0e10cSrcweir 		   aServiceStr.EqualsAscii( SCTEXTCONTENT_SERVICE );
1529cdf0e10cSrcweir }
1530cdf0e10cSrcweir 
getSupportedServiceNames()1531cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScHeaderFieldObj::getSupportedServiceNames()
1532cdf0e10cSrcweir 													throw(uno::RuntimeException)
1533cdf0e10cSrcweir {
1534cdf0e10cSrcweir 	uno::Sequence<rtl::OUString> aRet(2);
1535cdf0e10cSrcweir 	rtl::OUString* pArray = aRet.getArray();
1536cdf0e10cSrcweir 	pArray[0] = rtl::OUString::createFromAscii( SCTEXTFIELD_SERVICE );
1537cdf0e10cSrcweir 	pArray[1] = rtl::OUString::createFromAscii( SCTEXTCONTENT_SERVICE );
1538cdf0e10cSrcweir 	return aRet;
1539cdf0e10cSrcweir }
1540cdf0e10cSrcweir 
1541cdf0e10cSrcweir //------------------------------------------------------------------------
1542cdf0e10cSrcweir 
1543cdf0e10cSrcweir 
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir 
1546