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