merge the formfield patch from ooo-build
[ooovba.git] / svx / source / cui / tpgradnt.cxx
blob99f8b357b89def4f4d8d08112a9ba73c346d6a87
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tpgradnt.cxx,v $
10 * $Revision: 1.26 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 // include ---------------------------------------------------------------
39 #include <vcl/wrkwin.hxx>
40 #include <tools/shl.hxx>
41 #include <tools/urlobj.hxx>
42 #include <vcl/msgbox.hxx>
43 #include <svtools/pathoptions.hxx>
44 #include <sfx2/app.hxx>
45 #include <sfx2/filedlghelper.hxx>
46 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
48 #define _SVX_TPGRADNT_CXX
50 #include <svx/dialogs.hrc>
51 #include "helpid.hrc"
53 #include "xattr.hxx"
54 #include <svx/xtable.hxx>
55 #include <svx/xpool.hxx>
56 #include "drawitem.hxx"
57 #include "cuitabarea.hxx"
58 #include "tabarea.hrc"
59 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx"
60 #include "dlgname.hrc"
61 #include <svx/svxdlg.hxx> //CHINA001
62 #include <svx/dialmgr.hxx>
64 #define DLGWIN this->GetParent()->GetParent()
66 #define BITMAP_WIDTH 32
67 #define BITMAP_HEIGHT 12
69 /*************************************************************************
71 |* Dialog zum Aendern und Definieren der Farbverlaeufe
73 \************************************************************************/
75 SvxGradientTabPage::SvxGradientTabPage
77 Window* pParent,
78 const SfxItemSet& rInAttrs
79 ) :
80 SfxTabPage ( pParent, SVX_RES( RID_SVXPAGE_GRADIENT ), rInAttrs ),
82 aFlProp ( this, SVX_RES( FL_PROP ) ),
83 aFtType ( this, SVX_RES( FT_TYPE ) ),
84 aLbGradientType ( this, SVX_RES( LB_GRADIENT_TYPES ) ),
85 aFtCenterX ( this, SVX_RES( FT_CENTER_X ) ),
86 aMtrCenterX ( this, SVX_RES( MTR_CENTER_X ) ),
87 aFtCenterY ( this, SVX_RES( FT_CENTER_Y ) ),
88 aMtrCenterY ( this, SVX_RES( MTR_CENTER_Y ) ),
89 aFtAngle ( this, SVX_RES( FT_ANGLE ) ),
90 aMtrAngle ( this, SVX_RES( MTR_ANGLE ) ),
91 aFtBorder ( this, SVX_RES( FT_BORDER ) ),
92 aMtrBorder ( this, SVX_RES( MTR_BORDER ) ),
93 aFtColorFrom ( this, SVX_RES( FT_COLOR_FROM ) ),
94 aLbColorFrom ( this, SVX_RES( LB_COLOR_FROM ) ),
95 aMtrColorFrom ( this, SVX_RES( MTR_COLOR_FROM ) ),
96 aFtColorTo ( this, SVX_RES( FT_COLOR_TO ) ),
97 aLbColorTo ( this, SVX_RES( LB_COLOR_TO ) ),
98 aMtrColorTo ( this, SVX_RES( MTR_COLOR_TO ) ),
99 aLbGradients ( this, SVX_RES( LB_GRADIENTS ) ),
100 aCtlPreview ( this, SVX_RES( CTL_PREVIEW ) ),
101 aBtnAdd ( this, SVX_RES( BTN_ADD ) ),
102 aBtnModify ( this, SVX_RES( BTN_MODIFY ) ),
103 aBtnDelete ( this, SVX_RES( BTN_DELETE ) ),
104 aBtnLoad ( this, SVX_RES( BTN_LOAD ) ),
105 aBtnSave ( this, SVX_RES( BTN_SAVE ) ),
107 rOutAttrs ( rInAttrs ),
109 pColorTab( NULL ),
110 pGradientList( NULL ),
112 pXPool ( (XOutdevItemPool*) rInAttrs.GetPool() ),
113 aXFStyleItem ( XFILL_GRADIENT ),
114 aXGradientItem ( String(), XGradient( COL_BLACK, COL_WHITE ) ),
115 aXFillAttr ( pXPool ),
116 rXFSet ( aXFillAttr.GetItemSet() )
118 aBtnLoad.SetModeImage( Image( SVX_RES( RID_SVXIMG_LOAD_H ) ), BMP_COLOR_HIGHCONTRAST );
119 aBtnSave.SetModeImage( Image( SVX_RES( RID_SVXIMG_SAVE_H ) ), BMP_COLOR_HIGHCONTRAST );
121 FreeResource();
123 // diese Page braucht ExchangeSupport
124 SetExchangeSupport();
126 // Solange NICHT vom Item unterstuetzt
128 //aMtrColorTo.Disable();
129 aMtrColorTo.SetValue( 100 );
130 //aMtrColorFrom.Disable();
131 aMtrColorFrom.SetValue( 100 );
133 // Setzen des Output-Devices
134 rXFSet.Put( aXFStyleItem );
135 rXFSet.Put( aXGradientItem );
136 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
138 // Handler ueberladen
139 aLbGradients.SetSelectHdl(
140 LINK( this, SvxGradientTabPage, ChangeGradientHdl_Impl ) );
141 aBtnAdd.SetClickHdl( LINK( this, SvxGradientTabPage, ClickAddHdl_Impl ) );
142 aBtnModify.SetClickHdl(
143 LINK( this, SvxGradientTabPage, ClickModifyHdl_Impl ) );
144 aBtnDelete.SetClickHdl(
145 LINK( this, SvxGradientTabPage, ClickDeleteHdl_Impl ) );
147 Link aLink = LINK( this, SvxGradientTabPage, ModifiedHdl_Impl );
148 aLbGradientType.SetSelectHdl( aLink );
149 aMtrCenterX.SetModifyHdl( aLink );
150 aMtrCenterY.SetModifyHdl( aLink );
151 aMtrAngle.SetModifyHdl( aLink );
152 aMtrBorder.SetModifyHdl( aLink );
153 aMtrColorFrom.SetModifyHdl( aLink );
154 aLbColorFrom.SetSelectHdl( aLink );
155 aMtrColorTo.SetModifyHdl( aLink );
156 aLbColorTo.SetSelectHdl( aLink );
158 aBtnLoad.SetClickHdl(
159 LINK( this, SvxGradientTabPage, ClickLoadHdl_Impl ) );
160 aBtnSave.SetClickHdl(
161 LINK( this, SvxGradientTabPage, ClickSaveHdl_Impl ) );
163 // #i76307# always paint the preview in LTR, because this is what the document does
164 aCtlPreview.EnableRTL( FALSE );
167 // -----------------------------------------------------------------------
169 void SvxGradientTabPage::Construct()
171 // Farbtabelle
172 aLbColorFrom.Fill( pColorTab );
173 aLbColorTo.CopyEntries( aLbColorFrom );
175 // Farbverlauftabelle
176 aLbGradients.Fill( pGradientList );
179 // -----------------------------------------------------------------------
181 void SvxGradientTabPage::ActivatePage( const SfxItemSet& )
183 USHORT nPos;
184 USHORT nCount;
186 if( *pDlgType == 0 ) // Flaechen-Dialog
188 *pbAreaTP = FALSE;
190 if( pColorTab )
192 // ColorTable
193 if( *pnColorTableState & CT_CHANGED ||
194 *pnColorTableState & CT_MODIFIED )
196 if( *pnColorTableState & CT_CHANGED )
197 pColorTab = ( (SvxAreaTabDialog*) DLGWIN )->GetNewColorTable();
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 );
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 );
223 ModifiedHdl_Impl( this );
226 // Ermitteln (evtl. abschneiden) des Namens und in
227 // der GroupBox darstellen
228 String aString( SVX_RES( RID_SVXSTR_TABLE ) ); aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
229 INetURLObject aURL( pGradientList->GetPath() );
231 aURL.Append( pGradientList->GetName() );
232 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
234 if ( aURL.getBase().getLength() > 18 )
236 aString += String(aURL.getBase()).Copy( 0, 15 );
237 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
239 else
240 aString += String(aURL.getBase());
242 if ( *pPageType == PT_GRADIENT && *pPos != LISTBOX_ENTRY_NOTFOUND )
244 aLbGradients.SelectEntryPos( *pPos );
246 // Farben koennten geloescht worden sein
247 ChangeGradientHdl_Impl( this );
249 *pPageType = PT_GRADIENT;
250 *pPos = LISTBOX_ENTRY_NOTFOUND;
255 // -----------------------------------------------------------------------
257 int SvxGradientTabPage::DeactivatePage( SfxItemSet* _pSet )
259 if( CheckChanges_Impl() == -1L )
260 return KEEP_PAGE;
262 if( _pSet )
263 FillItemSet( *_pSet );
265 return LEAVE_PAGE;
268 // -----------------------------------------------------------------------
270 long SvxGradientTabPage::CheckChanges_Impl()
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 (USHORT) aMtrCenterX.GetValue(),
278 (USHORT) aMtrCenterY.GetValue(),
279 (USHORT) aMtrBorder.GetValue(),
280 (USHORT) aMtrColorFrom.GetValue(),
281 (USHORT) aMtrColorTo.GetValue() );
283 USHORT nPos = aLbGradients.GetSelectEntryPos();
284 if( nPos != LISTBOX_ENTRY_NOTFOUND )
286 XGradient aGradient = pGradientList->GetGradient( nPos )->GetGradient();
287 String aString = aLbGradients.GetSelectEntry();
289 if( !( aTmpGradient == aGradient ) )
291 ResMgr& rMgr = DIALOG_MGR();
292 Image aWarningBoxImage = WarningBox::GetStandardImage();
293 //CHINA001 SvxMessDialog aMessDlg( DLGWIN,
294 //CHINA001 String( ResId( RID_SVXSTR_GRADIENT, rMgr ) ),
295 //CHINA001 String( ResId( RID_SVXSTR_ASK_CHANGE_GRADIENT, rMgr ) ),
296 //CHINA001 &aWarningBoxImage );
297 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
298 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
299 AbstractSvxMessDialog* aMessDlg = pFact->CreateSvxMessDialog( DLGWIN, RID_SVXDLG_MESSBOX,
300 String( ResId( RID_SVXSTR_GRADIENT, rMgr ) ),
301 String( ResId( RID_SVXSTR_ASK_CHANGE_GRADIENT, rMgr ) ),
302 &aWarningBoxImage );
303 DBG_ASSERT(aMessDlg, "Dialogdiet fail!");//CHINA001
304 aMessDlg->SetButtonText( MESS_BTN_1, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1,
305 String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
306 aMessDlg->SetButtonText( MESS_BTN_2, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2,
307 String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
309 short nRet = aMessDlg->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
311 switch( nRet )
313 case RET_BTN_1: // Aendern
315 ClickModifyHdl_Impl( this );
316 aGradient = pGradientList->GetGradient( nPos )->GetGradient();
318 break;
320 case RET_BTN_2: // Hinzufuegen
322 ClickAddHdl_Impl( this );
323 nPos = aLbGradients.GetSelectEntryPos();
324 aGradient = pGradientList->GetGradient( nPos )->GetGradient();
326 break;
328 case RET_CANCEL:
329 // return( -1L ); <-- wuerde die Seite nicht verlassen
330 break;
331 // return( TRUE ); // Abbruch
333 delete aMessDlg; //add by CHINA001
336 nPos = aLbGradients.GetSelectEntryPos();
337 if( nPos != LISTBOX_ENTRY_NOTFOUND )
339 *pPos = nPos;
341 return 0L;
344 // -----------------------------------------------------------------------
346 BOOL SvxGradientTabPage::FillItemSet( SfxItemSet& rSet )
348 if( *pDlgType == 0 && *pPageType == PT_GRADIENT && *pbAreaTP == FALSE )
350 // CheckChanges(); <-- doppelte Abfrage ?
352 XGradient* pXGradient = NULL;
353 String aString;
354 USHORT nPos = aLbGradients.GetSelectEntryPos();
355 if( nPos != LISTBOX_ENTRY_NOTFOUND )
357 pXGradient = new XGradient( pGradientList->GetGradient( nPos )->GetGradient() );
358 aString = aLbGradients.GetSelectEntry();
361 else
362 // Farbverlauf wurde (unbekannt) uebergeben
364 pXGradient = new XGradient( aLbColorFrom.GetSelectEntryColor(),
365 aLbColorTo.GetSelectEntryColor(),
366 (XGradientStyle) aLbGradientType.GetSelectEntryPos(),
367 static_cast<long>(aMtrAngle.GetValue() * 10), // sollte in Resource geaendert werden
368 (USHORT) aMtrCenterX.GetValue(),
369 (USHORT) aMtrCenterY.GetValue(),
370 (USHORT) aMtrBorder.GetValue(),
371 (USHORT) aMtrColorFrom.GetValue(),
372 (USHORT) aMtrColorTo.GetValue() );
374 DBG_ASSERT( pXGradient, "XGradient konnte nicht erzeugt werden" );
375 rSet.Put( XFillStyleItem( XFILL_GRADIENT ) );
376 rSet.Put( XFillGradientItem( aString, *pXGradient ) );
378 delete pXGradient;
380 return TRUE;
383 // -----------------------------------------------------------------------
385 void SvxGradientTabPage::Reset( const SfxItemSet& )
387 // aLbGradients.SelectEntryPos( 0 );
388 ChangeGradientHdl_Impl( this );
390 // Status der Buttons ermitteln
391 if( pGradientList->Count() )
393 aBtnModify.Enable();
394 aBtnDelete.Enable();
395 aBtnSave.Enable();
397 else
399 aBtnModify.Disable();
400 aBtnDelete.Disable();
401 aBtnSave.Disable();
405 // -----------------------------------------------------------------------
407 SfxTabPage* SvxGradientTabPage::Create( Window* pWindow,
408 const SfxItemSet& rOutAttrs )
410 return new SvxGradientTabPage( pWindow, rOutAttrs );
413 //------------------------------------------------------------------------
415 IMPL_LINK( SvxGradientTabPage, ModifiedHdl_Impl, void *, pControl )
417 XGradientStyle eXGS = (XGradientStyle) aLbGradientType.GetSelectEntryPos();
419 XGradient aXGradient( aLbColorFrom.GetSelectEntryColor(),
420 aLbColorTo.GetSelectEntryColor(),
421 eXGS,
422 static_cast<long>(aMtrAngle.GetValue() * 10), // sollte in Resource geaendert werden
423 (USHORT) aMtrCenterX.GetValue(),
424 (USHORT) aMtrCenterY.GetValue(),
425 (USHORT) aMtrBorder.GetValue(),
426 (USHORT) aMtrColorFrom.GetValue(),
427 (USHORT) aMtrColorTo.GetValue() );
429 // Enablen/Disablen von Controls
430 if( pControl == &aLbGradientType || pControl == this )
431 SetControlState_Impl( eXGS );
433 // Anzeigen im XOutDev
434 rXFSet.Put( XFillGradientItem( String(), aXGradient ) );
435 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
437 aCtlPreview.Invalidate();
439 return 0L;
442 //------------------------------------------------------------------------
444 IMPL_LINK( SvxGradientTabPage, ClickAddHdl_Impl, void *, EMPTYARG )
446 ResMgr& rMgr = DIALOG_MGR();
447 String aNewName( ResId( RID_SVXSTR_GRADIENT, rMgr ) );
448 String aDesc( ResId( RID_SVXSTR_DESC_GRADIENT, rMgr ) );
449 String aName;
451 long nCount = pGradientList->Count();
452 long j = 1;
453 BOOL bDifferent = FALSE;
455 while( !bDifferent )
457 aName = aNewName;
458 aName += sal_Unicode(' ');
459 aName += UniString::CreateFromInt32( j++ );
460 bDifferent = TRUE;
462 for( long i = 0; i < nCount && bDifferent; i++ )
463 if( aName == pGradientList->GetGradient( i )->GetName() )
464 bDifferent = FALSE;
467 //CHINA001 SvxNameDialog* pDlg = new SvxNameDialog( DLGWIN, aName, aDesc );
468 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
469 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
470 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc, RID_SVXDLG_NAME );
471 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
472 WarningBox* pWarnBox = NULL;
473 USHORT nError = RID_SVXSTR_WARN_NAME_DUPLICATE;
475 while( pDlg->Execute() == RET_OK )
477 pDlg->GetName( aName );
479 bDifferent = TRUE;
481 for( long i = 0; i < nCount && bDifferent; i++ )
482 if( aName == pGradientList->GetGradient( i )->GetName() )
483 bDifferent = FALSE;
485 if( bDifferent )
487 nError = 0;
488 break;
491 if( !pWarnBox )
493 pWarnBox = new WarningBox( DLGWIN,
494 WinBits( WB_OK_CANCEL ),
495 String( ResId( nError, rMgr ) ) );
496 pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
499 if( pWarnBox->Execute() != RET_OK )
500 break;
502 //Rectangle aDlgRect( pDlg->GetPosPixel(), pDlg->GetSizePixel() );
503 delete pDlg;
504 delete pWarnBox;
506 if( !nError )
508 XGradient aXGradient( aLbColorFrom.GetSelectEntryColor(),
509 aLbColorTo.GetSelectEntryColor(),
510 (XGradientStyle) aLbGradientType.GetSelectEntryPos(),
511 static_cast<long>(aMtrAngle.GetValue() * 10), // sollte in Resource geaendert werden
512 (USHORT) aMtrCenterX.GetValue(),
513 (USHORT) aMtrCenterY.GetValue(),
514 (USHORT) aMtrBorder.GetValue(),
515 (USHORT) aMtrColorFrom.GetValue(),
516 (USHORT) aMtrColorTo.GetValue() );
517 XGradientEntry* pEntry = new XGradientEntry( aXGradient, aName );
519 pGradientList->Insert( pEntry, nCount );
521 aLbGradients.Append( pEntry );
523 aLbGradients.SelectEntryPos( aLbGradients.GetEntryCount() - 1 );
525 #ifdef WNT
526 // hack: #31355# W.P.
527 Rectangle aRect( aLbGradients.GetPosPixel(), aLbGradients.GetSizePixel() );
528 if( TRUE ) { // ??? overlapped with pDlg
529 // and srolling
530 Invalidate( aRect );
531 //aLbGradients.Invalidate();
533 #endif
535 // Flag fuer modifiziert setzen
536 *pnGradientListState |= CT_MODIFIED;
538 ChangeGradientHdl_Impl( this );
541 // Status der Buttons ermitteln
542 if( pGradientList->Count() )
544 aBtnModify.Enable();
545 aBtnDelete.Enable();
546 aBtnSave.Enable();
548 return 0L;
551 //------------------------------------------------------------------------
553 IMPL_LINK( SvxGradientTabPage, ClickModifyHdl_Impl, void *, EMPTYARG )
555 USHORT nPos = aLbGradients.GetSelectEntryPos();
557 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
559 ResMgr& rMgr = DIALOG_MGR();
560 String aNewName( ResId( RID_SVXSTR_GRADIENT, rMgr ) );
561 String aDesc( ResId( RID_SVXSTR_DESC_GRADIENT, rMgr ) );
562 String aName( pGradientList->GetGradient( nPos )->GetName() );
563 String aOldName = aName;
565 //CHINA001 SvxNameDialog* pDlg = new SvxNameDialog( DLGWIN, aName, aDesc );
566 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
567 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
568 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc, RID_SVXDLG_NAME );
569 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
571 long nCount = pGradientList->Count();
572 BOOL bDifferent = FALSE;
573 BOOL bLoop = TRUE;
575 while( bLoop && pDlg->Execute() == RET_OK )
577 pDlg->GetName( aName );
578 bDifferent = TRUE;
580 for( long i = 0; i < nCount && bDifferent; i++ )
582 if( aName == pGradientList->GetGradient( i )->GetName() &&
583 aName != aOldName )
584 bDifferent = FALSE;
587 if( bDifferent )
589 bLoop = FALSE;
590 XGradient aXGradient( aLbColorFrom.GetSelectEntryColor(),
591 aLbColorTo.GetSelectEntryColor(),
592 (XGradientStyle) aLbGradientType.GetSelectEntryPos(),
593 static_cast<long>(aMtrAngle.GetValue() * 10), // sollte in Resource geaendert werden
594 (USHORT) aMtrCenterX.GetValue(),
595 (USHORT) aMtrCenterY.GetValue(),
596 (USHORT) aMtrBorder.GetValue(),
597 (USHORT) aMtrColorFrom.GetValue(),
598 (USHORT) aMtrColorTo.GetValue() );
600 XGradientEntry* pEntry = new XGradientEntry( aXGradient, aName );
602 delete pGradientList->Replace( pEntry, nPos );
604 aLbGradients.Modify( pEntry, nPos );
606 aLbGradients.SelectEntryPos( nPos );
608 // Flag fuer modifiziert setzen
609 *pnGradientListState |= CT_MODIFIED;
611 else
613 WarningBox aBox( DLGWIN, WinBits( WB_OK ),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
614 aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
615 aBox.Execute();
619 delete pDlg;
621 return 0L;
624 //------------------------------------------------------------------------
626 IMPL_LINK( SvxGradientTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG )
628 USHORT nPos = aLbGradients.GetSelectEntryPos();
630 if( nPos != LISTBOX_ENTRY_NOTFOUND )
632 QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ),
633 //! SVX_RES( RID_SVXSTR_DEL_GRADIENT ),
634 String( SVX_RES( RID_SVXSTR_ASK_DEL_GRADIENT ) ) );
636 if ( aQueryBox.Execute() == RET_YES )
638 delete pGradientList->Remove( nPos );
639 aLbGradients.RemoveEntry( nPos );
640 aLbGradients.SelectEntryPos( 0 );
642 aCtlPreview.Invalidate();
644 ChangeGradientHdl_Impl( this );
646 // Flag fuer modifiziert setzen
647 *pnGradientListState |= CT_MODIFIED;
650 // Status der Buttons ermitteln
651 if( !pGradientList->Count() )
653 aBtnModify.Disable();
654 aBtnDelete.Disable();
655 aBtnSave.Disable();
657 return 0L;
660 // -----------------------------------------------------------------------
662 IMPL_LINK( SvxGradientTabPage, ClickLoadHdl_Impl, void *, EMPTYARG )
664 ResMgr& rMgr = DIALOG_MGR();
665 USHORT nReturn = RET_YES;
667 if ( *pnGradientListState & CT_MODIFIED )
669 nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ),
670 String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
672 if ( nReturn == RET_YES )
673 pGradientList->Save();
676 if ( nReturn != RET_CANCEL )
678 ::sfx2::FileDialogHelper aDlg(
679 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
680 0 );
681 String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sog" ) );
682 aDlg.AddFilter( aStrFilterType, aStrFilterType );
683 INetURLObject aFile( SvtPathOptions().GetPalettePath() );
684 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
686 if( aDlg.Execute() == ERRCODE_NONE )
688 EnterWait();
690 INetURLObject aURL( aDlg.GetPath() );
691 INetURLObject aPathURL( aURL );
693 aPathURL.removeSegment();
694 aPathURL.removeFinalSlash();
696 // Liste speichern
697 XGradientList* pGrdList = new XGradientList( aPathURL.GetMainURL( INetURLObject::NO_DECODE ), pXPool );
698 pGrdList->SetName( aURL.getName() );
700 if ( pGrdList->Load() )
702 if ( pGrdList )
704 // Pruefen, ob Tabelle geloescht werden darf:
705 if ( pGradientList !=
706 ( (SvxAreaTabDialog*) DLGWIN )->GetGradientList() )
707 delete pGradientList;
709 pGradientList = pGrdList;
710 ( (SvxAreaTabDialog*) DLGWIN )->
711 SetNewGradientList( pGradientList );
713 aLbGradients.Clear();
714 aLbGradients.Fill( pGradientList );
715 Reset( rOutAttrs );
717 pGradientList->SetName( aURL.getName() );
719 // Ermitteln (evtl. abschneiden) des Namens und in
720 // der GroupBox darstellen
721 String aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
722 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
724 if ( aURL.getBase().getLength() > 18 )
726 aString += String(aURL.getBase()).Copy( 0, 15 );
727 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
729 else
730 aString += String(aURL.getBase());
732 // Flag fuer gewechselt setzen
733 *pnGradientListState |= CT_CHANGED;
734 // Flag fuer modifiziert entfernen
735 *pnGradientListState &= ~CT_MODIFIED;
737 LeaveWait();
739 else
741 LeaveWait();
742 //aIStream.Close();
743 ErrorBox( DLGWIN, WinBits( WB_OK ),
744 String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
749 // Status der Buttons ermitteln
750 if( pGradientList->Count() )
752 aBtnModify.Enable();
753 aBtnDelete.Enable();
754 aBtnSave.Enable();
756 else
758 aBtnModify.Disable();
759 aBtnDelete.Disable();
760 aBtnSave.Disable();
762 return 0L;
765 // -----------------------------------------------------------------------
767 IMPL_LINK( SvxGradientTabPage, ClickSaveHdl_Impl, void *, EMPTYARG )
769 ::sfx2::FileDialogHelper aDlg(
770 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
771 String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sog" ) );
772 aDlg.AddFilter( aStrFilterType, aStrFilterType );
774 INetURLObject aFile( SvtPathOptions().GetPalettePath() );
775 DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
777 if( pGradientList->GetName().Len() )
779 aFile.Append( pGradientList->GetName() );
781 if( !aFile.getExtension().getLength() )
782 aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "sog" ) ) );
785 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
786 if ( aDlg.Execute() == ERRCODE_NONE )
788 INetURLObject aURL( aDlg.GetPath() );
789 INetURLObject aPathURL( aURL );
791 aPathURL.removeSegment();
792 aPathURL.removeFinalSlash();
794 pGradientList->SetName( aURL.getName() );
795 pGradientList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
797 if( pGradientList->Save() )
799 // Ermitteln (evtl. abschneiden) des Namens und in
800 // der GroupBox darstellen
801 String aString( SVX_RES( RID_SVXSTR_TABLE ) );
802 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
804 if ( aURL.getBase().getLength() > 18 )
806 aString += String(aURL.getBase()).Copy( 0, 15 );
807 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
809 else
810 aString += String(aURL.getBase());
812 // Flag fuer gespeichert setzen
813 *pnGradientListState |= CT_SAVED;
814 // Flag fuer modifiziert entfernen
815 *pnGradientListState &= ~CT_MODIFIED;
817 else
819 ErrorBox( DLGWIN, WinBits( WB_OK ),
820 String( SVX_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
824 return 0L;
827 //------------------------------------------------------------------------
829 IMPL_LINK( SvxGradientTabPage, ChangeGradientHdl_Impl, void *, EMPTYARG )
831 XGradient* pGradient = NULL;
832 int nPos = aLbGradients.GetSelectEntryPos();
834 if( nPos != LISTBOX_ENTRY_NOTFOUND )
835 pGradient = new XGradient( ( (XGradientEntry*) pGradientList->GetGradient( nPos ) )->GetGradient() );
836 else
838 const SfxPoolItem* pPoolItem = NULL;
839 if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), TRUE, &pPoolItem ) )
841 if( ( XFILL_GRADIENT == (XFillStyle) ( ( const XFillStyleItem* ) pPoolItem )->GetValue() ) &&
842 ( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLGRADIENT ), TRUE, &pPoolItem ) ) )
844 pGradient = new XGradient( ( ( const XFillGradientItem* ) pPoolItem )->GetGradientValue() );
847 if( !pGradient )
849 aLbGradients.SelectEntryPos( 0 );
850 nPos = aLbGradients.GetSelectEntryPos();
851 if( nPos != LISTBOX_ENTRY_NOTFOUND )
852 pGradient = new XGradient( ( (XGradientEntry*) pGradientList->GetGradient( nPos ) )->GetGradient() );
856 if( pGradient )
858 XGradientStyle eXGS = pGradient->GetGradientStyle();
860 aLbGradientType.SelectEntryPos(
861 sal::static_int_cast< USHORT >( eXGS ) );
862 // Wenn der EIntrag nicht in der Listbox ist, werden die Farben
863 // temporaer hinzugenommen
864 aLbColorFrom.SetNoSelection();
865 aLbColorFrom.SelectEntry( pGradient->GetStartColor() );
867 if ( aLbColorFrom.GetSelectEntryCount() == 0 )
869 aLbColorFrom.InsertEntry( pGradient->GetStartColor(),
870 String() );
871 aLbColorFrom.SelectEntry( pGradient->GetStartColor() );
873 aLbColorTo.SetNoSelection();
874 aLbColorTo.SelectEntry( pGradient->GetEndColor() );
876 if ( aLbColorTo.GetSelectEntryCount() == 0 )
878 aLbColorTo.InsertEntry( pGradient->GetEndColor(), String() );
879 aLbColorTo.SelectEntry( pGradient->GetEndColor() );
882 aMtrAngle.SetValue( pGradient->GetAngle() / 10 ); // sollte in Resource geaendert werden
883 aMtrBorder.SetValue( pGradient->GetBorder() );
884 aMtrCenterX.SetValue( pGradient->GetXOffset() );
885 aMtrCenterY.SetValue( pGradient->GetYOffset() );
886 aMtrColorFrom.SetValue( pGradient->GetStartIntens() );
887 aMtrColorTo.SetValue( pGradient->GetEndIntens() );
889 // Controls Disablen/Enablen
890 SetControlState_Impl( eXGS );
892 // ItemSet fuellen und an aCtlPreview weiterleiten
893 rXFSet.Put( XFillGradientItem( String(), *pGradient ) );
894 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
896 aCtlPreview.Invalidate();
897 delete pGradient;
899 return 0L;
902 //------------------------------------------------------------------------
904 void SvxGradientTabPage::SetControlState_Impl( XGradientStyle eXGS )
906 switch( eXGS )
908 case XGRAD_LINEAR:
909 case XGRAD_AXIAL:
910 aFtCenterX.Disable();
911 aMtrCenterX.Disable();
912 aFtCenterY.Disable();
913 aMtrCenterY.Disable();
914 aFtAngle.Enable();
915 aMtrAngle.Enable();
916 break;
918 case XGRAD_RADIAL:
919 aFtCenterX.Enable();
920 aMtrCenterX.Enable();
921 aFtCenterY.Enable();
922 aMtrCenterY.Enable();
923 aFtAngle.Disable();
924 aMtrAngle.Disable();
925 break;
927 case XGRAD_ELLIPTICAL:
928 aFtCenterX.Enable();
929 aMtrCenterX.Enable();
930 aFtCenterY.Enable();
931 aMtrCenterY.Enable();
932 aFtAngle.Enable();
933 aMtrAngle.Enable();
934 break;
936 case XGRAD_SQUARE:
937 case XGRAD_RECT:
938 aFtCenterX.Enable();
939 aMtrCenterX.Enable();
940 aFtCenterY.Enable();
941 aMtrCenterY.Enable();
942 aFtAngle.Enable();
943 aMtrAngle.Enable();
944 break;