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