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/shl.hxx>
21 : #include <tools/urlobj.hxx>
22 : #include <vcl/msgbox.hxx>
23 : #include <vcl/settings.hxx>
24 : #include <unotools/pathoptions.hxx>
25 : #include <sfx2/app.hxx>
26 : #include <sfx2/module.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 :
33 : #include "svx/xattr.hxx"
34 : #include <svx/xpool.hxx>
35 : #include <svx/xtable.hxx>
36 :
37 : #include "svx/drawitem.hxx"
38 : #include "cuitabline.hxx"
39 : #include "dlgname.hxx"
40 : #include "defdlgname.hxx"
41 : #include <svx/svxdlg.hxx>
42 : #include <dialmgr.hxx>
43 : #include "svx/dlgutil.hxx"
44 : #include <svx/dialmgr.hxx>
45 : #include <svx/dialogs.hrc>
46 :
47 : #define XOUT_WIDTH 150
48 :
49 0 : SvxLineDefTabPage::SvxLineDefTabPage
50 : (
51 : Window* pParent,
52 : const SfxItemSet& rInAttrs
53 : ) :
54 :
55 : SfxTabPage( pParent
56 : , "LineStylePage"
57 : , "cui/ui/linestyletabpage.ui"
58 : , rInAttrs ),
59 : rOutAttrs ( rInAttrs ),
60 :
61 0 : pXPool ( (XOutdevItemPool*) rInAttrs.GetPool() ),
62 : aXLStyle ( XLINE_DASH ),
63 : aXWidth ( XOUT_WIDTH ),
64 : aXDash ( OUString(), XDash( XDASH_RECT, 3, 7, 2, 40, 15 ) ),
65 : aXColor ( OUString(), COL_BLACK ),
66 : aXLineAttr ( pXPool ),
67 0 : rXLSet ( aXLineAttr.GetItemSet() )
68 : {
69 :
70 0 : get(m_pLbLineStyles ,"LB_LINESTYLES");
71 0 : get(m_pLbType1 ,"LB_TYPE_1");
72 0 : get(m_pLbType2 ,"LB_TYPE_2");
73 0 : get(m_pNumFldNumber1 ,"NUM_FLD_1");
74 0 : get(m_pNumFldNumber2 ,"NUM_FLD_2");
75 0 : get(m_pMtrLength1 ,"MTR_FLD_LENGTH_1");
76 0 : m_pMtrLength1->SetCustomUnitText("%");
77 0 : get(m_pMtrLength2 ,"MTR_FLD_LENGTH_2");
78 0 : m_pMtrLength2->SetCustomUnitText("%");
79 0 : get(m_pMtrDistance ,"MTR_FLD_DISTANCE");
80 0 : m_pMtrDistance->SetCustomUnitText("%");
81 0 : get(m_pCbxSynchronize ,"CBX_SYNCHRONIZE");
82 0 : get(m_pBtnAdd ,"BTN_ADD");
83 0 : get(m_pBtnModify ,"BTN_MODIFY");
84 0 : get(m_pBtnDelete ,"BTN_DELETE");
85 0 : get(m_pBtnLoad ,"BTN_LOAD");
86 0 : get(m_pBtnSave ,"BTN_SAVE");
87 0 : get(m_pCtlPreview ,"CTL_PREVIEW");
88 :
89 : // this page needs ExchangeSupport
90 0 : SetExchangeSupport();
91 :
92 : // adjust metric
93 0 : eFUnit = GetModuleFieldUnit( rInAttrs );
94 :
95 0 : switch ( eFUnit )
96 : {
97 : case FUNIT_M:
98 : case FUNIT_KM:
99 0 : eFUnit = FUNIT_MM;
100 0 : break;
101 : default: ; //prevent warning
102 : }
103 0 : SetFieldUnit( *m_pMtrDistance, eFUnit );
104 0 : SetFieldUnit( *m_pMtrLength1, eFUnit );
105 0 : SetFieldUnit( *m_pMtrLength2, eFUnit );
106 :
107 : // determine PoolUnit
108 0 : SfxItemPool* pPool = rOutAttrs.GetPool();
109 : DBG_ASSERT( pPool, "Wo ist der Pool?" );
110 0 : ePoolUnit = pPool->GetMetric( SID_ATTR_LINE_WIDTH );
111 :
112 0 : rXLSet.Put( aXLStyle );
113 0 : rXLSet.Put( aXWidth );
114 0 : rXLSet.Put( aXDash );
115 0 : rXLSet.Put( aXColor );
116 :
117 : // #i34740#
118 0 : m_pCtlPreview->SetLineAttributes(aXLineAttr.GetItemSet());
119 :
120 0 : m_pBtnAdd->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickAddHdl_Impl ) );
121 0 : m_pBtnModify->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickModifyHdl_Impl ) );
122 0 : m_pBtnDelete->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickDeleteHdl_Impl ) );
123 0 : m_pBtnLoad->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickLoadHdl_Impl ) );
124 0 : m_pBtnSave->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickSaveHdl_Impl ) );
125 :
126 0 : m_pNumFldNumber1->SetModifyHdl( LINK( this, SvxLineDefTabPage, ChangeNumber1Hdl_Impl ) );
127 0 : m_pNumFldNumber2->SetModifyHdl( LINK( this, SvxLineDefTabPage, ChangeNumber2Hdl_Impl ) );
128 0 : m_pLbLineStyles->SetSelectHdl( LINK( this, SvxLineDefTabPage, SelectLinestyleHdl_Impl ) );
129 :
130 : // #i122042# switch off default adding of 'none' and 'solid' entries
131 : // for this ListBox; we want to select only editable/dashed styles
132 0 : m_pLbLineStyles->setAddStandardFields(false);
133 :
134 : // absolute (in mm) or relative (in %)
135 0 : m_pCbxSynchronize->SetClickHdl( LINK( this, SvxLineDefTabPage, ChangeMetricHdl_Impl ) );
136 :
137 : // preview must be updated when there's something changed
138 0 : Link aLink = LINK( this, SvxLineDefTabPage, SelectTypeHdl_Impl );
139 0 : m_pLbType1->SetSelectHdl( aLink );
140 0 : m_pLbType2->SetSelectHdl( aLink );
141 0 : aLink = LINK( this, SvxLineDefTabPage, ChangePreviewHdl_Impl );
142 0 : m_pMtrLength1->SetModifyHdl( aLink );
143 0 : m_pMtrLength2->SetModifyHdl( aLink );
144 0 : m_pMtrDistance->SetModifyHdl( aLink );
145 :
146 0 : pDashList = NULL;
147 0 : }
148 :
149 :
150 :
151 :
152 0 : void SvxLineDefTabPage::Construct()
153 : {
154 : // Line style fill; do *not* add default fields here
155 0 : m_pLbLineStyles->Fill( pDashList );
156 0 : }
157 :
158 :
159 :
160 0 : void SvxLineDefTabPage::ActivatePage( const SfxItemSet& )
161 : {
162 0 : if( nDlgType == 0 ) // area dialog
163 : {
164 : // ActivatePage() is called before the dialog receives PageCreated() !!!
165 0 : if( pDashList.is() )
166 : {
167 0 : if( *pPageType == 1 &&
168 0 : *pPosDashLb != LISTBOX_ENTRY_NOTFOUND )
169 : {
170 0 : m_pLbLineStyles->SelectEntryPos( *pPosDashLb );
171 : }
172 : // so that a possibly existing line style is discarded
173 0 : SelectLinestyleHdl_Impl( this );
174 :
175 : // determining (and possibly cutting) the name
176 : // and displaying it in the GroupBox
177 : // OUString aString( CUI_RES( RID_SVXSTR_TABLE ) );
178 : // aString += ": ";
179 0 : INetURLObject aURL( pDashList->GetPath() );
180 :
181 0 : aURL.Append( pDashList->GetName() );
182 : DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
183 :
184 0 : *pPageType = 0; // 2
185 0 : *pPosDashLb = LISTBOX_ENTRY_NOTFOUND;
186 : }
187 : }
188 0 : }
189 :
190 :
191 :
192 0 : int SvxLineDefTabPage::DeactivatePage( SfxItemSet* _pSet )
193 : {
194 0 : CheckChanges_Impl();
195 :
196 0 : if( _pSet )
197 0 : FillItemSet( *_pSet );
198 :
199 0 : return( LEAVE_PAGE );
200 : }
201 :
202 :
203 :
204 0 : void SvxLineDefTabPage::CheckChanges_Impl()
205 : {
206 : // is here used to NOT lose changes
207 : //XDashStyle eXDS;
208 :
209 0 : if( m_pNumFldNumber1->GetText() != m_pNumFldNumber1->GetSavedValue() ||
210 0 : m_pMtrLength1->GetText() != m_pMtrLength1->GetSavedValue() ||
211 0 : m_pLbType1->GetSelectEntryPos() != m_pLbType1->GetSavedValue() ||
212 0 : m_pNumFldNumber2->GetText() != m_pNumFldNumber2->GetSavedValue() ||
213 0 : m_pMtrLength2->GetText() != m_pMtrLength2->GetSavedValue() ||
214 0 : m_pLbType2->GetSelectEntryPos() != m_pLbType2->GetSavedValue() ||
215 0 : m_pMtrDistance->GetText() != m_pMtrDistance->GetSavedValue() )
216 : {
217 0 : ResMgr& rMgr = CUI_MGR();
218 0 : Image aWarningBoxImage = WarningBox::GetStandardImage();
219 0 : SvxMessDialog* aMessDlg = new SvxMessDialog(GetParentDialog(),
220 0 : SVX_RESSTR( RID_SVXSTR_LINESTYLE ),
221 : OUString( ResId( RID_SVXSTR_ASK_CHANGE_LINESTYLE, rMgr ) ),
222 0 : &aWarningBoxImage );
223 : DBG_ASSERT(aMessDlg, "Dialogdiet fail!");
224 0 : aMessDlg->SetButtonText( MESS_BTN_1, OUString( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
225 0 : aMessDlg->SetButtonText( MESS_BTN_2, OUString( ResId( RID_SVXSTR_ADD, rMgr ) ) );
226 :
227 0 : short nRet = aMessDlg->Execute();
228 :
229 0 : switch( nRet )
230 : {
231 : case RET_BTN_1:
232 : {
233 0 : ClickModifyHdl_Impl( this );
234 : }
235 0 : break;
236 :
237 : case RET_BTN_2:
238 : {
239 0 : ClickAddHdl_Impl( this );
240 : }
241 0 : break;
242 :
243 : case RET_CANCEL:
244 0 : break;
245 : }
246 0 : delete aMessDlg;
247 : }
248 :
249 :
250 :
251 0 : sal_Int32 nPos = m_pLbLineStyles->GetSelectEntryPos();
252 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
253 : {
254 0 : *pPosDashLb = nPos;
255 : }
256 0 : }
257 :
258 :
259 :
260 0 : bool SvxLineDefTabPage::FillItemSet( SfxItemSet& rAttrs )
261 : {
262 0 : if( nDlgType == 0 ) // line dialog
263 : {
264 0 : if( *pPageType == 2 )
265 : {
266 0 : FillDash_Impl();
267 :
268 0 : OUString aString( m_pLbLineStyles->GetSelectEntry() );
269 0 : rAttrs.Put( XLineStyleItem( XLINE_DASH ) );
270 0 : rAttrs.Put( XLineDashItem( aString, aDash ) );
271 : }
272 : }
273 0 : return true;
274 : }
275 :
276 :
277 :
278 0 : void SvxLineDefTabPage::Reset( const SfxItemSet& rAttrs )
279 : {
280 0 : if( rAttrs.GetItemState( GetWhich( XATTR_LINESTYLE ) ) != SFX_ITEM_DONTCARE )
281 : {
282 0 : XLineStyle eXLS = (XLineStyle) ( ( const XLineStyleItem& ) rAttrs.Get( GetWhich( XATTR_LINESTYLE ) ) ).GetValue();
283 :
284 0 : switch( eXLS )
285 : {
286 : case XLINE_NONE:
287 : case XLINE_SOLID:
288 0 : m_pLbLineStyles->SelectEntryPos( 0 );
289 0 : break;
290 :
291 : case XLINE_DASH:
292 : {
293 0 : const XLineDashItem& rDashItem = ( const XLineDashItem& ) rAttrs.Get( XATTR_LINEDASH );
294 0 : aDash = rDashItem.GetDashValue();
295 :
296 0 : m_pLbLineStyles->SetNoSelection();
297 0 : m_pLbLineStyles->SelectEntry( rDashItem.GetName() );
298 : }
299 0 : break;
300 :
301 : default:
302 0 : break;
303 : }
304 : }
305 0 : SelectLinestyleHdl_Impl( NULL );
306 :
307 : // determine button state
308 0 : if( pDashList->Count() )
309 : {
310 0 : m_pBtnModify->Enable();
311 0 : m_pBtnDelete->Enable();
312 0 : m_pBtnSave->Enable();
313 : }
314 : else
315 : {
316 0 : m_pBtnModify->Disable();
317 0 : m_pBtnDelete->Disable();
318 0 : m_pBtnSave->Disable();
319 : }
320 0 : }
321 :
322 :
323 :
324 0 : SfxTabPage* SvxLineDefTabPage::Create( Window* pWindow, const SfxItemSet& rOutAttrs )
325 : {
326 0 : return( new SvxLineDefTabPage( pWindow, rOutAttrs ) );
327 : }
328 :
329 :
330 :
331 0 : IMPL_LINK( SvxLineDefTabPage, SelectLinestyleHdl_Impl, void *, p )
332 : {
333 0 : if(pDashList->Count())
334 : {
335 0 : int nTmp = m_pLbLineStyles->GetSelectEntryPos();
336 :
337 0 : if(LISTBOX_ENTRY_NOTFOUND == nTmp)
338 : {
339 : OSL_ENSURE(false, "OOps, non-existent LineDash selected (!)");
340 0 : nTmp = 1;
341 : }
342 :
343 0 : aDash = pDashList->GetDash( nTmp )->GetDash();
344 :
345 0 : FillDialog_Impl();
346 :
347 0 : rXLSet.Put( XLineDashItem( OUString(), aDash ) );
348 :
349 : // #i34740#
350 0 : m_pCtlPreview->SetLineAttributes(aXLineAttr.GetItemSet());
351 :
352 0 : m_pCtlPreview->Invalidate();
353 :
354 : // Is not set before, in order to take the new style
355 : // only if there was an entry selected in the ListBox.
356 : // If it was called via Reset(), then p is == NULL
357 0 : if( p )
358 0 : *pPageType = 2;
359 : }
360 0 : return( 0L );
361 : }
362 :
363 :
364 :
365 0 : IMPL_LINK_NOARG_INLINE_START(SvxLineDefTabPage, ChangePreviewHdl_Impl)
366 : {
367 0 : FillDash_Impl();
368 0 : m_pCtlPreview->Invalidate();
369 :
370 0 : return( 0L );
371 : }
372 0 : IMPL_LINK_NOARG_INLINE_END(SvxLineDefTabPage, ChangePreviewHdl_Impl)
373 :
374 :
375 :
376 0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ChangeNumber1Hdl_Impl)
377 : {
378 0 : if( m_pNumFldNumber1->GetValue() == 0L )
379 : {
380 0 : m_pNumFldNumber2->SetMin( 1L );
381 0 : m_pNumFldNumber2->SetFirst( 1L );
382 : }
383 : else
384 : {
385 0 : m_pNumFldNumber2->SetMin( 0L );
386 0 : m_pNumFldNumber2->SetFirst( 0L );
387 : }
388 :
389 0 : ChangePreviewHdl_Impl( this );
390 :
391 0 : return( 0L );
392 : }
393 :
394 :
395 :
396 0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ChangeNumber2Hdl_Impl)
397 : {
398 0 : if( m_pNumFldNumber2->GetValue() == 0L )
399 : {
400 0 : m_pNumFldNumber1->SetMin( 1L );
401 0 : m_pNumFldNumber1->SetFirst( 1L );
402 : }
403 : else
404 : {
405 0 : m_pNumFldNumber1->SetMin( 0L );
406 0 : m_pNumFldNumber1->SetFirst( 0L );
407 : }
408 :
409 0 : ChangePreviewHdl_Impl( this );
410 :
411 0 : return( 0L );
412 : }
413 :
414 :
415 :
416 :
417 0 : IMPL_LINK( SvxLineDefTabPage, ChangeMetricHdl_Impl, void *, p )
418 : {
419 0 : if( !m_pCbxSynchronize->IsChecked() && m_pMtrLength1->GetUnit() != eFUnit )
420 : {
421 : long nTmp1, nTmp2, nTmp3;
422 :
423 : // was changed with Control
424 0 : if( p )
425 : {
426 0 : nTmp1 = GetCoreValue( *m_pMtrLength1, ePoolUnit ) * XOUT_WIDTH / 100;
427 0 : nTmp2 = GetCoreValue( *m_pMtrLength2, ePoolUnit ) * XOUT_WIDTH / 100;
428 0 : nTmp3 = GetCoreValue( *m_pMtrDistance, ePoolUnit ) * XOUT_WIDTH / 100;
429 : }
430 : else
431 : {
432 0 : nTmp1 = GetCoreValue( *m_pMtrLength1, ePoolUnit );
433 0 : nTmp2 = GetCoreValue( *m_pMtrLength2, ePoolUnit );
434 0 : nTmp3 = GetCoreValue( *m_pMtrDistance, ePoolUnit );
435 : }
436 0 : m_pMtrLength1->SetDecimalDigits( 2 );
437 0 : m_pMtrLength2->SetDecimalDigits( 2 );
438 0 : m_pMtrDistance->SetDecimalDigits( 2 );
439 :
440 : // adjust metric
441 0 : m_pMtrLength1->SetUnit( eFUnit );
442 0 : m_pMtrLength2->SetUnit( eFUnit );
443 0 : m_pMtrDistance->SetUnit( eFUnit );
444 :
445 0 : SetMetricValue( *m_pMtrLength1, nTmp1, ePoolUnit );
446 0 : SetMetricValue( *m_pMtrLength2, nTmp2, ePoolUnit );
447 0 : SetMetricValue( *m_pMtrDistance, nTmp3, ePoolUnit );
448 : }
449 0 : else if( m_pCbxSynchronize->IsChecked() && m_pMtrLength1->GetUnit() != FUNIT_PERCENT )
450 : {
451 : long nTmp1, nTmp2, nTmp3;
452 :
453 : // was changed with Control
454 0 : if( p )
455 : {
456 0 : nTmp1 = GetCoreValue( *m_pMtrLength1, ePoolUnit ) * 100 / XOUT_WIDTH;
457 0 : nTmp2 = GetCoreValue( *m_pMtrLength2, ePoolUnit ) * 100 / XOUT_WIDTH;
458 0 : nTmp3 = GetCoreValue( *m_pMtrDistance, ePoolUnit ) * 100 / XOUT_WIDTH;
459 : }
460 : else
461 : {
462 0 : nTmp1 = GetCoreValue( *m_pMtrLength1, ePoolUnit );
463 0 : nTmp2 = GetCoreValue( *m_pMtrLength2, ePoolUnit );
464 0 : nTmp3 = GetCoreValue( *m_pMtrDistance, ePoolUnit );
465 : }
466 :
467 0 : m_pMtrLength1->SetDecimalDigits( 0 );
468 0 : m_pMtrLength2->SetDecimalDigits( 0 );
469 0 : m_pMtrDistance->SetDecimalDigits( 0 );
470 :
471 0 : m_pMtrLength1->SetUnit( FUNIT_PERCENT );
472 0 : m_pMtrLength2->SetUnit( FUNIT_PERCENT );
473 0 : m_pMtrDistance->SetUnit( FUNIT_PERCENT );
474 :
475 0 : SetMetricValue( *m_pMtrLength1, nTmp1, ePoolUnit );
476 0 : SetMetricValue( *m_pMtrLength2, nTmp2, ePoolUnit );
477 0 : SetMetricValue( *m_pMtrDistance, nTmp3, ePoolUnit );
478 :
479 : }
480 0 : SelectTypeHdl_Impl( NULL );
481 :
482 0 : return( 0L );
483 : }
484 :
485 :
486 :
487 0 : IMPL_LINK( SvxLineDefTabPage, SelectTypeHdl_Impl, void *, p )
488 : {
489 0 : if ( p == m_pLbType1 || !p )
490 : {
491 0 : if ( m_pLbType1->GetSelectEntryPos() == 0 )
492 : {
493 0 : m_pMtrLength1->Disable();
494 0 : m_pMtrLength1->SetText( "" );
495 : }
496 0 : else if ( !m_pMtrLength1->IsEnabled() )
497 : {
498 0 : m_pMtrLength1->Enable();
499 0 : m_pMtrLength1->Reformat();
500 : }
501 : }
502 :
503 0 : if ( p == m_pLbType2 || !p )
504 : {
505 0 : if ( m_pLbType2->GetSelectEntryPos() == 0 )
506 : {
507 0 : m_pMtrLength2->Disable();
508 0 : m_pMtrLength2->SetText( "" );
509 : }
510 0 : else if ( !m_pMtrLength2->IsEnabled() )
511 : {
512 0 : m_pMtrLength2->Enable();
513 0 : m_pMtrLength2->Reformat();
514 : }
515 : }
516 0 : ChangePreviewHdl_Impl( p );
517 0 : return( 0L );
518 : }
519 :
520 :
521 :
522 0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ClickAddHdl_Impl)
523 : {
524 0 : ResMgr& rMgr = CUI_MGR();
525 0 : OUString aNewName( SVX_RES( RID_SVXSTR_LINESTYLE ) );
526 0 : OUString aDesc( ResId( RID_SVXSTR_DESC_LINESTYLE, rMgr ) );
527 0 : OUString aName;
528 : XDashEntry* pEntry;
529 :
530 0 : long nCount = pDashList->Count();
531 0 : long j = 1;
532 0 : sal_Bool bDifferent = sal_False;
533 :
534 0 : while ( !bDifferent )
535 : {
536 0 : aName = aNewName;
537 0 : aName += " ";
538 0 : aName += OUString::number( j++ );
539 0 : bDifferent = sal_True;
540 :
541 0 : for ( long i = 0; i < nCount && bDifferent; i++ )
542 0 : if ( aName == pDashList->GetDash( i )->GetName() )
543 0 : bDifferent = sal_False;
544 : }
545 :
546 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
547 : DBG_ASSERT(pFact, "Dialogdiet fail!");
548 0 : AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
549 : DBG_ASSERT(pDlg, "Dialogdiet fail!");
550 0 : sal_Bool bLoop = sal_True;
551 :
552 0 : while ( bLoop && pDlg->Execute() == RET_OK )
553 : {
554 0 : pDlg->GetName( aName );
555 0 : bDifferent = sal_True;
556 :
557 0 : for( long i = 0; i < nCount && bDifferent; i++ )
558 : {
559 0 : if( aName == pDashList->GetDash( i )->GetName() )
560 0 : bDifferent = sal_False;
561 : }
562 :
563 0 : if( bDifferent )
564 : {
565 0 : bLoop = sal_False;
566 0 : FillDash_Impl();
567 :
568 0 : pEntry = new XDashEntry( aDash, aName );
569 :
570 0 : long nDashCount = pDashList->Count();
571 0 : pDashList->Insert( pEntry, nDashCount );
572 0 : const Bitmap aBitmap = pDashList->GetUiBitmap( nDashCount );
573 0 : m_pLbLineStyles->Append( *pEntry, pDashList->GetUiBitmap( nDashCount ) );
574 :
575 0 : m_pLbLineStyles->SelectEntryPos( m_pLbLineStyles->GetEntryCount() - 1 );
576 :
577 0 : *pnDashListState |= CT_MODIFIED;
578 :
579 0 : *pPageType = 2;
580 :
581 : // save values for changes recognition (-> method)
582 0 : m_pNumFldNumber1->SaveValue();
583 0 : m_pMtrLength1->SaveValue();
584 0 : m_pLbType1->SaveValue();
585 0 : m_pNumFldNumber2->SaveValue();
586 0 : m_pMtrLength2->SaveValue();
587 0 : m_pLbType2->SaveValue();
588 0 : m_pMtrDistance->SaveValue();
589 : }
590 : else
591 : {
592 :
593 0 : MessageDialog aBox( GetParentDialog()
594 : ,"DuplicateNameDialog"
595 0 : ,"cui/ui/queryduplicatedialog.ui");
596 0 : aBox.Execute();
597 : }
598 : }
599 0 : delete( pDlg );
600 :
601 : // determine button state
602 0 : if ( pDashList->Count() )
603 : {
604 0 : m_pBtnModify->Enable();
605 0 : m_pBtnDelete->Enable();
606 0 : m_pBtnSave->Enable();
607 : }
608 0 : return( 0L );
609 : }
610 :
611 :
612 :
613 0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ClickModifyHdl_Impl)
614 : {
615 0 : sal_Int32 nPos = m_pLbLineStyles->GetSelectEntryPos();
616 :
617 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
618 : {
619 0 : ResMgr& rMgr = CUI_MGR();
620 0 : OUString aDesc( ResId( RID_SVXSTR_DESC_LINESTYLE, rMgr ) );
621 0 : OUString aName( pDashList->GetDash( nPos )->GetName() );
622 0 : OUString aOldName = aName;
623 :
624 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
625 : DBG_ASSERT(pFact, "Dialogdiet fail!");
626 0 : AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
627 : DBG_ASSERT(pDlg, "Dialogdiet fail!");
628 :
629 0 : long nCount = pDashList->Count();
630 0 : sal_Bool bDifferent = sal_False;
631 0 : sal_Bool bLoop = sal_True;
632 :
633 0 : while ( bLoop && pDlg->Execute() == RET_OK )
634 : {
635 0 : pDlg->GetName( aName );
636 0 : bDifferent = sal_True;
637 :
638 0 : for( long i = 0; i < nCount && bDifferent; i++ )
639 : {
640 0 : if( aName == pDashList->GetDash( i )->GetName() &&
641 0 : aName != aOldName )
642 0 : bDifferent = sal_False;
643 : }
644 :
645 0 : if ( bDifferent )
646 : {
647 0 : bLoop = sal_False;
648 0 : FillDash_Impl();
649 :
650 0 : XDashEntry* pEntry = new XDashEntry( aDash, aName );
651 :
652 0 : delete pDashList->Replace( pEntry, nPos );
653 0 : m_pLbLineStyles->Modify( *pEntry, nPos, pDashList->GetUiBitmap( nPos ) );
654 :
655 0 : m_pLbLineStyles->SelectEntryPos( nPos );
656 :
657 0 : *pnDashListState |= CT_MODIFIED;
658 :
659 0 : *pPageType = 2;
660 :
661 : // save values for changes recognition (-> method)
662 0 : m_pNumFldNumber1->SaveValue();
663 0 : m_pMtrLength1->SaveValue();
664 0 : m_pLbType1->SaveValue();
665 0 : m_pNumFldNumber2->SaveValue();
666 0 : m_pMtrLength2->SaveValue();
667 0 : m_pLbType2->SaveValue();
668 0 : m_pMtrDistance->SaveValue();
669 : }
670 : else
671 : {
672 0 : MessageDialog aBox( GetParentDialog()
673 : ,"DuplicateNameDialog"
674 0 : ,"cui/ui/queryduplicatedialog.ui");
675 0 : aBox.Execute();
676 : }
677 : }
678 0 : delete( pDlg );
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::CreatePropertyList( XDASH_LIST, aPathURL.GetMainURL( INetURLObject::NO_DECODE ), "" )->AsDashList();
753 0 : pDshLst->SetName( aURL.getName() );
754 :
755 0 : if( pDshLst->Load() )
756 : {
757 0 : pDashList = pDshLst;
758 0 : ( (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: */
|