1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
32 #include "datauno.hxx"
33 #include "nameuno.hxx"
35 #include "content.hxx"
36 #include "scresid.hxx"
38 #include "unonames.hxx"
40 using namespace ::com::sun::star
;
42 //------------------------------------------------------------------------
44 sal_uInt16 nTypeResIds
[SC_LINKTARGETTYPE_COUNT
] =
46 SCSTR_CONTENT_TABLE
, // SC_LINKTARGETTYPE_SHEET
47 SCSTR_CONTENT_RANGENAME
, // SC_LINKTARGETTYPE_RANGENAME
48 SCSTR_CONTENT_DBAREA
// SC_LINKTARGETTYPE_DBAREA
51 static const SfxItemPropertyMapEntry
* lcl_GetLinkTargetMap()
53 static const SfxItemPropertyMapEntry aLinkTargetMap_Impl
[] =
55 {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT
), 0, &getCppuType((const uno::Reference
<awt::XBitmap
>*)0), beans::PropertyAttribute::READONLY
, 0 },
56 {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME
), 0, &getCppuType((const OUString
*)0), beans::PropertyAttribute::READONLY
, 0 },
59 return aLinkTargetMap_Impl
;
62 //------------------------------------------------------------------------
64 // service for ScLinkTargetTypeObj is not defined
65 // must not support document::LinkTarget because the target type cannot be used as a target
67 SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypesObj
, "ScLinkTargetTypesObj", "com.sun.star.document.LinkTargets" )
68 SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypeObj
, "ScLinkTargetTypeObj", "com.sun.star.document.LinkTargetSupplier" )
69 SC_SIMPLE_SERVICE_INFO( ScLinkTargetsObj
, "ScLinkTargetsObj", "com.sun.star.document.LinkTargets" )
71 //------------------------------------------------------------------------
73 ScLinkTargetTypesObj::ScLinkTargetTypesObj(ScDocShell
* pDocSh
) :
76 pDocShell
->GetDocument()->AddUnoObject(*this);
78 for (sal_uInt16 i
=0; i
<SC_LINKTARGETTYPE_COUNT
; i
++)
79 aNames
[i
] = ScResId( nTypeResIds
[i
] );
82 ScLinkTargetTypesObj::~ScLinkTargetTypesObj()
85 pDocShell
->GetDocument()->RemoveUnoObject(*this);
88 void ScLinkTargetTypesObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
90 if ( rHint
.ISA( SfxSimpleHint
) && ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
91 pDocShell
= NULL
; // document gone
94 // container::XNameAccess
96 uno::Any SAL_CALL
ScLinkTargetTypesObj::getByName(const OUString
& aName
)
97 throw( container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
101 OUString
aNameStr(aName
);
102 for (sal_uInt16 i
=0; i
<SC_LINKTARGETTYPE_COUNT
; i
++)
103 if ( aNames
[i
] == aNameStr
)
104 return uno::makeAny(uno::Reference
< beans::XPropertySet
>(new ScLinkTargetTypeObj( pDocShell
, i
)));
107 throw container::NoSuchElementException();
110 uno::Sequence
<OUString
> SAL_CALL
ScLinkTargetTypesObj::getElementNames(void) throw( uno::RuntimeException
)
112 uno::Sequence
<OUString
> aRet(SC_LINKTARGETTYPE_COUNT
);
113 OUString
* pArray
= aRet
.getArray();
114 for (sal_uInt16 i
=0; i
<SC_LINKTARGETTYPE_COUNT
; i
++)
115 pArray
[i
] = aNames
[i
];
119 sal_Bool SAL_CALL
ScLinkTargetTypesObj::hasByName(const OUString
& aName
) throw( uno::RuntimeException
)
121 OUString aNameStr
= aName
;
122 for (sal_uInt16 i
=0; i
<SC_LINKTARGETTYPE_COUNT
; i
++)
123 if ( aNames
[i
] == aNameStr
)
128 // container::XElementAccess
130 uno::Type SAL_CALL
ScLinkTargetTypesObj::getElementType(void) throw( uno::RuntimeException
)
132 return ::getCppuType((const uno::Reference
< beans::XPropertySet
>*)0);
135 sal_Bool SAL_CALL
ScLinkTargetTypesObj::hasElements(void) throw( uno::RuntimeException
)
140 //------------------------------------------------------------------------
142 ScLinkTargetTypeObj::ScLinkTargetTypeObj(ScDocShell
* pDocSh
, sal_uInt16 nT
) :
146 pDocShell
->GetDocument()->AddUnoObject(*this);
147 aName
= ScResId( nTypeResIds
[nType
] ); //! on demand?
150 ScLinkTargetTypeObj::~ScLinkTargetTypeObj()
153 pDocShell
->GetDocument()->RemoveUnoObject(*this);
156 void ScLinkTargetTypeObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
158 if ( rHint
.ISA( SfxSimpleHint
) && ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
159 pDocShell
= NULL
; // document gone
162 // document::XLinkTargetSupplier
164 uno::Reference
< container::XNameAccess
> SAL_CALL
ScLinkTargetTypeObj::getLinks(void) throw( uno::RuntimeException
)
166 uno::Reference
< container::XNameAccess
> xCollection
;
172 case SC_LINKTARGETTYPE_SHEET
:
173 xCollection
.set(new ScTableSheetsObj(pDocShell
));
175 case SC_LINKTARGETTYPE_RANGENAME
:
176 xCollection
.set(new ScGlobalNamedRangesObj(pDocShell
));
178 case SC_LINKTARGETTYPE_DBAREA
:
179 xCollection
.set(new ScDatabaseRangesObj(pDocShell
));
182 OSL_FAIL("invalid type");
186 // wrap collection in ScLinkTargetsObj because service document::LinkTargets requires
187 // beans::XPropertySet as ElementType in container::XNameAccess.
188 if ( xCollection
.is() )
189 return new ScLinkTargetsObj( xCollection
);
193 // beans::XPropertySet
195 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
ScLinkTargetTypeObj::getPropertySetInfo(void) throw( uno::RuntimeException
)
197 SolarMutexGuard aGuard
;
198 static uno::Reference
< beans::XPropertySetInfo
> aRef(new SfxItemPropertySetInfo( lcl_GetLinkTargetMap() ));
202 void SAL_CALL
ScLinkTargetTypeObj::setPropertyValue(const OUString
& /* aPropertyName */,
203 const uno::Any
& /* aValue */)
204 throw( beans::UnknownPropertyException
,
205 beans::PropertyVetoException
,
206 lang::IllegalArgumentException
,
207 lang::WrappedTargetException
,
208 uno::RuntimeException
)
210 // everything is read-only
214 void ScLinkTargetTypeObj::SetLinkTargetBitmap( uno::Any
& rRet
, sal_uInt16 nType
)
216 sal_uInt16 nImgId
= 0;
219 case SC_LINKTARGETTYPE_SHEET
:
220 nImgId
= SC_CONTENT_TABLE
;
222 case SC_LINKTARGETTYPE_RANGENAME
:
223 nImgId
= SC_CONTENT_RANGENAME
;
225 case SC_LINKTARGETTYPE_DBAREA
:
226 nImgId
= SC_CONTENT_DBAREA
;
231 ImageList
aEntryImages( ScResId( RID_IMAGELIST_NAVCONT
) );
232 const Image
& rImage
= aEntryImages
.GetImage( nImgId
);
233 rRet
<<= uno::Reference
< awt::XBitmap
> (VCLUnoHelper::CreateBitmap( rImage
.GetBitmapEx() ));
237 uno::Any SAL_CALL
ScLinkTargetTypeObj::getPropertyValue(const OUString
& PropertyName
)
238 throw( beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
241 OUString
aNameStr(PropertyName
);
242 if ( aNameStr
.equalsAscii( SC_UNO_LINKDISPBIT
) )
243 SetLinkTargetBitmap( aRet
, nType
);
244 else if ( aNameStr
.equalsAscii( SC_UNO_LINKDISPNAME
) )
245 aRet
<<= OUString( aName
);
250 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScLinkTargetTypeObj
)
252 //------------------------------------------------------------------------
254 ScLinkTargetsObj::ScLinkTargetsObj( const uno::Reference
< container::XNameAccess
> & rColl
) :
257 OSL_ENSURE( xCollection
.is(), "ScLinkTargetsObj: NULL" );
260 ScLinkTargetsObj::~ScLinkTargetsObj()
264 // container::XNameAccess
266 uno::Any SAL_CALL
ScLinkTargetsObj::getByName(const OUString
& aName
)
267 throw( container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
269 uno::Reference
< beans::XPropertySet
> xProp( ScUnoHelpFunctions::AnyToInterface( xCollection
->getByName(aName
) ), uno::UNO_QUERY
);
271 return uno::makeAny(xProp
);
273 throw container::NoSuchElementException();
274 // return uno::Any();
277 uno::Sequence
<OUString
> SAL_CALL
ScLinkTargetsObj::getElementNames(void) throw( uno::RuntimeException
)
279 return xCollection
->getElementNames();
282 sal_Bool SAL_CALL
ScLinkTargetsObj::hasByName(const OUString
& aName
) throw( uno::RuntimeException
)
284 return xCollection
->hasByName(aName
);
287 // container::XElementAccess
289 uno::Type SAL_CALL
ScLinkTargetsObj::getElementType(void) throw( uno::RuntimeException
)
291 return ::getCppuType((const uno::Reference
< beans::XPropertySet
>*)0);
294 sal_Bool SAL_CALL
ScLinkTargetsObj::hasElements(void) throw( uno::RuntimeException
)
296 return xCollection
->hasElements();
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */