Updated core
[LibreOffice.git] / cui / source / tabpages / tphatch.cxx
blobe73b8e0367e0a79450e9510edbaa268c56c3b8c5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
29 #include <cuires.hrc>
30 #include "tabarea.hrc"
31 #include "helpid.hrc"
32 #include "svx/xattr.hxx"
33 #include <svx/xpool.hxx>
34 #include <svx/xtable.hxx>
35 #include "svx/drawitem.hxx"
36 #include "cuitabarea.hxx"
37 #include "defdlgname.hxx"
38 #include "dlgname.hxx"
39 #include <svx/svxdlg.hxx>
40 #include <dialmgr.hxx>
41 #include "svx/dlgutil.hxx"
42 #include <svx/dialmgr.hxx>
43 #include "paragrph.hrc"
44 #include <svx/dialogs.hrc>
46 SvxHatchTabPage::SvxHatchTabPage
48 Window* pParent,
49 const SfxItemSet& rInAttrs
50 ) :
52 SvxTabPage ( pParent, CUI_RES( RID_SVXPAGE_HATCH ), rInAttrs ),
54 aFtDistance ( this, CUI_RES( FT_LINE_DISTANCE ) ),
55 aMtrDistance ( this, CUI_RES( MTR_FLD_DISTANCE ) ),
56 aFtAngle ( this, CUI_RES( FT_LINE_ANGLE ) ),
57 aMtrAngle ( this, CUI_RES( MTR_FLD_ANGLE ) ),
58 aCtlAngle ( this, CUI_RES( CTL_ANGLE ),
59 RP_RB, 200, 80, CS_ANGLE ),
60 aFlProp ( this, CUI_RES( FL_PROP ) ),
61 aFtLineType ( this, CUI_RES( FT_LINE_TYPE ) ),
62 aLbLineType ( this, CUI_RES( LB_LINE_TYPE ) ),
63 aFtLineColor ( this, CUI_RES( FT_LINE_COLOR ) ),
64 aLbLineColor ( this, CUI_RES( LB_LINE_COLOR ) ),
65 aLbHatchings ( this, CUI_RES( LB_HATCHINGS ) ),
66 aCtlPreview ( this, CUI_RES( CTL_PREVIEW ) ),
67 aBtnAdd ( this, CUI_RES( BTN_ADD ) ),
68 aBtnModify ( this, CUI_RES( BTN_MODIFY ) ),
69 aBtnDelete ( this, CUI_RES( BTN_DELETE ) ),
70 aBtnLoad ( this, CUI_RES( BTN_LOAD ) ),
71 aBtnSave ( this, CUI_RES( BTN_SAVE ) ),
73 rOutAttrs ( rInAttrs ),
75 pnHatchingListState ( 0 ),
76 pnColorListState ( 0 ),
77 pPageType ( 0 ),
78 pDlgType ( 0 ),
79 pPos ( 0 ),
80 pbAreaTP ( 0 ),
82 pXPool ( (XOutdevItemPool*) rInAttrs.GetPool() ),
83 aXFStyleItem ( XFILL_HATCH ),
84 aXHatchItem ( String(), XHatch() ),
85 aXFillAttr ( pXPool ),
86 rXFSet ( aXFillAttr.GetItemSet() )
89 FreeResource();
91 // this page needs ExchangeSupport
92 SetExchangeSupport();
94 // adjust metric
95 FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
97 switch ( eFUnit )
99 case FUNIT_M:
100 case FUNIT_KM:
101 eFUnit = FUNIT_MM;
102 break;
103 default: ;//prevent warning
105 SetFieldUnit( aMtrDistance, eFUnit );
107 // determine PoolUnit
108 SfxItemPool* pPool = rOutAttrs.GetPool();
109 DBG_ASSERT( pPool, "Wo ist der Pool?" );
110 ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
112 // setting the output device
113 rXFSet.Put( aXFStyleItem );
114 rXFSet.Put( aXHatchItem );
115 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
117 aLbHatchings.SetSelectHdl( LINK( this, SvxHatchTabPage, ChangeHatchHdl_Impl ) );
119 Link aLink = LINK( this, SvxHatchTabPage, ModifiedHdl_Impl );
120 aMtrDistance.SetModifyHdl( aLink );
121 aMtrAngle.SetModifyHdl( aLink );
122 aLbLineType.SetSelectHdl( aLink );
123 aLbLineColor.SetSelectHdl( aLink );
125 aBtnAdd.SetClickHdl( LINK( this, SvxHatchTabPage, ClickAddHdl_Impl ) );
126 aBtnModify.SetClickHdl(
127 LINK( this, SvxHatchTabPage, ClickModifyHdl_Impl ) );
128 aBtnDelete.SetClickHdl(
129 LINK( this, SvxHatchTabPage, ClickDeleteHdl_Impl ) );
130 aBtnLoad.SetClickHdl( LINK( this, SvxHatchTabPage, ClickLoadHdl_Impl ) );
131 aBtnSave.SetClickHdl( LINK( this, SvxHatchTabPage, ClickSaveHdl_Impl ) );
133 aCtlPreview.SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
135 aCtlPreview.SetAccessibleName(String(CUI_RES(STR_EXAMPLE)));
136 aLbHatchings.SetAccessibleName( String(CUI_RES(STR_LB_HATCHINGSTYLE)) );
137 aCtlAngle.SetAccessibleRelationMemberOf( &aFlProp );
138 aLbHatchings.SetAccessibleRelationMemberOf( &aFlProp );
139 aBtnAdd.SetAccessibleRelationMemberOf( &aFlProp );
140 aBtnModify.SetAccessibleRelationMemberOf( &aFlProp );
141 aBtnDelete.SetAccessibleRelationMemberOf( &aFlProp );
142 aLbHatchings.SetAccessibleRelationLabeledBy(&aLbHatchings);
145 // -----------------------------------------------------------------------
147 void SvxHatchTabPage::Construct()
149 aLbLineColor.Fill( pColorList );
150 aLbHatchings.Fill( pHatchingList );
153 // -----------------------------------------------------------------------
155 void SvxHatchTabPage::ActivatePage( const SfxItemSet& rSet )
157 sal_uInt16 nPos;
158 sal_uInt16 nCount;
160 if( *pDlgType == 0 ) // area dialog
162 *pbAreaTP = sal_False;
164 if( pColorList.is() )
166 // ColorList
167 if( *pnColorListState & CT_CHANGED ||
168 *pnColorListState & CT_MODIFIED )
170 if( *pnColorListState & CT_CHANGED )
171 pColorList = ( (SvxAreaTabDialog*) GetParentDialog() )->GetNewColorList();
173 // LbLineColor
174 nPos = aLbLineColor.GetSelectEntryPos();
175 aLbLineColor.Clear();
176 aLbLineColor.Fill( pColorList );
177 nCount = aLbLineColor.GetEntryCount();
178 if( nCount == 0 )
179 ; // this case should not occur
180 else if( nCount <= nPos )
181 aLbLineColor.SelectEntryPos( 0 );
182 else
183 aLbLineColor.SelectEntryPos( nPos );
185 ModifiedHdl_Impl( this );
188 // determining (possibly cutting) the name
189 // and displaying it in the GroupBox
190 OUString aString( CUI_RES( RID_SVXSTR_TABLE ) );
191 aString += ": ";
192 INetURLObject aURL( pHatchingList->GetPath() );
194 aURL.Append( pHatchingList->GetName() );
195 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
197 if ( aURL.getBase().getLength() > 18 )
199 aString += aURL.getBase().copy( 0, 15 );
200 aString += "...";
202 else
203 aString += aURL.getBase();
205 if( *pPageType == PT_HATCH && *pPos != LISTBOX_ENTRY_NOTFOUND )
207 aLbHatchings.SelectEntryPos( *pPos );
209 // colors could have been deleted
210 ChangeHatchHdl_Impl( this );
212 *pPageType = PT_HATCH;
213 *pPos = LISTBOX_ENTRY_NOTFOUND;
217 rXFSet.Put ( ( XFillColorItem& ) rSet.Get(XATTR_FILLCOLOR) );
218 rXFSet.Put ( ( XFillBackgroundItem&)rSet.Get(XATTR_FILLBACKGROUND) );
219 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
220 aCtlPreview.Invalidate();
223 // -----------------------------------------------------------------------
225 int SvxHatchTabPage::DeactivatePage( SfxItemSet* _pSet )
227 if ( CheckChanges_Impl() == -1L )
228 return KEEP_PAGE;
230 if( _pSet )
231 FillItemSet( *_pSet );
233 return LEAVE_PAGE;
236 // -----------------------------------------------------------------------
238 long SvxHatchTabPage::CheckChanges_Impl()
240 if( aMtrDistance.GetText() != aMtrDistance.GetSavedValue() ||
241 aMtrAngle.GetText() != aMtrAngle.GetSavedValue() ||
242 aLbLineType.GetSelectEntryPos() != aLbLineType.GetSavedValue() ||
243 aLbLineColor.GetSelectEntryPos() != aLbLineColor.GetSavedValue() ||
244 aLbHatchings.GetSelectEntryPos() != aLbHatchings.GetSavedValue() )
246 ResMgr& rMgr = CUI_MGR();
247 Image aWarningBoxImage = WarningBox::GetStandardImage();
248 SvxMessDialog* aMessDlg = new SvxMessDialog(GetParentDialog(),
249 SVX_RESSTR( RID_SVXSTR_HATCH ),
250 CUI_RESSTR( RID_SVXSTR_ASK_CHANGE_HATCH ),
251 &aWarningBoxImage );
252 DBG_ASSERT(aMessDlg, "Dialogdiet fail!");
253 aMessDlg->SetButtonText( MESS_BTN_1,
254 String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
255 aMessDlg->SetButtonText( MESS_BTN_2,
256 String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
258 short nRet = aMessDlg->Execute();
260 switch( nRet )
262 case RET_BTN_1:
264 ClickModifyHdl_Impl( this );
266 break;
268 case RET_BTN_2:
270 ClickAddHdl_Impl( this );
272 break;
274 case RET_CANCEL:
275 break;
277 delete aMessDlg;
280 sal_uInt16 nPos = aLbHatchings.GetSelectEntryPos();
281 if( nPos != LISTBOX_ENTRY_NOTFOUND )
282 *pPos = nPos;
283 return 0L;
286 // -----------------------------------------------------------------------
288 sal_Bool SvxHatchTabPage::FillItemSet( SfxItemSet& rSet )
290 if( *pDlgType == 0 && *pbAreaTP == sal_False ) // area dialog
292 if( *pPageType == PT_HATCH )
294 // CheckChanges(); <-- duplicate inquiry ?
296 XHatch* pXHatch = NULL;
297 String aString;
298 sal_uInt16 nPos = aLbHatchings.GetSelectEntryPos();
299 if( nPos != LISTBOX_ENTRY_NOTFOUND )
301 pXHatch = new XHatch( pHatchingList->GetHatch( nPos )->GetHatch() );
302 aString = aLbHatchings.GetSelectEntry();
304 // gradient has been (unidentifiedly) passed
305 else
307 pXHatch = new XHatch( aLbLineColor.GetSelectEntryColor(),
308 (XHatchStyle) aLbLineType.GetSelectEntryPos(),
309 GetCoreValue( aMtrDistance, ePoolUnit ),
310 static_cast<long>(aMtrAngle.GetValue() * 10) );
312 DBG_ASSERT( pXHatch, "XHatch konnte nicht erzeugt werden" );
313 rSet.Put( XFillStyleItem( XFILL_HATCH ) );
314 rSet.Put( XFillHatchItem( aString, *pXHatch ) );
316 delete pXHatch;
319 return sal_True;
322 // -----------------------------------------------------------------------
324 void SvxHatchTabPage::Reset( const SfxItemSet& rSet )
326 ChangeHatchHdl_Impl( this );
328 // determine button state
329 if( pHatchingList->Count() )
331 aBtnModify.Enable();
332 aBtnDelete.Enable();
333 aBtnSave.Enable();
335 else
337 aBtnModify.Disable();
338 aBtnDelete.Disable();
339 aBtnSave.Disable();
342 rXFSet.Put ( ( XFillColorItem& ) rSet.Get(XATTR_FILLCOLOR) );
343 rXFSet.Put ( ( XFillBackgroundItem&)rSet.Get(XATTR_FILLBACKGROUND) );
344 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
345 aCtlPreview.Invalidate();
348 // -----------------------------------------------------------------------
350 SfxTabPage* SvxHatchTabPage::Create( Window* pWindow,
351 const SfxItemSet& rSet )
353 return new SvxHatchTabPage( pWindow, rSet );
356 //------------------------------------------------------------------------
358 IMPL_LINK( SvxHatchTabPage, ModifiedHdl_Impl, void *, p )
360 if( p == &aMtrAngle )
362 switch( aMtrAngle.GetValue() )
364 case 135: aCtlAngle.SetActualRP( RP_LT ); break;
365 case 90: aCtlAngle.SetActualRP( RP_MT ); break;
366 case 45: aCtlAngle.SetActualRP( RP_RT ); break;
367 case 180: aCtlAngle.SetActualRP( RP_LM ); break;
368 case 0: aCtlAngle.SetActualRP( RP_RM ); break;
369 case 225: aCtlAngle.SetActualRP( RP_LB ); break;
370 case 270: aCtlAngle.SetActualRP( RP_MB ); break;
371 case 315: aCtlAngle.SetActualRP( RP_RB ); break;
372 default: aCtlAngle.SetActualRP( RP_MM ); break;
376 XHatch aXHatch( aLbLineColor.GetSelectEntryColor(),
377 (XHatchStyle) aLbLineType.GetSelectEntryPos(),
378 GetCoreValue( aMtrDistance, ePoolUnit ),
379 static_cast<long>(aMtrAngle.GetValue() * 10) );
381 rXFSet.Put( XFillHatchItem( String(), aXHatch ) );
382 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
384 aCtlPreview.Invalidate();
386 return 0L;
389 //------------------------------------------------------------------------
391 IMPL_LINK_NOARG(SvxHatchTabPage, ChangeHatchHdl_Impl)
393 XHatch* pHatch = NULL;
394 int nPos = aLbHatchings.GetSelectEntryPos();
396 if( nPos != LISTBOX_ENTRY_NOTFOUND )
397 pHatch = new XHatch( ( (XHatchEntry*) pHatchingList->GetHatch( nPos ) )->GetHatch() );
398 else
400 const SfxPoolItem* pPoolItem = NULL;
401 if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), sal_True, &pPoolItem ) )
403 if( ( XFILL_HATCH == (XFillStyle) ( ( const XFillStyleItem* ) pPoolItem )->GetValue() ) &&
404 ( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLHATCH ), sal_True, &pPoolItem ) ) )
406 pHatch = new XHatch( ( ( const XFillHatchItem* ) pPoolItem )->GetHatchValue() );
409 if( !pHatch )
411 aLbHatchings.SelectEntryPos( 0 );
412 nPos = aLbHatchings.GetSelectEntryPos();
413 if( nPos != LISTBOX_ENTRY_NOTFOUND )
414 pHatch = new XHatch( ( (XHatchEntry*) pHatchingList->GetHatch( nPos ) )->GetHatch() );
417 if( pHatch )
419 aLbLineType.SelectEntryPos(
420 sal::static_int_cast< sal_uInt16 >( pHatch->GetHatchStyle() ) );
421 // if the entry is not in the listbox
422 // the color is added temporarily
423 aLbLineColor.SetNoSelection();
424 aLbLineColor.SelectEntry( pHatch->GetColor() );
425 if( aLbLineColor.GetSelectEntryCount() == 0 )
427 aLbLineColor.InsertEntry( pHatch->GetColor(), String() );
428 aLbLineColor.SelectEntry( pHatch->GetColor() );
430 SetMetricValue( aMtrDistance, pHatch->GetDistance(), ePoolUnit );
431 aMtrAngle.SetValue( pHatch->GetAngle() / 10 );
433 switch( aMtrAngle.GetValue() )
435 case 135: aCtlAngle.SetActualRP( RP_LT ); break;
436 case 90: aCtlAngle.SetActualRP( RP_MT ); break;
437 case 45: aCtlAngle.SetActualRP( RP_RT ); break;
438 case 180: aCtlAngle.SetActualRP( RP_LM ); break;
439 case 0: aCtlAngle.SetActualRP( RP_RM ); break;
440 case 225: aCtlAngle.SetActualRP( RP_LB ); break;
441 case 270: aCtlAngle.SetActualRP( RP_MB ); break;
442 case 315: aCtlAngle.SetActualRP( RP_RB ); break;
443 default: aCtlAngle.SetActualRP( RP_MM ); break;
446 // fill ItemSet and pass it on to aCtlPreview
447 rXFSet.Put( XFillHatchItem( String(), *pHatch ) );
448 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
450 aCtlPreview.Invalidate();
451 delete pHatch;
453 aMtrDistance.SaveValue();
454 aMtrAngle.SaveValue();
455 aLbLineType.SaveValue();
456 aLbLineColor.SaveValue();
457 aLbHatchings.SaveValue();
459 return 0L;
462 //------------------------------------------------------------------------
464 IMPL_LINK_NOARG(SvxHatchTabPage, ClickAddHdl_Impl)
466 ResMgr& rMgr = CUI_MGR();
467 String aNewName( SVX_RES( RID_SVXSTR_HATCH ) );
468 String aDesc( CUI_RES( RID_SVXSTR_DESC_HATCH ) );
469 String aName;
471 long nCount = pHatchingList->Count();
472 long j = 1;
473 sal_Bool bDifferent = sal_False;
475 while( !bDifferent )
477 aName = aNewName;
478 aName += sal_Unicode(' ');
479 aName += OUString::valueOf( j++ );
480 bDifferent = sal_True;
482 for( long i = 0; i < nCount && bDifferent; i++ )
483 if( aName == pHatchingList->GetHatch( i )->GetName() )
484 bDifferent = sal_False;
487 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
488 DBG_ASSERT(pFact, "Dialogdiet fail!");
489 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
490 DBG_ASSERT(pDlg, "Dialogdiet fail!");
491 WarningBox* pWarnBox = NULL;
492 sal_uInt16 nError = RID_SVXSTR_WARN_NAME_DUPLICATE;
494 while( pDlg->Execute() == RET_OK )
496 pDlg->GetName( aName );
498 bDifferent = sal_True;
500 for( long i = 0; i < nCount && bDifferent; i++ )
501 if( aName == pHatchingList->GetHatch( i )->GetName() )
502 bDifferent = sal_False;
504 if( bDifferent ) {
505 nError = 0;
506 break;
509 if( !pWarnBox )
511 pWarnBox = new WarningBox( GetParentDialog(),
512 WinBits( WB_OK_CANCEL ),
513 String( ResId( nError, rMgr ) ) );
514 pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
517 if( pWarnBox->Execute() != RET_OK )
518 break;
520 delete pDlg;
521 delete pWarnBox;
523 if( !nError )
525 XHatch aXHatch( aLbLineColor.GetSelectEntryColor(),
526 (XHatchStyle) aLbLineType.GetSelectEntryPos(),
527 GetCoreValue( aMtrDistance, ePoolUnit ),
528 static_cast<long>(aMtrAngle.GetValue() * 10) );
529 XHatchEntry* pEntry = new XHatchEntry( aXHatch, aName );
531 pHatchingList->Insert( pEntry, nCount );
533 aLbHatchings.Append( pEntry );
535 aLbHatchings.SelectEntryPos( aLbHatchings.GetEntryCount() - 1 );
537 #ifdef WNT
538 // hack: #31355# W.P.
539 Rectangle aRect( aLbHatchings.GetPosPixel(), aLbHatchings.GetSizePixel() );
540 if( sal_True ) { // ??? overlapped with pDlg
541 // and srolling
542 Invalidate( aRect );
544 #endif
546 *pnHatchingListState |= CT_MODIFIED;
548 ChangeHatchHdl_Impl( this );
551 // determine button state
552 if( pHatchingList->Count() )
554 aBtnModify.Enable();
555 aBtnDelete.Enable();
556 aBtnSave.Enable();
558 return 0L;
561 //------------------------------------------------------------------------
563 IMPL_LINK_NOARG(SvxHatchTabPage, ClickModifyHdl_Impl)
565 sal_uInt16 nPos = aLbHatchings.GetSelectEntryPos();
567 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
569 ResMgr& rMgr = CUI_MGR();
570 String aDesc( CUI_RES( RID_SVXSTR_DESC_HATCH ) );
571 String aName( pHatchingList->GetHatch( nPos )->GetName() );
572 String aOldName = aName;
574 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
575 DBG_ASSERT(pFact, "Dialogdiet fail!");
576 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
577 DBG_ASSERT(pDlg, "Dialogdiet fail!");
579 long nCount = pHatchingList->Count();
580 sal_Bool bDifferent = sal_False;
581 sal_Bool bLoop = sal_True;
582 while( bLoop && pDlg->Execute() == RET_OK )
584 pDlg->GetName( aName );
585 bDifferent = sal_True;
587 for( long i = 0; i < nCount && bDifferent; i++ )
589 if( aName == pHatchingList->GetHatch( i )->GetName() &&
590 aName != aOldName )
591 bDifferent = sal_False;
594 if( bDifferent )
596 bLoop = sal_False;
597 XHatch aXHatch( aLbLineColor.GetSelectEntryColor(),
598 (XHatchStyle) aLbLineType.GetSelectEntryPos(),
599 GetCoreValue( aMtrDistance, ePoolUnit ),
600 static_cast<long>(aMtrAngle.GetValue() * 10) );
602 XHatchEntry* pEntry = new XHatchEntry( aXHatch, aName );
604 delete pHatchingList->Replace( pEntry, nPos );
606 aLbHatchings.Modify( pEntry, nPos );
608 aLbHatchings.SelectEntryPos( nPos );
610 // save values for changes recognition (-> method)
611 aMtrDistance.SaveValue();
612 aMtrAngle.SaveValue();
613 aLbLineType.SaveValue();
614 aLbLineColor.SaveValue();
615 aLbHatchings.SaveValue();
617 *pnHatchingListState |= CT_MODIFIED;
619 else
621 WarningBox aBox( GetParentDialog(), WinBits( WB_OK ),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
622 aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
623 aBox.Execute();
626 delete( pDlg );
628 return 0L;
631 //------------------------------------------------------------------------
633 IMPL_LINK_NOARG(SvxHatchTabPage, ClickDeleteHdl_Impl)
635 sal_uInt16 nPos = aLbHatchings.GetSelectEntryPos();
637 if( nPos != LISTBOX_ENTRY_NOTFOUND )
639 QueryBox aQueryBox( GetParentDialog(), WinBits( WB_YES_NO | WB_DEF_NO ),
640 String( CUI_RES( RID_SVXSTR_ASK_DEL_HATCH ) ) );
642 if( aQueryBox.Execute() == RET_YES )
644 delete pHatchingList->Remove( nPos );
645 aLbHatchings.RemoveEntry( nPos );
646 aLbHatchings.SelectEntryPos( 0 );
648 aCtlPreview.Invalidate();
650 ChangeHatchHdl_Impl( this );
652 *pnHatchingListState |= CT_MODIFIED;
655 // determine button state
656 if( !pHatchingList->Count() )
658 aBtnModify.Disable();
659 aBtnDelete.Disable();
660 aBtnSave.Disable();
662 return 0L;
665 // -----------------------------------------------------------------------
667 IMPL_LINK_NOARG(SvxHatchTabPage, ClickLoadHdl_Impl)
669 ResMgr& rMgr = CUI_MGR();
670 sal_uInt16 nReturn = RET_YES;
672 if ( *pnHatchingListState & CT_MODIFIED )
674 nReturn = WarningBox( GetParentDialog(), WinBits( WB_YES_NO_CANCEL ),
675 String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
677 if ( nReturn == RET_YES )
678 pHatchingList->Save();
681 if ( nReturn != RET_CANCEL )
683 ::sfx2::FileDialogHelper aDlg(
684 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
685 0 );
686 String aStrFilterType( "*.soh" );
687 aDlg.AddFilter( aStrFilterType, aStrFilterType );
688 INetURLObject aFile( SvtPathOptions().GetPalettePath() );
689 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
691 if( aDlg.Execute() == ERRCODE_NONE )
693 INetURLObject aURL( aDlg.GetPath() );
694 INetURLObject aPathURL( aURL );
696 aPathURL.removeSegment();
697 aPathURL.removeFinalSlash();
699 XHatchListRef pHatchList = XPropertyList::CreatePropertyList(
700 XHATCH_LIST, aPathURL.GetMainURL( INetURLObject::NO_DECODE ), pXPool )->AsHatchList();
701 pHatchList->SetName( aURL.getName() );
702 if( pHatchList->Load() )
704 pHatchingList = pHatchList;
705 ( (SvxAreaTabDialog*) GetParentDialog() )->SetNewHatchingList( pHatchingList );
707 aLbHatchings.Clear();
708 aLbHatchings.Fill( pHatchingList );
709 Reset( rOutAttrs );
711 pHatchingList->SetName( aURL.getName() );
713 // determining (and possibly cutting) the name
714 // and displaying it in the GroupBox
715 OUString aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
716 aString += ": ";
718 if ( aURL.getBase().getLength() > 18 )
720 aString += aURL.getBase().copy( 0, 15 );
721 aString += "...";
723 else
724 aString += aURL.getBase();
726 *pnHatchingListState |= CT_CHANGED;
727 *pnHatchingListState &= ~CT_MODIFIED;
729 else
730 ErrorBox( GetParentDialog(), WinBits( WB_OK ),
731 String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
735 // determine button state
736 if ( pHatchingList->Count() )
738 aBtnModify.Enable();
739 aBtnDelete.Enable();
740 aBtnSave.Enable();
742 else
744 aBtnModify.Disable();
745 aBtnDelete.Disable();
746 aBtnSave.Disable();
748 return 0L;
751 // -----------------------------------------------------------------------
753 IMPL_LINK_NOARG(SvxHatchTabPage, ClickSaveHdl_Impl)
755 ::sfx2::FileDialogHelper aDlg(
756 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
757 String aStrFilterType( "*.soh" );
758 aDlg.AddFilter( aStrFilterType, aStrFilterType );
760 INetURLObject aFile( SvtPathOptions().GetPalettePath() );
761 DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
763 if( pHatchingList->GetName().Len() )
765 aFile.Append( pHatchingList->GetName() );
767 if( aFile.getExtension().isEmpty() )
768 aFile.SetExtension( OUString("soh") );
771 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
772 if ( aDlg.Execute() == ERRCODE_NONE )
774 INetURLObject aURL( aDlg.GetPath() );
775 INetURLObject aPathURL( aURL );
777 aPathURL.removeSegment();
778 aPathURL.removeFinalSlash();
780 pHatchingList->SetName( aURL.getName() );
781 pHatchingList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
783 if( pHatchingList->Save() )
785 // determining (and possibly cutting) the name
786 // and displaying it in the GroupBox
787 OUString aString( CUI_RES( RID_SVXSTR_TABLE ) );
788 aString += ": ";
790 if ( aURL.getBase().getLength() > 18 )
792 aString += aURL.getBase().copy( 0, 15 );
793 aString += "...";
795 else
796 aString += aURL.getBase();
798 *pnHatchingListState |= CT_SAVED;
799 *pnHatchingListState &= ~CT_MODIFIED;
801 else
803 ErrorBox( GetParentDialog(), WinBits( WB_OK ),
804 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
808 return 0L;
811 //------------------------------------------------------------------------
813 void SvxHatchTabPage::PointChanged( Window* pWindow, RECT_POINT eRcPt )
815 if( pWindow == &aCtlAngle )
817 switch( eRcPt )
819 case RP_LT: aMtrAngle.SetValue( 135 ); break;
820 case RP_MT: aMtrAngle.SetValue( 90 ); break;
821 case RP_RT: aMtrAngle.SetValue( 45 ); break;
822 case RP_LM: aMtrAngle.SetValue( 180 ); break;
823 case RP_RM: aMtrAngle.SetValue( 0 ); break;
824 case RP_LB: aMtrAngle.SetValue( 225 ); break;
825 case RP_MB: aMtrAngle.SetValue( 270 ); break;
826 case RP_RB: aMtrAngle.SetValue( 315 ); break;
827 case RP_MM: break;
829 ModifiedHdl_Impl( this );
834 void SvxHatchTabPage::DataChanged( const DataChangedEvent& rDCEvt )
836 if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
837 aCtlPreview.SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
839 SvxTabPage::DataChanged( rDCEvt );
842 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */