Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sd / source / console / PresenterBitmapContainer.cxx
blobb25dacdf1101c286422ed13fd03d0e5d9ca89864
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/drawing/XPresenterHelper.hpp>
24 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
25 #include <utility>
26 #include <osl/diagnose.h>
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::uno;
31 namespace sdext::presenter {
33 //===== PresenterBitmapContainer ==============================================
35 PresenterBitmapContainer::PresenterBitmapContainer (
36 const OUString& rsConfigurationBase,
37 std::shared_ptr<PresenterBitmapContainer> xParentContainer,
38 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
39 css::uno::Reference<css::rendering::XCanvas> xCanvas,
40 css::uno::Reference<css::drawing::XPresenterHelper> xPresenterHelper)
41 : mpParentContainer(std::move(xParentContainer)),
42 mxCanvas(std::move(xCanvas)),
43 mxPresenterHelper(std::move(xPresenterHelper))
45 Initialize(rxComponentContext);
47 // Get access to the configuration.
48 PresenterConfigurationAccess aConfiguration (
49 rxComponentContext,
50 "org.openoffice.Office.PresenterScreen",
51 PresenterConfigurationAccess::READ_ONLY);
52 Reference<container::XNameAccess> xBitmapList (
53 aConfiguration.GetConfigurationNode(rsConfigurationBase),
54 UNO_QUERY_THROW);
56 LoadBitmaps(xBitmapList);
59 PresenterBitmapContainer::PresenterBitmapContainer (
60 const css::uno::Reference<css::container::XNameAccess>& rxRootNode,
61 std::shared_ptr<PresenterBitmapContainer> xParentContainer,
62 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
63 css::uno::Reference<css::rendering::XCanvas> xCanvas,
64 css::uno::Reference<css::drawing::XPresenterHelper> xPresenterHelper)
65 : mpParentContainer(std::move(xParentContainer)),
66 mxCanvas(std::move(xCanvas)),
67 mxPresenterHelper(std::move(xPresenterHelper))
69 Initialize(rxComponentContext);
71 LoadBitmaps(rxRootNode);
74 void PresenterBitmapContainer::Initialize (
75 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext)
77 if ( mxPresenterHelper.is())
78 return;
80 // Create an object that is able to load the bitmaps in a format that is
81 // supported by the canvas.
82 Reference<lang::XMultiComponentFactory> xFactory =
83 rxComponentContext->getServiceManager();
84 if ( ! xFactory.is())
85 return;
86 mxPresenterHelper.set(
87 xFactory->createInstanceWithContext(
88 "com.sun.star.drawing.PresenterHelper",
89 rxComponentContext),
90 UNO_QUERY_THROW);
93 PresenterBitmapContainer::~PresenterBitmapContainer()
95 maIconContainer.clear();
98 std::shared_ptr<PresenterBitmapContainer::BitmapDescriptor> PresenterBitmapContainer::GetBitmap (
99 const OUString& rsName) const
101 BitmapContainer::const_iterator iSet (maIconContainer.find(rsName));
102 if (iSet != maIconContainer.end())
103 return iSet->second;
104 else if (mpParentContainer != nullptr)
105 return mpParentContainer->GetBitmap(rsName);
106 else
107 return SharedBitmapDescriptor();
110 void PresenterBitmapContainer::LoadBitmaps (
111 const css::uno::Reference<css::container::XNameAccess>& rxBitmapList)
113 if ( ! mxCanvas.is())
114 return;
116 if ( ! rxBitmapList.is())
117 return;
121 // Load all button bitmaps.
122 if (rxBitmapList.is())
124 PresenterConfigurationAccess::ForAll(
125 rxBitmapList,
126 [this](OUString const& rKey, Reference<beans::XPropertySet> const& xProps)
128 this->ProcessBitmap(rKey, xProps);
132 catch (Exception&)
134 OSL_ASSERT(false);
138 std::shared_ptr<PresenterBitmapContainer::BitmapDescriptor> PresenterBitmapContainer::LoadBitmap (
139 const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
140 const OUString& rsPath,
141 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
142 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
143 const std::shared_ptr<BitmapDescriptor>& rpDefault)
145 SharedBitmapDescriptor pBitmap;
147 if (rxNode.is())
151 Reference<beans::XPropertySet> xBitmapProperties (
152 PresenterConfigurationAccess::GetConfigurationNode(rxNode, rsPath),
153 UNO_QUERY);
154 if (xBitmapProperties.is())
155 pBitmap = LoadBitmap(
156 xBitmapProperties,
157 rxPresenterHelper,
158 rxCanvas,
159 rpDefault);
161 catch (Exception&)
163 OSL_ASSERT(false);
167 return pBitmap;
170 void PresenterBitmapContainer::ProcessBitmap (
171 const OUString& rsKey,
172 const Reference<beans::XPropertySet>& rxProperties)
174 OUString sName;
175 if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties, "Name") >>= sName))
176 sName = rsKey;
178 maIconContainer[sName] = LoadBitmap(
179 rxProperties,
180 mxPresenterHelper,
181 mxCanvas,
182 SharedBitmapDescriptor());
185 std::shared_ptr<PresenterBitmapContainer::BitmapDescriptor> PresenterBitmapContainer::LoadBitmap (
186 const Reference<beans::XPropertySet>& rxProperties,
187 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
188 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
189 const std::shared_ptr<BitmapDescriptor>& rpDefault)
191 OSL_ASSERT(rxCanvas.is());
192 OSL_ASSERT(rxPresenterHelper.is());
194 SharedBitmapDescriptor pBitmap = std::make_shared<BitmapDescriptor>(rpDefault);
196 if ( ! rxProperties.is())
197 return pBitmap;
199 OUString sFileName;
201 // Load bitmaps.
202 if (PresenterConfigurationAccess::GetProperty(rxProperties, "NormalFileName") >>= sFileName)
205 pBitmap->SetBitmap(
206 BitmapDescriptor::Normal,
207 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
209 catch (Exception&)
211 if (PresenterConfigurationAccess::GetProperty(rxProperties, "MouseOverFileName") >>= sFileName)
214 pBitmap->SetBitmap(
215 BitmapDescriptor::MouseOver,
216 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
218 catch (Exception&)
220 if (PresenterConfigurationAccess::GetProperty(rxProperties, "ButtonDownFileName") >>= sFileName)
223 pBitmap->SetBitmap(
224 BitmapDescriptor::ButtonDown,
225 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
227 catch (Exception&)
229 if (PresenterConfigurationAccess::GetProperty(rxProperties, "DisabledFileName") >>= sFileName)
232 pBitmap->SetBitmap(
233 BitmapDescriptor::Disabled,
234 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
236 catch (Exception&)
238 if (PresenterConfigurationAccess::GetProperty(rxProperties, "MaskFileName") >>= sFileName)
241 pBitmap->SetBitmap(
242 BitmapDescriptor::Mask,
243 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
245 catch (Exception&)
248 PresenterConfigurationAccess::GetProperty(rxProperties, "XOffset") >>= pBitmap->mnXOffset;
249 PresenterConfigurationAccess::GetProperty(rxProperties, "YOffset") >>= pBitmap->mnYOffset;
251 PresenterConfigurationAccess::GetProperty(rxProperties, "XHotSpot") >>= pBitmap->mnXHotSpot;
252 PresenterConfigurationAccess::GetProperty(rxProperties, "YHotSpot") >>= pBitmap->mnYHotSpot;
254 PresenterConfigurationAccess::GetProperty(rxProperties, "ReplacementColor") >>= pBitmap->maReplacementColor;
256 OUString sTexturingMode;
257 if (PresenterConfigurationAccess::GetProperty(rxProperties, "HorizontalTexturingMode") >>= sTexturingMode)
258 pBitmap->meHorizontalTexturingMode = StringToTexturingMode(sTexturingMode);
259 if (PresenterConfigurationAccess::GetProperty(rxProperties, "VerticalTexturingMode") >>= sTexturingMode)
260 pBitmap->meVerticalTexturingMode = StringToTexturingMode(sTexturingMode);
262 return pBitmap;
265 PresenterBitmapContainer::BitmapDescriptor::TexturingMode
266 PresenterBitmapContainer::StringToTexturingMode (std::u16string_view rsTexturingMode)
268 if (rsTexturingMode == u"Once")
269 return PresenterBitmapContainer::BitmapDescriptor::Once;
270 else if (rsTexturingMode == u"Repeat")
271 return PresenterBitmapContainer::BitmapDescriptor::Repeat;
272 else if (rsTexturingMode == u"Stretch")
273 return PresenterBitmapContainer::BitmapDescriptor::Stretch;
274 else
275 return PresenterBitmapContainer::BitmapDescriptor::Once;
278 //===== PresenterBitmapContainer::BitmapSet ===================================
280 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor()
281 : mnWidth(0),
282 mnHeight(0),
283 mnXOffset(0),
284 mnYOffset(0),
285 mnXHotSpot(0),
286 mnYHotSpot(0),
287 maReplacementColor(0x00000000),
288 meHorizontalTexturingMode(Once),
289 meVerticalTexturingMode(Once)
293 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (
294 const std::shared_ptr<PresenterBitmapContainer::BitmapDescriptor>& rpDefault)
295 : mnWidth(0),
296 mnHeight(0),
297 mnXOffset(0),
298 mnYOffset(0),
299 mnXHotSpot(0),
300 mnYHotSpot(0),
301 maReplacementColor(0x00000000),
302 meHorizontalTexturingMode(Once),
303 meVerticalTexturingMode(Once)
305 if (rpDefault == nullptr)
306 return;
308 mnWidth = rpDefault->mnWidth;
309 mnHeight = rpDefault->mnHeight;
310 mnXOffset = rpDefault->mnXOffset;
311 mnYOffset = rpDefault->mnYOffset;
312 mnXHotSpot = rpDefault->mnXHotSpot;
313 mnYHotSpot = rpDefault->mnYHotSpot;
314 maReplacementColor = rpDefault->maReplacementColor;
315 meHorizontalTexturingMode = rpDefault->meHorizontalTexturingMode;
316 meVerticalTexturingMode = rpDefault->meVerticalTexturingMode;
317 mxNormalBitmap = rpDefault->mxNormalBitmap;
318 mxMouseOverBitmap = rpDefault->mxMouseOverBitmap;
319 mxButtonDownBitmap = rpDefault->mxButtonDownBitmap;
320 mxDisabledBitmap = rpDefault->mxDisabledBitmap;
321 mxMaskBitmap = rpDefault->mxMaskBitmap;
324 const css::uno::Reference<css::rendering::XBitmap>&
325 PresenterBitmapContainer::BitmapDescriptor::GetNormalBitmap() const
327 return mxNormalBitmap;
330 css::uno::Reference<css::rendering::XBitmap> const &
331 PresenterBitmapContainer::BitmapDescriptor::GetBitmap(const Mode eMode) const
333 switch (eMode)
335 case Normal:
336 default:
337 return mxNormalBitmap;
339 case MouseOver:
340 if (mxMouseOverBitmap.is())
341 return mxMouseOverBitmap;
342 else
343 return mxNormalBitmap;
345 case ButtonDown:
346 if (mxButtonDownBitmap.is())
347 return mxButtonDownBitmap;
348 else
349 return mxNormalBitmap;
351 case Disabled:
352 if (mxDisabledBitmap.is())
353 return mxDisabledBitmap;
354 else
355 return mxNormalBitmap;
357 case Mask:
358 return mxMaskBitmap;
362 void PresenterBitmapContainer::BitmapDescriptor::SetBitmap (
363 const Mode eMode,
364 const css::uno::Reference<css::rendering::XBitmap>& rxBitmap)
366 switch (eMode)
368 case Normal:
369 default:
370 mxNormalBitmap = rxBitmap;
371 if (mxNormalBitmap.is())
373 const geometry::IntegerSize2D aSize (mxNormalBitmap->getSize());
374 mnWidth = aSize.Width;
375 mnHeight = aSize.Height;
377 break;
379 case MouseOver:
380 mxMouseOverBitmap = rxBitmap;
381 break;
383 case ButtonDown:
384 mxButtonDownBitmap = rxBitmap;
385 break;
387 case Disabled:
388 mxDisabledBitmap = rxBitmap;
389 break;
391 case Mask:
392 mxMaskBitmap = rxBitmap;
393 break;
397 } // end of namespace ::sdext::presenter
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */