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