fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sdext / source / presenter / PresenterBitmapContainer.cxx
blobc8e7ac92ce87ce26a229391d91b1d80ffe62fc66
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>
29 #include <boost/bind.hpp>
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
33 using namespace ::std;
35 namespace sdext { namespace presenter {
37 //===== PresenterBitmapContainer ==============================================
39 PresenterBitmapContainer::PresenterBitmapContainer (
40 const OUString& rsConfigurationBase,
41 const ::boost::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
42 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
43 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
44 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper)
45 : mpParentContainer(rpParentContainer),
46 maIconContainer(),
47 mxCanvas(rxCanvas),
48 mxPresenterHelper(rxPresenterHelper)
50 Initialize(rxComponentContext);
52 // Get access to the configuration.
53 PresenterConfigurationAccess aConfiguration (
54 rxComponentContext,
55 "org.openoffice.Office.PresenterScreen",
56 PresenterConfigurationAccess::READ_ONLY);
57 Reference<container::XNameAccess> xBitmapList (
58 aConfiguration.GetConfigurationNode(rsConfigurationBase),
59 UNO_QUERY_THROW);
61 LoadBitmaps(xBitmapList);
64 PresenterBitmapContainer::PresenterBitmapContainer (
65 const css::uno::Reference<css::container::XNameAccess>& rxRootNode,
66 const ::boost::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
67 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
68 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
69 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper)
70 : mpParentContainer(rpParentContainer),
71 maIconContainer(),
72 mxCanvas(rxCanvas),
73 mxPresenterHelper(rxPresenterHelper)
75 Initialize(rxComponentContext);
77 LoadBitmaps(rxRootNode);
80 void PresenterBitmapContainer::Initialize (
81 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext)
83 if ( ! mxPresenterHelper.is())
85 // Create an object that is able to load the bitmaps in a format that is
86 // supported by the canvas.
87 Reference<lang::XMultiComponentFactory> xFactory (
88 rxComponentContext->getServiceManager(), UNO_QUERY);
89 if ( ! xFactory.is())
90 return;
91 mxPresenterHelper = Reference<drawing::XPresenterHelper>(
92 xFactory->createInstanceWithContext(
93 "com.sun.star.drawing.PresenterHelper",
94 rxComponentContext),
95 UNO_QUERY_THROW);
99 PresenterBitmapContainer::~PresenterBitmapContainer()
101 maIconContainer.clear();
104 SharedBitmapDescriptor PresenterBitmapContainer::GetBitmap (
105 const OUString& rsName) const
107 BitmapContainer::const_iterator iSet (maIconContainer.find(rsName));
108 if (iSet != maIconContainer.end())
109 return iSet->second;
110 else if (mpParentContainer.get() != NULL)
111 return mpParentContainer->GetBitmap(rsName);
112 else
113 return SharedBitmapDescriptor();
116 void PresenterBitmapContainer::LoadBitmaps (
117 const css::uno::Reference<css::container::XNameAccess>& rxBitmapList)
119 if ( ! mxCanvas.is())
120 return;
122 if ( ! rxBitmapList.is())
123 return;
127 // Load all button bitmaps.
128 if (rxBitmapList.is())
130 PresenterConfigurationAccess::ForAll(
131 rxBitmapList,
132 ::boost::bind(&PresenterBitmapContainer::ProcessBitmap, this, _1, _2));
135 catch (Exception&)
137 OSL_ASSERT(false);
141 SharedBitmapDescriptor PresenterBitmapContainer::LoadBitmap (
142 const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
143 const OUString& rsPath,
144 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
145 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
146 const SharedBitmapDescriptor& rpDefault)
148 SharedBitmapDescriptor pBitmap;
150 if (rxNode.is())
154 Reference<beans::XPropertySet> xBitmapProperties (
155 PresenterConfigurationAccess::GetConfigurationNode(rxNode, rsPath),
156 UNO_QUERY);
157 if (xBitmapProperties.is())
158 pBitmap = LoadBitmap(
159 xBitmapProperties,
160 rxPresenterHelper,
161 rxCanvas,
162 rpDefault);
164 catch (Exception&)
166 OSL_ASSERT(false);
170 return pBitmap;
173 void PresenterBitmapContainer::ProcessBitmap (
174 const OUString& rsKey,
175 const Reference<beans::XPropertySet>& rxProperties)
177 OUString sName;
178 if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties, "Name") >>= sName))
179 sName = rsKey;
181 maIconContainer[sName] = LoadBitmap(
182 rxProperties,
183 mxPresenterHelper,
184 mxCanvas,
185 SharedBitmapDescriptor());
188 SharedBitmapDescriptor PresenterBitmapContainer::LoadBitmap (
189 const Reference<beans::XPropertySet>& rxProperties,
190 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
191 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
192 const SharedBitmapDescriptor& rpDefault)
194 OSL_ASSERT(rxCanvas.is());
195 OSL_ASSERT(rxPresenterHelper.is());
197 SharedBitmapDescriptor pBitmap (new BitmapDescriptor(rpDefault));
199 if ( ! rxProperties.is())
200 return pBitmap;
202 OUString sFileName;
204 // Load bitmaps.
205 if (PresenterConfigurationAccess::GetProperty(rxProperties, "NormalFileName") >>= sFileName)
208 pBitmap->SetBitmap(
209 BitmapDescriptor::Normal,
210 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
212 catch (Exception&)
214 if (PresenterConfigurationAccess::GetProperty(rxProperties, "MouseOverFileName") >>= sFileName)
217 pBitmap->SetBitmap(
218 BitmapDescriptor::MouseOver,
219 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
221 catch (Exception&)
223 if (PresenterConfigurationAccess::GetProperty(rxProperties, "ButtonDownFileName") >>= sFileName)
226 pBitmap->SetBitmap(
227 BitmapDescriptor::ButtonDown,
228 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
230 catch (Exception&)
232 if (PresenterConfigurationAccess::GetProperty(rxProperties, "DisabledFileName") >>= sFileName)
235 pBitmap->SetBitmap(
236 BitmapDescriptor::Disabled,
237 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
239 catch (Exception&)
241 if (PresenterConfigurationAccess::GetProperty(rxProperties, "MaskFileName") >>= sFileName)
244 pBitmap->SetBitmap(
245 BitmapDescriptor::Mask,
246 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
248 catch (Exception&)
251 PresenterConfigurationAccess::GetProperty(rxProperties, "XOffset") >>= pBitmap->mnXOffset;
252 PresenterConfigurationAccess::GetProperty(rxProperties, "YOffset") >>= pBitmap->mnYOffset;
254 PresenterConfigurationAccess::GetProperty(rxProperties, "XHotSpot") >>= pBitmap->mnXHotSpot;
255 PresenterConfigurationAccess::GetProperty(rxProperties, "YHotSpot") >>= pBitmap->mnYHotSpot;
257 PresenterConfigurationAccess::GetProperty(rxProperties, "ReplacementColor") >>= pBitmap->maReplacementColor;
259 OUString sTexturingMode;
260 if (PresenterConfigurationAccess::GetProperty(rxProperties, "HorizontalTexturingMode") >>= sTexturingMode)
261 pBitmap->meHorizontalTexturingMode = StringToTexturingMode(sTexturingMode);
262 if (PresenterConfigurationAccess::GetProperty(rxProperties, "VerticalTexturingMode") >>= sTexturingMode)
263 pBitmap->meVerticalTexturingMode = StringToTexturingMode(sTexturingMode);
265 return pBitmap;
268 PresenterBitmapContainer::BitmapDescriptor::TexturingMode
269 PresenterBitmapContainer::StringToTexturingMode (const OUString& rsTexturingMode)
271 if (rsTexturingMode == "Once")
272 return PresenterBitmapContainer::BitmapDescriptor::Once;
273 else if (rsTexturingMode == "Repeat")
274 return PresenterBitmapContainer::BitmapDescriptor::Repeat;
275 else if (rsTexturingMode == "Stretch")
276 return PresenterBitmapContainer::BitmapDescriptor::Stretch;
277 else
278 return PresenterBitmapContainer::BitmapDescriptor::Once;
281 //===== PresenterBitmapContainer::BitmapSet ===================================
283 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor()
284 : mnWidth(0),
285 mnHeight(0),
286 mnXOffset(0),
287 mnYOffset(0),
288 mnXHotSpot(0),
289 mnYHotSpot(0),
290 maReplacementColor(0x00000000),
291 meHorizontalTexturingMode(Once),
292 meVerticalTexturingMode(Once),
293 mxNormalBitmap(),
294 mxMouseOverBitmap(),
295 mxButtonDownBitmap(),
296 mxDisabledBitmap(),
297 mxMaskBitmap()
301 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (
302 const ::boost::shared_ptr<PresenterBitmapContainer::BitmapDescriptor>& rpDefault)
303 : mnWidth(0),
304 mnHeight(0),
305 mnXOffset(0),
306 mnYOffset(0),
307 mnXHotSpot(0),
308 mnYHotSpot(0),
309 maReplacementColor(0x00000000),
310 meHorizontalTexturingMode(Once),
311 meVerticalTexturingMode(Once),
312 mxNormalBitmap(),
313 mxMouseOverBitmap(),
314 mxButtonDownBitmap(),
315 mxDisabledBitmap(),
316 mxMaskBitmap()
318 if (rpDefault.get() != NULL)
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;
337 css::uno::Reference<css::rendering::XBitmap>
338 PresenterBitmapContainer::BitmapDescriptor::GetNormalBitmap() const
340 return mxNormalBitmap;
343 css::uno::Reference<css::rendering::XBitmap>
344 PresenterBitmapContainer::BitmapDescriptor::GetBitmap(const Mode eMode) const
346 switch (eMode)
348 case Normal:
349 default:
350 return mxNormalBitmap;
352 case MouseOver:
353 if (mxMouseOverBitmap.is())
354 return mxMouseOverBitmap;
355 else
356 return mxNormalBitmap;
358 case ButtonDown:
359 if (mxButtonDownBitmap.is())
360 return mxButtonDownBitmap;
361 else
362 return mxNormalBitmap;
364 case Disabled:
365 if (mxDisabledBitmap.is())
366 return mxDisabledBitmap;
367 else
368 return mxNormalBitmap;
370 case Mask:
371 return mxMaskBitmap;
375 void PresenterBitmapContainer::BitmapDescriptor::SetBitmap (
376 const Mode eMode,
377 const css::uno::Reference<css::rendering::XBitmap>& rxBitmap)
379 switch (eMode)
381 case Normal:
382 default:
383 mxNormalBitmap = rxBitmap;
384 if (mxNormalBitmap.is())
386 const geometry::IntegerSize2D aSize (mxNormalBitmap->getSize());
387 mnWidth = aSize.Width;
388 mnHeight = aSize.Height;
390 break;
392 case MouseOver:
393 mxMouseOverBitmap = rxBitmap;
394 break;
396 case ButtonDown:
397 mxButtonDownBitmap = rxBitmap;
398 break;
400 case Disabled:
401 mxDisabledBitmap = rxBitmap;
402 break;
404 case Mask:
405 mxMaskBitmap = rxBitmap;
406 break;
410 } } // end of namespace ::sdext::presenter
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */