xref: /aoo41x/main/sc/source/ui/unoobj/targuno.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 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <vcl/image.hxx>
30cdf0e10cSrcweir #include <vcl/virdev.hxx>
31cdf0e10cSrcweir //#include <toolkit/unoiface.hxx>
32cdf0e10cSrcweir #include <toolkit/unohlp.hxx>
33cdf0e10cSrcweir #include <svl/itemprop.hxx>
34cdf0e10cSrcweir #include <svl/smplhint.hxx>
35cdf0e10cSrcweir #include <vcl/svapp.hxx>
36cdf0e10cSrcweir #include <vcl/settings.hxx>
37cdf0e10cSrcweir #include <com/sun/star/awt/XBitmap.hpp>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include "targuno.hxx"
40cdf0e10cSrcweir #include "miscuno.hxx"
41cdf0e10cSrcweir #include "docuno.hxx"
42cdf0e10cSrcweir #include "datauno.hxx"
43cdf0e10cSrcweir #include "nameuno.hxx"
44cdf0e10cSrcweir #include "docsh.hxx"
45cdf0e10cSrcweir #include "content.hxx"
46cdf0e10cSrcweir #include "unoguard.hxx"
47cdf0e10cSrcweir #include "scresid.hxx"
48cdf0e10cSrcweir #include "sc.hrc"
49cdf0e10cSrcweir #include "unonames.hxx"
50cdf0e10cSrcweir 
51cdf0e10cSrcweir using  namespace ::com::sun::star;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir //------------------------------------------------------------------------
54cdf0e10cSrcweir 
55cdf0e10cSrcweir sal_uInt16 nTypeResIds[SC_LINKTARGETTYPE_COUNT] =
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	SCSTR_CONTENT_TABLE,		// SC_LINKTARGETTYPE_SHEET
58cdf0e10cSrcweir 	SCSTR_CONTENT_RANGENAME,	// SC_LINKTARGETTYPE_RANGENAME
59cdf0e10cSrcweir 	SCSTR_CONTENT_DBAREA		// SC_LINKTARGETTYPE_DBAREA
60cdf0e10cSrcweir };
61cdf0e10cSrcweir 
lcl_GetLinkTargetMap()62cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetLinkTargetMap()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     static SfxItemPropertyMapEntry aLinkTargetMap_Impl[] =
65cdf0e10cSrcweir 	{
66cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_LINKDISPBIT),	0,	&getCppuType((const uno::Reference<awt::XBitmap>*)0),	beans::PropertyAttribute::READONLY, 0 },
67cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_LINKDISPNAME),	0,	&getCppuType((const ::rtl::OUString*)0),				beans::PropertyAttribute::READONLY, 0 },
68cdf0e10cSrcweir         {0,0,0,0,0,0}
69cdf0e10cSrcweir 	};
70cdf0e10cSrcweir 	return aLinkTargetMap_Impl;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir //------------------------------------------------------------------------
74cdf0e10cSrcweir 
75cdf0e10cSrcweir // service for ScLinkTargetTypeObj is not defined
76cdf0e10cSrcweir //	must not support document::LinkTarget because the target type cannot be used as a target
77cdf0e10cSrcweir 
78cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypesObj, "ScLinkTargetTypesObj", "com.sun.star.document.LinkTargets" )
79cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypeObj,  "ScLinkTargetTypeObj",  "com.sun.star.document.LinkTargetSupplier" )
80cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScLinkTargetsObj,     "ScLinkTargetsObj",     "com.sun.star.document.LinkTargets" )
81cdf0e10cSrcweir 
82cdf0e10cSrcweir //------------------------------------------------------------------------
83cdf0e10cSrcweir 
ScLinkTargetTypesObj(ScDocShell * pDocSh)84cdf0e10cSrcweir ScLinkTargetTypesObj::ScLinkTargetTypesObj(ScDocShell* pDocSh) :
85cdf0e10cSrcweir 	pDocShell( pDocSh )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	pDocShell->GetDocument()->AddUnoObject(*this);
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
90cdf0e10cSrcweir 		aNames[i] = String( ScResId( nTypeResIds[i] ) );
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
~ScLinkTargetTypesObj()93cdf0e10cSrcweir ScLinkTargetTypesObj::~ScLinkTargetTypesObj()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	if (pDocShell)
96cdf0e10cSrcweir 		pDocShell->GetDocument()->RemoveUnoObject(*this);
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)99cdf0e10cSrcweir void ScLinkTargetTypesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir 	if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
102cdf0e10cSrcweir 		pDocShell = NULL;		// document gone
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir // container::XNameAccess
106cdf0e10cSrcweir 
getByName(const rtl::OUString & aName)107cdf0e10cSrcweir uno::Any SAL_CALL ScLinkTargetTypesObj::getByName(const rtl::OUString& aName)
108cdf0e10cSrcweir 		throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	if (pDocShell)
111cdf0e10cSrcweir 	{
112cdf0e10cSrcweir 		String aNameStr(aName);
113cdf0e10cSrcweir 		for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
114cdf0e10cSrcweir 			if ( aNames[i] == aNameStr )
115cdf0e10cSrcweir                 return uno::makeAny(uno::Reference< beans::XPropertySet >(new ScLinkTargetTypeObj( pDocShell, i )));
116cdf0e10cSrcweir 	}
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	throw container::NoSuchElementException();
119cdf0e10cSrcweir //    return uno::Any();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
getElementNames(void)122cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScLinkTargetTypesObj::getElementNames(void) throw( uno::RuntimeException )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	uno::Sequence<rtl::OUString> aRet(SC_LINKTARGETTYPE_COUNT);
125cdf0e10cSrcweir 	rtl::OUString* pArray = aRet.getArray();
126cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
127cdf0e10cSrcweir 		pArray[i] = aNames[i];
128cdf0e10cSrcweir 	return aRet;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
hasByName(const rtl::OUString & aName)131cdf0e10cSrcweir sal_Bool SAL_CALL ScLinkTargetTypesObj::hasByName(const rtl::OUString& aName) throw( uno::RuntimeException )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir 	String aNameStr = aName;
134cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
135cdf0e10cSrcweir 		if ( aNames[i] == aNameStr )
136cdf0e10cSrcweir 			return sal_True;
137cdf0e10cSrcweir 	return sal_False;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir // container::XElementAccess
141cdf0e10cSrcweir 
getElementType(void)142cdf0e10cSrcweir uno::Type SAL_CALL ScLinkTargetTypesObj::getElementType(void) throw( uno::RuntimeException )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	return ::getCppuType((const uno::Reference< beans::XPropertySet >*)0);
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
hasElements(void)147cdf0e10cSrcweir sal_Bool SAL_CALL ScLinkTargetTypesObj::hasElements(void) throw( uno::RuntimeException )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	return sal_True;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir //------------------------------------------------------------------------
153cdf0e10cSrcweir 
ScLinkTargetTypeObj(ScDocShell * pDocSh,sal_uInt16 nT)154cdf0e10cSrcweir ScLinkTargetTypeObj::ScLinkTargetTypeObj(ScDocShell* pDocSh, sal_uInt16 nT) :
155cdf0e10cSrcweir 	pDocShell( pDocSh ),
156cdf0e10cSrcweir 	nType( nT )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir 	pDocShell->GetDocument()->AddUnoObject(*this);
159cdf0e10cSrcweir 	aName = String( ScResId( nTypeResIds[nType] ) );	//! on demand?
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
~ScLinkTargetTypeObj()162cdf0e10cSrcweir ScLinkTargetTypeObj::~ScLinkTargetTypeObj()
163cdf0e10cSrcweir {
164cdf0e10cSrcweir 	if (pDocShell)
165cdf0e10cSrcweir 		pDocShell->GetDocument()->RemoveUnoObject(*this);
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)168cdf0e10cSrcweir void ScLinkTargetTypeObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 	if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
171cdf0e10cSrcweir 		pDocShell = NULL;		// document gone
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir // document::XLinkTargetSupplier
175cdf0e10cSrcweir 
getLinks(void)176cdf0e10cSrcweir uno::Reference< container::XNameAccess > SAL_CALL  ScLinkTargetTypeObj::getLinks(void) throw( uno::RuntimeException )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir 	uno::Reference< container::XNameAccess >  xCollection;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	if ( pDocShell )
181cdf0e10cSrcweir 	{
182cdf0e10cSrcweir 		switch ( nType )
183cdf0e10cSrcweir 		{
184cdf0e10cSrcweir 			case SC_LINKTARGETTYPE_SHEET:
185cdf0e10cSrcweir 				xCollection.set(new ScTableSheetsObj(pDocShell));
186cdf0e10cSrcweir 				break;
187cdf0e10cSrcweir 			case SC_LINKTARGETTYPE_RANGENAME:
188cdf0e10cSrcweir 				xCollection.set(new ScNamedRangesObj(pDocShell));
189cdf0e10cSrcweir 				break;
190cdf0e10cSrcweir 			case SC_LINKTARGETTYPE_DBAREA:
191cdf0e10cSrcweir 				xCollection.set(new ScDatabaseRangesObj(pDocShell));
192cdf0e10cSrcweir 				break;
193cdf0e10cSrcweir 			default:
194cdf0e10cSrcweir 				DBG_ERROR("invalid type");
195cdf0e10cSrcweir 		}
196cdf0e10cSrcweir 	}
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	//	wrap collection in ScLinkTargetsObj because service document::LinkTargets requires
199cdf0e10cSrcweir 	//	beans::XPropertySet as ElementType in container::XNameAccess.
200cdf0e10cSrcweir 	if ( xCollection.is() )
201cdf0e10cSrcweir 		return new ScLinkTargetsObj( xCollection );
202cdf0e10cSrcweir 	return NULL;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir // beans::XPropertySet
206cdf0e10cSrcweir 
getPropertySetInfo(void)207cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > SAL_CALL  ScLinkTargetTypeObj::getPropertySetInfo(void) throw( uno::RuntimeException )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir 	ScUnoGuard aGuard;
210cdf0e10cSrcweir 	static uno::Reference< beans::XPropertySetInfo >  aRef(new SfxItemPropertySetInfo( lcl_GetLinkTargetMap() ));
211cdf0e10cSrcweir 	return aRef;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir 
setPropertyValue(const rtl::OUString &,const uno::Any &)214cdf0e10cSrcweir void SAL_CALL ScLinkTargetTypeObj::setPropertyValue(const rtl::OUString& /* aPropertyName */,
215cdf0e10cSrcweir             const uno::Any& /* aValue */)
216cdf0e10cSrcweir 		throw(	beans::UnknownPropertyException,
217cdf0e10cSrcweir 				beans::PropertyVetoException,
218cdf0e10cSrcweir 				lang::IllegalArgumentException,
219cdf0e10cSrcweir 				lang::WrappedTargetException,
220cdf0e10cSrcweir  				uno::RuntimeException )
221cdf0e10cSrcweir {
222cdf0e10cSrcweir 	//	everything is read-only
223cdf0e10cSrcweir 	//!	exception?
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir //	static
SetLinkTargetBitmap(uno::Any & rRet,sal_uInt16 nType)227cdf0e10cSrcweir void ScLinkTargetTypeObj::SetLinkTargetBitmap( uno::Any& rRet, sal_uInt16 nType )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir 	sal_uInt16 nImgId = 0;
230cdf0e10cSrcweir 	switch ( nType )
231cdf0e10cSrcweir 	{
232cdf0e10cSrcweir 		case SC_LINKTARGETTYPE_SHEET:
233cdf0e10cSrcweir 			nImgId = SC_CONTENT_TABLE;
234cdf0e10cSrcweir 			break;
235cdf0e10cSrcweir 		case SC_LINKTARGETTYPE_RANGENAME:
236cdf0e10cSrcweir 			nImgId = SC_CONTENT_RANGENAME;
237cdf0e10cSrcweir 			break;
238cdf0e10cSrcweir 		case SC_LINKTARGETTYPE_DBAREA:
239cdf0e10cSrcweir 			nImgId = SC_CONTENT_DBAREA;
240cdf0e10cSrcweir 			break;
241cdf0e10cSrcweir 	}
242cdf0e10cSrcweir 	if (nImgId)
243cdf0e10cSrcweir 	{
244cdf0e10cSrcweir         sal_Bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
245cdf0e10cSrcweir         ImageList aEntryImages( ScResId( bHighContrast ? RID_IMAGELIST_H_NAVCONT : RID_IMAGELIST_NAVCONT ) );
246cdf0e10cSrcweir 		const Image& rImage = aEntryImages.GetImage( nImgId );
247cdf0e10cSrcweir 		rRet <<= uno::Reference< awt::XBitmap > (VCLUnoHelper::CreateBitmap( rImage.GetBitmapEx() ));
248cdf0e10cSrcweir 	}
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
getPropertyValue(const rtl::OUString & PropertyName)251cdf0e10cSrcweir uno::Any SAL_CALL ScLinkTargetTypeObj::getPropertyValue(const rtl::OUString& PropertyName)
252cdf0e10cSrcweir 		throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	uno::Any aRet;
255cdf0e10cSrcweir 	String aNameStr(PropertyName);
256cdf0e10cSrcweir 	if ( aNameStr.EqualsAscii( SC_UNO_LINKDISPBIT ) )
257cdf0e10cSrcweir 		SetLinkTargetBitmap( aRet, nType );
258cdf0e10cSrcweir 	else if ( aNameStr.EqualsAscii( SC_UNO_LINKDISPNAME ) )
259cdf0e10cSrcweir 		aRet <<= rtl::OUString( aName );
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 	return aRet;
262cdf0e10cSrcweir }
263cdf0e10cSrcweir 
SC_IMPL_DUMMY_PROPERTY_LISTENER(ScLinkTargetTypeObj)264cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScLinkTargetTypeObj )
265cdf0e10cSrcweir 
266cdf0e10cSrcweir //------------------------------------------------------------------------
267cdf0e10cSrcweir 
268cdf0e10cSrcweir ScLinkTargetsObj::ScLinkTargetsObj( const uno::Reference< container::XNameAccess > & rColl ) :
269cdf0e10cSrcweir 	xCollection( rColl )
270cdf0e10cSrcweir {
271cdf0e10cSrcweir 	DBG_ASSERT( xCollection.is(), "ScLinkTargetsObj: NULL" );
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
~ScLinkTargetsObj()274cdf0e10cSrcweir ScLinkTargetsObj::~ScLinkTargetsObj()
275cdf0e10cSrcweir {
276cdf0e10cSrcweir }
277cdf0e10cSrcweir 
278cdf0e10cSrcweir // container::XNameAccess
279cdf0e10cSrcweir 
getByName(const rtl::OUString & aName)280cdf0e10cSrcweir uno::Any SAL_CALL ScLinkTargetsObj::getByName(const rtl::OUString& aName)
281cdf0e10cSrcweir 		throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
282cdf0e10cSrcweir {
283cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet >  xProp( ScUnoHelpFunctions::AnyToInterface( xCollection->getByName(aName) ), uno::UNO_QUERY );
284cdf0e10cSrcweir 	if (xProp.is())
285cdf0e10cSrcweir         return uno::makeAny(xProp);
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 	throw container::NoSuchElementException();
288cdf0e10cSrcweir //    return uno::Any();
289cdf0e10cSrcweir }
290cdf0e10cSrcweir 
getElementNames(void)291cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScLinkTargetsObj::getElementNames(void) throw( uno::RuntimeException )
292cdf0e10cSrcweir {
293cdf0e10cSrcweir 	return xCollection->getElementNames();
294cdf0e10cSrcweir }
295cdf0e10cSrcweir 
hasByName(const rtl::OUString & aName)296cdf0e10cSrcweir sal_Bool SAL_CALL ScLinkTargetsObj::hasByName(const rtl::OUString& aName) throw( uno::RuntimeException )
297cdf0e10cSrcweir {
298cdf0e10cSrcweir 	return xCollection->hasByName(aName);
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir // container::XElementAccess
302cdf0e10cSrcweir 
getElementType(void)303cdf0e10cSrcweir uno::Type SAL_CALL ScLinkTargetsObj::getElementType(void) throw( uno::RuntimeException )
304cdf0e10cSrcweir {
305cdf0e10cSrcweir 	return ::getCppuType((const uno::Reference< beans::XPropertySet >*)0);
306cdf0e10cSrcweir }
307cdf0e10cSrcweir 
hasElements(void)308cdf0e10cSrcweir sal_Bool SAL_CALL ScLinkTargetsObj::hasElements(void) throw( uno::RuntimeException )
309cdf0e10cSrcweir {
310cdf0e10cSrcweir 	return xCollection->hasElements();
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 
315