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_cui.hxx" 26 27 // include --------------------------------------------------------------- 28 #include <tools/shl.hxx> 29 #include <tools/urlobj.hxx> 30 #include <unotools/pathoptions.hxx> 31 #include <sfx2/app.hxx> 32 #include <sfx2/module.hxx> 33 #include <svtools/colrdlg.hxx> 34 #include <vcl/msgbox.hxx> 35 #include <sfx2/filedlghelper.hxx> 36 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp" 37 38 #define _SVX_TPCOLOR_CXX 39 40 #include <cuires.hrc> 41 #include "helpid.hrc" 42 #include "svx/xattr.hxx" 43 #include <svx/xpool.hxx> 44 #include <svx/xtable.hxx> 45 #include "svx/drawitem.hxx" 46 #include "cuitabarea.hxx" 47 #include "tabarea.hrc" 48 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx" 49 //#include "dlgname.hrc" 50 #include <svx/svxdlg.hxx> //CHINA001 51 #include <dialmgr.hxx> 52 #include <cuitabline.hxx> 53 #include <svx/dialmgr.hxx> 54 #include <svx/dialogs.hrc> 55 56 #define DLGWIN GetParentDialog( this ) 57 58 /************************************************************************* 59 |* 60 |* Dialog zum Aendern und Definieren der Farben 61 |* 62 \************************************************************************/ 63 64 static Window* GetParentDialog( Window* pWindow ) 65 { 66 while( pWindow ) 67 { 68 if( pWindow->IsDialog() ) 69 break; 70 71 pWindow = pWindow->GetParent(); 72 } 73 74 return pWindow; 75 } 76 77 SvxColorTabPage::SvxColorTabPage 78 ( 79 Window* pParent, 80 const SfxItemSet& rInAttrs 81 ) : 82 83 SfxTabPage ( pParent, CUI_RES( RID_SVXPAGE_COLOR ), rInAttrs ), 84 85 aFlProp ( this, CUI_RES( FL_PROP ) ), 86 aFtName ( this, CUI_RES( FT_NAME ) ), 87 aEdtName ( this, CUI_RES( EDT_NAME ) ), 88 aFtColor ( this, CUI_RES( FT_COLOR ) ), 89 aLbColor ( this, CUI_RES( LB_COLOR ) ), 90 91 aTableNameFT ( this, CUI_RES( FT_TABLE_NAME ) ), 92 aValSetColorTable ( this, CUI_RES( CTL_COLORTABLE ) ), 93 94 aCtlPreviewOld ( this, CUI_RES( CTL_PREVIEW_OLD ) ), 95 aCtlPreviewNew ( this, CUI_RES( CTL_PREVIEW_NEW ) ), 96 97 aLbColorModel ( this, CUI_RES( LB_COLORMODEL ) ), 98 aFtColorModel1 ( this, CUI_RES( FT_1 ) ), 99 aMtrFldColorModel1 ( this, CUI_RES( MTR_FLD_1 ) ), 100 aFtColorModel2 ( this, CUI_RES( FT_2 ) ), 101 aMtrFldColorModel2 ( this, CUI_RES( MTR_FLD_2 ) ), 102 aFtColorModel3 ( this, CUI_RES( FT_3 ) ), 103 aMtrFldColorModel3 ( this, CUI_RES( MTR_FLD_3 ) ), 104 aFtColorModel4 ( this, CUI_RES( FT_4 ) ), 105 aMtrFldColorModel4 ( this, CUI_RES( MTR_FLD_4 ) ), 106 aBtnAdd ( this, CUI_RES( BTN_ADD ) ), 107 aBtnModify ( this, CUI_RES( BTN_MODIFY ) ), 108 aBtnWorkOn ( this, CUI_RES( BTN_WORK_ON ) ), 109 aBtnDelete ( this, CUI_RES( BTN_DELETE ) ), 110 aBtnLoad ( this, CUI_RES( BTN_LOAD ) ), 111 aBtnSave ( this, CUI_RES( BTN_SAVE ) ), 112 113 rOutAttrs ( rInAttrs ), 114 pColorTab( NULL ), 115 116 bDeleteColorTable ( sal_True ), 117 118 pXPool ( (XOutdevItemPool*) rInAttrs.GetPool() ), 119 aXFStyleItem ( XFILL_SOLID ), 120 aXFillColorItem ( String(), Color( COL_BLACK ) ), 121 aXFillAttr ( pXPool ), 122 rXFSet ( aXFillAttr.GetItemSet() ), 123 124 eCM ( CM_RGB ) 125 126 { 127 aBtnLoad.SetModeImage( Image( CUI_RES( RID_SVXIMG_LOAD_H ) ), BMP_COLOR_HIGHCONTRAST ); 128 aBtnSave.SetModeImage( Image( CUI_RES( RID_SVXIMG_SAVE_H ) ), BMP_COLOR_HIGHCONTRAST ); 129 130 FreeResource(); 131 132 // diese Page braucht ExchangeSupport 133 SetExchangeSupport(); 134 135 // Setzen des Output-Devices 136 rXFSet.Put( aXFStyleItem ); 137 rXFSet.Put( aXFillColorItem ); 138 aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() ); 139 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); 140 141 // Handler ueberladen 142 aLbColor.SetSelectHdl( 143 LINK( this, SvxColorTabPage, SelectColorLBHdl_Impl ) ); 144 aValSetColorTable.SetSelectHdl( 145 LINK( this, SvxColorTabPage, SelectValSetHdl_Impl ) ); 146 aLbColorModel.SetSelectHdl( 147 LINK( this, SvxColorTabPage, SelectColorModelHdl_Impl ) ); 148 149 Link aLink = LINK( this, SvxColorTabPage, ModifiedHdl_Impl ); 150 aMtrFldColorModel1.SetModifyHdl( aLink ); 151 aMtrFldColorModel2.SetModifyHdl( aLink ); 152 aMtrFldColorModel3.SetModifyHdl( aLink ); 153 aMtrFldColorModel4.SetModifyHdl( aLink ); 154 155 aBtnAdd.SetClickHdl( LINK( this, SvxColorTabPage, ClickAddHdl_Impl ) ); 156 aBtnModify.SetClickHdl( 157 LINK( this, SvxColorTabPage, ClickModifyHdl_Impl ) ); 158 aBtnWorkOn.SetClickHdl( 159 LINK( this, SvxColorTabPage, ClickWorkOnHdl_Impl ) ); 160 aBtnDelete.SetClickHdl( 161 LINK( this, SvxColorTabPage, ClickDeleteHdl_Impl ) ); 162 aBtnLoad.SetClickHdl( LINK( this, SvxColorTabPage, ClickLoadHdl_Impl ) ); 163 aBtnSave.SetClickHdl( LINK( this, SvxColorTabPage, ClickSaveHdl_Impl ) ); 164 165 // ValueSet 166 aValSetColorTable.SetStyle( aValSetColorTable.GetStyle() | WB_VSCROLL | WB_ITEMBORDER ); 167 aValSetColorTable.SetColCount( 8 ); 168 aValSetColorTable.SetLineCount( 10 ); 169 aValSetColorTable.SetExtraSpacing( 0 ); 170 aValSetColorTable.Show(); 171 172 aLbColorModel.SetAccessibleName( String( CUI_RES(STR_CUI_COLORMODEL) ) ); 173 aBtnAdd.SetAccessibleRelationMemberOf( &aFlProp ); 174 aBtnModify.SetAccessibleRelationMemberOf( &aFlProp ); 175 aBtnWorkOn.SetAccessibleRelationMemberOf( &aFlProp ); 176 aBtnDelete.SetAccessibleRelationMemberOf( &aFlProp ); 177 } 178 179 // ----------------------------------------------------------------------- 180 181 void SvxColorTabPage::Construct() 182 { 183 aLbColor.Fill( pColorTab ); 184 FillValueSet_Impl( aValSetColorTable ); 185 } 186 187 // ----------------------------------------------------------------------- 188 189 void SvxColorTabPage::ActivatePage( const SfxItemSet& ) 190 { 191 if( *pDlgType == 0 ) // Flaechen-Dialog 192 { 193 *pbAreaTP = sal_False; 194 195 if( pColorTab ) 196 { 197 if( *pPageType == PT_COLOR && *pPos != LISTBOX_ENTRY_NOTFOUND ) 198 { 199 aLbColor.SelectEntryPos( *pPos ); 200 aValSetColorTable.SelectItem( aLbColor.GetSelectEntryPos() + 1 ); 201 aEdtName.SetText( aLbColor.GetSelectEntry() ); 202 203 ChangeColorHdl_Impl( this ); 204 } 205 else if( *pPageType == PT_COLOR && *pPos == LISTBOX_ENTRY_NOTFOUND ) 206 { 207 const SfxPoolItem* pPoolItem = NULL; 208 if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), sal_True, &pPoolItem ) ) 209 { 210 aLbColorModel.SelectEntryPos( CM_RGB ); 211 212 aAktuellColor.SetColor ( ( ( const XFillColorItem* ) pPoolItem )->GetColorValue().GetColor() ); 213 214 aEdtName.SetText( ( ( const XFillColorItem* ) pPoolItem )->GetName() ); 215 216 aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) ); 217 aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) ); 218 aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) ); 219 220 // ItemSet fuellen und an XOut weiterleiten 221 rXFSet.Put( XFillColorItem( String(), aAktuellColor ) ); 222 aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() ); 223 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); 224 225 aCtlPreviewNew.Invalidate(); 226 aCtlPreviewOld.Invalidate(); 227 } 228 } 229 230 // Ermitteln (evtl. abschneiden) des Namens und in 231 // der GroupBox darstellen 232 String aString( CUI_RES( RID_SVXSTR_TABLE ) ); aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) ); 233 INetURLObject aURL( pColorTab->GetPath() ); 234 235 aURL.Append( pColorTab->GetName() ); 236 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" ); 237 238 if ( aURL.getBase().getLength() > 18 ) 239 { 240 aString += String(aURL.getBase()).Copy( 0, 15 ); 241 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) ); 242 } 243 else 244 aString += String(aURL.getBase()); 245 246 aTableNameFT.SetText( aString ); 247 248 // Damit evtl. geaenderte Farbe verworfen wird 249 SelectColorLBHdl_Impl( this ); 250 251 *pPageType = PT_COLOR; 252 *pPos = LISTBOX_ENTRY_NOTFOUND; 253 } 254 } 255 else 256 { 257 // Buttons werden gehided, weil Paletten z.Z. nur 258 // ueber den AreaDlg funktionieren!!! 259 // ActivatePage() muss von anderen Dialogen explizit 260 // gerufen werden, da ActivatePage() nicht gerufen wird, 261 // wenn Seite als Erste im Dialog angezeigt wird 262 aBtnLoad.Hide(); 263 aBtnSave.Hide(); 264 } 265 } 266 267 // ----------------------------------------------------------------------- 268 269 int SvxColorTabPage::DeactivatePage( SfxItemSet* _pSet ) 270 { 271 if ( CheckChanges_Impl() == -1L ) 272 return( KEEP_PAGE ); 273 274 if( _pSet ) 275 FillItemSet( *_pSet ); 276 277 return( LEAVE_PAGE ); 278 } 279 280 // ----------------------------------------------------------------------- 281 282 long SvxColorTabPage::CheckChanges_Impl() 283 { 284 // wird hier benutzt, um Aenderungen NICHT zu verlieren 285 286 Color aTmpColor (aAktuellColor); 287 if (eCM != CM_RGB) 288 ConvertColorValues (aTmpColor, CM_RGB); 289 290 sal_uInt16 nPos = aLbColor.GetSelectEntryPos(); 291 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 292 { 293 Color aColor = pColorTab->GetColor( nPos )->GetColor(); 294 String aString = aLbColor.GetSelectEntry(); 295 296 // aNewColor, da COL_USER != COL_irgendwas, auch wenn RGB-Werte gleich 297 // Color aNewColor( aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue() ); 298 299 if( ColorToPercent_Impl( aTmpColor.GetRed() ) != ColorToPercent_Impl( aColor.GetRed() ) || 300 ColorToPercent_Impl( aTmpColor.GetGreen() ) != ColorToPercent_Impl( aColor.GetGreen() ) || 301 ColorToPercent_Impl( aTmpColor.GetBlue() ) != ColorToPercent_Impl( aColor.GetBlue() ) || 302 aString != aEdtName.GetText() ) 303 { 304 ResMgr& rMgr = CUI_MGR(); 305 Image aWarningBoxImage = WarningBox::GetStandardImage(); 306 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 307 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001 308 AbstractSvxMessDialog* aMessDlg = pFact->CreateSvxMessDialog( DLGWIN, RID_SVXDLG_MESSBOX, 309 SVX_RESSTR( RID_SVXSTR_COLOR ), 310 String( ResId( RID_SVXSTR_ASK_CHANGE_COLOR, rMgr ) ), 311 &aWarningBoxImage ); 312 DBG_ASSERT(aMessDlg, "Dialogdiet fail!");//CHINA001 313 aMessDlg->SetButtonText( MESS_BTN_1, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1, 314 String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) ); 315 aMessDlg->SetButtonText( MESS_BTN_2, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2, 316 String( ResId( RID_SVXSTR_ADD, rMgr ) ) ); 317 318 short nRet = aMessDlg->Execute(); //CHINA001 short nRet = aMessDlg.Execute(); 319 320 switch( nRet ) 321 { 322 case RET_BTN_1: // Aendern 323 { 324 ClickModifyHdl_Impl( this ); 325 aColor = pColorTab->GetColor( nPos )->GetColor(); 326 } 327 break; 328 329 case RET_BTN_2: // Hinzufuegen 330 { 331 ClickAddHdl_Impl( this ); 332 nPos = aLbColor.GetSelectEntryPos(); 333 aColor = pColorTab->GetColor( nPos )->GetColor(); 334 } 335 break; 336 337 case RET_CANCEL: 338 // return( -1L ); <-- wuerde die Seite nicht verlassen 339 break; 340 // return( sal_True ); // Abbruch 341 } 342 delete aMessDlg; //add by CHINA001 343 } 344 } 345 if( *pDlgType == 0 ) // Flaechen-Dialog 346 { 347 nPos = aLbColor.GetSelectEntryPos(); 348 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 349 { 350 *pPos = nPos; 351 } 352 } 353 return( 0L ); 354 } 355 356 // ----------------------------------------------------------------------- 357 358 sal_Bool SvxColorTabPage::FillItemSet( SfxItemSet& rSet ) 359 { 360 if( ( *pDlgType != 0 ) || 361 ( *pPageType == PT_COLOR && *pbAreaTP == sal_False ) ) 362 { 363 String aString; 364 Color aColor; 365 366 // CheckChanges_Impl(); <-- doppelte Abfrage ? 367 368 sal_uInt16 nPos = aLbColor.GetSelectEntryPos(); 369 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 370 { 371 aColor = pColorTab->GetColor( nPos )->GetColor(); 372 aString = aLbColor.GetSelectEntry(); 373 } 374 else 375 { 376 aColor.SetColor (aAktuellColor.GetColor()); 377 if (eCM != CM_RGB) 378 ConvertColorValues (aColor, CM_RGB); 379 } 380 rSet.Put( XFillColorItem( aString, aColor ) ); 381 rSet.Put( XFillStyleItem( XFILL_SOLID ) ); 382 } 383 384 return( sal_True ); 385 } 386 387 // ----------------------------------------------------------------------- 388 389 void SvxColorTabPage::Reset( const SfxItemSet& rSet ) 390 { 391 sal_uInt16 nState = rSet.GetItemState( XATTR_FILLCOLOR ); 392 393 if ( nState >= SFX_ITEM_DEFAULT ) 394 { 395 XFillColorItem aColorItem( (const XFillColorItem&)rSet.Get( XATTR_FILLCOLOR ) ); 396 aLbColor.SelectEntry( aColorItem.GetColorValue() ); 397 aValSetColorTable.SelectItem( aLbColor.GetSelectEntryPos() + 1 ); 398 aEdtName.SetText( aLbColor.GetSelectEntry() ); 399 } 400 401 // Farbmodell setzen 402 String aStr = GetUserData(); 403 aLbColorModel.SelectEntryPos( (sal_uInt16) aStr.ToInt32() ); 404 405 ChangeColorHdl_Impl( this ); 406 SelectColorModelHdl_Impl( this ); 407 408 aCtlPreviewOld.Invalidate(); 409 410 // Status der Buttons ermitteln 411 if( pColorTab->Count() ) 412 { 413 aBtnModify.Enable(); 414 aBtnWorkOn.Enable(); 415 aBtnDelete.Enable(); 416 aBtnSave.Enable(); 417 } 418 else 419 { 420 aBtnModify.Disable(); 421 aBtnWorkOn.Disable(); 422 aBtnDelete.Disable(); 423 aBtnSave.Disable(); 424 } 425 } 426 427 // ----------------------------------------------------------------------- 428 429 SfxTabPage* SvxColorTabPage::Create( Window* pWindow, 430 const SfxItemSet& rOutAttrs ) 431 { 432 return( new SvxColorTabPage( pWindow, rOutAttrs ) ); 433 } 434 435 //------------------------------------------------------------------------ 436 437 // 438 // Wird aufgerufen, wenn Inhalt der MtrFileds f�r Farbwerte ver�ndert wird 439 // 440 IMPL_LINK( SvxColorTabPage, ModifiedHdl_Impl, void *, EMPTYARG ) 441 { 442 // lese aktuelle MtrFields aus, wenn cmyk, dann k-Wert als Trans.-Farbe 443 aAktuellColor.SetColor ( Color( (sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel4.GetValue() ), 444 (sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel1.GetValue() ), 445 (sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel2.GetValue() ), 446 (sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel3.GetValue() ) ).GetColor() ); 447 448 Color aTmpColor(aAktuellColor); 449 if (eCM != CM_RGB) 450 ConvertColorValues (aTmpColor, CM_RGB); 451 452 rXFSet.Put( XFillColorItem( String(), aTmpColor ) ); 453 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); 454 455 aCtlPreviewNew.Invalidate(); 456 457 return( 0L ); 458 } 459 460 //------------------------------------------------------------------------ 461 462 // 463 // Button 'Hinzuf�gen' 464 // 465 IMPL_LINK( SvxColorTabPage, ClickAddHdl_Impl, void *, EMPTYARG ) 466 { 467 Window *pWindow = this; 468 bool bEnabled; 469 while( pWindow ) 470 { 471 bEnabled = pWindow->IsEnabled(); 472 pWindow = pWindow->GetParent(); 473 } 474 475 ResMgr& rMgr = CUI_MGR(); 476 String aDesc( ResId( RID_SVXSTR_DESC_COLOR, rMgr ) ); 477 String aName( aEdtName.GetText() ); 478 XColorEntry* pEntry; 479 long nCount = pColorTab->Count(); 480 sal_Bool bDifferent = sal_True; 481 482 // Pruefen, ob Name schon vorhanden ist 483 for ( long i = 0; i < nCount && bDifferent; i++ ) 484 if ( aName == pColorTab->GetColor( i )->GetName() ) 485 bDifferent = sal_False; 486 487 // Wenn ja, wird wiederholt ein neuer Name angefordert 488 if ( !bDifferent ) 489 { 490 WarningBox aWarningBox( DLGWIN, WinBits( WB_OK ), 491 String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) ); 492 aWarningBox.SetHelpId( HID_WARN_NAME_DUPLICATE ); 493 aWarningBox.Execute(); 494 495 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 496 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001 497 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc ); 498 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001 499 sal_Bool bLoop = sal_True; 500 501 while ( !bDifferent && bLoop && pDlg->Execute() == RET_OK ) 502 { 503 pDlg->GetName( aName ); 504 bDifferent = sal_True; 505 506 for( long i = 0; i < nCount && bDifferent; i++ ) 507 { 508 if( aName == pColorTab->GetColor( i )->GetName() ) 509 bDifferent = sal_False; 510 } 511 512 if( bDifferent ) 513 bLoop = sal_False; 514 else 515 aWarningBox.Execute(); 516 } 517 delete( pDlg ); 518 } 519 520 // Wenn nicht vorhanden, wird Eintrag aufgenommen 521 if( bDifferent ) 522 { 523 if (eCM != CM_RGB) 524 ConvertColorValues (aAktuellColor, CM_RGB); 525 pEntry = new XColorEntry( aAktuellColor, aName ); 526 527 pColorTab->Insert( pColorTab->Count(), pEntry ); 528 529 aLbColor.Append( pEntry ); 530 aValSetColorTable.InsertItem( aValSetColorTable.GetItemCount() + 1, 531 pEntry->GetColor(), pEntry->GetName() ); 532 533 aLbColor.SelectEntryPos( aLbColor.GetEntryCount() - 1 ); 534 535 // Flag fuer modifiziert setzen 536 *pnColorTableState |= CT_MODIFIED; 537 538 SelectColorLBHdl_Impl( this ); 539 } 540 // Status der Buttons ermitteln 541 if( pColorTab->Count() ) 542 { 543 aBtnModify.Enable(); 544 aBtnWorkOn.Enable(); 545 aBtnDelete.Enable(); 546 aBtnSave.Enable(); 547 } 548 return( 0L ); 549 } 550 551 //------------------------------------------------------------------------ 552 553 // 554 // Button '�ndern' 555 // 556 IMPL_LINK( SvxColorTabPage, ClickModifyHdl_Impl, void *, EMPTYARG ) 557 { 558 sal_uInt16 nPos = aLbColor.GetSelectEntryPos(); 559 560 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 561 { 562 ResMgr& rMgr = CUI_MGR(); 563 String aDesc( ResId( RID_SVXSTR_DESC_COLOR, rMgr ) ); 564 String aName( aEdtName.GetText() ); 565 long nCount = pColorTab->Count(); 566 sal_Bool bDifferent = sal_True; 567 568 // Pruefen, ob Name schon vorhanden ist 569 for ( long i = 0; i < nCount && bDifferent; i++ ) 570 if ( aName == pColorTab->GetColor( i )->GetName() && nPos != i ) 571 bDifferent = sal_False; 572 573 // Wenn ja, wird wiederholt ein neuer Name angefordert 574 if ( !bDifferent ) 575 { 576 WarningBox aWarningBox( DLGWIN, WinBits( WB_OK ), 577 String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) ); 578 aWarningBox.SetHelpId( HID_WARN_NAME_DUPLICATE ); 579 aWarningBox.Execute(); 580 581 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 582 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001 583 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc ); 584 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001 585 sal_Bool bLoop = sal_True; 586 587 while ( !bDifferent && bLoop && pDlg->Execute() == RET_OK ) 588 { 589 pDlg->GetName( aName ); 590 bDifferent = sal_True; 591 592 for ( long i = 0; i < nCount && bDifferent; i++ ) 593 if( aName == pColorTab->GetColor( i )->GetName() && nPos != i ) 594 bDifferent = sal_False; 595 596 if( bDifferent ) 597 bLoop = sal_False; 598 else 599 aWarningBox.Execute(); 600 } 601 delete( pDlg ); 602 } 603 604 // Wenn nicht vorhanden, wird Eintrag aufgenommen 605 if( bDifferent ) 606 { 607 XColorEntry* pEntry = pColorTab->GetColor( nPos ); 608 609 Color aTmpColor (aAktuellColor); 610 if (eCM != CM_RGB) 611 ConvertColorValues (aTmpColor, CM_RGB); 612 613 pEntry->SetColor( aTmpColor ); 614 pEntry->SetName( aName ); 615 616 aLbColor.Modify( pEntry, nPos ); 617 aLbColor.SelectEntryPos( nPos ); 618 ///// 619 aValSetColorTable.SetItemColor( nPos + 1, pEntry->GetColor() ); 620 aValSetColorTable.SetItemText( nPos + 1, pEntry->GetName() ); 621 aEdtName.SetText( aName ); 622 623 aCtlPreviewOld.Invalidate(); 624 625 // Flag fuer modifiziert setzen 626 *pnColorTableState |= CT_MODIFIED; 627 } 628 } 629 return( 0L ); 630 } 631 632 //------------------------------------------------------------------------ 633 634 // 635 // Button 'Bearbeiten' 636 // 637 IMPL_LINK( SvxColorTabPage, ClickWorkOnHdl_Impl, void *, EMPTYARG ) 638 { 639 SvColorDialog* pColorDlg = new SvColorDialog( DLGWIN ); 640 641 Color aTmpColor (aAktuellColor); 642 if (eCM != CM_RGB) 643 ConvertColorValues (aTmpColor, CM_RGB); 644 645 pColorDlg->SetColor (aTmpColor); 646 pColorDlg->SetMode( svtools::ColorPickerMode_MODIFY ); 647 648 if( pColorDlg->Execute() == RET_OK ) 649 { 650 sal_uInt16 nK = 0; 651 Color aPreviewColor = pColorDlg->GetColor(); 652 aAktuellColor = aPreviewColor; 653 if (eCM != CM_RGB) 654 ConvertColorValues (aAktuellColor, eCM); 655 656 aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) ); 657 aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) ); 658 aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) ); 659 aMtrFldColorModel4.SetValue( ColorToPercent_Impl( nK ) ); 660 661 // ItemSet fuellen und an XOut weiterleiten 662 rXFSet.Put( XFillColorItem( String(), aPreviewColor ) ); 663 //aCtlPreviewOld.SetAttributes( aXFillAttr ); 664 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); 665 666 aCtlPreviewNew.Invalidate(); 667 } 668 delete( pColorDlg ); 669 670 return( 0L ); 671 } 672 673 //------------------------------------------------------------------------ 674 675 // 676 // Button 'Loeschen' 677 // 678 IMPL_LINK( SvxColorTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG ) 679 { 680 sal_uInt16 nPos = aLbColor.GetSelectEntryPos(); 681 682 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 683 { 684 QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ), 685 String( CUI_RES( RID_SVXSTR_ASK_DEL_COLOR ) ) ); 686 687 if( aQueryBox.Execute() == RET_YES ) 688 { 689 // Jetzt wird richtig geloescht 690 sal_uLong nCount = pColorTab->Count() - 1; 691 XColorEntry* pEntry; 692 693 pEntry = pColorTab->Remove( nPos ); 694 DBG_ASSERT( pEntry, "ColorEntry nicht vorhanden (1) !" ); 695 delete pEntry; 696 697 for( sal_uLong i = nPos; i < nCount; i++ ) 698 { 699 pEntry = pColorTab->Remove( i + 1 ); 700 DBG_ASSERT( pEntry, "ColorEntry nicht vorhanden (2) !" ); 701 pColorTab->Insert( i, pEntry ); 702 } 703 704 // Listbox und ValueSet aktualisieren 705 aLbColor.RemoveEntry( nPos ); 706 aValSetColorTable.Clear(); 707 FillValueSet_Impl( aValSetColorTable ); 708 709 // Positionieren 710 aLbColor.SelectEntryPos( nPos ); 711 SelectColorLBHdl_Impl( this ); 712 713 aCtlPreviewOld.Invalidate(); 714 715 // Flag fuer modifiziert setzen 716 *pnColorTableState |= CT_MODIFIED; 717 } 718 } 719 // Status der Buttons ermitteln 720 if( !pColorTab->Count() ) 721 { 722 aBtnModify.Disable(); 723 aBtnWorkOn.Disable(); 724 aBtnDelete.Disable(); 725 aBtnSave.Disable(); 726 } 727 return( 0L ); 728 } 729 730 // ----------------------------------------------------------------------- 731 732 // 733 // Button 'Farbtabelle laden' 734 // 735 IMPL_LINK( SvxColorTabPage, ClickLoadHdl_Impl, void *, EMPTYARG ) 736 { 737 ResMgr& rMgr = CUI_MGR(); 738 sal_uInt16 nReturn = RET_YES; 739 740 if( *pnColorTableState & CT_MODIFIED ) 741 { 742 nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ), 743 String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute(); 744 745 if ( nReturn == RET_YES ) 746 pColorTab->Save(); 747 } 748 749 if ( nReturn != RET_CANCEL ) 750 { 751 ::sfx2::FileDialogHelper aDlg( 752 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 753 0 ); 754 String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soc" ) ); 755 aDlg.AddFilter( aStrFilterType, aStrFilterType ); 756 INetURLObject aFile( SvtPathOptions().GetPalettePath() ); 757 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) ); 758 759 if ( aDlg.Execute() == ERRCODE_NONE ) 760 { 761 INetURLObject aURL( aDlg.GetPath() ); 762 INetURLObject aPathURL( aURL ); 763 764 aPathURL.removeSegment(); 765 aPathURL.removeFinalSlash(); 766 767 // Tabelle speichern 768 XColorTable* pColTab = new XColorTable( aPathURL.GetMainURL( INetURLObject::NO_DECODE ), pXPool ); 769 pColTab->SetName( aURL.getName() ); // XXX 770 if( pColTab->Load() ) 771 { 772 if( pColTab ) 773 { 774 // Pruefen, ob Tabelle geloescht werden darf: 775 const XColorTable *pTempTable = 0; 776 SvxAreaTabDialog* pArea = dynamic_cast< SvxAreaTabDialog* >( DLGWIN ); 777 SvxLineTabDialog* pLine = dynamic_cast< SvxLineTabDialog* >( DLGWIN ); 778 if( pArea ) 779 { 780 pTempTable = pArea->GetColorTable(); 781 } 782 else if( pLine ) 783 { 784 pTempTable = pLine->GetColorTable(); 785 } 786 787 if( pColorTab != pTempTable ) 788 { 789 if( bDeleteColorTable ) 790 delete pColorTab; 791 else 792 bDeleteColorTable = sal_True; 793 } 794 795 pColorTab = pColTab; 796 if( pArea ) 797 { 798 pArea->SetNewColorTable( pColorTab ); 799 } 800 else if( pLine ) 801 { 802 pLine->SetNewColorTable( pColorTab ); 803 } 804 805 aLbColor.Clear(); 806 aValSetColorTable.Clear(); 807 Construct(); 808 Reset( rOutAttrs ); 809 810 pColorTab->SetName( aURL.getName() ); 811 812 // Ermitteln (evtl. abschneiden) des Namens und in 813 // der GroupBox darstellen 814 String aString( ResId( RID_SVXSTR_TABLE, rMgr ) ); 815 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) ); 816 817 if ( aURL.getBase().getLength() > 18 ) 818 { 819 aString += String(aURL.getBase()).Copy( 0, 15 ); 820 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) ); 821 } 822 else 823 aString += String(aURL.getBase()); 824 825 aTableNameFT.SetText( aString ); 826 827 // Flag fuer gewechselt setzen 828 *pnColorTableState |= CT_CHANGED; 829 // Flag fuer modifiziert entfernen 830 *pnColorTableState &= ~CT_MODIFIED; 831 832 if( aLbColor.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND ) 833 aLbColor.SelectEntryPos( 0 ); 834 else 835 aLbColor.SelectEntryPos( aLbColor.GetSelectEntryPos() ); 836 837 ChangeColorHdl_Impl( this ); 838 SelectColorLBHdl_Impl( this ); 839 } 840 } 841 else 842 { 843 //aIStream.Close(); 844 ErrorBox aErrorBox( DLGWIN, WinBits( WB_OK ), 845 String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ); 846 aErrorBox.Execute(); 847 } 848 } 849 } 850 851 // Status der Buttons ermitteln 852 if ( pColorTab->Count() ) 853 { 854 aBtnModify.Enable(); 855 aBtnWorkOn.Enable(); 856 aBtnDelete.Enable(); 857 aBtnSave.Enable(); 858 } 859 else 860 { 861 aBtnModify.Disable(); 862 aBtnWorkOn.Disable(); 863 aBtnDelete.Disable(); 864 aBtnSave.Disable(); 865 } 866 return( 0L ); 867 } 868 869 // ----------------------------------------------------------------------- 870 871 // 872 // Button 'Farbtabelle speichern' 873 // 874 IMPL_LINK( SvxColorTabPage, ClickSaveHdl_Impl, void *, EMPTYARG ) 875 { 876 ::sfx2::FileDialogHelper aDlg( 877 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 ); 878 String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soc" ) ); 879 aDlg.AddFilter( aStrFilterType, aStrFilterType ); 880 881 INetURLObject aFile( SvtPathOptions().GetPalettePath() ); 882 DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" ); 883 884 if( pColorTab->GetName().Len() ) 885 { 886 aFile.Append( pColorTab->GetName() ); 887 888 if( !aFile.getExtension().getLength() ) 889 aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "soc" ) ) ); 890 } 891 892 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) ); 893 if ( aDlg.Execute() == ERRCODE_NONE ) 894 { 895 INetURLObject aURL( aDlg.GetPath() ); 896 INetURLObject aPathURL( aURL ); 897 898 aPathURL.removeSegment(); 899 aPathURL.removeFinalSlash(); 900 901 pColorTab->SetName( aURL.getName() ); 902 pColorTab->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) ); 903 904 if( pColorTab->Save() ) 905 { 906 // Ermitteln (evtl. abschneiden) des Namens und in 907 // der GroupBox darstellen 908 String aString( CUI_RES( RID_SVXSTR_TABLE ) ); 909 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) ); 910 911 if ( aURL.getBase().getLength() > 18 ) 912 { 913 aString += String(aURL.getBase()).Copy( 0, 15 ); 914 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) ); 915 } 916 else 917 aString += String(aURL.getBase()); 918 aTableNameFT.SetText( aString ); 919 920 // Flag fuer gespeichert setzen 921 *pnColorTableState |= CT_SAVED; 922 // Flag fuer modifiziert entfernen 923 *pnColorTableState &= ~CT_MODIFIED; 924 } 925 else 926 { 927 ErrorBox aErrorBox( DLGWIN, WinBits( WB_OK ), 928 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ); 929 aErrorBox.Execute(); 930 } 931 } 932 return( 0L ); 933 } 934 935 //------------------------------------------------------------------------ 936 937 IMPL_LINK( SvxColorTabPage, SelectColorLBHdl_Impl, void *, EMPTYARG ) 938 { 939 sal_uInt16 nPos = aLbColor.GetSelectEntryPos(); 940 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 941 { 942 aValSetColorTable.SelectItem( nPos + 1 ); 943 aEdtName.SetText( aLbColor.GetSelectEntry() ); 944 945 rXFSet.Put( XFillColorItem( String(), 946 aLbColor.GetSelectEntryColor() ) ); 947 aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() ); 948 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); 949 950 aCtlPreviewOld.Invalidate(); 951 aCtlPreviewNew.Invalidate(); 952 953 ChangeColorHdl_Impl( this ); 954 } 955 return( 0L ); 956 } 957 958 //------------------------------------------------------------------------ 959 960 IMPL_LINK( SvxColorTabPage, SelectValSetHdl_Impl, void *, EMPTYARG ) 961 { 962 sal_uInt16 nPos = aValSetColorTable.GetSelectItemId(); 963 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 964 { 965 aLbColor.SelectEntryPos( nPos - 1 ); 966 aEdtName.SetText( aLbColor.GetSelectEntry() ); 967 968 rXFSet.Put( XFillColorItem( String(), 969 aLbColor.GetSelectEntryColor() ) ); 970 aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() ); 971 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); 972 973 aCtlPreviewOld.Invalidate(); 974 aCtlPreviewNew.Invalidate(); 975 976 ChangeColorHdl_Impl( this ); 977 } 978 return( 0L ); 979 } 980 981 //------------------------------------------------------------------------ 982 983 // 984 // Farbwerte je nach �bergebenes Farbmodell umrechnen 985 // 986 void SvxColorTabPage::ConvertColorValues (Color& rColor, ColorModel eModell) 987 { 988 switch (eModell) 989 { 990 case CM_RGB: 991 { 992 CmykToRgb_Impl (rColor, (sal_uInt16)rColor.GetTransparency() ); 993 rColor.SetTransparency ((sal_uInt8) 0); 994 } 995 break; 996 997 case CM_CMYK: 998 { 999 sal_uInt16 nK; 1000 RgbToCmyk_Impl (rColor, nK ); 1001 rColor.SetTransparency ((sal_uInt8) nK); 1002 } 1003 break; 1004 } 1005 } 1006 1007 // 1008 // Auswahl Listbox 'Farbmodell' (RGB/CMY) 1009 // 1010 IMPL_LINK( SvxColorTabPage, SelectColorModelHdl_Impl, void *, EMPTYARG ) 1011 { 1012 int nPos = aLbColorModel.GetSelectEntryPos(); 1013 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 1014 { 1015 if (eCM != (ColorModel) nPos) 1016 { 1017 // wenn Farbmodell geaendert wurde, dann Werte umrechnen 1018 ConvertColorValues (aAktuellColor, (ColorModel) nPos); 1019 } 1020 1021 eCM = (ColorModel) nPos; 1022 1023 switch( eCM ) 1024 { 1025 case CM_RGB: 1026 { 1027 String aStr( aLbColorModel.GetSelectEntry() ); 1028 String aColorStr( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "~X" ) ) ); 1029 xub_StrLen nIdx = 1; 1030 aColorStr.SetChar( nIdx, aStr.GetChar( 0 ) ); 1031 aFtColorModel1.SetText( aColorStr ); 1032 aColorStr.SetChar( nIdx, aStr.GetChar( 1 ) ); 1033 aFtColorModel2.SetText( aColorStr ); 1034 aColorStr.SetChar( nIdx, aStr.GetChar( 2 ) ); 1035 aFtColorModel3.SetText( aColorStr ); 1036 1037 aFtColorModel4.Hide(); 1038 aMtrFldColorModel4.Hide(); 1039 aMtrFldColorModel4.SetValue( 0L ); 1040 1041 aMtrFldColorModel1.SetHelpId( HID_TPCOLOR_RGB_1 ); 1042 aMtrFldColorModel2.SetHelpId( HID_TPCOLOR_RGB_2 ); 1043 aMtrFldColorModel3.SetHelpId( HID_TPCOLOR_RGB_3 ); 1044 1045 // Da der alte HelpText noch am Control steht wuerde 1046 // ein Umsetzen der HelpID alleine nichts bewirken 1047 aMtrFldColorModel1.SetHelpText( String() ); 1048 aMtrFldColorModel2.SetHelpText( String() ); 1049 aMtrFldColorModel3.SetHelpText( String() ); 1050 1051 // RGB-Werte im Bereich 0..255 verarbeiten (nicht in %), 1052 // dazu MetricField's entsprechend einstellen 1053 aMtrFldColorModel1.SetUnit(FUNIT_NONE); 1054 aMtrFldColorModel1.SetMin(0); 1055 aMtrFldColorModel1.SetMax(255); 1056 aMtrFldColorModel1.SetLast(255); 1057 1058 aMtrFldColorModel2.SetUnit(FUNIT_NONE); 1059 aMtrFldColorModel2.SetMin(0); 1060 aMtrFldColorModel2.SetMax(255); 1061 aMtrFldColorModel2.SetLast(255); 1062 1063 aMtrFldColorModel3.SetUnit(FUNIT_NONE); 1064 aMtrFldColorModel3.SetMin(0); 1065 aMtrFldColorModel3.SetMax(255); 1066 aMtrFldColorModel3.SetLast(255); 1067 } 1068 break; 1069 1070 case CM_CMYK: 1071 { 1072 String aStr( aLbColorModel.GetSelectEntry() ); 1073 String aColorStr( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "~X" ) ) ); 1074 xub_StrLen nIdx = 1; 1075 aColorStr.SetChar( nIdx, aStr.GetChar( 0 ) ); 1076 aFtColorModel1.SetText( aColorStr ); 1077 aColorStr.SetChar( nIdx, aStr.GetChar( 1 ) ); 1078 aFtColorModel2.SetText( aColorStr ); 1079 aColorStr.SetChar( nIdx,aStr.GetChar( 2 ) ); 1080 aFtColorModel3.SetText( aColorStr ); 1081 aColorStr.SetChar( nIdx,aStr.GetChar( 3 ) ); 1082 aFtColorModel4.SetText( aColorStr ); 1083 1084 aFtColorModel4.Show(); 1085 aMtrFldColorModel4.Show(); 1086 1087 aMtrFldColorModel1.SetHelpId( HID_TPCOLOR_CMYK_1 ); 1088 aMtrFldColorModel2.SetHelpId( HID_TPCOLOR_CMYK_2 ); 1089 aMtrFldColorModel3.SetHelpId( HID_TPCOLOR_CMYK_3 ); 1090 1091 // s.o. 1092 aMtrFldColorModel1.SetHelpText( String() ); 1093 aMtrFldColorModel2.SetHelpText( String() ); 1094 aMtrFldColorModel3.SetHelpText( String() ); 1095 1096 // CMYK-Werte im Bereich 0..100% verarbeiten, 1097 // dazu MetricField's entsprechend einstellen 1098 String aStrUnit( RTL_CONSTASCII_USTRINGPARAM( " %" ) ); 1099 1100 aMtrFldColorModel1.SetUnit(FUNIT_CUSTOM); 1101 aMtrFldColorModel1.SetCustomUnitText( aStrUnit ); 1102 aMtrFldColorModel1.SetMin(0); 1103 aMtrFldColorModel1.SetMax(100); 1104 aMtrFldColorModel1.SetLast(100); 1105 1106 aMtrFldColorModel2.SetUnit(FUNIT_CUSTOM); 1107 aMtrFldColorModel2.SetCustomUnitText( aStrUnit ); 1108 aMtrFldColorModel2.SetMin(0); 1109 aMtrFldColorModel2.SetMax(100); 1110 aMtrFldColorModel2.SetLast(100); 1111 1112 aMtrFldColorModel3.SetUnit(FUNIT_CUSTOM); 1113 aMtrFldColorModel3.SetCustomUnitText( aStrUnit ); 1114 aMtrFldColorModel3.SetMin(0); 1115 aMtrFldColorModel3.SetMax(100); 1116 aMtrFldColorModel3.SetLast(100); 1117 } 1118 break; 1119 } 1120 1121 aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) ); 1122 aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) ); 1123 aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) ); 1124 aMtrFldColorModel4.SetValue( ColorToPercent_Impl( aAktuellColor.GetTransparency() ) ); 1125 } 1126 1127 aMtrFldColorModel1.SetAccessibleName( GetNonMnemonicString(aFtColorModel1.GetText()) ); 1128 aMtrFldColorModel2.SetAccessibleName( GetNonMnemonicString(aFtColorModel2.GetText()) ); 1129 aMtrFldColorModel3.SetAccessibleName( GetNonMnemonicString(aFtColorModel3.GetText()) ); 1130 aMtrFldColorModel4.SetAccessibleName( GetNonMnemonicString(aFtColorModel4.GetText()) ); 1131 1132 return( 0L ); 1133 } 1134 1135 //------------------------------------------------------------------------ 1136 1137 long SvxColorTabPage::ChangeColorHdl_Impl( void* ) 1138 { 1139 int nPos = aLbColor.GetSelectEntryPos(); 1140 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 1141 { 1142 XColorEntry* pEntry = pColorTab->GetColor( nPos ); 1143 1144 aAktuellColor.SetColor ( pEntry->GetColor().GetColor() ); 1145 if (eCM != CM_RGB) 1146 ConvertColorValues (aAktuellColor, eCM); 1147 1148 aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) ); 1149 aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) ); 1150 aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) ); 1151 aMtrFldColorModel4.SetValue( ColorToPercent_Impl( aAktuellColor.GetTransparency() ) ); 1152 1153 // ItemSet fuellen und an XOut weiterleiten 1154 rXFSet.Put( XFillColorItem( String(), pEntry->GetColor() ) ); 1155 aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() ); 1156 aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() ); 1157 1158 aCtlPreviewNew.Invalidate(); 1159 } 1160 return( 0L ); 1161 } 1162 1163 //------------------------------------------------------------------------ 1164 1165 void SvxColorTabPage::FillValueSet_Impl( ValueSet& rVs ) 1166 { 1167 long nCount = pColorTab->Count(); 1168 XColorEntry* pColorEntry; 1169 1170 for( long i = 0; i < nCount; i++ ) 1171 { 1172 pColorEntry = pColorTab->GetColor( i ); 1173 rVs.InsertItem( (sal_uInt16) i + 1, pColorEntry->GetColor(), pColorEntry->GetName() ); 1174 } 1175 } 1176 1177 //------------------------------------------------------------------------ 1178 1179 // Ein RGB-Wert wird in einen CMYK-Wert konvertiert, wobei die Color- 1180 // Klasse vergewaltigt wird, da R in C, G in M und B in Y umgewandelt 1181 // wird. Der Wert K wird in einer Extra-Variablen gehalten. 1182 // Bei weiteren Farbmodellen sollte man hierfuer eigene Klassen entwickeln, 1183 // die dann auch entsprechende Casts enthalten. 1184 1185 void SvxColorTabPage::RgbToCmyk_Impl( Color& rColor, sal_uInt16& rK ) 1186 { 1187 sal_uInt16 nColor1, nColor2, nColor3; 1188 sal_uInt16 nProzent; // nur temporaer !!! 1189 1190 nColor1 = 255 - rColor.GetRed(); 1191 nProzent = ColorToPercent_Impl( nColor1 ); 1192 1193 nColor2 = 255 - rColor.GetGreen(); 1194 nProzent = ColorToPercent_Impl( nColor2 ); 1195 1196 nColor3 = 255 - rColor.GetBlue(); 1197 nProzent = ColorToPercent_Impl( nColor3 ); 1198 1199 rK = Min( Min( nColor1, nColor2 ), nColor3 ); 1200 1201 rColor.SetRed( sal::static_int_cast< sal_uInt8 >( nColor1 - rK ) ); 1202 rColor.SetGreen( sal::static_int_cast< sal_uInt8 >( nColor2 - rK ) ); 1203 rColor.SetBlue( sal::static_int_cast< sal_uInt8 >( nColor3 - rK ) ); 1204 } 1205 1206 //------------------------------------------------------------------------ 1207 1208 // Umgekehrter Fall zu RgbToCmyk_Impl (s.o.) 1209 1210 void SvxColorTabPage::CmykToRgb_Impl( Color& rColor, const sal_uInt16 nK ) 1211 { 1212 long lTemp; 1213 1214 lTemp = 255 - ( rColor.GetRed() + nK ); 1215 1216 if( lTemp < 0L ) 1217 lTemp = 0L; 1218 rColor.SetRed( (sal_uInt8)lTemp ); 1219 1220 lTemp = 255 - ( rColor.GetGreen() + nK ); 1221 1222 if( lTemp < 0L ) 1223 lTemp = 0L; 1224 rColor.SetGreen( (sal_uInt8)lTemp ); 1225 1226 lTemp = 255 - ( rColor.GetBlue() + nK ); 1227 1228 if( lTemp < 0L ) 1229 lTemp = 0L; 1230 rColor.SetBlue( (sal_uInt8)lTemp ); 1231 } 1232 1233 //------------------------------------------------------------------------ 1234 1235 sal_uInt16 SvxColorTabPage::ColorToPercent_Impl( sal_uInt16 nColor ) 1236 { 1237 sal_uInt16 nWert = 0; 1238 1239 switch (eCM) 1240 { 1241 case CM_RGB : 1242 nWert = nColor; 1243 break; 1244 1245 case CM_CMYK: 1246 nWert = (sal_uInt16) ( (double) nColor * 100.0 / 255.0 + 0.5 ); 1247 break; 1248 } 1249 1250 return ( nWert ); 1251 } 1252 1253 //------------------------------------------------------------------------ 1254 1255 sal_uInt16 SvxColorTabPage::PercentToColor_Impl( sal_uInt16 nPercent ) 1256 { 1257 sal_uInt16 nWert = 0; 1258 1259 switch (eCM) 1260 { 1261 case CM_RGB : 1262 nWert = nPercent; 1263 break; 1264 1265 case CM_CMYK: 1266 nWert = (sal_uInt16) ( (double) nPercent * 255.0 / 100.0 + 0.5 ); 1267 break; 1268 } 1269 1270 return ( nWert ); 1271 } 1272 1273 //------------------------------------------------------------------------ 1274 1275 void SvxColorTabPage::FillUserData() 1276 { 1277 // Das Farbmodell wird in der Ini-Datei festgehalten 1278 SetUserData( UniString::CreateFromInt32( eCM ) ); 1279 } 1280 1281 1282