Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sdext / source / presenter / PresenterBitmapContainer.cxx
blobea39f17e2588f20478645a47e9eec1016df50753
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 "PresenterBitmapContainer.hxx"
21 #include "PresenterConfigurationAccess.hxx"
23 #include <com/sun/star/deployment/XPackageInformationProvider.hpp>
24 #include <com/sun/star/drawing/XPresenterHelper.hpp>
25 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
26 #include <com/sun/star/rendering/CompositeOperation.hpp>
27 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
28 #include <osl/diagnose.h>
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::uno;
32 using namespace ::std;
34 namespace sdext { namespace presenter {
36 //===== PresenterBitmapContainer ==============================================
38 PresenterBitmapContainer::PresenterBitmapContainer (
39 const OUString& rsConfigurationBase,
40 const std::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
41 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
42 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
43 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper)
44 : mpParentContainer(rpParentContainer),
45 maIconContainer(),
46 mxCanvas(rxCanvas),
47 mxPresenterHelper(rxPresenterHelper)
49 Initialize(rxComponentContext);
51 // Get access to the configuration.
52 PresenterConfigurationAccess aConfiguration (
53 rxComponentContext,
54 "org.openoffice.Office.PresenterScreen",
55 PresenterConfigurationAccess::READ_ONLY);
56 Reference<container::XNameAccess> xBitmapList (
57 aConfiguration.GetConfigurationNode(rsConfigurationBase),
58 UNO_QUERY_THROW);
60 LoadBitmaps(xBitmapList);
63 PresenterBitmapContainer::PresenterBitmapContainer (
64 const css::uno::Reference<css::container::XNameAccess>& rxRootNode,
65 const std::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
66 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
67 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
68 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper)
69 : mpParentContainer(rpParentContainer),
70 maIconContainer(),
71 mxCanvas(rxCanvas),
72 mxPresenterHelper(rxPresenterHelper)
74 Initialize(rxComponentContext);
76 LoadBitmaps(rxRootNode);
79 void PresenterBitmapContainer::Initialize (
80 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext)
82 if ( ! mxPresenterHelper.is())
84 // Create an object that is able to load the bitmaps in a format that is
85 // supported by the canvas.
86 Reference<lang::XMultiComponentFactory> xFactory (
87 rxComponentContext->getServiceManager(), UNO_QUERY);
88 if ( ! xFactory.is())
89 return;
90 mxPresenterHelper.set(
91 xFactory->createInstanceWithContext(
92 "com.sun.star.drawing.PresenterHelper",
93 rxComponentContext),
94 UNO_QUERY_THROW);
98 PresenterBitmapContainer::~PresenterBitmapContainer()
100 maIconContainer.clear();
103 SharedBitmapDescriptor PresenterBitmapContainer::GetBitmap (
104 const OUString& rsName) const
106 BitmapContainer::const_iterator iSet (maIconContainer.find(rsName));
107 if (iSet != maIconContainer.end())
108 return iSet->second;
109 else if (mpParentContainer.get() != nullptr)
110 return mpParentContainer->GetBitmap(rsName);
111 else
112 return SharedBitmapDescriptor();
115 void PresenterBitmapContainer::LoadBitmaps (
116 const css::uno::Reference<css::container::XNameAccess>& rxBitmapList)
118 if ( ! mxCanvas.is())
119 return;
121 if ( ! rxBitmapList.is())
122 return;
126 // Load all button bitmaps.
127 if (rxBitmapList.is())
129 PresenterConfigurationAccess::ForAll(
130 rxBitmapList,
131 [this](OUString const& rKey, Reference<beans::XPropertySet> const& xProps)
133 this->ProcessBitmap(rKey, xProps);
137 catch (Exception&)
139 OSL_ASSERT(false);
143 SharedBitmapDescriptor PresenterBitmapContainer::LoadBitmap (
144 const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
145 const OUString& rsPath,
146 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
147 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
148 const SharedBitmapDescriptor& rpDefault)
150 SharedBitmapDescriptor pBitmap;
152 if (rxNode.is())
156 Reference<beans::XPropertySet> xBitmapProperties (
157 PresenterConfigurationAccess::GetConfigurationNode(rxNode, rsPath),
158 UNO_QUERY);
159 if (xBitmapProperties.is())
160 pBitmap = LoadBitmap(
161 xBitmapProperties,
162 rxPresenterHelper,
163 rxCanvas,
164 rpDefault);
166 catch (Exception&)
168 OSL_ASSERT(false);
172 return pBitmap;
175 void PresenterBitmapContainer::ProcessBitmap (
176 const OUString& rsKey,
177 const Reference<beans::XPropertySet>& rxProperties)
179 OUString sName;
180 if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties, "Name") >>= sName))
181 sName = rsKey;
183 maIconContainer[sName] = LoadBitmap(
184 rxProperties,
185 mxPresenterHelper,
186 mxCanvas,
187 SharedBitmapDescriptor());
190 SharedBitmapDescriptor PresenterBitmapContainer::LoadBitmap (
191 const Reference<beans::XPropertySet>& rxProperties,
192 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
193 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
194 const SharedBitmapDescriptor& rpDefault)
196 OSL_ASSERT(rxCanvas.is());
197 OSL_ASSERT(rxPresenterHelper.is());
199 SharedBitmapDescriptor pBitmap (new BitmapDescriptor(rpDefault));
201 if ( ! rxProperties.is())
202 return pBitmap;
204 OUString sFileName;
206 // Load bitmaps.
207 if (PresenterConfigurationAccess::GetProperty(rxProperties, "NormalFileName") >>= sFileName)
210 pBitmap->SetBitmap(
211 BitmapDescriptor::Normal,
212 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
214 catch (Exception&)
216 if (PresenterConfigurationAccess::GetProperty(rxProperties, "MouseOverFileName") >>= sFileName)
219 pBitmap->SetBitmap(
220 BitmapDescriptor::MouseOver,
221 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
223 catch (Exception&)
225 if (PresenterConfigurationAccess::GetProperty(rxProperties, "ButtonDownFileName") >>= sFileName)
228 pBitmap->SetBitmap(
229 BitmapDescriptor::ButtonDown,
230 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
232 catch (Exception&)
234 if (PresenterConfigurationAccess::GetProperty(rxProperties, "DisabledFileName") >>= sFileName)
237 pBitmap->SetBitmap(
238 BitmapDescriptor::Disabled,
239 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
241 catch (Exception&)
243 if (PresenterConfigurationAccess::GetProperty(rxProperties, "MaskFileName") >>= sFileName)
246 pBitmap->SetBitmap(
247 BitmapDescriptor::Mask,
248 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
250 catch (Exception&)
253 PresenterConfigurationAccess::GetProperty(rxProperties, "XOffset") >>= pBitmap->mnXOffset;
254 PresenterConfigurationAccess::GetProperty(rxProperties, "YOffset") >>= pBitmap->mnYOffset;
256 PresenterConfigurationAccess::GetProperty(rxProperties, "XHotSpot") >>= pBitmap->mnXHotSpot;
257 PresenterConfigurationAccess::GetProperty(rxProperties, "YHotSpot") >>= pBitmap->mnYHotSpot;
259 PresenterConfigurationAccess::GetProperty(rxProperties, "ReplacementColor") >>= pBitmap->maReplacementColor;
261 OUString sTexturingMode;
262 if (PresenterConfigurationAccess::GetProperty(rxProperties, "HorizontalTexturingMode") >>= sTexturingMode)
263 pBitmap->meHorizontalTexturingMode = StringToTexturingMode(sTexturingMode);
264 if (PresenterConfigurationAccess::GetProperty(rxProperties, "VerticalTexturingMode") >>= sTexturingMode)
265 pBitmap->meVerticalTexturingMode = StringToTexturingMode(sTexturingMode);
267 return pBitmap;
270 PresenterBitmapContainer::BitmapDescriptor::TexturingMode
271 PresenterBitmapContainer::StringToTexturingMode (const OUString& rsTexturingMode)
273 if (rsTexturingMode == "Once")
274 return PresenterBitmapContainer::BitmapDescriptor::Once;
275 else if (rsTexturingMode == "Repeat")
276 return PresenterBitmapContainer::BitmapDescriptor::Repeat;
277 else if (rsTexturingMode == "Stretch")
278 return PresenterBitmapContainer::BitmapDescriptor::Stretch;
279 else
280 return PresenterBitmapContainer::BitmapDescriptor::Once;
283 //===== PresenterBitmapContainer::BitmapSet ===================================
285 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor()
286 : mnWidth(0),
287 mnHeight(0),
288 mnXOffset(0),
289 mnYOffset(0),
290 mnXHotSpot(0),
291 mnYHotSpot(0),
292 maReplacementColor(0x00000000),
293 meHorizontalTexturingMode(Once),
294 meVerticalTexturingMode(Once),
295 mxNormalBitmap(),
296 mxMouseOverBitmap(),
297 mxButtonDownBitmap(),
298 mxDisabledBitmap(),
299 mxMaskBitmap()
303 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (
304 const std::shared_ptr<PresenterBitmapContainer::BitmapDescriptor>& rpDefault)
305 : mnWidth(0),
306 mnHeight(0),
307 mnXOffset(0),
308 mnYOffset(0),
309 mnXHotSpot(0),
310 mnYHotSpot(0),
311 maReplacementColor(0x00000000),
312 meHorizontalTexturingMode(Once),
313 meVerticalTexturingMode(Once),
314 mxNormalBitmap(),
315 mxMouseOverBitmap(),
316 mxButtonDownBitmap(),
317 mxDisabledBitmap(),
318 mxMaskBitmap()
320 if (rpDefault.get() != nullptr)
322 mnWidth = rpDefault->mnWidth;
323 mnHeight = rpDefault->mnHeight;
324 mnXOffset = rpDefault->mnXOffset;
325 mnYOffset = rpDefault->mnYOffset;
326 mnXHotSpot = rpDefault->mnXHotSpot;
327 mnYHotSpot = rpDefault->mnYHotSpot;
328 maReplacementColor = rpDefault->maReplacementColor;
329 meHorizontalTexturingMode = rpDefault->meHorizontalTexturingMode;
330 meVerticalTexturingMode = rpDefault->meVerticalTexturingMode;
331 mxNormalBitmap = rpDefault->mxNormalBitmap;
332 mxMouseOverBitmap = rpDefault->mxMouseOverBitmap;
333 mxButtonDownBitmap = rpDefault->mxButtonDownBitmap;
334 mxDisabledBitmap = rpDefault->mxDisabledBitmap;
335 mxMaskBitmap = rpDefault->mxMaskBitmap;
339 const css::uno::Reference<css::rendering::XBitmap>&
340 PresenterBitmapContainer::BitmapDescriptor::GetNormalBitmap() const
342 return mxNormalBitmap;
345 css::uno::Reference<css::rendering::XBitmap> const &
346 PresenterBitmapContainer::BitmapDescriptor::GetBitmap(const Mode eMode) const
348 switch (eMode)
350 case Normal:
351 default:
352 return mxNormalBitmap;
354 case MouseOver:
355 if (mxMouseOverBitmap.is())
356 return mxMouseOverBitmap;
357 else
358 return mxNormalBitmap;
360 case ButtonDown:
361 if (mxButtonDownBitmap.is())
362 return mxButtonDownBitmap;
363 else
364 return mxNormalBitmap;
366 case Disabled:
367 if (mxDisabledBitmap.is())
368 return mxDisabledBitmap;
369 else
370 return mxNormalBitmap;
372 case Mask:
373 return mxMaskBitmap;
377 void PresenterBitmapContainer::BitmapDescriptor::SetBitmap (
378 const Mode eMode,
379 const css::uno::Reference<css::rendering::XBitmap>& rxBitmap)
381 switch (eMode)
383 case Normal:
384 default:
385 mxNormalBitmap = rxBitmap;
386 if (mxNormalBitmap.is())
388 const geometry::IntegerSize2D aSize (mxNormalBitmap->getSize());
389 mnWidth = aSize.Width;
390 mnHeight = aSize.Height;
392 break;
394 case MouseOver:
395 mxMouseOverBitmap = rxBitmap;
396 break;
398 case ButtonDown:
399 mxButtonDownBitmap = rxBitmap;
400 break;
402 case Disabled:
403 mxDisabledBitmap = rxBitmap;
404 break;
406 case Mask:
407 mxMaskBitmap = rxBitmap;
408 break;
412 } } // end of namespace ::sdext::presenter
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */