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/drawing/XPresenterHelper.hpp>
24 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
26 #include <osl/diagnose.h>
28 using namespace ::com::sun::star
;
29 using namespace ::com::sun::star::uno
;
31 namespace sdext::presenter
{
33 //===== PresenterBitmapContainer ==============================================
35 PresenterBitmapContainer::PresenterBitmapContainer (
36 const OUString
& rsConfigurationBase
,
37 std::shared_ptr
<PresenterBitmapContainer
> xParentContainer
,
38 const css::uno::Reference
<css::uno::XComponentContext
>& rxComponentContext
,
39 css::uno::Reference
<css::rendering::XCanvas
> xCanvas
,
40 css::uno::Reference
<css::drawing::XPresenterHelper
> xPresenterHelper
)
41 : mpParentContainer(std::move(xParentContainer
)),
42 mxCanvas(std::move(xCanvas
)),
43 mxPresenterHelper(std::move(xPresenterHelper
))
45 Initialize(rxComponentContext
);
47 // Get access to the configuration.
48 PresenterConfigurationAccess
aConfiguration (
50 "org.openoffice.Office.PresenterScreen",
51 PresenterConfigurationAccess::READ_ONLY
);
52 Reference
<container::XNameAccess
> xBitmapList (
53 aConfiguration
.GetConfigurationNode(rsConfigurationBase
),
56 LoadBitmaps(xBitmapList
);
59 PresenterBitmapContainer::PresenterBitmapContainer (
60 const css::uno::Reference
<css::container::XNameAccess
>& rxRootNode
,
61 std::shared_ptr
<PresenterBitmapContainer
> xParentContainer
,
62 const css::uno::Reference
<css::uno::XComponentContext
>& rxComponentContext
,
63 css::uno::Reference
<css::rendering::XCanvas
> xCanvas
,
64 css::uno::Reference
<css::drawing::XPresenterHelper
> xPresenterHelper
)
65 : mpParentContainer(std::move(xParentContainer
)),
66 mxCanvas(std::move(xCanvas
)),
67 mxPresenterHelper(std::move(xPresenterHelper
))
69 Initialize(rxComponentContext
);
71 LoadBitmaps(rxRootNode
);
74 void PresenterBitmapContainer::Initialize (
75 const css::uno::Reference
<css::uno::XComponentContext
>& rxComponentContext
)
77 if ( mxPresenterHelper
.is())
80 // Create an object that is able to load the bitmaps in a format that is
81 // supported by the canvas.
82 Reference
<lang::XMultiComponentFactory
> xFactory
=
83 rxComponentContext
->getServiceManager();
86 mxPresenterHelper
.set(
87 xFactory
->createInstanceWithContext(
88 "com.sun.star.drawing.PresenterHelper",
93 PresenterBitmapContainer::~PresenterBitmapContainer()
95 maIconContainer
.clear();
98 std::shared_ptr
<PresenterBitmapContainer::BitmapDescriptor
> PresenterBitmapContainer::GetBitmap (
99 const OUString
& rsName
) const
101 BitmapContainer::const_iterator
iSet (maIconContainer
.find(rsName
));
102 if (iSet
!= maIconContainer
.end())
104 else if (mpParentContainer
!= nullptr)
105 return mpParentContainer
->GetBitmap(rsName
);
107 return SharedBitmapDescriptor();
110 void PresenterBitmapContainer::LoadBitmaps (
111 const css::uno::Reference
<css::container::XNameAccess
>& rxBitmapList
)
113 if ( ! mxCanvas
.is())
116 if ( ! rxBitmapList
.is())
121 // Load all button bitmaps.
122 if (rxBitmapList
.is())
124 PresenterConfigurationAccess::ForAll(
126 [this](OUString
const& rKey
, Reference
<beans::XPropertySet
> const& xProps
)
128 this->ProcessBitmap(rKey
, xProps
);
138 std::shared_ptr
<PresenterBitmapContainer::BitmapDescriptor
> PresenterBitmapContainer::LoadBitmap (
139 const css::uno::Reference
<css::container::XHierarchicalNameAccess
>& rxNode
,
140 const OUString
& rsPath
,
141 const css::uno::Reference
<css::drawing::XPresenterHelper
>& rxPresenterHelper
,
142 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
143 const std::shared_ptr
<BitmapDescriptor
>& rpDefault
)
145 SharedBitmapDescriptor pBitmap
;
151 Reference
<beans::XPropertySet
> xBitmapProperties (
152 PresenterConfigurationAccess::GetConfigurationNode(rxNode
, rsPath
),
154 if (xBitmapProperties
.is())
155 pBitmap
= LoadBitmap(
170 void PresenterBitmapContainer::ProcessBitmap (
171 const OUString
& rsKey
,
172 const Reference
<beans::XPropertySet
>& rxProperties
)
175 if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties
, "Name") >>= sName
))
178 maIconContainer
[sName
] = LoadBitmap(
182 SharedBitmapDescriptor());
185 std::shared_ptr
<PresenterBitmapContainer::BitmapDescriptor
> PresenterBitmapContainer::LoadBitmap (
186 const Reference
<beans::XPropertySet
>& rxProperties
,
187 const css::uno::Reference
<css::drawing::XPresenterHelper
>& rxPresenterHelper
,
188 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
189 const std::shared_ptr
<BitmapDescriptor
>& rpDefault
)
191 OSL_ASSERT(rxCanvas
.is());
192 OSL_ASSERT(rxPresenterHelper
.is());
194 SharedBitmapDescriptor pBitmap
= std::make_shared
<BitmapDescriptor
>(rpDefault
);
196 if ( ! rxProperties
.is())
202 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "NormalFileName") >>= sFileName
)
206 BitmapDescriptor::Normal
,
207 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
211 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "MouseOverFileName") >>= sFileName
)
215 BitmapDescriptor::MouseOver
,
216 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
220 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "ButtonDownFileName") >>= sFileName
)
224 BitmapDescriptor::ButtonDown
,
225 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
229 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "DisabledFileName") >>= sFileName
)
233 BitmapDescriptor::Disabled
,
234 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
238 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "MaskFileName") >>= sFileName
)
242 BitmapDescriptor::Mask
,
243 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
248 PresenterConfigurationAccess::GetProperty(rxProperties
, "XOffset") >>= pBitmap
->mnXOffset
;
249 PresenterConfigurationAccess::GetProperty(rxProperties
, "YOffset") >>= pBitmap
->mnYOffset
;
251 PresenterConfigurationAccess::GetProperty(rxProperties
, "XHotSpot") >>= pBitmap
->mnXHotSpot
;
252 PresenterConfigurationAccess::GetProperty(rxProperties
, "YHotSpot") >>= pBitmap
->mnYHotSpot
;
254 PresenterConfigurationAccess::GetProperty(rxProperties
, "ReplacementColor") >>= pBitmap
->maReplacementColor
;
256 OUString sTexturingMode
;
257 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "HorizontalTexturingMode") >>= sTexturingMode
)
258 pBitmap
->meHorizontalTexturingMode
= StringToTexturingMode(sTexturingMode
);
259 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "VerticalTexturingMode") >>= sTexturingMode
)
260 pBitmap
->meVerticalTexturingMode
= StringToTexturingMode(sTexturingMode
);
265 PresenterBitmapContainer::BitmapDescriptor::TexturingMode
266 PresenterBitmapContainer::StringToTexturingMode (std::u16string_view rsTexturingMode
)
268 if (rsTexturingMode
== u
"Once")
269 return PresenterBitmapContainer::BitmapDescriptor::Once
;
270 else if (rsTexturingMode
== u
"Repeat")
271 return PresenterBitmapContainer::BitmapDescriptor::Repeat
;
272 else if (rsTexturingMode
== u
"Stretch")
273 return PresenterBitmapContainer::BitmapDescriptor::Stretch
;
275 return PresenterBitmapContainer::BitmapDescriptor::Once
;
278 //===== PresenterBitmapContainer::BitmapSet ===================================
280 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor()
287 maReplacementColor(0x00000000),
288 meHorizontalTexturingMode(Once
),
289 meVerticalTexturingMode(Once
)
293 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (
294 const std::shared_ptr
<PresenterBitmapContainer::BitmapDescriptor
>& rpDefault
)
301 maReplacementColor(0x00000000),
302 meHorizontalTexturingMode(Once
),
303 meVerticalTexturingMode(Once
)
305 if (rpDefault
== nullptr)
308 mnWidth
= rpDefault
->mnWidth
;
309 mnHeight
= rpDefault
->mnHeight
;
310 mnXOffset
= rpDefault
->mnXOffset
;
311 mnYOffset
= rpDefault
->mnYOffset
;
312 mnXHotSpot
= rpDefault
->mnXHotSpot
;
313 mnYHotSpot
= rpDefault
->mnYHotSpot
;
314 maReplacementColor
= rpDefault
->maReplacementColor
;
315 meHorizontalTexturingMode
= rpDefault
->meHorizontalTexturingMode
;
316 meVerticalTexturingMode
= rpDefault
->meVerticalTexturingMode
;
317 mxNormalBitmap
= rpDefault
->mxNormalBitmap
;
318 mxMouseOverBitmap
= rpDefault
->mxMouseOverBitmap
;
319 mxButtonDownBitmap
= rpDefault
->mxButtonDownBitmap
;
320 mxDisabledBitmap
= rpDefault
->mxDisabledBitmap
;
321 mxMaskBitmap
= rpDefault
->mxMaskBitmap
;
324 const css::uno::Reference
<css::rendering::XBitmap
>&
325 PresenterBitmapContainer::BitmapDescriptor::GetNormalBitmap() const
327 return mxNormalBitmap
;
330 css::uno::Reference
<css::rendering::XBitmap
> const &
331 PresenterBitmapContainer::BitmapDescriptor::GetBitmap(const Mode eMode
) const
337 return mxNormalBitmap
;
340 if (mxMouseOverBitmap
.is())
341 return mxMouseOverBitmap
;
343 return mxNormalBitmap
;
346 if (mxButtonDownBitmap
.is())
347 return mxButtonDownBitmap
;
349 return mxNormalBitmap
;
352 if (mxDisabledBitmap
.is())
353 return mxDisabledBitmap
;
355 return mxNormalBitmap
;
362 void PresenterBitmapContainer::BitmapDescriptor::SetBitmap (
364 const css::uno::Reference
<css::rendering::XBitmap
>& rxBitmap
)
370 mxNormalBitmap
= rxBitmap
;
371 if (mxNormalBitmap
.is())
373 const geometry::IntegerSize2D
aSize (mxNormalBitmap
->getSize());
374 mnWidth
= aSize
.Width
;
375 mnHeight
= aSize
.Height
;
380 mxMouseOverBitmap
= rxBitmap
;
384 mxButtonDownBitmap
= rxBitmap
;
388 mxDisabledBitmap
= rxBitmap
;
392 mxMaskBitmap
= rxBitmap
;
397 } // end of namespace ::sdext::presenter
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */