Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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/dialoghelper.hxx>
27 : #include <sfx2/filedlghelper.hxx>
28 : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
29 :
30 : #include <cuires.hrc>
31 : #include "helpid.hrc"
32 : #include "svx/xattr.hxx"
33 : #include <svx/xtable.hxx>
34 : #include <svx/xpool.hxx>
35 : #include "svx/drawitem.hxx"
36 : #include "cuitabarea.hxx"
37 : #include "tabarea.hrc"
38 : #include "defdlgname.hxx"
39 : #include "dlgname.hxx"
40 : #include <svx/svxdlg.hxx>
41 : #include <dialmgr.hxx>
42 : #include <svx/dialmgr.hxx>
43 : #include <svx/dialogs.hrc>
44 : #include "paragrph.hrc"
45 :
46 0 : SvxGradientTabPage::SvxGradientTabPage
47 : (
48 : Window* pParent,
49 : const SfxItemSet& rInAttrs
50 : ) :
51 : SfxTabPage ( pParent, "GradientPage", "cui/ui/gradientpage.ui", rInAttrs ),
52 :
53 : rOutAttrs ( rInAttrs ),
54 :
55 : pnGradientListState ( 0 ),
56 : pnColorListState ( 0 ),
57 : pPageType ( 0 ),
58 : pDlgType ( 0 ),
59 : pPos ( 0 ),
60 : pbAreaTP ( 0 ),
61 :
62 0 : pXPool ( (XOutdevItemPool*) rInAttrs.GetPool() ),
63 : aXFStyleItem ( XFILL_GRADIENT ),
64 : aXGradientItem ( String(), XGradient( COL_BLACK, COL_WHITE ) ),
65 : aXFillAttr ( pXPool ),
66 0 : rXFSet ( aXFillAttr.GetItemSet() )
67 : {
68 0 : get(m_pLbGradientType, "gradienttypelb");
69 0 : get(m_pFtCenterX, "centerxft");
70 0 : get(m_pMtrCenterX, "centerxmtr");
71 0 : get(m_pFtCenterY, "centeryft");
72 0 : get(m_pMtrCenterY, "centerymtr");
73 0 : get(m_pFtAngle, "angleft");
74 0 : get(m_pMtrAngle, "anglemtr");
75 0 : m_pMtrAngle->SetUnit(FUNIT_CUSTOM);
76 0 : get(m_pFtAngleDegrees, "anglemtrdegrees");
77 0 : m_pMtrAngle->SetCustomUnitText(m_pFtAngleDegrees->GetText());
78 0 : get(m_pMtrBorder, "bordermtr");
79 0 : get(m_pLbColorFrom, "colorfromlb");
80 0 : get(m_pMtrColorFrom, "colorfrommtr");
81 0 : get(m_pLbColorTo, "colortolb");
82 0 : get(m_pMtrColorTo, "colortomtr");
83 0 : get(m_pLbGradients, "gradientslb");
84 0 : Size aSize = LogicToPixel(Size(88, 110), MAP_APPFONT);
85 0 : m_pLbGradients->set_width_request(aSize.Width());
86 0 : m_pLbGradients->set_height_request(aSize.Height());
87 0 : get(m_pCtlPreview, "previewctl");
88 0 : aSize = LogicToPixel(Size(88, 42), MAP_APPFONT);
89 0 : m_pCtlPreview->set_width_request(aSize.Width());
90 0 : m_pCtlPreview->set_height_request(aSize.Height());
91 0 : get(m_pBtnAdd, "add");
92 0 : get(m_pBtnModify, "modify");
93 0 : get(m_pBtnDelete, "delete");
94 0 : get(m_pBtnLoad, "load");
95 0 : get(m_pBtnSave, "save");
96 :
97 0 : m_pLbGradients->SetAccessibleName(GetText());
98 :
99 :
100 : // this page needs ExchangeSupport
101 0 : SetExchangeSupport();
102 :
103 : // as long as NOT supported by the item
104 :
105 0 : m_pMtrColorTo->SetValue( 100 );
106 0 : m_pMtrColorFrom->SetValue( 100 );
107 :
108 : // setting the output device
109 0 : rXFSet.Put( aXFStyleItem );
110 0 : rXFSet.Put( aXGradientItem );
111 0 : m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
112 :
113 : // overload the handler
114 : m_pLbGradients->SetSelectHdl(
115 0 : LINK( this, SvxGradientTabPage, ChangeGradientHdl_Impl ) );
116 0 : m_pBtnAdd->SetClickHdl( LINK( this, SvxGradientTabPage, ClickAddHdl_Impl ) );
117 : m_pBtnModify->SetClickHdl(
118 0 : LINK( this, SvxGradientTabPage, ClickModifyHdl_Impl ) );
119 : m_pBtnDelete->SetClickHdl(
120 0 : LINK( this, SvxGradientTabPage, ClickDeleteHdl_Impl ) );
121 :
122 0 : Link aLink = LINK( this, SvxGradientTabPage, ModifiedHdl_Impl );
123 0 : m_pLbGradientType->SetSelectHdl( aLink );
124 0 : m_pMtrCenterX->SetModifyHdl( aLink );
125 0 : m_pMtrCenterY->SetModifyHdl( aLink );
126 0 : m_pMtrAngle->SetModifyHdl( aLink );
127 0 : m_pMtrBorder->SetModifyHdl( aLink );
128 0 : m_pMtrColorFrom->SetModifyHdl( aLink );
129 0 : m_pLbColorFrom->SetSelectHdl( aLink );
130 0 : m_pMtrColorTo->SetModifyHdl( aLink );
131 0 : m_pLbColorTo->SetSelectHdl( aLink );
132 :
133 : m_pBtnLoad->SetClickHdl(
134 0 : LINK( this, SvxGradientTabPage, ClickLoadHdl_Impl ) );
135 : m_pBtnSave->SetClickHdl(
136 0 : LINK( this, SvxGradientTabPage, ClickSaveHdl_Impl ) );
137 :
138 : // #i76307# always paint the preview in LTR, because this is what the document does
139 0 : m_pCtlPreview->EnableRTL( sal_False );
140 :
141 0 : setPreviewsToSamePlace(pParent, this);
142 0 : }
143 :
144 : // -----------------------------------------------------------------------
145 :
146 0 : void SvxGradientTabPage::Construct()
147 : {
148 0 : m_pLbColorFrom->Fill( pColorList );
149 0 : m_pLbColorTo->CopyEntries( *m_pLbColorFrom );
150 :
151 0 : m_pLbGradients->Fill( pGradientList );
152 0 : }
153 :
154 : // -----------------------------------------------------------------------
155 :
156 0 : void SvxGradientTabPage::ActivatePage( const SfxItemSet& )
157 : {
158 : sal_uInt16 nPos;
159 : sal_uInt16 nCount;
160 :
161 0 : if( *pDlgType == 0 ) // area dialog
162 : {
163 0 : *pbAreaTP = sal_False;
164 :
165 0 : if( pColorList.is() )
166 : {
167 : // ColorList
168 0 : if( *pnColorListState & CT_CHANGED ||
169 0 : *pnColorListState & CT_MODIFIED )
170 : {
171 0 : if( *pnColorListState & CT_CHANGED )
172 0 : pColorList = ( (SvxAreaTabDialog*) GetParentDialog() )->GetNewColorList();
173 :
174 : // LbColorFrom
175 0 : nPos = m_pLbColorFrom->GetSelectEntryPos();
176 0 : m_pLbColorFrom->Clear();
177 0 : m_pLbColorFrom->Fill( pColorList );
178 0 : nCount = m_pLbColorFrom->GetEntryCount();
179 0 : if( nCount == 0 )
180 : ; // this case should not occur
181 0 : else if( nCount <= nPos )
182 0 : m_pLbColorFrom->SelectEntryPos( 0 );
183 : else
184 0 : m_pLbColorFrom->SelectEntryPos( nPos );
185 :
186 : // LbColorTo
187 0 : nPos = m_pLbColorTo->GetSelectEntryPos();
188 0 : m_pLbColorTo->Clear();
189 0 : m_pLbColorTo->CopyEntries( *m_pLbColorFrom );
190 0 : nCount = m_pLbColorTo->GetEntryCount();
191 0 : if( nCount == 0 )
192 : ; // this case should not occur
193 0 : else if( nCount <= nPos )
194 0 : m_pLbColorTo->SelectEntryPos( 0 );
195 : else
196 0 : m_pLbColorTo->SelectEntryPos( nPos );
197 :
198 0 : ModifiedHdl_Impl( this );
199 : }
200 :
201 : // determining (and possibly cutting) the name and
202 : // displaying it in the GroupBox
203 0 : OUString aString( CUI_RES( RID_SVXSTR_TABLE ) );
204 0 : aString += ": ";
205 0 : INetURLObject aURL( pGradientList->GetPath() );
206 :
207 0 : aURL.Append( pGradientList->GetName() );
208 : DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
209 :
210 0 : if ( aURL.getBase().getLength() > 18 )
211 : {
212 0 : aString += aURL.getBase().copy( 0, 15 );
213 0 : aString += "...";
214 : }
215 : else
216 0 : aString += aURL.getBase();
217 :
218 0 : if ( *pPageType == PT_GRADIENT && *pPos != LISTBOX_ENTRY_NOTFOUND )
219 : {
220 0 : m_pLbGradients->SelectEntryPos( *pPos );
221 : }
222 : // colors could have been deleted
223 0 : ChangeGradientHdl_Impl( this );
224 :
225 0 : *pPageType = PT_GRADIENT;
226 0 : *pPos = LISTBOX_ENTRY_NOTFOUND;
227 : }
228 : }
229 0 : }
230 :
231 : // -----------------------------------------------------------------------
232 :
233 0 : int SvxGradientTabPage::DeactivatePage( SfxItemSet* _pSet )
234 : {
235 0 : if( CheckChanges_Impl() == -1L )
236 0 : return KEEP_PAGE;
237 :
238 0 : if( _pSet )
239 0 : FillItemSet( *_pSet );
240 :
241 0 : return LEAVE_PAGE;
242 : }
243 :
244 : // -----------------------------------------------------------------------
245 :
246 0 : long SvxGradientTabPage::CheckChanges_Impl()
247 : {
248 : // is used here in order to NOT lose changes
249 0 : XGradient aTmpGradient( m_pLbColorFrom->GetSelectEntryColor(),
250 0 : m_pLbColorTo->GetSelectEntryColor(),
251 0 : (XGradientStyle) m_pLbGradientType->GetSelectEntryPos(),
252 0 : static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
253 0 : (sal_uInt16) m_pMtrCenterX->GetValue(),
254 0 : (sal_uInt16) m_pMtrCenterY->GetValue(),
255 0 : (sal_uInt16) m_pMtrBorder->GetValue(),
256 0 : (sal_uInt16) m_pMtrColorFrom->GetValue(),
257 0 : (sal_uInt16) m_pMtrColorTo->GetValue() );
258 :
259 0 : sal_uInt16 nPos = m_pLbGradients->GetSelectEntryPos();
260 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
261 : {
262 0 : XGradient aGradient = pGradientList->GetGradient( nPos )->GetGradient();
263 :
264 0 : if( !( aTmpGradient == aGradient ) )
265 : {
266 0 : ResMgr& rMgr = CUI_MGR();
267 0 : Image aWarningBoxImage = WarningBox::GetStandardImage();
268 0 : SvxMessDialog* aMessDlg = new SvxMessDialog(GetParentDialog(),
269 0 : SVX_RESSTR( RID_SVXSTR_GRADIENT ),
270 0 : CUI_RESSTR( RID_SVXSTR_ASK_CHANGE_GRADIENT ),
271 0 : &aWarningBoxImage );
272 : DBG_ASSERT(aMessDlg, "Dialogdiet fail!");
273 : aMessDlg->SetButtonText( MESS_BTN_1,
274 0 : String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
275 : aMessDlg->SetButtonText( MESS_BTN_2,
276 0 : String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
277 :
278 0 : short nRet = aMessDlg->Execute();
279 :
280 0 : switch( nRet )
281 : {
282 : case RET_BTN_1:
283 : {
284 0 : ClickModifyHdl_Impl( this );
285 0 : aGradient = pGradientList->GetGradient( nPos )->GetGradient();
286 : }
287 0 : break;
288 :
289 : case RET_BTN_2:
290 : {
291 0 : ClickAddHdl_Impl( this );
292 0 : nPos = m_pLbGradients->GetSelectEntryPos();
293 0 : aGradient = pGradientList->GetGradient( nPos )->GetGradient();
294 : }
295 0 : break;
296 :
297 : case RET_CANCEL:
298 0 : break;
299 : }
300 0 : delete aMessDlg;
301 : }
302 : }
303 0 : nPos = m_pLbGradients->GetSelectEntryPos();
304 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
305 : {
306 0 : *pPos = nPos;
307 : }
308 0 : return 0L;
309 : }
310 :
311 : // -----------------------------------------------------------------------
312 :
313 0 : sal_Bool SvxGradientTabPage::FillItemSet( SfxItemSet& rSet )
314 : {
315 0 : if( *pDlgType == 0 && *pPageType == PT_GRADIENT && *pbAreaTP == sal_False )
316 : {
317 : // CheckChanges(); <-- duplicate inquiry ?
318 :
319 0 : XGradient* pXGradient = NULL;
320 0 : String aString;
321 0 : sal_uInt16 nPos = m_pLbGradients->GetSelectEntryPos();
322 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
323 : {
324 0 : pXGradient = new XGradient( pGradientList->GetGradient( nPos )->GetGradient() );
325 0 : aString = m_pLbGradients->GetSelectEntry();
326 :
327 : }
328 : else
329 : // gradient was passed (unidentified)
330 : {
331 0 : pXGradient = new XGradient( m_pLbColorFrom->GetSelectEntryColor(),
332 0 : m_pLbColorTo->GetSelectEntryColor(),
333 0 : (XGradientStyle) m_pLbGradientType->GetSelectEntryPos(),
334 0 : static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
335 0 : (sal_uInt16) m_pMtrCenterX->GetValue(),
336 0 : (sal_uInt16) m_pMtrCenterY->GetValue(),
337 0 : (sal_uInt16) m_pMtrBorder->GetValue(),
338 0 : (sal_uInt16) m_pMtrColorFrom->GetValue(),
339 0 : (sal_uInt16) m_pMtrColorTo->GetValue() );
340 : }
341 : DBG_ASSERT( pXGradient, "XGradient konnte nicht erzeugt werden" );
342 0 : rSet.Put( XFillStyleItem( XFILL_GRADIENT ) );
343 0 : rSet.Put( XFillGradientItem( aString, *pXGradient ) );
344 :
345 0 : delete pXGradient;
346 : }
347 0 : return sal_True;
348 : }
349 :
350 : // -----------------------------------------------------------------------
351 :
352 0 : void SvxGradientTabPage::Reset( const SfxItemSet& )
353 : {
354 : // m_pLbGradients->SelectEntryPos( 0 );
355 0 : ChangeGradientHdl_Impl( this );
356 :
357 : // determine state of the buttons
358 0 : if( pGradientList->Count() )
359 : {
360 0 : m_pBtnModify->Enable();
361 0 : m_pBtnDelete->Enable();
362 0 : m_pBtnSave->Enable();
363 : }
364 : else
365 : {
366 0 : m_pBtnModify->Disable();
367 0 : m_pBtnDelete->Disable();
368 0 : m_pBtnSave->Disable();
369 : }
370 0 : }
371 :
372 : // -----------------------------------------------------------------------
373 :
374 0 : SfxTabPage* SvxGradientTabPage::Create( Window* pWindow,
375 : const SfxItemSet& rOutAttrs )
376 : {
377 0 : return new SvxGradientTabPage( pWindow, rOutAttrs );
378 : }
379 :
380 : //------------------------------------------------------------------------
381 :
382 0 : IMPL_LINK( SvxGradientTabPage, ModifiedHdl_Impl, void *, pControl )
383 : {
384 0 : XGradientStyle eXGS = (XGradientStyle) m_pLbGradientType->GetSelectEntryPos();
385 :
386 0 : XGradient aXGradient( m_pLbColorFrom->GetSelectEntryColor(),
387 0 : m_pLbColorTo->GetSelectEntryColor(),
388 : eXGS,
389 0 : static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
390 0 : (sal_uInt16) m_pMtrCenterX->GetValue(),
391 0 : (sal_uInt16) m_pMtrCenterY->GetValue(),
392 0 : (sal_uInt16) m_pMtrBorder->GetValue(),
393 0 : (sal_uInt16) m_pMtrColorFrom->GetValue(),
394 0 : (sal_uInt16) m_pMtrColorTo->GetValue() );
395 :
396 : // enable/disable controls
397 0 : if( pControl == m_pLbGradientType || pControl == this )
398 0 : SetControlState_Impl( eXGS );
399 :
400 : // displaying in XOutDev
401 0 : rXFSet.Put( XFillGradientItem( String(), aXGradient ) );
402 0 : m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
403 :
404 0 : m_pCtlPreview->Invalidate();
405 :
406 0 : return 0L;
407 : }
408 :
409 : //------------------------------------------------------------------------
410 :
411 0 : IMPL_LINK_NOARG(SvxGradientTabPage, ClickAddHdl_Impl)
412 : {
413 0 : ResMgr& rMgr = CUI_MGR();
414 0 : String aNewName( SVX_RES( RID_SVXSTR_GRADIENT ) );
415 0 : String aDesc( CUI_RES( RID_SVXSTR_DESC_GRADIENT ) );
416 0 : String aName;
417 :
418 0 : long nCount = pGradientList->Count();
419 0 : long j = 1;
420 0 : sal_Bool bDifferent = sal_False;
421 :
422 0 : while( !bDifferent )
423 : {
424 0 : aName = aNewName;
425 0 : aName += sal_Unicode(' ');
426 0 : aName += OUString::valueOf( j++ );
427 0 : bDifferent = sal_True;
428 :
429 0 : for( long i = 0; i < nCount && bDifferent; i++ )
430 0 : if( aName == pGradientList->GetGradient( i )->GetName() )
431 0 : bDifferent = sal_False;
432 : }
433 :
434 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
435 : DBG_ASSERT(pFact, "Dialogdiet fail!");
436 0 : AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
437 : DBG_ASSERT(pDlg, "Dialogdiet fail!");
438 0 : WarningBox* pWarnBox = NULL;
439 0 : sal_uInt16 nError = RID_SVXSTR_WARN_NAME_DUPLICATE;
440 :
441 0 : while( pDlg->Execute() == RET_OK )
442 : {
443 0 : pDlg->GetName( aName );
444 :
445 0 : bDifferent = sal_True;
446 :
447 0 : for( long i = 0; i < nCount && bDifferent; i++ )
448 0 : if( aName == pGradientList->GetGradient( i )->GetName() )
449 0 : bDifferent = sal_False;
450 :
451 0 : if( bDifferent )
452 : {
453 0 : nError = 0;
454 0 : break;
455 : }
456 :
457 0 : if( !pWarnBox )
458 : {
459 0 : pWarnBox = new WarningBox( GetParentDialog(),
460 : WinBits( WB_OK_CANCEL ),
461 0 : String( ResId( nError, rMgr ) ) );
462 0 : pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
463 : }
464 :
465 0 : if( pWarnBox->Execute() != RET_OK )
466 0 : break;
467 : }
468 0 : delete pDlg;
469 0 : delete pWarnBox;
470 :
471 0 : if( !nError )
472 : {
473 0 : XGradient aXGradient( m_pLbColorFrom->GetSelectEntryColor(),
474 0 : m_pLbColorTo->GetSelectEntryColor(),
475 0 : (XGradientStyle) m_pLbGradientType->GetSelectEntryPos(),
476 0 : static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
477 0 : (sal_uInt16) m_pMtrCenterX->GetValue(),
478 0 : (sal_uInt16) m_pMtrCenterY->GetValue(),
479 0 : (sal_uInt16) m_pMtrBorder->GetValue(),
480 0 : (sal_uInt16) m_pMtrColorFrom->GetValue(),
481 0 : (sal_uInt16) m_pMtrColorTo->GetValue() );
482 0 : XGradientEntry* pEntry = new XGradientEntry( aXGradient, aName );
483 :
484 0 : pGradientList->Insert( pEntry, nCount );
485 :
486 0 : m_pLbGradients->Append( *pEntry, pGradientList->GetUiBitmap( nCount ) );
487 :
488 0 : m_pLbGradients->SelectEntryPos( m_pLbGradients->GetEntryCount() - 1 );
489 :
490 : #ifdef WNT
491 : // hack: #31355# W.P.
492 : Rectangle aRect( m_pLbGradients->GetPosPixel(), m_pLbGradients->GetSizePixel() );
493 : if( sal_True ) { // ??? overlapped with pDlg
494 : // and srolling
495 : Invalidate( aRect );
496 : }
497 : #endif
498 :
499 0 : *pnGradientListState |= CT_MODIFIED;
500 :
501 0 : ChangeGradientHdl_Impl( this );
502 : }
503 :
504 : // determine button state
505 0 : if( pGradientList->Count() )
506 : {
507 0 : m_pBtnModify->Enable();
508 0 : m_pBtnDelete->Enable();
509 0 : m_pBtnSave->Enable();
510 : }
511 0 : return 0L;
512 : }
513 :
514 : //------------------------------------------------------------------------
515 :
516 0 : IMPL_LINK_NOARG(SvxGradientTabPage, ClickModifyHdl_Impl)
517 : {
518 0 : sal_uInt16 nPos = m_pLbGradients->GetSelectEntryPos();
519 :
520 0 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
521 : {
522 0 : ResMgr& rMgr = CUI_MGR();
523 0 : String aDesc( CUI_RES( RID_SVXSTR_DESC_GRADIENT ) );
524 0 : String aName( pGradientList->GetGradient( nPos )->GetName() );
525 0 : String aOldName = aName;
526 :
527 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
528 : DBG_ASSERT(pFact, "Dialogdiet fail!");
529 0 : AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
530 : DBG_ASSERT(pDlg, "Dialogdiet fail!");
531 :
532 0 : long nCount = pGradientList->Count();
533 0 : sal_Bool bDifferent = sal_False;
534 0 : sal_Bool bLoop = sal_True;
535 :
536 0 : while( bLoop && pDlg->Execute() == RET_OK )
537 : {
538 0 : pDlg->GetName( aName );
539 0 : bDifferent = sal_True;
540 :
541 0 : for( long i = 0; i < nCount && bDifferent; i++ )
542 : {
543 0 : if( aName == pGradientList->GetGradient( i )->GetName() &&
544 0 : aName != aOldName )
545 0 : bDifferent = sal_False;
546 : }
547 :
548 0 : if( bDifferent )
549 : {
550 0 : bLoop = sal_False;
551 0 : XGradient aXGradient( m_pLbColorFrom->GetSelectEntryColor(),
552 0 : m_pLbColorTo->GetSelectEntryColor(),
553 0 : (XGradientStyle) m_pLbGradientType->GetSelectEntryPos(),
554 0 : static_cast<long>(m_pMtrAngle->GetValue() * 10), // should be changed in resource
555 0 : (sal_uInt16) m_pMtrCenterX->GetValue(),
556 0 : (sal_uInt16) m_pMtrCenterY->GetValue(),
557 0 : (sal_uInt16) m_pMtrBorder->GetValue(),
558 0 : (sal_uInt16) m_pMtrColorFrom->GetValue(),
559 0 : (sal_uInt16) m_pMtrColorTo->GetValue() );
560 :
561 0 : XGradientEntry* pEntry = new XGradientEntry( aXGradient, aName );
562 :
563 0 : delete pGradientList->Replace( pEntry, nPos );
564 :
565 0 : m_pLbGradients->Modify( *pEntry, nPos, pGradientList->GetUiBitmap( nPos ) );
566 :
567 0 : m_pLbGradients->SelectEntryPos( nPos );
568 :
569 0 : *pnGradientListState |= CT_MODIFIED;
570 : }
571 : else
572 : {
573 0 : WarningBox aBox( GetParentDialog(), WinBits( WB_OK ),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
574 0 : aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
575 0 : aBox.Execute();
576 : }
577 :
578 : }
579 0 : delete pDlg;
580 : }
581 0 : return 0L;
582 : }
583 :
584 : //------------------------------------------------------------------------
585 :
586 0 : IMPL_LINK_NOARG(SvxGradientTabPage, ClickDeleteHdl_Impl)
587 : {
588 0 : sal_uInt16 nPos = m_pLbGradients->GetSelectEntryPos();
589 :
590 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
591 : {
592 0 : QueryBox aQueryBox( GetParentDialog(), WinBits( WB_YES_NO | WB_DEF_NO ),
593 0 : String( CUI_RES( RID_SVXSTR_ASK_DEL_GRADIENT ) ) );
594 :
595 0 : if ( aQueryBox.Execute() == RET_YES )
596 : {
597 0 : delete pGradientList->Remove( nPos );
598 0 : m_pLbGradients->RemoveEntry( nPos );
599 0 : m_pLbGradients->SelectEntryPos( 0 );
600 :
601 0 : m_pCtlPreview->Invalidate();
602 :
603 0 : ChangeGradientHdl_Impl( this );
604 :
605 0 : *pnGradientListState |= CT_MODIFIED;
606 0 : }
607 : }
608 : // determine button state
609 0 : if( !pGradientList->Count() )
610 : {
611 0 : m_pBtnModify->Disable();
612 0 : m_pBtnDelete->Disable();
613 0 : m_pBtnSave->Disable();
614 : }
615 0 : return 0L;
616 : }
617 :
618 : // -----------------------------------------------------------------------
619 :
620 0 : IMPL_LINK_NOARG(SvxGradientTabPage, ClickLoadHdl_Impl)
621 : {
622 0 : ResMgr& rMgr = CUI_MGR();
623 0 : sal_uInt16 nReturn = RET_YES;
624 :
625 0 : if ( *pnGradientListState & CT_MODIFIED )
626 : {
627 0 : nReturn = WarningBox( GetParentDialog(), WinBits( WB_YES_NO_CANCEL ),
628 0 : String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
629 :
630 0 : if ( nReturn == RET_YES )
631 0 : pGradientList->Save();
632 : }
633 :
634 0 : if ( nReturn != RET_CANCEL )
635 : {
636 : ::sfx2::FileDialogHelper aDlg(
637 : com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
638 0 : 0 );
639 0 : String aStrFilterType( "*.sog" );
640 0 : aDlg.AddFilter( aStrFilterType, aStrFilterType );
641 0 : INetURLObject aFile( SvtPathOptions().GetPalettePath() );
642 0 : aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
643 :
644 0 : if( aDlg.Execute() == ERRCODE_NONE )
645 : {
646 0 : EnterWait();
647 :
648 0 : INetURLObject aURL( aDlg.GetPath() );
649 0 : INetURLObject aPathURL( aURL );
650 :
651 0 : aPathURL.removeSegment();
652 0 : aPathURL.removeFinalSlash();
653 :
654 : // save list
655 : XGradientListRef pGrdList = XPropertyList::CreatePropertyList(
656 0 : XGRADIENT_LIST, aPathURL.GetMainURL( INetURLObject::NO_DECODE ) )->AsGradientList();
657 0 : pGrdList->SetName( aURL.getName() );
658 :
659 0 : if ( pGrdList->Load() )
660 : {
661 0 : pGradientList = pGrdList;
662 0 : ( (SvxAreaTabDialog*) GetParentDialog() )->
663 0 : SetNewGradientList( pGradientList );
664 :
665 0 : m_pLbGradients->Clear();
666 0 : m_pLbGradients->Fill( pGradientList );
667 0 : Reset( rOutAttrs );
668 :
669 0 : pGradientList->SetName( aURL.getName() );
670 :
671 : // determining (possibly cutting) the name
672 : // and displaying it in the GroupBox
673 0 : OUString aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
674 0 : aString += ": ";
675 :
676 0 : if ( aURL.getBase().getLength() > 18 )
677 : {
678 0 : aString += aURL.getBase().copy( 0, 15 );
679 0 : aString += "...";
680 : }
681 : else
682 0 : aString += aURL.getBase();
683 :
684 0 : *pnGradientListState |= CT_CHANGED;
685 0 : *pnGradientListState &= ~CT_MODIFIED;
686 0 : LeaveWait();
687 : }
688 : else
689 : {
690 0 : LeaveWait();
691 0 : ErrorBox( GetParentDialog(), WinBits( WB_OK ),
692 0 : String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
693 0 : }
694 0 : }
695 : }
696 :
697 : // determine button state
698 0 : if( pGradientList->Count() )
699 : {
700 0 : m_pBtnModify->Enable();
701 0 : m_pBtnDelete->Enable();
702 0 : m_pBtnSave->Enable();
703 : }
704 : else
705 : {
706 0 : m_pBtnModify->Disable();
707 0 : m_pBtnDelete->Disable();
708 0 : m_pBtnSave->Disable();
709 : }
710 0 : return 0L;
711 : }
712 :
713 : // -----------------------------------------------------------------------
714 :
715 0 : IMPL_LINK_NOARG(SvxGradientTabPage, ClickSaveHdl_Impl)
716 : {
717 : ::sfx2::FileDialogHelper aDlg(
718 0 : com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
719 0 : String aStrFilterType( "*.sog" );
720 0 : aDlg.AddFilter( aStrFilterType, aStrFilterType );
721 :
722 0 : INetURLObject aFile( SvtPathOptions().GetPalettePath() );
723 : DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
724 :
725 0 : if( pGradientList->GetName().Len() )
726 : {
727 0 : aFile.Append( pGradientList->GetName() );
728 :
729 0 : if( aFile.getExtension().isEmpty() )
730 0 : aFile.SetExtension( OUString("sog") );
731 : }
732 :
733 0 : aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
734 0 : if ( aDlg.Execute() == ERRCODE_NONE )
735 : {
736 0 : INetURLObject aURL( aDlg.GetPath() );
737 0 : INetURLObject aPathURL( aURL );
738 :
739 0 : aPathURL.removeSegment();
740 0 : aPathURL.removeFinalSlash();
741 :
742 0 : pGradientList->SetName( aURL.getName() );
743 0 : pGradientList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
744 :
745 0 : if( pGradientList->Save() )
746 : {
747 : // determining (possibly cutting) the name
748 : // and displaying it in the GroupBox
749 0 : OUString aString( CUI_RES( RID_SVXSTR_TABLE ) );
750 0 : aString += ": ";
751 :
752 0 : if ( aURL.getBase().getLength() > 18 )
753 : {
754 0 : aString += aURL.getBase().copy( 0, 15 );
755 0 : aString += "...";
756 : }
757 : else
758 0 : aString += aURL.getBase();
759 :
760 0 : *pnGradientListState |= CT_SAVED;
761 0 : *pnGradientListState &= ~CT_MODIFIED;
762 : }
763 : else
764 : {
765 0 : ErrorBox( GetParentDialog(), WinBits( WB_OK ),
766 0 : String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
767 0 : }
768 : }
769 :
770 0 : return 0L;
771 : }
772 :
773 : //------------------------------------------------------------------------
774 :
775 0 : IMPL_LINK_NOARG(SvxGradientTabPage, ChangeGradientHdl_Impl)
776 : {
777 0 : XGradient* pGradient = NULL;
778 0 : int nPos = m_pLbGradients->GetSelectEntryPos();
779 :
780 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
781 0 : pGradient = new XGradient( ( (XGradientEntry*) pGradientList->GetGradient( nPos ) )->GetGradient() );
782 : else
783 : {
784 0 : const SfxPoolItem* pPoolItem = NULL;
785 0 : if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), sal_True, &pPoolItem ) )
786 : {
787 0 : if( ( XFILL_GRADIENT == (XFillStyle) ( ( const XFillStyleItem* ) pPoolItem )->GetValue() ) &&
788 0 : ( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLGRADIENT ), sal_True, &pPoolItem ) ) )
789 : {
790 0 : pGradient = new XGradient( ( ( const XFillGradientItem* ) pPoolItem )->GetGradientValue() );
791 : }
792 : }
793 0 : if( !pGradient )
794 : {
795 0 : m_pLbGradients->SelectEntryPos( 0 );
796 0 : nPos = m_pLbGradients->GetSelectEntryPos();
797 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
798 0 : pGradient = new XGradient( ( (XGradientEntry*) pGradientList->GetGradient( nPos ) )->GetGradient() );
799 : }
800 : }
801 :
802 0 : if( pGradient )
803 : {
804 0 : XGradientStyle eXGS = pGradient->GetGradientStyle();
805 :
806 : m_pLbGradientType->SelectEntryPos(
807 0 : sal::static_int_cast< sal_uInt16 >( eXGS ) );
808 : // if the entry is not in the listbox ist,
809 : // colors are added temporarily
810 0 : m_pLbColorFrom->SetNoSelection();
811 0 : m_pLbColorFrom->SelectEntry( pGradient->GetStartColor() );
812 :
813 0 : if ( m_pLbColorFrom->GetSelectEntryCount() == 0 )
814 : {
815 : m_pLbColorFrom->InsertEntry( pGradient->GetStartColor(),
816 0 : String() );
817 0 : m_pLbColorFrom->SelectEntry( pGradient->GetStartColor() );
818 : }
819 0 : m_pLbColorTo->SetNoSelection();
820 0 : m_pLbColorTo->SelectEntry( pGradient->GetEndColor() );
821 :
822 0 : if ( m_pLbColorTo->GetSelectEntryCount() == 0 )
823 : {
824 0 : m_pLbColorTo->InsertEntry( pGradient->GetEndColor(), String() );
825 0 : m_pLbColorTo->SelectEntry( pGradient->GetEndColor() );
826 : }
827 :
828 0 : m_pMtrAngle->SetValue( pGradient->GetAngle() / 10 ); // should be changed in resource
829 0 : m_pMtrBorder->SetValue( pGradient->GetBorder() );
830 0 : m_pMtrCenterX->SetValue( pGradient->GetXOffset() );
831 0 : m_pMtrCenterY->SetValue( pGradient->GetYOffset() );
832 0 : m_pMtrColorFrom->SetValue( pGradient->GetStartIntens() );
833 0 : m_pMtrColorTo->SetValue( pGradient->GetEndIntens() );
834 :
835 : // disable/enable controls
836 0 : SetControlState_Impl( eXGS );
837 :
838 : // fill ItemSet and pass it on to aCtlPreview
839 0 : rXFSet.Put( XFillGradientItem( String(), *pGradient ) );
840 0 : m_pCtlPreview->SetAttributes( aXFillAttr.GetItemSet() );
841 :
842 0 : m_pCtlPreview->Invalidate();
843 0 : delete pGradient;
844 : }
845 0 : return 0L;
846 : }
847 :
848 : //------------------------------------------------------------------------
849 :
850 0 : void SvxGradientTabPage::SetControlState_Impl( XGradientStyle eXGS )
851 : {
852 0 : switch( eXGS )
853 : {
854 : case XGRAD_LINEAR:
855 : case XGRAD_AXIAL:
856 0 : m_pFtCenterX->Disable();
857 0 : m_pMtrCenterX->Disable();
858 0 : m_pFtCenterY->Disable();
859 0 : m_pMtrCenterY->Disable();
860 0 : m_pFtAngle->Enable();
861 0 : m_pMtrAngle->Enable();
862 0 : break;
863 :
864 : case XGRAD_RADIAL:
865 0 : m_pFtCenterX->Enable();
866 0 : m_pMtrCenterX->Enable();
867 0 : m_pFtCenterY->Enable();
868 0 : m_pMtrCenterY->Enable();
869 0 : m_pFtAngle->Disable();
870 0 : m_pMtrAngle->Disable();
871 0 : break;
872 :
873 : case XGRAD_ELLIPTICAL:
874 0 : m_pFtCenterX->Enable();
875 0 : m_pMtrCenterX->Enable();
876 0 : m_pFtCenterY->Enable();
877 0 : m_pMtrCenterY->Enable();
878 0 : m_pFtAngle->Enable();
879 0 : m_pMtrAngle->Enable();
880 0 : break;
881 :
882 : case XGRAD_SQUARE:
883 : case XGRAD_RECT:
884 0 : m_pFtCenterX->Enable();
885 0 : m_pMtrCenterX->Enable();
886 0 : m_pFtCenterY->Enable();
887 0 : m_pMtrCenterY->Enable();
888 0 : m_pFtAngle->Enable();
889 0 : m_pMtrAngle->Enable();
890 0 : break;
891 : }
892 0 : }
893 :
894 :
895 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|