1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sdext.hxx"
26
27 #include "PresenterBitmapContainer.hxx"
28 #include "PresenterConfigurationAccess.hxx"
29
30 #include <com/sun/star/deployment/XPackageInformationProvider.hpp>
31 #include <com/sun/star/drawing/XPresenterHelper.hpp>
32 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
33 #include <com/sun/star/rendering/CompositeOperation.hpp>
34 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
35 #include <boost/bind.hpp>
36 #include <map>
37
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::std;
41 using ::rtl::OUString;
42
43 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
44
45
46 namespace sdext { namespace presenter {
47
48 namespace {
49 static OUString gsNameProperty (A2S("Name"));
50 static OUString gsNormalFileNameProperty (A2S("NormalFileName"));
51 static OUString gsMouseOverFileNameProperty (A2S("MouseOverFileName"));
52 static OUString gsButtonDownFileNameProperty (A2S("ButtonDownFileName"));
53 static OUString gsDisabledFileNameProperty (A2S("DisabledFileName"));
54 static OUString gsMaskFileNameProperty (A2S("MaskFileName"));
55 static OUString gsXOffsetProperty (A2S("XOffset"));
56 static OUString gsYOffsetProperty (A2S("YOffset"));
57 static OUString gsXHotSpotProperty (A2S("XHotSpot"));
58 static OUString gsYHotSpotProperty (A2S("YHotSpot"));
59 static OUString gsReplacementColorProperty (A2S("ReplacementColor"));
60 static OUString gsHorizontalTexturingModeProperty (A2S("HorizontalTexturingMode"));
61 static OUString gsVerticalTexturingModeProperty (A2S("VerticalTexturingMode"));
62 }
63
64 //===== PresenterBitmapContainer ==============================================
65
PresenterBitmapContainer(const::rtl::OUString & rsConfigurationBase,const::boost::shared_ptr<PresenterBitmapContainer> & rpParentContainer,const css::uno::Reference<css::uno::XComponentContext> & rxComponentContext,const css::uno::Reference<css::rendering::XCanvas> & rxCanvas,const css::uno::Reference<css::drawing::XPresenterHelper> & rxPresenterHelper)66 PresenterBitmapContainer::PresenterBitmapContainer (
67 const ::rtl::OUString& rsConfigurationBase,
68 const ::boost::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
69 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
70 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
71 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper)
72 : mpParentContainer(rpParentContainer),
73 maIconContainer(),
74 mxCanvas(rxCanvas),
75 mxPresenterHelper(rxPresenterHelper)
76 {
77 Initialize(rxComponentContext);
78
79 // Get access to the configuration.
80 PresenterConfigurationAccess aConfiguration (
81 rxComponentContext,
82 A2S("org.openoffice.Office.PresenterScreen"),
83 PresenterConfigurationAccess::READ_ONLY);
84 Reference<container::XNameAccess> xBitmapList (
85 aConfiguration.GetConfigurationNode(rsConfigurationBase),
86 UNO_QUERY_THROW);
87
88 LoadBitmaps(xBitmapList);
89 }
90
91
92
93
94
PresenterBitmapContainer(const css::uno::Reference<css::container::XNameAccess> & rxRootNode,const::boost::shared_ptr<PresenterBitmapContainer> & rpParentContainer,const css::uno::Reference<css::uno::XComponentContext> & rxComponentContext,const css::uno::Reference<css::rendering::XCanvas> & rxCanvas,const css::uno::Reference<css::drawing::XPresenterHelper> & rxPresenterHelper)95 PresenterBitmapContainer::PresenterBitmapContainer (
96 const css::uno::Reference<css::container::XNameAccess>& rxRootNode,
97 const ::boost::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
98 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
99 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
100 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper)
101 : mpParentContainer(rpParentContainer),
102 maIconContainer(),
103 mxCanvas(rxCanvas),
104 mxPresenterHelper(rxPresenterHelper)
105 {
106 Initialize(rxComponentContext);
107
108 LoadBitmaps(rxRootNode);
109 }
110
111
112
113
Initialize(const css::uno::Reference<css::uno::XComponentContext> & rxComponentContext)114 void PresenterBitmapContainer::Initialize (
115 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext)
116 {
117 if ( ! mxPresenterHelper.is())
118 {
119 // Create an object that is able to load the bitmaps in a format that is
120 // supported by the canvas.
121 Reference<lang::XMultiComponentFactory> xFactory (
122 rxComponentContext->getServiceManager(), UNO_QUERY);
123 if ( ! xFactory.is())
124 return;
125 mxPresenterHelper = Reference<drawing::XPresenterHelper>(
126 xFactory->createInstanceWithContext(
127 A2S("com.sun.star.drawing.PresenterHelper"),
128 rxComponentContext),
129 UNO_QUERY_THROW);
130 }
131 }
132
133
134
135
~PresenterBitmapContainer(void)136 PresenterBitmapContainer::~PresenterBitmapContainer (void)
137 {
138 maIconContainer.clear();
139 }
140
141
142
143
GetBitmap(const OUString & rsName) const144 SharedBitmapDescriptor PresenterBitmapContainer::GetBitmap (
145 const OUString& rsName) const
146 {
147 BitmapContainer::const_iterator iSet (maIconContainer.find(rsName));
148 if (iSet != maIconContainer.end())
149 return iSet->second;
150 else if (mpParentContainer.get() != NULL)
151 return mpParentContainer->GetBitmap(rsName);
152 else
153 return SharedBitmapDescriptor();
154 }
155
156
157
158
LoadBitmaps(const css::uno::Reference<css::container::XNameAccess> & rxBitmapList)159 void PresenterBitmapContainer::LoadBitmaps (
160 const css::uno::Reference<css::container::XNameAccess>& rxBitmapList)
161 {
162 if ( ! mxCanvas.is())
163 return;
164
165 if ( ! rxBitmapList.is())
166 return;
167
168 try
169 {
170 // Load all button bitmaps.
171 if (rxBitmapList.is())
172 {
173 PresenterConfigurationAccess::ForAll(
174 rxBitmapList,
175 ::boost::bind(&PresenterBitmapContainer::ProcessBitmap, this, _1, _2));
176 }
177 }
178 catch (Exception&)
179 {
180 OSL_ASSERT(false);
181 }
182 }
183
184
185
186
LoadBitmap(const css::uno::Reference<css::container::XHierarchicalNameAccess> & rxNode,const::rtl::OUString & rsPath,const css::uno::Reference<css::drawing::XPresenterHelper> & rxPresenterHelper,const css::uno::Reference<css::rendering::XCanvas> & rxCanvas,const SharedBitmapDescriptor & rpDefault)187 SharedBitmapDescriptor PresenterBitmapContainer::LoadBitmap (
188 const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
189 const ::rtl::OUString& rsPath,
190 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
191 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
192 const SharedBitmapDescriptor& rpDefault)
193 {
194 SharedBitmapDescriptor pBitmap;
195
196 if (rxNode.is())
197 {
198 try
199 {
200 Reference<beans::XPropertySet> xBitmapProperties (
201 PresenterConfigurationAccess::GetConfigurationNode(rxNode, rsPath),
202 UNO_QUERY);
203 if (xBitmapProperties.is())
204 pBitmap = LoadBitmap(
205 xBitmapProperties,
206 rxPresenterHelper,
207 rxCanvas,
208 rpDefault);
209 }
210 catch (Exception&)
211 {
212 OSL_ASSERT(false);
213 }
214 }
215
216 return pBitmap;
217 }
218
219
220
221
ProcessBitmap(const OUString & rsKey,const Reference<beans::XPropertySet> & rxProperties)222 void PresenterBitmapContainer::ProcessBitmap (
223 const OUString& rsKey,
224 const Reference<beans::XPropertySet>& rxProperties)
225 {
226 OUString sName;
227 if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties, gsNameProperty) >>= sName))
228 sName = rsKey;
229
230 maIconContainer[sName] = LoadBitmap(
231 rxProperties,
232 mxPresenterHelper,
233 mxCanvas,
234 SharedBitmapDescriptor());
235 }
236
237
238
239
LoadBitmap(const Reference<beans::XPropertySet> & rxProperties,const css::uno::Reference<css::drawing::XPresenterHelper> & rxPresenterHelper,const css::uno::Reference<css::rendering::XCanvas> & rxCanvas,const SharedBitmapDescriptor & rpDefault)240 SharedBitmapDescriptor PresenterBitmapContainer::LoadBitmap (
241 const Reference<beans::XPropertySet>& rxProperties,
242 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
243 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
244 const SharedBitmapDescriptor& rpDefault)
245 {
246 OSL_ASSERT(rxCanvas.is());
247 OSL_ASSERT(rxPresenterHelper.is());
248
249 SharedBitmapDescriptor pBitmap (new BitmapDescriptor(rpDefault));
250
251 if ( ! rxProperties.is())
252 return pBitmap;
253
254 OUString sFileName;
255
256 // Load bitmaps.
257 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsNormalFileNameProperty) >>= sFileName)
258 try
259 {
260 pBitmap->SetBitmap(
261 BitmapDescriptor::Normal,
262 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
263 }
264 catch (Exception&)
265 {}
266 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsMouseOverFileNameProperty) >>= sFileName)
267 try
268 {
269 pBitmap->SetBitmap(
270 BitmapDescriptor::MouseOver,
271 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
272 }
273 catch (Exception&)
274 {}
275 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsButtonDownFileNameProperty) >>= sFileName)
276 try
277 {
278 pBitmap->SetBitmap(
279 BitmapDescriptor::ButtonDown,
280 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
281 }
282 catch (Exception&)
283 {}
284 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsDisabledFileNameProperty) >>= sFileName)
285 try
286 {
287 pBitmap->SetBitmap(
288 BitmapDescriptor::Disabled,
289 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
290 }
291 catch (Exception&)
292 {}
293 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsMaskFileNameProperty) >>= sFileName)
294 try
295 {
296 pBitmap->SetBitmap(
297 BitmapDescriptor::Mask,
298 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
299 }
300 catch (Exception&)
301 {}
302
303
304 PresenterConfigurationAccess::GetProperty(rxProperties, gsXOffsetProperty) >>= pBitmap->mnXOffset;
305 PresenterConfigurationAccess::GetProperty(rxProperties, gsYOffsetProperty) >>= pBitmap->mnYOffset;
306
307 PresenterConfigurationAccess::GetProperty(rxProperties, gsXHotSpotProperty) >>= pBitmap->mnXHotSpot;
308 PresenterConfigurationAccess::GetProperty(rxProperties, gsYHotSpotProperty) >>= pBitmap->mnYHotSpot;
309
310 PresenterConfigurationAccess::GetProperty(rxProperties, gsReplacementColorProperty) >>= pBitmap->maReplacementColor;
311
312 OUString sTexturingMode;
313 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsHorizontalTexturingModeProperty) >>= sTexturingMode)
314 pBitmap->meHorizontalTexturingMode = StringToTexturingMode(sTexturingMode);
315 if (PresenterConfigurationAccess::GetProperty(rxProperties, gsVerticalTexturingModeProperty) >>= sTexturingMode)
316 pBitmap->meVerticalTexturingMode = StringToTexturingMode(sTexturingMode);
317
318 return pBitmap;
319 }
320
321
322
323
324 PresenterBitmapContainer::BitmapDescriptor::TexturingMode
StringToTexturingMode(const OUString & rsTexturingMode)325 PresenterBitmapContainer::StringToTexturingMode (const OUString& rsTexturingMode)
326 {
327 if (rsTexturingMode == A2S("Once"))
328 return PresenterBitmapContainer::BitmapDescriptor::Once;
329 else if (rsTexturingMode == A2S("Repeat"))
330 return PresenterBitmapContainer::BitmapDescriptor::Repeat;
331 else if (rsTexturingMode == A2S("Stretch"))
332 return PresenterBitmapContainer::BitmapDescriptor::Stretch;
333 else
334 return PresenterBitmapContainer::BitmapDescriptor::Once;
335 }
336
337
338
339
340 //===== PresenterBitmapContainer::BitmapSet ===================================
341
BitmapDescriptor(void)342 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (void)
343 : mnWidth(0),
344 mnHeight(0),
345 mnXOffset(0),
346 mnYOffset(0),
347 mnXHotSpot(0),
348 mnYHotSpot(0),
349 maReplacementColor(0x00000000),
350 meHorizontalTexturingMode(Once),
351 meVerticalTexturingMode(Once),
352 mxNormalBitmap(),
353 mxMouseOverBitmap(),
354 mxButtonDownBitmap(),
355 mxDisabledBitmap(),
356 mxMaskBitmap()
357 {
358 }
359
360
361
362
BitmapDescriptor(const::boost::shared_ptr<PresenterBitmapContainer::BitmapDescriptor> & rpDefault)363 PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (
364 const ::boost::shared_ptr<PresenterBitmapContainer::BitmapDescriptor>& rpDefault)
365 : mnWidth(0),
366 mnHeight(0),
367 mnXOffset(0),
368 mnYOffset(0),
369 mnXHotSpot(0),
370 mnYHotSpot(0),
371 maReplacementColor(0x00000000),
372 meHorizontalTexturingMode(Once),
373 meVerticalTexturingMode(Once),
374 mxNormalBitmap(),
375 mxMouseOverBitmap(),
376 mxButtonDownBitmap(),
377 mxDisabledBitmap(),
378 mxMaskBitmap()
379 {
380 if (rpDefault.get() != NULL)
381 {
382 mnWidth = rpDefault->mnWidth;
383 mnHeight = rpDefault->mnHeight;
384 mnXOffset = rpDefault->mnXOffset;
385 mnYOffset = rpDefault->mnYOffset;
386 mnXHotSpot = rpDefault->mnXHotSpot;
387 mnYHotSpot = rpDefault->mnYHotSpot;
388 maReplacementColor = rpDefault->maReplacementColor;
389 meHorizontalTexturingMode = rpDefault->meHorizontalTexturingMode;
390 meVerticalTexturingMode = rpDefault->meVerticalTexturingMode;
391 mxNormalBitmap = rpDefault->mxNormalBitmap;
392 mxMouseOverBitmap = rpDefault->mxMouseOverBitmap;
393 mxButtonDownBitmap = rpDefault->mxButtonDownBitmap;
394 mxDisabledBitmap = rpDefault->mxDisabledBitmap;
395 mxMaskBitmap = rpDefault->mxMaskBitmap;
396 }
397 }
398
399
400 css::uno::Reference<css::rendering::XBitmap>
GetNormalBitmap(void) const401 PresenterBitmapContainer::BitmapDescriptor::GetNormalBitmap (void) const
402 {
403 return mxNormalBitmap;
404 }
405
406
407
408
409 css::uno::Reference<css::rendering::XBitmap>
GetBitmap(const Mode eMode,const bool bMissingDefaultsToNormal) const410 PresenterBitmapContainer::BitmapDescriptor::GetBitmap (
411 const Mode eMode,
412 const bool bMissingDefaultsToNormal) const
413 {
414 switch (eMode)
415 {
416 case Normal:
417 default:
418 return mxNormalBitmap;
419
420 case MouseOver:
421 if (mxMouseOverBitmap.is())
422 return mxMouseOverBitmap;
423 else if (bMissingDefaultsToNormal)
424 return mxNormalBitmap;
425
426 case ButtonDown:
427 if (mxButtonDownBitmap.is())
428 return mxButtonDownBitmap;
429 else if (bMissingDefaultsToNormal)
430 return mxNormalBitmap;
431
432 case Disabled:
433 if (mxDisabledBitmap.is())
434 return mxDisabledBitmap;
435 else if (bMissingDefaultsToNormal)
436 return mxNormalBitmap;
437
438 case Mask:
439 return mxMaskBitmap;
440 }
441 return NULL;
442 }
443
444
445
446
SetBitmap(const Mode eMode,const css::uno::Reference<css::rendering::XBitmap> & rxBitmap)447 void PresenterBitmapContainer::BitmapDescriptor::SetBitmap (
448 const Mode eMode,
449 const css::uno::Reference<css::rendering::XBitmap>& rxBitmap)
450 {
451 switch (eMode)
452 {
453 case Normal:
454 default:
455 mxNormalBitmap = rxBitmap;
456 if (mxNormalBitmap.is())
457 {
458 const geometry::IntegerSize2D aSize (mxNormalBitmap->getSize());
459 mnWidth = aSize.Width;
460 mnHeight = aSize.Height;
461 }
462 break;
463
464 case MouseOver:
465 mxMouseOverBitmap = rxBitmap;
466 break;
467
468 case ButtonDown:
469 mxButtonDownBitmap = rxBitmap;
470 break;
471
472 case Disabled:
473 mxDisabledBitmap = rxBitmap;
474 break;
475
476 case Mask:
477 mxMaskBitmap = rxBitmap;
478 break;
479 }
480 }
481
482
483
484
485 } } // end of namespace ::sdext::presenter
486