1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
31 // include ---------------------------------------------------------------
32 #include <vcl/wrkwin.hxx>
33 #include <tools/shl.hxx>
34 #include <tools/urlobj.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <unotools/pathoptions.hxx>
37 #include <sfx2/app.hxx>
38 #include <sfx2/filedlghelper.hxx>
39 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
41 #define _SVX_TPGRADNT_CXX
45 #include "svx/xattr.hxx"
46 #include <svx/xtable.hxx>
47 #include <svx/xpool.hxx>
48 #include "svx/drawitem.hxx"
49 #include "cuitabarea.hxx"
50 #include "tabarea.hrc"
51 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx"
52 //#include "dlgname.hrc"
53 #include <svx/svxdlg.hxx> //CHINA001
54 #include <dialmgr.hxx>
55 #include <svx/dialmgr.hxx>
56 #include <svx/dialogs.hrc>
57 #include "paragrph.hrc"
59 #define DLGWIN this->GetParent()->GetParent()
61 #define BITMAP_WIDTH 32
62 #define BITMAP_HEIGHT 12
64 /*************************************************************************
66 |* Dialog zum Aendern und Definieren der Farbverlaeufe
68 \************************************************************************/
70 SvxGradientTabPage::SvxGradientTabPage
73 const SfxItemSet
& rInAttrs
75 SfxTabPage ( pParent
, CUI_RES( RID_SVXPAGE_GRADIENT
), rInAttrs
),
77 aFlProp ( this, CUI_RES( FL_PROP
) ),
78 aFtType ( this, CUI_RES( FT_TYPE
) ),
79 aLbGradientType ( this, CUI_RES( LB_GRADIENT_TYPES
) ),
80 aFtCenterX ( this, CUI_RES( FT_CENTER_X
) ),
81 aMtrCenterX ( this, CUI_RES( MTR_CENTER_X
) ),
82 aFtCenterY ( this, CUI_RES( FT_CENTER_Y
) ),
83 aMtrCenterY ( this, CUI_RES( MTR_CENTER_Y
) ),
84 aFtAngle ( this, CUI_RES( FT_ANGLE
) ),
85 aMtrAngle ( this, CUI_RES( MTR_ANGLE
) ),
86 aFtBorder ( this, CUI_RES( FT_BORDER
) ),
87 aMtrBorder ( this, CUI_RES( MTR_BORDER
) ),
88 aFtColorFrom ( this, CUI_RES( FT_COLOR_FROM
) ),
89 aLbColorFrom ( this, CUI_RES( LB_COLOR_FROM
) ),
90 aMtrColorFrom ( this, CUI_RES( MTR_COLOR_FROM
) ),
91 aFtColorTo ( this, CUI_RES( FT_COLOR_TO
) ),
92 aLbColorTo ( this, CUI_RES( LB_COLOR_TO
) ),
93 aMtrColorTo ( this, CUI_RES( MTR_COLOR_TO
) ),
94 aLbGradients ( this, CUI_RES( LB_GRADIENTS
) ),
95 aCtlPreview ( this, CUI_RES( CTL_PREVIEW
) ),
96 aBtnAdd ( this, CUI_RES( BTN_ADD
) ),
97 aBtnModify ( this, CUI_RES( BTN_MODIFY
) ),
98 aBtnDelete ( this, CUI_RES( BTN_DELETE
) ),
99 aBtnLoad ( this, CUI_RES( BTN_LOAD
) ),
100 aBtnSave ( this, CUI_RES( BTN_SAVE
) ),
102 rOutAttrs ( rInAttrs
),
105 pGradientList( NULL
),
107 pXPool ( (XOutdevItemPool
*) rInAttrs
.GetPool() ),
108 aXFStyleItem ( XFILL_GRADIENT
),
109 aXGradientItem ( String(), XGradient( COL_BLACK
, COL_WHITE
) ),
110 aXFillAttr ( pXPool
),
111 rXFSet ( aXFillAttr
.GetItemSet() )
113 aBtnLoad
.SetModeImage( Image( CUI_RES( RID_SVXIMG_LOAD_H
) ), BMP_COLOR_HIGHCONTRAST
);
114 aBtnSave
.SetModeImage( Image( CUI_RES( RID_SVXIMG_SAVE_H
) ), BMP_COLOR_HIGHCONTRAST
);
118 aCtlPreview
.SetAccessibleName(String(CUI_RES(STR_EXAMPLE
)));
119 aLbGradients
.SetAccessibleName( GetText());
122 // diese Page braucht ExchangeSupport
123 SetExchangeSupport();
125 // Solange NICHT vom Item unterstuetzt
127 //aMtrColorTo.Disable();
128 aMtrColorTo
.SetValue( 100 );
129 //aMtrColorFrom.Disable();
130 aMtrColorFrom
.SetValue( 100 );
132 // Setzen des Output-Devices
133 rXFSet
.Put( aXFStyleItem
);
134 rXFSet
.Put( aXGradientItem
);
135 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
137 // Handler ueberladen
138 aLbGradients
.SetSelectHdl(
139 LINK( this, SvxGradientTabPage
, ChangeGradientHdl_Impl
) );
140 aBtnAdd
.SetClickHdl( LINK( this, SvxGradientTabPage
, ClickAddHdl_Impl
) );
141 aBtnModify
.SetClickHdl(
142 LINK( this, SvxGradientTabPage
, ClickModifyHdl_Impl
) );
143 aBtnDelete
.SetClickHdl(
144 LINK( this, SvxGradientTabPage
, ClickDeleteHdl_Impl
) );
146 Link aLink
= LINK( this, SvxGradientTabPage
, ModifiedHdl_Impl
);
147 aLbGradientType
.SetSelectHdl( aLink
);
148 aMtrCenterX
.SetModifyHdl( aLink
);
149 aMtrCenterY
.SetModifyHdl( aLink
);
150 aMtrAngle
.SetModifyHdl( aLink
);
151 aMtrBorder
.SetModifyHdl( aLink
);
152 aMtrColorFrom
.SetModifyHdl( aLink
);
153 aLbColorFrom
.SetSelectHdl( aLink
);
154 aMtrColorTo
.SetModifyHdl( aLink
);
155 aLbColorTo
.SetSelectHdl( aLink
);
157 aBtnLoad
.SetClickHdl(
158 LINK( this, SvxGradientTabPage
, ClickLoadHdl_Impl
) );
159 aBtnSave
.SetClickHdl(
160 LINK( this, SvxGradientTabPage
, ClickSaveHdl_Impl
) );
162 aBtnAdd
.SetAccessibleRelationMemberOf( &aFlProp
);
163 aBtnModify
.SetAccessibleRelationMemberOf( &aFlProp
);
164 aBtnDelete
.SetAccessibleRelationMemberOf( &aFlProp
);
165 aLbGradients
.SetAccessibleRelationLabeledBy(&aLbGradients
);
167 // #i76307# always paint the preview in LTR, because this is what the document does
168 aCtlPreview
.EnableRTL( sal_False
);
171 // -----------------------------------------------------------------------
173 void SvxGradientTabPage::Construct()
176 aLbColorFrom
.Fill( pColorTab
);
177 aLbColorTo
.CopyEntries( aLbColorFrom
);
179 // Farbverlauftabelle
180 aLbGradients
.Fill( pGradientList
);
183 // -----------------------------------------------------------------------
185 void SvxGradientTabPage::ActivatePage( const SfxItemSet
& )
190 if( *pDlgType
== 0 ) // Flaechen-Dialog
192 *pbAreaTP
= sal_False
;
197 if( *pnColorTableState
& CT_CHANGED
||
198 *pnColorTableState
& CT_MODIFIED
)
200 if( *pnColorTableState
& CT_CHANGED
)
201 pColorTab
= ( (SvxAreaTabDialog
*) DLGWIN
)->GetNewColorTable();
204 nPos
= aLbColorFrom
.GetSelectEntryPos();
205 aLbColorFrom
.Clear();
206 aLbColorFrom
.Fill( pColorTab
);
207 nCount
= aLbColorFrom
.GetEntryCount();
209 ; // Dieser Fall sollte nicht auftreten
210 else if( nCount
<= nPos
)
211 aLbColorFrom
.SelectEntryPos( 0 );
213 aLbColorFrom
.SelectEntryPos( nPos
);
216 nPos
= aLbColorTo
.GetSelectEntryPos();
218 aLbColorTo
.CopyEntries( aLbColorFrom
);
219 nCount
= aLbColorTo
.GetEntryCount();
221 ; // Dieser Fall sollte nicht auftreten
222 else if( nCount
<= nPos
)
223 aLbColorTo
.SelectEntryPos( 0 );
225 aLbColorTo
.SelectEntryPos( nPos
);
227 ModifiedHdl_Impl( this );
230 // Ermitteln (evtl. abschneiden) des Namens und in
231 // der GroupBox darstellen
232 String
aString( CUI_RES( RID_SVXSTR_TABLE
) ); aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
233 INetURLObject
aURL( pGradientList
->GetPath() );
235 aURL
.Append( pGradientList
->GetName() );
236 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
238 if ( aURL
.getBase().getLength() > 18 )
240 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
241 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
244 aString
+= String(aURL
.getBase());
246 if ( *pPageType
== PT_GRADIENT
&& *pPos
!= LISTBOX_ENTRY_NOTFOUND
)
248 aLbGradients
.SelectEntryPos( *pPos
);
250 // Farben koennten geloescht worden sein
251 ChangeGradientHdl_Impl( this );
253 *pPageType
= PT_GRADIENT
;
254 *pPos
= LISTBOX_ENTRY_NOTFOUND
;
259 // -----------------------------------------------------------------------
261 int SvxGradientTabPage::DeactivatePage( SfxItemSet
* _pSet
)
263 if( CheckChanges_Impl() == -1L )
267 FillItemSet( *_pSet
);
272 // -----------------------------------------------------------------------
274 long SvxGradientTabPage::CheckChanges_Impl()
276 // wird hier benutzt, um Aenderungen NICHT zu verlieren
277 XGradient
aTmpGradient( aLbColorFrom
.GetSelectEntryColor(),
278 aLbColorTo
.GetSelectEntryColor(),
279 (XGradientStyle
) aLbGradientType
.GetSelectEntryPos(),
280 static_cast<long>(aMtrAngle
.GetValue() * 10), // sollte in Resource geaendert werden
281 (sal_uInt16
) aMtrCenterX
.GetValue(),
282 (sal_uInt16
) aMtrCenterY
.GetValue(),
283 (sal_uInt16
) aMtrBorder
.GetValue(),
284 (sal_uInt16
) aMtrColorFrom
.GetValue(),
285 (sal_uInt16
) aMtrColorTo
.GetValue() );
287 sal_uInt16 nPos
= aLbGradients
.GetSelectEntryPos();
288 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
290 XGradient aGradient
= pGradientList
->GetGradient( nPos
)->GetGradient();
291 String aString
= aLbGradients
.GetSelectEntry();
293 if( !( aTmpGradient
== aGradient
) )
295 ResMgr
& rMgr
= CUI_MGR();
296 Image aWarningBoxImage
= WarningBox::GetStandardImage();
297 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
298 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
299 AbstractSvxMessDialog
* aMessDlg
= pFact
->CreateSvxMessDialog( DLGWIN
, RID_SVXDLG_MESSBOX
,
300 SVX_RESSTR( RID_SVXSTR_GRADIENT
),
301 CUI_RESSTR( RID_SVXSTR_ASK_CHANGE_GRADIENT
),
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();
313 case RET_BTN_1
: // Aendern
315 ClickModifyHdl_Impl( this );
316 aGradient
= pGradientList
->GetGradient( nPos
)->GetGradient();
320 case RET_BTN_2
: // Hinzufuegen
322 ClickAddHdl_Impl( this );
323 nPos
= aLbGradients
.GetSelectEntryPos();
324 aGradient
= pGradientList
->GetGradient( nPos
)->GetGradient();
329 // return( -1L ); <-- wuerde die Seite nicht verlassen
331 // return( sal_True ); // Abbruch
333 delete aMessDlg
; //add by CHINA001
336 nPos
= aLbGradients
.GetSelectEntryPos();
337 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
344 // -----------------------------------------------------------------------
346 sal_Bool
SvxGradientTabPage::FillItemSet( SfxItemSet
& rSet
)
348 if( *pDlgType
== 0 && *pPageType
== PT_GRADIENT
&& *pbAreaTP
== sal_False
)
350 // CheckChanges(); <-- doppelte Abfrage ?
352 XGradient
* pXGradient
= NULL
;
354 sal_uInt16 nPos
= aLbGradients
.GetSelectEntryPos();
355 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
357 pXGradient
= new XGradient( pGradientList
->GetGradient( nPos
)->GetGradient() );
358 aString
= aLbGradients
.GetSelectEntry();
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 (sal_uInt16
) aMtrCenterX
.GetValue(),
369 (sal_uInt16
) aMtrCenterY
.GetValue(),
370 (sal_uInt16
) aMtrBorder
.GetValue(),
371 (sal_uInt16
) aMtrColorFrom
.GetValue(),
372 (sal_uInt16
) aMtrColorTo
.GetValue() );
374 DBG_ASSERT( pXGradient
, "XGradient konnte nicht erzeugt werden" );
375 rSet
.Put( XFillStyleItem( XFILL_GRADIENT
) );
376 rSet
.Put( XFillGradientItem( aString
, *pXGradient
) );
383 // -----------------------------------------------------------------------
385 void SvxGradientTabPage::Reset( const SfxItemSet
& )
387 // aLbGradients.SelectEntryPos( 0 );
388 ChangeGradientHdl_Impl( this );
390 // Status der Buttons ermitteln
391 if( pGradientList
->Count() )
399 aBtnModify
.Disable();
400 aBtnDelete
.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(),
422 static_cast<long>(aMtrAngle
.GetValue() * 10), // sollte in Resource geaendert werden
423 (sal_uInt16
) aMtrCenterX
.GetValue(),
424 (sal_uInt16
) aMtrCenterY
.GetValue(),
425 (sal_uInt16
) aMtrBorder
.GetValue(),
426 (sal_uInt16
) aMtrColorFrom
.GetValue(),
427 (sal_uInt16
) 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();
442 //------------------------------------------------------------------------
444 IMPL_LINK( SvxGradientTabPage
, ClickAddHdl_Impl
, void *, EMPTYARG
)
446 ResMgr
& rMgr
= CUI_MGR();
447 String
aNewName( SVX_RES( RID_SVXSTR_GRADIENT
) );
448 String
aDesc( CUI_RES( RID_SVXSTR_DESC_GRADIENT
) );
451 long nCount
= pGradientList
->Count();
453 sal_Bool bDifferent
= sal_False
;
458 aName
+= sal_Unicode(' ');
459 aName
+= UniString::CreateFromInt32( j
++ );
460 bDifferent
= sal_True
;
462 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
463 if( aName
== pGradientList
->GetGradient( i
)->GetName() )
464 bDifferent
= sal_False
;
467 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
468 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
469 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( DLGWIN
, aName
, aDesc
);
470 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
471 WarningBox
* pWarnBox
= NULL
;
472 sal_uInt16 nError
= RID_SVXSTR_WARN_NAME_DUPLICATE
;
474 while( pDlg
->Execute() == RET_OK
)
476 pDlg
->GetName( aName
);
478 bDifferent
= sal_True
;
480 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
481 if( aName
== pGradientList
->GetGradient( i
)->GetName() )
482 bDifferent
= sal_False
;
492 pWarnBox
= new WarningBox( DLGWIN
,
493 WinBits( WB_OK_CANCEL
),
494 String( ResId( nError
, rMgr
) ) );
495 pWarnBox
->SetHelpId( HID_WARN_NAME_DUPLICATE
);
498 if( pWarnBox
->Execute() != RET_OK
)
501 //Rectangle aDlgRect( pDlg->GetPosPixel(), pDlg->GetSizePixel() );
507 XGradient
aXGradient( aLbColorFrom
.GetSelectEntryColor(),
508 aLbColorTo
.GetSelectEntryColor(),
509 (XGradientStyle
) aLbGradientType
.GetSelectEntryPos(),
510 static_cast<long>(aMtrAngle
.GetValue() * 10), // sollte in Resource geaendert werden
511 (sal_uInt16
) aMtrCenterX
.GetValue(),
512 (sal_uInt16
) aMtrCenterY
.GetValue(),
513 (sal_uInt16
) aMtrBorder
.GetValue(),
514 (sal_uInt16
) aMtrColorFrom
.GetValue(),
515 (sal_uInt16
) aMtrColorTo
.GetValue() );
516 XGradientEntry
* pEntry
= new XGradientEntry( aXGradient
, aName
);
518 pGradientList
->Insert( pEntry
, nCount
);
520 aLbGradients
.Append( pEntry
);
522 aLbGradients
.SelectEntryPos( aLbGradients
.GetEntryCount() - 1 );
525 // hack: #31355# W.P.
526 Rectangle
aRect( aLbGradients
.GetPosPixel(), aLbGradients
.GetSizePixel() );
527 if( sal_True
) { // ??? overlapped with pDlg
530 //aLbGradients.Invalidate();
534 // Flag fuer modifiziert setzen
535 *pnGradientListState
|= CT_MODIFIED
;
537 ChangeGradientHdl_Impl( this );
540 // Status der Buttons ermitteln
541 if( pGradientList
->Count() )
550 //------------------------------------------------------------------------
552 IMPL_LINK( SvxGradientTabPage
, ClickModifyHdl_Impl
, void *, EMPTYARG
)
554 sal_uInt16 nPos
= aLbGradients
.GetSelectEntryPos();
556 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
558 ResMgr
& rMgr
= CUI_MGR();
559 String
aNewName( SVX_RES( RID_SVXSTR_GRADIENT
) );
560 String
aDesc( CUI_RES( RID_SVXSTR_DESC_GRADIENT
) );
561 String
aName( pGradientList
->GetGradient( nPos
)->GetName() );
562 String aOldName
= aName
;
564 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
565 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
566 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( DLGWIN
, aName
, aDesc
);
567 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
569 long nCount
= pGradientList
->Count();
570 sal_Bool bDifferent
= sal_False
;
571 sal_Bool bLoop
= sal_True
;
573 while( bLoop
&& pDlg
->Execute() == RET_OK
)
575 pDlg
->GetName( aName
);
576 bDifferent
= sal_True
;
578 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
580 if( aName
== pGradientList
->GetGradient( i
)->GetName() &&
582 bDifferent
= sal_False
;
588 XGradient
aXGradient( aLbColorFrom
.GetSelectEntryColor(),
589 aLbColorTo
.GetSelectEntryColor(),
590 (XGradientStyle
) aLbGradientType
.GetSelectEntryPos(),
591 static_cast<long>(aMtrAngle
.GetValue() * 10), // sollte in Resource geaendert werden
592 (sal_uInt16
) aMtrCenterX
.GetValue(),
593 (sal_uInt16
) aMtrCenterY
.GetValue(),
594 (sal_uInt16
) aMtrBorder
.GetValue(),
595 (sal_uInt16
) aMtrColorFrom
.GetValue(),
596 (sal_uInt16
) aMtrColorTo
.GetValue() );
598 XGradientEntry
* pEntry
= new XGradientEntry( aXGradient
, aName
);
600 delete pGradientList
->Replace( pEntry
, nPos
);
602 aLbGradients
.Modify( pEntry
, nPos
);
604 aLbGradients
.SelectEntryPos( nPos
);
606 // Flag fuer modifiziert setzen
607 *pnGradientListState
|= CT_MODIFIED
;
611 WarningBox
aBox( DLGWIN
, WinBits( WB_OK
),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE
, rMgr
) ) );
612 aBox
.SetHelpId( HID_WARN_NAME_DUPLICATE
);
622 //------------------------------------------------------------------------
624 IMPL_LINK( SvxGradientTabPage
, ClickDeleteHdl_Impl
, void *, EMPTYARG
)
626 sal_uInt16 nPos
= aLbGradients
.GetSelectEntryPos();
628 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
630 QueryBox
aQueryBox( DLGWIN
, WinBits( WB_YES_NO
| WB_DEF_NO
),
631 String( CUI_RES( RID_SVXSTR_ASK_DEL_GRADIENT
) ) );
633 if ( aQueryBox
.Execute() == RET_YES
)
635 delete pGradientList
->Remove( nPos
);
636 aLbGradients
.RemoveEntry( nPos
);
637 aLbGradients
.SelectEntryPos( 0 );
639 aCtlPreview
.Invalidate();
641 ChangeGradientHdl_Impl( this );
643 // Flag fuer modifiziert setzen
644 *pnGradientListState
|= CT_MODIFIED
;
647 // Status der Buttons ermitteln
648 if( !pGradientList
->Count() )
650 aBtnModify
.Disable();
651 aBtnDelete
.Disable();
657 // -----------------------------------------------------------------------
659 IMPL_LINK( SvxGradientTabPage
, ClickLoadHdl_Impl
, void *, EMPTYARG
)
661 ResMgr
& rMgr
= CUI_MGR();
662 sal_uInt16 nReturn
= RET_YES
;
664 if ( *pnGradientListState
& CT_MODIFIED
)
666 nReturn
= WarningBox( DLGWIN
, WinBits( WB_YES_NO_CANCEL
),
667 String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE
, rMgr
) ) ).Execute();
669 if ( nReturn
== RET_YES
)
670 pGradientList
->Save();
673 if ( nReturn
!= RET_CANCEL
)
675 ::sfx2::FileDialogHelper
aDlg(
676 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
678 String
aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sog" ) );
679 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
680 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
681 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
683 if( aDlg
.Execute() == ERRCODE_NONE
)
687 INetURLObject
aURL( aDlg
.GetPath() );
688 INetURLObject
aPathURL( aURL
);
690 aPathURL
.removeSegment();
691 aPathURL
.removeFinalSlash();
694 XGradientList
* pGrdList
= new XGradientList( aPathURL
.GetMainURL( INetURLObject::NO_DECODE
), pXPool
);
695 pGrdList
->SetName( aURL
.getName() );
697 if ( pGrdList
->Load() )
701 // Pruefen, ob Tabelle geloescht werden darf:
702 if ( pGradientList
!=
703 ( (SvxAreaTabDialog
*) DLGWIN
)->GetGradientList() )
704 delete pGradientList
;
706 pGradientList
= pGrdList
;
707 ( (SvxAreaTabDialog
*) DLGWIN
)->
708 SetNewGradientList( pGradientList
);
710 aLbGradients
.Clear();
711 aLbGradients
.Fill( pGradientList
);
714 pGradientList
->SetName( aURL
.getName() );
716 // Ermitteln (evtl. abschneiden) des Namens und in
717 // der GroupBox darstellen
718 String
aString( ResId( RID_SVXSTR_TABLE
, rMgr
) );
719 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
721 if ( aURL
.getBase().getLength() > 18 )
723 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
724 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
727 aString
+= String(aURL
.getBase());
729 // Flag fuer gewechselt setzen
730 *pnGradientListState
|= CT_CHANGED
;
731 // Flag fuer modifiziert entfernen
732 *pnGradientListState
&= ~CT_MODIFIED
;
740 ErrorBox( DLGWIN
, WinBits( WB_OK
),
741 String( ResId( RID_SVXSTR_READ_DATA_ERROR
, rMgr
) ) ).Execute();
746 // Status der Buttons ermitteln
747 if( pGradientList
->Count() )
755 aBtnModify
.Disable();
756 aBtnDelete
.Disable();
762 // -----------------------------------------------------------------------
764 IMPL_LINK( SvxGradientTabPage
, ClickSaveHdl_Impl
, void *, EMPTYARG
)
766 ::sfx2::FileDialogHelper
aDlg(
767 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE
, 0 );
768 String
aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sog" ) );
769 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
771 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
772 DBG_ASSERT( aFile
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
774 if( pGradientList
->GetName().Len() )
776 aFile
.Append( pGradientList
->GetName() );
778 if( !aFile
.getExtension().getLength() )
779 aFile
.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "sog" ) ) );
782 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
783 if ( aDlg
.Execute() == ERRCODE_NONE
)
785 INetURLObject
aURL( aDlg
.GetPath() );
786 INetURLObject
aPathURL( aURL
);
788 aPathURL
.removeSegment();
789 aPathURL
.removeFinalSlash();
791 pGradientList
->SetName( aURL
.getName() );
792 pGradientList
->SetPath( aPathURL
.GetMainURL( INetURLObject::NO_DECODE
) );
794 if( pGradientList
->Save() )
796 // Ermitteln (evtl. abschneiden) des Namens und in
797 // der GroupBox darstellen
798 String
aString( CUI_RES( RID_SVXSTR_TABLE
) );
799 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
801 if ( aURL
.getBase().getLength() > 18 )
803 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
804 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
807 aString
+= String(aURL
.getBase());
809 // Flag fuer gespeichert setzen
810 *pnGradientListState
|= CT_SAVED
;
811 // Flag fuer modifiziert entfernen
812 *pnGradientListState
&= ~CT_MODIFIED
;
816 ErrorBox( DLGWIN
, WinBits( WB_OK
),
817 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR
) ) ).Execute();
824 //------------------------------------------------------------------------
826 IMPL_LINK( SvxGradientTabPage
, ChangeGradientHdl_Impl
, void *, EMPTYARG
)
828 XGradient
* pGradient
= NULL
;
829 int nPos
= aLbGradients
.GetSelectEntryPos();
831 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
832 pGradient
= new XGradient( ( (XGradientEntry
*) pGradientList
->GetGradient( nPos
) )->GetGradient() );
835 const SfxPoolItem
* pPoolItem
= NULL
;
836 if( SFX_ITEM_SET
== rOutAttrs
.GetItemState( GetWhich( XATTR_FILLSTYLE
), sal_True
, &pPoolItem
) )
838 if( ( XFILL_GRADIENT
== (XFillStyle
) ( ( const XFillStyleItem
* ) pPoolItem
)->GetValue() ) &&
839 ( SFX_ITEM_SET
== rOutAttrs
.GetItemState( GetWhich( XATTR_FILLGRADIENT
), sal_True
, &pPoolItem
) ) )
841 pGradient
= new XGradient( ( ( const XFillGradientItem
* ) pPoolItem
)->GetGradientValue() );
846 aLbGradients
.SelectEntryPos( 0 );
847 nPos
= aLbGradients
.GetSelectEntryPos();
848 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
849 pGradient
= new XGradient( ( (XGradientEntry
*) pGradientList
->GetGradient( nPos
) )->GetGradient() );
855 XGradientStyle eXGS
= pGradient
->GetGradientStyle();
857 aLbGradientType
.SelectEntryPos(
858 sal::static_int_cast
< sal_uInt16
>( eXGS
) );
859 // Wenn der EIntrag nicht in der Listbox ist, werden die Farben
860 // temporaer hinzugenommen
861 aLbColorFrom
.SetNoSelection();
862 aLbColorFrom
.SelectEntry( pGradient
->GetStartColor() );
864 if ( aLbColorFrom
.GetSelectEntryCount() == 0 )
866 aLbColorFrom
.InsertEntry( pGradient
->GetStartColor(),
868 aLbColorFrom
.SelectEntry( pGradient
->GetStartColor() );
870 aLbColorTo
.SetNoSelection();
871 aLbColorTo
.SelectEntry( pGradient
->GetEndColor() );
873 if ( aLbColorTo
.GetSelectEntryCount() == 0 )
875 aLbColorTo
.InsertEntry( pGradient
->GetEndColor(), String() );
876 aLbColorTo
.SelectEntry( pGradient
->GetEndColor() );
879 aMtrAngle
.SetValue( pGradient
->GetAngle() / 10 ); // sollte in Resource geaendert werden
880 aMtrBorder
.SetValue( pGradient
->GetBorder() );
881 aMtrCenterX
.SetValue( pGradient
->GetXOffset() );
882 aMtrCenterY
.SetValue( pGradient
->GetYOffset() );
883 aMtrColorFrom
.SetValue( pGradient
->GetStartIntens() );
884 aMtrColorTo
.SetValue( pGradient
->GetEndIntens() );
886 // Controls Disablen/Enablen
887 SetControlState_Impl( eXGS
);
889 // ItemSet fuellen und an aCtlPreview weiterleiten
890 rXFSet
.Put( XFillGradientItem( String(), *pGradient
) );
891 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
893 aCtlPreview
.Invalidate();
899 //------------------------------------------------------------------------
901 void SvxGradientTabPage::SetControlState_Impl( XGradientStyle eXGS
)
907 aFtCenterX
.Disable();
908 aMtrCenterX
.Disable();
909 aFtCenterY
.Disable();
910 aMtrCenterY
.Disable();
917 aMtrCenterX
.Enable();
919 aMtrCenterY
.Enable();
924 case XGRAD_ELLIPTICAL
:
926 aMtrCenterX
.Enable();
928 aMtrCenterY
.Enable();
936 aMtrCenterX
.Enable();
938 aMtrCenterY
.Enable();