xref: /trunk/main/cui/source/tabpages/tplnedef.cxx (revision c7be74b1)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <tools/shl.hxx>
29 #include <tools/urlobj.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <unotools/pathoptions.hxx>
32 #include <sfx2/app.hxx>
33 #include <sfx2/module.hxx>
34 #include <sfx2/filedlghelper.hxx>
35 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
36 
37 #define _SVX_TPLNEDEF_CXX
38 
39 #include <cuires.hrc>
40 #include "tabline.hrc"
41 //#include "dlgname.hrc"
42 #include "helpid.hrc"
43 
44 #include "svx/xattr.hxx"
45 #include <svx/xpool.hxx>
46 #include <svx/xtable.hxx>
47 
48 #include "svx/drawitem.hxx"
49 #include "cuitabline.hxx"
50 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx"
51 #include <svx/svxdlg.hxx> //CHINA001
52 #include <dialmgr.hxx>
53 #include "svx/dlgutil.hxx"
54 #include <svx/dialmgr.hxx>
55 #include <svx/dialogs.hrc>
56 
57 #define DLGWIN this->GetParent()->GetParent()
58 
59 #define BITMAP_WIDTH   32
60 #define BITMAP_HEIGHT  12
61 #define XOUT_WIDTH    150
62 
63 /*************************************************************************
64 |*
65 |*	Dialog zum Definieren von Linienstilen
66 |*
67 \************************************************************************/
68 
69 SvxLineDefTabPage::SvxLineDefTabPage
70 (
71 	Window* pParent,
72 	const SfxItemSet& rInAttrs
73 ) :
74 
75 	SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_LINE_DEF ), rInAttrs ),
76 
77     aFlDefinition   ( this, CUI_RES( FL_DEFINITION ) ),
78     aFTLinestyle    ( this, CUI_RES( FT_LINESTYLE ) ),
79     aLbLineStyles   ( this, CUI_RES( LB_LINESTYLES ) ),
80     aFtType         ( this, CUI_RES( FT_TYPE ) ),
81 	aLbType1		( this, CUI_RES( LB_TYPE_1 ) ),
82 	aLbType2		( this, CUI_RES( LB_TYPE_2 ) ),
83 	aFtNumber		( this, CUI_RES( FT_NUMBER ) ),
84 	aNumFldNumber1	( this, CUI_RES( NUM_FLD_1 ) ),
85 	aNumFldNumber2	( this, CUI_RES( NUM_FLD_2 ) ),
86     aFtLength       ( this, CUI_RES( FT_LENGTH ) ),
87     aMtrLength1     ( this, CUI_RES( MTR_FLD_LENGTH_1 ) ),
88     aMtrLength2     ( this, CUI_RES( MTR_FLD_LENGTH_2 ) ),
89     aFtDistance     ( this, CUI_RES( FT_DISTANCE ) ),
90 	aMtrDistance	( this, CUI_RES( MTR_FLD_DISTANCE ) ),
91     aCbxSynchronize ( this, CUI_RES( CBX_SYNCHRONIZE ) ),
92     aBtnAdd         ( this, CUI_RES( BTN_ADD ) ),
93 	aBtnModify		( this, CUI_RES( BTN_MODIFY ) ),
94 	aBtnDelete		( this, CUI_RES( BTN_DELETE ) ),
95     aBtnLoad        ( this, CUI_RES( BTN_LOAD ) ),
96 	aBtnSave		( this, CUI_RES( BTN_SAVE ) ),
97     aCtlPreview     ( this, CUI_RES( CTL_PREVIEW ) ),
98 
99     rOutAttrs       ( rInAttrs ),
100 
101     pXPool              ( (XOutdevItemPool*) rInAttrs.GetPool() ),
102     aXLStyle            ( XLINE_DASH ),
103     aXWidth             ( XOUT_WIDTH ),
104     aXDash              ( String(), XDash( XDASH_RECT, 3, 7, 2, 40, 15 ) ),
105     aXColor             ( String(), COL_BLACK ),
106     aXLineAttr          ( pXPool ),
107     rXLSet              ( aXLineAttr.GetItemSet() )
108 {
109 	aBtnLoad.SetModeImage( Image( CUI_RES( RID_SVXIMG_LOAD_H ) ), BMP_COLOR_HIGHCONTRAST );
110 	aBtnSave.SetModeImage( Image( CUI_RES( RID_SVXIMG_SAVE_H ) ), BMP_COLOR_HIGHCONTRAST );
111 
112 	aLbType1.SetAccessibleName(String(CUI_RES( STR_START_TYPE ) ) );
113 	aLbType2.SetAccessibleName(String(CUI_RES( STR_END_TYPE ) ) );
114 	aNumFldNumber1.SetAccessibleName(String(CUI_RES( STR_START_NUM ) ) );
115 	aNumFldNumber2.SetAccessibleName(String(CUI_RES( STR_END_NUM ) ) );
116 	aMtrLength1.SetAccessibleName(String(CUI_RES( STR_START_LENGTH ) ) );
117 	aMtrLength2.SetAccessibleName(String(CUI_RES( STR_END_LENGTH ) ) );
118 
119 	FreeResource();
120 
121 	// diese Page braucht ExchangeSupport
122 	SetExchangeSupport();
123 
124 	// Metrik einstellen
125 	eFUnit = GetModuleFieldUnit( rInAttrs );
126 
127 	switch ( eFUnit )
128 	{
129 		case FUNIT_M:
130 		case FUNIT_KM:
131 			eFUnit = FUNIT_MM;
132 			break;
133         default: ; //prevent warning
134 	}
135 	SetFieldUnit( aMtrDistance, eFUnit );
136 	SetFieldUnit( aMtrLength1, eFUnit );
137 	SetFieldUnit( aMtrLength2, eFUnit );
138 
139 	// PoolUnit ermitteln
140 	SfxItemPool* pPool = rOutAttrs.GetPool();
141 	DBG_ASSERT( pPool, "Wo ist der Pool?" );
142 	ePoolUnit = pPool->GetMetric( SID_ATTR_LINE_WIDTH );
143 
144 	rXLSet.Put( aXLStyle );
145 	rXLSet.Put( aXWidth );
146 	rXLSet.Put( aXDash );
147 	rXLSet.Put( aXColor );
148 
149 	// #i34740#
150 	aCtlPreview.SetLineAttributes(aXLineAttr.GetItemSet());
151 
152 	aBtnAdd.SetClickHdl( LINK( this, SvxLineDefTabPage, ClickAddHdl_Impl ) );
153 	aBtnModify.SetClickHdl(
154 		LINK( this, SvxLineDefTabPage, ClickModifyHdl_Impl ) );
155 	aBtnDelete.SetClickHdl(
156 		LINK( this, SvxLineDefTabPage, ClickDeleteHdl_Impl ) );
157 	aBtnLoad.SetClickHdl( LINK( this, SvxLineDefTabPage, ClickLoadHdl_Impl ) );
158 	aBtnSave.SetClickHdl( LINK( this, SvxLineDefTabPage, ClickSaveHdl_Impl ) );
159 
160 	aNumFldNumber1.SetModifyHdl(
161 		LINK( this, SvxLineDefTabPage, ChangeNumber1Hdl_Impl ) );
162 	aNumFldNumber2.SetModifyHdl(
163 		LINK( this, SvxLineDefTabPage, ChangeNumber2Hdl_Impl ) );
164 	aLbLineStyles.SetSelectHdl(
165 		LINK( this, SvxLineDefTabPage, SelectLinestyleHdl_Impl ) );
166 
167     // #122042# switch off default adding of 'none' and 'solid' entries
168     // for this ListBox; we want to select only editable/dashed styles
169     aLbLineStyles.setAddStandardFields(false);
170 
171 	// Absolut (in mm) oder Relativ (in %)
172 	aCbxSynchronize.SetClickHdl(
173 		LINK( this, SvxLineDefTabPage, ChangeMetricHdl_Impl ) );
174 
175 	// Wenn sich etwas aendert, muss Preview upgedatet werden werden
176 	Link aLink = LINK( this, SvxLineDefTabPage, SelectTypeHdl_Impl );
177 	aLbType1.SetSelectHdl( aLink );
178 	aLbType2.SetSelectHdl( aLink );
179 	aLink = LINK( this, SvxLineDefTabPage, ChangePreviewHdl_Impl );
180 	aMtrLength1.SetModifyHdl( aLink );
181 	aMtrLength2.SetModifyHdl( aLink );
182 	aMtrDistance.SetModifyHdl( aLink );
183 
184 	aBtnAdd.SetAccessibleRelationMemberOf( &aFlDefinition );
185 	aBtnModify.SetAccessibleRelationMemberOf( &aFlDefinition );
186 	aBtnDelete.SetAccessibleRelationMemberOf( &aFlDefinition );
187 	aBtnLoad.SetAccessibleRelationMemberOf( &aFlDefinition );
188 	aBtnSave.SetAccessibleRelationMemberOf( &aFlDefinition );
189 }
190 
191 
192 // -----------------------------------------------------------------------
193 
194 void SvxLineDefTabPage::Construct()
195 {
196 	// Line style fill; do *not* add default fields here
197 	aLbLineStyles.Fill( maDashList );
198 }
199 
200 // -----------------------------------------------------------------------
201 
202 void SvxLineDefTabPage::ActivatePage( const SfxItemSet& )
203 {
204 	if( *pDlgType == 0 ) // Flaechen-Dialog
205 	{
206 		// ActivatePage() wird aufgerufen bevor der Dialog PageCreated() erhaelt !!!
207 		if( maDashList.get() )
208 		{
209             if( *pPageType == 1 &&
210 				*pPosDashLb != LISTBOX_ENTRY_NOTFOUND )
211 			{
212 				aLbLineStyles.SelectEntryPos( *pPosDashLb );
213 			}
214 			// Damit evtl. vorhandener Linestyle verworfen wird
215 			SelectLinestyleHdl_Impl( this );
216 
217 			// Ermitteln (evtl. abschneiden) des Namens und in
218 			// der GroupBox darstellen
219 			String			aString( CUI_RES( RID_SVXSTR_TABLE ) ); aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
220 			INetURLObject	aURL( maDashList->GetPath() );
221 
222 			aURL.Append( maDashList->GetName() );
223 			DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
224 
225 /*			if ( aURL.getBase().Len() > 18 )
226 			{
227 				aString += aURL.getBase().Copy( 0, 15 );
228 				aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
229 			}
230 			else
231 				aString += aURL.getBase();
232 
233 			aFTLinestyle.SetText( aString );
234 */
235 			*pPageType = 0; // 2
236 			*pPosDashLb = LISTBOX_ENTRY_NOTFOUND;
237 		}
238 	}
239 }
240 
241 // -----------------------------------------------------------------------
242 
243 int SvxLineDefTabPage::DeactivatePage( SfxItemSet* _pSet )
244 {
245 	CheckChanges_Impl();
246 
247     if( _pSet )
248         FillItemSet( *_pSet );
249 
250 	return( LEAVE_PAGE );
251 }
252 
253 // -----------------------------------------------------------------------
254 
255 void SvxLineDefTabPage::CheckChanges_Impl()
256 {
257 	// wird hier benutzt, um Aenderungen NICHT zu verlieren
258 	//XDashStyle eXDS;
259 
260 	if( aNumFldNumber1.GetText() 	 != aNumFldNumber1.GetSavedValue() ||
261 		aMtrLength1.GetText() 		 != aMtrLength1.GetSavedValue() ||
262 		aLbType1.GetSelectEntryPos() != aLbType1.GetSavedValue() ||
263 		aNumFldNumber2.GetText() 	 != aNumFldNumber2.GetSavedValue() ||
264 		aMtrLength2.GetText() 		 != aMtrLength2.GetSavedValue() ||
265 		aLbType2.GetSelectEntryPos() != aLbType2.GetSavedValue() ||
266 		aMtrDistance.GetText() 		 != aMtrDistance.GetSavedValue() )
267 	{
268 		ResMgr& rMgr = CUI_MGR();
269         Image aWarningBoxImage = WarningBox::GetStandardImage();
270 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
271 		DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
272 		AbstractSvxMessDialog* aMessDlg = pFact->CreateSvxMessDialog( DLGWIN, RID_SVXDLG_MESSBOX,
273 													SVX_RESSTR( RID_SVXSTR_LINESTYLE ),
274 													String( ResId( RID_SVXSTR_ASK_CHANGE_LINESTYLE, rMgr ) ),
275 													&aWarningBoxImage );
276 		DBG_ASSERT(aMessDlg, "Dialogdiet fail!");//CHINA001
277 		aMessDlg->SetButtonText( MESS_BTN_1, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1,
278 								String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
279 		aMessDlg->SetButtonText( MESS_BTN_2, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2,
280 								String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
281 
282 		short nRet = aMessDlg->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
283 
284 		switch( nRet )
285 		{
286 			case RET_BTN_1: // Aendern
287 			{
288 				ClickModifyHdl_Impl( this );
289 				//aXDash = maDashList->Get( nPos )->GetDash();
290 			}
291 			break;
292 
293 			case RET_BTN_2: // Hinzufuegen
294 			{
295 				ClickAddHdl_Impl( this );
296 				//nPos = aLbLineStyles.GetSelectEntryPos();
297 				//aXDash = maDashList->Get( nPos )->GetDash();
298 			}
299 			break;
300 
301 			case RET_CANCEL:
302 			break;
303 			// return( sal_True ); // Abbruch
304 		}
305 		delete aMessDlg; //add by CHINA001
306 	}
307 
308 
309 
310 	sal_uInt16 nPos = aLbLineStyles.GetSelectEntryPos();
311 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
312 	{
313 		*pPosDashLb = nPos;
314 	}
315 }
316 
317 // -----------------------------------------------------------------------
318 
319 sal_Bool SvxLineDefTabPage::FillItemSet( SfxItemSet& rAttrs )
320 {
321 	if( *pDlgType == 0 ) // Linien-Dialog
322 	{
323 		if( *pPageType == 2 )
324 		{
325 			//CheckChanges_Impl();
326 
327 			FillDash_Impl();
328 
329 			String aString( aLbLineStyles.GetSelectEntry() );
330 			rAttrs.Put( XLineStyleItem( XLINE_DASH ) );
331 			rAttrs.Put( XLineDashItem( aString, aDash ) );
332 		}
333 	}
334 	return( sal_True );
335 }
336 
337 // -----------------------------------------------------------------------
338 
339 void SvxLineDefTabPage::Reset( const SfxItemSet& rAttrs )
340 {
341 	if( rAttrs.GetItemState( GetWhich( XATTR_LINESTYLE ) ) != SFX_ITEM_DONTCARE )
342 	{
343 		XLineStyle eXLS = (XLineStyle) ( ( const XLineStyleItem& ) rAttrs.Get( GetWhich( XATTR_LINESTYLE ) ) ).GetValue();
344 
345 		switch( eXLS )
346 		{
347 			case XLINE_NONE:
348 			case XLINE_SOLID:
349 				aLbLineStyles.SelectEntryPos( 0 );
350 				break;
351 
352 			case XLINE_DASH:
353 			{
354 				const XLineDashItem& rDashItem = ( const XLineDashItem& ) rAttrs.Get( XATTR_LINEDASH );
355                 aDash = rDashItem.GetDashValue();
356 
357 				aLbLineStyles.SetNoSelection();
358 				aLbLineStyles.SelectEntry( rDashItem.GetName() );
359 			}
360 				break;
361 
362 			default:
363 				break;
364 		}
365 	}
366 	SelectLinestyleHdl_Impl( NULL );
367 
368 	// Status der Buttons ermitteln
369 	if( maDashList.get() && maDashList->Count() )
370 	{
371 		aBtnModify.Enable();
372 		aBtnDelete.Enable();
373 		aBtnSave.Enable();
374 	}
375 	else
376 	{
377 		aBtnModify.Disable();
378 		aBtnDelete.Disable();
379 		aBtnSave.Disable();
380 	}
381 }
382 
383 // -----------------------------------------------------------------------
384 
385 SfxTabPage* SvxLineDefTabPage::Create( Window* pWindow,
386 				const SfxItemSet& rOutAttrs )
387 {
388 	return( new SvxLineDefTabPage( pWindow, rOutAttrs ) );
389 }
390 
391 //------------------------------------------------------------------------
392 
393 IMPL_LINK( SvxLineDefTabPage, SelectLinestyleHdl_Impl, void *, p )
394 {
395 	if(maDashList.get() && maDashList->Count())
396 	{
397 		int nTmp = aLbLineStyles.GetSelectEntryPos();
398 
399         if(LISTBOX_ENTRY_NOTFOUND == nTmp)
400 		{
401             OSL_ENSURE(false, "OOps, non-existent LineDash selected (!)");
402             nTmp = 1;
403 		}
404 
405         aDash = maDashList->GetDash( nTmp )->GetDash();
406 
407 		FillDialog_Impl();
408 
409 		rXLSet.Put( XLineDashItem( String(), aDash ) );
410 
411 		// #i34740#
412 		aCtlPreview.SetLineAttributes(aXLineAttr.GetItemSet());
413 
414 		aCtlPreview.Invalidate();
415 
416 		// Wird erst hier gesetzt, um den Style nur dann zu uebernehmen,
417 		// wenn in der ListBox ein Eintrag ausgewaehlt wurde
418 		// Wenn ueber Reset() gerufen wurde ist p == NULL
419 		if( p )
420 			*pPageType = 2;
421 	}
422 	return( 0L );
423 }
424 
425 //------------------------------------------------------------------------
426 
427 IMPL_LINK_INLINE_START( SvxLineDefTabPage, ChangePreviewHdl_Impl, void *, EMPTYARG )
428 {
429 	FillDash_Impl();
430 	aCtlPreview.Invalidate();
431 
432 	return( 0L );
433 }
434 IMPL_LINK_INLINE_END( SvxLineDefTabPage, ChangePreviewHdl_Impl, void *, EMPTYARG )
435 
436 //------------------------------------------------------------------------
437 
438 IMPL_LINK( SvxLineDefTabPage, ChangeNumber1Hdl_Impl, void *, EMPTYARG )
439 {
440 	if( aNumFldNumber1.GetValue() == 0L )
441 	{
442         aNumFldNumber2.SetMin( 1L );
443         aNumFldNumber2.SetFirst( 1L );
444 	}
445 	else
446 	{
447         aNumFldNumber2.SetMin( 0L );
448         aNumFldNumber2.SetFirst( 0L );
449 	}
450 
451 	ChangePreviewHdl_Impl( this );
452 
453 	return( 0L );
454 }
455 
456 //------------------------------------------------------------------------
457 
458 IMPL_LINK( SvxLineDefTabPage, ChangeNumber2Hdl_Impl, void *, EMPTYARG )
459 {
460 	if( aNumFldNumber2.GetValue() == 0L )
461 	{
462         aNumFldNumber1.SetMin( 1L );
463         aNumFldNumber1.SetFirst( 1L );
464 	}
465 	else
466 	{
467         aNumFldNumber1.SetMin( 0L );
468         aNumFldNumber1.SetFirst( 0L );
469 	}
470 
471 	ChangePreviewHdl_Impl( this );
472 
473 	return( 0L );
474 }
475 
476 
477 //------------------------------------------------------------------------
478 
479 IMPL_LINK( SvxLineDefTabPage, ChangeMetricHdl_Impl, void *, p )
480 {
481 	if( !aCbxSynchronize.IsChecked() && aMtrLength1.GetUnit() != eFUnit )
482 	{
483 		long nTmp1, nTmp2, nTmp3;
484 
485 		// Wurde ueber Control geaendert
486 		if( p )
487 		{
488 			nTmp1 = GetCoreValue( aMtrLength1, ePoolUnit ) * XOUT_WIDTH / 100;
489 			nTmp2 = GetCoreValue( aMtrLength2, ePoolUnit ) * XOUT_WIDTH / 100;
490 			nTmp3 = GetCoreValue( aMtrDistance, ePoolUnit ) * XOUT_WIDTH / 100;
491 		}
492 		else
493 		{
494 			nTmp1 = GetCoreValue( aMtrLength1, ePoolUnit );
495 			nTmp2 = GetCoreValue( aMtrLength2, ePoolUnit );
496 			nTmp3 = GetCoreValue( aMtrDistance, ePoolUnit );
497 		}
498 		aMtrLength1.SetDecimalDigits( 2 );
499 		aMtrLength2.SetDecimalDigits( 2 );
500 		aMtrDistance.SetDecimalDigits( 2 );
501 
502 		// Metrik einstellen
503 		aMtrLength1.SetUnit( eFUnit );
504 		aMtrLength2.SetUnit( eFUnit );
505 		aMtrDistance.SetUnit( eFUnit );
506 
507 		SetMetricValue( aMtrLength1, nTmp1, ePoolUnit );
508 		SetMetricValue( aMtrLength2, nTmp2, ePoolUnit );
509 		SetMetricValue( aMtrDistance, nTmp3, ePoolUnit );
510 	}
511 	else if( aCbxSynchronize.IsChecked() && aMtrLength1.GetUnit() != FUNIT_CUSTOM )
512 	{
513 		long nTmp1, nTmp2, nTmp3;
514 
515 		// Wurde ueber Control geaendert
516 		if( p )
517 		{
518 			nTmp1 = GetCoreValue( aMtrLength1, ePoolUnit ) * 100 / XOUT_WIDTH;
519 			nTmp2 = GetCoreValue( aMtrLength2, ePoolUnit ) * 100 / XOUT_WIDTH;
520 			nTmp3 = GetCoreValue( aMtrDistance, ePoolUnit ) * 100 / XOUT_WIDTH;
521 		}
522 		else
523 		{
524 			nTmp1 = GetCoreValue( aMtrLength1, ePoolUnit );
525 			nTmp2 = GetCoreValue( aMtrLength2, ePoolUnit );
526 			nTmp3 = GetCoreValue( aMtrDistance, ePoolUnit );
527 		}
528 
529 		aMtrLength1.SetDecimalDigits( 0 );
530 		aMtrLength2.SetDecimalDigits( 0 );
531 		aMtrDistance.SetDecimalDigits( 0 );
532 
533 		aMtrLength1.SetUnit( FUNIT_CUSTOM );
534 		aMtrLength2.SetUnit( FUNIT_CUSTOM );
535 		aMtrDistance.SetUnit( FUNIT_CUSTOM );
536 
537 
538 		SetMetricValue( aMtrLength1, nTmp1, ePoolUnit );
539 		SetMetricValue( aMtrLength2, nTmp2, ePoolUnit );
540 		SetMetricValue( aMtrDistance, nTmp3, ePoolUnit );
541 	}
542 	SelectTypeHdl_Impl( NULL );
543 
544 	return( 0L );
545 }
546 
547 //------------------------------------------------------------------------
548 
549 IMPL_LINK( SvxLineDefTabPage, SelectTypeHdl_Impl, void *, p )
550 {
551 	if ( p == &aLbType1 || !p )
552 	{
553 		if ( aLbType1.GetSelectEntryPos() == 0 )
554 		{
555 			aMtrLength1.Disable();
556 			aMtrLength1.SetText( String() );
557 		}
558 		else if ( !aMtrLength1.IsEnabled() )
559 		{
560 			aMtrLength1.Enable();
561 			aMtrLength1.Reformat();
562 		}
563 	}
564 
565 	if ( p == &aLbType2 || !p )
566 	{
567 		if ( aLbType2.GetSelectEntryPos() == 0 )
568 		{
569 			aMtrLength2.Disable();
570 			aMtrLength2.SetText( String() );
571 		}
572 		else if ( !aMtrLength2.IsEnabled() )
573 		{
574 			aMtrLength2.Enable();
575 			aMtrLength2.Reformat();
576 		}
577 	}
578 	ChangePreviewHdl_Impl( p );
579 	return( 0L );
580 }
581 
582 //------------------------------------------------------------------------
583 
584 IMPL_LINK( SvxLineDefTabPage, ClickAddHdl_Impl, void *, EMPTYARG )
585 {
586 	ResMgr& rMgr = CUI_MGR();
587 	String aNewName( SVX_RES( RID_SVXSTR_LINESTYLE ) );
588 	String aDesc( ResId( RID_SVXSTR_DESC_LINESTYLE, rMgr ) );
589 	String aName;
590 	XDashEntry* pEntry;
591 
592 	long nCount = maDashList.get() ? maDashList->Count() : 0;
593 	long j = 1;
594 	sal_Bool bDifferent = sal_False;
595 
596 	while ( !bDifferent )
597 	{
598 		aName = aNewName;
599 		aName += sal_Unicode(' ');
600 		aName += UniString::CreateFromInt32( j++ );
601 		bDifferent = sal_True;
602 
603 		for ( long i = 0; i < nCount && bDifferent; i++ )
604             if ( aName == maDashList->GetDash( i )->GetName() )
605 				bDifferent = sal_False;
606 	}
607 
608 	SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
609 	DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
610 	AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
611 	DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
612 	sal_Bool bLoop = sal_True;
613 
614 	while ( bLoop && pDlg->Execute() == RET_OK )
615 	{
616 		pDlg->GetName( aName );
617 		bDifferent = sal_True;
618 
619 		for( long i = 0; i < nCount && bDifferent; i++ )
620 		{
621             if( aName == maDashList->GetDash( i )->GetName() )
622 				bDifferent = sal_False;
623 		}
624 
625 		if( bDifferent )
626 		{
627 			bLoop = sal_False;
628 			FillDash_Impl();
629 
630 			pEntry = new XDashEntry( aDash, aName );
631 
632             long nDashCount = maDashList.get() ? maDashList->Count() : 0;
633             maDashList->Insert( pEntry, nDashCount );
634             const Bitmap aBitmap = maDashList->GetUiBitmap( nDashCount );
635 			aLbLineStyles.Append( pEntry, &aBitmap );
636 
637 			aLbLineStyles.SelectEntryPos( aLbLineStyles.GetEntryCount() - 1 );
638 
639 			// Flag fuer modifiziert setzen
640 			*pnDashListState |= CT_MODIFIED;
641 
642 			*pPageType = 2;
643 
644 			// Werte sichern fuer Changes-Erkennung ( -> Methode )
645 			aNumFldNumber1.SaveValue();
646 			aMtrLength1.SaveValue();
647 			aLbType1.SaveValue();
648 			aNumFldNumber2.SaveValue();
649 			aMtrLength2.SaveValue();
650 			aLbType2.SaveValue();
651 			aMtrDistance.SaveValue();
652 		}
653 		else
654 		{
655 			WarningBox aBox( DLGWIN, WinBits( WB_OK ),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
656 			aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
657 			aBox.Execute();
658 		}
659 	}
660 	delete( pDlg );
661 
662 	// Status der Buttons ermitteln
663 	if ( maDashList.get() && maDashList->Count() )
664 	{
665 		aBtnModify.Enable();
666 		aBtnDelete.Enable();
667 		aBtnSave.Enable();
668 	}
669 	return( 0L );
670 }
671 
672 //------------------------------------------------------------------------
673 
674 IMPL_LINK( SvxLineDefTabPage, ClickModifyHdl_Impl, void *, EMPTYARG )
675 {
676 	sal_uInt16 nPos = aLbLineStyles.GetSelectEntryPos();
677 
678 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
679 	{
680 		ResMgr& rMgr = CUI_MGR();
681 		String aNewName( SVX_RES( RID_SVXSTR_LINESTYLE ) );
682 		String aDesc( ResId( RID_SVXSTR_DESC_LINESTYLE, rMgr ) );
683         String aName( maDashList->GetDash( nPos )->GetName() );
684 		String aOldName = aName;
685 
686 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
687 		DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
688 		AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
689 		DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
690 
691 		long nCount = maDashList.get() ? maDashList->Count() : 0;
692 		sal_Bool bDifferent = sal_False;
693 		sal_Bool bLoop = sal_True;
694 
695 		while ( bLoop && pDlg->Execute() == RET_OK )
696 		{
697 			pDlg->GetName( aName );
698 			bDifferent = sal_True;
699 
700 			for( long i = 0; i < nCount && bDifferent; i++ )
701 			{
702                 if( aName == maDashList->GetDash( i )->GetName() &&
703 					aName != aOldName )
704 					bDifferent = sal_False;
705 			}
706 
707 			if ( bDifferent )
708 			{
709 				bLoop = sal_False;
710 				FillDash_Impl();
711 
712 				XDashEntry* pEntry = new XDashEntry( aDash, aName );
713 
714 				delete maDashList->Replace( pEntry, nPos );
715 				const Bitmap aBitmap = maDashList->GetUiBitmap( nPos );
716 				aLbLineStyles.Modify( pEntry, nPos, &aBitmap );
717 
718 				aLbLineStyles.SelectEntryPos( nPos );
719 
720 				// Flag fuer modifiziert setzen
721 				*pnDashListState |= CT_MODIFIED;
722 
723 				*pPageType = 2;
724 
725 				// Werte sichern fuer Changes-Erkennung ( -> Methode )
726 				aNumFldNumber1.SaveValue();
727 				aMtrLength1.SaveValue();
728 				aLbType1.SaveValue();
729 				aNumFldNumber2.SaveValue();
730 				aMtrLength2.SaveValue();
731 				aLbType2.SaveValue();
732 				aMtrDistance.SaveValue();
733 			}
734 			else
735 			{
736 				WarningBox aBox( DLGWIN, WinBits( WB_OK ), String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
737 				aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
738 				aBox.Execute();
739 			}
740 		}
741 		delete( pDlg );
742 	}
743 	return( 0L );
744 }
745 
746 //------------------------------------------------------------------------
747 
748 IMPL_LINK( SvxLineDefTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG )
749 {
750 	sal_uInt16 nPos = aLbLineStyles.GetSelectEntryPos();
751 
752 	if ( nPos != LISTBOX_ENTRY_NOTFOUND )
753 	{
754 		QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ),
755 			String( CUI_RES( RID_SVXSTR_ASK_DEL_LINESTYLE ) ) );
756 
757 		if ( aQueryBox.Execute() == RET_YES )
758 		{
759 			delete maDashList->Remove( nPos );
760 			aLbLineStyles.RemoveEntry( nPos );
761 			aLbLineStyles.SelectEntryPos( 0 );
762 
763 			SelectLinestyleHdl_Impl( this );
764 			*pPageType = 0; // Style soll nicht uebernommen werden
765 
766 			// Flag fuer modifiziert setzen
767 			*pnDashListState |= CT_MODIFIED;
768 
769 			ChangePreviewHdl_Impl( this );
770 		}
771 	}
772 
773 	// Status der Buttons ermitteln
774 	if ( !maDashList.get() || !maDashList->Count() )
775 	{
776 		aBtnModify.Disable();
777 		aBtnDelete.Disable();
778 		aBtnSave.Disable();
779 	}
780 	return( 0L );
781 }
782 
783 // -----------------------------------------------------------------------
784 
785 IMPL_LINK( SvxLineDefTabPage, ClickLoadHdl_Impl, void *, EMPTYARG )
786 {
787 	ResMgr& rMgr = CUI_MGR();
788 	sal_uInt16 nReturn = RET_YES;
789 
790 	if ( *pnDashListState & CT_MODIFIED )
791 	{
792 		nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ),
793 			String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
794 
795 		if ( nReturn == RET_YES )
796 			maDashList->Save();
797 	}
798 
799 	if ( nReturn != RET_CANCEL )
800 	{
801     	::sfx2::FileDialogHelper aDlg(
802             com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
803             0 );
804 		String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sod" ) );
805 		aDlg.AddFilter( aStrFilterType, aStrFilterType );
806 		INetURLObject aFile( SvtPathOptions().GetPalettePath() );
807 		aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
808 
809 		if( aDlg.Execute() == ERRCODE_NONE )
810 		{
811 			INetURLObject aURL( aDlg.GetPath() );
812 			INetURLObject aPathURL( aURL );
813 
814 			aPathURL.removeSegment();
815 			aPathURL.removeFinalSlash();
816 
817 			// Liste speichern
818 			XDashListSharedPtr aDshLst(XPropertyListFactory::CreateSharedXDashList(aPathURL.GetMainURL(INetURLObject::NO_DECODE)));
819 			aDshLst->SetName( aURL.getName() );
820 
821 			if( aDshLst->Load() )
822 			{
823 				if( aDshLst.get() )
824 				{
825 					maDashList = aDshLst;
826 					( (SvxLineTabDialog*) DLGWIN )->SetNewDashList( maDashList );
827 
828 					aLbLineStyles.Clear();
829 					aLbLineStyles.Fill( maDashList );
830 					Reset( rOutAttrs );
831 
832 					maDashList->SetName( aURL.getName() );
833 
834 /*					// Ermitteln (evtl. abschneiden) des Namens und in
835 					// der GroupBox darstellen
836 					String aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
837 					aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
838 
839 					if ( aURL.getBase().Len() > 18 )
840 					{
841 						aString += aURL.getBase().Copy( 0, 15 );
842 						aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
843 					}
844 					else
845 						aString += aURL.getBase();
846 
847 					aGrpLinestyles.SetText( aString );
848 */
849 					// Flag fuer gewechselt setzen
850 					*pnDashListState |= CT_CHANGED;
851 					// Flag fuer modifiziert entfernen
852 					*pnDashListState &= ~CT_MODIFIED;
853 				}
854 			}
855 			else
856 				//aIStream.Close();
857 				ErrorBox( DLGWIN, WinBits( WB_OK ),
858 					String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
859 		}
860 	}
861 
862 	// Status der Buttons ermitteln
863 	if ( maDashList.get() && maDashList->Count() )
864 	{
865 		aBtnModify.Enable();
866 		aBtnDelete.Enable();
867 		aBtnSave.Enable();
868 	}
869 	else
870 	{
871 		aBtnModify.Disable();
872 		aBtnDelete.Disable();
873 		aBtnSave.Disable();
874 	}
875 	return( 0L );
876 }
877 
878 // -----------------------------------------------------------------------
879 
880 IMPL_LINK( SvxLineDefTabPage, ClickSaveHdl_Impl, void *, EMPTYARG )
881 {
882    	::sfx2::FileDialogHelper aDlg(
883         com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
884 	String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sod" ) );
885 	aDlg.AddFilter( aStrFilterType, aStrFilterType );
886 
887 	INetURLObject aFile( SvtPathOptions().GetPalettePath() );
888 	DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
889 
890 	if( maDashList->GetName().Len() )
891 	{
892 		aFile.Append( maDashList->GetName() );
893 
894 		if( !aFile.getExtension().getLength() )
895 			aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "sod" ) ) );
896 	}
897 
898 	aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
899 	if ( aDlg.Execute() == ERRCODE_NONE )
900 	{
901 		INetURLObject aURL( aDlg.GetPath() );
902 		INetURLObject aPathURL( aURL );
903 
904 		aPathURL.removeSegment();
905 		aPathURL.removeFinalSlash();
906 
907 		maDashList->SetName( aURL.getName() );
908 		maDashList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
909 
910 		if( maDashList->Save() )
911 		{
912 /*			// Ermitteln (evtl. abschneiden) des Namens und in
913 			// der GroupBox darstellen
914 			String aString( CUI_RES( RID_SVXSTR_TABLE ) );
915 			aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
916 
917 			if ( aURL.getBase().Len() > 18 )
918 			{
919 				aString += aURL.getBase().Copy( 0, 15 );
920 				aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
921 			}
922 			else
923 				aString += aURL.getBase();
924 
925 			aGrpLinestyles.SetText( aString );
926 */
927 			// Flag fuer gespeichert setzen
928 			*pnDashListState |= CT_SAVED;
929 			// Flag fuer modifiziert entfernen
930 			*pnDashListState &= ~CT_MODIFIED;
931 		}
932 		else
933 		{
934 			ErrorBox( DLGWIN, WinBits( WB_OK ),
935 				String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
936 		}
937 	}
938 
939 	return( 0L );
940 }
941 
942 //------------------------------------------------------------------------
943 
944 void SvxLineDefTabPage::FillDash_Impl()
945 {
946 	XDashStyle eXDS;
947 
948 /*	Alle Stile werden z.Z. nicht benutzt
949 	if( aRbtEnds1.IsChecked() )
950 		eXDS = XDASH_ROUND;
951 	else if( aRbtEnds2.IsChecked() )
952 		eXDS = XDASH_RECT;
953 	else
954 		eXDS = XDASH_RECT;
955 */
956 	if( aCbxSynchronize.IsChecked() )
957 		eXDS = XDASH_RECTRELATIVE;
958 	else
959 		eXDS = XDASH_RECT;
960 
961 	aDash.SetDashStyle( eXDS );
962 	aDash.SetDots( (sal_uInt8) aNumFldNumber1.GetValue() );
963 	aDash.SetDotLen( aLbType1.GetSelectEntryPos() == 0 ? 0 :
964 								GetCoreValue( aMtrLength1, ePoolUnit ) );
965 	aDash.SetDashes( (sal_uInt8) aNumFldNumber2.GetValue() );
966 	aDash.SetDashLen( aLbType2.GetSelectEntryPos() == 0 ? 0 :
967 								GetCoreValue( aMtrLength2, ePoolUnit ) );
968 	aDash.SetDistance( GetCoreValue( aMtrDistance, ePoolUnit ) );
969 
970 	rXLSet.Put( XLineDashItem( String(), aDash ) );
971 
972 	// #i34740#
973 	aCtlPreview.SetLineAttributes(aXLineAttr.GetItemSet());
974 }
975 
976 //------------------------------------------------------------------------
977 
978 void SvxLineDefTabPage::FillDialog_Impl()
979 {
980 	XDashStyle eXDS = aDash.GetDashStyle(); // XDASH_RECT, XDASH_ROUND
981 	if( eXDS == XDASH_RECTRELATIVE )
982 		aCbxSynchronize.Check();
983 	else
984 		aCbxSynchronize.Check( sal_False );
985 
986 	aNumFldNumber1.SetValue( aDash.GetDots() );
987 	//aMtrLength1.SetValue( aDash.GetDotLen() );
988 	SetMetricValue( aMtrLength1, aDash.GetDotLen(), ePoolUnit );
989 	aLbType1.SelectEntryPos( aDash.GetDotLen() == 0 ? 0 : 1 );
990 	aNumFldNumber2.SetValue( aDash.GetDashes() );
991 	//aMtrLength2.SetValue( aDash.GetDashLen() );
992 	SetMetricValue( aMtrLength2, aDash.GetDashLen(), ePoolUnit );
993 	aLbType2.SelectEntryPos( aDash.GetDashLen() == 0 ? 0 : 1 );
994 	//aMtrDistance.SetValue( aDash.GetDistance() );
995 	SetMetricValue( aMtrDistance, aDash.GetDistance(), ePoolUnit );
996 
997 	ChangeMetricHdl_Impl( NULL );
998 
999 	// Werte sichern fuer Changes-Erkennung ( -> Methode )
1000 	aNumFldNumber1.SaveValue();
1001 	aMtrLength1.SaveValue();
1002 	aLbType1.SaveValue();
1003 	aNumFldNumber2.SaveValue();
1004 	aMtrLength2.SaveValue();
1005 	aLbType2.SaveValue();
1006 	aMtrDistance.SaveValue();
1007 }
1008 
1009 
1010 void SvxLineDefTabPage::DataChanged( const DataChangedEvent& rDCEvt )
1011 {
1012 	SfxTabPage::DataChanged( rDCEvt );
1013 
1014 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1015 	{
1016 		sal_uInt16 nOldSelect = aLbLineStyles.GetSelectEntryPos();
1017 		aLbLineStyles.Clear();
1018 		aLbLineStyles.Fill( maDashList );
1019 		aLbLineStyles.SelectEntryPos( nOldSelect );
1020 	}
1021 }
1022 
1023