1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
),
48 mxPresenterHelper(rxPresenterHelper
)
50 Initialize(rxComponentContext
);
52 // Get access to the configuration.
53 PresenterConfigurationAccess
aConfiguration (
55 "org.openoffice.Office.PresenterScreen",
56 PresenterConfigurationAccess::READ_ONLY
);
57 Reference
<container::XNameAccess
> xBitmapList (
58 aConfiguration
.GetConfigurationNode(rsConfigurationBase
),
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
),
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
);
91 mxPresenterHelper
= Reference
<drawing::XPresenterHelper
>(
92 xFactory
->createInstanceWithContext(
93 "com.sun.star.drawing.PresenterHelper",
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())
110 else if (mpParentContainer
.get() != NULL
)
111 return mpParentContainer
->GetBitmap(rsName
);
113 return SharedBitmapDescriptor();
116 void PresenterBitmapContainer::LoadBitmaps (
117 const css::uno::Reference
<css::container::XNameAccess
>& rxBitmapList
)
119 if ( ! mxCanvas
.is())
122 if ( ! rxBitmapList
.is())
127 // Load all button bitmaps.
128 if (rxBitmapList
.is())
130 PresenterConfigurationAccess::ForAll(
132 ::boost::bind(&PresenterBitmapContainer::ProcessBitmap
, this, _1
, _2
));
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
;
154 Reference
<beans::XPropertySet
> xBitmapProperties (
155 PresenterConfigurationAccess::GetConfigurationNode(rxNode
, rsPath
),
157 if (xBitmapProperties
.is())
158 pBitmap
= LoadBitmap(
173 void PresenterBitmapContainer::ProcessBitmap (
174 const OUString
& rsKey
,
175 const Reference
<beans::XPropertySet
>& rxProperties
)
178 if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties
, "Name") >>= sName
))
181 maIconContainer
[sName
] = LoadBitmap(
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())
205 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "NormalFileName") >>= sFileName
)
209 BitmapDescriptor::Normal
,
210 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
214 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "MouseOverFileName") >>= sFileName
)
218 BitmapDescriptor::MouseOver
,
219 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
223 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "ButtonDownFileName") >>= sFileName
)
227 BitmapDescriptor::ButtonDown
,
228 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
232 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "DisabledFileName") >>= sFileName
)
236 BitmapDescriptor::Disabled
,
237 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
241 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "MaskFileName") >>= sFileName
)
245 BitmapDescriptor::Mask
,
246 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
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
);
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
;
278 return PresenterBitmapContainer::BitmapDescriptor::Once
;
281 //===== PresenterBitmapContainer::BitmapSet ===================================
283 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor()
290 maReplacementColor(0x00000000),
291 meHorizontalTexturingMode(Once
),
292 meVerticalTexturingMode(Once
),
295 mxButtonDownBitmap(),
301 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (
302 const ::boost::shared_ptr
<PresenterBitmapContainer::BitmapDescriptor
>& rpDefault
)
309 maReplacementColor(0x00000000),
310 meHorizontalTexturingMode(Once
),
311 meVerticalTexturingMode(Once
),
314 mxButtonDownBitmap(),
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
350 return mxNormalBitmap
;
353 if (mxMouseOverBitmap
.is())
354 return mxMouseOverBitmap
;
356 return mxNormalBitmap
;
359 if (mxButtonDownBitmap
.is())
360 return mxButtonDownBitmap
;
362 return mxNormalBitmap
;
365 if (mxDisabledBitmap
.is())
366 return mxDisabledBitmap
;
368 return mxNormalBitmap
;
375 void PresenterBitmapContainer::BitmapDescriptor::SetBitmap (
377 const css::uno::Reference
<css::rendering::XBitmap
>& rxBitmap
)
383 mxNormalBitmap
= rxBitmap
;
384 if (mxNormalBitmap
.is())
386 const geometry::IntegerSize2D
aSize (mxNormalBitmap
->getSize());
387 mnWidth
= aSize
.Width
;
388 mnHeight
= aSize
.Height
;
393 mxMouseOverBitmap
= rxBitmap
;
397 mxButtonDownBitmap
= rxBitmap
;
401 mxDisabledBitmap
= rxBitmap
;
405 mxMaskBitmap
= rxBitmap
;
410 } } // end of namespace ::sdext::presenter
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */