xref: /trunk/main/cui/source/tabpages/tplneend.cxx (revision aa64976b)
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/filedlghelper.hxx>
34 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
35 
36 #define _SVX_TPLNEEND_CXX
37 
38 #include <cuires.hrc>
39 #include "tabline.hrc"
40 #include "helpid.hrc"
41 #include <svx/dialmgr.hxx>
42 #include <svx/svdobj.hxx>
43 #include <svx/svdopath.hxx>
44 #include "svx/drawitem.hxx"
45 #include <svx/xpool.hxx>
46 #include <svx/xtable.hxx>
47 #include "cuitabline.hxx"
48 #include <svx/svxdlg.hxx> //CHINA001
49 #include <dialmgr.hxx>
50 #include "svx/dlgutil.hxx"
51 #include <basegfx/range/b2drange.hxx>
52 #include <basegfx/polygon/b2dpolygontools.hxx>
53 #include <basegfx/matrix/b2dhommatrix.hxx>
54 #include <basegfx/polygon/b2dpolygon.hxx>
55 #include <basegfx/polygon/b2dpolypolygontools.hxx>
56 #include <basegfx/matrix/b2dhommatrixtools.hxx>
57 #include <svx/dialogs.hrc>
58 
59 #define DLGWIN this->GetParent()->GetParent()
60 
61 #define BITMAP_WIDTH   32
62 #define BITMAP_HEIGHT  12
63 #define XOUT_WIDTH    150
64 
65 /*************************************************************************
66 |*
67 |*	Dialog zum Definieren von Linienenden-Stilen
68 |*
69 \************************************************************************/
70 
SvxLineEndDefTabPage(Window * pParent,const SfxItemSet & rInAttrs)71 SvxLineEndDefTabPage::SvxLineEndDefTabPage
72 (
73 	Window* pParent,
74 	const SfxItemSet& rInAttrs
75 ) :
76 
77 	SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_LINEEND_DEF ), rInAttrs ),
78 
79     aFlTip              ( this, CUI_RES( FL_TIP ) ),
80     aFTTitle            ( this, CUI_RES( FT_TITLE ) ),
81     aEdtName            ( this, CUI_RES( EDT_NAME ) ),
82     aFTLineEndStyle     ( this, CUI_RES( FT_LINE_END_STYLE ) ),
83     aLbLineEnds         ( this, CUI_RES( LB_LINEENDS ) ),
84     aBtnAdd             ( this, CUI_RES( BTN_ADD ) ),
85     aBtnModify          ( this, CUI_RES( BTN_MODIFY ) ),
86     aBtnDelete          ( this, CUI_RES( BTN_DELETE ) ),
87     aBtnLoad            ( this, CUI_RES( BTN_LOAD ) ),
88 	aBtnSave 		    ( this, CUI_RES( BTN_SAVE ) ),
89     aFiTip              ( this, CUI_RES( FI_TIP ) ),
90     aCtlPreview         ( this, CUI_RES( CTL_PREVIEW ) ),
91 
92     rOutAttrs           ( rInAttrs ),
93     pPolyObj( NULL ),
94 
95     pXPool              ( (XOutdevItemPool*) rInAttrs.GetPool() ),
96     aXLStyle            ( XLINE_SOLID ),
97     aXWidth             ( XOUT_WIDTH ),
98     aXColor             ( String(), COL_BLACK ),
99     aXLineAttr          ( pXPool ),
100     rXLSet              ( aXLineAttr.GetItemSet() ),
101     maLineEndList()
102 {
103 	aBtnLoad.SetModeImage( Image( CUI_RES( RID_SVXIMG_LOAD_H ) ), BMP_COLOR_HIGHCONTRAST );
104 	aBtnSave.SetModeImage( Image( CUI_RES( RID_SVXIMG_SAVE_H ) ), BMP_COLOR_HIGHCONTRAST );
105 
106 	FreeResource();
107 
108 	// diese Page braucht ExchangeSupport
109 	SetExchangeSupport();
110 
111 	rXLSet.Put( aXLStyle );
112 	rXLSet.Put( aXWidth );
113 	rXLSet.Put( aXColor );
114 	rXLSet.Put( XLineStartWidthItem( aCtlPreview.GetOutputSize().Height()  / 2 ) );
115 	rXLSet.Put( XLineEndWidthItem( aCtlPreview.GetOutputSize().Height() / 2 ) );
116 
117 	// #i34740#
118 	aCtlPreview.SetLineAttributes(aXLineAttr.GetItemSet());
119 
120 	aBtnAdd.SetClickHdl(
121 		LINK( this, SvxLineEndDefTabPage, ClickAddHdl_Impl ) );
122 	aBtnModify.SetClickHdl(
123 		LINK( this, SvxLineEndDefTabPage, ClickModifyHdl_Impl ) );
124 	aBtnDelete.SetClickHdl(
125 		LINK( this, SvxLineEndDefTabPage, ClickDeleteHdl_Impl ) );
126 	aBtnLoad.SetClickHdl(
127 		LINK( this, SvxLineEndDefTabPage, ClickLoadHdl_Impl ) );
128 	aBtnSave.SetClickHdl(
129 		LINK( this, SvxLineEndDefTabPage, ClickSaveHdl_Impl ) );
130 
131 	aLbLineEnds.SetSelectHdl(
132 		LINK( this, SvxLineEndDefTabPage, SelectLineEndHdl_Impl ) );
133 
134 	aBtnAdd.SetAccessibleRelationMemberOf(&aFlTip);
135 	aBtnModify.SetAccessibleRelationMemberOf(&aFlTip);
136 	aBtnDelete.SetAccessibleRelationMemberOf(&aFlTip);
137 }
138 
139 //------------------------------------------------------------------------
140 
~SvxLineEndDefTabPage()141 SvxLineEndDefTabPage::~SvxLineEndDefTabPage()
142 {
143 }
144 
145 // -----------------------------------------------------------------------
146 
Construct()147 void SvxLineEndDefTabPage::Construct()
148 {
149 	aLbLineEnds.Fill( maLineEndList );
150 
151 	bool bCreateArrowPossible = true;
152 
153 	if( !pPolyObj )
154 	{
155 		bCreateArrowPossible = false;
156 	}
157 	else if( !pPolyObj->ISA( SdrPathObj ) )
158 	{
159 		SdrObjTransformInfoRec aInfoRec;
160 		pPolyObj->TakeObjInfo( aInfoRec );
161 		SdrObject* pNewObj = 0;
162 		if( aInfoRec.bCanConvToPath )
163 			pNewObj = pPolyObj->ConvertToPolyObj( sal_True, sal_False );
164 
165 		bCreateArrowPossible = pNewObj && pNewObj->ISA( SdrPathObj );
166         SdrObject::Free( pNewObj );
167 	}
168 
169 	if( !bCreateArrowPossible )
170 		aBtnAdd.Disable();
171 }
172 
173 // -----------------------------------------------------------------------
174 
ActivatePage(const SfxItemSet &)175 void SvxLineEndDefTabPage::ActivatePage( const SfxItemSet& )
176 {
177 	if( *pDlgType == 0 ) // Flaechen-Dialog
178 	{
179 		// ActivatePage() wird aufgerufen bevor der Dialog PageCreated() erhaelt !!!
180 		if( maLineEndList.get() )
181 		{
182             if( *pPosLineEndLb != LISTBOX_ENTRY_NOTFOUND )
183 			{
184 				aLbLineEnds.SelectEntryPos( *pPosLineEndLb );
185 				SelectLineEndHdl_Impl( this );
186 			}
187 			INetURLObject	aURL( maLineEndList->GetPath() );
188 
189 			aURL.Append( maLineEndList->GetName() );
190 			DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
191 /*			// Ermitteln (evtl. abschneiden) des Namens und in
192 			// der GroupBox darstellen
193 			String			aString( CUI_RES( RID_SVXSTR_TABLE ) ); aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
194 
195 			if ( aURL.getBase().Len() > 18 )
196 			{
197 				aString += aURL.getBase().Copy( 0, 15 );
198 				aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
199 			}
200 			else
201 				aString += aURL.getBase();
202 
203 			aGrpLineEnds.SetText( aString );
204 */
205 			*pPageType = 0; // 3
206 			*pPosLineEndLb = LISTBOX_ENTRY_NOTFOUND;
207 		}
208 	}
209 }
210 
211 // -----------------------------------------------------------------------
212 
DeactivatePage(SfxItemSet * _pSet)213 int SvxLineEndDefTabPage::DeactivatePage( SfxItemSet* _pSet )
214 {
215 	CheckChanges_Impl();
216 
217     if( _pSet )
218         FillItemSet( *_pSet );
219 
220 	return( LEAVE_PAGE );
221 }
222 
223 // -----------------------------------------------------------------------
224 
CheckChanges_Impl()225 void SvxLineEndDefTabPage::CheckChanges_Impl()
226 {
227 	sal_uInt16 nPos = aLbLineEnds.GetSelectEntryPos();
228 
229 	if ( nPos != LISTBOX_ENTRY_NOTFOUND )
230 	{
231 		String aString = aEdtName.GetText();
232 
233 		if( aString != aLbLineEnds.GetSelectEntry() )
234 		{
235 			QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ),
236 				CUI_RESSTR( RID_SVXSTR_ASK_CHANGE_LINEEND ) );
237 
238 			if ( aQueryBox.Execute() == RET_YES )
239 				ClickModifyHdl_Impl( this );
240 		}
241 	}
242 	nPos = aLbLineEnds.GetSelectEntryPos();
243 
244 	if ( nPos != LISTBOX_ENTRY_NOTFOUND )
245 		*pPosLineEndLb = nPos;
246 }
247 
248 // -----------------------------------------------------------------------
249 
FillItemSet(SfxItemSet & rSet)250 sal_Bool SvxLineEndDefTabPage::FillItemSet( SfxItemSet& rSet )
251 {
252 	if( *pDlgType == 0 ) // Linien-Dialog
253 	{
254 		if( *pPageType == 3 )
255 		{
256 			CheckChanges_Impl();
257 
258 			long nPos = aLbLineEnds.GetSelectEntryPos();
259             XLineEndEntry* pEntry = maLineEndList->GetLineEnd( nPos );
260 
261             rSet.Put( XLineStartItem( pEntry->GetName(), pEntry->GetLineEnd() ) );
262             rSet.Put( XLineEndItem( pEntry->GetName(), pEntry->GetLineEnd() ) );
263 		}
264 	}
265 	return( sal_True );
266 }
267 
268 // -----------------------------------------------------------------------
269 
Reset(const SfxItemSet &)270 void SvxLineEndDefTabPage::Reset( const SfxItemSet& )
271 {
272 	aLbLineEnds.SelectEntryPos( 0 );
273 
274 	// Update lineend
275 	if( maLineEndList.get() && maLineEndList->Count() > 0 )
276 	{
277 		int nPos = aLbLineEnds.GetSelectEntryPos();
278 
279         XLineEndEntry* pEntry = maLineEndList->GetLineEnd( nPos );
280 
281 		aEdtName.SetText( aLbLineEnds.GetSelectEntry() );
282 
283 		rXLSet.Put( XLineStartItem( String(), pEntry->GetLineEnd() ) );
284 		rXLSet.Put( XLineEndItem( String(), pEntry->GetLineEnd() ) );
285 
286 		// #i34740#
287 		aCtlPreview.SetLineAttributes(aXLineAttr.GetItemSet());
288 
289 		aCtlPreview.Invalidate();
290 	}
291 
292 	// Status der Buttons ermitteln
293 	if( maLineEndList.get() && maLineEndList->Count() )
294 	{
295 		aBtnModify.Enable();
296 		aBtnDelete.Enable();
297 		aBtnSave.Enable();
298 	}
299 	else
300 	{
301 		aBtnModify.Disable();
302 		aBtnDelete.Disable();
303 		aBtnSave.Disable();
304 	}
305 }
306 
307 // -----------------------------------------------------------------------
308 
Create(Window * pWindow,const SfxItemSet & rSet)309 SfxTabPage* SvxLineEndDefTabPage::Create( Window* pWindow,
310                 const SfxItemSet& rSet )
311 {
312     return( new SvxLineEndDefTabPage( pWindow, rSet ) );
313 }
314 
315 //------------------------------------------------------------------------
316 
IMPL_LINK(SvxLineEndDefTabPage,SelectLineEndHdl_Impl,void *,EMPTYARG)317 IMPL_LINK( SvxLineEndDefTabPage, SelectLineEndHdl_Impl, void *, EMPTYARG )
318 {
319 	if( maLineEndList.get() && maLineEndList->Count() > 0 )
320 	{
321 		int nPos = aLbLineEnds.GetSelectEntryPos();
322 
323         XLineEndEntry* pEntry = maLineEndList->GetLineEnd( nPos );
324 
325 		aEdtName.SetText( aLbLineEnds.GetSelectEntry() );
326 
327 		rXLSet.Put( XLineStartItem( String(), pEntry->GetLineEnd() ) );
328 		rXLSet.Put( XLineEndItem( String(), pEntry->GetLineEnd() ) );
329 
330 		// #i34740#
331 		aCtlPreview.SetLineAttributes(aXLineAttr.GetItemSet());
332 
333 		aCtlPreview.Invalidate();
334 
335 		// Wird erst hier gesetzt, um den Style nur dann zu uebernehmen,
336 		// wenn in der ListBox ein Eintrag ausgewaehlt wurde
337 		*pPageType = 3;
338 	}
339 	return( 0L );
340 }
341 
342 //------------------------------------------------------------------------
343 
ChangePreviewHdl_Impl(void *)344 long SvxLineEndDefTabPage::ChangePreviewHdl_Impl( void* )
345 {
346 	aCtlPreview.Invalidate();
347 	return( 0L );
348 }
349 
350 //------------------------------------------------------------------------
351 
IMPL_LINK(SvxLineEndDefTabPage,ClickModifyHdl_Impl,void *,EMPTYARG)352 IMPL_LINK( SvxLineEndDefTabPage, ClickModifyHdl_Impl, void *, EMPTYARG )
353 {
354 	sal_uInt16 nPos = aLbLineEnds.GetSelectEntryPos();
355 
356 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
357 	{
358 		ResMgr& rMgr = CUI_MGR();
359 		String aDesc( ResId( RID_SVXSTR_DESC_LINEEND, rMgr ) );
360 		String aName( aEdtName.GetText() );
361 		long nCount = maLineEndList.get() ? maLineEndList->Count() : 0;
362 		sal_Bool bDifferent = sal_True;
363 
364 		// Pruefen, ob Name schon vorhanden ist
365 		for ( long i = 0; i < nCount && bDifferent; i++ )
366             if ( aName == maLineEndList->GetLineEnd( i )->GetName() )
367 				bDifferent = sal_False;
368 
369 		// Wenn ja, wird wiederholt ein neuer Name angefordert
370 		if ( !bDifferent )
371 		{
372 			WarningBox aWarningBox( DLGWIN, WinBits( WB_OK ),
373 				String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
374 			aWarningBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
375 			aWarningBox.Execute();
376 
377 			SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
378 			DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
379 			AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
380 			DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
381 			sal_Bool bLoop = sal_True;
382 
383 			while( !bDifferent && bLoop && pDlg->Execute() == RET_OK )
384 			{
385 				pDlg->GetName( aName );
386 				bDifferent = sal_True;
387 
388 				for( long i = 0; i < nCount && bDifferent; i++ )
389 				{
390                     if( aName == maLineEndList->GetLineEnd( i )->GetName() )
391 						bDifferent = sal_False;
392 				}
393 
394 				if( bDifferent )
395 					bLoop = sal_False;
396 				else
397 					aWarningBox.Execute();
398 			}
399 			delete( pDlg );
400 		}
401 
402         // Wenn nicht vorhanden, wird Eintrag aufgenommen
403         if( bDifferent )
404         {
405             const XLineEndEntry* pOldEntry = maLineEndList->GetLineEnd( nPos );
406 
407             if(pOldEntry)
408             {
409                 // #123497# Need to replace the existing entry with a new one (old returned needs to be deleted)
410                 XLineEndEntry* pEntry = new XLineEndEntry(pOldEntry->GetLineEnd(), aName);
411                 delete maLineEndList->Replace(pEntry, nPos);
412 
413                 aEdtName.SetText( aName );
414 
415                 aLbLineEnds.Modify( *pEntry, nPos, maLineEndList->GetUiBitmap( nPos ) );
416                 aLbLineEnds.SelectEntryPos( nPos );
417 
418                 // Flag fuer modifiziert setzen
419                 *pnLineEndListState |= CT_MODIFIED;
420 
421                 *pPageType = 3;
422             }
423             else
424             {
425                 OSL_ENSURE(false, "LineEnd to be modified not existing (!)");
426             }
427         }
428     }
429     return( 0L );
430 }
431 
432 //------------------------------------------------------------------------
433 
IMPL_LINK(SvxLineEndDefTabPage,ClickAddHdl_Impl,void *,EMPTYARG)434 IMPL_LINK( SvxLineEndDefTabPage, ClickAddHdl_Impl, void *, EMPTYARG )
435 {
436 	if( pPolyObj )
437 	{
438 		const SdrObject* pNewObj;
439 		SdrObject* pConvPolyObj = NULL;
440 
441 		if( pPolyObj->ISA( SdrPathObj ) )
442 		{
443 			pNewObj = pPolyObj;
444 		}
445 		else
446 		{
447 			SdrObjTransformInfoRec aInfoRec;
448 			pPolyObj->TakeObjInfo( aInfoRec );
449 
450 			if( aInfoRec.bCanConvToPath )
451 			{
452 				pNewObj = pConvPolyObj = pPolyObj->ConvertToPolyObj( sal_True, sal_False );
453 
454 				if( !pNewObj || !pNewObj->ISA( SdrPathObj ) )
455 					return( 0L ); // Abbruch, zusaetzliche Sicherheit, die bei
456 							// Gruppenobjekten aber nichts bringt.
457 			}
458 			else return( 0L ); // Abbruch
459 		}
460 
461 		basegfx::B2DPolyPolygon aNewPolyPolygon(((SdrPathObj*)pNewObj)->GetPathPoly());
462 		basegfx::B2DRange aNewRange(basegfx::tools::getRange(aNewPolyPolygon));
463 
464 		// Normalisieren
465         aNewPolyPolygon.transform(basegfx::tools::createTranslateB2DHomMatrix(
466             -aNewRange.getMinX(), -aNewRange.getMinY()));
467 
468 		// Loeschen des angelegten PolyObjektes
469         SdrObject::Free( pConvPolyObj );
470 
471 		XLineEndEntry* pEntry;
472 
473 		ResMgr& rMgr = CUI_MGR();
474 		String aNewName( SVX_RES( RID_SVXSTR_LINEEND ) );
475 		String aDesc( ResId( RID_SVXSTR_DESC_LINEEND, rMgr ) );
476 		String aName;
477 
478 		long nCount = maLineEndList.get() ? maLineEndList->Count() : 0;
479 		long j = 1;
480 		sal_Bool bDifferent = sal_False;
481 
482 		while ( !bDifferent )
483 		{
484 			aName = aNewName;
485 			aName += sal_Unicode(' ');
486 			aName += UniString::CreateFromInt32( j++ );
487 			bDifferent = sal_True;
488 
489 			for( long i = 0; i < nCount && bDifferent; i++ )
490                 if ( aName == maLineEndList->GetLineEnd( i )->GetName() )
491 					bDifferent = sal_False;
492 		}
493 
494 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
495 		DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
496 		AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
497 		DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
498 		sal_Bool bLoop = sal_True;
499 
500 		while ( bLoop && pDlg->Execute() == RET_OK )
501 		{
502 			pDlg->GetName( aName );
503 			bDifferent = sal_True;
504 
505 			for( long i = 0; i < nCount && bDifferent; i++ )
506 			{
507                 if( aName == maLineEndList->GetLineEnd( i )->GetName() )
508 					bDifferent = sal_False;
509 			}
510 
511 			if( bDifferent )
512 			{
513 				bLoop = sal_False;
514 				pEntry = new XLineEndEntry( aNewPolyPolygon, aName );
515 
516                 long nLineEndCount = maLineEndList.get() ? maLineEndList->Count() : 0;
517                 maLineEndList->Insert( pEntry, nLineEndCount );
518 
519 				// Zur ListBox hinzufuegen
520 				aLbLineEnds.Append( *pEntry, maLineEndList->GetUiBitmap( nLineEndCount ) );
521 				aLbLineEnds.SelectEntryPos( aLbLineEnds.GetEntryCount() - 1 );
522 
523 				// Flag fuer modifiziert setzen
524 				*pnLineEndListState |= CT_MODIFIED;
525 
526 				SelectLineEndHdl_Impl( this );
527 			}
528 			else
529 			{
530 				WarningBox aBox( DLGWIN, WinBits( WB_OK ),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
531 				aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
532 				aBox.Execute();
533 			}
534 		}
535 		delete pDlg;
536 	}
537 	else
538 		aBtnAdd.Disable();
539 
540 	// Status der Buttons ermitteln
541 	if ( maLineEndList.get() && maLineEndList->Count() )
542 	{
543 		aBtnModify.Enable();
544 		aBtnDelete.Enable();
545 		aBtnSave.Enable();
546 	}
547 	return( 0L );
548 }
549 
550 //------------------------------------------------------------------------
551 
IMPL_LINK(SvxLineEndDefTabPage,ClickDeleteHdl_Impl,void *,EMPTYARG)552 IMPL_LINK( SvxLineEndDefTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG )
553 {
554 	sal_uInt16 nPos = aLbLineEnds.GetSelectEntryPos();
555 
556 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
557 	{
558 		QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ),
559 			String( CUI_RES( RID_SVXSTR_ASK_DEL_LINEEND ) ) );
560 
561 		if ( aQueryBox.Execute() == RET_YES )
562 		{
563 			delete maLineEndList->Remove( nPos );
564 			aLbLineEnds.RemoveEntry( nPos );
565 			aLbLineEnds.SelectEntryPos( 0 );
566 
567 			SelectLineEndHdl_Impl( this );
568 			*pPageType = 0; // LineEnd soll nicht uebernommen werden
569 
570 			// Flag fuer modifiziert setzen
571 			*pnLineEndListState |= CT_MODIFIED;
572 
573 			ChangePreviewHdl_Impl( this );
574 		}
575 	}
576 	// Status der Buttons ermitteln
577 	if( !maLineEndList.get() || !maLineEndList->Count() )
578 	{
579 		aBtnModify.Disable();
580 		aBtnDelete.Disable();
581 		aBtnSave.Disable();
582 	}
583 	return( 0L );
584 }
585 
586 //------------------------------------------------------------------------
587 
IMPL_LINK(SvxLineEndDefTabPage,ClickLoadHdl_Impl,void *,EMPTYARG)588 IMPL_LINK( SvxLineEndDefTabPage, ClickLoadHdl_Impl, void *, EMPTYARG )
589 {
590 	ResMgr& rMgr = CUI_MGR();
591 	sal_uInt16 nReturn = RET_YES;
592 
593 	if ( *pnLineEndListState & CT_MODIFIED )
594 	{
595 		nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ),
596 			String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
597 
598 		if ( nReturn == RET_YES )
599 			maLineEndList->Save();
600 	}
601 
602 	if ( nReturn != RET_CANCEL )
603 	{
604     	::sfx2::FileDialogHelper aDlg(
605             com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
606             0 );
607 		String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soe" ) );
608 		aDlg.AddFilter( aStrFilterType, aStrFilterType );
609 		INetURLObject aFile( SvtPathOptions().GetPalettePath() );
610 		aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
611 
612 		if( aDlg.Execute() == ERRCODE_NONE )
613 		{
614 			INetURLObject aURL( aDlg.GetPath() );
615 			INetURLObject aPathURL( aURL );
616 
617 			aPathURL.removeSegment();
618 			aPathURL.removeFinalSlash();
619 
620 			// Liste speichern
621 			XLineEndListSharedPtr aLeList(XPropertyListFactory::CreateSharedXLineEndList(aPathURL.GetMainURL(INetURLObject::NO_DECODE)));
622 			aLeList->SetName( aURL.getName() );
623 			if( aLeList->Load() )
624 			{
625 				if( aLeList.get() )
626 				{
627 					maLineEndList = aLeList;
628 					( (SvxLineTabDialog*) DLGWIN )->SetNewLineEndList( maLineEndList );
629 					aLbLineEnds.Clear();
630 					aLbLineEnds.Fill( maLineEndList );
631 					Reset( rOutAttrs );
632 
633 					maLineEndList->SetName( aURL.getName() );
634 
635 /*					// Ermitteln (evtl. abschneiden) des Namens und in
636 					// der GroupBox darstellen
637 					String aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
638 					aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
639 					if( aURL.getBase().Len() > 18 )
640 					{
641 						aString += aURL.getBase().Copy( 0, 15 );
642 						aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
643 					}
644 					else
645 						aString += aURL.getBase();
646 
647 					aGrpLineEnds.SetText( aString );
648 */
649 					// Flag fuer gewechselt setzen
650 					*pnLineEndListState |= CT_CHANGED;
651 					// Flag fuer modifiziert entfernen
652 					*pnLineEndListState &= ~CT_MODIFIED;
653 				}
654 			}
655 			else
656 				ErrorBox( DLGWIN, WinBits( WB_OK ),
657 					String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
658 		}
659 	}
660 
661 	// Status der Buttons ermitteln
662 	if ( maLineEndList.get() && maLineEndList->Count() )
663 	{
664 		aBtnModify.Enable();
665 		aBtnDelete.Enable();
666 		aBtnSave.Enable();
667 	}
668 	else
669 	{
670 		aBtnModify.Disable();
671 		aBtnDelete.Disable();
672 		aBtnSave.Disable();
673 	}
674 	return( 0L );
675 }
676 
677 //------------------------------------------------------------------------
678 
IMPL_LINK(SvxLineEndDefTabPage,ClickSaveHdl_Impl,void *,EMPTYARG)679 IMPL_LINK( SvxLineEndDefTabPage, ClickSaveHdl_Impl, void *, EMPTYARG )
680 {
681    	::sfx2::FileDialogHelper aDlg(
682         com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
683 	String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soe" ) );
684 	aDlg.AddFilter( aStrFilterType, aStrFilterType );
685 
686 	INetURLObject aFile( SvtPathOptions().GetPalettePath() );
687 	DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
688 
689 	if( maLineEndList.get() && maLineEndList->GetName().Len() )
690 	{
691 		aFile.Append( maLineEndList->GetName() );
692 
693 		if( !aFile.getExtension().getLength() )
694 			aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "soe" ) ) );
695 	}
696 
697 	aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
698 	if ( aDlg.Execute() == ERRCODE_NONE )
699 	{
700 		INetURLObject	aURL( aDlg.GetPath() );
701 		INetURLObject	aPathURL( aURL );
702 
703 		aPathURL.removeSegment();
704 		aPathURL.removeFinalSlash();
705 
706 		maLineEndList->SetName( aURL.getName() );
707 		maLineEndList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
708 
709 		if( maLineEndList->Save() )
710 		{
711 /*			// Ermitteln (evtl. abschneiden) des Namens und in
712 			// der GroupBox darstellen
713 			String aString( CUI_RES( RID_SVXSTR_TABLE ) );
714 			aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
715 
716 			if ( aURL.getBase().Len() > 18 )
717 			{
718 				aString += aURL.getBase().Copy( 0, 15 );
719 				aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
720 			}
721 			else
722 				aString += aURL.getBase();
723 			aGrpLineEnds.SetText( aString );
724 */
725 			// Flag fuer gespeichert setzen
726 			*pnLineEndListState |= CT_SAVED;
727 			// Flag fuer modifiziert entfernen
728 			*pnLineEndListState &= ~CT_MODIFIED;
729 		}
730 		else
731 		{
732 			ErrorBox( DLGWIN, WinBits( WB_OK ),
733 				String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
734 		}
735 	}
736 	return( 0L );
737 }
738 
DataChanged(const DataChangedEvent & rDCEvt)739 void SvxLineEndDefTabPage::DataChanged( const DataChangedEvent& rDCEvt )
740 {
741 	SfxTabPage::DataChanged( rDCEvt );
742 
743 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
744 	{
745 		sal_uInt16 nOldSelect = aLbLineEnds.GetSelectEntryPos();
746 		aLbLineEnds.Clear();
747 		aLbLineEnds.Fill( maLineEndList );
748 		aLbLineEnds.SelectEntryPos( nOldSelect );
749 	}
750 }
751 
752