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