vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / sdext / source / presenter / PresenterBitmapContainer.cxx
blobea2ff23a87597aebded74245ceb3dc9d573a75c5
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 <osl/diagnose.h>
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::uno;
29 using namespace ::std;
31 namespace sdext { namespace presenter {
33 //===== PresenterBitmapContainer ==============================================
35 PresenterBitmapContainer::PresenterBitmapContainer (
36 const OUString& rsConfigurationBase,
37 const std::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
38 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
39 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
40 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper)
41 : mpParentContainer(rpParentContainer),
42 maIconContainer(),
43 mxCanvas(rxCanvas),
44 mxPresenterHelper(rxPresenterHelper)
46 Initialize(rxComponentContext);
48 // Get access to the configuration.
49 PresenterConfigurationAccess aConfiguration (
50 rxComponentContext,
51 "org.openoffice.Office.PresenterScreen",
52 PresenterConfigurationAccess::READ_ONLY);
53 Reference<container::XNameAccess> xBitmapList (
54 aConfiguration.GetConfigurationNode(rsConfigurationBase),
55 UNO_QUERY_THROW);
57 LoadBitmaps(xBitmapList);
60 PresenterBitmapContainer::PresenterBitmapContainer (
61 const css::uno::Reference<css::container::XNameAccess>& rxRootNode,
62 const std::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
63 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
64 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
65 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper)
66 : mpParentContainer(rpParentContainer),
67 maIconContainer(),
68 mxCanvas(rxCanvas),
69 mxPresenterHelper(rxPresenterHelper)
71 Initialize(rxComponentContext);
73 LoadBitmaps(rxRootNode);
76 void PresenterBitmapContainer::Initialize (
77 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext)
79 if ( mxPresenterHelper.is())
80 return;
82 // Create an object that is able to load the bitmaps in a format that is
83 // supported by the canvas.
84 Reference<lang::XMultiComponentFactory> xFactory =
85 rxComponentContext->getServiceManager();
86 if ( ! xFactory.is())
87 return;
88 mxPresenterHelper.set(
89 xFactory->createInstanceWithContext(
90 "com.sun.star.drawing.PresenterHelper",
91 rxComponentContext),
92 UNO_QUERY_THROW);
95 PresenterBitmapContainer::~PresenterBitmapContainer()
97 maIconContainer.clear();
100 std::shared_ptr<PresenterBitmapContainer::BitmapDescriptor> PresenterBitmapContainer::GetBitmap (
101 const OUString& rsName) const
103 BitmapContainer::const_iterator iSet (maIconContainer.find(rsName));
104 if (iSet != maIconContainer.end())
105 return iSet->second;
106 else if (mpParentContainer != nullptr)
107 return mpParentContainer->GetBitmap(rsName);
108 else
109 return SharedBitmapDescriptor();
112 void PresenterBitmapContainer::LoadBitmaps (
113 const css::uno::Reference<css::container::XNameAccess>& rxBitmapList)
115 if ( ! mxCanvas.is())
116 return;
118 if ( ! rxBitmapList.is())
119 return;
123 // Load all button bitmaps.
124 if (rxBitmapList.is())
126 PresenterConfigurationAccess::ForAll(
127 rxBitmapList,
128 [this](OUString const& rKey, Reference<beans::XPropertySet> const& xProps)
130 this->ProcessBitmap(rKey, xProps);
134 catch (Exception&)
136 OSL_ASSERT(false);
140 std::shared_ptr<PresenterBitmapContainer::BitmapDescriptor> PresenterBitmapContainer::LoadBitmap (
141 const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
142 const OUString& rsPath,
143 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
144 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
145 const std::shared_ptr<BitmapDescriptor>& rpDefault)
147 SharedBitmapDescriptor pBitmap;
149 if (rxNode.is())
153 Reference<beans::XPropertySet> xBitmapProperties (
154 PresenterConfigurationAccess::GetConfigurationNode(rxNode, rsPath),
155 UNO_QUERY);
156 if (xBitmapProperties.is())
157 pBitmap = LoadBitmap(
158 xBitmapProperties,
159 rxPresenterHelper,
160 rxCanvas,
161 rpDefault);
163 catch (Exception&)
165 OSL_ASSERT(false);
169 return pBitmap;
172 void PresenterBitmapContainer::ProcessBitmap (
173 const OUString& rsKey,
174 const Reference<beans::XPropertySet>& rxProperties)
176 OUString sName;
177 if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties, "Name") >>= sName))
178 sName = rsKey;
180 maIconContainer[sName] = LoadBitmap(
181 rxProperties,
182 mxPresenterHelper,
183 mxCanvas,
184 SharedBitmapDescriptor());
187 std::shared_ptr<PresenterBitmapContainer::BitmapDescriptor> PresenterBitmapContainer::LoadBitmap (
188 const Reference<beans::XPropertySet>& rxProperties,
189 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
190 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
191 const std::shared_ptr<BitmapDescriptor>& rpDefault)
193 OSL_ASSERT(rxCanvas.is());
194 OSL_ASSERT(rxPresenterHelper.is());
196 SharedBitmapDescriptor pBitmap (new BitmapDescriptor(rpDefault));
198 if ( ! rxProperties.is())
199 return pBitmap;
201 OUString sFileName;
203 // Load bitmaps.
204 if (PresenterConfigurationAccess::GetProperty(rxProperties, "NormalFileName") >>= sFileName)
207 pBitmap->SetBitmap(
208 BitmapDescriptor::Normal,
209 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
211 catch (Exception&)
213 if (PresenterConfigurationAccess::GetProperty(rxProperties, "MouseOverFileName") >>= sFileName)
216 pBitmap->SetBitmap(
217 BitmapDescriptor::MouseOver,
218 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
220 catch (Exception&)
222 if (PresenterConfigurationAccess::GetProperty(rxProperties, "ButtonDownFileName") >>= sFileName)
225 pBitmap->SetBitmap(
226 BitmapDescriptor::ButtonDown,
227 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
229 catch (Exception&)
231 if (PresenterConfigurationAccess::GetProperty(rxProperties, "DisabledFileName") >>= sFileName)
234 pBitmap->SetBitmap(
235 BitmapDescriptor::Disabled,
236 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
238 catch (Exception&)
240 if (PresenterConfigurationAccess::GetProperty(rxProperties, "MaskFileName") >>= sFileName)
243 pBitmap->SetBitmap(
244 BitmapDescriptor::Mask,
245 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
247 catch (Exception&)
250 PresenterConfigurationAccess::GetProperty(rxProperties, "XOffset") >>= pBitmap->mnXOffset;
251 PresenterConfigurationAccess::GetProperty(rxProperties, "YOffset") >>= pBitmap->mnYOffset;
253 PresenterConfigurationAccess::GetProperty(rxProperties, "XHotSpot") >>= pBitmap->mnXHotSpot;
254 PresenterConfigurationAccess::GetProperty(rxProperties, "YHotSpot") >>= pBitmap->mnYHotSpot;
256 PresenterConfigurationAccess::GetProperty(rxProperties, "ReplacementColor") >>= pBitmap->maReplacementColor;
258 OUString sTexturingMode;
259 if (PresenterConfigurationAccess::GetProperty(rxProperties, "HorizontalTexturingMode") >>= sTexturingMode)
260 pBitmap->meHorizontalTexturingMode = StringToTexturingMode(sTexturingMode);
261 if (PresenterConfigurationAccess::GetProperty(rxProperties, "VerticalTexturingMode") >>= sTexturingMode)
262 pBitmap->meVerticalTexturingMode = StringToTexturingMode(sTexturingMode);
264 return pBitmap;
267 PresenterBitmapContainer::BitmapDescriptor::TexturingMode
268 PresenterBitmapContainer::StringToTexturingMode (const OUString& rsTexturingMode)
270 if (rsTexturingMode == "Once")
271 return PresenterBitmapContainer::BitmapDescriptor::Once;
272 else if (rsTexturingMode == "Repeat")
273 return PresenterBitmapContainer::BitmapDescriptor::Repeat;
274 else if (rsTexturingMode == "Stretch")
275 return PresenterBitmapContainer::BitmapDescriptor::Stretch;
276 else
277 return PresenterBitmapContainer::BitmapDescriptor::Once;
280 //===== PresenterBitmapContainer::BitmapSet ===================================
282 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor()
283 : mnWidth(0),
284 mnHeight(0),
285 mnXOffset(0),
286 mnYOffset(0),
287 mnXHotSpot(0),
288 mnYHotSpot(0),
289 maReplacementColor(0x00000000),
290 meHorizontalTexturingMode(Once),
291 meVerticalTexturingMode(Once),
292 mxNormalBitmap(),
293 mxMouseOverBitmap(),
294 mxButtonDownBitmap(),
295 mxDisabledBitmap(),
296 mxMaskBitmap()
300 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (
301 const std::shared_ptr<PresenterBitmapContainer::BitmapDescriptor>& rpDefault)
302 : mnWidth(0),
303 mnHeight(0),
304 mnXOffset(0),
305 mnYOffset(0),
306 mnXHotSpot(0),
307 mnYHotSpot(0),
308 maReplacementColor(0x00000000),
309 meHorizontalTexturingMode(Once),
310 meVerticalTexturingMode(Once),
311 mxNormalBitmap(),
312 mxMouseOverBitmap(),
313 mxButtonDownBitmap(),
314 mxDisabledBitmap(),
315 mxMaskBitmap()
317 if (rpDefault == nullptr)
318 return;
320 mnWidth = rpDefault->mnWidth;
321 mnHeight = rpDefault->mnHeight;
322 mnXOffset = rpDefault->mnXOffset;
323 mnYOffset = rpDefault->mnYOffset;
324 mnXHotSpot = rpDefault->mnXHotSpot;
325 mnYHotSpot = rpDefault->mnYHotSpot;
326 maReplacementColor = rpDefault->maReplacementColor;
327 meHorizontalTexturingMode = rpDefault->meHorizontalTexturingMode;
328 meVerticalTexturingMode = rpDefault->meVerticalTexturingMode;
329 mxNormalBitmap = rpDefault->mxNormalBitmap;
330 mxMouseOverBitmap = rpDefault->mxMouseOverBitmap;
331 mxButtonDownBitmap = rpDefault->mxButtonDownBitmap;
332 mxDisabledBitmap = rpDefault->mxDisabledBitmap;
333 mxMaskBitmap = rpDefault->mxMaskBitmap;
336 const css::uno::Reference<css::rendering::XBitmap>&
337 PresenterBitmapContainer::BitmapDescriptor::GetNormalBitmap() const
339 return mxNormalBitmap;
342 css::uno::Reference<css::rendering::XBitmap> const &
343 PresenterBitmapContainer::BitmapDescriptor::GetBitmap(const Mode eMode) const
345 switch (eMode)
347 case Normal:
348 default:
349 return mxNormalBitmap;
351 case MouseOver:
352 if (mxMouseOverBitmap.is())
353 return mxMouseOverBitmap;
354 else
355 return mxNormalBitmap;
357 case ButtonDown:
358 if (mxButtonDownBitmap.is())
359 return mxButtonDownBitmap;
360 else
361 return mxNormalBitmap;
363 case Disabled:
364 if (mxDisabledBitmap.is())
365 return mxDisabledBitmap;
366 else
367 return mxNormalBitmap;
369 case Mask:
370 return mxMaskBitmap;
374 void PresenterBitmapContainer::BitmapDescriptor::SetBitmap (
375 const Mode eMode,
376 const css::uno::Reference<css::rendering::XBitmap>& rxBitmap)
378 switch (eMode)
380 case Normal:
381 default:
382 mxNormalBitmap = rxBitmap;
383 if (mxNormalBitmap.is())
385 const geometry::IntegerSize2D aSize (mxNormalBitmap->getSize());
386 mnWidth = aSize.Width;
387 mnHeight = aSize.Height;
389 break;
391 case MouseOver:
392 mxMouseOverBitmap = rxBitmap;
393 break;
395 case ButtonDown:
396 mxButtonDownBitmap = rxBitmap;
397 break;
399 case Disabled:
400 mxDisabledBitmap = rxBitmap;
401 break;
403 case Mask:
404 mxMaskBitmap = rxBitmap;
405 break;
409 } } // end of namespace ::sdext::presenter
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */