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