Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "PresenterBitmapContainer.hxx"
21 : #include "PresenterConfigurationAccess.hxx"
22 :
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 <boost/bind.hpp>
29 :
30 : using namespace ::com::sun::star;
31 : using namespace ::com::sun::star::uno;
32 : using namespace ::std;
33 :
34 : namespace sdext { namespace presenter {
35 :
36 : //===== PresenterBitmapContainer ==============================================
37 :
38 0 : PresenterBitmapContainer::PresenterBitmapContainer (
39 : const OUString& rsConfigurationBase,
40 : const ::boost::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),
45 : maIconContainer(),
46 : mxCanvas(rxCanvas),
47 0 : mxPresenterHelper(rxPresenterHelper)
48 : {
49 0 : Initialize(rxComponentContext);
50 :
51 : // Get access to the configuration.
52 : PresenterConfigurationAccess aConfiguration (
53 : rxComponentContext,
54 : "org.openoffice.Office.PresenterScreen",
55 0 : PresenterConfigurationAccess::READ_ONLY);
56 : Reference<container::XNameAccess> xBitmapList (
57 : aConfiguration.GetConfigurationNode(rsConfigurationBase),
58 0 : UNO_QUERY_THROW);
59 :
60 0 : LoadBitmaps(xBitmapList);
61 0 : }
62 :
63 0 : PresenterBitmapContainer::PresenterBitmapContainer (
64 : const css::uno::Reference<css::container::XNameAccess>& rxRootNode,
65 : const ::boost::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),
70 : maIconContainer(),
71 : mxCanvas(rxCanvas),
72 0 : mxPresenterHelper(rxPresenterHelper)
73 : {
74 0 : Initialize(rxComponentContext);
75 :
76 0 : LoadBitmaps(rxRootNode);
77 0 : }
78 :
79 0 : void PresenterBitmapContainer::Initialize (
80 : const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext)
81 : {
82 0 : if ( ! mxPresenterHelper.is())
83 : {
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 0 : rxComponentContext->getServiceManager(), UNO_QUERY);
88 0 : if ( ! xFactory.is())
89 0 : return;
90 0 : mxPresenterHelper = Reference<drawing::XPresenterHelper>(
91 0 : xFactory->createInstanceWithContext(
92 : "com.sun.star.drawing.PresenterHelper",
93 0 : rxComponentContext),
94 0 : UNO_QUERY_THROW);
95 : }
96 : }
97 :
98 0 : PresenterBitmapContainer::~PresenterBitmapContainer (void)
99 : {
100 0 : maIconContainer.clear();
101 0 : }
102 :
103 0 : SharedBitmapDescriptor PresenterBitmapContainer::GetBitmap (
104 : const OUString& rsName) const
105 : {
106 0 : BitmapContainer::const_iterator iSet (maIconContainer.find(rsName));
107 0 : if (iSet != maIconContainer.end())
108 0 : return iSet->second;
109 0 : else if (mpParentContainer.get() != NULL)
110 0 : return mpParentContainer->GetBitmap(rsName);
111 : else
112 0 : return SharedBitmapDescriptor();
113 : }
114 :
115 0 : void PresenterBitmapContainer::LoadBitmaps (
116 : const css::uno::Reference<css::container::XNameAccess>& rxBitmapList)
117 : {
118 0 : if ( ! mxCanvas.is())
119 0 : return;
120 :
121 0 : if ( ! rxBitmapList.is())
122 0 : return;
123 :
124 : try
125 : {
126 : // Load all button bitmaps.
127 0 : if (rxBitmapList.is())
128 : {
129 : PresenterConfigurationAccess::ForAll(
130 : rxBitmapList,
131 0 : ::boost::bind(&PresenterBitmapContainer::ProcessBitmap, this, _1, _2));
132 : }
133 : }
134 0 : catch (Exception&)
135 : {
136 : OSL_ASSERT(false);
137 : }
138 : }
139 :
140 0 : SharedBitmapDescriptor 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 SharedBitmapDescriptor& rpDefault)
146 : {
147 0 : SharedBitmapDescriptor pBitmap;
148 :
149 0 : if (rxNode.is())
150 : {
151 : try
152 : {
153 : Reference<beans::XPropertySet> xBitmapProperties (
154 : PresenterConfigurationAccess::GetConfigurationNode(rxNode, rsPath),
155 0 : UNO_QUERY);
156 0 : if (xBitmapProperties.is())
157 0 : pBitmap = LoadBitmap(
158 : xBitmapProperties,
159 : rxPresenterHelper,
160 : rxCanvas,
161 0 : rpDefault);
162 : }
163 0 : catch (Exception&)
164 : {
165 : OSL_ASSERT(false);
166 : }
167 : }
168 :
169 0 : return pBitmap;
170 : }
171 :
172 0 : void PresenterBitmapContainer::ProcessBitmap (
173 : const OUString& rsKey,
174 : const Reference<beans::XPropertySet>& rxProperties)
175 : {
176 0 : OUString sName;
177 0 : if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties, "Name") >>= sName))
178 0 : sName = rsKey;
179 :
180 0 : maIconContainer[sName] = LoadBitmap(
181 : rxProperties,
182 : mxPresenterHelper,
183 : mxCanvas,
184 0 : SharedBitmapDescriptor());
185 0 : }
186 :
187 0 : SharedBitmapDescriptor 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 SharedBitmapDescriptor& rpDefault)
192 : {
193 : OSL_ASSERT(rxCanvas.is());
194 : OSL_ASSERT(rxPresenterHelper.is());
195 :
196 0 : SharedBitmapDescriptor pBitmap (new BitmapDescriptor(rpDefault));
197 :
198 0 : if ( ! rxProperties.is())
199 0 : return pBitmap;
200 :
201 0 : OUString sFileName;
202 :
203 : // Load bitmaps.
204 0 : if (PresenterConfigurationAccess::GetProperty(rxProperties, "NormalFileName") >>= sFileName)
205 : try
206 : {
207 : pBitmap->SetBitmap(
208 : BitmapDescriptor::Normal,
209 0 : rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
210 : }
211 0 : catch (Exception&)
212 : {}
213 0 : if (PresenterConfigurationAccess::GetProperty(rxProperties, "MouseOverFileName") >>= sFileName)
214 : try
215 : {
216 : pBitmap->SetBitmap(
217 : BitmapDescriptor::MouseOver,
218 0 : rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
219 : }
220 0 : catch (Exception&)
221 : {}
222 0 : if (PresenterConfigurationAccess::GetProperty(rxProperties, "ButtonDownFileName") >>= sFileName)
223 : try
224 : {
225 : pBitmap->SetBitmap(
226 : BitmapDescriptor::ButtonDown,
227 0 : rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
228 : }
229 0 : catch (Exception&)
230 : {}
231 0 : if (PresenterConfigurationAccess::GetProperty(rxProperties, "DisabledFileName") >>= sFileName)
232 : try
233 : {
234 : pBitmap->SetBitmap(
235 : BitmapDescriptor::Disabled,
236 0 : rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
237 : }
238 0 : catch (Exception&)
239 : {}
240 0 : if (PresenterConfigurationAccess::GetProperty(rxProperties, "MaskFileName") >>= sFileName)
241 : try
242 : {
243 : pBitmap->SetBitmap(
244 : BitmapDescriptor::Mask,
245 0 : rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
246 : }
247 0 : catch (Exception&)
248 : {}
249 :
250 0 : PresenterConfigurationAccess::GetProperty(rxProperties, "XOffset") >>= pBitmap->mnXOffset;
251 0 : PresenterConfigurationAccess::GetProperty(rxProperties, "YOffset") >>= pBitmap->mnYOffset;
252 :
253 0 : PresenterConfigurationAccess::GetProperty(rxProperties, "XHotSpot") >>= pBitmap->mnXHotSpot;
254 0 : PresenterConfigurationAccess::GetProperty(rxProperties, "YHotSpot") >>= pBitmap->mnYHotSpot;
255 :
256 0 : PresenterConfigurationAccess::GetProperty(rxProperties, "ReplacementColor") >>= pBitmap->maReplacementColor;
257 :
258 0 : OUString sTexturingMode;
259 0 : if (PresenterConfigurationAccess::GetProperty(rxProperties, "HorizontalTexturingMode") >>= sTexturingMode)
260 0 : pBitmap->meHorizontalTexturingMode = StringToTexturingMode(sTexturingMode);
261 0 : if (PresenterConfigurationAccess::GetProperty(rxProperties, "VerticalTexturingMode") >>= sTexturingMode)
262 0 : pBitmap->meVerticalTexturingMode = StringToTexturingMode(sTexturingMode);
263 :
264 0 : return pBitmap;
265 : }
266 :
267 : PresenterBitmapContainer::BitmapDescriptor::TexturingMode
268 0 : PresenterBitmapContainer::StringToTexturingMode (const OUString& rsTexturingMode)
269 : {
270 0 : if (rsTexturingMode == "Once")
271 0 : return PresenterBitmapContainer::BitmapDescriptor::Once;
272 0 : else if (rsTexturingMode == "Repeat")
273 0 : return PresenterBitmapContainer::BitmapDescriptor::Repeat;
274 0 : else if (rsTexturingMode == "Stretch")
275 0 : return PresenterBitmapContainer::BitmapDescriptor::Stretch;
276 : else
277 0 : return PresenterBitmapContainer::BitmapDescriptor::Once;
278 : }
279 :
280 : //===== PresenterBitmapContainer::BitmapSet ===================================
281 :
282 0 : PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (void)
283 : : mnWidth(0),
284 : mnHeight(0),
285 : mnXOffset(0),
286 : mnYOffset(0),
287 : mnXHotSpot(0),
288 : mnYHotSpot(0),
289 : maReplacementColor(0x00000000),
290 : meHorizontalTexturingMode(Once),
291 : meVerticalTexturingMode(Once),
292 : mxNormalBitmap(),
293 : mxMouseOverBitmap(),
294 : mxButtonDownBitmap(),
295 : mxDisabledBitmap(),
296 0 : mxMaskBitmap()
297 : {
298 0 : }
299 :
300 0 : PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (
301 : const ::boost::shared_ptr<PresenterBitmapContainer::BitmapDescriptor>& rpDefault)
302 : : mnWidth(0),
303 : mnHeight(0),
304 : mnXOffset(0),
305 : mnYOffset(0),
306 : mnXHotSpot(0),
307 : mnYHotSpot(0),
308 : maReplacementColor(0x00000000),
309 : meHorizontalTexturingMode(Once),
310 : meVerticalTexturingMode(Once),
311 : mxNormalBitmap(),
312 : mxMouseOverBitmap(),
313 : mxButtonDownBitmap(),
314 : mxDisabledBitmap(),
315 0 : mxMaskBitmap()
316 : {
317 0 : if (rpDefault.get() != NULL)
318 : {
319 0 : mnWidth = rpDefault->mnWidth;
320 0 : mnHeight = rpDefault->mnHeight;
321 0 : mnXOffset = rpDefault->mnXOffset;
322 0 : mnYOffset = rpDefault->mnYOffset;
323 0 : mnXHotSpot = rpDefault->mnXHotSpot;
324 0 : mnYHotSpot = rpDefault->mnYHotSpot;
325 0 : maReplacementColor = rpDefault->maReplacementColor;
326 0 : meHorizontalTexturingMode = rpDefault->meHorizontalTexturingMode;
327 0 : meVerticalTexturingMode = rpDefault->meVerticalTexturingMode;
328 0 : mxNormalBitmap = rpDefault->mxNormalBitmap;
329 0 : mxMouseOverBitmap = rpDefault->mxMouseOverBitmap;
330 0 : mxButtonDownBitmap = rpDefault->mxButtonDownBitmap;
331 0 : mxDisabledBitmap = rpDefault->mxDisabledBitmap;
332 0 : mxMaskBitmap = rpDefault->mxMaskBitmap;
333 : }
334 0 : }
335 :
336 : css::uno::Reference<css::rendering::XBitmap>
337 0 : PresenterBitmapContainer::BitmapDescriptor::GetNormalBitmap() const
338 : {
339 0 : return mxNormalBitmap;
340 : }
341 :
342 : css::uno::Reference<css::rendering::XBitmap>
343 0 : PresenterBitmapContainer::BitmapDescriptor::GetBitmap(const Mode eMode) const
344 : {
345 0 : switch (eMode)
346 : {
347 : case Normal:
348 : default:
349 0 : return mxNormalBitmap;
350 :
351 : case MouseOver:
352 0 : if (mxMouseOverBitmap.is())
353 0 : return mxMouseOverBitmap;
354 : else
355 0 : return mxNormalBitmap;
356 :
357 : case ButtonDown:
358 0 : if (mxButtonDownBitmap.is())
359 0 : return mxButtonDownBitmap;
360 : else
361 0 : return mxNormalBitmap;
362 :
363 : case Disabled:
364 0 : if (mxDisabledBitmap.is())
365 0 : return mxDisabledBitmap;
366 : else
367 0 : return mxNormalBitmap;
368 :
369 : case Mask:
370 0 : return mxMaskBitmap;
371 : }
372 : }
373 :
374 0 : void PresenterBitmapContainer::BitmapDescriptor::SetBitmap (
375 : const Mode eMode,
376 : const css::uno::Reference<css::rendering::XBitmap>& rxBitmap)
377 : {
378 0 : switch (eMode)
379 : {
380 : case Normal:
381 : default:
382 0 : mxNormalBitmap = rxBitmap;
383 0 : if (mxNormalBitmap.is())
384 : {
385 0 : const geometry::IntegerSize2D aSize (mxNormalBitmap->getSize());
386 0 : mnWidth = aSize.Width;
387 0 : mnHeight = aSize.Height;
388 : }
389 0 : break;
390 :
391 : case MouseOver:
392 0 : mxMouseOverBitmap = rxBitmap;
393 0 : break;
394 :
395 : case ButtonDown:
396 0 : mxButtonDownBitmap = rxBitmap;
397 0 : break;
398 :
399 : case Disabled:
400 0 : mxDisabledBitmap = rxBitmap;
401 0 : break;
402 :
403 : case Mask:
404 0 : mxMaskBitmap = rxBitmap;
405 0 : break;
406 : }
407 0 : }
408 :
409 24 : } } // end of namespace ::sdext::presenter
410 :
411 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|