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>
30 using namespace ::com::sun::star
;
31 using namespace ::com::sun::star::uno
;
32 using namespace ::std
;
34 namespace sdext
{ namespace presenter
{
36 //===== PresenterBitmapContainer ==============================================
38 PresenterBitmapContainer::PresenterBitmapContainer (
39 const OUString
& rsConfigurationBase
,
40 const std::shared_ptr
<PresenterBitmapContainer
>& rpParentContainer
,
41 const css::uno::Reference
<css::uno::XComponentContext
>& rxComponentContext
,
42 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
43 const css::uno::Reference
<css::drawing::XPresenterHelper
>& rxPresenterHelper
)
44 : mpParentContainer(rpParentContainer
),
47 mxPresenterHelper(rxPresenterHelper
)
49 Initialize(rxComponentContext
);
51 // Get access to the configuration.
52 PresenterConfigurationAccess
aConfiguration (
54 "org.openoffice.Office.PresenterScreen",
55 PresenterConfigurationAccess::READ_ONLY
);
56 Reference
<container::XNameAccess
> xBitmapList (
57 aConfiguration
.GetConfigurationNode(rsConfigurationBase
),
60 LoadBitmaps(xBitmapList
);
63 PresenterBitmapContainer::PresenterBitmapContainer (
64 const css::uno::Reference
<css::container::XNameAccess
>& rxRootNode
,
65 const std::shared_ptr
<PresenterBitmapContainer
>& rpParentContainer
,
66 const css::uno::Reference
<css::uno::XComponentContext
>& rxComponentContext
,
67 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
68 const css::uno::Reference
<css::drawing::XPresenterHelper
>& rxPresenterHelper
)
69 : mpParentContainer(rpParentContainer
),
72 mxPresenterHelper(rxPresenterHelper
)
74 Initialize(rxComponentContext
);
76 LoadBitmaps(rxRootNode
);
79 void PresenterBitmapContainer::Initialize (
80 const css::uno::Reference
<css::uno::XComponentContext
>& rxComponentContext
)
82 if ( ! mxPresenterHelper
.is())
84 // Create an object that is able to load the bitmaps in a format that is
85 // supported by the canvas.
86 Reference
<lang::XMultiComponentFactory
> xFactory (
87 rxComponentContext
->getServiceManager(), UNO_QUERY
);
90 mxPresenterHelper
.set(
91 xFactory
->createInstanceWithContext(
92 "com.sun.star.drawing.PresenterHelper",
98 PresenterBitmapContainer::~PresenterBitmapContainer()
100 maIconContainer
.clear();
103 SharedBitmapDescriptor
PresenterBitmapContainer::GetBitmap (
104 const OUString
& rsName
) const
106 BitmapContainer::const_iterator
iSet (maIconContainer
.find(rsName
));
107 if (iSet
!= maIconContainer
.end())
109 else if (mpParentContainer
.get() != nullptr)
110 return mpParentContainer
->GetBitmap(rsName
);
112 return SharedBitmapDescriptor();
115 void PresenterBitmapContainer::LoadBitmaps (
116 const css::uno::Reference
<css::container::XNameAccess
>& rxBitmapList
)
118 if ( ! mxCanvas
.is())
121 if ( ! rxBitmapList
.is())
126 // Load all button bitmaps.
127 if (rxBitmapList
.is())
129 PresenterConfigurationAccess::ForAll(
131 [this](OUString
const& rKey
, Reference
<beans::XPropertySet
> const& xProps
)
133 this->ProcessBitmap(rKey
, xProps
);
143 SharedBitmapDescriptor
PresenterBitmapContainer::LoadBitmap (
144 const css::uno::Reference
<css::container::XHierarchicalNameAccess
>& rxNode
,
145 const OUString
& rsPath
,
146 const css::uno::Reference
<css::drawing::XPresenterHelper
>& rxPresenterHelper
,
147 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
148 const SharedBitmapDescriptor
& rpDefault
)
150 SharedBitmapDescriptor pBitmap
;
156 Reference
<beans::XPropertySet
> xBitmapProperties (
157 PresenterConfigurationAccess::GetConfigurationNode(rxNode
, rsPath
),
159 if (xBitmapProperties
.is())
160 pBitmap
= LoadBitmap(
175 void PresenterBitmapContainer::ProcessBitmap (
176 const OUString
& rsKey
,
177 const Reference
<beans::XPropertySet
>& rxProperties
)
180 if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties
, "Name") >>= sName
))
183 maIconContainer
[sName
] = LoadBitmap(
187 SharedBitmapDescriptor());
190 SharedBitmapDescriptor
PresenterBitmapContainer::LoadBitmap (
191 const Reference
<beans::XPropertySet
>& rxProperties
,
192 const css::uno::Reference
<css::drawing::XPresenterHelper
>& rxPresenterHelper
,
193 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
194 const SharedBitmapDescriptor
& rpDefault
)
196 OSL_ASSERT(rxCanvas
.is());
197 OSL_ASSERT(rxPresenterHelper
.is());
199 SharedBitmapDescriptor
pBitmap (new BitmapDescriptor(rpDefault
));
201 if ( ! rxProperties
.is())
207 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "NormalFileName") >>= sFileName
)
211 BitmapDescriptor::Normal
,
212 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
216 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "MouseOverFileName") >>= sFileName
)
220 BitmapDescriptor::MouseOver
,
221 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
225 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "ButtonDownFileName") >>= sFileName
)
229 BitmapDescriptor::ButtonDown
,
230 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
234 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "DisabledFileName") >>= sFileName
)
238 BitmapDescriptor::Disabled
,
239 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
243 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "MaskFileName") >>= sFileName
)
247 BitmapDescriptor::Mask
,
248 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
253 PresenterConfigurationAccess::GetProperty(rxProperties
, "XOffset") >>= pBitmap
->mnXOffset
;
254 PresenterConfigurationAccess::GetProperty(rxProperties
, "YOffset") >>= pBitmap
->mnYOffset
;
256 PresenterConfigurationAccess::GetProperty(rxProperties
, "XHotSpot") >>= pBitmap
->mnXHotSpot
;
257 PresenterConfigurationAccess::GetProperty(rxProperties
, "YHotSpot") >>= pBitmap
->mnYHotSpot
;
259 PresenterConfigurationAccess::GetProperty(rxProperties
, "ReplacementColor") >>= pBitmap
->maReplacementColor
;
261 OUString sTexturingMode
;
262 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "HorizontalTexturingMode") >>= sTexturingMode
)
263 pBitmap
->meHorizontalTexturingMode
= StringToTexturingMode(sTexturingMode
);
264 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "VerticalTexturingMode") >>= sTexturingMode
)
265 pBitmap
->meVerticalTexturingMode
= StringToTexturingMode(sTexturingMode
);
270 PresenterBitmapContainer::BitmapDescriptor::TexturingMode
271 PresenterBitmapContainer::StringToTexturingMode (const OUString
& rsTexturingMode
)
273 if (rsTexturingMode
== "Once")
274 return PresenterBitmapContainer::BitmapDescriptor::Once
;
275 else if (rsTexturingMode
== "Repeat")
276 return PresenterBitmapContainer::BitmapDescriptor::Repeat
;
277 else if (rsTexturingMode
== "Stretch")
278 return PresenterBitmapContainer::BitmapDescriptor::Stretch
;
280 return PresenterBitmapContainer::BitmapDescriptor::Once
;
283 //===== PresenterBitmapContainer::BitmapSet ===================================
285 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor()
292 maReplacementColor(0x00000000),
293 meHorizontalTexturingMode(Once
),
294 meVerticalTexturingMode(Once
),
297 mxButtonDownBitmap(),
303 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (
304 const std::shared_ptr
<PresenterBitmapContainer::BitmapDescriptor
>& rpDefault
)
311 maReplacementColor(0x00000000),
312 meHorizontalTexturingMode(Once
),
313 meVerticalTexturingMode(Once
),
316 mxButtonDownBitmap(),
320 if (rpDefault
.get() != nullptr)
322 mnWidth
= rpDefault
->mnWidth
;
323 mnHeight
= rpDefault
->mnHeight
;
324 mnXOffset
= rpDefault
->mnXOffset
;
325 mnYOffset
= rpDefault
->mnYOffset
;
326 mnXHotSpot
= rpDefault
->mnXHotSpot
;
327 mnYHotSpot
= rpDefault
->mnYHotSpot
;
328 maReplacementColor
= rpDefault
->maReplacementColor
;
329 meHorizontalTexturingMode
= rpDefault
->meHorizontalTexturingMode
;
330 meVerticalTexturingMode
= rpDefault
->meVerticalTexturingMode
;
331 mxNormalBitmap
= rpDefault
->mxNormalBitmap
;
332 mxMouseOverBitmap
= rpDefault
->mxMouseOverBitmap
;
333 mxButtonDownBitmap
= rpDefault
->mxButtonDownBitmap
;
334 mxDisabledBitmap
= rpDefault
->mxDisabledBitmap
;
335 mxMaskBitmap
= rpDefault
->mxMaskBitmap
;
339 const css::uno::Reference
<css::rendering::XBitmap
>&
340 PresenterBitmapContainer::BitmapDescriptor::GetNormalBitmap() const
342 return mxNormalBitmap
;
345 css::uno::Reference
<css::rendering::XBitmap
> const &
346 PresenterBitmapContainer::BitmapDescriptor::GetBitmap(const Mode eMode
) const
352 return mxNormalBitmap
;
355 if (mxMouseOverBitmap
.is())
356 return mxMouseOverBitmap
;
358 return mxNormalBitmap
;
361 if (mxButtonDownBitmap
.is())
362 return mxButtonDownBitmap
;
364 return mxNormalBitmap
;
367 if (mxDisabledBitmap
.is())
368 return mxDisabledBitmap
;
370 return mxNormalBitmap
;
377 void PresenterBitmapContainer::BitmapDescriptor::SetBitmap (
379 const css::uno::Reference
<css::rendering::XBitmap
>& rxBitmap
)
385 mxNormalBitmap
= rxBitmap
;
386 if (mxNormalBitmap
.is())
388 const geometry::IntegerSize2D
aSize (mxNormalBitmap
->getSize());
389 mnWidth
= aSize
.Width
;
390 mnHeight
= aSize
.Height
;
395 mxMouseOverBitmap
= rxBitmap
;
399 mxButtonDownBitmap
= rxBitmap
;
403 mxDisabledBitmap
= rxBitmap
;
407 mxMaskBitmap
= rxBitmap
;
412 } } // end of namespace ::sdext::presenter
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */