Update ooo320-m1
[ooovba.git] / svx / source / cui / tphatch.cxx
blob42f576836b34120e7aee172e7f748386f00c3194
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tphatch.cxx,v $
10 * $Revision: 1.29 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 // include ---------------------------------------------------------------
39 #include <tools/shl.hxx>
40 #include <tools/urlobj.hxx>
41 #ifndef _MSGBOX_HXX //autogen
42 #include <vcl/msgbox.hxx>
43 #endif
44 #include <svtools/pathoptions.hxx>
45 #include <sfx2/app.hxx>
46 #include <sfx2/module.hxx>
47 #include <sfx2/filedlghelper.hxx>
48 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
50 #define _SVX_TPHATCH_CXX
52 #include <svx/dialogs.hrc>
53 #include "tabarea.hrc"
54 #include "dlgname.hrc"
55 #include "helpid.hrc"
60 #include "xattr.hxx"
61 #include <svx/xpool.hxx>
62 #include <svx/xtable.hxx>
64 #include "drawitem.hxx"
65 #include "cuitabarea.hxx"
66 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx"
67 #include <svx/svxdlg.hxx> //CHINA001
68 #include <svx/dialmgr.hxx>
69 #include "dlgutil.hxx"
71 #define DLGWIN this->GetParent()->GetParent()
73 #define BITMAP_WIDTH 32
74 #define BITMAP_HEIGHT 12
76 /*************************************************************************
78 |* Dialog zum Aendern und Definieren der Schraffuren
80 \************************************************************************/
82 SvxHatchTabPage::SvxHatchTabPage
84 Window* pParent,
85 const SfxItemSet& rInAttrs
86 ) :
88 SvxTabPage ( pParent, SVX_RES( RID_SVXPAGE_HATCH ), rInAttrs ),
90 aFtDistance ( this, SVX_RES( FT_LINE_DISTANCE ) ),
91 aMtrDistance ( this, SVX_RES( MTR_FLD_DISTANCE ) ),
92 aFtAngle ( this, SVX_RES( FT_LINE_ANGLE ) ),
93 aMtrAngle ( this, SVX_RES( MTR_FLD_ANGLE ) ),
94 aCtlAngle ( this, SVX_RES( CTL_ANGLE ),
95 RP_RB, 200, 80, CS_ANGLE ),
96 aFlProp ( this, SVX_RES( FL_PROP ) ),
97 aFtLineType ( this, SVX_RES( FT_LINE_TYPE ) ),
98 aLbLineType ( this, SVX_RES( LB_LINE_TYPE ) ),
99 aFtLineColor ( this, SVX_RES( FT_LINE_COLOR ) ),
100 aLbLineColor ( this, SVX_RES( LB_LINE_COLOR ) ),
101 aLbHatchings ( this, SVX_RES( LB_HATCHINGS ) ),
102 aCtlPreview ( this, SVX_RES( CTL_PREVIEW ) ),
103 aBtnAdd ( this, SVX_RES( BTN_ADD ) ),
104 aBtnModify ( this, SVX_RES( BTN_MODIFY ) ),
105 aBtnDelete ( this, SVX_RES( BTN_DELETE ) ),
106 aBtnLoad ( this, SVX_RES( BTN_LOAD ) ),
107 aBtnSave ( this, SVX_RES( BTN_SAVE ) ),
109 rOutAttrs ( rInAttrs ),
110 pColorTab( NULL ),
111 pHatchingList( NULL ),
113 pXPool ( (XOutdevItemPool*) rInAttrs.GetPool() ),
114 aXFStyleItem ( XFILL_HATCH ),
115 aXHatchItem ( String(), XHatch() ),
116 aXFillAttr ( pXPool ),
117 rXFSet ( aXFillAttr.GetItemSet() )
120 aBtnLoad.SetModeImage( Image( SVX_RES( RID_SVXIMG_LOAD_H ) ), BMP_COLOR_HIGHCONTRAST );
121 aBtnSave.SetModeImage( Image( SVX_RES( RID_SVXIMG_SAVE_H ) ), BMP_COLOR_HIGHCONTRAST );
123 FreeResource();
125 // diese Page braucht ExchangeSupport
126 SetExchangeSupport();
128 // Metrik einstellen
129 FieldUnit eFUnit = GetModuleFieldUnit( &rInAttrs );
131 switch ( eFUnit )
133 case FUNIT_M:
134 case FUNIT_KM:
135 eFUnit = FUNIT_MM;
136 break;
137 default: ;//prevent warning
139 SetFieldUnit( aMtrDistance, eFUnit );
141 // PoolUnit ermitteln
142 SfxItemPool* pPool = rOutAttrs.GetPool();
143 DBG_ASSERT( pPool, "Wo ist der Pool?" );
144 ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
146 // Setzen des Output-Devices
147 rXFSet.Put( aXFStyleItem );
148 rXFSet.Put( aXHatchItem );
149 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
151 aLbHatchings.SetSelectHdl( LINK( this, SvxHatchTabPage, ChangeHatchHdl_Impl ) );
153 Link aLink = LINK( this, SvxHatchTabPage, ModifiedHdl_Impl );
154 aMtrDistance.SetModifyHdl( aLink );
155 aMtrAngle.SetModifyHdl( aLink );
156 aLbLineType.SetSelectHdl( aLink );
157 aLbLineColor.SetSelectHdl( aLink );
159 aBtnAdd.SetClickHdl( LINK( this, SvxHatchTabPage, ClickAddHdl_Impl ) );
160 aBtnModify.SetClickHdl(
161 LINK( this, SvxHatchTabPage, ClickModifyHdl_Impl ) );
162 aBtnDelete.SetClickHdl(
163 LINK( this, SvxHatchTabPage, ClickDeleteHdl_Impl ) );
164 aBtnLoad.SetClickHdl( LINK( this, SvxHatchTabPage, ClickLoadHdl_Impl ) );
165 aBtnSave.SetClickHdl( LINK( this, SvxHatchTabPage, ClickSaveHdl_Impl ) );
167 aCtlPreview.SetDrawMode( GetDisplayBackground().GetColor().IsDark() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
170 // -----------------------------------------------------------------------
172 void SvxHatchTabPage::Construct()
174 // Farbtabelle
175 aLbLineColor.Fill( pColorTab );
177 // Schraffurentabelle
178 aLbHatchings.Fill( pHatchingList );
181 // -----------------------------------------------------------------------
183 void SvxHatchTabPage::ActivatePage( const SfxItemSet& rSet )
185 USHORT nPos;
186 USHORT nCount;
188 if( *pDlgType == 0 ) // Flaechen-Dialog
190 *pbAreaTP = FALSE;
192 if( pColorTab )
194 // ColorTable
195 if( *pnColorTableState & CT_CHANGED ||
196 *pnColorTableState & CT_MODIFIED )
198 if( *pnColorTableState & CT_CHANGED )
199 pColorTab = ( (SvxAreaTabDialog*) DLGWIN )->GetNewColorTable();
201 // LbLineColor
202 nPos = aLbLineColor.GetSelectEntryPos();
203 aLbLineColor.Clear();
204 aLbLineColor.Fill( pColorTab );
205 nCount = aLbLineColor.GetEntryCount();
206 if( nCount == 0 )
207 ; // Dieser Fall sollte nicht auftreten
208 else if( nCount <= nPos )
209 aLbLineColor.SelectEntryPos( 0 );
210 else
211 aLbLineColor.SelectEntryPos( nPos );
213 ModifiedHdl_Impl( this );
216 // Ermitteln (evtl. abschneiden) des Namens und in
217 // der GroupBox darstellen
218 String aString( SVX_RES( RID_SVXSTR_TABLE ) ); aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
219 INetURLObject aURL( pHatchingList->GetPath() );
221 aURL.Append( pHatchingList->GetName() );
222 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
224 if ( aURL.getBase().getLength() > 18 )
226 aString += String(aURL.getBase()).Copy( 0, 15 );
227 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
229 else
230 aString += String(aURL.getBase());
232 if( *pPageType == PT_HATCH && *pPos != LISTBOX_ENTRY_NOTFOUND )
234 aLbHatchings.SelectEntryPos( *pPos );
236 // Farben koennten geloescht worden sein
237 ChangeHatchHdl_Impl( this );
239 *pPageType = PT_HATCH;
240 *pPos = LISTBOX_ENTRY_NOTFOUND;
244 rXFSet.Put ( ( XFillColorItem& ) rSet.Get(XATTR_FILLCOLOR) );
245 rXFSet.Put ( ( XFillBackgroundItem&)rSet.Get(XATTR_FILLBACKGROUND) );
246 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
247 aCtlPreview.Invalidate();
250 // -----------------------------------------------------------------------
252 int SvxHatchTabPage::DeactivatePage( SfxItemSet* _pSet )
254 if ( CheckChanges_Impl() == -1L )
255 return KEEP_PAGE;
257 if( _pSet )
258 FillItemSet( *_pSet );
260 return LEAVE_PAGE;
263 // -----------------------------------------------------------------------
265 long SvxHatchTabPage::CheckChanges_Impl()
267 if( aMtrDistance.GetText() != aMtrDistance.GetSavedValue() ||
268 aMtrAngle.GetText() != aMtrAngle.GetSavedValue() ||
269 aLbLineType.GetSelectEntryPos() != aLbLineType.GetSavedValue() ||
270 aLbLineColor.GetSelectEntryPos() != aLbLineColor.GetSavedValue() ||
271 aLbHatchings.GetSelectEntryPos() != aLbHatchings.GetSavedValue() )
273 ResMgr& rMgr = DIALOG_MGR();
274 Image aWarningBoxImage = WarningBox::GetStandardImage();
275 //CHINA001 SvxMessDialog aMessDlg( DLGWIN,
276 //CHINA001 String( ResId( RID_SVXSTR_HATCH, rMgr ) ),
277 //CHINA001 String( ResId( RID_SVXSTR_ASK_CHANGE_HATCH, rMgr ) ),
278 //CHINA001 &aWarningBoxImage );
279 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
280 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
281 AbstractSvxMessDialog* aMessDlg = pFact->CreateSvxMessDialog( DLGWIN, RID_SVXDLG_MESSBOX,
282 String( ResId( RID_SVXSTR_HATCH, rMgr ) ),
283 String( ResId( RID_SVXSTR_ASK_CHANGE_HATCH, rMgr ) ),
284 &aWarningBoxImage );
285 DBG_ASSERT(aMessDlg, "Dialogdiet fail!");//CHINA001
286 aMessDlg->SetButtonText( MESS_BTN_1, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1,
287 String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
288 aMessDlg->SetButtonText( MESS_BTN_2, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2,
289 String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
291 short nRet = aMessDlg->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
293 switch( nRet )
295 case RET_BTN_1: // Aendern
297 ClickModifyHdl_Impl( this );
299 break;
301 case RET_BTN_2: // Hinzufuegen
303 ClickAddHdl_Impl( this );
305 break;
307 case RET_CANCEL:
308 // return( -1L ); <-- wuerde die Seite nicht verlassen
309 break;
310 // return( TRUE ); // Abbruch
312 delete aMessDlg; //add by CHINA001
315 USHORT nPos = aLbHatchings.GetSelectEntryPos();
316 if( nPos != LISTBOX_ENTRY_NOTFOUND )
317 *pPos = nPos;
318 return 0L;
321 // -----------------------------------------------------------------------
323 BOOL SvxHatchTabPage::FillItemSet( SfxItemSet& rSet )
325 if( *pDlgType == 0 && *pbAreaTP == FALSE ) // Flaechen-Dialog
327 if( *pPageType == PT_HATCH )
329 // CheckChanges(); <-- doppelte Abfrage ?
331 XHatch* pXHatch = NULL;
332 String aString;
333 USHORT nPos = aLbHatchings.GetSelectEntryPos();
334 if( nPos != LISTBOX_ENTRY_NOTFOUND )
336 pXHatch = new XHatch( pHatchingList->GetHatch( nPos )->GetHatch() );
337 aString = aLbHatchings.GetSelectEntry();
339 // Farbverlauf wurde (unbekannt) uebergeben
340 else
342 pXHatch = new XHatch( aLbLineColor.GetSelectEntryColor(),
343 (XHatchStyle) aLbLineType.GetSelectEntryPos(),
344 GetCoreValue( aMtrDistance, ePoolUnit ),
345 static_cast<long>(aMtrAngle.GetValue() * 10) );
347 DBG_ASSERT( pXHatch, "XHatch konnte nicht erzeugt werden" );
348 rSet.Put( XFillStyleItem( XFILL_HATCH ) );
349 rSet.Put( XFillHatchItem( aString, *pXHatch ) );
351 delete pXHatch;
354 return TRUE;
357 // -----------------------------------------------------------------------
359 void SvxHatchTabPage::Reset( const SfxItemSet& rSet )
361 // aLbHatchings.SelectEntryPos( 0 );
362 ChangeHatchHdl_Impl( this );
364 // Status der Buttons ermitteln
365 if( pHatchingList->Count() )
367 aBtnModify.Enable();
368 aBtnDelete.Enable();
369 aBtnSave.Enable();
371 else
373 aBtnModify.Disable();
374 aBtnDelete.Disable();
375 aBtnSave.Disable();
378 rXFSet.Put ( ( XFillColorItem& ) rSet.Get(XATTR_FILLCOLOR) );
379 rXFSet.Put ( ( XFillBackgroundItem&)rSet.Get(XATTR_FILLBACKGROUND) );
380 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
381 aCtlPreview.Invalidate();
384 // -----------------------------------------------------------------------
386 SfxTabPage* SvxHatchTabPage::Create( Window* pWindow,
387 const SfxItemSet& rSet )
389 return new SvxHatchTabPage( pWindow, rSet );
392 //------------------------------------------------------------------------
394 IMPL_LINK( SvxHatchTabPage, ModifiedHdl_Impl, void *, p )
396 if( p == &aMtrAngle )
398 // Setzen des Winkels im AngleControl
399 switch( aMtrAngle.GetValue() )
401 case 135: aCtlAngle.SetActualRP( RP_LT ); break;
402 case 90: aCtlAngle.SetActualRP( RP_MT ); break;
403 case 45: aCtlAngle.SetActualRP( RP_RT ); break;
404 case 180: aCtlAngle.SetActualRP( RP_LM ); break;
405 case 0: aCtlAngle.SetActualRP( RP_RM ); break;
406 case 225: aCtlAngle.SetActualRP( RP_LB ); break;
407 case 270: aCtlAngle.SetActualRP( RP_MB ); break;
408 case 315: aCtlAngle.SetActualRP( RP_RB ); break;
409 default: aCtlAngle.SetActualRP( RP_MM ); break;
413 XHatch aXHatch( aLbLineColor.GetSelectEntryColor(),
414 (XHatchStyle) aLbLineType.GetSelectEntryPos(),
415 GetCoreValue( aMtrDistance, ePoolUnit ),
416 static_cast<long>(aMtrAngle.GetValue() * 10) );
418 rXFSet.Put( XFillHatchItem( String(), aXHatch ) );
419 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
421 aCtlPreview.Invalidate();
423 return 0L;
426 //------------------------------------------------------------------------
428 IMPL_LINK( SvxHatchTabPage, ChangeHatchHdl_Impl, void *, EMPTYARG )
430 XHatch* pHatch = NULL;
431 int nPos = aLbHatchings.GetSelectEntryPos();
433 if( nPos != LISTBOX_ENTRY_NOTFOUND )
434 pHatch = new XHatch( ( (XHatchEntry*) pHatchingList->GetHatch( nPos ) )->GetHatch() );
435 else
437 const SfxPoolItem* pPoolItem = NULL;
438 if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), TRUE, &pPoolItem ) )
440 if( ( XFILL_HATCH == (XFillStyle) ( ( const XFillStyleItem* ) pPoolItem )->GetValue() ) &&
441 ( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLHATCH ), TRUE, &pPoolItem ) ) )
443 pHatch = new XHatch( ( ( const XFillHatchItem* ) pPoolItem )->GetHatchValue() );
446 if( !pHatch )
448 aLbHatchings.SelectEntryPos( 0 );
449 nPos = aLbHatchings.GetSelectEntryPos();
450 if( nPos != LISTBOX_ENTRY_NOTFOUND )
451 pHatch = new XHatch( ( (XHatchEntry*) pHatchingList->GetHatch( nPos ) )->GetHatch() );
454 if( pHatch )
456 aLbLineType.SelectEntryPos(
457 sal::static_int_cast< USHORT >( pHatch->GetHatchStyle() ) );
458 // Wenn der Eintrag nicht in der Listbox ist, wird die Farbe
459 // temporaer hinzugenommen
460 aLbLineColor.SetNoSelection();
461 aLbLineColor.SelectEntry( pHatch->GetColor() );
462 if( aLbLineColor.GetSelectEntryCount() == 0 )
464 aLbLineColor.InsertEntry( pHatch->GetColor(), String() );
465 aLbLineColor.SelectEntry( pHatch->GetColor() );
467 SetMetricValue( aMtrDistance, pHatch->GetDistance(), ePoolUnit );
468 aMtrAngle.SetValue( pHatch->GetAngle() / 10 );
470 // Setzen des Winkels im AngleControl
471 switch( aMtrAngle.GetValue() )
473 case 135: aCtlAngle.SetActualRP( RP_LT ); break;
474 case 90: aCtlAngle.SetActualRP( RP_MT ); break;
475 case 45: aCtlAngle.SetActualRP( RP_RT ); break;
476 case 180: aCtlAngle.SetActualRP( RP_LM ); break;
477 case 0: aCtlAngle.SetActualRP( RP_RM ); break;
478 case 225: aCtlAngle.SetActualRP( RP_LB ); break;
479 case 270: aCtlAngle.SetActualRP( RP_MB ); break;
480 case 315: aCtlAngle.SetActualRP( RP_RB ); break;
481 default: aCtlAngle.SetActualRP( RP_MM ); break;
484 // Backgroundcolor
486 const SfxPoolItem* pPoolItem = NULL;
487 if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLBACKGROUND ), TRUE, &pPoolItem ) )
489 rXFSet.Put ( XFillBackgroundItem( ( ( XFillBackgroundItem* )pPoolItem)->GetValue() ) );
490 if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), TRUE, &pPoolItem ) )
492 Color aColor( ( ( const XFillColorItem* ) pPoolItem )->GetValue() );
493 rXFSet.Put( XFillColorItem( String(), aColor ) );
497 // ItemSet fuellen und an aCtlPreview weiterleiten
498 rXFSet.Put( XFillHatchItem( String(), *pHatch ) );
499 aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
501 aCtlPreview.Invalidate();
502 delete pHatch;
504 aMtrDistance.SaveValue();
505 aMtrAngle.SaveValue();
506 aLbLineType.SaveValue();
507 aLbLineColor.SaveValue();
508 aLbHatchings.SaveValue();
510 return 0L;
513 //------------------------------------------------------------------------
515 IMPL_LINK( SvxHatchTabPage, ClickAddHdl_Impl, void *, EMPTYARG )
517 ResMgr& rMgr = DIALOG_MGR();
518 String aNewName( ResId( RID_SVXSTR_HATCH, rMgr ) );
519 String aDesc( ResId( RID_SVXSTR_DESC_HATCH, rMgr ) );
520 String aName;
522 long nCount = pHatchingList->Count();
523 long j = 1;
524 BOOL bDifferent = FALSE;
526 while( !bDifferent )
528 aName = aNewName;
529 aName += sal_Unicode(' ');
530 aName += UniString::CreateFromInt32( j++ );
531 bDifferent = TRUE;
533 for( long i = 0; i < nCount && bDifferent; i++ )
534 if( aName == pHatchingList->GetHatch( i )->GetName() )
535 bDifferent = FALSE;
538 //CHINA001 SvxNameDialog* pDlg = new SvxNameDialog( DLGWIN, aName, aDesc );
539 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
540 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
541 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc, RID_SVXDLG_NAME );
542 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
543 WarningBox* pWarnBox = NULL;
544 USHORT nError = RID_SVXSTR_WARN_NAME_DUPLICATE;
546 while( pDlg->Execute() == RET_OK )
548 pDlg->GetName( aName );
550 bDifferent = TRUE;
552 for( long i = 0; i < nCount && bDifferent; i++ )
553 if( aName == pHatchingList->GetHatch( i )->GetName() )
554 bDifferent = FALSE;
556 if( bDifferent ) {
557 nError = 0;
558 break;
561 if( !pWarnBox )
563 pWarnBox = new WarningBox( DLGWIN,
564 WinBits( WB_OK_CANCEL ),
565 String( ResId( nError, rMgr ) ) );
566 pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
569 if( pWarnBox->Execute() != RET_OK )
570 break;
572 //Rectangle aDlgRect( pDlg->GetPosPixel(), pDlg->GetSizePixel() );
573 delete pDlg;
574 delete pWarnBox;
576 if( !nError )
578 XHatch aXHatch( aLbLineColor.GetSelectEntryColor(),
579 (XHatchStyle) aLbLineType.GetSelectEntryPos(),
580 GetCoreValue( aMtrDistance, ePoolUnit ),
581 static_cast<long>(aMtrAngle.GetValue() * 10) );
582 XHatchEntry* pEntry = new XHatchEntry( aXHatch, aName );
584 pHatchingList->Insert( pEntry, nCount );
586 aLbHatchings.Append( pEntry );
588 aLbHatchings.SelectEntryPos( aLbHatchings.GetEntryCount() - 1 );
590 #ifdef WNT
591 // hack: #31355# W.P.
592 Rectangle aRect( aLbHatchings.GetPosPixel(), aLbHatchings.GetSizePixel() );
593 if( TRUE ) { // ??? overlapped with pDlg
594 // and srolling
595 Invalidate( aRect );
596 //aLbHatchings.Invalidate();
598 #endif
600 // Flag fuer modifiziert setzen
601 *pnHatchingListState |= CT_MODIFIED;
603 ChangeHatchHdl_Impl( this );
606 // Status der Buttons ermitteln
607 if( pHatchingList->Count() )
609 aBtnModify.Enable();
610 aBtnDelete.Enable();
611 aBtnSave.Enable();
613 return 0L;
616 //------------------------------------------------------------------------
618 IMPL_LINK( SvxHatchTabPage, ClickModifyHdl_Impl, void *, EMPTYARG )
620 USHORT nPos = aLbHatchings.GetSelectEntryPos();
622 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
624 ResMgr& rMgr = DIALOG_MGR();
625 String aNewName( ResId( RID_SVXSTR_HATCH, rMgr ) );
626 String aDesc( ResId( RID_SVXSTR_DESC_HATCH, rMgr ) );
627 String aName( pHatchingList->GetHatch( nPos )->GetName() );
628 String aOldName = aName;
630 //CHINA001 SvxNameDialog* pDlg = new SvxNameDialog( DLGWIN, aName, aDesc );
631 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
632 DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
633 AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc, RID_SVXDLG_NAME );
634 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
636 long nCount = pHatchingList->Count();
637 BOOL bDifferent = FALSE;
638 BOOL bLoop = TRUE;
639 while( bLoop && pDlg->Execute() == RET_OK )
641 pDlg->GetName( aName );
642 bDifferent = TRUE;
644 for( long i = 0; i < nCount && bDifferent; i++ )
646 if( aName == pHatchingList->GetHatch( i )->GetName() &&
647 aName != aOldName )
648 bDifferent = FALSE;
651 if( bDifferent )
653 bLoop = FALSE;
654 XHatch aXHatch( aLbLineColor.GetSelectEntryColor(),
655 (XHatchStyle) aLbLineType.GetSelectEntryPos(),
656 GetCoreValue( aMtrDistance, ePoolUnit ),
657 static_cast<long>(aMtrAngle.GetValue() * 10) );
659 XHatchEntry* pEntry = new XHatchEntry( aXHatch, aName );
661 delete pHatchingList->Replace( pEntry, nPos );
663 aLbHatchings.Modify( pEntry, nPos );
665 aLbHatchings.SelectEntryPos( nPos );
667 // Werte sichern fuer Changes-Erkennung ( -> Methode )
668 aMtrDistance.SaveValue();
669 aMtrAngle.SaveValue();
670 aLbLineType.SaveValue();
671 aLbLineColor.SaveValue();
672 aLbHatchings.SaveValue();
674 // Flag fuer modifiziert setzen
675 *pnHatchingListState |= CT_MODIFIED;
677 else
679 WarningBox aBox( DLGWIN, WinBits( WB_OK ),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
680 aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
681 aBox.Execute();
684 delete( pDlg );
686 return 0L;
689 //------------------------------------------------------------------------
691 IMPL_LINK( SvxHatchTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG )
693 USHORT nPos = aLbHatchings.GetSelectEntryPos();
695 if( nPos != LISTBOX_ENTRY_NOTFOUND )
697 QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ),
698 //! SVX_RES( RID_SVXSTR_DEL_HATCH ),
699 String( SVX_RES( RID_SVXSTR_ASK_DEL_HATCH ) ) );
701 if( aQueryBox.Execute() == RET_YES )
703 delete pHatchingList->Remove( nPos );
704 aLbHatchings.RemoveEntry( nPos );
705 aLbHatchings.SelectEntryPos( 0 );
707 aCtlPreview.Invalidate();
709 ChangeHatchHdl_Impl( this );
711 // Flag fuer modifiziert setzen
712 *pnHatchingListState |= CT_MODIFIED;
715 // Status der Buttons ermitteln
716 if( !pHatchingList->Count() )
718 aBtnModify.Disable();
719 aBtnDelete.Disable();
720 aBtnSave.Disable();
722 return 0L;
725 // -----------------------------------------------------------------------
727 IMPL_LINK( SvxHatchTabPage, ClickLoadHdl_Impl, void *, EMPTYARG )
729 ResMgr& rMgr = DIALOG_MGR();
730 USHORT nReturn = RET_YES;
732 if ( *pnHatchingListState & CT_MODIFIED )
734 nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ),
735 String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
737 if ( nReturn == RET_YES )
738 pHatchingList->Save();
741 if ( nReturn != RET_CANCEL )
743 ::sfx2::FileDialogHelper aDlg(
744 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
745 0 );
746 String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soh" ) );
747 aDlg.AddFilter( aStrFilterType, aStrFilterType );
748 INetURLObject aFile( SvtPathOptions().GetPalettePath() );
749 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
751 if( aDlg.Execute() == ERRCODE_NONE )
753 INetURLObject aURL( aDlg.GetPath() );
754 INetURLObject aPathURL( aURL );
756 aPathURL.removeSegment();
757 aPathURL.removeFinalSlash();
759 // Liste speichern
760 XHatchList* pHatchList = new XHatchList( aPathURL.GetMainURL( INetURLObject::NO_DECODE ), pXPool );
761 pHatchList->SetName( aURL.getName() );
762 if( pHatchList->Load() )
764 if( pHatchList )
766 // Pruefen, ob Tabelle geloescht werden darf:
767 if( pHatchingList != ( (SvxAreaTabDialog*) DLGWIN )->GetHatchingList() )
768 delete pHatchingList;
770 pHatchingList = pHatchList;
771 ( (SvxAreaTabDialog*) DLGWIN )->SetNewHatchingList( pHatchingList );
773 aLbHatchings.Clear();
774 aLbHatchings.Fill( pHatchingList );
775 Reset( rOutAttrs );
777 pHatchingList->SetName( aURL.getName() );
779 // Ermitteln (evtl. abschneiden) des Namens und in
780 // der GroupBox darstellen
781 String aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
782 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
784 if ( aURL.getBase().getLength() > 18 )
786 aString += String(aURL.getBase()).Copy( 0, 15 );
787 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
789 else
790 aString += String(aURL.getBase());
792 // Flag fuer gewechselt setzen
793 *pnHatchingListState |= CT_CHANGED;
794 // Flag fuer modifiziert entfernen
795 *pnHatchingListState &= ~CT_MODIFIED;
798 else
799 ErrorBox( DLGWIN, WinBits( WB_OK ),
800 String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
804 // Status der Buttons ermitteln
805 if ( pHatchingList->Count() )
807 aBtnModify.Enable();
808 aBtnDelete.Enable();
809 aBtnSave.Enable();
811 else
813 aBtnModify.Disable();
814 aBtnDelete.Disable();
815 aBtnSave.Disable();
817 return 0L;
820 // -----------------------------------------------------------------------
822 IMPL_LINK( SvxHatchTabPage, ClickSaveHdl_Impl, void *, EMPTYARG )
824 ::sfx2::FileDialogHelper aDlg(
825 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
826 String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soh" ) );
827 aDlg.AddFilter( aStrFilterType, aStrFilterType );
829 INetURLObject aFile( SvtPathOptions().GetPalettePath() );
830 DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
832 if( pHatchingList->GetName().Len() )
834 aFile.Append( pHatchingList->GetName() );
836 if( !aFile.getExtension().getLength() )
837 aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "soh" ) ) );
840 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
841 if ( aDlg.Execute() == ERRCODE_NONE )
843 INetURLObject aURL( aDlg.GetPath() );
844 INetURLObject aPathURL( aURL );
846 aPathURL.removeSegment();
847 aPathURL.removeFinalSlash();
849 pHatchingList->SetName( aURL.getName() );
850 pHatchingList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
852 if( pHatchingList->Save() )
854 // Ermitteln (evtl. abschneiden) des Namens und in
855 // der GroupBox darstellen
856 String aString( SVX_RES( RID_SVXSTR_TABLE ) );
857 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
859 if ( aURL.getBase().getLength() > 18 )
861 aString += String(aURL.getBase()).Copy( 0, 15 );
862 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
864 else
865 aString += String(aURL.getBase());
867 // Flag fuer gespeichert setzen
868 *pnHatchingListState |= CT_SAVED;
869 // Flag fuer modifiziert entfernen
870 *pnHatchingListState &= ~CT_MODIFIED;
872 else
874 ErrorBox( DLGWIN, WinBits( WB_OK ),
875 String( SVX_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
879 return 0L;
882 //------------------------------------------------------------------------
884 void SvxHatchTabPage::PointChanged( Window* pWindow, RECT_POINT eRcPt )
886 if( pWindow == &aCtlAngle )
888 switch( eRcPt )
890 case RP_LT: aMtrAngle.SetValue( 135 ); break;
891 case RP_MT: aMtrAngle.SetValue( 90 ); break;
892 case RP_RT: aMtrAngle.SetValue( 45 ); break;
893 case RP_LM: aMtrAngle.SetValue( 180 ); break;
894 case RP_RM: aMtrAngle.SetValue( 0 ); break;
895 case RP_LB: aMtrAngle.SetValue( 225 ); break;
896 case RP_MB: aMtrAngle.SetValue( 270 ); break;
897 case RP_RB: aMtrAngle.SetValue( 315 ); break;
898 case RP_MM: break;
900 ModifiedHdl_Impl( this );
905 void SvxHatchTabPage::DataChanged( const DataChangedEvent& rDCEvt )
907 if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
908 aCtlPreview.SetDrawMode( GetDisplayBackground().GetColor().IsDark() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
910 SvxTabPage::DataChanged( rDCEvt );