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>
25 #include <osl/diagnose.h>
27 using namespace ::com::sun::star
;
28 using namespace ::com::sun::star::uno
;
29 using namespace ::std
;
31 namespace sdext
{ namespace presenter
{
33 //===== PresenterBitmapContainer ==============================================
35 PresenterBitmapContainer::PresenterBitmapContainer (
36 const OUString
& rsConfigurationBase
,
37 const std::shared_ptr
<PresenterBitmapContainer
>& rpParentContainer
,
38 const css::uno::Reference
<css::uno::XComponentContext
>& rxComponentContext
,
39 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
40 const css::uno::Reference
<css::drawing::XPresenterHelper
>& rxPresenterHelper
)
41 : mpParentContainer(rpParentContainer
),
44 mxPresenterHelper(rxPresenterHelper
)
46 Initialize(rxComponentContext
);
48 // Get access to the configuration.
49 PresenterConfigurationAccess
aConfiguration (
51 "org.openoffice.Office.PresenterScreen",
52 PresenterConfigurationAccess::READ_ONLY
);
53 Reference
<container::XNameAccess
> xBitmapList (
54 aConfiguration
.GetConfigurationNode(rsConfigurationBase
),
57 LoadBitmaps(xBitmapList
);
60 PresenterBitmapContainer::PresenterBitmapContainer (
61 const css::uno::Reference
<css::container::XNameAccess
>& rxRootNode
,
62 const std::shared_ptr
<PresenterBitmapContainer
>& rpParentContainer
,
63 const css::uno::Reference
<css::uno::XComponentContext
>& rxComponentContext
,
64 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
65 const css::uno::Reference
<css::drawing::XPresenterHelper
>& rxPresenterHelper
)
66 : mpParentContainer(rpParentContainer
),
69 mxPresenterHelper(rxPresenterHelper
)
71 Initialize(rxComponentContext
);
73 LoadBitmaps(rxRootNode
);
76 void PresenterBitmapContainer::Initialize (
77 const css::uno::Reference
<css::uno::XComponentContext
>& rxComponentContext
)
79 if ( mxPresenterHelper
.is())
82 // Create an object that is able to load the bitmaps in a format that is
83 // supported by the canvas.
84 Reference
<lang::XMultiComponentFactory
> xFactory
=
85 rxComponentContext
->getServiceManager();
88 mxPresenterHelper
.set(
89 xFactory
->createInstanceWithContext(
90 "com.sun.star.drawing.PresenterHelper",
95 PresenterBitmapContainer::~PresenterBitmapContainer()
97 maIconContainer
.clear();
100 std::shared_ptr
<PresenterBitmapContainer::BitmapDescriptor
> PresenterBitmapContainer::GetBitmap (
101 const OUString
& rsName
) const
103 BitmapContainer::const_iterator
iSet (maIconContainer
.find(rsName
));
104 if (iSet
!= maIconContainer
.end())
106 else if (mpParentContainer
!= nullptr)
107 return mpParentContainer
->GetBitmap(rsName
);
109 return SharedBitmapDescriptor();
112 void PresenterBitmapContainer::LoadBitmaps (
113 const css::uno::Reference
<css::container::XNameAccess
>& rxBitmapList
)
115 if ( ! mxCanvas
.is())
118 if ( ! rxBitmapList
.is())
123 // Load all button bitmaps.
124 if (rxBitmapList
.is())
126 PresenterConfigurationAccess::ForAll(
128 [this](OUString
const& rKey
, Reference
<beans::XPropertySet
> const& xProps
)
130 this->ProcessBitmap(rKey
, xProps
);
140 std::shared_ptr
<PresenterBitmapContainer::BitmapDescriptor
> PresenterBitmapContainer::LoadBitmap (
141 const css::uno::Reference
<css::container::XHierarchicalNameAccess
>& rxNode
,
142 const OUString
& rsPath
,
143 const css::uno::Reference
<css::drawing::XPresenterHelper
>& rxPresenterHelper
,
144 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
145 const std::shared_ptr
<BitmapDescriptor
>& rpDefault
)
147 SharedBitmapDescriptor pBitmap
;
153 Reference
<beans::XPropertySet
> xBitmapProperties (
154 PresenterConfigurationAccess::GetConfigurationNode(rxNode
, rsPath
),
156 if (xBitmapProperties
.is())
157 pBitmap
= LoadBitmap(
172 void PresenterBitmapContainer::ProcessBitmap (
173 const OUString
& rsKey
,
174 const Reference
<beans::XPropertySet
>& rxProperties
)
177 if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties
, "Name") >>= sName
))
180 maIconContainer
[sName
] = LoadBitmap(
184 SharedBitmapDescriptor());
187 std::shared_ptr
<PresenterBitmapContainer::BitmapDescriptor
> PresenterBitmapContainer::LoadBitmap (
188 const Reference
<beans::XPropertySet
>& rxProperties
,
189 const css::uno::Reference
<css::drawing::XPresenterHelper
>& rxPresenterHelper
,
190 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
191 const std::shared_ptr
<BitmapDescriptor
>& rpDefault
)
193 OSL_ASSERT(rxCanvas
.is());
194 OSL_ASSERT(rxPresenterHelper
.is());
196 SharedBitmapDescriptor
pBitmap (new BitmapDescriptor(rpDefault
));
198 if ( ! rxProperties
.is())
204 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "NormalFileName") >>= sFileName
)
208 BitmapDescriptor::Normal
,
209 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
213 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "MouseOverFileName") >>= sFileName
)
217 BitmapDescriptor::MouseOver
,
218 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
222 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "ButtonDownFileName") >>= sFileName
)
226 BitmapDescriptor::ButtonDown
,
227 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
231 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "DisabledFileName") >>= sFileName
)
235 BitmapDescriptor::Disabled
,
236 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
240 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "MaskFileName") >>= sFileName
)
244 BitmapDescriptor::Mask
,
245 rxPresenterHelper
->loadBitmap(sFileName
, rxCanvas
));
250 PresenterConfigurationAccess::GetProperty(rxProperties
, "XOffset") >>= pBitmap
->mnXOffset
;
251 PresenterConfigurationAccess::GetProperty(rxProperties
, "YOffset") >>= pBitmap
->mnYOffset
;
253 PresenterConfigurationAccess::GetProperty(rxProperties
, "XHotSpot") >>= pBitmap
->mnXHotSpot
;
254 PresenterConfigurationAccess::GetProperty(rxProperties
, "YHotSpot") >>= pBitmap
->mnYHotSpot
;
256 PresenterConfigurationAccess::GetProperty(rxProperties
, "ReplacementColor") >>= pBitmap
->maReplacementColor
;
258 OUString sTexturingMode
;
259 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "HorizontalTexturingMode") >>= sTexturingMode
)
260 pBitmap
->meHorizontalTexturingMode
= StringToTexturingMode(sTexturingMode
);
261 if (PresenterConfigurationAccess::GetProperty(rxProperties
, "VerticalTexturingMode") >>= sTexturingMode
)
262 pBitmap
->meVerticalTexturingMode
= StringToTexturingMode(sTexturingMode
);
267 PresenterBitmapContainer::BitmapDescriptor::TexturingMode
268 PresenterBitmapContainer::StringToTexturingMode (const OUString
& rsTexturingMode
)
270 if (rsTexturingMode
== "Once")
271 return PresenterBitmapContainer::BitmapDescriptor::Once
;
272 else if (rsTexturingMode
== "Repeat")
273 return PresenterBitmapContainer::BitmapDescriptor::Repeat
;
274 else if (rsTexturingMode
== "Stretch")
275 return PresenterBitmapContainer::BitmapDescriptor::Stretch
;
277 return PresenterBitmapContainer::BitmapDescriptor::Once
;
280 //===== PresenterBitmapContainer::BitmapSet ===================================
282 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor()
289 maReplacementColor(0x00000000),
290 meHorizontalTexturingMode(Once
),
291 meVerticalTexturingMode(Once
),
294 mxButtonDownBitmap(),
300 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (
301 const std::shared_ptr
<PresenterBitmapContainer::BitmapDescriptor
>& rpDefault
)
308 maReplacementColor(0x00000000),
309 meHorizontalTexturingMode(Once
),
310 meVerticalTexturingMode(Once
),
313 mxButtonDownBitmap(),
317 if (rpDefault
== nullptr)
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
;
336 const css::uno::Reference
<css::rendering::XBitmap
>&
337 PresenterBitmapContainer::BitmapDescriptor::GetNormalBitmap() const
339 return mxNormalBitmap
;
342 css::uno::Reference
<css::rendering::XBitmap
> const &
343 PresenterBitmapContainer::BitmapDescriptor::GetBitmap(const Mode eMode
) const
349 return mxNormalBitmap
;
352 if (mxMouseOverBitmap
.is())
353 return mxMouseOverBitmap
;
355 return mxNormalBitmap
;
358 if (mxButtonDownBitmap
.is())
359 return mxButtonDownBitmap
;
361 return mxNormalBitmap
;
364 if (mxDisabledBitmap
.is())
365 return mxDisabledBitmap
;
367 return mxNormalBitmap
;
374 void PresenterBitmapContainer::BitmapDescriptor::SetBitmap (
376 const css::uno::Reference
<css::rendering::XBitmap
>& rxBitmap
)
382 mxNormalBitmap
= rxBitmap
;
383 if (mxNormalBitmap
.is())
385 const geometry::IntegerSize2D
aSize (mxNormalBitmap
->getSize());
386 mnWidth
= aSize
.Width
;
387 mnHeight
= aSize
.Height
;
392 mxMouseOverBitmap
= rxBitmap
;
396 mxButtonDownBitmap
= rxBitmap
;
400 mxDisabledBitmap
= rxBitmap
;
404 mxMaskBitmap
= rxBitmap
;
409 } } // end of namespace ::sdext::presenter
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */