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 #include <sfx2/sidebar/propertypanel.hrc> 23 #include <sfx2/sidebar/Theme.hxx> 24 #include <sfx2/sidebar/ControlFactory.hxx> 25 #include <GraphicPropertyPanel.hxx> 26 #include <GraphicPropertyPanel.hrc> 27 #include <svx/dialogs.hrc> 28 #include <svx/dialmgr.hxx> 29 #include <vcl/field.hxx> 30 #include <vcl/lstbox.hxx> 31 #include <svl/intitem.hxx> 32 #include <sfx2/bindings.hxx> 33 #include <sfx2/dispatch.hxx> 34 #include "svx/dialogs.hrc" 35 36 using namespace css; 37 using namespace cssu; 38 using ::sfx2::sidebar::Theme; 39 40 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString))) 41 42 ////////////////////////////////////////////////////////////////////////////// 43 // namespace open 44 45 namespace svx { namespace sidebar { 46 47 ////////////////////////////////////////////////////////////////////////////// 48 49 GraphicPropertyPanel::GraphicPropertyPanel( 50 Window* pParent, 51 const cssu::Reference<css::frame::XFrame>& rxFrame, 52 SfxBindings* pBindings) 53 : Control( 54 pParent, 55 SVX_RES(RID_SIDEBAR_GRAPHIC_PANEL)), 56 mpFtBrightness(new FixedText(this, SVX_RES(FT_BRIGHTNESS))), 57 mpMtrBrightness(new MetricField(this, SVX_RES(MTR_BRIGHTNESS))), 58 mpFtContrast(new FixedText(this, SVX_RES(FT_CONTRAST))), 59 mpMtrContrast(new MetricField(this, SVX_RES(MTR_CONTRAST))), 60 mpFtColorMode(new FixedText(this, SVX_RES(FT_COLOR_MODE))), 61 mpLBColorMode(new ListBox(this, SVX_RES(LB_COLOR_MODE))), 62 mpFtTrans(new FixedText(this, SVX_RES(FT_TRANSPARENT))), 63 mpMtrTrans(new MetricField(this, SVX_RES(MTR_TRANSPARENT))), 64 mpMtrRed(new MetricField(this, SVX_RES(MF_RED))), 65 mpMtrGreen(new MetricField(this, SVX_RES(MF_GREEN))), 66 mpMtrBlue(new MetricField(this, SVX_RES(MF_BLUE))), 67 mpMtrGamma(new MetricField(this, SVX_RES(MF_GAMMA))), 68 maBrightControl(SID_ATTR_GRAF_LUMINANCE, *pBindings, *this), 69 maContrastControl(SID_ATTR_GRAF_CONTRAST, *pBindings, *this), 70 maTransparenceControl(SID_ATTR_GRAF_TRANSPARENCE, *pBindings, *this), 71 maRedControl(SID_ATTR_GRAF_RED, *pBindings, *this), 72 maGreenControl(SID_ATTR_GRAF_GREEN, *pBindings, *this), 73 maBlueControl(SID_ATTR_GRAF_BLUE, *pBindings, *this), 74 maGammaControl(SID_ATTR_GRAF_GAMMA, *pBindings, *this), 75 maModeControl(SID_ATTR_GRAF_MODE, *pBindings, *this), 76 maImgRed(this, SVX_RES(IMG_RED)), 77 maImgGreen(this, SVX_RES(IMG_GREEN)), 78 maImgBlue(this, SVX_RES(IMG_BLUE)), 79 maImgGamma(this, SVX_RES(IMG_GAMMA)), 80 mxFrame(rxFrame), 81 mpBindings(pBindings) 82 { 83 Initialize(); 84 FreeResource(); 85 } 86 87 ////////////////////////////////////////////////////////////////////////////// 88 89 GraphicPropertyPanel::~GraphicPropertyPanel() 90 { 91 } 92 93 ////////////////////////////////////////////////////////////////////////////// 94 95 void GraphicPropertyPanel::Initialize() 96 { 97 mpFtBrightness->SetBackground(Wallpaper()); 98 mpFtContrast->SetBackground(Wallpaper()); 99 mpFtColorMode->SetBackground(Wallpaper()); 100 mpFtTrans->SetBackground(Wallpaper()); 101 102 mpMtrBrightness->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyBrightnessHdl ) ); 103 mpMtrBrightness->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Brightness"))); 104 mpMtrContrast->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyContrastHdl ) ); 105 mpMtrContrast->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Contrast"))); 106 mpMtrTrans->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyTransHdl ) ); 107 mpMtrTrans->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Transparency"))); 108 109 mpLBColorMode->InsertEntry(String(SVX_RES(RID_SVXSTR_GRAFMODE_STANDARD))); 110 mpLBColorMode->InsertEntry(String(SVX_RES(RID_SVXSTR_GRAFMODE_GREYS))); 111 mpLBColorMode->InsertEntry(String(SVX_RES(RID_SVXSTR_GRAFMODE_MONO))); 112 mpLBColorMode->InsertEntry(String(SVX_RES(RID_SVXSTR_GRAFMODE_WATERMARK))); 113 mpLBColorMode->SetSelectHdl( LINK( this, GraphicPropertyPanel, ClickColorModeHdl )); 114 mpLBColorMode->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Color mode"))); 115 116 mpMtrRed->SetModifyHdl( LINK( this, GraphicPropertyPanel, RedHdl ) ); 117 mpMtrGreen->SetModifyHdl( LINK( this, GraphicPropertyPanel, GreenHdl ) ); 118 mpMtrBlue->SetModifyHdl( LINK( this, GraphicPropertyPanel, BlueHdl ) ); 119 mpMtrGamma->SetModifyHdl( LINK( this, GraphicPropertyPanel, GammaHdl ) ); 120 mpMtrRed->SetAccessibleName(mpMtrRed->GetQuickHelpText()); 121 mpMtrGreen->SetAccessibleName(mpMtrGreen->GetQuickHelpText()); 122 mpMtrBlue->SetAccessibleName(mpMtrBlue->GetQuickHelpText()); 123 mpMtrGamma->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Gamma value"))); 124 125 mpMtrRed->SetAccessibleRelationLabeledBy(mpMtrRed.get()); 126 mpMtrGreen->SetAccessibleRelationLabeledBy(mpMtrGreen.get()); 127 mpMtrBlue->SetAccessibleRelationLabeledBy(mpMtrBlue.get()); 128 mpMtrGamma->SetAccessibleRelationLabeledBy(mpMtrGamma.get()); 129 mpMtrBrightness->SetAccessibleRelationLabeledBy(mpFtBrightness.get()); 130 mpMtrContrast->SetAccessibleRelationLabeledBy(mpFtContrast.get()); 131 mpMtrTrans->SetAccessibleRelationLabeledBy(mpFtTrans.get()); 132 mpLBColorMode->SetAccessibleRelationLabeledBy(mpFtColorMode.get()); 133 134 // Fix left position of some controls that may be wrong due to 135 // rounding errors. 136 const sal_Int32 nRight0 (mpLBColorMode->GetPosPixel().X() + mpLBColorMode->GetSizePixel().Width()); 137 const sal_Int32 nRight1 (mpMtrTrans->GetPosPixel().X() + mpMtrTrans->GetSizePixel().Width()); 138 mpMtrRed->SetPosPixel(Point( 139 nRight0 - mpMtrRed->GetSizePixel().Width(), 140 mpMtrRed->GetPosPixel().Y())); 141 mpMtrBlue->SetPosPixel(Point( 142 nRight0 - mpMtrBlue->GetSizePixel().Width(), 143 mpMtrBlue->GetPosPixel().Y())); 144 mpMtrGreen->SetPosPixel(Point( 145 nRight1 - mpMtrGreen->GetSizePixel().Width(), 146 mpMtrGreen->GetPosPixel().Y())); 147 mpMtrGamma->SetPosPixel(Point( 148 nRight1 - mpMtrGamma->GetSizePixel().Width(), 149 mpMtrGamma->GetPosPixel().Y())); 150 } 151 152 153 154 155 ////////////////////////////////////////////////////////////////////////////// 156 157 IMPL_LINK( GraphicPropertyPanel, ModifyBrightnessHdl, void *, EMPTYARG ) 158 { 159 const sal_Int16 nBright = mpMtrBrightness->GetValue(); 160 const SfxInt16Item aBrightItem( SID_ATTR_GRAF_LUMINANCE, nBright ); 161 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_LUMINANCE, SFX_CALLMODE_RECORD, &aBrightItem, 0L); 162 return 0L; 163 } 164 165 ////////////////////////////////////////////////////////////////////////////// 166 167 IMPL_LINK( GraphicPropertyPanel, ModifyContrastHdl, void *, EMPTYARG ) 168 { 169 const sal_Int16 nContrast = mpMtrContrast->GetValue(); 170 const SfxInt16Item aContrastItem( SID_ATTR_GRAF_CONTRAST, nContrast ); 171 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_CONTRAST, SFX_CALLMODE_RECORD, &aContrastItem, 0L); 172 return 0L; 173 } 174 175 ////////////////////////////////////////////////////////////////////////////// 176 177 IMPL_LINK( GraphicPropertyPanel, ModifyTransHdl, void *, EMPTYARG ) 178 { 179 const sal_Int16 nTrans = mpMtrTrans->GetValue(); 180 const SfxInt16Item aTransItem( SID_ATTR_GRAF_TRANSPARENCE, nTrans ); 181 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_TRANSPARENCE, SFX_CALLMODE_RECORD, &aTransItem, 0L); 182 return 0L; 183 } 184 185 ////////////////////////////////////////////////////////////////////////////// 186 187 IMPL_LINK( GraphicPropertyPanel, ClickColorModeHdl, ToolBox *, /* pBox */) 188 { 189 const sal_Int16 nTrans = mpLBColorMode->GetSelectEntryPos(); 190 const SfxInt16Item aTransItem( SID_ATTR_GRAF_MODE, nTrans ); 191 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_MODE, SFX_CALLMODE_RECORD, &aTransItem, 0L); 192 return 0L; 193 } 194 195 ////////////////////////////////////////////////////////////////////////////// 196 197 IMPL_LINK( GraphicPropertyPanel, RedHdl, void*, EMPTYARG ) 198 { 199 const sal_Int16 nRed = mpMtrRed->GetValue(); 200 const SfxInt16Item aRedItem( SID_ATTR_GRAF_RED, nRed ); 201 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_RED, SFX_CALLMODE_RECORD, &aRedItem, 0L); 202 return 0L; 203 } 204 205 ////////////////////////////////////////////////////////////////////////////// 206 207 IMPL_LINK( GraphicPropertyPanel, GreenHdl, void*, EMPTYARG ) 208 { 209 const sal_Int16 nGreen = mpMtrGreen->GetValue(); 210 const SfxInt16Item aGreenItem( SID_ATTR_GRAF_GREEN, nGreen ); 211 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_GREEN, SFX_CALLMODE_RECORD, &aGreenItem, 0L); 212 return 0L; 213 } 214 215 ////////////////////////////////////////////////////////////////////////////// 216 217 IMPL_LINK(GraphicPropertyPanel, BlueHdl, void *, EMPTYARG) 218 { 219 const sal_Int16 nBlue = mpMtrBlue->GetValue(); 220 const SfxInt16Item aBlueItem( SID_ATTR_GRAF_BLUE, nBlue ); 221 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_BLUE, SFX_CALLMODE_RECORD, &aBlueItem, 0L); 222 return 0L; 223 } 224 225 ////////////////////////////////////////////////////////////////////////////// 226 227 IMPL_LINK(GraphicPropertyPanel, GammaHdl, void *, EMPTYARG) 228 { 229 const sal_Int32 nGamma = mpMtrGamma->GetValue(); 230 const SfxInt32Item nGammaItem( SID_ATTR_GRAF_GAMMA, nGamma ); 231 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_GAMMA, SFX_CALLMODE_RECORD, &nGammaItem, 0L); 232 return 0L; 233 } 234 235 ////////////////////////////////////////////////////////////////////////////// 236 237 void GraphicPropertyPanel::SetupIcons(void) 238 { 239 if(Theme::GetBoolean(Theme::Bool_UseSymphonyIcons)) 240 { 241 // todo 242 } 243 else 244 { 245 // todo 246 } 247 } 248 249 ////////////////////////////////////////////////////////////////////////////// 250 251 GraphicPropertyPanel* GraphicPropertyPanel::Create ( 252 Window* pParent, 253 const cssu::Reference<css::frame::XFrame>& rxFrame, 254 SfxBindings* pBindings) 255 { 256 if (pParent == NULL) 257 throw lang::IllegalArgumentException(A2S("no parent Window given to GraphicPropertyPanel::Create"), NULL, 0); 258 if ( ! rxFrame.is()) 259 throw lang::IllegalArgumentException(A2S("no XFrame given to GraphicPropertyPanel::Create"), NULL, 1); 260 if (pBindings == NULL) 261 throw lang::IllegalArgumentException(A2S("no SfxBindings given to GraphicPropertyPanel::Create"), NULL, 2); 262 263 return new GraphicPropertyPanel( 264 pParent, 265 rxFrame, 266 pBindings); 267 } 268 269 ////////////////////////////////////////////////////////////////////////////// 270 271 void GraphicPropertyPanel::DataChanged( 272 const DataChangedEvent& rEvent) 273 { 274 (void)rEvent; 275 276 SetupIcons(); 277 } 278 279 ////////////////////////////////////////////////////////////////////////////// 280 281 void GraphicPropertyPanel::NotifyItemUpdate( 282 sal_uInt16 nSID, 283 SfxItemState eState, 284 const SfxPoolItem* pState, 285 const bool bIsEnabled) 286 { 287 (void)bIsEnabled; 288 289 switch( nSID ) 290 { 291 case SID_ATTR_GRAF_LUMINANCE: 292 { 293 if(eState >= SFX_ITEM_AVAILABLE) 294 { 295 mpMtrBrightness->Enable(); 296 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState); 297 298 if(pItem) 299 { 300 const sal_Int64 nBright = pItem->GetValue(); 301 mpMtrBrightness->SetValue(nBright); 302 } 303 } 304 else if(SFX_ITEM_DISABLED == eState) 305 { 306 mpMtrBrightness->Disable(); 307 } 308 else 309 { 310 mpMtrBrightness->Enable(); 311 mpMtrBrightness->SetText(String()); 312 } 313 break; 314 } 315 case SID_ATTR_GRAF_CONTRAST: 316 { 317 if(eState >= SFX_ITEM_AVAILABLE) 318 { 319 mpMtrContrast->Enable(); 320 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState); 321 322 if(pItem) 323 { 324 const sal_Int64 nContrast = pItem->GetValue(); 325 mpMtrContrast->SetValue(nContrast); 326 } 327 } 328 else if(SFX_ITEM_DISABLED == eState) 329 { 330 mpMtrContrast->Disable(); 331 } 332 else 333 { 334 mpMtrContrast->Enable(); 335 mpMtrContrast->SetText(String()); 336 } 337 break; 338 } 339 case SID_ATTR_GRAF_TRANSPARENCE: 340 { 341 if(eState >= SFX_ITEM_AVAILABLE) 342 { 343 mpMtrTrans->Enable(); 344 const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState); 345 346 if(pItem) 347 { 348 const sal_Int64 nTrans = pItem->GetValue(); 349 mpMtrTrans->SetValue(nTrans); 350 } 351 } 352 else if(SFX_ITEM_DISABLED == eState) 353 { 354 mpMtrTrans->Disable(); 355 } 356 else 357 { 358 mpMtrTrans->Enable(); 359 mpMtrTrans->SetText(String()); 360 } 361 break; 362 } 363 case SID_ATTR_GRAF_MODE: 364 { 365 if(eState >= SFX_ITEM_AVAILABLE) 366 { 367 mpLBColorMode->Enable(); 368 const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState); 369 370 if(pItem) 371 { 372 const sal_Int64 nTrans = pItem->GetValue(); 373 mpLBColorMode->SelectEntryPos(nTrans); 374 } 375 } 376 else if(SFX_ITEM_DISABLED == eState) 377 { 378 mpLBColorMode->Disable(); 379 } 380 else 381 { 382 mpLBColorMode->Enable(); 383 mpLBColorMode->SetNoSelection(); 384 } 385 break; 386 } 387 case SID_ATTR_GRAF_RED: 388 { 389 if(eState >= SFX_ITEM_AVAILABLE) 390 { 391 mpMtrRed->Enable(); 392 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState); 393 394 if(pItem) 395 { 396 const sal_Int64 nRed = pItem->GetValue(); 397 mpMtrRed->SetValue( nRed ); 398 } 399 } 400 else if(SFX_ITEM_DISABLED == eState) 401 { 402 mpMtrRed->Disable(); 403 } 404 else 405 { 406 mpMtrRed->Enable(); 407 mpMtrRed->SetText(String()); 408 } 409 break; 410 } 411 case SID_ATTR_GRAF_GREEN: 412 { 413 if(eState >= SFX_ITEM_AVAILABLE) 414 { 415 mpMtrGreen->Enable(); 416 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState); 417 418 if(pItem) 419 { 420 const sal_Int64 nGreen = pItem->GetValue(); 421 mpMtrGreen->SetValue( nGreen ); 422 } 423 } 424 else if(SFX_ITEM_DISABLED == eState) 425 { 426 mpMtrGreen->Disable(); 427 } 428 else 429 { 430 mpMtrGreen->Enable(); 431 mpMtrGreen->SetText(String()); 432 } 433 break; 434 } 435 case SID_ATTR_GRAF_BLUE: 436 { 437 if(eState >= SFX_ITEM_AVAILABLE) 438 { 439 mpMtrBlue->Enable(); 440 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState); 441 442 if(pItem) 443 { 444 const sal_Int64 nBlue = pItem->GetValue(); 445 mpMtrBlue->SetValue( nBlue ); 446 } 447 } 448 else if(SFX_ITEM_DISABLED == eState) 449 { 450 mpMtrBlue->Disable(); 451 } 452 else 453 { 454 mpMtrBlue->Enable(); 455 mpMtrBlue->SetText(String()); 456 } 457 break; 458 } 459 case SID_ATTR_GRAF_GAMMA: 460 { 461 if(eState >= SFX_ITEM_AVAILABLE) 462 { 463 mpMtrGamma->Enable(); 464 const SfxUInt32Item* pItem = dynamic_cast< const SfxUInt32Item* >(pState); 465 466 if(pItem) 467 { 468 const sal_Int64 nGamma = pItem->GetValue(); 469 mpMtrGamma->SetValue( nGamma ); 470 } 471 } 472 else if(SFX_ITEM_DISABLED == eState) 473 { 474 mpMtrGamma->Disable(); 475 } 476 else 477 { 478 mpMtrGamma->Enable(); 479 mpMtrGamma->SetText(String()); 480 } 481 break; 482 } 483 } 484 } 485 486 487 488 489 ////////////////////////////////////////////////////////////////////////////// 490 491 SfxBindings* GraphicPropertyPanel::GetBindings() 492 { 493 return mpBindings; 494 } 495 496 ////////////////////////////////////////////////////////////////////////////// 497 // namespace close 498 499 }} // end of namespace ::svx::sidebar 500 501 ////////////////////////////////////////////////////////////////////////////// 502 // eof 503