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 #include "precompiled_sd.hxx" 29 30 #include "view/SlsTheme.hxx" 31 #include "SlsResource.hxx" 32 #include "controller/SlsProperties.hxx" 33 #include "sdresid.hxx" 34 #include <tools/color.hxx> 35 #include <vcl/outdev.hxx> 36 #include <vcl/image.hxx> 37 #include <vcl/svapp.hxx> 38 #include <svtools/colorcfg.hxx> 39 40 namespace sd { namespace slidesorter { namespace view { 41 42 const static ColorData Black = 0x000000; 43 const static ColorData White = 0xffffff; 44 45 46 47 ColorData ChangeLuminance (const ColorData aColorData, const int nValue) 48 { 49 Color aColor (aColorData); 50 if (nValue > 0) 51 aColor.IncreaseLuminance(nValue); 52 else 53 aColor.DecreaseLuminance(-nValue); 54 return aColor.GetColor(); 55 } 56 57 ColorData HGBAdapt ( 58 const ColorData aColorData, 59 const sal_Int32 nNewSaturation, 60 const sal_Int32 nNewBrightness) 61 { 62 sal_uInt16 nHue (0); 63 sal_uInt16 nSaturation (0); 64 sal_uInt16 nBrightness (0); 65 Color(aColorData).RGBtoHSB(nHue, nSaturation, nBrightness); 66 return Color::HSBtoRGB( 67 nHue, 68 nNewSaturation>=0 ? nNewSaturation : nSaturation, 69 nNewBrightness>=0 ? nNewBrightness : nBrightness); 70 } 71 72 73 74 75 Theme::Theme (const ::boost::shared_ptr<controller::Properties>& rpProperties) 76 : mbIsHighContrastMode(false), 77 maBackgroundColor(rpProperties->GetBackgroundColor().GetColor()), 78 maPageBackgroundColor(COL_WHITE), 79 maGradients(), 80 maIcons(), 81 maColor(), 82 maIntegerValues() 83 { 84 { 85 LocalResource aResource (RID_SLIDESORTER_ICONS); 86 87 maStrings.resize(_StringType_Size_); 88 maStrings[String_DragAndDropPages] = String(SdResId(STRING_DRAG_AND_DROP_PAGES)); 89 maStrings[String_DragAndDropSlides] = String(SdResId(STRING_DRAG_AND_DROP_SLIDES)); 90 maStrings[String_Command1] = String(SdResId(STRING_COMMAND1)); 91 maStrings[String_Command2] = String(SdResId(STRING_COMMAND2_A)); 92 maStrings[String_Command2B] = String(SdResId(STRING_COMMAND2_B)); 93 maStrings[String_Command3] = String(SdResId(STRING_COMMAND3)); 94 95 maColor.resize(_ColorType_Size_); 96 maColor[Color_Background] = maBackgroundColor; 97 maColor[Color_ButtonBackground] = Black; 98 maColor[Color_ButtonText] = 0xc0c0c0; 99 maColor[Color_ButtonTextHover] = White; 100 maColor[Color_PageNumberDefault] = 0x0808080; 101 maColor[Color_PageNumberHover] = 0x4c4c4c; 102 maColor[Color_PageNumberHighContrast] = White; 103 maColor[Color_PageNumberBrightBackground] = 0x333333; 104 maColor[Color_PageNumberDarkBackground] = 0xcccccc; 105 maColor[Color_PreviewBorder] = 0x949599; 106 107 maIntegerValues.resize(_IntegerValueType_Size_); 108 maIntegerValues[Integer_ButtonCornerRadius] = 3; 109 maIntegerValues[Integer_ButtonMaxAlpha] = 0; 110 maIntegerValues[Integer_ButtonBarMaxAlpha] = 0; 111 maIntegerValues[Integer_ButtonPaintType] = 1; 112 maIntegerValues[Integer_ButtonBorder] = 4; 113 maIntegerValues[Integer_ButtonGap] = 0; 114 maIntegerValues[Integer_ButtonFadeInDelay] = 800; 115 maIntegerValues[Integer_ButtonFadeInDuration] = 100; 116 maIntegerValues[Integer_ButtonFadeOutDelay] = 0; 117 maIntegerValues[Integer_ButtonFadeOutDuration] = 100; 118 maIntegerValues[Integer_ToolTipDelay] = 1000; 119 maIntegerValues[Integer_FocusIndicatorWidth] = 3; 120 } 121 122 Update(rpProperties); 123 } 124 125 126 127 128 void Theme::Update (const ::boost::shared_ptr<controller::Properties>& rpProperties) 129 { 130 const bool bSavedHighContrastMode (mbIsHighContrastMode); 131 mbIsHighContrastMode = rpProperties->IsHighContrastModeActive(); 132 133 // Set up colors. 134 maBackgroundColor = rpProperties->GetBackgroundColor().GetColor(); 135 maPageBackgroundColor = svtools::ColorConfig().GetColorValue(svtools::DOCCOLOR).nColor; 136 137 maColor[Color_Background] = maBackgroundColor; 138 139 maGradients.resize(_GradientColorType_Size_); 140 141 maColor[Color_Background] = maBackgroundColor; 142 const ColorData aSelectionColor (rpProperties->GetSelectionColor().GetColor()); 143 maColor[Color_Selection] = aSelectionColor; 144 if (Color(aSelectionColor).IsBright()) 145 maColor[Color_PageCountFontColor] = Black; 146 else 147 maColor[Color_PageCountFontColor] = White; 148 149 // Set up gradients. 150 SetGradient(Gradient_SelectedPage, aSelectionColor, 50, 50, +100,+100, +50,+25); 151 SetGradient(Gradient_MouseOverPage, aSelectionColor, 75, 75, +100,+100, +50,+25); 152 SetGradient(Gradient_SelectedAndFocusedPage, aSelectionColor, 50, 50, +100,+100, -50,-75); 153 SetGradient(Gradient_MouseOverSelectedAndFocusedPage, aSelectionColor, 75, 75, +100,+100, -50,-75); 154 SetGradient(Gradient_FocusedPage, aSelectionColor, -1,-1, 0,0, -50,-75); 155 156 SetGradient(Gradient_ButtonBackground, Black, -1,-1, 0,0, 0,0); 157 SetGradient(Gradient_NormalPage, maBackgroundColor, -1,-1, 0,0, 0,0); 158 159 // The focused gradient needs special handling because its fill color is 160 // like that of the NormalPage gradient. 161 GetGradient(Gradient_FocusedPage).maFillColor1 = GetGradient(Gradient_NormalPage).maFillColor1; 162 GetGradient(Gradient_FocusedPage).maFillColor2 = GetGradient(Gradient_NormalPage).maFillColor2; 163 164 // Set up icons. 165 if (bSavedHighContrastMode != mbIsHighContrastMode || maIcons.empty()) 166 { 167 LocalResource aResource (RID_SLIDESORTER_ICONS); 168 169 maIcons.resize(_IconType_Size_); 170 if (mbIsHighContrastMode) 171 { 172 InitializeIcon(Icon_RawShadow, IMAGE_SHADOW); 173 InitializeIcon(Icon_RawInsertShadow, IMAGE_INSERT_SHADOW); 174 InitializeIcon(Icon_HideSlideOverlay, IMAGE_HIDE_SLIDE_OVERLAY); 175 176 InitializeIcon(Icon_ButtonBarLarge, IMAGE_BUTTONBAR_LARGE_HC); 177 InitializeIcon(Icon_ButtonBarMedium, IMAGE_BUTTONBAR_MEDIUM_HC); 178 InitializeIcon(Icon_ButtonBarSmall, IMAGE_BUTTONBAR_SMALL_HC); 179 180 InitializeIcon(Icon_Command1Large, IMAGE_COMMAND1_LARGE_HC); 181 InitializeIcon(Icon_Command1LargeHover, IMAGE_COMMAND1_LARGE_HOVER_HC); 182 InitializeIcon(Icon_Command1Medium, IMAGE_COMMAND1_MEDIUM_HC); 183 InitializeIcon(Icon_Command1MediumHover, IMAGE_COMMAND1_MEDIUM_HOVER_HC); 184 InitializeIcon(Icon_Command1Small, IMAGE_COMMAND1_SMALL_HC); 185 InitializeIcon(Icon_Command1SmallHover, IMAGE_COMMAND1_SMALL_HOVER_HC); 186 187 InitializeIcon(Icon_Command2Large, IMAGE_COMMAND2_LARGE_HC); 188 InitializeIcon(Icon_Command2LargeHover, IMAGE_COMMAND2_LARGE_HOVER_HC); 189 InitializeIcon(Icon_Command2Medium, IMAGE_COMMAND2_MEDIUM_HC); 190 InitializeIcon(Icon_Command2MediumHover, IMAGE_COMMAND2_MEDIUM_HOVER_HC); 191 InitializeIcon(Icon_Command2Small, IMAGE_COMMAND2_SMALL_HC); 192 InitializeIcon(Icon_Command2SmallHover, IMAGE_COMMAND2_SMALL_HOVER_HC); 193 194 InitializeIcon(Icon_Command2BLarge, IMAGE_COMMAND2B_LARGE_HC); 195 InitializeIcon(Icon_Command2BLargeHover, IMAGE_COMMAND2B_LARGE_HOVER_HC); 196 InitializeIcon(Icon_Command2BMedium, IMAGE_COMMAND2B_MEDIUM_HC); 197 InitializeIcon(Icon_Command2BMediumHover, IMAGE_COMMAND2B_MEDIUM_HOVER_HC); 198 InitializeIcon(Icon_Command2BSmall, IMAGE_COMMAND2B_SMALL_HC); 199 InitializeIcon(Icon_Command2BSmallHover, IMAGE_COMMAND2B_SMALL_HOVER_HC); 200 201 InitializeIcon(Icon_Command3Large, IMAGE_COMMAND3_LARGE_HC); 202 InitializeIcon(Icon_Command3LargeHover, IMAGE_COMMAND3_LARGE_HOVER_HC); 203 InitializeIcon(Icon_Command3Medium, IMAGE_COMMAND3_SMALL_HC); 204 InitializeIcon(Icon_Command3MediumHover, IMAGE_COMMAND3_SMALL_HOVER_HC); 205 InitializeIcon(Icon_Command3Small, IMAGE_COMMAND3_SMALL_HC); 206 InitializeIcon(Icon_Command3SmallHover, IMAGE_COMMAND3_SMALL_HOVER_HC); 207 } 208 else 209 { 210 InitializeIcon(Icon_RawShadow, IMAGE_SHADOW); 211 InitializeIcon(Icon_RawInsertShadow, IMAGE_INSERT_SHADOW); 212 InitializeIcon(Icon_HideSlideOverlay, IMAGE_HIDE_SLIDE_OVERLAY); 213 214 InitializeIcon(Icon_ButtonBarLarge, IMAGE_BUTTONBAR_LARGE); 215 InitializeIcon(Icon_ButtonBarMedium, IMAGE_BUTTONBAR_MEDIUM); 216 InitializeIcon(Icon_ButtonBarSmall, IMAGE_BUTTONBAR_SMALL); 217 218 InitializeIcon(Icon_Command1Large, IMAGE_COMMAND1_LARGE); 219 InitializeIcon(Icon_Command1LargeHover, IMAGE_COMMAND1_LARGE_HOVER); 220 InitializeIcon(Icon_Command1Medium, IMAGE_COMMAND1_MEDIUM); 221 InitializeIcon(Icon_Command1MediumHover, IMAGE_COMMAND1_MEDIUM_HOVER); 222 InitializeIcon(Icon_Command1Small, IMAGE_COMMAND1_SMALL); 223 InitializeIcon(Icon_Command1SmallHover, IMAGE_COMMAND1_SMALL_HOVER); 224 225 InitializeIcon(Icon_Command2Large, IMAGE_COMMAND2_LARGE); 226 InitializeIcon(Icon_Command2LargeHover, IMAGE_COMMAND2_LARGE_HOVER); 227 InitializeIcon(Icon_Command2Medium, IMAGE_COMMAND2_MEDIUM); 228 InitializeIcon(Icon_Command2MediumHover, IMAGE_COMMAND2_MEDIUM_HOVER); 229 InitializeIcon(Icon_Command2Small, IMAGE_COMMAND2_SMALL); 230 InitializeIcon(Icon_Command2SmallHover, IMAGE_COMMAND2_SMALL_HOVER); 231 232 InitializeIcon(Icon_Command2BLarge, IMAGE_COMMAND2B_LARGE); 233 InitializeIcon(Icon_Command2BLargeHover, IMAGE_COMMAND2B_LARGE_HOVER); 234 InitializeIcon(Icon_Command2BMedium, IMAGE_COMMAND2B_MEDIUM); 235 InitializeIcon(Icon_Command2BMediumHover, IMAGE_COMMAND2B_MEDIUM_HOVER); 236 InitializeIcon(Icon_Command2BSmall, IMAGE_COMMAND2B_SMALL); 237 InitializeIcon(Icon_Command2BSmallHover, IMAGE_COMMAND2B_SMALL_HOVER); 238 239 InitializeIcon(Icon_Command3Large, IMAGE_COMMAND3_LARGE); 240 InitializeIcon(Icon_Command3LargeHover, IMAGE_COMMAND3_LARGE_HOVER); 241 InitializeIcon(Icon_Command3Medium, IMAGE_COMMAND3_MEDIUM); 242 InitializeIcon(Icon_Command3MediumHover, IMAGE_COMMAND3_MEDIUM_HOVER); 243 InitializeIcon(Icon_Command3Small, IMAGE_COMMAND3_SMALL); 244 InitializeIcon(Icon_Command3SmallHover, IMAGE_COMMAND3_SMALL_HOVER); 245 } 246 InitializeIcon(Icon_FocusBorder, IMAGE_FOCUS_BORDER); 247 } 248 } 249 250 251 252 253 ::boost::shared_ptr<Font> Theme::GetFont ( 254 const FontType eType, 255 const OutputDevice& rDevice) 256 { 257 ::boost::shared_ptr<Font> pFont; 258 259 switch (eType) 260 { 261 case Font_PageNumber: 262 pFont.reset(new Font(Application::GetSettings().GetStyleSettings().GetAppFont())); 263 pFont->SetTransparent(sal_True); 264 pFont->SetWeight(WEIGHT_BOLD); 265 break; 266 267 case Font_PageCount: 268 pFont.reset(new Font(Application::GetSettings().GetStyleSettings().GetAppFont())); 269 pFont->SetTransparent(sal_True); 270 pFont->SetWeight(WEIGHT_NORMAL); 271 { 272 const Size aSize (pFont->GetSize()); 273 pFont->SetSize(Size(aSize.Width()*5/3, aSize.Height()*5/3)); 274 } 275 break; 276 277 case Font_Button: 278 pFont.reset(new Font(Application::GetSettings().GetStyleSettings().GetAppFont())); 279 pFont->SetTransparent(sal_True); 280 pFont->SetWeight(WEIGHT_BOLD); 281 { 282 const Size aSize (pFont->GetSize()); 283 pFont->SetSize(Size(aSize.Width()*4/3, aSize.Height()*4/3)); 284 } 285 break; 286 } 287 288 if (pFont) 289 { 290 // Transform the point size to pixel size. 291 const MapMode aFontMapMode (MAP_POINT); 292 const Size aFontSize (rDevice.LogicToPixel(pFont->GetSize(), aFontMapMode)); 293 294 // Transform the font size to the logical coordinates of the device. 295 pFont->SetSize(rDevice.PixelToLogic(aFontSize)); 296 } 297 298 return pFont; 299 } 300 301 302 303 304 ColorData Theme::GetColor (const ColorType eType) 305 { 306 if (eType>=0 && sal_uInt32(eType)<maColor.size()) 307 return maColor[eType]; 308 else 309 return 0; 310 } 311 312 313 314 315 void Theme::SetColor ( 316 const ColorType eType, 317 const ColorData aData) 318 { 319 if (eType>=0 && sal_uInt32(eType)<maColor.size()) 320 maColor[eType] = aData; 321 } 322 323 324 325 326 ColorData Theme::GetGradientColor ( 327 const GradientColorType eType, 328 const GradientColorClass eClass) 329 { 330 GradientDescriptor& rDescriptor (GetGradient(eType)); 331 332 switch (eClass) 333 { 334 case Border1: return rDescriptor.maBorderColor1; 335 case Border2: return rDescriptor.maBorderColor2; 336 case Fill1: return rDescriptor.maFillColor1; 337 case Fill2: return rDescriptor.maFillColor2; 338 default: OSL_ASSERT(false); // fall through 339 case Base: return rDescriptor.maBaseColor; 340 } 341 } 342 343 344 345 346 sal_Int32 Theme::GetGradientOffset ( 347 const GradientColorType eType, 348 const GradientColorClass eClass) 349 { 350 GradientDescriptor& rDescriptor (GetGradient(eType)); 351 352 switch (eClass) 353 { 354 case Border1: return rDescriptor.mnBorderOffset1; 355 case Border2: return rDescriptor.mnBorderOffset2; 356 case Fill1: return rDescriptor.mnFillOffset1; 357 case Fill2: return rDescriptor.mnFillOffset2; 358 default: OSL_ASSERT(false); // fall through 359 case Base: return 0; 360 } 361 } 362 363 364 365 366 void Theme::SetGradient ( 367 const GradientColorType eType, 368 const ColorData aBaseColor, 369 const sal_Int32 nSaturationOverride, 370 const sal_Int32 nBrightnessOverride, 371 const sal_Int32 nFillStartOffset, 372 const sal_Int32 nFillEndOffset, 373 const sal_Int32 nBorderStartOffset, 374 const sal_Int32 nBorderEndOffset) 375 { 376 GradientDescriptor& rGradient (GetGradient(eType)); 377 378 rGradient.maBaseColor = aBaseColor; 379 380 rGradient.mnSaturationOverride = nSaturationOverride; 381 rGradient.mnBrightnessOverride = nBrightnessOverride; 382 const ColorData aColor (nSaturationOverride>=0 || nBrightnessOverride>=0 383 ? HGBAdapt(aBaseColor, nSaturationOverride, nBrightnessOverride) 384 : aBaseColor); 385 386 rGradient.maFillColor1 = ChangeLuminance(aColor, nFillStartOffset); 387 rGradient.maFillColor2 = ChangeLuminance(aColor, nFillEndOffset); 388 rGradient.maBorderColor1 = ChangeLuminance(aColor, nBorderStartOffset); 389 rGradient.maBorderColor2 = ChangeLuminance(aColor, nBorderEndOffset); 390 391 rGradient.mnFillOffset1 = nFillStartOffset; 392 rGradient.mnFillOffset2 = nFillEndOffset; 393 rGradient.mnBorderOffset1 = nBorderStartOffset; 394 rGradient.mnBorderOffset2 = nBorderEndOffset; 395 } 396 397 398 399 400 sal_Int32 Theme::GetGradientSaturationOverride (const GradientColorType eType) 401 { 402 GradientDescriptor& rGradient (GetGradient(eType)); 403 return rGradient.mnSaturationOverride; 404 } 405 406 407 408 409 sal_Int32 Theme::GetGradientBrightnessOverride (const GradientColorType eType) 410 { 411 GradientDescriptor& rGradient (GetGradient(eType)); 412 return rGradient.mnBrightnessOverride; 413 } 414 415 416 417 418 void Theme::SetGradientSaturationOverride (const GradientColorType eType, const sal_Int32 nValue) 419 { 420 GradientDescriptor& rGradient (GetGradient(eType)); 421 SetGradient( 422 eType, 423 rGradient.maBaseColor, 424 nValue, 425 rGradient.mnBrightnessOverride, 426 rGradient.mnFillOffset1, 427 rGradient.mnFillOffset2, 428 rGradient.mnBorderOffset1, 429 rGradient.mnBorderOffset2); 430 } 431 432 433 434 435 void Theme::SetGradientBrightnessOverride (const GradientColorType eType, const sal_Int32 nValue) 436 { 437 GradientDescriptor& rGradient (GetGradient(eType)); 438 SetGradient(eType, 439 rGradient.maBaseColor, 440 rGradient.mnSaturationOverride, 441 nValue, 442 rGradient.mnFillOffset1, 443 rGradient.mnFillOffset2, 444 rGradient.mnBorderOffset1, 445 rGradient.mnBorderOffset2); 446 } 447 448 449 450 451 const BitmapEx& Theme::GetIcon (const IconType eType) 452 { 453 if (eType>=0 && size_t(eType)<maIcons.size()) 454 return maIcons[eType]; 455 else 456 { 457 OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size()); 458 return maIcons[0]; 459 } 460 } 461 462 463 464 465 sal_Int32 Theme::GetIntegerValue (const IntegerValueType eType) const 466 { 467 if (eType>=0 && size_t(eType)<maIntegerValues.size()) 468 return maIntegerValues[eType]; 469 else 470 { 471 OSL_ASSERT(eType>=0 && size_t(eType)<maIntegerValues.size()); 472 return 0; 473 } 474 } 475 476 477 478 479 void Theme::SetIntegerValue (const IntegerValueType eType, const sal_Int32 nValue) 480 { 481 if (eType>=0 && size_t(eType)<maIntegerValues.size()) 482 maIntegerValues[eType] = nValue; 483 else 484 { 485 OSL_ASSERT(eType>=0 && size_t(eType)<maIntegerValues.size()); 486 } 487 } 488 489 490 491 492 ::rtl::OUString Theme::GetString (const StringType eType) const 493 { 494 if (eType>=0 && size_t(eType)<maStrings.size()) 495 return maStrings[eType]; 496 else 497 { 498 OSL_ASSERT(eType>=0 && size_t(eType)<maStrings.size()); 499 return ::rtl::OUString(); 500 } 501 } 502 503 504 505 506 Theme::GradientDescriptor& Theme::GetGradient (const GradientColorType eType) 507 { 508 if (eType>=0 && size_t(eType)<maGradients.size()) 509 return maGradients[eType]; 510 else 511 { 512 OSL_ASSERT(eType>=0 && size_t(eType)<maGradients.size()); 513 return maGradients[0]; 514 } 515 } 516 517 518 519 520 void Theme::InitializeIcon (const IconType eType, sal_uInt16 nResourceId) 521 { 522 if (eType>=0 && size_t(eType)<maIcons.size()) 523 { 524 const BitmapEx aIcon (Image(SdResId(nResourceId)).GetBitmapEx()); 525 maIcons[eType] = aIcon; 526 } 527 else 528 { 529 OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size()); 530 } 531 } 532 533 534 535 536 } } } // end of namespace ::sd::slidesorter::view 537