fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / unoobj / targuno.cxx
blob09dce622012521ddc54c839c369f2b7d52c0320a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/image.hxx>
21 #include <vcl/virdev.hxx>
22 #include <toolkit/helper/vclunohelper.hxx>
23 #include <svl/itemprop.hxx>
24 #include <svl/smplhint.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/settings.hxx>
27 #include <com/sun/star/awt/XBitmap.hpp>
29 #include "targuno.hxx"
30 #include "miscuno.hxx"
31 #include "docuno.hxx"
32 #include "datauno.hxx"
33 #include "nameuno.hxx"
34 #include "docsh.hxx"
35 #include "content.hxx"
36 #include "scresid.hxx"
37 #include "sc.hrc"
38 #include "unonames.hxx"
40 using namespace ::com::sun::star;
42 sal_uInt16 nTypeResIds[SC_LINKTARGETTYPE_COUNT] =
44 SCSTR_CONTENT_TABLE, // SC_LINKTARGETTYPE_SHEET
45 SCSTR_CONTENT_RANGENAME, // SC_LINKTARGETTYPE_RANGENAME
46 SCSTR_CONTENT_DBAREA // SC_LINKTARGETTYPE_DBAREA
49 static const SfxItemPropertyMapEntry* lcl_GetLinkTargetMap()
51 static const SfxItemPropertyMapEntry aLinkTargetMap_Impl[] =
53 {OUString(SC_UNO_LINKDISPBIT), 0, cppu::UnoType<awt::XBitmap>::get(), beans::PropertyAttribute::READONLY, 0 },
54 {OUString(SC_UNO_LINKDISPNAME), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0 },
55 { OUString(), 0, css::uno::Type(), 0, 0 }
57 return aLinkTargetMap_Impl;
60 // service for ScLinkTargetTypeObj is not defined
61 // must not support document::LinkTarget because the target type cannot be used as a target
63 SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypesObj, "ScLinkTargetTypesObj", "com.sun.star.document.LinkTargets" )
64 SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypeObj, "ScLinkTargetTypeObj", "com.sun.star.document.LinkTargetSupplier" )
65 SC_SIMPLE_SERVICE_INFO( ScLinkTargetsObj, "ScLinkTargetsObj", "com.sun.star.document.LinkTargets" )
67 ScLinkTargetTypesObj::ScLinkTargetTypesObj(ScDocShell* pDocSh) :
68 pDocShell( pDocSh )
70 pDocShell->GetDocument().AddUnoObject(*this);
72 for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
73 aNames[i] = ScResId( nTypeResIds[i] );
76 ScLinkTargetTypesObj::~ScLinkTargetTypesObj()
78 SolarMutexGuard g;
80 if (pDocShell)
81 pDocShell->GetDocument().RemoveUnoObject(*this);
84 void ScLinkTargetTypesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
86 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
87 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
88 pDocShell = NULL; // document gone
91 // container::XNameAccess
93 uno::Any SAL_CALL ScLinkTargetTypesObj::getByName(const OUString& aName)
94 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
96 if (pDocShell)
98 OUString aNameStr(aName);
99 for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
100 if ( aNames[i] == aNameStr )
101 return uno::makeAny(uno::Reference< beans::XPropertySet >(new ScLinkTargetTypeObj( pDocShell, i )));
104 throw container::NoSuchElementException();
107 uno::Sequence<OUString> SAL_CALL ScLinkTargetTypesObj::getElementNames() throw( uno::RuntimeException, std::exception )
109 uno::Sequence<OUString> aRet(SC_LINKTARGETTYPE_COUNT);
110 OUString* pArray = aRet.getArray();
111 for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
112 pArray[i] = aNames[i];
113 return aRet;
116 sal_Bool SAL_CALL ScLinkTargetTypesObj::hasByName(const OUString& aName) throw( uno::RuntimeException, std::exception )
118 OUString aNameStr = aName;
119 for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
120 if ( aNames[i] == aNameStr )
121 return sal_True;
122 return false;
125 // container::XElementAccess
127 uno::Type SAL_CALL ScLinkTargetTypesObj::getElementType() throw( uno::RuntimeException, std::exception )
129 return cppu::UnoType<beans::XPropertySet>::get();
132 sal_Bool SAL_CALL ScLinkTargetTypesObj::hasElements() throw( uno::RuntimeException, std::exception )
134 return sal_True;
137 ScLinkTargetTypeObj::ScLinkTargetTypeObj(ScDocShell* pDocSh, sal_uInt16 nT) :
138 pDocShell( pDocSh ),
139 nType( nT )
141 pDocShell->GetDocument().AddUnoObject(*this);
142 aName = ScResId( nTypeResIds[nType] ); //! on demand?
145 ScLinkTargetTypeObj::~ScLinkTargetTypeObj()
147 SolarMutexGuard g;
149 if (pDocShell)
150 pDocShell->GetDocument().RemoveUnoObject(*this);
153 void ScLinkTargetTypeObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
155 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
156 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
157 pDocShell = NULL; // document gone
160 // document::XLinkTargetSupplier
162 uno::Reference< container::XNameAccess > SAL_CALL ScLinkTargetTypeObj::getLinks() throw( uno::RuntimeException, std::exception )
164 uno::Reference< container::XNameAccess > xCollection;
166 if ( pDocShell )
168 switch ( nType )
170 case SC_LINKTARGETTYPE_SHEET:
171 xCollection.set(new ScTableSheetsObj(pDocShell));
172 break;
173 case SC_LINKTARGETTYPE_RANGENAME:
174 xCollection.set(new ScGlobalNamedRangesObj(pDocShell));
175 break;
176 case SC_LINKTARGETTYPE_DBAREA:
177 xCollection.set(new ScDatabaseRangesObj(pDocShell));
178 break;
179 default:
180 OSL_FAIL("invalid type");
184 // wrap collection in ScLinkTargetsObj because service document::LinkTargets requires
185 // beans::XPropertySet as ElementType in container::XNameAccess.
186 if ( xCollection.is() )
187 return new ScLinkTargetsObj( xCollection );
188 return NULL;
191 // beans::XPropertySet
193 uno::Reference< beans::XPropertySetInfo > SAL_CALL ScLinkTargetTypeObj::getPropertySetInfo() throw( uno::RuntimeException, std::exception )
195 SolarMutexGuard aGuard;
196 static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( lcl_GetLinkTargetMap() ));
197 return aRef;
200 void SAL_CALL ScLinkTargetTypeObj::setPropertyValue(const OUString& /* aPropertyName */,
201 const uno::Any& /* aValue */)
202 throw( beans::UnknownPropertyException,
203 beans::PropertyVetoException,
204 lang::IllegalArgumentException,
205 lang::WrappedTargetException,
206 uno::RuntimeException, std::exception )
208 // everything is read-only
209 //! exception?
212 void ScLinkTargetTypeObj::SetLinkTargetBitmap( uno::Any& rRet, sal_uInt16 nType )
214 sal_uInt16 nImgId = 0;
215 switch ( nType )
217 case SC_LINKTARGETTYPE_SHEET:
218 nImgId = SC_CONTENT_TABLE;
219 break;
220 case SC_LINKTARGETTYPE_RANGENAME:
221 nImgId = SC_CONTENT_RANGENAME;
222 break;
223 case SC_LINKTARGETTYPE_DBAREA:
224 nImgId = SC_CONTENT_DBAREA;
225 break;
227 if (nImgId)
229 ImageList aEntryImages( ScResId( RID_IMAGELIST_NAVCONT ) );
230 const Image& rImage = aEntryImages.GetImage( nImgId );
231 rRet <<= uno::Reference< awt::XBitmap > (VCLUnoHelper::CreateBitmap( rImage.GetBitmapEx() ));
235 uno::Any SAL_CALL ScLinkTargetTypeObj::getPropertyValue(const OUString& PropertyName)
236 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
238 uno::Any aRet;
239 OUString aNameStr(PropertyName);
240 if ( aNameStr == SC_UNO_LINKDISPBIT )
241 SetLinkTargetBitmap( aRet, nType );
242 else if ( aNameStr == SC_UNO_LINKDISPNAME )
243 aRet <<= OUString( aName );
245 return aRet;
248 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScLinkTargetTypeObj )
250 ScLinkTargetsObj::ScLinkTargetsObj( const uno::Reference< container::XNameAccess > & rColl ) :
251 xCollection( rColl )
253 OSL_ENSURE( xCollection.is(), "ScLinkTargetsObj: NULL" );
256 ScLinkTargetsObj::~ScLinkTargetsObj()
260 // container::XNameAccess
262 uno::Any SAL_CALL ScLinkTargetsObj::getByName(const OUString& aName)
263 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
265 uno::Reference< beans::XPropertySet > xProp( ScUnoHelpFunctions::AnyToInterface( xCollection->getByName(aName) ), uno::UNO_QUERY );
266 if (xProp.is())
267 return uno::makeAny(xProp);
269 throw container::NoSuchElementException();
270 // return uno::Any();
273 uno::Sequence<OUString> SAL_CALL ScLinkTargetsObj::getElementNames() throw( uno::RuntimeException, std::exception )
275 return xCollection->getElementNames();
278 sal_Bool SAL_CALL ScLinkTargetsObj::hasByName(const OUString& aName) throw( uno::RuntimeException, std::exception )
280 return xCollection->hasByName(aName);
283 // container::XElementAccess
285 uno::Type SAL_CALL ScLinkTargetsObj::getElementType() throw( uno::RuntimeException, std::exception )
287 return cppu::UnoType<beans::XPropertySet>::get();
290 sal_Bool SAL_CALL ScLinkTargetsObj::hasElements() throw( uno::RuntimeException, std::exception )
292 return xCollection->hasElements();
295 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */