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 <vcl/wrkwin.hxx> 29 #include <tools/shl.hxx> 30 #include <tools/urlobj.hxx> 31 #include <vcl/msgbox.hxx> 32 #include <unotools/pathoptions.hxx> 33 #include <sfx2/app.hxx> 34 #include <sfx2/filedlghelper.hxx> 35 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp" 36 37 #define _SVX_TPGRADNT_CXX 38 39 #include <cuires.hrc> 40 #include "helpid.hrc" 41 #include "svx/xattr.hxx" 42 #include <svx/xtable.hxx> 43 #include <svx/xpool.hxx> 44 #include "svx/drawitem.hxx" 45 #include "cuitabarea.hxx" 46 #include "tabarea.hrc" 47 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx" 48 //#include "dlgname.hrc" 49 #include <svx/svxdlg.hxx> //CHINA001 50 #include <dialmgr.hxx> 51 #include <svx/dialmgr.hxx> 52 #include <svx/dialogs.hrc> 53 #include "paragrph.hrc" 54 55 #define DLGWIN this->GetParent()->GetParent() 56 57 #define BITMAP_WIDTH 32 58 #define BITMAP_HEIGHT 12 59 60 /************************************************************************* 61 |* 62 |* Dialog zum Aendern und Definieren der Farbverlaeufe 63 |* 64 \************************************************************************/ 65 66 SvxGradientTabPage::SvxGradientTabPage 67 ( 68 Window* pParent, 69 const SfxItemSet& rInAttrs 70 ) : 71 SfxTabPage ( pParent, CUI_RES( RID_SVXPAGE_GRADIENT ), rInAttrs ), 72 73 aFlProp ( this, CUI_RES( FL_PROP ) ), 74 aFtType ( this, CUI_RES( FT_TYPE ) ), 75 aLbGradientType ( this, CUI_RES( LB_GRADIENT_TYPES ) ), 76 aFtCenterX ( this, CUI_RES( FT_CENTER_X ) ), 77 aMtrCenterX ( this, CUI_RES( MTR_CENTER_X ) ), 78 aFtCenterY ( this, CUI_RES( FT_CENTER_Y ) ), 79 aMtrCenterY ( this, CUI_RES( MTR_CENTER_Y ) ), 80 aFtAngle ( this, CUI_RES( FT_ANGLE ) ), 81 aMtrAngle ( this, CUI_RES( MTR_ANGLE ) ), 82 aFtBorder ( this, CUI_RES( FT_BORDER ) ), 83 aMtrBorder ( this, CUI_RES( MTR_BORDER ) ), 84 aFtColorFrom ( this, CUI_RES( FT_COLOR_FROM ) ), 85 aLbColorFrom ( this, CUI_RES( LB_COLOR_FROM ) ), 86 aMtrColorFrom ( this, CUI_RES( MTR_COLOR_FROM ) ), 87 aFtColorTo ( this, CUI_RES( FT_COLOR_TO ) ), 88 aLbColorTo ( this, CUI_RES( LB_COLOR_TO ) ), 89 aMtrColorTo ( this, CUI_RES( MTR_COLOR_TO ) ), 90 aLbGradients ( this, CUI_RES( LB_GRADIENTS ) ), 91 aCtlPreview ( this, CUI_RES( CTL_PREVIEW ) ), 92 aBtnAdd ( this, CUI_RES( BTN_ADD ) ), 93 aBtnModify ( this, CUI_RES( BTN_MODIFY ) ), 94 aBtnDelete ( this, CUI_RES( BTN_DELETE ) ), 95 aBtnLoad ( this, CUI_RES( BTN_LOAD ) ), 96 aBtnSave ( this, CUI_RES( BTN_SAVE ) ), 97 98 rOutAttrs ( rInAttrs ), 99 100 maColorTab(), 101 maGradientList(), 102 103 pXPool ( (XOutdevItemPool*) rInAttrs.GetPool() ), 104 aXFStyleItem ( XFILL_GRADIENT ), 105 aXGradientItem ( String(), XGradient( COL_BLACK, COL_WHITE ) ), 106 aXFillAttr ( pXPool ), 107 rXFSet ( aXFillAttr.GetItemSet() ) 108 { 109 aBtnLoad.SetModeImage( Image( CUI_RES( RID_SVXIMG_LOAD_H ) ), BMP_COLOR_HIGHCONTRAST ); 110 aBtnSave.SetModeImage( Image( CUI_RES( RID_SVXIMG_SAVE_H ) ), BMP_COLOR_HIGHCONTRAST ); 111 112 FreeResource(); 113 114 aCtlPreview.SetAccessibleName(String(CUI_RES(STR_EXAMPLE))); 115 aLbGradients.SetAccessibleName( GetText()); 116 117 118 // diese Page braucht ExchangeSupport 119 SetExchangeSupport(); 120 121 // Solange NICHT vom Item unterstuetzt 122 123 //aMtrColorTo.Disable(); 124 aMtrColorTo.SetValue( 100 ); 125 //aMtrColorFrom.Disable(); 126 aMtrColorFrom.SetValue( 100 ); 127 128 // Setzen des Output-Devices 129 rXFSet.Put( aXFStyleItem ); 130 rXFSet.Put( aXGradientItem ); 131 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() ); 132 133 // Handler ueberladen 134 aLbGradients.SetSelectHdl( 135 LINK( this, SvxGradientTabPage, ChangeGradientHdl_Impl ) ); 136 aBtnAdd.SetClickHdl( LINK( this, SvxGradientTabPage, ClickAddHdl_Impl ) ); 137 aBtnModify.SetClickHdl( 138 LINK( this, SvxGradientTabPage, ClickModifyHdl_Impl ) ); 139 aBtnDelete.SetClickHdl( 140 LINK( this, SvxGradientTabPage, ClickDeleteHdl_Impl ) ); 141 142 Link aLink = LINK( this, SvxGradientTabPage, ModifiedHdl_Impl ); 143 aLbGradientType.SetSelectHdl( aLink ); 144 aMtrCenterX.SetModifyHdl( aLink ); 145 aMtrCenterY.SetModifyHdl( aLink ); 146 aMtrAngle.SetModifyHdl( aLink ); 147 aMtrBorder.SetModifyHdl( aLink ); 148 aMtrColorFrom.SetModifyHdl( aLink ); 149 aLbColorFrom.SetSelectHdl( aLink ); 150 aMtrColorTo.SetModifyHdl( aLink ); 151 aLbColorTo.SetSelectHdl( aLink ); 152 153 aBtnLoad.SetClickHdl( 154 LINK( this, SvxGradientTabPage, ClickLoadHdl_Impl ) ); 155 aBtnSave.SetClickHdl( 156 LINK( this, SvxGradientTabPage, ClickSaveHdl_Impl ) ); 157 158 aBtnAdd.SetAccessibleRelationMemberOf( &aFlProp ); 159 aBtnModify.SetAccessibleRelationMemberOf( &aFlProp ); 160 aBtnDelete.SetAccessibleRelationMemberOf( &aFlProp ); 161 aLbGradients.SetAccessibleRelationLabeledBy(&aLbGradients); 162 163 // #i76307# always paint the preview in LTR, because this is what the document does 164 aCtlPreview.EnableRTL( sal_False ); 165 } 166 167 // ----------------------------------------------------------------------- 168 169 void SvxGradientTabPage::Construct() 170 { 171 // Farbtabelle 172 aLbColorFrom.Fill( maColorTab ); 173 aLbColorTo.CopyEntries( aLbColorFrom ); 174 175 // Farbverlauftabelle 176 aLbGradients.Fill( maGradientList ); 177 } 178 179 // ----------------------------------------------------------------------- 180 181 void SvxGradientTabPage::ActivatePage( const SfxItemSet& ) 182 { 183 sal_uInt16 nPos; 184 sal_uInt16 nCount; 185 186 if( *pDlgType == 0 ) // Flaechen-Dialog 187 { 188 *pbAreaTP = sal_False; 189 190 if( maColorTab.get() ) 191 { 192 // ColorTable 193 if( *pnColorTableState & CT_CHANGED || 194 *pnColorTableState & CT_MODIFIED ) 195 { 196 if( *pnColorTableState & CT_CHANGED ) 197 maColorTab = ( (SvxAreaTabDialog*) DLGWIN )->GetNewColorTable(); 198 199 // LbColorFrom 200 nPos = aLbColorFrom.GetSelectEntryPos(); 201 aLbColorFrom.Clear(); 202 aLbColorFrom.Fill( maColorTab ); 203 nCount = aLbColorFrom.GetEntryCount(); 204 if( nCount == 0 ) 205 ; // Dieser Fall sollte nicht auftreten 206 else if( nCount <= nPos ) 207 aLbColorFrom.SelectEntryPos( 0 ); 208 else 209 aLbColorFrom.SelectEntryPos( nPos ); 210 211 // LbColorTo 212 nPos = aLbColorTo.GetSelectEntryPos(); 213 aLbColorTo.Clear(); 214 aLbColorTo.CopyEntries( aLbColorFrom ); 215 nCount = aLbColorTo.GetEntryCount(); 216 if( nCount == 0 ) 217 ; // Dieser Fall sollte nicht auftreten 218 else if( nCount <= nPos ) 219 aLbColorTo.SelectEntryPos( 0 ); 220 else 221 aLbColorTo.SelectEntryPos( nPos ); 222 223 ModifiedHdl_Impl( this ); 224 } 225 226 // Ermitteln (evtl. abschneiden) des Namens und in 227 // der GroupBox darstellen 228 String aString( CUI_RES( RID_SVXSTR_TABLE ) ); aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) ); 229 INetURLObject aURL( maGradientList->GetPath() ); 230 231 aURL.Append( maGradientList->GetName() ); 232 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" ); 233 234 if ( aURL.getBase().getLength() > 18 ) 235 { 236 aString += String(aURL.getBase()).Copy( 0, 15 ); 237 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) ); 238 } 239 else 240 aString += String(aURL.getBase()); 241 242 if ( *pPageType == PT_GRADIENT && *pPos != LISTBOX_ENTRY_NOTFOUND ) 243 { 244 aLbGradients.SelectEntryPos( *pPos ); 245 } 246 // Farben koennten geloescht worden sein 247 ChangeGradientHdl_Impl( this ); 248 249 *pPageType = PT_GRADIENT; 250 *pPos = LISTBOX_ENTRY_NOTFOUND; 251 } 252 } 253 } 254 255 // ----------------------------------------------------------------------- 256 257 int SvxGradientTabPage::DeactivatePage( SfxItemSet* _pSet ) 258 { 259 if( CheckChanges_Impl() == -1L ) 260 return KEEP_PAGE; 261 262 if( _pSet ) 263 FillItemSet( *_pSet ); 264 265 return LEAVE_PAGE; 266 } 267 268 // ----------------------------------------------------------------------- 269 270 long SvxGradientTabPage::CheckChanges_Impl() 271 { 272 // wird hier benutzt, um Aenderungen NICHT zu verlieren 273 XGradient aTmpGradient( aLbColorFrom.GetSelectEntryColor(), 274 aLbColorTo.GetSelectEntryColor(), 275 (XGradientStyle) aLbGradientType.GetSelectEntryPos(), 276 static_cast<long>(aMtrAngle.GetValue() * 10), // sollte in Resource geaendert werden 277 (sal_uInt16) aMtrCenterX.GetValue(), 278 (sal_uInt16) aMtrCenterY.GetValue(), 279 (sal_uInt16) aMtrBorder.GetValue(), 280 (sal_uInt16) aMtrColorFrom.GetValue(), 281 (sal_uInt16) aMtrColorTo.GetValue() ); 282 283 sal_uInt16 nPos = aLbGradients.GetSelectEntryPos(); 284 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 285 { 286 XGradient aGradient = maGradientList->GetGradient( nPos )->GetGradient(); 287 String aString = aLbGradients.GetSelectEntry(); 288 289 if( !( aTmpGradient == aGradient ) ) 290 { 291 ResMgr& rMgr = CUI_MGR(); 292 Image aWarningBoxImage = WarningBox::GetStandardImage(); 293 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 294 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001 295 AbstractSvxMessDialog* aMessDlg = pFact->CreateSvxMessDialog( DLGWIN, RID_SVXDLG_MESSBOX, 296 SVX_RESSTR( RID_SVXSTR_GRADIENT ), 297 CUI_RESSTR( RID_SVXSTR_ASK_CHANGE_GRADIENT ), 298 &aWarningBoxImage ); 299 DBG_ASSERT(aMessDlg, "Dialogdiet fail!");//CHINA001 300 aMessDlg->SetButtonText( MESS_BTN_1, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1, 301 String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) ); 302 aMessDlg->SetButtonText( MESS_BTN_2, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2, 303 String( ResId( RID_SVXSTR_ADD, rMgr ) ) ); 304 305 short nRet = aMessDlg->Execute(); //CHINA001 short nRet = aMessDlg.Execute(); 306 307 switch( nRet ) 308 { 309 case RET_BTN_1: // Aendern 310 { 311 ClickModifyHdl_Impl( this ); 312 aGradient = maGradientList->GetGradient( nPos )->GetGradient(); 313 } 314 break; 315 316 case RET_BTN_2: // Hinzufuegen 317 { 318 ClickAddHdl_Impl( this ); 319 nPos = aLbGradients.GetSelectEntryPos(); 320 aGradient = maGradientList->GetGradient( nPos )->GetGradient(); 321 } 322 break; 323 324 case RET_CANCEL: 325 // return( -1L ); <-- wuerde die Seite nicht verlassen 326 break; 327 // return( sal_True ); // Abbruch 328 } 329 delete aMessDlg; //add by CHINA001 330 } 331 } 332 nPos = aLbGradients.GetSelectEntryPos(); 333 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 334 { 335 *pPos = nPos; 336 } 337 return 0L; 338 } 339 340 // ----------------------------------------------------------------------- 341 342 sal_Bool SvxGradientTabPage::FillItemSet( SfxItemSet& rSet ) 343 { 344 if( *pDlgType == 0 && *pPageType == PT_GRADIENT && *pbAreaTP == sal_False ) 345 { 346 // CheckChanges(); <-- doppelte Abfrage ? 347 348 XGradient* pXGradient = NULL; 349 String aString; 350 sal_uInt16 nPos = aLbGradients.GetSelectEntryPos(); 351 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 352 { 353 pXGradient = new XGradient( maGradientList->GetGradient( nPos )->GetGradient() ); 354 aString = aLbGradients.GetSelectEntry(); 355 356 } 357 else 358 // Farbverlauf wurde (unbekannt) uebergeben 359 { 360 pXGradient = new XGradient( aLbColorFrom.GetSelectEntryColor(), 361 aLbColorTo.GetSelectEntryColor(), 362 (XGradientStyle) aLbGradientType.GetSelectEntryPos(), 363 static_cast<long>(aMtrAngle.GetValue() * 10), // sollte in Resource geaendert werden 364 (sal_uInt16) aMtrCenterX.GetValue(), 365 (sal_uInt16) aMtrCenterY.GetValue(), 366 (sal_uInt16) aMtrBorder.GetValue(), 367 (sal_uInt16) aMtrColorFrom.GetValue(), 368 (sal_uInt16) aMtrColorTo.GetValue() ); 369 } 370 DBG_ASSERT( pXGradient, "XGradient konnte nicht erzeugt werden" ); 371 rSet.Put( XFillStyleItem( XFILL_GRADIENT ) ); 372 rSet.Put( XFillGradientItem( aString, *pXGradient ) ); 373 374 delete pXGradient; 375 } 376 return sal_True; 377 } 378 379 // ----------------------------------------------------------------------- 380 381 void SvxGradientTabPage::Reset( const SfxItemSet& ) 382 { 383 // aLbGradients.SelectEntryPos( 0 ); 384 ChangeGradientHdl_Impl( this ); 385 386 // Status der Buttons ermitteln 387 if( maGradientList->Count() ) 388 { 389 aBtnModify.Enable(); 390 aBtnDelete.Enable(); 391 aBtnSave.Enable(); 392 } 393 else 394 { 395 aBtnModify.Disable(); 396 aBtnDelete.Disable(); 397 aBtnSave.Disable(); 398 } 399 } 400 401 // ----------------------------------------------------------------------- 402 403 SfxTabPage* SvxGradientTabPage::Create( Window* pWindow, 404 const SfxItemSet& rOutAttrs ) 405 { 406 return new SvxGradientTabPage( pWindow, rOutAttrs ); 407 } 408 409 //------------------------------------------------------------------------ 410 411 IMPL_LINK( SvxGradientTabPage, ModifiedHdl_Impl, void *, pControl ) 412 { 413 XGradientStyle eXGS = (XGradientStyle) aLbGradientType.GetSelectEntryPos(); 414 415 XGradient aXGradient( aLbColorFrom.GetSelectEntryColor(), 416 aLbColorTo.GetSelectEntryColor(), 417 eXGS, 418 static_cast<long>(aMtrAngle.GetValue() * 10), // sollte in Resource geaendert werden 419 (sal_uInt16) aMtrCenterX.GetValue(), 420 (sal_uInt16) aMtrCenterY.GetValue(), 421 (sal_uInt16) aMtrBorder.GetValue(), 422 (sal_uInt16) aMtrColorFrom.GetValue(), 423 (sal_uInt16) aMtrColorTo.GetValue() ); 424 425 // Enablen/Disablen von Controls 426 if( pControl == &aLbGradientType || pControl == this ) 427 SetControlState_Impl( eXGS ); 428 429 // Anzeigen im XOutDev 430 rXFSet.Put( XFillGradientItem( String(), aXGradient ) ); 431 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() ); 432 433 aCtlPreview.Invalidate(); 434 435 return 0L; 436 } 437 438 //------------------------------------------------------------------------ 439 440 IMPL_LINK( SvxGradientTabPage, ClickAddHdl_Impl, void *, EMPTYARG ) 441 { 442 ResMgr& rMgr = CUI_MGR(); 443 String aNewName( SVX_RES( RID_SVXSTR_GRADIENT ) ); 444 String aDesc( CUI_RES( RID_SVXSTR_DESC_GRADIENT ) ); 445 String aName; 446 447 long nCount = maGradientList.get() ? maGradientList->Count() : 0; 448 long j = 1; 449 sal_Bool bDifferent = sal_False; 450 451 while( !bDifferent ) 452 { 453 aName = aNewName; 454 aName += sal_Unicode(' '); 455 aName += UniString::CreateFromInt32( j++ ); 456 bDifferent = sal_True; 457 458 for( long i = 0; i < nCount && bDifferent; i++ ) 459 if( aName == maGradientList->GetGradient( i )->GetName() ) 460 bDifferent = sal_False; 461 } 462 463 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 464 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001 465 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc ); 466 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001 467 WarningBox* pWarnBox = NULL; 468 sal_uInt16 nError = RID_SVXSTR_WARN_NAME_DUPLICATE; 469 470 while( pDlg->Execute() == RET_OK ) 471 { 472 pDlg->GetName( aName ); 473 474 bDifferent = sal_True; 475 476 for( long i = 0; i < nCount && bDifferent; i++ ) 477 if( aName == maGradientList->GetGradient( i )->GetName() ) 478 bDifferent = sal_False; 479 480 if( bDifferent ) 481 { 482 nError = 0; 483 break; 484 } 485 486 if( !pWarnBox ) 487 { 488 pWarnBox = new WarningBox( DLGWIN, 489 WinBits( WB_OK_CANCEL ), 490 String( ResId( nError, rMgr ) ) ); 491 pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE ); 492 } 493 494 if( pWarnBox->Execute() != RET_OK ) 495 break; 496 } 497 //Rectangle aDlgRect( pDlg->GetPosPixel(), pDlg->GetSizePixel() ); 498 delete pDlg; 499 delete pWarnBox; 500 501 if( !nError ) 502 { 503 XGradient aXGradient( aLbColorFrom.GetSelectEntryColor(), 504 aLbColorTo.GetSelectEntryColor(), 505 (XGradientStyle) aLbGradientType.GetSelectEntryPos(), 506 static_cast<long>(aMtrAngle.GetValue() * 10), // sollte in Resource geaendert werden 507 (sal_uInt16) aMtrCenterX.GetValue(), 508 (sal_uInt16) aMtrCenterY.GetValue(), 509 (sal_uInt16) aMtrBorder.GetValue(), 510 (sal_uInt16) aMtrColorFrom.GetValue(), 511 (sal_uInt16) aMtrColorTo.GetValue() ); 512 XGradientEntry* pEntry = new XGradientEntry( aXGradient, aName ); 513 514 maGradientList->Insert( pEntry, nCount ); 515 516 aLbGradients.Append( pEntry ); 517 518 aLbGradients.SelectEntryPos( aLbGradients.GetEntryCount() - 1 ); 519 520 #ifdef WNT 521 // hack: #31355# W.P. 522 Rectangle aRect( aLbGradients.GetPosPixel(), aLbGradients.GetSizePixel() ); 523 if( sal_True ) { // ??? overlapped with pDlg 524 // and srolling 525 Invalidate( aRect ); 526 //aLbGradients.Invalidate(); 527 } 528 #endif 529 530 // Flag fuer modifiziert setzen 531 *pnGradientListState |= CT_MODIFIED; 532 533 ChangeGradientHdl_Impl( this ); 534 } 535 536 // Status der Buttons ermitteln 537 if( maGradientList.get() && maGradientList->Count() ) 538 { 539 aBtnModify.Enable(); 540 aBtnDelete.Enable(); 541 aBtnSave.Enable(); 542 } 543 return 0L; 544 } 545 546 //------------------------------------------------------------------------ 547 548 IMPL_LINK( SvxGradientTabPage, ClickModifyHdl_Impl, void *, EMPTYARG ) 549 { 550 sal_uInt16 nPos = aLbGradients.GetSelectEntryPos(); 551 552 if ( nPos != LISTBOX_ENTRY_NOTFOUND ) 553 { 554 ResMgr& rMgr = CUI_MGR(); 555 String aNewName( SVX_RES( RID_SVXSTR_GRADIENT ) ); 556 String aDesc( CUI_RES( RID_SVXSTR_DESC_GRADIENT ) ); 557 String aName( maGradientList->GetGradient( nPos )->GetName() ); 558 String aOldName = aName; 559 560 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 561 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001 562 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc ); 563 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001 564 565 long nCount = maGradientList.get() ? maGradientList->Count() : 0; 566 sal_Bool bDifferent = sal_False; 567 sal_Bool bLoop = sal_True; 568 569 while( bLoop && pDlg->Execute() == RET_OK ) 570 { 571 pDlg->GetName( aName ); 572 bDifferent = sal_True; 573 574 for( long i = 0; i < nCount && bDifferent; i++ ) 575 { 576 if( aName == maGradientList->GetGradient( i )->GetName() && 577 aName != aOldName ) 578 bDifferent = sal_False; 579 } 580 581 if( bDifferent ) 582 { 583 bLoop = sal_False; 584 XGradient aXGradient( aLbColorFrom.GetSelectEntryColor(), 585 aLbColorTo.GetSelectEntryColor(), 586 (XGradientStyle) aLbGradientType.GetSelectEntryPos(), 587 static_cast<long>(aMtrAngle.GetValue() * 10), // sollte in Resource geaendert werden 588 (sal_uInt16) aMtrCenterX.GetValue(), 589 (sal_uInt16) aMtrCenterY.GetValue(), 590 (sal_uInt16) aMtrBorder.GetValue(), 591 (sal_uInt16) aMtrColorFrom.GetValue(), 592 (sal_uInt16) aMtrColorTo.GetValue() ); 593 594 XGradientEntry* pEntry = new XGradientEntry( aXGradient, aName ); 595 596 delete maGradientList->Replace( pEntry, nPos ); 597 598 aLbGradients.Modify( pEntry, nPos ); 599 600 aLbGradients.SelectEntryPos( nPos ); 601 602 // Flag fuer modifiziert setzen 603 *pnGradientListState |= CT_MODIFIED; 604 } 605 else 606 { 607 WarningBox aBox( DLGWIN, WinBits( WB_OK ),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) ); 608 aBox.SetHelpId( HID_WARN_NAME_DUPLICATE ); 609 aBox.Execute(); 610 } 611 612 } 613 delete pDlg; 614 } 615 return 0L; 616 } 617 618 //------------------------------------------------------------------------ 619 620 IMPL_LINK( SvxGradientTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG ) 621 { 622 sal_uInt16 nPos = aLbGradients.GetSelectEntryPos(); 623 624 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 625 { 626 QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ), 627 String( CUI_RES( RID_SVXSTR_ASK_DEL_GRADIENT ) ) ); 628 629 if ( aQueryBox.Execute() == RET_YES ) 630 { 631 delete maGradientList->Remove( nPos ); 632 aLbGradients.RemoveEntry( nPos ); 633 aLbGradients.SelectEntryPos( 0 ); 634 635 aCtlPreview.Invalidate(); 636 637 ChangeGradientHdl_Impl( this ); 638 639 // Flag fuer modifiziert setzen 640 *pnGradientListState |= CT_MODIFIED; 641 } 642 } 643 // Status der Buttons ermitteln 644 if( !maGradientList.get() || !maGradientList->Count() ) 645 { 646 aBtnModify.Disable(); 647 aBtnDelete.Disable(); 648 aBtnSave.Disable(); 649 } 650 return 0L; 651 } 652 653 // ----------------------------------------------------------------------- 654 655 IMPL_LINK( SvxGradientTabPage, ClickLoadHdl_Impl, void *, EMPTYARG ) 656 { 657 ResMgr& rMgr = CUI_MGR(); 658 sal_uInt16 nReturn = RET_YES; 659 660 if ( *pnGradientListState & CT_MODIFIED ) 661 { 662 nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ), 663 String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute(); 664 665 if ( nReturn == RET_YES ) 666 maGradientList->Save(); 667 } 668 669 if ( nReturn != RET_CANCEL ) 670 { 671 ::sfx2::FileDialogHelper aDlg( 672 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 673 0 ); 674 String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sog" ) ); 675 aDlg.AddFilter( aStrFilterType, aStrFilterType ); 676 INetURLObject aFile( SvtPathOptions().GetPalettePath() ); 677 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) ); 678 679 if( aDlg.Execute() == ERRCODE_NONE ) 680 { 681 EnterWait(); 682 683 INetURLObject aURL( aDlg.GetPath() ); 684 INetURLObject aPathURL( aURL ); 685 686 aPathURL.removeSegment(); 687 aPathURL.removeFinalSlash(); 688 689 // Liste speichern 690 XGradientListSharedPtr aGrdList(XPropertyListFactory::CreateSharedXGradientList(aPathURL.GetMainURL(INetURLObject::NO_DECODE))); 691 aGrdList->SetName( aURL.getName() ); 692 693 if ( aGrdList->Load() ) 694 { 695 if ( aGrdList ) 696 { 697 maGradientList = aGrdList; 698 ( (SvxAreaTabDialog*) DLGWIN )->SetNewGradientList( maGradientList ); 699 700 aLbGradients.Clear(); 701 aLbGradients.Fill( maGradientList ); 702 Reset( rOutAttrs ); 703 704 maGradientList->SetName( aURL.getName() ); 705 706 // Ermitteln (evtl. abschneiden) des Namens und in 707 // der GroupBox darstellen 708 String aString( ResId( RID_SVXSTR_TABLE, rMgr ) ); 709 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) ); 710 711 if ( aURL.getBase().getLength() > 18 ) 712 { 713 aString += String(aURL.getBase()).Copy( 0, 15 ); 714 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) ); 715 } 716 else 717 aString += String(aURL.getBase()); 718 719 // Flag fuer gewechselt setzen 720 *pnGradientListState |= CT_CHANGED; 721 // Flag fuer modifiziert entfernen 722 *pnGradientListState &= ~CT_MODIFIED; 723 } 724 LeaveWait(); 725 } 726 else 727 { 728 LeaveWait(); 729 //aIStream.Close(); 730 ErrorBox( DLGWIN, WinBits( WB_OK ), 731 String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute(); 732 } 733 } 734 } 735 736 // Status der Buttons ermitteln 737 if( maGradientList.get() && maGradientList->Count() ) 738 { 739 aBtnModify.Enable(); 740 aBtnDelete.Enable(); 741 aBtnSave.Enable(); 742 } 743 else 744 { 745 aBtnModify.Disable(); 746 aBtnDelete.Disable(); 747 aBtnSave.Disable(); 748 } 749 return 0L; 750 } 751 752 // ----------------------------------------------------------------------- 753 754 IMPL_LINK( SvxGradientTabPage, ClickSaveHdl_Impl, void *, EMPTYARG ) 755 { 756 ::sfx2::FileDialogHelper aDlg( 757 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 ); 758 String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sog" ) ); 759 aDlg.AddFilter( aStrFilterType, aStrFilterType ); 760 761 INetURLObject aFile( SvtPathOptions().GetPalettePath() ); 762 DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" ); 763 764 if( maGradientList->GetName().Len() ) 765 { 766 aFile.Append( maGradientList->GetName() ); 767 768 if( !aFile.getExtension().getLength() ) 769 aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "sog" ) ) ); 770 } 771 772 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) ); 773 if ( aDlg.Execute() == ERRCODE_NONE ) 774 { 775 INetURLObject aURL( aDlg.GetPath() ); 776 INetURLObject aPathURL( aURL ); 777 778 aPathURL.removeSegment(); 779 aPathURL.removeFinalSlash(); 780 781 maGradientList->SetName( aURL.getName() ); 782 maGradientList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) ); 783 784 if( maGradientList->Save() ) 785 { 786 // Ermitteln (evtl. abschneiden) des Namens und in 787 // der GroupBox darstellen 788 String aString( CUI_RES( RID_SVXSTR_TABLE ) ); 789 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) ); 790 791 if ( aURL.getBase().getLength() > 18 ) 792 { 793 aString += String(aURL.getBase()).Copy( 0, 15 ); 794 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) ); 795 } 796 else 797 aString += String(aURL.getBase()); 798 799 // Flag fuer gespeichert setzen 800 *pnGradientListState |= CT_SAVED; 801 // Flag fuer modifiziert entfernen 802 *pnGradientListState &= ~CT_MODIFIED; 803 } 804 else 805 { 806 ErrorBox( DLGWIN, WinBits( WB_OK ), 807 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute(); 808 } 809 } 810 811 return 0L; 812 } 813 814 //------------------------------------------------------------------------ 815 816 IMPL_LINK( SvxGradientTabPage, ChangeGradientHdl_Impl, void *, EMPTYARG ) 817 { 818 XGradient* pGradient = NULL; 819 int nPos = aLbGradients.GetSelectEntryPos(); 820 821 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 822 pGradient = new XGradient( ( (XGradientEntry*) maGradientList->GetGradient( nPos ) )->GetGradient() ); 823 else 824 { 825 const SfxPoolItem* pPoolItem = NULL; 826 if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), sal_True, &pPoolItem ) ) 827 { 828 if( ( XFILL_GRADIENT == (XFillStyle) ( ( const XFillStyleItem* ) pPoolItem )->GetValue() ) && 829 ( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLGRADIENT ), sal_True, &pPoolItem ) ) ) 830 { 831 pGradient = new XGradient( ( ( const XFillGradientItem* ) pPoolItem )->GetGradientValue() ); 832 } 833 } 834 if( !pGradient ) 835 { 836 aLbGradients.SelectEntryPos( 0 ); 837 nPos = aLbGradients.GetSelectEntryPos(); 838 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 839 pGradient = new XGradient( ( (XGradientEntry*) maGradientList->GetGradient( nPos ) )->GetGradient() ); 840 } 841 } 842 843 if( pGradient ) 844 { 845 XGradientStyle eXGS = pGradient->GetGradientStyle(); 846 847 aLbGradientType.SelectEntryPos( 848 sal::static_int_cast< sal_uInt16 >( eXGS ) ); 849 // Wenn der EIntrag nicht in der Listbox ist, werden die Farben 850 // temporaer hinzugenommen 851 aLbColorFrom.SetNoSelection(); 852 aLbColorFrom.SelectEntry( pGradient->GetStartColor() ); 853 854 if ( aLbColorFrom.GetSelectEntryCount() == 0 ) 855 { 856 aLbColorFrom.InsertEntry( pGradient->GetStartColor(), 857 String() ); 858 aLbColorFrom.SelectEntry( pGradient->GetStartColor() ); 859 } 860 aLbColorTo.SetNoSelection(); 861 aLbColorTo.SelectEntry( pGradient->GetEndColor() ); 862 863 if ( aLbColorTo.GetSelectEntryCount() == 0 ) 864 { 865 aLbColorTo.InsertEntry( pGradient->GetEndColor(), String() ); 866 aLbColorTo.SelectEntry( pGradient->GetEndColor() ); 867 } 868 869 aMtrAngle.SetValue( pGradient->GetAngle() / 10 ); // sollte in Resource geaendert werden 870 aMtrBorder.SetValue( pGradient->GetBorder() ); 871 aMtrCenterX.SetValue( pGradient->GetXOffset() ); 872 aMtrCenterY.SetValue( pGradient->GetYOffset() ); 873 aMtrColorFrom.SetValue( pGradient->GetStartIntens() ); 874 aMtrColorTo.SetValue( pGradient->GetEndIntens() ); 875 876 // Controls Disablen/Enablen 877 SetControlState_Impl( eXGS ); 878 879 // ItemSet fuellen und an aCtlPreview weiterleiten 880 rXFSet.Put( XFillGradientItem( String(), *pGradient ) ); 881 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() ); 882 883 aCtlPreview.Invalidate(); 884 delete pGradient; 885 } 886 return 0L; 887 } 888 889 //------------------------------------------------------------------------ 890 891 void SvxGradientTabPage::SetControlState_Impl( XGradientStyle eXGS ) 892 { 893 switch( eXGS ) 894 { 895 case XGRAD_LINEAR: 896 case XGRAD_AXIAL: 897 aFtCenterX.Disable(); 898 aMtrCenterX.Disable(); 899 aFtCenterY.Disable(); 900 aMtrCenterY.Disable(); 901 aFtAngle.Enable(); 902 aMtrAngle.Enable(); 903 break; 904 905 case XGRAD_RADIAL: 906 aFtCenterX.Enable(); 907 aMtrCenterX.Enable(); 908 aFtCenterY.Enable(); 909 aMtrCenterY.Enable(); 910 aFtAngle.Disable(); 911 aMtrAngle.Disable(); 912 break; 913 914 case XGRAD_ELLIPTICAL: 915 aFtCenterX.Enable(); 916 aMtrCenterX.Enable(); 917 aFtCenterY.Enable(); 918 aMtrCenterY.Enable(); 919 aFtAngle.Enable(); 920 aMtrAngle.Enable(); 921 break; 922 923 case XGRAD_SQUARE: 924 case XGRAD_RECT: 925 aFtCenterX.Enable(); 926 aMtrCenterX.Enable(); 927 aFtCenterY.Enable(); 928 aMtrCenterY.Enable(); 929 aFtAngle.Enable(); 930 aMtrAngle.Enable(); 931 break; 932 } 933 } 934 935 936