LibreOffice Module sdext (master)  1
PresenterBitmapContainer.cxx
Go to the documentation of this file.
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 
22 
23 #include <com/sun/star/drawing/XPresenterHelper.hpp>
24 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
25 #include <osl/diagnose.h>
26 
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::uno;
29 using namespace ::std;
30 
31 namespace sdext::presenter {
32 
33 //===== PresenterBitmapContainer ==============================================
34 
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),
42  mxCanvas(rxCanvas),
43  mxPresenterHelper(rxPresenterHelper)
44 {
45  Initialize(rxComponentContext);
46 
47  // Get access to the configuration.
48  PresenterConfigurationAccess aConfiguration (
49  rxComponentContext,
50  "org.openoffice.Office.PresenterScreen",
53  aConfiguration.GetConfigurationNode(rsConfigurationBase),
54  UNO_QUERY_THROW);
55 
56  LoadBitmaps(xBitmapList);
57 }
58 
60  const css::uno::Reference<css::container::XNameAccess>& rxRootNode,
61  const std::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
62  const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
63  const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
64  const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper)
65  : mpParentContainer(rpParentContainer),
66  mxCanvas(rxCanvas),
67  mxPresenterHelper(rxPresenterHelper)
68 {
69  Initialize(rxComponentContext);
70 
71  LoadBitmaps(rxRootNode);
72 }
73 
75  const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext)
76 {
77  if ( mxPresenterHelper.is())
78  return;
79 
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();
84  if ( ! xFactory.is())
85  return;
87  xFactory->createInstanceWithContext(
88  "com.sun.star.drawing.PresenterHelper",
89  rxComponentContext),
90  UNO_QUERY_THROW);
91 }
92 
94 {
95  maIconContainer.clear();
96 }
97 
98 std::shared_ptr<PresenterBitmapContainer::BitmapDescriptor> PresenterBitmapContainer::GetBitmap (
99  const OUString& rsName) const
100 {
101  BitmapContainer::const_iterator iSet (maIconContainer.find(rsName));
102  if (iSet != maIconContainer.end())
103  return iSet->second;
104  else if (mpParentContainer != nullptr)
105  return mpParentContainer->GetBitmap(rsName);
106  else
107  return SharedBitmapDescriptor();
108 }
109 
111  const css::uno::Reference<css::container::XNameAccess>& rxBitmapList)
112 {
113  if ( ! mxCanvas.is())
114  return;
115 
116  if ( ! rxBitmapList.is())
117  return;
118 
119  try
120  {
121  // Load all button bitmaps.
122  if (rxBitmapList.is())
123  {
125  rxBitmapList,
126  [this](OUString const& rKey, Reference<beans::XPropertySet> const& xProps)
127  {
128  this->ProcessBitmap(rKey, xProps);
129  });
130  }
131  }
132  catch (Exception&)
133  {
134  OSL_ASSERT(false);
135  }
136 }
137 
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)
144 {
145  SharedBitmapDescriptor pBitmap;
146 
147  if (rxNode.is())
148  {
149  try
150  {
151  Reference<beans::XPropertySet> xBitmapProperties (
153  UNO_QUERY);
154  if (xBitmapProperties.is())
155  pBitmap = LoadBitmap(
156  xBitmapProperties,
157  rxPresenterHelper,
158  rxCanvas,
159  rpDefault);
160  }
161  catch (Exception&)
162  {
163  OSL_ASSERT(false);
164  }
165  }
166 
167  return pBitmap;
168 }
169 
171  const OUString& rsKey,
172  const Reference<beans::XPropertySet>& rxProperties)
173 {
174  OUString sName;
175  if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties, "Name") >>= sName))
176  sName = rsKey;
177 
178  maIconContainer[sName] = LoadBitmap(
179  rxProperties,
181  mxCanvas,
183 }
184 
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)
190 {
191  OSL_ASSERT(rxCanvas.is());
192  OSL_ASSERT(rxPresenterHelper.is());
193 
194  SharedBitmapDescriptor pBitmap = std::make_shared<BitmapDescriptor>(rpDefault);
195 
196  if ( ! rxProperties.is())
197  return pBitmap;
198 
199  OUString sFileName;
200 
201  // Load bitmaps.
202  if (PresenterConfigurationAccess::GetProperty(rxProperties, "NormalFileName") >>= sFileName)
203  try
204  {
205  pBitmap->SetBitmap(
207  rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
208  }
209  catch (Exception&)
210  {}
211  if (PresenterConfigurationAccess::GetProperty(rxProperties, "MouseOverFileName") >>= sFileName)
212  try
213  {
214  pBitmap->SetBitmap(
216  rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
217  }
218  catch (Exception&)
219  {}
220  if (PresenterConfigurationAccess::GetProperty(rxProperties, "ButtonDownFileName") >>= sFileName)
221  try
222  {
223  pBitmap->SetBitmap(
225  rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
226  }
227  catch (Exception&)
228  {}
229  if (PresenterConfigurationAccess::GetProperty(rxProperties, "DisabledFileName") >>= sFileName)
230  try
231  {
232  pBitmap->SetBitmap(
234  rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
235  }
236  catch (Exception&)
237  {}
238  if (PresenterConfigurationAccess::GetProperty(rxProperties, "MaskFileName") >>= sFileName)
239  try
240  {
241  pBitmap->SetBitmap(
243  rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
244  }
245  catch (Exception&)
246  {}
247 
248  PresenterConfigurationAccess::GetProperty(rxProperties, "XOffset") >>= pBitmap->mnXOffset;
249  PresenterConfigurationAccess::GetProperty(rxProperties, "YOffset") >>= pBitmap->mnYOffset;
250 
251  PresenterConfigurationAccess::GetProperty(rxProperties, "XHotSpot") >>= pBitmap->mnXHotSpot;
252  PresenterConfigurationAccess::GetProperty(rxProperties, "YHotSpot") >>= pBitmap->mnYHotSpot;
253 
254  PresenterConfigurationAccess::GetProperty(rxProperties, "ReplacementColor") >>= pBitmap->maReplacementColor;
255 
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);
261 
262  return pBitmap;
263 }
264 
266  PresenterBitmapContainer::StringToTexturingMode (std::u16string_view rsTexturingMode)
267 {
268  if (rsTexturingMode == u"Once")
270  else if (rsTexturingMode == u"Repeat")
272  else if (rsTexturingMode == u"Stretch")
274  else
276 }
277 
278 //===== PresenterBitmapContainer::BitmapSet ===================================
279 
281  : mnWidth(0),
282  mnHeight(0),
283  mnXOffset(0),
284  mnYOffset(0),
285  mnXHotSpot(0),
286  mnYHotSpot(0),
287  maReplacementColor(0x00000000),
288  meHorizontalTexturingMode(Once),
289  meVerticalTexturingMode(Once)
290 {
291 }
292 
294  const std::shared_ptr<PresenterBitmapContainer::BitmapDescriptor>& rpDefault)
295  : mnWidth(0),
296  mnHeight(0),
297  mnXOffset(0),
298  mnYOffset(0),
299  mnXHotSpot(0),
300  mnYHotSpot(0),
301  maReplacementColor(0x00000000),
302  meHorizontalTexturingMode(Once),
303  meVerticalTexturingMode(Once)
304 {
305  if (rpDefault == nullptr)
306  return;
307 
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;
322 }
323 
324 const css::uno::Reference<css::rendering::XBitmap>&
326 {
327  return mxNormalBitmap;
328 }
329 
330 css::uno::Reference<css::rendering::XBitmap> const &
332 {
333  switch (eMode)
334  {
335  case Normal:
336  default:
337  return mxNormalBitmap;
338 
339  case MouseOver:
340  if (mxMouseOverBitmap.is())
341  return mxMouseOverBitmap;
342  else
343  return mxNormalBitmap;
344 
345  case ButtonDown:
346  if (mxButtonDownBitmap.is())
347  return mxButtonDownBitmap;
348  else
349  return mxNormalBitmap;
350 
351  case Disabled:
352  if (mxDisabledBitmap.is())
353  return mxDisabledBitmap;
354  else
355  return mxNormalBitmap;
356 
357  case Mask:
358  return mxMaskBitmap;
359  }
360 }
361 
363  const Mode eMode,
364  const css::uno::Reference<css::rendering::XBitmap>& rxBitmap)
365 {
366  switch (eMode)
367  {
368  case Normal:
369  default:
370  mxNormalBitmap = rxBitmap;
371  if (mxNormalBitmap.is())
372  {
373  const geometry::IntegerSize2D aSize (mxNormalBitmap->getSize());
374  mnWidth = aSize.Width;
375  mnHeight = aSize.Height;
376  }
377  break;
378 
379  case MouseOver:
380  mxMouseOverBitmap = rxBitmap;
381  break;
382 
383  case ButtonDown:
384  mxButtonDownBitmap = rxBitmap;
385  break;
386 
387  case Disabled:
388  mxDisabledBitmap = rxBitmap;
389  break;
390 
391  case Mask:
392  mxMaskBitmap = rxBitmap;
393  break;
394  }
395 }
396 
397 } // end of namespace ::sdext::presenter
398 
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void ForAll(const css::uno::Reference< css::container::XNameAccess > &rxContainer, const ::std::vector< OUString > &rArguments, const ItemProcessor &rProcessor)
Execute a functor for all elements of the given container.
Reference< rendering::XCanvas > mxCanvas
double mnHeight
void SetBitmap(const Mode eMode, const css::uno::Reference< css::rendering::XBitmap > &rxBitmap)
static css::uno::Any GetProperty(const css::uno::Reference< css::beans::XPropertySet > &rxProperties, const OUString &rsKey)
This method wraps a call to getPropertyValue() and returns an empty Any instead of throwing an except...
css::uno::Reference< css::rendering::XBitmap > mxNormalBitmap
void ProcessBitmap(const OUString &rsKey, const css::uno::Reference< css::beans::XPropertySet > &rProperties)
std::shared_ptr< PresenterBitmapContainer::BitmapDescriptor > SharedBitmapDescriptor
Reference< drawing::XPresenterHelper > mxPresenterHelper
This class gives access to the configuration.
css::uno::Reference< css::rendering::XBitmap > mxButtonDownBitmap
css::uno::Reference< css::rendering::XBitmap > mxMaskBitmap
const char * sName
void Initialize(const css::uno::Reference< css::uno::XComponentContext > &rxComponentContext)
css::uno::Reference< css::rendering::XCanvas > mxCanvas
css::uno::Reference< css::rendering::XBitmap > mxMouseOverBitmap
static BitmapDescriptor::TexturingMode StringToTexturingMode(std::u16string_view rsTexturingMode)
css::uno::Any GetConfigurationNode(const OUString &rsPathToNode)
Return a configuration node below the root of the called object.
float u
std::shared_ptr< BitmapDescriptor > GetBitmap(const OUString &rsName) const
Return the bitmap set that is associated with the given name.
css::uno::Reference< css::rendering::XBitmap > const & GetBitmap(const Mode eMode) const
css::uno::Reference< css::drawing::XPresenterHelper > mxPresenterHelper
static std::shared_ptr< BitmapDescriptor > LoadBitmap(const css::uno::Reference< css::container::XHierarchicalNameAccess > &rxNode, const OUString &rsPathToBitmapNode, const css::uno::Reference< css::drawing::XPresenterHelper > &rxPresenterHelper, const css::uno::Reference< css::rendering::XCanvas > &rxCanvas, const std::shared_ptr< BitmapDescriptor > &rpDefaultBitmap)
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
PresenterBitmapContainer(const OUString &rsConfigurationBase, const std::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=nullptr)
Create a new bitmap container from a section of the configuration.
double mnWidth
css::uno::Reference< css::rendering::XBitmap > mxDisabledBitmap
const css::uno::Reference< css::rendering::XBitmap > & GetNormalBitmap() const
Reference< XSingleServiceFactory > xFactory
std::shared_ptr< PresenterBitmapContainer > mpParentContainer
void LoadBitmaps(const css::uno::Reference< css::container::XNameAccess > &rsRootNode)