bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / tabpages / tpgradnt.cxx
blobe737410c36cb7655b46d8c0c852d64f983448b0d
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/urlobj.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <unotools/pathoptions.hxx>
24 #include <sfx2/app.hxx>
25 #include <sfx2/dialoghelper.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 "defdlgname.hxx"
37 #include "dlgname.hxx"
38 #include <svx/svxdlg.hxx>
39 #include <dialmgr.hxx>
40 #include <svx/dialmgr.hxx>
41 #include <svx/dialogs.hrc>
42 #include "paragrph.hrc"
43 #include <boost/scoped_ptr.hpp>
45 using namespace com::sun::star;
47 SvxGradientTabPage::SvxGradientTabPage
49 vcl::Window* pParent,
50 const SfxItemSet& rInAttrs
51 ) :
52 SfxTabPage ( pParent, "GradientPage", "cui/ui/gradientpage.ui", &rInAttrs ),
54 rOutAttrs ( rInAttrs ),
56 pnGradientListState ( 0 ),
57 pnColorListState ( 0 ),
58 pPageType ( 0 ),
59 nDlgType ( 0 ),
60 pPos ( 0 ),
61 pbAreaTP ( 0 ),
63 pXPool ( static_cast<XOutdevItemPool*>( rInAttrs.GetPool() )),
64 aXFStyleItem ( drawing::FillStyle_GRADIENT ),
65 aXGradientItem ( OUString(), XGradient( COL_BLACK, COL_WHITE ) ),
66 aXFillAttr ( pXPool ),
67 rXFSet ( aXFillAttr.GetItemSet() )
69 get(m_pLbGradientType, "gradienttypelb");
70 get(m_pFtCenterX, "centerxft");
71 get(m_pMtrCenterX, "centerxmtr");
72 get(m_pFtCenterY, "centeryft");
73 get(m_pMtrCenterY, "centerymtr");
74 get(m_pFtAngle, "angleft");
75 get(m_pMtrAngle, "anglemtr");
76 get(m_pMtrBorder, "bordermtr");
77 get(m_pLbColorFrom, "colorfromlb");
78 get(m_pMtrColorFrom, "colorfrommtr");
79 get(m_pLbColorTo, "colortolb");
80 get(m_pMtrColorTo, "colortomtr");
81 get(m_pLbGradients, "gradientslb");
82 Size aSize = getDrawListBoxOptimalSize(this);
83 m_pLbGradients->set_width_request(aSize.Width());
84 m_pLbGradients->set_height_request(aSize.Height());
85 get(m_pCtlPreview, "previewctl");
86 aSize = getDrawPreviewOptimalSize(this);
87 m_pCtlPreview->set_width_request(aSize.Width());
88 m_pCtlPreview->set_height_request(aSize.Height());
89 get(m_pBtnAdd, "add");
90 get(m_pBtnModify, "modify");
91 get(m_pBtnDelete, "delete");
92 get(m_pBtnLoad, "load");
93 get(m_pBtnSave, "save");
95 m_pLbGradients->SetAccessibleName(GetText());
98 // this page needs ExchangeSupport
99 SetExchangeSupport();
101 // as long as NOT supported by the item
103 m_pMtrColorTo->SetValue( 100 );
104 m_pMtrColorFrom->SetValue( 100 );
106 // setting the output device
107 rXFSet.Put( aXFStyleItem );
108 rXFSet.Put( aXGradientItem );
109 m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
111 // set handler
112 m_pLbGradients->SetSelectHdl(
113 LINK( this, SvxGradientTabPage, ChangeGradientHdl_Impl ) );
114 m_pBtnAdd->SetClickHdl( LINK( this, SvxGradientTabPage, ClickAddHdl_Impl ) );
115 m_pBtnModify->SetClickHdl(
116 LINK( this, SvxGradientTabPage, ClickModifyHdl_Impl ) );
117 m_pBtnDelete->SetClickHdl(
118 LINK( this, SvxGradientTabPage, ClickDeleteHdl_Impl ) );
120 Link<> aLink = LINK( this, SvxGradientTabPage, ModifiedHdl_Impl );
121 m_pLbGradientType->SetSelectHdl( aLink );
122 m_pMtrCenterX->SetModifyHdl( aLink );
123 m_pMtrCenterY->SetModifyHdl( aLink );
124 m_pMtrAngle->SetModifyHdl( aLink );
125 m_pMtrBorder->SetModifyHdl( aLink );
126 m_pMtrColorFrom->SetModifyHdl( aLink );
127 m_pLbColorFrom->SetSelectHdl( aLink );
128 m_pMtrColorTo->SetModifyHdl( aLink );
129 m_pLbColorTo->SetSelectHdl( aLink );
131 m_pBtnLoad->SetClickHdl(
132 LINK( this, SvxGradientTabPage, ClickLoadHdl_Impl ) );
133 m_pBtnSave->SetClickHdl(
134 LINK( this, SvxGradientTabPage, ClickSaveHdl_Impl ) );
136 // #i76307# always paint the preview in LTR, because this is what the document does
137 m_pCtlPreview->EnableRTL( false );
139 setPreviewsToSamePlace(pParent, this);
142 SvxGradientTabPage::~SvxGradientTabPage()
144 disposeOnce();
147 void SvxGradientTabPage::dispose()
149 m_pLbGradientType.clear();
150 m_pFtCenterX.clear();
151 m_pMtrCenterX.clear();
152 m_pFtCenterY.clear();
153 m_pMtrCenterY.clear();
154 m_pFtAngle.clear();
155 m_pMtrAngle.clear();
156 m_pMtrBorder.clear();
157 m_pLbColorFrom.clear();
158 m_pMtrColorFrom.clear();
159 m_pLbColorTo.clear();
160 m_pMtrColorTo.clear();
161 m_pLbGradients.clear();
162 m_pCtlPreview.clear();
163 m_pBtnAdd.clear();
164 m_pBtnModify.clear();
165 m_pBtnDelete.clear();
166 m_pBtnLoad.clear();
167 m_pBtnSave.clear();
168 SfxTabPage::dispose();
172 void SvxGradientTabPage::Construct()
174 m_pLbColorFrom->Fill( pColorList );
175 m_pLbColorTo->CopyEntries( *m_pLbColorFrom );
177 m_pLbGradients->Fill( pGradientList );
182 void SvxGradientTabPage::ActivatePage( const SfxItemSet& )
184 sal_Int32 nPos;
185 sal_Int32 nCount;
187 if( nDlgType == 0 ) // area dialog
189 *pbAreaTP = false;
191 if( pColorList.is() )
193 // ColorList
194 if( *pnColorListState & ChangeType::CHANGED ||
195 *pnColorListState & ChangeType::MODIFIED )
197 if( *pnColorListState & ChangeType::CHANGED )
198 pColorList = static_cast<SvxAreaTabDialog*>( GetParentDialog() )->GetNewColorList();
200 // LbColorFrom
201 nPos = m_pLbColorFrom->GetSelectEntryPos();
202 m_pLbColorFrom->Clear();
203 m_pLbColorFrom->Fill( pColorList );
204 nCount = m_pLbColorFrom->GetEntryCount();
205 if( nCount == 0 )
206 ; // this case should not occur
207 else if( nCount <= nPos )
208 m_pLbColorFrom->SelectEntryPos( 0 );
209 else
210 m_pLbColorFrom->SelectEntryPos( nPos );
212 // LbColorTo
213 nPos = m_pLbColorTo->GetSelectEntryPos();
214 m_pLbColorTo->Clear();
215 m_pLbColorTo->CopyEntries( *m_pLbColorFrom );
216 nCount = m_pLbColorTo->GetEntryCount();
217 if( nCount == 0 )
218 ; // this case should not occur
219 else if( nCount <= nPos )
220 m_pLbColorTo->SelectEntryPos( 0 );
221 else
222 m_pLbColorTo->SelectEntryPos( nPos );
224 ModifiedHdl_Impl( this );
227 // determining (and possibly cutting) the name and
228 // displaying it in the GroupBox
229 OUString aString( CUI_RES( RID_SVXSTR_TABLE ) );
230 aString += ": ";
231 INetURLObject aURL( pGradientList->GetPath() );
233 aURL.Append( pGradientList->GetName() );
234 DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
236 if ( aURL.getBase().getLength() > 18 )
238 aString += aURL.getBase().copy( 0, 15 );
239 aString += "...";
241 else
242 aString += aURL.getBase();
244 if ( *pPageType == PT_GRADIENT && *pPos != LISTBOX_ENTRY_NOTFOUND )
246 m_pLbGradients->SelectEntryPos( *pPos );
248 // colors could have been deleted
249 ChangeGradientHdl_Impl( this );
251 *pPageType = PT_GRADIENT;
252 *pPos = LISTBOX_ENTRY_NOTFOUND;
259 SfxTabPage::sfxpg SvxGradientTabPage::DeactivatePage( SfxItemSet* _pSet )
261 if( CheckChanges_Impl() == -1L )
262 return KEEP_PAGE;
264 if( _pSet )
265 FillItemSet( _pSet );
267 return LEAVE_PAGE;
272 long SvxGradientTabPage::CheckChanges_Impl()
274 // is used here in order to NOT lose changes
275 XGradient aTmpGradient( m_pLbColorFrom->GetSelectEntryColor(),
276 m_pLbColorTo->GetSelectEntryColor(),
277 (css::awt::GradientStyle) m_pLbGradientType->GetSelectEntryPos(),
278 static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
279 (sal_uInt16) m_pMtrCenterX->GetValue(),
280 (sal_uInt16) m_pMtrCenterY->GetValue(),
281 (sal_uInt16) m_pMtrBorder->GetValue(),
282 (sal_uInt16) m_pMtrColorFrom->GetValue(),
283 (sal_uInt16) m_pMtrColorTo->GetValue() );
285 sal_Int32 nPos = m_pLbGradients->GetSelectEntryPos();
286 if( nPos != LISTBOX_ENTRY_NOTFOUND )
288 XGradient aGradient = pGradientList->GetGradient( nPos )->GetGradient();
290 if( !( aTmpGradient == aGradient ) )
292 ResMgr& rMgr = CUI_MGR();
293 Image aWarningBoxImage = WarningBox::GetStandardImage();
294 ScopedVclPtrInstance<SvxMessDialog> aMessDlg( GetParentDialog(),
295 SVX_RESSTR( RID_SVXSTR_GRADIENT ),
296 CUI_RESSTR( RID_SVXSTR_ASK_CHANGE_GRADIENT ),
297 &aWarningBoxImage );
298 DBG_ASSERT(aMessDlg, "Dialog creation failed!");
299 aMessDlg->SetButtonText( MESS_BTN_1,
300 OUString( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
301 aMessDlg->SetButtonText( MESS_BTN_2,
302 OUString( ResId( RID_SVXSTR_ADD, rMgr ) ) );
304 short nRet = aMessDlg->Execute();
306 switch( nRet )
308 case RET_BTN_1:
310 ClickModifyHdl_Impl( this );
311 aGradient = pGradientList->GetGradient( nPos )->GetGradient();
313 break;
315 case RET_BTN_2:
317 ClickAddHdl_Impl( this );
318 nPos = m_pLbGradients->GetSelectEntryPos();
319 aGradient = pGradientList->GetGradient( nPos )->GetGradient();
321 break;
323 case RET_CANCEL:
324 break;
328 nPos = m_pLbGradients->GetSelectEntryPos();
329 if( nPos != LISTBOX_ENTRY_NOTFOUND )
331 *pPos = nPos;
333 return 0L;
338 bool SvxGradientTabPage::FillItemSet( SfxItemSet* rSet )
340 if( nDlgType == 0 && *pPageType == PT_GRADIENT && !*pbAreaTP )
342 // CheckChanges(); <-- duplicate inquiry ?
344 boost::scoped_ptr<XGradient> pXGradient;
345 OUString aString;
346 sal_Int32 nPos = m_pLbGradients->GetSelectEntryPos();
347 if( nPos != LISTBOX_ENTRY_NOTFOUND )
349 pXGradient.reset(new XGradient( pGradientList->GetGradient( nPos )->GetGradient() ));
350 aString = m_pLbGradients->GetSelectEntry();
353 else
354 // gradient was passed (unidentified)
356 pXGradient.reset(new XGradient( m_pLbColorFrom->GetSelectEntryColor(),
357 m_pLbColorTo->GetSelectEntryColor(),
358 (css::awt::GradientStyle) m_pLbGradientType->GetSelectEntryPos(),
359 static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
360 (sal_uInt16) m_pMtrCenterX->GetValue(),
361 (sal_uInt16) m_pMtrCenterY->GetValue(),
362 (sal_uInt16) m_pMtrBorder->GetValue(),
363 (sal_uInt16) m_pMtrColorFrom->GetValue(),
364 (sal_uInt16) m_pMtrColorTo->GetValue() ));
366 DBG_ASSERT( pXGradient, "XGradient konnte nicht erzeugt werden" );
367 rSet->Put( XFillStyleItem( drawing::FillStyle_GRADIENT ) );
368 rSet->Put( XFillGradientItem( aString, *pXGradient ) );
370 return true;
375 void SvxGradientTabPage::Reset( const SfxItemSet* )
377 // m_pLbGradients->SelectEntryPos( 0 );
378 ChangeGradientHdl_Impl( this );
380 // determine state of the buttons
381 if( pGradientList->Count() )
383 m_pBtnModify->Enable();
384 m_pBtnDelete->Enable();
385 m_pBtnSave->Enable();
387 else
389 m_pBtnModify->Disable();
390 m_pBtnDelete->Disable();
391 m_pBtnSave->Disable();
397 VclPtr<SfxTabPage> SvxGradientTabPage::Create( vcl::Window* pWindow,
398 const SfxItemSet* rOutAttrs )
400 return VclPtr<SvxGradientTabPage>::Create( pWindow, *rOutAttrs );
405 IMPL_LINK( SvxGradientTabPage, ModifiedHdl_Impl, void *, pControl )
407 css::awt::GradientStyle eXGS = (css::awt::GradientStyle) m_pLbGradientType->GetSelectEntryPos();
409 XGradient aXGradient( m_pLbColorFrom->GetSelectEntryColor(),
410 m_pLbColorTo->GetSelectEntryColor(),
411 eXGS,
412 static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
413 (sal_uInt16) m_pMtrCenterX->GetValue(),
414 (sal_uInt16) m_pMtrCenterY->GetValue(),
415 (sal_uInt16) m_pMtrBorder->GetValue(),
416 (sal_uInt16) m_pMtrColorFrom->GetValue(),
417 (sal_uInt16) m_pMtrColorTo->GetValue() );
419 // enable/disable controls
420 if( pControl == m_pLbGradientType || pControl == this )
421 SetControlState_Impl( eXGS );
423 // displaying in XOutDev
424 rXFSet.Put( XFillGradientItem( OUString(), aXGradient ) );
425 m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
427 m_pCtlPreview->Invalidate();
429 return 0L;
434 IMPL_LINK_NOARG(SvxGradientTabPage, ClickAddHdl_Impl)
436 OUString aNewName( SVX_RES( RID_SVXSTR_GRADIENT ) );
437 OUString aDesc( CUI_RES( RID_SVXSTR_DESC_GRADIENT ) );
438 OUString aName;
440 long nCount = pGradientList->Count();
441 long j = 1;
442 bool bDifferent = false;
444 while( !bDifferent )
446 aName = aNewName;
447 aName += " ";
448 aName += OUString::number( j++ );
449 bDifferent = true;
451 for( long i = 0; i < nCount && bDifferent; i++ )
452 if( aName == pGradientList->GetGradient( i )->GetName() )
453 bDifferent = false;
456 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
457 boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ));
458 ScopedVclPtr<MessageDialog> pWarnBox;
459 sal_uInt16 nError = 1;
461 while (pDlg->Execute() == RET_OK)
463 pDlg->GetName( aName );
465 bDifferent = true;
467 for (long i = 0; i < nCount && bDifferent; ++i)
469 if( aName == pGradientList->GetGradient( i )->GetName() )
470 bDifferent = false;
473 if (bDifferent)
475 nError = 0;
476 break;
479 if( !pWarnBox )
481 pWarnBox.reset(VclPtr<MessageDialog>::Create( GetParentDialog()
482 ,"DuplicateNameDialog"
483 ,"cui/ui/queryduplicatedialog.ui"));
486 if( pWarnBox->Execute() != RET_OK )
487 break;
489 pDlg.reset();
490 pWarnBox.reset();
492 if( !nError )
494 XGradient aXGradient( m_pLbColorFrom->GetSelectEntryColor(),
495 m_pLbColorTo->GetSelectEntryColor(),
496 (css::awt::GradientStyle) m_pLbGradientType->GetSelectEntryPos(),
497 static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
498 (sal_uInt16) m_pMtrCenterX->GetValue(),
499 (sal_uInt16) m_pMtrCenterY->GetValue(),
500 (sal_uInt16) m_pMtrBorder->GetValue(),
501 (sal_uInt16) m_pMtrColorFrom->GetValue(),
502 (sal_uInt16) m_pMtrColorTo->GetValue() );
503 XGradientEntry* pEntry = new XGradientEntry( aXGradient, aName );
505 pGradientList->Insert( pEntry, nCount );
507 m_pLbGradients->Append( *pEntry, pGradientList->GetUiBitmap( nCount ) );
509 m_pLbGradients->SelectEntryPos( m_pLbGradients->GetEntryCount() - 1 );
511 #ifdef WNT
512 // hack: #31355# W.P.
513 Rectangle aRect( m_pLbGradients->GetPosPixel(), m_pLbGradients->GetSizePixel() );
514 if( sal_True ) { // ??? overlapped with pDlg
515 // and srolling
516 Invalidate( aRect );
518 #endif
520 *pnGradientListState |= ChangeType::MODIFIED;
522 ChangeGradientHdl_Impl( this );
525 // determine button state
526 if( pGradientList->Count() )
528 m_pBtnModify->Enable();
529 m_pBtnDelete->Enable();
530 m_pBtnSave->Enable();
532 return 0L;
537 IMPL_LINK_NOARG(SvxGradientTabPage, ClickModifyHdl_Impl)
539 sal_Int32 nPos = m_pLbGradients->GetSelectEntryPos();
541 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
543 OUString aDesc( CUI_RES( RID_SVXSTR_DESC_GRADIENT ) );
544 OUString aName( pGradientList->GetGradient( nPos )->GetName() );
545 OUString aOldName = aName;
547 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
548 DBG_ASSERT(pFact, "Dialog creation failed!");
549 boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ));
550 DBG_ASSERT(pDlg, "Dialog creation failed!");
552 long nCount = pGradientList->Count();
553 bool bLoop = true;
555 while( bLoop && pDlg->Execute() == RET_OK )
557 pDlg->GetName( aName );
558 bool bDifferent = true;
560 for( long i = 0; i < nCount && bDifferent; i++ )
562 if( aName == pGradientList->GetGradient( i )->GetName() &&
563 aName != aOldName )
564 bDifferent = false;
567 if( bDifferent )
569 bLoop = false;
570 XGradient aXGradient( m_pLbColorFrom->GetSelectEntryColor(),
571 m_pLbColorTo->GetSelectEntryColor(),
572 (css::awt::GradientStyle) m_pLbGradientType->GetSelectEntryPos(),
573 static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
574 (sal_uInt16) m_pMtrCenterX->GetValue(),
575 (sal_uInt16) m_pMtrCenterY->GetValue(),
576 (sal_uInt16) m_pMtrBorder->GetValue(),
577 (sal_uInt16) m_pMtrColorFrom->GetValue(),
578 (sal_uInt16) m_pMtrColorTo->GetValue() );
580 XGradientEntry* pEntry = new XGradientEntry( aXGradient, aName );
582 delete pGradientList->Replace( pEntry, nPos );
584 m_pLbGradients->Modify( *pEntry, nPos, pGradientList->GetUiBitmap( nPos ) );
586 m_pLbGradients->SelectEntryPos( nPos );
588 *pnGradientListState |= ChangeType::MODIFIED;
590 else
592 ScopedVclPtrInstance<MessageDialog> aBox( GetParentDialog()
593 ,"DuplicateNameDialog"
594 ,"cui/ui/queryduplicatedialog.ui" );
595 aBox->Execute();
600 return 0L;
605 IMPL_LINK_NOARG(SvxGradientTabPage, ClickDeleteHdl_Impl)
607 sal_Int32 nPos = m_pLbGradients->GetSelectEntryPos();
609 if( nPos != LISTBOX_ENTRY_NOTFOUND )
611 ScopedVclPtrInstance< MessageDialog > aQueryBox( GetParentDialog(),"AskDelGradientDialog","cui/ui/querydeletegradientdialog.ui");
613 if ( aQueryBox->Execute() == RET_YES )
615 delete pGradientList->Remove( nPos );
616 m_pLbGradients->RemoveEntry( nPos );
617 m_pLbGradients->SelectEntryPos( 0 );
619 m_pCtlPreview->Invalidate();
621 ChangeGradientHdl_Impl( this );
623 *pnGradientListState |= ChangeType::MODIFIED;
626 // determine button state
627 if( !pGradientList->Count() )
629 m_pBtnModify->Disable();
630 m_pBtnDelete->Disable();
631 m_pBtnSave->Disable();
633 return 0L;
638 IMPL_LINK_NOARG(SvxGradientTabPage, ClickLoadHdl_Impl)
640 ResMgr& rMgr = CUI_MGR();
641 sal_uInt16 nReturn = RET_YES;
643 if ( *pnGradientListState & ChangeType::MODIFIED )
645 nReturn = ScopedVclPtrInstance<MessageDialog>::Create( GetParentDialog()
646 ,"AskSaveList"
647 ,"cui/ui/querysavelistdialog.ui")->Execute();
649 if ( nReturn == RET_YES )
650 pGradientList->Save();
653 if ( nReturn != RET_CANCEL )
655 ::sfx2::FileDialogHelper aDlg( com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
656 OUString aStrFilterType( "*.sog" );
657 aDlg.AddFilter( aStrFilterType, aStrFilterType );
658 INetURLObject aFile( SvtPathOptions().GetPalettePath() );
659 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
661 if( aDlg.Execute() == ERRCODE_NONE )
663 EnterWait();
665 INetURLObject aURL( aDlg.GetPath() );
666 INetURLObject aPathURL( aURL );
668 aPathURL.removeSegment();
669 aPathURL.removeFinalSlash();
671 // save list
672 XGradientListRef pGrdList = XPropertyList::AsGradientList(
673 XPropertyList::CreatePropertyList(
674 XGRADIENT_LIST,
675 aPathURL.GetMainURL(INetURLObject::NO_DECODE), ""));
676 pGrdList->SetName( aURL.getName() );
678 if ( pGrdList->Load() )
680 pGradientList = pGrdList;
681 static_cast<SvxAreaTabDialog*>( GetParentDialog() )->
682 SetNewGradientList( pGradientList );
684 m_pLbGradients->Clear();
685 m_pLbGradients->Fill( pGradientList );
686 Reset( &rOutAttrs );
688 pGradientList->SetName( aURL.getName() );
690 // determining (possibly cutting) the name
691 // and displaying it in the GroupBox
692 OUString aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
693 aString += ": ";
695 if ( aURL.getBase().getLength() > 18 )
697 aString += aURL.getBase().copy( 0, 15 );
698 aString += "...";
700 else
701 aString += aURL.getBase();
703 *pnGradientListState |= ChangeType::CHANGED;
704 *pnGradientListState &= ~ChangeType::MODIFIED;
705 LeaveWait();
707 else
709 LeaveWait();
710 ScopedVclPtrInstance<MessageDialog>::Create( GetParentDialog()
711 ,"NoLoadedFileDialog"
712 ,"cui/ui/querynoloadedfiledialog.ui")->Execute();
717 // determine button state
718 if( pGradientList->Count() )
720 m_pBtnModify->Enable();
721 m_pBtnDelete->Enable();
722 m_pBtnSave->Enable();
724 else
726 m_pBtnModify->Disable();
727 m_pBtnDelete->Disable();
728 m_pBtnSave->Disable();
730 return 0L;
735 IMPL_LINK_NOARG(SvxGradientTabPage, ClickSaveHdl_Impl)
737 ::sfx2::FileDialogHelper aDlg(
738 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
739 OUString aStrFilterType( "*.sog" );
740 aDlg.AddFilter( aStrFilterType, aStrFilterType );
742 INetURLObject aFile( SvtPathOptions().GetPalettePath() );
743 DBG_ASSERT( aFile.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
745 if( !pGradientList->GetName().isEmpty() )
747 aFile.Append( pGradientList->GetName() );
749 if( aFile.getExtension().isEmpty() )
750 aFile.SetExtension( OUString("sog") );
753 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
754 if ( aDlg.Execute() == ERRCODE_NONE )
756 INetURLObject aURL( aDlg.GetPath() );
757 INetURLObject aPathURL( aURL );
759 aPathURL.removeSegment();
760 aPathURL.removeFinalSlash();
762 pGradientList->SetName( aURL.getName() );
763 pGradientList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
765 if( pGradientList->Save() )
767 // determining (possibly cutting) the name
768 // and displaying it in the GroupBox
769 OUString aString( CUI_RES( RID_SVXSTR_TABLE ) );
770 aString += ": ";
772 if ( aURL.getBase().getLength() > 18 )
774 aString += aURL.getBase().copy( 0, 15 );
775 aString += "...";
777 else
778 aString += aURL.getBase();
780 *pnGradientListState |= ChangeType::SAVED;
781 *pnGradientListState &= ~ChangeType::MODIFIED;
783 else
785 ScopedVclPtrInstance<MessageDialog>::Create( GetParentDialog()
786 ,"NoSaveFileDialog"
787 ,"cui/ui/querynosavefiledialog.ui")->Execute();
791 return 0L;
796 IMPL_LINK_NOARG(SvxGradientTabPage, ChangeGradientHdl_Impl)
798 boost::scoped_ptr<XGradient> pGradient;
799 int nPos = m_pLbGradients->GetSelectEntryPos();
801 if( nPos != LISTBOX_ENTRY_NOTFOUND )
802 pGradient.reset(new XGradient( pGradientList->GetGradient( nPos )->GetGradient() ));
803 else
805 const SfxPoolItem* pPoolItem = NULL;
806 if( SfxItemState::SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), true, &pPoolItem ) )
808 if( ( drawing::FillStyle_GRADIENT == (drawing::FillStyle) static_cast<const XFillStyleItem*>( pPoolItem )->GetValue() ) &&
809 ( SfxItemState::SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLGRADIENT ), true, &pPoolItem ) ) )
811 pGradient.reset(new XGradient( static_cast<const XFillGradientItem*>( pPoolItem )->GetGradientValue() ));
814 if( !pGradient )
816 m_pLbGradients->SelectEntryPos( 0 );
817 nPos = m_pLbGradients->GetSelectEntryPos();
818 if( nPos != LISTBOX_ENTRY_NOTFOUND )
819 pGradient.reset(new XGradient( pGradientList->GetGradient( nPos )->GetGradient() ));
823 if( pGradient )
825 css::awt::GradientStyle eXGS = pGradient->GetGradientStyle();
827 m_pLbGradientType->SelectEntryPos(
828 sal::static_int_cast< sal_Int32 >( eXGS ) );
829 // if the entry is not in the listbox,
830 // colors are added temporarily
831 m_pLbColorFrom->SetNoSelection();
832 m_pLbColorFrom->SelectEntry( pGradient->GetStartColor() );
834 if ( m_pLbColorFrom->GetSelectEntryCount() == 0 )
836 m_pLbColorFrom->InsertEntry( pGradient->GetStartColor(),
837 OUString() );
838 m_pLbColorFrom->SelectEntry( pGradient->GetStartColor() );
840 m_pLbColorTo->SetNoSelection();
841 m_pLbColorTo->SelectEntry( pGradient->GetEndColor() );
843 if ( m_pLbColorTo->GetSelectEntryCount() == 0 )
845 m_pLbColorTo->InsertEntry( pGradient->GetEndColor(), OUString() );
846 m_pLbColorTo->SelectEntry( pGradient->GetEndColor() );
849 m_pMtrAngle->SetValue( pGradient->GetAngle() / 10 ); // should be changed in resource
850 m_pMtrBorder->SetValue( pGradient->GetBorder() );
851 m_pMtrCenterX->SetValue( pGradient->GetXOffset() );
852 m_pMtrCenterY->SetValue( pGradient->GetYOffset() );
853 m_pMtrColorFrom->SetValue( pGradient->GetStartIntens() );
854 m_pMtrColorTo->SetValue( pGradient->GetEndIntens() );
856 // disable/enable controls
857 SetControlState_Impl( eXGS );
859 // fill ItemSet and pass it on to aCtlPreview
860 rXFSet.Put( XFillGradientItem( OUString(), *pGradient ) );
861 m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
863 m_pCtlPreview->Invalidate();
865 return 0L;
870 void SvxGradientTabPage::SetControlState_Impl( css::awt::GradientStyle eXGS )
872 switch( eXGS )
874 case css::awt::GradientStyle_LINEAR:
875 case css::awt::GradientStyle_AXIAL:
876 m_pFtCenterX->Disable();
877 m_pMtrCenterX->Disable();
878 m_pFtCenterY->Disable();
879 m_pMtrCenterY->Disable();
880 m_pFtAngle->Enable();
881 m_pMtrAngle->Enable();
882 break;
884 case css::awt::GradientStyle_RADIAL:
885 m_pFtCenterX->Enable();
886 m_pMtrCenterX->Enable();
887 m_pFtCenterY->Enable();
888 m_pMtrCenterY->Enable();
889 m_pFtAngle->Disable();
890 m_pMtrAngle->Disable();
891 break;
893 case css::awt::GradientStyle_ELLIPTICAL:
894 m_pFtCenterX->Enable();
895 m_pMtrCenterX->Enable();
896 m_pFtCenterY->Enable();
897 m_pMtrCenterY->Enable();
898 m_pFtAngle->Enable();
899 m_pMtrAngle->Enable();
900 break;
902 case css::awt::GradientStyle_SQUARE:
903 case css::awt::GradientStyle_RECT:
904 m_pFtCenterX->Enable();
905 m_pMtrCenterX->Enable();
906 m_pFtCenterY->Enable();
907 m_pMtrCenterY->Enable();
908 m_pFtAngle->Enable();
909 m_pMtrAngle->Enable();
910 break;
911 default:
912 break;
917 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */