update dev300-m58
[ooovba.git] / sdext / source / presenter / PresenterBitmapContainer.cxx
blob73ef1891d230cf95ff5547b8c33893e050513214
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterBitmapContainer.cxx,v $
11 * $Revision: 1.6 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterBitmapContainer.hxx"
36 #include "PresenterComponent.hxx"
37 #include "PresenterConfigurationAccess.hxx"
39 #include <com/sun/star/deployment/XPackageInformationProvider.hpp>
40 #include <com/sun/star/drawing/XPresenterHelper.hpp>
41 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
42 #include <com/sun/star/rendering/CompositeOperation.hpp>
43 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
44 #include <boost/bind.hpp>
45 #include <map>
47 using namespace ::com::sun::star;
48 using namespace ::com::sun::star::uno;
49 using namespace ::std;
50 using ::rtl::OUString;
52 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
55 namespace sdext { namespace presenter {
57 namespace {
58 static OUString gsNameProperty (A2S("Name"));
59 static OUString gsNormalFileNameProperty (A2S("NormalFileName"));
60 static OUString gsMouseOverFileNameProperty (A2S("MouseOverFileName"));
61 static OUString gsButtonDownFileNameProperty (A2S("ButtonDownFileName"));
62 static OUString gsDisabledFileNameProperty (A2S("DisabledFileName"));
63 static OUString gsMaskFileNameProperty (A2S("MaskFileName"));
64 static OUString gsXOffsetProperty (A2S("XOffset"));
65 static OUString gsYOffsetProperty (A2S("YOffset"));
66 static OUString gsXHotSpotProperty (A2S("XHotSpot"));
67 static OUString gsYHotSpotProperty (A2S("YHotSpot"));
68 static OUString gsReplacementColorProperty (A2S("ReplacementColor"));
69 static OUString gsHorizontalTexturingModeProperty (A2S("HorizontalTexturingMode"));
70 static OUString gsVerticalTexturingModeProperty (A2S("VerticalTexturingMode"));
73 //===== PresenterBitmapContainer ==============================================
75 PresenterBitmapContainer::PresenterBitmapContainer (
76 const ::rtl::OUString& rsConfigurationBase,
77 const ::boost::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
78 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
79 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
80 const OUString& rsBasePath,
81 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper)
82 : mpParentContainer(rpParentContainer),
83 maIconContainer(),
84 msBasePath(rsBasePath),
85 mxCanvas(rxCanvas),
86 mxPresenterHelper(rxPresenterHelper)
88 Initialize(rxComponentContext);
90 // Get access to the configuration.
91 PresenterConfigurationAccess aConfiguration (
92 rxComponentContext,
93 A2S("org.openoffice.Office.extension.PresenterScreen"),
94 PresenterConfigurationAccess::READ_ONLY);
95 Reference<container::XNameAccess> xBitmapList (
96 aConfiguration.GetConfigurationNode(rsConfigurationBase),
97 UNO_QUERY_THROW);
99 LoadBitmaps(xBitmapList);
106 PresenterBitmapContainer::PresenterBitmapContainer (
107 const css::uno::Reference<css::container::XNameAccess>& rxRootNode,
108 const ::boost::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
109 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
110 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
111 const OUString& rsBasePath,
112 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper)
113 : mpParentContainer(rpParentContainer),
114 maIconContainer(),
115 msBasePath(rsBasePath),
116 mxCanvas(rxCanvas),
117 mxPresenterHelper(rxPresenterHelper)
119 Initialize(rxComponentContext);
121 LoadBitmaps(rxRootNode);
127 void PresenterBitmapContainer::Initialize (
128 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext)
130 if ( ! mxPresenterHelper.is())
132 // Create an object that is able to load the bitmaps in a format that is
133 // supported by the canvas.
134 Reference<lang::XMultiComponentFactory> xFactory (
135 rxComponentContext->getServiceManager(), UNO_QUERY);
136 if ( ! xFactory.is())
137 return;
138 mxPresenterHelper = Reference<drawing::XPresenterHelper>(
139 xFactory->createInstanceWithContext(
140 A2S("com.sun.star.drawing.PresenterHelper"),
141 rxComponentContext),
142 UNO_QUERY_THROW);
149 PresenterBitmapContainer::~PresenterBitmapContainer (void)
151 maIconContainer.clear();
157 SharedBitmapDescriptor PresenterBitmapContainer::GetBitmap (
158 const OUString& rsName) const
160 BitmapContainer::const_iterator iSet (maIconContainer.find(rsName));
161 if (iSet != maIconContainer.end())
162 return iSet->second;
163 else if (mpParentContainer.get() != NULL)
164 return mpParentContainer->GetBitmap(rsName);
165 else
166 return SharedBitmapDescriptor();
172 void PresenterBitmapContainer::LoadBitmaps (
173 const css::uno::Reference<css::container::XNameAccess>& rxBitmapList)
175 if ( ! mxCanvas.is())
176 return;
178 if ( ! rxBitmapList.is())
179 return;
183 // Load all button bitmaps.
184 if (rxBitmapList.is())
186 PresenterConfigurationAccess::ForAll(
187 rxBitmapList,
188 ::boost::bind(&PresenterBitmapContainer::ProcessBitmap, this, _1, _2));
191 catch (Exception&)
193 OSL_ASSERT(false);
200 SharedBitmapDescriptor PresenterBitmapContainer::LoadBitmap (
201 const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
202 const ::rtl::OUString& rsPath,
203 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
204 const OUString& rsBasePath,
205 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
206 const SharedBitmapDescriptor& rpDefault)
208 SharedBitmapDescriptor pBitmap;
210 if (rxNode.is())
214 Reference<beans::XPropertySet> xBitmapProperties (
215 PresenterConfigurationAccess::GetConfigurationNode(rxNode, rsPath),
216 UNO_QUERY);
217 if (xBitmapProperties.is())
218 pBitmap = LoadBitmap(
219 xBitmapProperties,
220 rxPresenterHelper,
221 rsBasePath,
222 rxCanvas,
223 rpDefault);
225 catch (Exception&)
227 OSL_ASSERT(false);
231 return pBitmap;
237 void PresenterBitmapContainer::ProcessBitmap (
238 const OUString& rsKey,
239 const Reference<beans::XPropertySet>& rxProperties)
241 OUString sName;
242 if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties, gsNameProperty) >>= sName))
243 sName = rsKey;
245 maIconContainer[sName] = LoadBitmap(
246 rxProperties,
247 mxPresenterHelper,
248 msBasePath,
249 mxCanvas,
250 SharedBitmapDescriptor());
256 SharedBitmapDescriptor PresenterBitmapContainer::LoadBitmap (
257 const Reference<beans::XPropertySet>& rxProperties,
258 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
259 const OUString& rsBasePath,
260 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
261 const SharedBitmapDescriptor& rpDefault)
263 OSL_ASSERT(rxCanvas.is());
264 OSL_ASSERT(rxPresenterHelper.is());
266 SharedBitmapDescriptor pBitmap (new BitmapDescriptor(rpDefault));
268 if ( ! rxProperties.is())
269 return pBitmap;
271 OUString sFileName;
273 // Load bitmaps.
274 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsNormalFileNameProperty) >>= sFileName)
277 pBitmap->SetBitmap(
278 BitmapDescriptor::Normal,
279 rxPresenterHelper->loadBitmap(rsBasePath + sFileName, rxCanvas));
281 catch (Exception&)
283 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsMouseOverFileNameProperty) >>= sFileName)
286 pBitmap->SetBitmap(
287 BitmapDescriptor::MouseOver,
288 rxPresenterHelper->loadBitmap(rsBasePath + sFileName, rxCanvas));
290 catch (Exception&)
292 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsButtonDownFileNameProperty) >>= sFileName)
295 pBitmap->SetBitmap(
296 BitmapDescriptor::ButtonDown,
297 rxPresenterHelper->loadBitmap(rsBasePath + sFileName, rxCanvas));
299 catch (Exception&)
301 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsDisabledFileNameProperty) >>= sFileName)
304 pBitmap->SetBitmap(
305 BitmapDescriptor::Disabled,
306 rxPresenterHelper->loadBitmap(rsBasePath + sFileName, rxCanvas));
308 catch (Exception&)
310 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsMaskFileNameProperty) >>= sFileName)
313 pBitmap->SetBitmap(
314 BitmapDescriptor::Mask,
315 rxPresenterHelper->loadBitmap(rsBasePath + sFileName, rxCanvas));
317 catch (Exception&)
321 PresenterConfigurationAccess::GetProperty(rxProperties, gsXOffsetProperty) >>= pBitmap->mnXOffset;
322 PresenterConfigurationAccess::GetProperty(rxProperties, gsYOffsetProperty) >>= pBitmap->mnYOffset;
324 PresenterConfigurationAccess::GetProperty(rxProperties, gsXHotSpotProperty) >>= pBitmap->mnXHotSpot;
325 PresenterConfigurationAccess::GetProperty(rxProperties, gsYHotSpotProperty) >>= pBitmap->mnYHotSpot;
327 PresenterConfigurationAccess::GetProperty(rxProperties, gsReplacementColorProperty) >>= pBitmap->maReplacementColor;
329 OUString sTexturingMode;
330 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsHorizontalTexturingModeProperty) >>= sTexturingMode)
331 pBitmap->meHorizontalTexturingMode = StringToTexturingMode(sTexturingMode);
332 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsVerticalTexturingModeProperty) >>= sTexturingMode)
333 pBitmap->meVerticalTexturingMode = StringToTexturingMode(sTexturingMode);
335 return pBitmap;
341 PresenterBitmapContainer::BitmapDescriptor::TexturingMode
342 PresenterBitmapContainer::StringToTexturingMode (const OUString& rsTexturingMode)
344 if (rsTexturingMode == A2S("Once"))
345 return PresenterBitmapContainer::BitmapDescriptor::Once;
346 else if (rsTexturingMode == A2S("Repeat"))
347 return PresenterBitmapContainer::BitmapDescriptor::Repeat;
348 else if (rsTexturingMode == A2S("Stretch"))
349 return PresenterBitmapContainer::BitmapDescriptor::Stretch;
350 else
351 return PresenterBitmapContainer::BitmapDescriptor::Once;
357 //===== PresenterBitmapContainer::BitmapSet ===================================
359 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (void)
360 : mnWidth(0),
361 mnHeight(0),
362 mnXOffset(0),
363 mnYOffset(0),
364 mnXHotSpot(0),
365 mnYHotSpot(0),
366 maReplacementColor(0x00000000),
367 meHorizontalTexturingMode(Once),
368 meVerticalTexturingMode(Once),
369 mxNormalBitmap(),
370 mxMouseOverBitmap(),
371 mxButtonDownBitmap(),
372 mxDisabledBitmap(),
373 mxMaskBitmap()
380 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (
381 const ::boost::shared_ptr<PresenterBitmapContainer::BitmapDescriptor>& rpDefault)
382 : mnWidth(0),
383 mnHeight(0),
384 mnXOffset(0),
385 mnYOffset(0),
386 mnXHotSpot(0),
387 mnYHotSpot(0),
388 maReplacementColor(0x00000000),
389 meHorizontalTexturingMode(Once),
390 meVerticalTexturingMode(Once),
391 mxNormalBitmap(),
392 mxMouseOverBitmap(),
393 mxButtonDownBitmap(),
394 mxDisabledBitmap(),
395 mxMaskBitmap()
397 if (rpDefault.get() != NULL)
399 mnWidth = rpDefault->mnWidth;
400 mnHeight = rpDefault->mnHeight;
401 mnXOffset = rpDefault->mnXOffset;
402 mnYOffset = rpDefault->mnYOffset;
403 mnXHotSpot = rpDefault->mnXHotSpot;
404 mnYHotSpot = rpDefault->mnYHotSpot;
405 maReplacementColor = rpDefault->maReplacementColor;
406 meHorizontalTexturingMode = rpDefault->meHorizontalTexturingMode;
407 meVerticalTexturingMode = rpDefault->meVerticalTexturingMode;
408 mxNormalBitmap = rpDefault->mxNormalBitmap;
409 mxMouseOverBitmap = rpDefault->mxMouseOverBitmap;
410 mxButtonDownBitmap = rpDefault->mxButtonDownBitmap;
411 mxDisabledBitmap = rpDefault->mxDisabledBitmap;
412 mxMaskBitmap = rpDefault->mxMaskBitmap;
417 css::uno::Reference<css::rendering::XBitmap>
418 PresenterBitmapContainer::BitmapDescriptor::GetNormalBitmap (void) const
420 return mxNormalBitmap;
426 css::uno::Reference<css::rendering::XBitmap>
427 PresenterBitmapContainer::BitmapDescriptor::GetBitmap (
428 const Mode eMode,
429 const bool bMissingDefaultsToNormal) const
431 switch (eMode)
433 case Normal:
434 default:
435 return mxNormalBitmap;
437 case MouseOver:
438 if (mxMouseOverBitmap.is())
439 return mxMouseOverBitmap;
440 else if (bMissingDefaultsToNormal)
441 return mxNormalBitmap;
443 case ButtonDown:
444 if (mxButtonDownBitmap.is())
445 return mxButtonDownBitmap;
446 else if (bMissingDefaultsToNormal)
447 return mxNormalBitmap;
449 case Disabled:
450 if (mxDisabledBitmap.is())
451 return mxDisabledBitmap;
452 else if (bMissingDefaultsToNormal)
453 return mxNormalBitmap;
455 case Mask:
456 return mxMaskBitmap;
458 return NULL;
464 void PresenterBitmapContainer::BitmapDescriptor::SetBitmap (
465 const Mode eMode,
466 const css::uno::Reference<css::rendering::XBitmap>& rxBitmap)
468 switch (eMode)
470 case Normal:
471 default:
472 mxNormalBitmap = rxBitmap;
473 if (mxNormalBitmap.is())
475 const geometry::IntegerSize2D aSize (mxNormalBitmap->getSize());
476 mnWidth = aSize.Width;
477 mnHeight = aSize.Height;
479 break;
481 case MouseOver:
482 mxMouseOverBitmap = rxBitmap;
483 break;
485 case ButtonDown:
486 mxButtonDownBitmap = rxBitmap;
487 break;
489 case Disabled:
490 mxDisabledBitmap = rxBitmap;
491 break;
493 case Mask:
494 mxMaskBitmap = rxBitmap;
495 break;
502 } } // end of namespace ::sdext::presenter