LibreOffice Module sc (master) 1
targuno.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
23#include <svl/itemprop.hxx>
24#include <svl/hint.hxx>
25#include <utility>
26#include <vcl/svapp.hxx>
27#include <osl/diagnose.h>
28#include <com/sun/star/awt/XBitmap.hpp>
29#include <com/sun/star/beans/PropertyAttribute.hpp>
30
31#include <targuno.hxx>
32#include <miscuno.hxx>
33#include <docuno.hxx>
34#include <datauno.hxx>
35#include <nameuno.hxx>
36#include <docsh.hxx>
37#include <content.hxx>
38#include <scresid.hxx>
39#include <strings.hrc>
40#include <bitmaps.hlst>
41#include <unonames.hxx>
42
43using namespace ::com::sun::star;
44
46{
47 SCSTR_CONTENT_TABLE, // SC_LINKTARGETTYPE_SHEET
48 SCSTR_CONTENT_RANGENAME, // SC_LINKTARGETTYPE_RANGENAME
49 SCSTR_CONTENT_DBAREA // SC_LINKTARGETTYPE_DBAREA
50};
51
53{
54 static const SfxItemPropertyMapEntry aLinkTargetMap_Impl[] =
55 {
56 { SC_UNO_LINKDISPBIT, 0, cppu::UnoType<awt::XBitmap>::get(), beans::PropertyAttribute::READONLY, 0 },
57 { SC_UNO_LINKDISPNAME, 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0 },
58 };
59 return aLinkTargetMap_Impl;
60}
61
62// service for ScLinkTargetTypeObj is not defined
63// must not support document::LinkTarget because the target type cannot be used as a target
64
65SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypesObj, "ScLinkTargetTypesObj", "com.sun.star.document.LinkTargets" )
66SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypeObj, "ScLinkTargetTypeObj", "com.sun.star.document.LinkTargetSupplier" )
67SC_SIMPLE_SERVICE_INFO( ScLinkTargetsObj, "ScLinkTargetsObj", "com.sun.star.document.LinkTargets" )
68
70 pDocShell( pDocSh )
71{
72 pDocShell->GetDocument().AddUnoObject(*this);
73
74 for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
75 aNames[i] = ScResId(aTypeResIds[i]);
76}
77
79{
81
82 if (pDocShell)
84}
85
87{
88 if ( rHint.GetId() == SfxHintId::Dying )
89 pDocShell = nullptr; // document gone
90}
91
92// container::XNameAccess
93
94uno::Any SAL_CALL ScLinkTargetTypesObj::getByName(const OUString& aName)
95{
96 if (pDocShell)
97 {
98 for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
99 if ( aNames[i] == aName )
100 return uno::Any(uno::Reference< beans::XPropertySet >(new ScLinkTargetTypeObj( pDocShell, i )));
101 }
102
103 throw container::NoSuchElementException();
104}
105
106uno::Sequence<OUString> SAL_CALL ScLinkTargetTypesObj::getElementNames()
107{
108 uno::Sequence<OUString> aRet(SC_LINKTARGETTYPE_COUNT);
109 OUString* pArray = aRet.getArray();
110 for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
111 pArray[i] = aNames[i];
112 return aRet;
113}
114
115sal_Bool SAL_CALL ScLinkTargetTypesObj::hasByName(const OUString& aName)
116{
117 for (const auto & i : aNames)
118 if ( i == aName )
119 return true;
120 return false;
121}
122
123// container::XElementAccess
124
126{
128}
129
131{
132 return true;
133}
134
136 pDocShell( pDocSh ),
137 nType( nT )
138{
141}
142
144{
146
147 if (pDocShell)
149}
150
152{
153 if ( rHint.GetId() == SfxHintId::Dying )
154 pDocShell = nullptr; // document gone
155}
156
157// document::XLinkTargetSupplier
158
159uno::Reference< container::XNameAccess > SAL_CALL ScLinkTargetTypeObj::getLinks()
160{
161 uno::Reference< container::XNameAccess > xCollection;
162
163 if ( pDocShell )
164 {
165 switch ( nType )
166 {
168 xCollection.set(new ScTableSheetsObj(pDocShell));
169 break;
171 xCollection.set(new ScGlobalNamedRangesObj(pDocShell));
172 break;
174 xCollection.set(new ScDatabaseRangesObj(pDocShell));
175 break;
176 default:
177 OSL_FAIL("invalid type");
178 }
179 }
180
181 // wrap collection in ScLinkTargetsObj because service document::LinkTargets requires
182 // beans::XPropertySet as ElementType in container::XNameAccess.
183 if ( xCollection.is() )
184 return new ScLinkTargetsObj( xCollection );
185 return nullptr;
186}
187
188// beans::XPropertySet
189
190uno::Reference< beans::XPropertySetInfo > SAL_CALL ScLinkTargetTypeObj::getPropertySetInfo()
191{
192 static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( lcl_GetLinkTargetMap() ));
193 return aRef;
194}
195
196void SAL_CALL ScLinkTargetTypeObj::setPropertyValue(const OUString& /* aPropertyName */,
197 const uno::Any& /* aValue */)
198{
199 // everything is read-only
201}
202
203constexpr rtl::OUStringConstExpr aContentBmps[]=
204{
205 RID_BMP_CONTENT_TABLE,
206 RID_BMP_CONTENT_RANGENAME,
207 RID_BMP_CONTENT_DBAREA,
208 RID_BMP_CONTENT_GRAPHIC,
209 RID_BMP_CONTENT_OLEOBJECT,
210 RID_BMP_CONTENT_NOTE,
211 RID_BMP_CONTENT_AREALINK,
212 RID_BMP_CONTENT_DRAWING
213};
214
216{
218 switch ( nType )
219 {
221 nImgId = ScContentId::TABLE;
222 break;
224 nImgId = ScContentId::RANGENAME;
225 break;
227 nImgId = ScContentId::DBAREA;
228 break;
229 }
230 if (nImgId != ScContentId::ROOT)
231 {
232 BitmapEx aBitmapEx { OUString(aContentBmps[static_cast<int>(nImgId) -1 ]) };
233 rRet <<= VCLUnoHelper::CreateBitmap(aBitmapEx);
234 }
235}
236
237uno::Any SAL_CALL ScLinkTargetTypeObj::getPropertyValue(const OUString& PropertyName)
238{
239 uno::Any aRet;
240 if ( PropertyName == SC_UNO_LINKDISPBIT )
241 SetLinkTargetBitmap( aRet, nType );
242 else if ( PropertyName == SC_UNO_LINKDISPNAME )
243 aRet <<= aName;
244
245 return aRet;
246}
247
249
250ScLinkTargetsObj::ScLinkTargetsObj( uno::Reference< container::XNameAccess > xColl ) :
251 xCollection(std::move( xColl ))
252{
253 OSL_ENSURE( xCollection.is(), "ScLinkTargetsObj: NULL" );
254}
255
257{
258}
259
260// container::XNameAccess
261
262uno::Any SAL_CALL ScLinkTargetsObj::getByName(const OUString& aName)
263{
264 uno::Reference<beans::XPropertySet> xProp(xCollection->getByName(aName), uno::UNO_QUERY);
265 if (xProp.is())
266 return uno::Any(xProp);
267
268 throw container::NoSuchElementException();
269}
270
271uno::Sequence<OUString> SAL_CALL ScLinkTargetsObj::getElementNames()
272{
273 return xCollection->getElementNames();
274}
275
276sal_Bool SAL_CALL ScLinkTargetsObj::hasByName(const OUString& aName)
277{
278 return xCollection->hasByName(aName);
279}
280
281// container::XElementAccess
282
284{
286}
287
289{
290 return xCollection->hasElements();
291}
292
293/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const ScDocument & GetDocument() const
Definition: docsh.hxx:219
void AddUnoObject(SfxListener &rObject)
Definition: documen3.cxx:901
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:909
virtual ~ScLinkTargetTypeObj() override
Definition: targuno.cxx:143
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: targuno.cxx:151
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: targuno.cxx:237
ScDocShell * pDocShell
Definition: targuno.hxx:82
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: targuno.cxx:196
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getLinks() override
Definition: targuno.cxx:159
static void SetLinkTargetBitmap(css::uno::Any &rRet, sal_uInt16 nType)
Definition: targuno.cxx:215
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: targuno.cxx:190
ScLinkTargetTypeObj(ScDocShell *pDocSh, sal_uInt16 nT)
Definition: targuno.cxx:135
sal_uInt16 nType
Definition: targuno.hxx:83
Graphic / OleObject (need separate collections!)
Definition: targuno.hxx:49
virtual ~ScLinkTargetTypesObj() override
Definition: targuno.cxx:78
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: targuno.cxx:106
ScDocShell * pDocShell
Definition: targuno.hxx:51
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
Definition: targuno.cxx:94
OUString aNames[SC_LINKTARGETTYPE_COUNT]
Definition: targuno.hxx:52
virtual sal_Bool SAL_CALL hasElements() override
Definition: targuno.cxx:130
virtual css::uno::Type SAL_CALL getElementType() override
Definition: targuno.cxx:125
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: targuno.cxx:86
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
Definition: targuno.cxx:115
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: targuno.cxx:271
virtual css::uno::Type SAL_CALL getElementType() override
Definition: targuno.cxx:283
virtual sal_Bool SAL_CALL hasElements() override
Definition: targuno.cxx:288
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
Definition: targuno.cxx:262
virtual ~ScLinkTargetsObj() override
Definition: targuno.cxx:256
css::uno::Reference< css::container::XNameAccess > xCollection
Definition: targuno.hxx:122
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
Definition: targuno.cxx:276
SfxHintId GetId() const
static css::uno::Reference< css::awt::XBitmap > CreateBitmap(const BitmapEx &rBitmap)
css::uno::Type const & get()
ScContentId
Definition: content.hxx:35
OUString aName
#define SC_SIMPLE_SERVICE_INFO(ClassName, ClassNameAscii, ServiceAscii)
Definition: miscuno.hxx:63
#define SC_IMPL_DUMMY_PROPERTY_LISTENER(ClassName)
Definition: miscuno.hxx:72
int i
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
constexpr rtl::OUStringConstExpr aContentBmps[]
Definition: targuno.cxx:203
const TranslateId aTypeResIds[SC_LINKTARGETTYPE_COUNT]
Definition: targuno.cxx:45
static o3tl::span< const SfxItemPropertyMapEntry > lcl_GetLinkTargetMap()
Definition: targuno.cxx:52
#define SC_LINKTARGETTYPE_RANGENAME
Definition: targuno.hxx:36
#define SC_LINKTARGETTYPE_SHEET
Definition: targuno.hxx:35
#define SC_LINKTARGETTYPE_DBAREA
Definition: targuno.hxx:37
#define SC_LINKTARGETTYPE_COUNT
Definition: targuno.hxx:39
unsigned char sal_Bool
constexpr OUStringLiteral SC_UNO_LINKDISPBIT
Definition: unonames.hxx:197
constexpr OUStringLiteral SC_UNO_LINKDISPNAME
Definition: unonames.hxx:198