update credits
[LibreOffice.git] / cui / source / tabpages / tpgradnt.cxx
bloba5506b2fb4a42ead91c70a8f07cc97856cddf78a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/wrkwin.hxx>
21 #include <tools/shl.hxx>
22 #include <tools/urlobj.hxx>
23 #include <vcl/msgbox.hxx>
24 #include <unotools/pathoptions.hxx>
25 #include <sfx2/app.hxx>
26 #include <sfx2/filedlghelper.hxx>
27 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
29 #include <cuires.hrc>
30 #include "helpid.hrc"
31 #include "svx/xattr.hxx"
32 #include <svx/xtable.hxx>
33 #include <svx/xpool.hxx>
34 #include "svx/drawitem.hxx"
35 #include "cuitabarea.hxx"
36 #include "tabarea.hrc"
37 #include "defdlgname.hxx"
38 #include "dlgname.hxx"
39 #include <svx/svxdlg.hxx>
40 #include <dialmgr.hxx>
41 #include <svx/dialmgr.hxx>
42 #include <svx/dialogs.hrc>
43 #include "paragrph.hrc"
45 SvxGradientTabPage::SvxGradientTabPage
47 Window* pParent,
48 const SfxItemSet& rInAttrs
49 ) :
50 SfxTabPage ( pParent, "GradientPage", "cui/ui/gradientpage.ui", rInAttrs ),
52 rOutAttrs ( rInAttrs ),
54 pnGradientListState ( 0 ),
55 pnColorListState ( 0 ),
56 pPageType ( 0 ),
57 pDlgType ( 0 ),
58 pPos ( 0 ),
59 pbAreaTP ( 0 ),
61 pXPool ( (XOutdevItemPool*) rInAttrs.GetPool() ),
62 aXFStyleItem ( XFILL_GRADIENT ),
63 aXGradientItem ( String(), XGradient( COL_BLACK, COL_WHITE ) ),
64 aXFillAttr ( pXPool ),
65 rXFSet ( aXFillAttr.GetItemSet() )
67 get(m_pLbGradientType, "gradienttypelb");
68 get(m_pFtCenterX, "centerxft");
69 get(m_pMtrCenterX, "centerxmtr");
70 get(m_pFtCenterY, "centeryft");
71 get(m_pMtrCenterY, "centerymtr");
72 get(m_pFtAngle, "angleft");
73 get(m_pMtrAngle, "anglemtr");
74 m_pMtrAngle->SetUnit(FUNIT_CUSTOM);
75 get(m_pFtAngleDegrees, "anglemtrdegrees");
76 m_pMtrAngle->SetCustomUnitText(m_pFtAngleDegrees->GetText());
77 get(m_pMtrBorder, "bordermtr");
78 get(m_pLbColorFrom, "colorfromlb");
79 get(m_pMtrColorFrom, "colorfrommtr");
80 get(m_pLbColorTo, "colortolb");
81 get(m_pMtrColorTo, "colortomtr");
82 get(m_pLbGradients, "gradientslb");
83 Size aSize = LogicToPixel(Size(88, 110), MAP_APPFONT);
84 m_pLbGradients->set_width_request(aSize.Width());
85 m_pLbGradients->set_height_request(aSize.Height());
86 get(m_pCtlPreview, "previewctl");
87 aSize = LogicToPixel(Size(88, 42), MAP_APPFONT);
88 m_pCtlPreview->set_width_request(aSize.Width());
89 m_pCtlPreview->set_height_request(aSize.Height());
90 get(m_pBtnAdd, "add");
91 get(m_pBtnModify, "modify");
92 get(m_pBtnDelete, "delete");
93 get(m_pBtnLoad, "load");
94 get(m_pBtnSave, "save");
96 m_pCtlPreview->SetAccessibleName(String(CUI_RES(STR_EXAMPLE)));
97 m_pLbGradients->SetAccessibleName( GetText());
100 // this page needs ExchangeSupport
101 SetExchangeSupport();
103 // as long as NOT supported by the item
105 m_pMtrColorTo->SetValue( 100 );
106 m_pMtrColorFrom->SetValue( 100 );
108 // setting the output device
109 rXFSet.Put( aXFStyleItem );
110 rXFSet.Put( aXGradientItem );
111 m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
113 // overload the handler
114 m_pLbGradients->SetSelectHdl(
115 LINK( this, SvxGradientTabPage, ChangeGradientHdl_Impl ) );
116 m_pBtnAdd->SetClickHdl( LINK( this, SvxGradientTabPage, ClickAddHdl_Impl ) );
117 m_pBtnModify->SetClickHdl(
118 LINK( this, SvxGradientTabPage, ClickModifyHdl_Impl ) );
119 m_pBtnDelete->SetClickHdl(
120 LINK( this, SvxGradientTabPage, ClickDeleteHdl_Impl ) );
122 Link aLink = LINK( this, SvxGradientTabPage, ModifiedHdl_Impl );
123 m_pLbGradientType->SetSelectHdl( aLink );
124 m_pMtrCenterX->SetModifyHdl( aLink );
125 m_pMtrCenterY->SetModifyHdl( aLink );
126 m_pMtrAngle->SetModifyHdl( aLink );
127 m_pMtrBorder->SetModifyHdl( aLink );
128 m_pMtrColorFrom->SetModifyHdl( aLink );
129 m_pLbColorFrom->SetSelectHdl( aLink );
130 m_pMtrColorTo->SetModifyHdl( aLink );
131 m_pLbColorTo->SetSelectHdl( aLink );
133 m_pBtnLoad->SetClickHdl(
134 LINK( this, SvxGradientTabPage, ClickLoadHdl_Impl ) );
135 m_pBtnSave->SetClickHdl(
136 LINK( this, SvxGradientTabPage, ClickSaveHdl_Impl ) );
138 // #i76307# always paint the preview in LTR, because this is what the document does
139 m_pCtlPreview->EnableRTL( sal_False );
142 // -----------------------------------------------------------------------
144 void SvxGradientTabPage::Construct()
146 m_pLbColorFrom->Fill( pColorList );
147 m_pLbColorTo->CopyEntries( *m_pLbColorFrom );
149 m_pLbGradients->Fill( pGradientList );
152 // -----------------------------------------------------------------------
154 void SvxGradientTabPage::ActivatePage( const SfxItemSet& )
156 sal_uInt16 nPos;
157 sal_uInt16 nCount;
159 if( *pDlgType == 0 ) // area dialog
161 *pbAreaTP = sal_False;
163 if( pColorList.is() )
165 // ColorList
166 if( *pnColorListState & CT_CHANGED ||
167 *pnColorListState & CT_MODIFIED )
169 if( *pnColorListState & CT_CHANGED )
170 pColorList = ( (SvxAreaTabDialog*) GetParentDialog() )->GetNewColorList();
172 // LbColorFrom
173 nPos = m_pLbColorFrom->GetSelectEntryPos();
174 m_pLbColorFrom->Clear();
175 m_pLbColorFrom->Fill( pColorList );
176 nCount = m_pLbColorFrom->GetEntryCount();
177 if( nCount == 0 )
178 ; // this case should not occur
179 else if( nCount <= nPos )
180 m_pLbColorFrom->SelectEntryPos( 0 );
181 else
182 m_pLbColorFrom->SelectEntryPos( nPos );
184 // LbColorTo
185 nPos = m_pLbColorTo->GetSelectEntryPos();
186 m_pLbColorTo->Clear();
187 m_pLbColorTo->CopyEntries( *m_pLbColorFrom );
188 nCount = m_pLbColorTo->GetEntryCount();
189 if( nCount == 0 )
190 ; // this case should not occur
191 else if( nCount <= nPos )
192 m_pLbColorTo->SelectEntryPos( 0 );
193 else
194 m_pLbColorTo->SelectEntryPos( nPos );
196 ModifiedHdl_Impl( this );
199 // determining (and possibly cutting) the name and
200 // displaying it in the GroupBox
201 OUString aString( CUI_RES( RID_SVXSTR_TABLE ) );
202 aString += ": ";
203 INetURLObject aURL( pGradientList->GetPath() );
205 aURL.Append( pGradientList->GetName() );
206 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
208 if ( aURL.getBase().getLength() > 18 )
210 aString += aURL.getBase().copy( 0, 15 );
211 aString += "...";
213 else
214 aString += aURL.getBase();
216 if ( *pPageType == PT_GRADIENT && *pPos != LISTBOX_ENTRY_NOTFOUND )
218 m_pLbGradients->SelectEntryPos( *pPos );
220 // colors could have been deleted
221 ChangeGradientHdl_Impl( this );
223 *pPageType = PT_GRADIENT;
224 *pPos = LISTBOX_ENTRY_NOTFOUND;
229 // -----------------------------------------------------------------------
231 int SvxGradientTabPage::DeactivatePage( SfxItemSet* _pSet )
233 if( CheckChanges_Impl() == -1L )
234 return KEEP_PAGE;
236 if( _pSet )
237 FillItemSet( *_pSet );
239 return LEAVE_PAGE;
242 // -----------------------------------------------------------------------
244 long SvxGradientTabPage::CheckChanges_Impl()
246 // is used here in order to NOT lose changes
247 XGradient aTmpGradient( m_pLbColorFrom->GetSelectEntryColor(),
248 m_pLbColorTo->GetSelectEntryColor(),
249 (XGradientStyle) m_pLbGradientType->GetSelectEntryPos(),
250 static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
251 (sal_uInt16) m_pMtrCenterX->GetValue(),
252 (sal_uInt16) m_pMtrCenterY->GetValue(),
253 (sal_uInt16) m_pMtrBorder->GetValue(),
254 (sal_uInt16) m_pMtrColorFrom->GetValue(),
255 (sal_uInt16) m_pMtrColorTo->GetValue() );
257 sal_uInt16 nPos = m_pLbGradients->GetSelectEntryPos();
258 if( nPos != LISTBOX_ENTRY_NOTFOUND )
260 XGradient aGradient = pGradientList->GetGradient( nPos )->GetGradient();
262 if( !( aTmpGradient == aGradient ) )
264 ResMgr& rMgr = CUI_MGR();
265 Image aWarningBoxImage = WarningBox::GetStandardImage();
266 SvxMessDialog* aMessDlg = new SvxMessDialog(GetParentDialog(),
267 SVX_RESSTR( RID_SVXSTR_GRADIENT ),
268 CUI_RESSTR( RID_SVXSTR_ASK_CHANGE_GRADIENT ),
269 &aWarningBoxImage );
270 DBG_ASSERT(aMessDlg, "Dialogdiet fail!");
271 aMessDlg->SetButtonText( MESS_BTN_1,
272 String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
273 aMessDlg->SetButtonText( MESS_BTN_2,
274 String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
276 short nRet = aMessDlg->Execute();
278 switch( nRet )
280 case RET_BTN_1:
282 ClickModifyHdl_Impl( this );
283 aGradient = pGradientList->GetGradient( nPos )->GetGradient();
285 break;
287 case RET_BTN_2:
289 ClickAddHdl_Impl( this );
290 nPos = m_pLbGradients->GetSelectEntryPos();
291 aGradient = pGradientList->GetGradient( nPos )->GetGradient();
293 break;
295 case RET_CANCEL:
296 break;
298 delete aMessDlg;
301 nPos = m_pLbGradients->GetSelectEntryPos();
302 if( nPos != LISTBOX_ENTRY_NOTFOUND )
304 *pPos = nPos;
306 return 0L;
309 // -----------------------------------------------------------------------
311 sal_Bool SvxGradientTabPage::FillItemSet( SfxItemSet& rSet )
313 if( *pDlgType == 0 && *pPageType == PT_GRADIENT && *pbAreaTP == sal_False )
315 // CheckChanges(); <-- duplicate inquiry ?
317 XGradient* pXGradient = NULL;
318 String aString;
319 sal_uInt16 nPos = m_pLbGradients->GetSelectEntryPos();
320 if( nPos != LISTBOX_ENTRY_NOTFOUND )
322 pXGradient = new XGradient( pGradientList->GetGradient( nPos )->GetGradient() );
323 aString = m_pLbGradients->GetSelectEntry();
326 else
327 // gradient was passed (unidentified)
329 pXGradient = new XGradient( m_pLbColorFrom->GetSelectEntryColor(),
330 m_pLbColorTo->GetSelectEntryColor(),
331 (XGradientStyle) m_pLbGradientType->GetSelectEntryPos(),
332 static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
333 (sal_uInt16) m_pMtrCenterX->GetValue(),
334 (sal_uInt16) m_pMtrCenterY->GetValue(),
335 (sal_uInt16) m_pMtrBorder->GetValue(),
336 (sal_uInt16) m_pMtrColorFrom->GetValue(),
337 (sal_uInt16) m_pMtrColorTo->GetValue() );
339 DBG_ASSERT( pXGradient, "XGradient konnte nicht erzeugt werden" );
340 rSet.Put( XFillStyleItem( XFILL_GRADIENT ) );
341 rSet.Put( XFillGradientItem( aString, *pXGradient ) );
343 delete pXGradient;
345 return sal_True;
348 // -----------------------------------------------------------------------
350 void SvxGradientTabPage::Reset( const SfxItemSet& )
352 // m_pLbGradients->SelectEntryPos( 0 );
353 ChangeGradientHdl_Impl( this );
355 // determine state of the buttons
356 if( pGradientList->Count() )
358 m_pBtnModify->Enable();
359 m_pBtnDelete->Enable();
360 m_pBtnSave->Enable();
362 else
364 m_pBtnModify->Disable();
365 m_pBtnDelete->Disable();
366 m_pBtnSave->Disable();
370 // -----------------------------------------------------------------------
372 SfxTabPage* SvxGradientTabPage::Create( Window* pWindow,
373 const SfxItemSet& rOutAttrs )
375 return new SvxGradientTabPage( pWindow, rOutAttrs );
378 //------------------------------------------------------------------------
380 IMPL_LINK( SvxGradientTabPage, ModifiedHdl_Impl, void *, pControl )
382 XGradientStyle eXGS = (XGradientStyle) m_pLbGradientType->GetSelectEntryPos();
384 XGradient aXGradient( m_pLbColorFrom->GetSelectEntryColor(),
385 m_pLbColorTo->GetSelectEntryColor(),
386 eXGS,
387 static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
388 (sal_uInt16) m_pMtrCenterX->GetValue(),
389 (sal_uInt16) m_pMtrCenterY->GetValue(),
390 (sal_uInt16) m_pMtrBorder->GetValue(),
391 (sal_uInt16) m_pMtrColorFrom->GetValue(),
392 (sal_uInt16) m_pMtrColorTo->GetValue() );
394 // enable/disable controls
395 if( pControl == m_pLbGradientType || pControl == this )
396 SetControlState_Impl( eXGS );
398 // displaying in XOutDev
399 rXFSet.Put( XFillGradientItem( String(), aXGradient ) );
400 m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
402 m_pCtlPreview->Invalidate();
404 return 0L;
407 //------------------------------------------------------------------------
409 IMPL_LINK_NOARG(SvxGradientTabPage, ClickAddHdl_Impl)
411 ResMgr& rMgr = CUI_MGR();
412 String aNewName( SVX_RES( RID_SVXSTR_GRADIENT ) );
413 String aDesc( CUI_RES( RID_SVXSTR_DESC_GRADIENT ) );
414 String aName;
416 long nCount = pGradientList->Count();
417 long j = 1;
418 sal_Bool bDifferent = sal_False;
420 while( !bDifferent )
422 aName = aNewName;
423 aName += sal_Unicode(' ');
424 aName += OUString::valueOf( j++ );
425 bDifferent = sal_True;
427 for( long i = 0; i < nCount && bDifferent; i++ )
428 if( aName == pGradientList->GetGradient( i )->GetName() )
429 bDifferent = sal_False;
432 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
433 DBG_ASSERT(pFact, "Dialogdiet fail!");
434 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
435 DBG_ASSERT(pDlg, "Dialogdiet fail!");
436 WarningBox* pWarnBox = NULL;
437 sal_uInt16 nError = RID_SVXSTR_WARN_NAME_DUPLICATE;
439 while( pDlg->Execute() == RET_OK )
441 pDlg->GetName( aName );
443 bDifferent = sal_True;
445 for( long i = 0; i < nCount && bDifferent; i++ )
446 if( aName == pGradientList->GetGradient( i )->GetName() )
447 bDifferent = sal_False;
449 if( bDifferent )
451 nError = 0;
452 break;
455 if( !pWarnBox )
457 pWarnBox = new WarningBox( GetParentDialog(),
458 WinBits( WB_OK_CANCEL ),
459 String( ResId( nError, rMgr ) ) );
460 pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
463 if( pWarnBox->Execute() != RET_OK )
464 break;
466 delete pDlg;
467 delete pWarnBox;
469 if( !nError )
471 XGradient aXGradient( m_pLbColorFrom->GetSelectEntryColor(),
472 m_pLbColorTo->GetSelectEntryColor(),
473 (XGradientStyle) m_pLbGradientType->GetSelectEntryPos(),
474 static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
475 (sal_uInt16) m_pMtrCenterX->GetValue(),
476 (sal_uInt16) m_pMtrCenterY->GetValue(),
477 (sal_uInt16) m_pMtrBorder->GetValue(),
478 (sal_uInt16) m_pMtrColorFrom->GetValue(),
479 (sal_uInt16) m_pMtrColorTo->GetValue() );
480 XGradientEntry* pEntry = new XGradientEntry( aXGradient, aName );
482 pGradientList->Insert( pEntry, nCount );
484 m_pLbGradients->Append( pEntry );
486 m_pLbGradients->SelectEntryPos( m_pLbGradients->GetEntryCount() - 1 );
488 #ifdef WNT
489 // hack: #31355# W.P.
490 Rectangle aRect( m_pLbGradients->GetPosPixel(), m_pLbGradients->GetSizePixel() );
491 if( sal_True ) { // ??? overlapped with pDlg
492 // and srolling
493 Invalidate( aRect );
495 #endif
497 *pnGradientListState |= CT_MODIFIED;
499 ChangeGradientHdl_Impl( this );
502 // determine button state
503 if( pGradientList->Count() )
505 m_pBtnModify->Enable();
506 m_pBtnDelete->Enable();
507 m_pBtnSave->Enable();
509 return 0L;
512 //------------------------------------------------------------------------
514 IMPL_LINK_NOARG(SvxGradientTabPage, ClickModifyHdl_Impl)
516 sal_uInt16 nPos = m_pLbGradients->GetSelectEntryPos();
518 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
520 ResMgr& rMgr = CUI_MGR();
521 String aDesc( CUI_RES( RID_SVXSTR_DESC_GRADIENT ) );
522 String aName( pGradientList->GetGradient( nPos )->GetName() );
523 String aOldName = aName;
525 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
526 DBG_ASSERT(pFact, "Dialogdiet fail!");
527 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
528 DBG_ASSERT(pDlg, "Dialogdiet fail!");
530 long nCount = pGradientList->Count();
531 sal_Bool bDifferent = sal_False;
532 sal_Bool bLoop = sal_True;
534 while( bLoop && pDlg->Execute() == RET_OK )
536 pDlg->GetName( aName );
537 bDifferent = sal_True;
539 for( long i = 0; i < nCount && bDifferent; i++ )
541 if( aName == pGradientList->GetGradient( i )->GetName() &&
542 aName != aOldName )
543 bDifferent = sal_False;
546 if( bDifferent )
548 bLoop = sal_False;
549 XGradient aXGradient( m_pLbColorFrom->GetSelectEntryColor(),
550 m_pLbColorTo->GetSelectEntryColor(),
551 (XGradientStyle) m_pLbGradientType->GetSelectEntryPos(),
552 static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
553 (sal_uInt16) m_pMtrCenterX->GetValue(),
554 (sal_uInt16) m_pMtrCenterY->GetValue(),
555 (sal_uInt16) m_pMtrBorder->GetValue(),
556 (sal_uInt16) m_pMtrColorFrom->GetValue(),
557 (sal_uInt16) m_pMtrColorTo->GetValue() );
559 XGradientEntry* pEntry = new XGradientEntry( aXGradient, aName );
561 delete pGradientList->Replace( pEntry, nPos );
563 m_pLbGradients->Modify( pEntry, nPos );
565 m_pLbGradients->SelectEntryPos( nPos );
567 *pnGradientListState |= CT_MODIFIED;
569 else
571 WarningBox aBox( GetParentDialog(), WinBits( WB_OK ),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
572 aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
573 aBox.Execute();
577 delete pDlg;
579 return 0L;
582 //------------------------------------------------------------------------
584 IMPL_LINK_NOARG(SvxGradientTabPage, ClickDeleteHdl_Impl)
586 sal_uInt16 nPos = m_pLbGradients->GetSelectEntryPos();
588 if( nPos != LISTBOX_ENTRY_NOTFOUND )
590 QueryBox aQueryBox( GetParentDialog(), WinBits( WB_YES_NO | WB_DEF_NO ),
591 String( CUI_RES( RID_SVXSTR_ASK_DEL_GRADIENT ) ) );
593 if ( aQueryBox.Execute() == RET_YES )
595 delete pGradientList->Remove( nPos );
596 m_pLbGradients->RemoveEntry( nPos );
597 m_pLbGradients->SelectEntryPos( 0 );
599 m_pCtlPreview->Invalidate();
601 ChangeGradientHdl_Impl( this );
603 *pnGradientListState |= CT_MODIFIED;
606 // determine button state
607 if( !pGradientList->Count() )
609 m_pBtnModify->Disable();
610 m_pBtnDelete->Disable();
611 m_pBtnSave->Disable();
613 return 0L;
616 // -----------------------------------------------------------------------
618 IMPL_LINK_NOARG(SvxGradientTabPage, ClickLoadHdl_Impl)
620 ResMgr& rMgr = CUI_MGR();
621 sal_uInt16 nReturn = RET_YES;
623 if ( *pnGradientListState & CT_MODIFIED )
625 nReturn = WarningBox( GetParentDialog(), WinBits( WB_YES_NO_CANCEL ),
626 String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
628 if ( nReturn == RET_YES )
629 pGradientList->Save();
632 if ( nReturn != RET_CANCEL )
634 ::sfx2::FileDialogHelper aDlg(
635 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
636 0 );
637 String aStrFilterType( "*.sog" );
638 aDlg.AddFilter( aStrFilterType, aStrFilterType );
639 INetURLObject aFile( SvtPathOptions().GetPalettePath() );
640 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
642 if( aDlg.Execute() == ERRCODE_NONE )
644 EnterWait();
646 INetURLObject aURL( aDlg.GetPath() );
647 INetURLObject aPathURL( aURL );
649 aPathURL.removeSegment();
650 aPathURL.removeFinalSlash();
652 // save list
653 XGradientListRef pGrdList = XPropertyList::CreatePropertyList(
654 XGRADIENT_LIST, aPathURL.GetMainURL( INetURLObject::NO_DECODE ), pXPool )->AsGradientList();
655 pGrdList->SetName( aURL.getName() );
657 if ( pGrdList->Load() )
659 pGradientList = pGrdList;
660 ( (SvxAreaTabDialog*) GetParentDialog() )->
661 SetNewGradientList( pGradientList );
663 m_pLbGradients->Clear();
664 m_pLbGradients->Fill( pGradientList );
665 Reset( rOutAttrs );
667 pGradientList->SetName( aURL.getName() );
669 // determining (possibly cutting) the name
670 // and displaying it in the GroupBox
671 OUString aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
672 aString += ": ";
674 if ( aURL.getBase().getLength() > 18 )
676 aString += aURL.getBase().copy( 0, 15 );
677 aString += "...";
679 else
680 aString += aURL.getBase();
682 *pnGradientListState |= CT_CHANGED;
683 *pnGradientListState &= ~CT_MODIFIED;
684 LeaveWait();
686 else
688 LeaveWait();
689 ErrorBox( GetParentDialog(), WinBits( WB_OK ),
690 String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
695 // determine button state
696 if( pGradientList->Count() )
698 m_pBtnModify->Enable();
699 m_pBtnDelete->Enable();
700 m_pBtnSave->Enable();
702 else
704 m_pBtnModify->Disable();
705 m_pBtnDelete->Disable();
706 m_pBtnSave->Disable();
708 return 0L;
711 // -----------------------------------------------------------------------
713 IMPL_LINK_NOARG(SvxGradientTabPage, ClickSaveHdl_Impl)
715 ::sfx2::FileDialogHelper aDlg(
716 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
717 String aStrFilterType( "*.sog" );
718 aDlg.AddFilter( aStrFilterType, aStrFilterType );
720 INetURLObject aFile( SvtPathOptions().GetPalettePath() );
721 DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
723 if( pGradientList->GetName().Len() )
725 aFile.Append( pGradientList->GetName() );
727 if( aFile.getExtension().isEmpty() )
728 aFile.SetExtension( OUString("sog") );
731 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
732 if ( aDlg.Execute() == ERRCODE_NONE )
734 INetURLObject aURL( aDlg.GetPath() );
735 INetURLObject aPathURL( aURL );
737 aPathURL.removeSegment();
738 aPathURL.removeFinalSlash();
740 pGradientList->SetName( aURL.getName() );
741 pGradientList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
743 if( pGradientList->Save() )
745 // determining (possibly cutting) the name
746 // and displaying it in the GroupBox
747 OUString aString( CUI_RES( RID_SVXSTR_TABLE ) );
748 aString += ": ";
750 if ( aURL.getBase().getLength() > 18 )
752 aString += aURL.getBase().copy( 0, 15 );
753 aString += "...";
755 else
756 aString += aURL.getBase();
758 *pnGradientListState |= CT_SAVED;
759 *pnGradientListState &= ~CT_MODIFIED;
761 else
763 ErrorBox( GetParentDialog(), WinBits( WB_OK ),
764 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
768 return 0L;
771 //------------------------------------------------------------------------
773 IMPL_LINK_NOARG(SvxGradientTabPage, ChangeGradientHdl_Impl)
775 XGradient* pGradient = NULL;
776 int nPos = m_pLbGradients->GetSelectEntryPos();
778 if( nPos != LISTBOX_ENTRY_NOTFOUND )
779 pGradient = new XGradient( ( (XGradientEntry*) pGradientList->GetGradient( nPos ) )->GetGradient() );
780 else
782 const SfxPoolItem* pPoolItem = NULL;
783 if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), sal_True, &pPoolItem ) )
785 if( ( XFILL_GRADIENT == (XFillStyle) ( ( const XFillStyleItem* ) pPoolItem )->GetValue() ) &&
786 ( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLGRADIENT ), sal_True, &pPoolItem ) ) )
788 pGradient = new XGradient( ( ( const XFillGradientItem* ) pPoolItem )->GetGradientValue() );
791 if( !pGradient )
793 m_pLbGradients->SelectEntryPos( 0 );
794 nPos = m_pLbGradients->GetSelectEntryPos();
795 if( nPos != LISTBOX_ENTRY_NOTFOUND )
796 pGradient = new XGradient( ( (XGradientEntry*) pGradientList->GetGradient( nPos ) )->GetGradient() );
800 if( pGradient )
802 XGradientStyle eXGS = pGradient->GetGradientStyle();
804 m_pLbGradientType->SelectEntryPos(
805 sal::static_int_cast< sal_uInt16 >( eXGS ) );
806 // if the entry is not in the listbox ist,
807 // colors are added temporarily
808 m_pLbColorFrom->SetNoSelection();
809 m_pLbColorFrom->SelectEntry( pGradient->GetStartColor() );
811 if ( m_pLbColorFrom->GetSelectEntryCount() == 0 )
813 m_pLbColorFrom->InsertEntry( pGradient->GetStartColor(),
814 String() );
815 m_pLbColorFrom->SelectEntry( pGradient->GetStartColor() );
817 m_pLbColorTo->SetNoSelection();
818 m_pLbColorTo->SelectEntry( pGradient->GetEndColor() );
820 if ( m_pLbColorTo->GetSelectEntryCount() == 0 )
822 m_pLbColorTo->InsertEntry( pGradient->GetEndColor(), String() );
823 m_pLbColorTo->SelectEntry( pGradient->GetEndColor() );
826 m_pMtrAngle->SetValue( pGradient->GetAngle() / 10 ); // should be changed in resource
827 m_pMtrBorder->SetValue( pGradient->GetBorder() );
828 m_pMtrCenterX->SetValue( pGradient->GetXOffset() );
829 m_pMtrCenterY->SetValue( pGradient->GetYOffset() );
830 m_pMtrColorFrom->SetValue( pGradient->GetStartIntens() );
831 m_pMtrColorTo->SetValue( pGradient->GetEndIntens() );
833 // disable/enable controls
834 SetControlState_Impl( eXGS );
836 // fill ItemSet and pass it on to aCtlPreview
837 rXFSet.Put( XFillGradientItem( String(), *pGradient ) );
838 m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
840 m_pCtlPreview->Invalidate();
841 delete pGradient;
843 return 0L;
846 //------------------------------------------------------------------------
848 void SvxGradientTabPage::SetControlState_Impl( XGradientStyle eXGS )
850 switch( eXGS )
852 case XGRAD_LINEAR:
853 case XGRAD_AXIAL:
854 m_pFtCenterX->Disable();
855 m_pMtrCenterX->Disable();
856 m_pFtCenterY->Disable();
857 m_pMtrCenterY->Disable();
858 m_pFtAngle->Enable();
859 m_pMtrAngle->Enable();
860 break;
862 case XGRAD_RADIAL:
863 m_pFtCenterX->Enable();
864 m_pMtrCenterX->Enable();
865 m_pFtCenterY->Enable();
866 m_pMtrCenterY->Enable();
867 m_pFtAngle->Disable();
868 m_pMtrAngle->Disable();
869 break;
871 case XGRAD_ELLIPTICAL:
872 m_pFtCenterX->Enable();
873 m_pMtrCenterX->Enable();
874 m_pFtCenterY->Enable();
875 m_pMtrCenterY->Enable();
876 m_pFtAngle->Enable();
877 m_pMtrAngle->Enable();
878 break;
880 case XGRAD_SQUARE:
881 case XGRAD_RECT:
882 m_pFtCenterX->Enable();
883 m_pMtrCenterX->Enable();
884 m_pFtCenterY->Enable();
885 m_pMtrCenterY->Enable();
886 m_pFtAngle->Enable();
887 m_pMtrAngle->Enable();
888 break;
893 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */