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 <tools/urlobj.hxx>
21 : #include <vcl/msgbox.hxx>
22 : #include <vcl/settings.hxx>
23 : #include <unotools/pathoptions.hxx>
24 : #include <sfx2/app.hxx>
25 : #include <sfx2/module.hxx>
26 : #include <sfx2/filedlghelper.hxx>
27 : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
28 :
29 : #include <cuires.hrc>
30 : #include "helpid.hrc"
31 :
32 : #include "svx/xattr.hxx"
33 : #include <svx/xpool.hxx>
34 : #include <svx/xtable.hxx>
35 :
36 : #include "svx/drawitem.hxx"
37 : #include "cuitabline.hxx"
38 : #include "dlgname.hxx"
39 : #include "defdlgname.hxx"
40 : #include <svx/svxdlg.hxx>
41 : #include <dialmgr.hxx>
42 : #include "svx/dlgutil.hxx"
43 : #include <svx/dialmgr.hxx>
44 : #include <svx/dialogs.hrc>
45 : #include <boost/scoped_ptr.hpp>
46 :
47 : #define XOUT_WIDTH 150
48 :
49 0 : SvxLineDefTabPage::SvxLineDefTabPage
50 : (
51 : vcl::Window* pParent,
52 : const SfxItemSet& rInAttrs
53 : ) :
54 :
55 : SfxTabPage( pParent
56 : , "LineStylePage"
57 : , "cui/ui/linestyletabpage.ui"
58 : , &rInAttrs ),
59 : rOutAttrs ( rInAttrs ),
60 : bObjSelected ( false ),
61 :
62 0 : pXPool ( static_cast<XOutdevItemPool*>(rInAttrs.GetPool()) ),
63 : aXLStyle ( XLINE_DASH ),
64 : aXWidth ( XOUT_WIDTH ),
65 : aXDash ( OUString(), XDash( XDASH_RECT, 3, 7, 2, 40, 15 ) ),
66 : aXColor ( OUString(), COL_BLACK ),
67 : aXLineAttr ( pXPool ),
68 0 : rXLSet ( aXLineAttr.GetItemSet() ),
69 : pnDashListState(0),
70 : pPageType(0),
71 : nDlgType(0),
72 0 : pPosDashLb(0)
73 : {
74 :
75 0 : get(m_pLbLineStyles ,"LB_LINESTYLES");
76 0 : get(m_pLbType1 ,"LB_TYPE_1");
77 0 : get(m_pLbType2 ,"LB_TYPE_2");
78 0 : get(m_pNumFldNumber1 ,"NUM_FLD_1");
79 0 : get(m_pNumFldNumber2 ,"NUM_FLD_2");
80 0 : get(m_pMtrLength1 ,"MTR_FLD_LENGTH_1");
81 0 : m_pMtrLength1->SetCustomUnitText("%");
82 0 : get(m_pMtrLength2 ,"MTR_FLD_LENGTH_2");
83 0 : m_pMtrLength2->SetCustomUnitText("%");
84 0 : get(m_pMtrDistance ,"MTR_FLD_DISTANCE");
85 0 : m_pMtrDistance->SetCustomUnitText("%");
86 0 : get(m_pCbxSynchronize ,"CBX_SYNCHRONIZE");
87 0 : get(m_pBtnAdd ,"BTN_ADD");
88 0 : get(m_pBtnModify ,"BTN_MODIFY");
89 0 : get(m_pBtnDelete ,"BTN_DELETE");
90 0 : get(m_pBtnLoad ,"BTN_LOAD");
91 0 : get(m_pBtnSave ,"BTN_SAVE");
92 0 : get(m_pCtlPreview ,"CTL_PREVIEW");
93 :
94 : // this page needs ExchangeSupport
95 0 : SetExchangeSupport();
96 :
97 : // adjust metric
98 0 : eFUnit = GetModuleFieldUnit( rInAttrs );
99 :
100 0 : switch ( eFUnit )
101 : {
102 : case FUNIT_M:
103 : case FUNIT_KM:
104 0 : eFUnit = FUNIT_MM;
105 0 : break;
106 : default: ; //prevent warning
107 : }
108 0 : SetFieldUnit( *m_pMtrDistance, eFUnit );
109 0 : SetFieldUnit( *m_pMtrLength1, eFUnit );
110 0 : SetFieldUnit( *m_pMtrLength2, eFUnit );
111 :
112 : // determine PoolUnit
113 0 : SfxItemPool* pPool = rOutAttrs.GetPool();
114 : DBG_ASSERT( pPool, "Wo ist der Pool?" );
115 0 : ePoolUnit = pPool->GetMetric( SID_ATTR_LINE_WIDTH );
116 :
117 0 : rXLSet.Put( aXLStyle );
118 0 : rXLSet.Put( aXWidth );
119 0 : rXLSet.Put( aXDash );
120 0 : rXLSet.Put( aXColor );
121 :
122 : // #i34740#
123 0 : m_pCtlPreview->SetLineAttributes(aXLineAttr.GetItemSet());
124 :
125 0 : m_pBtnAdd->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickAddHdl_Impl ) );
126 0 : m_pBtnModify->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickModifyHdl_Impl ) );
127 0 : m_pBtnDelete->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickDeleteHdl_Impl ) );
128 0 : m_pBtnLoad->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickLoadHdl_Impl ) );
129 0 : m_pBtnSave->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickSaveHdl_Impl ) );
130 :
131 0 : m_pNumFldNumber1->SetModifyHdl( LINK( this, SvxLineDefTabPage, ChangeNumber1Hdl_Impl ) );
132 0 : m_pNumFldNumber2->SetModifyHdl( LINK( this, SvxLineDefTabPage, ChangeNumber2Hdl_Impl ) );
133 0 : m_pLbLineStyles->SetSelectHdl( LINK( this, SvxLineDefTabPage, SelectLinestyleHdl_Impl ) );
134 :
135 : // #i122042# switch off default adding of 'none' and 'solid' entries
136 : // for this ListBox; we want to select only editable/dashed styles
137 0 : m_pLbLineStyles->setAddStandardFields(false);
138 :
139 : // absolute (in mm) or relative (in %)
140 0 : m_pCbxSynchronize->SetClickHdl( LINK( this, SvxLineDefTabPage, ChangeMetricHdl_Impl ) );
141 :
142 : // preview must be updated when there's something changed
143 0 : Link aLink = LINK( this, SvxLineDefTabPage, SelectTypeHdl_Impl );
144 0 : m_pLbType1->SetSelectHdl( aLink );
145 0 : m_pLbType2->SetSelectHdl( aLink );
146 0 : aLink = LINK( this, SvxLineDefTabPage, ChangePreviewHdl_Impl );
147 0 : m_pMtrLength1->SetModifyHdl( aLink );
148 0 : m_pMtrLength2->SetModifyHdl( aLink );
149 0 : m_pMtrDistance->SetModifyHdl( aLink );
150 :
151 0 : pDashList = NULL;
152 0 : }
153 :
154 0 : void SvxLineDefTabPage::Construct()
155 : {
156 : // Line style fill; do *not* add default fields here
157 0 : m_pLbLineStyles->Fill( pDashList );
158 0 : }
159 :
160 :
161 :
162 0 : void SvxLineDefTabPage::ActivatePage( const SfxItemSet& )
163 : {
164 0 : if( nDlgType == 0 ) // area dialog
165 : {
166 : // ActivatePage() is called before the dialog receives PageCreated() !!!
167 0 : if( pDashList.is() )
168 : {
169 0 : if( *pPageType == 1 &&
170 0 : *pPosDashLb != LISTBOX_ENTRY_NOTFOUND )
171 : {
172 0 : m_pLbLineStyles->SelectEntryPos( *pPosDashLb );
173 : }
174 : // so that a possibly existing line style is discarded
175 0 : SelectLinestyleHdl_Impl( this );
176 :
177 : // determining (and possibly cutting) the name
178 : // and displaying it in the GroupBox
179 : // OUString aString( CUI_RES( RID_SVXSTR_TABLE ) );
180 : // aString += ": ";
181 0 : INetURLObject aURL( pDashList->GetPath() );
182 :
183 0 : aURL.Append( pDashList->GetName() );
184 : DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
185 :
186 0 : *pPageType = 0; // 2
187 0 : *pPosDashLb = LISTBOX_ENTRY_NOTFOUND;
188 : }
189 : }
190 0 : }
191 :
192 :
193 :
194 0 : int SvxLineDefTabPage::DeactivatePage( SfxItemSet* _pSet )
195 : {
196 0 : CheckChanges_Impl();
197 :
198 0 : if( _pSet )
199 0 : FillItemSet( _pSet );
200 :
201 0 : return( LEAVE_PAGE );
202 : }
203 :
204 :
205 :
206 0 : void SvxLineDefTabPage::CheckChanges_Impl()
207 : {
208 : // is here used to NOT lose changes
209 : //XDashStyle eXDS;
210 :
211 0 : if( m_pNumFldNumber1->IsValueChangedFromSaved() ||
212 0 : m_pMtrLength1->IsValueChangedFromSaved() ||
213 0 : m_pLbType1->IsValueChangedFromSaved() ||
214 0 : m_pNumFldNumber2->IsValueChangedFromSaved() ||
215 0 : m_pMtrLength2->IsValueChangedFromSaved() ||
216 0 : m_pLbType2->IsValueChangedFromSaved() ||
217 0 : m_pMtrDistance->IsValueChangedFromSaved() )
218 : {
219 0 : ResMgr& rMgr = CUI_MGR();
220 0 : Image aWarningBoxImage = WarningBox::GetStandardImage();
221 0 : boost::scoped_ptr<SvxMessDialog> aMessDlg(new SvxMessDialog(GetParentDialog(),
222 0 : SVX_RESSTR( RID_SVXSTR_LINESTYLE ),
223 : OUString( ResId( RID_SVXSTR_ASK_CHANGE_LINESTYLE, rMgr ) ),
224 0 : &aWarningBoxImage ));
225 : DBG_ASSERT(aMessDlg, "Dialog creation failed!");
226 0 : aMessDlg->SetButtonText( MESS_BTN_1, OUString( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
227 0 : aMessDlg->SetButtonText( MESS_BTN_2, OUString( ResId( RID_SVXSTR_ADD, rMgr ) ) );
228 :
229 0 : short nRet = aMessDlg->Execute();
230 :
231 0 : switch( nRet )
232 : {
233 : case RET_BTN_1:
234 : {
235 0 : ClickModifyHdl_Impl( this );
236 : }
237 0 : break;
238 :
239 : case RET_BTN_2:
240 : {
241 0 : ClickAddHdl_Impl( this );
242 : }
243 0 : break;
244 :
245 : case RET_CANCEL:
246 0 : break;
247 0 : }
248 : }
249 :
250 :
251 :
252 0 : sal_Int32 nPos = m_pLbLineStyles->GetSelectEntryPos();
253 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
254 : {
255 0 : *pPosDashLb = nPos;
256 : }
257 0 : }
258 :
259 :
260 :
261 0 : bool SvxLineDefTabPage::FillItemSet( SfxItemSet* rAttrs )
262 : {
263 0 : if( nDlgType == 0 ) // line dialog
264 : {
265 0 : if( *pPageType == 2 )
266 : {
267 0 : FillDash_Impl();
268 :
269 0 : OUString aString( m_pLbLineStyles->GetSelectEntry() );
270 0 : rAttrs->Put( XLineStyleItem( XLINE_DASH ) );
271 0 : rAttrs->Put( XLineDashItem( aString, aDash ) );
272 : }
273 : }
274 0 : return true;
275 : }
276 :
277 :
278 :
279 0 : void SvxLineDefTabPage::Reset( const SfxItemSet* rAttrs )
280 : {
281 0 : if( rAttrs->GetItemState( GetWhich( XATTR_LINESTYLE ) ) != SfxItemState::DONTCARE )
282 : {
283 0 : XLineStyle eXLS = (XLineStyle) static_cast<const XLineStyleItem&>( rAttrs->Get( GetWhich( XATTR_LINESTYLE ) ) ).GetValue();
284 :
285 0 : switch( eXLS )
286 : {
287 : case XLINE_NONE:
288 : case XLINE_SOLID:
289 0 : m_pLbLineStyles->SelectEntryPos( 0 );
290 0 : break;
291 :
292 : case XLINE_DASH:
293 : {
294 0 : const XLineDashItem& rDashItem = static_cast<const XLineDashItem&>( rAttrs->Get( XATTR_LINEDASH ) );
295 0 : aDash = rDashItem.GetDashValue();
296 :
297 0 : m_pLbLineStyles->SetNoSelection();
298 0 : m_pLbLineStyles->SelectEntry( rDashItem.GetName() );
299 : }
300 0 : break;
301 :
302 : default:
303 0 : break;
304 : }
305 : }
306 0 : SelectLinestyleHdl_Impl( NULL );
307 :
308 : // determine button state
309 0 : if( pDashList->Count() )
310 : {
311 0 : m_pBtnModify->Enable();
312 0 : m_pBtnDelete->Enable();
313 0 : m_pBtnSave->Enable();
314 : }
315 : else
316 : {
317 0 : m_pBtnModify->Disable();
318 0 : m_pBtnDelete->Disable();
319 0 : m_pBtnSave->Disable();
320 : }
321 0 : }
322 :
323 :
324 :
325 0 : SfxTabPage* SvxLineDefTabPage::Create( vcl::Window* pWindow, const SfxItemSet* rOutAttrs )
326 : {
327 0 : return( new SvxLineDefTabPage( pWindow, *rOutAttrs ) );
328 : }
329 :
330 :
331 :
332 0 : IMPL_LINK( SvxLineDefTabPage, SelectLinestyleHdl_Impl, void *, p )
333 : {
334 0 : if(pDashList->Count())
335 : {
336 0 : int nTmp = m_pLbLineStyles->GetSelectEntryPos();
337 :
338 0 : if(LISTBOX_ENTRY_NOTFOUND == nTmp)
339 : {
340 : OSL_ENSURE(false, "OOps, non-existent LineDash selected (!)");
341 0 : nTmp = 1;
342 : }
343 :
344 0 : aDash = pDashList->GetDash( nTmp )->GetDash();
345 :
346 0 : FillDialog_Impl();
347 :
348 0 : rXLSet.Put( XLineDashItem( OUString(), aDash ) );
349 :
350 : // #i34740#
351 0 : m_pCtlPreview->SetLineAttributes(aXLineAttr.GetItemSet());
352 :
353 0 : m_pCtlPreview->Invalidate();
354 :
355 : // Is not set before, in order to take the new style
356 : // only if there was an entry selected in the ListBox.
357 : // If it was called via Reset(), then p is == NULL
358 0 : if( p )
359 0 : *pPageType = 2;
360 : }
361 0 : return( 0L );
362 : }
363 :
364 :
365 :
366 0 : IMPL_LINK_NOARG_INLINE_START(SvxLineDefTabPage, ChangePreviewHdl_Impl)
367 : {
368 0 : FillDash_Impl();
369 0 : m_pCtlPreview->Invalidate();
370 :
371 0 : return( 0L );
372 : }
373 0 : IMPL_LINK_NOARG_INLINE_END(SvxLineDefTabPage, ChangePreviewHdl_Impl)
374 :
375 :
376 :
377 0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ChangeNumber1Hdl_Impl)
378 : {
379 0 : if( m_pNumFldNumber1->GetValue() == 0L )
380 : {
381 0 : m_pNumFldNumber2->SetMin( 1L );
382 0 : m_pNumFldNumber2->SetFirst( 1L );
383 : }
384 : else
385 : {
386 0 : m_pNumFldNumber2->SetMin( 0L );
387 0 : m_pNumFldNumber2->SetFirst( 0L );
388 : }
389 :
390 0 : ChangePreviewHdl_Impl( this );
391 :
392 0 : return( 0L );
393 : }
394 :
395 :
396 :
397 0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ChangeNumber2Hdl_Impl)
398 : {
399 0 : if( m_pNumFldNumber2->GetValue() == 0L )
400 : {
401 0 : m_pNumFldNumber1->SetMin( 1L );
402 0 : m_pNumFldNumber1->SetFirst( 1L );
403 : }
404 : else
405 : {
406 0 : m_pNumFldNumber1->SetMin( 0L );
407 0 : m_pNumFldNumber1->SetFirst( 0L );
408 : }
409 :
410 0 : ChangePreviewHdl_Impl( this );
411 :
412 0 : return( 0L );
413 : }
414 :
415 :
416 :
417 :
418 0 : IMPL_LINK( SvxLineDefTabPage, ChangeMetricHdl_Impl, void *, p )
419 : {
420 0 : if( !m_pCbxSynchronize->IsChecked() && m_pMtrLength1->GetUnit() != eFUnit )
421 : {
422 : long nTmp1, nTmp2, nTmp3;
423 :
424 : // was changed with Control
425 0 : if( p )
426 : {
427 0 : nTmp1 = GetCoreValue( *m_pMtrLength1, ePoolUnit ) * XOUT_WIDTH / 100;
428 0 : nTmp2 = GetCoreValue( *m_pMtrLength2, ePoolUnit ) * XOUT_WIDTH / 100;
429 0 : nTmp3 = GetCoreValue( *m_pMtrDistance, ePoolUnit ) * XOUT_WIDTH / 100;
430 : }
431 : else
432 : {
433 0 : nTmp1 = GetCoreValue( *m_pMtrLength1, ePoolUnit );
434 0 : nTmp2 = GetCoreValue( *m_pMtrLength2, ePoolUnit );
435 0 : nTmp3 = GetCoreValue( *m_pMtrDistance, ePoolUnit );
436 : }
437 0 : m_pMtrLength1->SetDecimalDigits( 2 );
438 0 : m_pMtrLength2->SetDecimalDigits( 2 );
439 0 : m_pMtrDistance->SetDecimalDigits( 2 );
440 :
441 : // adjust metric
442 0 : m_pMtrLength1->SetUnit( eFUnit );
443 0 : m_pMtrLength2->SetUnit( eFUnit );
444 0 : m_pMtrDistance->SetUnit( eFUnit );
445 :
446 0 : SetMetricValue( *m_pMtrLength1, nTmp1, ePoolUnit );
447 0 : SetMetricValue( *m_pMtrLength2, nTmp2, ePoolUnit );
448 0 : SetMetricValue( *m_pMtrDistance, nTmp3, ePoolUnit );
449 : }
450 0 : else if( m_pCbxSynchronize->IsChecked() && m_pMtrLength1->GetUnit() != FUNIT_PERCENT )
451 : {
452 : long nTmp1, nTmp2, nTmp3;
453 :
454 : // was changed with Control
455 0 : if( p )
456 : {
457 0 : nTmp1 = GetCoreValue( *m_pMtrLength1, ePoolUnit ) * 100 / XOUT_WIDTH;
458 0 : nTmp2 = GetCoreValue( *m_pMtrLength2, ePoolUnit ) * 100 / XOUT_WIDTH;
459 0 : nTmp3 = GetCoreValue( *m_pMtrDistance, ePoolUnit ) * 100 / XOUT_WIDTH;
460 : }
461 : else
462 : {
463 0 : nTmp1 = GetCoreValue( *m_pMtrLength1, ePoolUnit );
464 0 : nTmp2 = GetCoreValue( *m_pMtrLength2, ePoolUnit );
465 0 : nTmp3 = GetCoreValue( *m_pMtrDistance, ePoolUnit );
466 : }
467 :
468 0 : m_pMtrLength1->SetDecimalDigits( 0 );
469 0 : m_pMtrLength2->SetDecimalDigits( 0 );
470 0 : m_pMtrDistance->SetDecimalDigits( 0 );
471 :
472 0 : m_pMtrLength1->SetUnit( FUNIT_PERCENT );
473 0 : m_pMtrLength2->SetUnit( FUNIT_PERCENT );
474 0 : m_pMtrDistance->SetUnit( FUNIT_PERCENT );
475 :
476 0 : SetMetricValue( *m_pMtrLength1, nTmp1, ePoolUnit );
477 0 : SetMetricValue( *m_pMtrLength2, nTmp2, ePoolUnit );
478 0 : SetMetricValue( *m_pMtrDistance, nTmp3, ePoolUnit );
479 :
480 : }
481 0 : SelectTypeHdl_Impl( NULL );
482 :
483 0 : return( 0L );
484 : }
485 :
486 :
487 :
488 0 : IMPL_LINK( SvxLineDefTabPage, SelectTypeHdl_Impl, void *, p )
489 : {
490 0 : if ( p == m_pLbType1 || !p )
491 : {
492 0 : if ( m_pLbType1->GetSelectEntryPos() == 0 )
493 : {
494 0 : m_pMtrLength1->Disable();
495 0 : m_pMtrLength1->SetText( "" );
496 : }
497 0 : else if ( !m_pMtrLength1->IsEnabled() )
498 : {
499 0 : m_pMtrLength1->Enable();
500 0 : m_pMtrLength1->Reformat();
501 : }
502 : }
503 :
504 0 : if ( p == m_pLbType2 || !p )
505 : {
506 0 : if ( m_pLbType2->GetSelectEntryPos() == 0 )
507 : {
508 0 : m_pMtrLength2->Disable();
509 0 : m_pMtrLength2->SetText( "" );
510 : }
511 0 : else if ( !m_pMtrLength2->IsEnabled() )
512 : {
513 0 : m_pMtrLength2->Enable();
514 0 : m_pMtrLength2->Reformat();
515 : }
516 : }
517 0 : ChangePreviewHdl_Impl( p );
518 0 : return( 0L );
519 : }
520 :
521 :
522 :
523 0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ClickAddHdl_Impl)
524 : {
525 0 : ResMgr& rMgr = CUI_MGR();
526 0 : OUString aNewName( SVX_RES( RID_SVXSTR_LINESTYLE ) );
527 0 : OUString aDesc( ResId( RID_SVXSTR_DESC_LINESTYLE, rMgr ) );
528 0 : OUString aName;
529 : XDashEntry* pEntry;
530 :
531 0 : long nCount = pDashList->Count();
532 0 : long j = 1;
533 0 : bool bDifferent = false;
534 :
535 0 : while ( !bDifferent )
536 : {
537 0 : aName = aNewName;
538 0 : aName += " ";
539 0 : aName += OUString::number( j++ );
540 0 : bDifferent = true;
541 :
542 0 : for ( long i = 0; i < nCount && bDifferent; i++ )
543 0 : if ( aName == pDashList->GetDash( i )->GetName() )
544 0 : bDifferent = false;
545 : }
546 :
547 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
548 : DBG_ASSERT(pFact, "Dialog creation failed!");
549 0 : boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ));
550 : DBG_ASSERT(pDlg, "Dialog creation failed!");
551 0 : bool bLoop = true;
552 :
553 0 : while ( bLoop && pDlg->Execute() == RET_OK )
554 : {
555 0 : pDlg->GetName( aName );
556 0 : bDifferent = true;
557 :
558 0 : for( long i = 0; i < nCount && bDifferent; i++ )
559 : {
560 0 : if( aName == pDashList->GetDash( i )->GetName() )
561 0 : bDifferent = false;
562 : }
563 :
564 0 : if( bDifferent )
565 : {
566 0 : bLoop = false;
567 0 : FillDash_Impl();
568 :
569 0 : pEntry = new XDashEntry( aDash, aName );
570 :
571 0 : long nDashCount = pDashList->Count();
572 0 : pDashList->Insert( pEntry, nDashCount );
573 0 : const Bitmap aBitmap = pDashList->GetUiBitmap( nDashCount );
574 0 : m_pLbLineStyles->Append( *pEntry, pDashList->GetUiBitmap( nDashCount ) );
575 :
576 0 : m_pLbLineStyles->SelectEntryPos( m_pLbLineStyles->GetEntryCount() - 1 );
577 :
578 0 : *pnDashListState |= CT_MODIFIED;
579 :
580 0 : *pPageType = 2;
581 :
582 : // save values for changes recognition (-> method)
583 0 : m_pNumFldNumber1->SaveValue();
584 0 : m_pMtrLength1->SaveValue();
585 0 : m_pLbType1->SaveValue();
586 0 : m_pNumFldNumber2->SaveValue();
587 0 : m_pMtrLength2->SaveValue();
588 0 : m_pLbType2->SaveValue();
589 0 : m_pMtrDistance->SaveValue();
590 : }
591 : else
592 : {
593 :
594 0 : MessageDialog aBox( GetParentDialog()
595 : ,"DuplicateNameDialog"
596 0 : ,"cui/ui/queryduplicatedialog.ui");
597 0 : aBox.Execute();
598 : }
599 : }
600 0 : pDlg.reset();
601 :
602 : // determine button state
603 0 : if ( pDashList->Count() )
604 : {
605 0 : m_pBtnModify->Enable();
606 0 : m_pBtnDelete->Enable();
607 0 : m_pBtnSave->Enable();
608 : }
609 0 : return( 0L );
610 : }
611 :
612 :
613 :
614 0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ClickModifyHdl_Impl)
615 : {
616 0 : sal_Int32 nPos = m_pLbLineStyles->GetSelectEntryPos();
617 :
618 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
619 : {
620 0 : ResMgr& rMgr = CUI_MGR();
621 0 : OUString aDesc( ResId( RID_SVXSTR_DESC_LINESTYLE, rMgr ) );
622 0 : OUString aName( pDashList->GetDash( nPos )->GetName() );
623 0 : OUString aOldName = aName;
624 :
625 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
626 : DBG_ASSERT(pFact, "Dialog creation failed!");
627 0 : boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ));
628 : DBG_ASSERT(pDlg, "Dialog creation failed!");
629 :
630 0 : long nCount = pDashList->Count();
631 0 : bool bDifferent = false;
632 0 : bool bLoop = true;
633 :
634 0 : while ( bLoop && pDlg->Execute() == RET_OK )
635 : {
636 0 : pDlg->GetName( aName );
637 0 : bDifferent = true;
638 :
639 0 : for( long i = 0; i < nCount && bDifferent; i++ )
640 : {
641 0 : if( aName == pDashList->GetDash( i )->GetName() &&
642 0 : aName != aOldName )
643 0 : bDifferent = false;
644 : }
645 :
646 0 : if ( bDifferent )
647 : {
648 0 : bLoop = false;
649 0 : FillDash_Impl();
650 :
651 0 : XDashEntry* pEntry = new XDashEntry( aDash, aName );
652 :
653 0 : delete pDashList->Replace( pEntry, nPos );
654 0 : m_pLbLineStyles->Modify( *pEntry, nPos, pDashList->GetUiBitmap( nPos ) );
655 :
656 0 : m_pLbLineStyles->SelectEntryPos( nPos );
657 :
658 0 : *pnDashListState |= CT_MODIFIED;
659 :
660 0 : *pPageType = 2;
661 :
662 : // save values for changes recognition (-> method)
663 0 : m_pNumFldNumber1->SaveValue();
664 0 : m_pMtrLength1->SaveValue();
665 0 : m_pLbType1->SaveValue();
666 0 : m_pNumFldNumber2->SaveValue();
667 0 : m_pMtrLength2->SaveValue();
668 0 : m_pLbType2->SaveValue();
669 0 : m_pMtrDistance->SaveValue();
670 : }
671 : else
672 : {
673 0 : MessageDialog aBox( GetParentDialog()
674 : ,"DuplicateNameDialog"
675 0 : ,"cui/ui/queryduplicatedialog.ui");
676 0 : aBox.Execute();
677 : }
678 0 : }
679 : }
680 0 : return( 0L );
681 : }
682 :
683 :
684 :
685 0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ClickDeleteHdl_Impl)
686 : {
687 0 : sal_Int32 nPos = m_pLbLineStyles->GetSelectEntryPos();
688 :
689 0 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
690 : {
691 0 : MessageDialog aQueryBox( GetParentDialog()
692 : ,"AskDelLineStyleDialog"
693 0 : ,"cui/ui/querydeletelinestyledialog.ui");
694 :
695 0 : if ( aQueryBox.Execute() == RET_YES )
696 : {
697 0 : delete pDashList->Remove( nPos );
698 0 : m_pLbLineStyles->RemoveEntry( nPos );
699 0 : m_pLbLineStyles->SelectEntryPos( 0 );
700 :
701 0 : SelectLinestyleHdl_Impl( this );
702 0 : *pPageType = 0; // style should not be taken
703 :
704 0 : *pnDashListState |= CT_MODIFIED;
705 :
706 0 : ChangePreviewHdl_Impl( this );
707 0 : }
708 : }
709 :
710 : // determine button state
711 0 : if ( !pDashList->Count() )
712 : {
713 0 : m_pBtnModify->Disable();
714 0 : m_pBtnDelete->Disable();
715 0 : m_pBtnSave->Disable();
716 : }
717 0 : return( 0L );
718 : }
719 :
720 :
721 :
722 0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ClickLoadHdl_Impl)
723 : {
724 0 : sal_uInt16 nReturn = RET_YES;
725 :
726 0 : if ( *pnDashListState & CT_MODIFIED )
727 : {
728 0 : nReturn = MessageDialog( GetParentDialog()
729 : ,"AskSaveList"
730 0 : ,"cui/ui/querysavelistdialog.ui").Execute();
731 :
732 0 : if ( nReturn == RET_YES )
733 0 : pDashList->Save();
734 : }
735 :
736 0 : if ( nReturn != RET_CANCEL )
737 : {
738 0 : ::sfx2::FileDialogHelper aDlg( com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
739 0 : OUString aStrFilterType( "*.sod" );
740 0 : aDlg.AddFilter( aStrFilterType, aStrFilterType );
741 0 : INetURLObject aFile( SvtPathOptions().GetPalettePath() );
742 0 : aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
743 :
744 0 : if( aDlg.Execute() == ERRCODE_NONE )
745 : {
746 0 : INetURLObject aURL( aDlg.GetPath() );
747 0 : INetURLObject aPathURL( aURL );
748 :
749 0 : aPathURL.removeSegment();
750 0 : aPathURL.removeFinalSlash();
751 :
752 0 : XDashListRef pDshLst = XPropertyList::AsDashList(XPropertyList::CreatePropertyList( XDASH_LIST, aPathURL.GetMainURL( INetURLObject::NO_DECODE ), "" ));
753 0 : pDshLst->SetName( aURL.getName() );
754 :
755 0 : if( pDshLst->Load() )
756 : {
757 0 : pDashList = pDshLst;
758 0 : static_cast<SvxLineTabDialog*>( GetParentDialog() )->SetNewDashList( pDashList );
759 :
760 0 : m_pLbLineStyles->Clear();
761 0 : m_pLbLineStyles->Fill( pDashList );
762 0 : Reset( &rOutAttrs );
763 :
764 0 : pDashList->SetName( aURL.getName() );
765 :
766 0 : *pnDashListState |= CT_CHANGED;
767 0 : *pnDashListState &= ~CT_MODIFIED;
768 : }
769 : else
770 : //aIStream.Close();
771 0 : MessageDialog( GetParentDialog()
772 : ,"NoLoadedFileDialog"
773 0 : ,"cui/ui/querynoloadedfiledialog.ui").Execute();
774 0 : }
775 : }
776 :
777 : // determine button state
778 0 : if ( pDashList->Count() )
779 : {
780 0 : m_pBtnModify->Enable();
781 0 : m_pBtnDelete->Enable();
782 0 : m_pBtnSave->Enable();
783 : }
784 : else
785 : {
786 0 : m_pBtnModify->Disable();
787 0 : m_pBtnDelete->Disable();
788 0 : m_pBtnSave->Disable();
789 : }
790 0 : return( 0L );
791 : }
792 :
793 :
794 :
795 0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ClickSaveHdl_Impl)
796 : {
797 0 : ::sfx2::FileDialogHelper aDlg( com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
798 0 : OUString aStrFilterType( "*.sod" );
799 0 : aDlg.AddFilter( aStrFilterType, aStrFilterType );
800 :
801 0 : INetURLObject aFile( SvtPathOptions().GetPalettePath() );
802 : DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
803 :
804 0 : if( !pDashList->GetName().isEmpty() )
805 : {
806 0 : aFile.Append( pDashList->GetName() );
807 :
808 0 : if( aFile.getExtension().isEmpty() )
809 0 : aFile.SetExtension( OUString("sod") );
810 : }
811 :
812 0 : aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
813 0 : if ( aDlg.Execute() == ERRCODE_NONE )
814 : {
815 0 : INetURLObject aURL( aDlg.GetPath() );
816 0 : INetURLObject aPathURL( aURL );
817 :
818 0 : aPathURL.removeSegment();
819 0 : aPathURL.removeFinalSlash();
820 :
821 0 : pDashList->SetName( aURL.getName() );
822 0 : pDashList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
823 :
824 0 : if( pDashList->Save() )
825 : {
826 0 : *pnDashListState |= CT_SAVED;
827 0 : *pnDashListState &= ~CT_MODIFIED;
828 : }
829 : else
830 : {
831 0 : MessageDialog( GetParentDialog()
832 : ,"NoSaveFileDialog"
833 0 : ,"cui/ui/querynosavefiledialog.ui").Execute();
834 0 : }
835 : }
836 :
837 0 : return( 0L );
838 : }
839 :
840 :
841 :
842 0 : void SvxLineDefTabPage::FillDash_Impl()
843 : {
844 : XDashStyle eXDS;
845 :
846 0 : if( m_pCbxSynchronize->IsChecked() )
847 0 : eXDS = XDASH_RECTRELATIVE;
848 : else
849 0 : eXDS = XDASH_RECT;
850 :
851 0 : aDash.SetDashStyle( eXDS );
852 0 : aDash.SetDots( (sal_uInt8) m_pNumFldNumber1->GetValue() );
853 0 : aDash.SetDotLen( m_pLbType1->GetSelectEntryPos() == 0 ? 0 : GetCoreValue( *m_pMtrLength1, ePoolUnit ) );
854 0 : aDash.SetDashes( (sal_uInt8) m_pNumFldNumber2->GetValue() );
855 0 : aDash.SetDashLen( m_pLbType2->GetSelectEntryPos() == 0 ? 0 : GetCoreValue( *m_pMtrLength2, ePoolUnit ) );
856 0 : aDash.SetDistance( GetCoreValue( *m_pMtrDistance, ePoolUnit ) );
857 :
858 0 : rXLSet.Put( XLineDashItem( OUString(), aDash ) );
859 :
860 : // #i34740#
861 0 : m_pCtlPreview->SetLineAttributes(aXLineAttr.GetItemSet());
862 0 : }
863 :
864 :
865 :
866 0 : void SvxLineDefTabPage::FillDialog_Impl()
867 : {
868 0 : XDashStyle eXDS = aDash.GetDashStyle(); // XDASH_RECT, XDASH_ROUND
869 0 : if( eXDS == XDASH_RECTRELATIVE )
870 0 : m_pCbxSynchronize->Check();
871 : else
872 0 : m_pCbxSynchronize->Check( false );
873 :
874 0 : m_pNumFldNumber1->SetValue( aDash.GetDots() );
875 0 : SetMetricValue( *m_pMtrLength1, aDash.GetDotLen(), ePoolUnit );
876 0 : m_pLbType1->SelectEntryPos( aDash.GetDotLen() == 0 ? 0 : 1 );
877 0 : m_pNumFldNumber2->SetValue( aDash.GetDashes() );
878 0 : SetMetricValue( *m_pMtrLength2, aDash.GetDashLen(), ePoolUnit );
879 0 : m_pLbType2->SelectEntryPos( aDash.GetDashLen() == 0 ? 0 : 1 );
880 0 : SetMetricValue( *m_pMtrDistance, aDash.GetDistance(), ePoolUnit );
881 :
882 0 : ChangeMetricHdl_Impl( NULL );
883 :
884 : // save values for changes recognition (-> method)
885 0 : m_pNumFldNumber1->SaveValue();
886 0 : m_pMtrLength1->SaveValue();
887 0 : m_pLbType1->SaveValue();
888 0 : m_pNumFldNumber2->SaveValue();
889 0 : m_pMtrLength2->SaveValue();
890 0 : m_pLbType2->SaveValue();
891 0 : m_pMtrDistance->SaveValue();
892 0 : }
893 :
894 :
895 0 : void SvxLineDefTabPage::DataChanged( const DataChangedEvent& rDCEvt )
896 : {
897 0 : SfxTabPage::DataChanged( rDCEvt );
898 :
899 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
900 : {
901 0 : sal_Int32 nOldSelect = m_pLbLineStyles->GetSelectEntryPos();
902 0 : m_pLbLineStyles->Clear();
903 0 : m_pLbLineStyles->Fill( pDashList );
904 0 : m_pLbLineStyles->SelectEntryPos( nOldSelect );
905 : }
906 0 : }
907 :
908 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|