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 pColorTab( NULL ), 101 pGradientList( NULL ), 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( pColorTab ); 173 aLbColorTo.CopyEntries( aLbColorFrom ); 174 175 // Farbverlauftabelle 176 aLbGradients.Fill( pGradientList ); 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( pColorTab ) 191 { 192 // ColorTable 193 if( *pnColorTableState & CT_CHANGED || 194 *pnColorTableState & CT_MODIFIED ) 195 { 196 if( *pnColorTableState & CT_CHANGED ) 197 pColorTab = ( (SvxAreaTabDialog*) DLGWIN )->GetNewColorTable(); 198 199 // LbColorFrom 200 nPos = aLbColorFrom.GetSelectEntryPos(); 201 aLbColorFrom.Clear(); 202 aLbColorFrom.Fill( pColorTab ); 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( pGradientList->GetPath() ); 230 231 aURL.Append( pGradientList->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 = pGradientList->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 = pGradientList->GetGradient( nPos )->GetGradient(); 313 } 314 break; 315 316 case RET_BTN_2: // Hinzufuegen 317 { 318 ClickAddHdl_Impl( this ); 319 nPos = aLbGradients.GetSelectEntryPos(); 320 aGradient = pGradientList->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( pGradientList->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( pGradientList->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 = pGradientList->Count(); 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 == pGradientList->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 == pGradientList->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 pGradientList->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( pGradientList->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( pGradientList->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 = pGradientList->Count(); 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 == pGradientList->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 pGradientList->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 pGradientList->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( !pGradientList->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 pGradientList->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 XGradientList* pGrdList = new XGradientList( aPathURL.GetMainURL( INetURLObject::NO_DECODE ), pXPool ); 691 pGrdList->SetName( aURL.getName() ); 692 693 if ( pGrdList->Load() ) 694 { 695 if ( pGrdList ) 696 { 697 // Pruefen, ob Tabelle geloescht werden darf: 698 if ( pGradientList != 699 ( (SvxAreaTabDialog*) DLGWIN )->GetGradientList() ) 700 delete pGradientList; 701 702 pGradientList = pGrdList; 703 ( (SvxAreaTabDialog*) DLGWIN )-> 704 SetNewGradientList( pGradientList ); 705 706 aLbGradients.Clear(); 707 aLbGradients.Fill( pGradientList ); 708 Reset( rOutAttrs ); 709 710 pGradientList->SetName( aURL.getName() ); 711 712 // Ermitteln (evtl. abschneiden) des Namens und in 713 // der GroupBox darstellen 714 String aString( ResId( RID_SVXSTR_TABLE, rMgr ) ); 715 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) ); 716 717 if ( aURL.getBase().getLength() > 18 ) 718 { 719 aString += String(aURL.getBase()).Copy( 0, 15 ); 720 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) ); 721 } 722 else 723 aString += String(aURL.getBase()); 724 725 // Flag fuer gewechselt setzen 726 *pnGradientListState |= CT_CHANGED; 727 // Flag fuer modifiziert entfernen 728 *pnGradientListState &= ~CT_MODIFIED; 729 } 730 LeaveWait(); 731 } 732 else 733 { 734 LeaveWait(); 735 //aIStream.Close(); 736 ErrorBox( DLGWIN, WinBits( WB_OK ), 737 String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute(); 738 } 739 } 740 } 741 742 // Status der Buttons ermitteln 743 if( pGradientList->Count() ) 744 { 745 aBtnModify.Enable(); 746 aBtnDelete.Enable(); 747 aBtnSave.Enable(); 748 } 749 else 750 { 751 aBtnModify.Disable(); 752 aBtnDelete.Disable(); 753 aBtnSave.Disable(); 754 } 755 return 0L; 756 } 757 758 // ----------------------------------------------------------------------- 759 760 IMPL_LINK( SvxGradientTabPage, ClickSaveHdl_Impl, void *, EMPTYARG ) 761 { 762 ::sfx2::FileDialogHelper aDlg( 763 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 ); 764 String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sog" ) ); 765 aDlg.AddFilter( aStrFilterType, aStrFilterType ); 766 767 INetURLObject aFile( SvtPathOptions().GetPalettePath() ); 768 DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" ); 769 770 if( pGradientList->GetName().Len() ) 771 { 772 aFile.Append( pGradientList->GetName() ); 773 774 if( !aFile.getExtension().getLength() ) 775 aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "sog" ) ) ); 776 } 777 778 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) ); 779 if ( aDlg.Execute() == ERRCODE_NONE ) 780 { 781 INetURLObject aURL( aDlg.GetPath() ); 782 INetURLObject aPathURL( aURL ); 783 784 aPathURL.removeSegment(); 785 aPathURL.removeFinalSlash(); 786 787 pGradientList->SetName( aURL.getName() ); 788 pGradientList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) ); 789 790 if( pGradientList->Save() ) 791 { 792 // Ermitteln (evtl. abschneiden) des Namens und in 793 // der GroupBox darstellen 794 String aString( CUI_RES( RID_SVXSTR_TABLE ) ); 795 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) ); 796 797 if ( aURL.getBase().getLength() > 18 ) 798 { 799 aString += String(aURL.getBase()).Copy( 0, 15 ); 800 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) ); 801 } 802 else 803 aString += String(aURL.getBase()); 804 805 // Flag fuer gespeichert setzen 806 *pnGradientListState |= CT_SAVED; 807 // Flag fuer modifiziert entfernen 808 *pnGradientListState &= ~CT_MODIFIED; 809 } 810 else 811 { 812 ErrorBox( DLGWIN, WinBits( WB_OK ), 813 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute(); 814 } 815 } 816 817 return 0L; 818 } 819 820 //------------------------------------------------------------------------ 821 822 IMPL_LINK( SvxGradientTabPage, ChangeGradientHdl_Impl, void *, EMPTYARG ) 823 { 824 XGradient* pGradient = NULL; 825 int nPos = aLbGradients.GetSelectEntryPos(); 826 827 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 828 pGradient = new XGradient( ( (XGradientEntry*) pGradientList->GetGradient( nPos ) )->GetGradient() ); 829 else 830 { 831 const SfxPoolItem* pPoolItem = NULL; 832 if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), sal_True, &pPoolItem ) ) 833 { 834 if( ( XFILL_GRADIENT == (XFillStyle) ( ( const XFillStyleItem* ) pPoolItem )->GetValue() ) && 835 ( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLGRADIENT ), sal_True, &pPoolItem ) ) ) 836 { 837 pGradient = new XGradient( ( ( const XFillGradientItem* ) pPoolItem )->GetGradientValue() ); 838 } 839 } 840 if( !pGradient ) 841 { 842 aLbGradients.SelectEntryPos( 0 ); 843 nPos = aLbGradients.GetSelectEntryPos(); 844 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 845 pGradient = new XGradient( ( (XGradientEntry*) pGradientList->GetGradient( nPos ) )->GetGradient() ); 846 } 847 } 848 849 if( pGradient ) 850 { 851 XGradientStyle eXGS = pGradient->GetGradientStyle(); 852 853 aLbGradientType.SelectEntryPos( 854 sal::static_int_cast< sal_uInt16 >( eXGS ) ); 855 // Wenn der EIntrag nicht in der Listbox ist, werden die Farben 856 // temporaer hinzugenommen 857 aLbColorFrom.SetNoSelection(); 858 aLbColorFrom.SelectEntry( pGradient->GetStartColor() ); 859 860 if ( aLbColorFrom.GetSelectEntryCount() == 0 ) 861 { 862 aLbColorFrom.InsertEntry( pGradient->GetStartColor(), 863 String() ); 864 aLbColorFrom.SelectEntry( pGradient->GetStartColor() ); 865 } 866 aLbColorTo.SetNoSelection(); 867 aLbColorTo.SelectEntry( pGradient->GetEndColor() ); 868 869 if ( aLbColorTo.GetSelectEntryCount() == 0 ) 870 { 871 aLbColorTo.InsertEntry( pGradient->GetEndColor(), String() ); 872 aLbColorTo.SelectEntry( pGradient->GetEndColor() ); 873 } 874 875 aMtrAngle.SetValue( pGradient->GetAngle() / 10 ); // sollte in Resource geaendert werden 876 aMtrBorder.SetValue( pGradient->GetBorder() ); 877 aMtrCenterX.SetValue( pGradient->GetXOffset() ); 878 aMtrCenterY.SetValue( pGradient->GetYOffset() ); 879 aMtrColorFrom.SetValue( pGradient->GetStartIntens() ); 880 aMtrColorTo.SetValue( pGradient->GetEndIntens() ); 881 882 // Controls Disablen/Enablen 883 SetControlState_Impl( eXGS ); 884 885 // ItemSet fuellen und an aCtlPreview weiterleiten 886 rXFSet.Put( XFillGradientItem( String(), *pGradient ) ); 887 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() ); 888 889 aCtlPreview.Invalidate(); 890 delete pGradient; 891 } 892 return 0L; 893 } 894 895 //------------------------------------------------------------------------ 896 897 void SvxGradientTabPage::SetControlState_Impl( XGradientStyle eXGS ) 898 { 899 switch( eXGS ) 900 { 901 case XGRAD_LINEAR: 902 case XGRAD_AXIAL: 903 aFtCenterX.Disable(); 904 aMtrCenterX.Disable(); 905 aFtCenterY.Disable(); 906 aMtrCenterY.Disable(); 907 aFtAngle.Enable(); 908 aMtrAngle.Enable(); 909 break; 910 911 case XGRAD_RADIAL: 912 aFtCenterX.Enable(); 913 aMtrCenterX.Enable(); 914 aFtCenterY.Enable(); 915 aMtrCenterY.Enable(); 916 aFtAngle.Disable(); 917 aMtrAngle.Disable(); 918 break; 919 920 case XGRAD_ELLIPTICAL: 921 aFtCenterX.Enable(); 922 aMtrCenterX.Enable(); 923 aFtCenterY.Enable(); 924 aMtrCenterY.Enable(); 925 aFtAngle.Enable(); 926 aMtrAngle.Enable(); 927 break; 928 929 case XGRAD_SQUARE: 930 case XGRAD_RECT: 931 aFtCenterX.Enable(); 932 aMtrCenterX.Enable(); 933 aFtCenterY.Enable(); 934 aMtrCenterY.Enable(); 935 aFtAngle.Enable(); 936 aMtrAngle.Enable(); 937 break; 938 } 939 } 940 941 942