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