1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterBitmapContainer.cxx,v $
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>
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
{
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
),
84 msBasePath(rsBasePath
),
86 mxPresenterHelper(rxPresenterHelper
)
88 Initialize(rxComponentContext
);
90 // Get access to the configuration.
91 PresenterConfigurationAccess
aConfiguration (
93 A2S("org.openoffice.Office.extension.PresenterScreen"),
94 PresenterConfigurationAccess::READ_ONLY
);
95 Reference
<container::XNameAccess
> xBitmapList (
96 aConfiguration
.GetConfigurationNode(rsConfigurationBase
),
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
),
115 msBasePath(rsBasePath
),
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())
138 mxPresenterHelper
= Reference
<drawing::XPresenterHelper
>(
139 xFactory
->createInstanceWithContext(
140 A2S("com.sun.star.drawing.PresenterHelper"),
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())
163 else if (mpParentContainer
.get() != NULL
)
164 return mpParentContainer
->GetBitmap(rsName
);
166 return SharedBitmapDescriptor();
172 void PresenterBitmapContainer::LoadBitmaps (
173 const css::uno::Reference
<css::container::XNameAccess
>& rxBitmapList
)
175 if ( ! mxCanvas
.is())
178 if ( ! rxBitmapList
.is())
183 // Load all button bitmaps.
184 if (rxBitmapList
.is())
186 PresenterConfigurationAccess::ForAll(
188 ::boost::bind(&PresenterBitmapContainer::ProcessBitmap
, this, _1
, _2
));
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
;
214 Reference
<beans::XPropertySet
> xBitmapProperties (
215 PresenterConfigurationAccess::GetConfigurationNode(rxNode
, rsPath
),
217 if (xBitmapProperties
.is())
218 pBitmap
= LoadBitmap(
237 void PresenterBitmapContainer::ProcessBitmap (
238 const OUString
& rsKey
,
239 const Reference
<beans::XPropertySet
>& rxProperties
)
242 if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties
, gsNameProperty
) >>= sName
))
245 maIconContainer
[sName
] = LoadBitmap(
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())
274 if (PresenterConfigurationAccess::GetProperty(rxProperties
, gsNormalFileNameProperty
) >>= sFileName
)
278 BitmapDescriptor::Normal
,
279 rxPresenterHelper
->loadBitmap(rsBasePath
+ sFileName
, rxCanvas
));
283 if (PresenterConfigurationAccess::GetProperty(rxProperties
, gsMouseOverFileNameProperty
) >>= sFileName
)
287 BitmapDescriptor::MouseOver
,
288 rxPresenterHelper
->loadBitmap(rsBasePath
+ sFileName
, rxCanvas
));
292 if (PresenterConfigurationAccess::GetProperty(rxProperties
, gsButtonDownFileNameProperty
) >>= sFileName
)
296 BitmapDescriptor::ButtonDown
,
297 rxPresenterHelper
->loadBitmap(rsBasePath
+ sFileName
, rxCanvas
));
301 if (PresenterConfigurationAccess::GetProperty(rxProperties
, gsDisabledFileNameProperty
) >>= sFileName
)
305 BitmapDescriptor::Disabled
,
306 rxPresenterHelper
->loadBitmap(rsBasePath
+ sFileName
, rxCanvas
));
310 if (PresenterConfigurationAccess::GetProperty(rxProperties
, gsMaskFileNameProperty
) >>= sFileName
)
314 BitmapDescriptor::Mask
,
315 rxPresenterHelper
->loadBitmap(rsBasePath
+ sFileName
, rxCanvas
));
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
);
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
;
351 return PresenterBitmapContainer::BitmapDescriptor::Once
;
357 //===== PresenterBitmapContainer::BitmapSet ===================================
359 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (void)
366 maReplacementColor(0x00000000),
367 meHorizontalTexturingMode(Once
),
368 meVerticalTexturingMode(Once
),
371 mxButtonDownBitmap(),
380 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (
381 const ::boost::shared_ptr
<PresenterBitmapContainer::BitmapDescriptor
>& rpDefault
)
388 maReplacementColor(0x00000000),
389 meHorizontalTexturingMode(Once
),
390 meVerticalTexturingMode(Once
),
393 mxButtonDownBitmap(),
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 (
429 const bool bMissingDefaultsToNormal
) const
435 return mxNormalBitmap
;
438 if (mxMouseOverBitmap
.is())
439 return mxMouseOverBitmap
;
440 else if (bMissingDefaultsToNormal
)
441 return mxNormalBitmap
;
444 if (mxButtonDownBitmap
.is())
445 return mxButtonDownBitmap
;
446 else if (bMissingDefaultsToNormal
)
447 return mxNormalBitmap
;
450 if (mxDisabledBitmap
.is())
451 return mxDisabledBitmap
;
452 else if (bMissingDefaultsToNormal
)
453 return mxNormalBitmap
;
464 void PresenterBitmapContainer::BitmapDescriptor::SetBitmap (
466 const css::uno::Reference
<css::rendering::XBitmap
>& rxBitmap
)
472 mxNormalBitmap
= rxBitmap
;
473 if (mxNormalBitmap
.is())
475 const geometry::IntegerSize2D
aSize (mxNormalBitmap
->getSize());
476 mnWidth
= aSize
.Width
;
477 mnHeight
= aSize
.Height
;
482 mxMouseOverBitmap
= rxBitmap
;
486 mxButtonDownBitmap
= rxBitmap
;
490 mxDisabledBitmap
= rxBitmap
;
494 mxMaskBitmap
= rxBitmap
;
502 } } // end of namespace ::sdext::presenter