1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
31 // include ---------------------------------------------------------------
32 #include <tools/shl.hxx>
33 #include <tools/urlobj.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <unotools/pathoptions.hxx>
36 #include <sfx2/app.hxx>
37 #include <sfx2/module.hxx>
38 #include <sfx2/filedlghelper.hxx>
39 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
41 #define _SVX_TPHATCH_CXX
44 #include "tabarea.hrc"
45 //#include "dlgname.hrc"
47 #include "svx/xattr.hxx"
48 #include <svx/xpool.hxx>
49 #include <svx/xtable.hxx>
50 #include "svx/drawitem.hxx"
51 #include "cuitabarea.hxx"
52 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx"
53 #include <svx/svxdlg.hxx> //CHINA001
54 #include <dialmgr.hxx>
55 #include "svx/dlgutil.hxx"
56 #include <svx/dialmgr.hxx>
57 #include "paragrph.hrc"
58 #include <svx/dialogs.hrc>
60 #define DLGWIN this->GetParent()->GetParent()
62 #define BITMAP_WIDTH 32
63 #define BITMAP_HEIGHT 12
65 /*************************************************************************
67 |* Dialog zum Aendern und Definieren der Schraffuren
69 \************************************************************************/
71 SvxHatchTabPage::SvxHatchTabPage
74 const SfxItemSet
& rInAttrs
77 SvxTabPage ( pParent
, CUI_RES( RID_SVXPAGE_HATCH
), rInAttrs
),
79 aFtDistance ( this, CUI_RES( FT_LINE_DISTANCE
) ),
80 aMtrDistance ( this, CUI_RES( MTR_FLD_DISTANCE
) ),
81 aFtAngle ( this, CUI_RES( FT_LINE_ANGLE
) ),
82 aMtrAngle ( this, CUI_RES( MTR_FLD_ANGLE
) ),
83 aCtlAngle ( this, CUI_RES( CTL_ANGLE
),
84 RP_RB
, 200, 80, CS_ANGLE
),
85 aFlProp ( this, CUI_RES( FL_PROP
) ),
86 aFtLineType ( this, CUI_RES( FT_LINE_TYPE
) ),
87 aLbLineType ( this, CUI_RES( LB_LINE_TYPE
) ),
88 aFtLineColor ( this, CUI_RES( FT_LINE_COLOR
) ),
89 aLbLineColor ( this, CUI_RES( LB_LINE_COLOR
) ),
90 aLbHatchings ( this, CUI_RES( LB_HATCHINGS
) ),
91 aCtlPreview ( this, CUI_RES( CTL_PREVIEW
) ),
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
) ),
98 rOutAttrs ( rInAttrs
),
100 pHatchingList( NULL
),
102 pXPool ( (XOutdevItemPool
*) rInAttrs
.GetPool() ),
103 aXFStyleItem ( XFILL_HATCH
),
104 aXHatchItem ( String(), XHatch() ),
105 aXFillAttr ( pXPool
),
106 rXFSet ( aXFillAttr
.GetItemSet() )
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
);
114 // diese Page braucht ExchangeSupport
115 SetExchangeSupport();
118 FieldUnit eFUnit
= GetModuleFieldUnit( rInAttrs
);
126 default: ;//prevent warning
128 SetFieldUnit( aMtrDistance
, eFUnit
);
130 // PoolUnit ermitteln
131 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
132 DBG_ASSERT( pPool
, "Wo ist der Pool?" );
133 ePoolUnit
= pPool
->GetMetric( SID_ATTR_FILL_HATCH
);
135 // Setzen des Output-Devices
136 rXFSet
.Put( aXFStyleItem
);
137 rXFSet
.Put( aXHatchItem
);
138 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
140 aLbHatchings
.SetSelectHdl( LINK( this, SvxHatchTabPage
, ChangeHatchHdl_Impl
) );
142 Link aLink
= LINK( this, SvxHatchTabPage
, ModifiedHdl_Impl
);
143 aMtrDistance
.SetModifyHdl( aLink
);
144 aMtrAngle
.SetModifyHdl( aLink
);
145 aLbLineType
.SetSelectHdl( aLink
);
146 aLbLineColor
.SetSelectHdl( aLink
);
148 aBtnAdd
.SetClickHdl( LINK( this, SvxHatchTabPage
, ClickAddHdl_Impl
) );
149 aBtnModify
.SetClickHdl(
150 LINK( this, SvxHatchTabPage
, ClickModifyHdl_Impl
) );
151 aBtnDelete
.SetClickHdl(
152 LINK( this, SvxHatchTabPage
, ClickDeleteHdl_Impl
) );
153 aBtnLoad
.SetClickHdl( LINK( this, SvxHatchTabPage
, ClickLoadHdl_Impl
) );
154 aBtnSave
.SetClickHdl( LINK( this, SvxHatchTabPage
, ClickSaveHdl_Impl
) );
156 aCtlPreview
.SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST
: OUTPUT_DRAWMODE_COLOR
);
158 aCtlPreview
.SetAccessibleName(String(CUI_RES(STR_EXAMPLE
)));
159 aLbHatchings
.SetAccessibleName( String(CUI_RES(STR_LB_HATCHINGSTYLE
)) );
160 aCtlAngle
.SetAccessibleRelationMemberOf( &aFlProp
);
161 aLbHatchings
.SetAccessibleRelationMemberOf( &aFlProp
);
162 aBtnAdd
.SetAccessibleRelationMemberOf( &aFlProp
);
163 aBtnModify
.SetAccessibleRelationMemberOf( &aFlProp
);
164 aBtnDelete
.SetAccessibleRelationMemberOf( &aFlProp
);
165 aLbHatchings
.SetAccessibleRelationLabeledBy(&aLbHatchings
);
168 // -----------------------------------------------------------------------
170 void SvxHatchTabPage::Construct()
173 aLbLineColor
.Fill( pColorTab
);
175 // Schraffurentabelle
176 aLbHatchings
.Fill( pHatchingList
);
179 // -----------------------------------------------------------------------
181 void SvxHatchTabPage::ActivatePage( const SfxItemSet
& rSet
)
186 if( *pDlgType
== 0 ) // Flaechen-Dialog
188 *pbAreaTP
= sal_False
;
193 if( *pnColorTableState
& CT_CHANGED
||
194 *pnColorTableState
& CT_MODIFIED
)
196 if( *pnColorTableState
& CT_CHANGED
)
197 pColorTab
= ( (SvxAreaTabDialog
*) DLGWIN
)->GetNewColorTable();
200 nPos
= aLbLineColor
.GetSelectEntryPos();
201 aLbLineColor
.Clear();
202 aLbLineColor
.Fill( pColorTab
);
203 nCount
= aLbLineColor
.GetEntryCount();
205 ; // Dieser Fall sollte nicht auftreten
206 else if( nCount
<= nPos
)
207 aLbLineColor
.SelectEntryPos( 0 );
209 aLbLineColor
.SelectEntryPos( nPos
);
211 ModifiedHdl_Impl( this );
214 // Ermitteln (evtl. abschneiden) des Namens und in
215 // der GroupBox darstellen
216 String
aString( CUI_RES( RID_SVXSTR_TABLE
) ); aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
217 INetURLObject
aURL( pHatchingList
->GetPath() );
219 aURL
.Append( pHatchingList
->GetName() );
220 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
222 if ( aURL
.getBase().getLength() > 18 )
224 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
225 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
228 aString
+= String(aURL
.getBase());
230 if( *pPageType
== PT_HATCH
&& *pPos
!= LISTBOX_ENTRY_NOTFOUND
)
232 aLbHatchings
.SelectEntryPos( *pPos
);
234 // Farben koennten geloescht worden sein
235 ChangeHatchHdl_Impl( this );
237 *pPageType
= PT_HATCH
;
238 *pPos
= LISTBOX_ENTRY_NOTFOUND
;
242 rXFSet
.Put ( ( XFillColorItem
& ) rSet
.Get(XATTR_FILLCOLOR
) );
243 rXFSet
.Put ( ( XFillBackgroundItem
&)rSet
.Get(XATTR_FILLBACKGROUND
) );
244 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
245 aCtlPreview
.Invalidate();
248 // -----------------------------------------------------------------------
250 int SvxHatchTabPage::DeactivatePage( SfxItemSet
* _pSet
)
252 if ( CheckChanges_Impl() == -1L )
256 FillItemSet( *_pSet
);
261 // -----------------------------------------------------------------------
263 long SvxHatchTabPage::CheckChanges_Impl()
265 if( aMtrDistance
.GetText() != aMtrDistance
.GetSavedValue() ||
266 aMtrAngle
.GetText() != aMtrAngle
.GetSavedValue() ||
267 aLbLineType
.GetSelectEntryPos() != aLbLineType
.GetSavedValue() ||
268 aLbLineColor
.GetSelectEntryPos() != aLbLineColor
.GetSavedValue() ||
269 aLbHatchings
.GetSelectEntryPos() != aLbHatchings
.GetSavedValue() )
271 ResMgr
& rMgr
= CUI_MGR();
272 Image aWarningBoxImage
= WarningBox::GetStandardImage();
273 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
274 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
275 AbstractSvxMessDialog
* aMessDlg
= pFact
->CreateSvxMessDialog( DLGWIN
, RID_SVXDLG_MESSBOX
,
276 SVX_RESSTR( RID_SVXSTR_HATCH
),
277 CUI_RESSTR( RID_SVXSTR_ASK_CHANGE_HATCH
),
279 DBG_ASSERT(aMessDlg
, "Dialogdiet fail!");//CHINA001
280 aMessDlg
->SetButtonText( MESS_BTN_1
, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1,
281 String( ResId( RID_SVXSTR_CHANGE
, rMgr
) ) );
282 aMessDlg
->SetButtonText( MESS_BTN_2
, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2,
283 String( ResId( RID_SVXSTR_ADD
, rMgr
) ) );
285 short nRet
= aMessDlg
->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
289 case RET_BTN_1
: // Aendern
291 ClickModifyHdl_Impl( this );
295 case RET_BTN_2
: // Hinzufuegen
297 ClickAddHdl_Impl( this );
302 // return( -1L ); <-- wuerde die Seite nicht verlassen
304 // return( sal_True ); // Abbruch
306 delete aMessDlg
; //add by CHINA001
309 sal_uInt16 nPos
= aLbHatchings
.GetSelectEntryPos();
310 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
315 // -----------------------------------------------------------------------
317 sal_Bool
SvxHatchTabPage::FillItemSet( SfxItemSet
& rSet
)
319 if( *pDlgType
== 0 && *pbAreaTP
== sal_False
) // Flaechen-Dialog
321 if( *pPageType
== PT_HATCH
)
323 // CheckChanges(); <-- doppelte Abfrage ?
325 XHatch
* pXHatch
= NULL
;
327 sal_uInt16 nPos
= aLbHatchings
.GetSelectEntryPos();
328 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
330 pXHatch
= new XHatch( pHatchingList
->GetHatch( nPos
)->GetHatch() );
331 aString
= aLbHatchings
.GetSelectEntry();
333 // Farbverlauf wurde (unbekannt) uebergeben
336 pXHatch
= new XHatch( aLbLineColor
.GetSelectEntryColor(),
337 (XHatchStyle
) aLbLineType
.GetSelectEntryPos(),
338 GetCoreValue( aMtrDistance
, ePoolUnit
),
339 static_cast<long>(aMtrAngle
.GetValue() * 10) );
341 DBG_ASSERT( pXHatch
, "XHatch konnte nicht erzeugt werden" );
342 rSet
.Put( XFillStyleItem( XFILL_HATCH
) );
343 rSet
.Put( XFillHatchItem( aString
, *pXHatch
) );
351 // -----------------------------------------------------------------------
353 void SvxHatchTabPage::Reset( const SfxItemSet
& rSet
)
355 // aLbHatchings.SelectEntryPos( 0 );
356 ChangeHatchHdl_Impl( this );
358 // Status der Buttons ermitteln
359 if( pHatchingList
->Count() )
367 aBtnModify
.Disable();
368 aBtnDelete
.Disable();
372 rXFSet
.Put ( ( XFillColorItem
& ) rSet
.Get(XATTR_FILLCOLOR
) );
373 rXFSet
.Put ( ( XFillBackgroundItem
&)rSet
.Get(XATTR_FILLBACKGROUND
) );
374 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
375 aCtlPreview
.Invalidate();
378 // -----------------------------------------------------------------------
380 SfxTabPage
* SvxHatchTabPage::Create( Window
* pWindow
,
381 const SfxItemSet
& rSet
)
383 return new SvxHatchTabPage( pWindow
, rSet
);
386 //------------------------------------------------------------------------
388 IMPL_LINK( SvxHatchTabPage
, ModifiedHdl_Impl
, void *, p
)
390 if( p
== &aMtrAngle
)
392 // Setzen des Winkels im AngleControl
393 switch( aMtrAngle
.GetValue() )
395 case 135: aCtlAngle
.SetActualRP( RP_LT
); break;
396 case 90: aCtlAngle
.SetActualRP( RP_MT
); break;
397 case 45: aCtlAngle
.SetActualRP( RP_RT
); break;
398 case 180: aCtlAngle
.SetActualRP( RP_LM
); break;
399 case 0: aCtlAngle
.SetActualRP( RP_RM
); break;
400 case 225: aCtlAngle
.SetActualRP( RP_LB
); break;
401 case 270: aCtlAngle
.SetActualRP( RP_MB
); break;
402 case 315: aCtlAngle
.SetActualRP( RP_RB
); break;
403 default: aCtlAngle
.SetActualRP( RP_MM
); break;
407 XHatch
aXHatch( aLbLineColor
.GetSelectEntryColor(),
408 (XHatchStyle
) aLbLineType
.GetSelectEntryPos(),
409 GetCoreValue( aMtrDistance
, ePoolUnit
),
410 static_cast<long>(aMtrAngle
.GetValue() * 10) );
412 rXFSet
.Put( XFillHatchItem( String(), aXHatch
) );
413 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
415 aCtlPreview
.Invalidate();
420 //------------------------------------------------------------------------
422 IMPL_LINK( SvxHatchTabPage
, ChangeHatchHdl_Impl
, void *, EMPTYARG
)
424 XHatch
* pHatch
= NULL
;
425 int nPos
= aLbHatchings
.GetSelectEntryPos();
427 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
428 pHatch
= new XHatch( ( (XHatchEntry
*) pHatchingList
->GetHatch( nPos
) )->GetHatch() );
431 const SfxPoolItem
* pPoolItem
= NULL
;
432 if( SFX_ITEM_SET
== rOutAttrs
.GetItemState( GetWhich( XATTR_FILLSTYLE
), sal_True
, &pPoolItem
) )
434 if( ( XFILL_HATCH
== (XFillStyle
) ( ( const XFillStyleItem
* ) pPoolItem
)->GetValue() ) &&
435 ( SFX_ITEM_SET
== rOutAttrs
.GetItemState( GetWhich( XATTR_FILLHATCH
), sal_True
, &pPoolItem
) ) )
437 pHatch
= new XHatch( ( ( const XFillHatchItem
* ) pPoolItem
)->GetHatchValue() );
442 aLbHatchings
.SelectEntryPos( 0 );
443 nPos
= aLbHatchings
.GetSelectEntryPos();
444 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
445 pHatch
= new XHatch( ( (XHatchEntry
*) pHatchingList
->GetHatch( nPos
) )->GetHatch() );
450 aLbLineType
.SelectEntryPos(
451 sal::static_int_cast
< sal_uInt16
>( pHatch
->GetHatchStyle() ) );
452 // Wenn der Eintrag nicht in der Listbox ist, wird die Farbe
453 // temporaer hinzugenommen
454 aLbLineColor
.SetNoSelection();
455 aLbLineColor
.SelectEntry( pHatch
->GetColor() );
456 if( aLbLineColor
.GetSelectEntryCount() == 0 )
458 aLbLineColor
.InsertEntry( pHatch
->GetColor(), String() );
459 aLbLineColor
.SelectEntry( pHatch
->GetColor() );
461 SetMetricValue( aMtrDistance
, pHatch
->GetDistance(), ePoolUnit
);
462 aMtrAngle
.SetValue( pHatch
->GetAngle() / 10 );
464 // Setzen des Winkels im AngleControl
465 switch( aMtrAngle
.GetValue() )
467 case 135: aCtlAngle
.SetActualRP( RP_LT
); break;
468 case 90: aCtlAngle
.SetActualRP( RP_MT
); break;
469 case 45: aCtlAngle
.SetActualRP( RP_RT
); break;
470 case 180: aCtlAngle
.SetActualRP( RP_LM
); break;
471 case 0: aCtlAngle
.SetActualRP( RP_RM
); break;
472 case 225: aCtlAngle
.SetActualRP( RP_LB
); break;
473 case 270: aCtlAngle
.SetActualRP( RP_MB
); break;
474 case 315: aCtlAngle
.SetActualRP( RP_RB
); break;
475 default: aCtlAngle
.SetActualRP( RP_MM
); break;
480 const SfxPoolItem* pPoolItem = NULL;
481 if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLBACKGROUND ), sal_True, &pPoolItem ) )
483 rXFSet.Put ( XFillBackgroundItem( ( ( XFillBackgroundItem* )pPoolItem)->GetValue() ) );
484 if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), sal_True, &pPoolItem ) )
486 Color aColor( ( ( const XFillColorItem* ) pPoolItem )->GetValue() );
487 rXFSet.Put( XFillColorItem( String(), aColor ) );
491 // ItemSet fuellen und an aCtlPreview weiterleiten
492 rXFSet
.Put( XFillHatchItem( String(), *pHatch
) );
493 aCtlPreview
.SetAttributes( aXFillAttr
.GetItemSet() );
495 aCtlPreview
.Invalidate();
498 aMtrDistance
.SaveValue();
499 aMtrAngle
.SaveValue();
500 aLbLineType
.SaveValue();
501 aLbLineColor
.SaveValue();
502 aLbHatchings
.SaveValue();
507 //------------------------------------------------------------------------
509 IMPL_LINK( SvxHatchTabPage
, ClickAddHdl_Impl
, void *, EMPTYARG
)
511 ResMgr
& rMgr
= CUI_MGR();
512 String
aNewName( SVX_RES( RID_SVXSTR_HATCH
) );
513 String
aDesc( CUI_RES( RID_SVXSTR_DESC_HATCH
) );
516 long nCount
= pHatchingList
->Count();
518 sal_Bool bDifferent
= sal_False
;
523 aName
+= sal_Unicode(' ');
524 aName
+= UniString::CreateFromInt32( j
++ );
525 bDifferent
= sal_True
;
527 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
528 if( aName
== pHatchingList
->GetHatch( i
)->GetName() )
529 bDifferent
= sal_False
;
532 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
533 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
534 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( DLGWIN
, aName
, aDesc
);
535 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
536 WarningBox
* pWarnBox
= NULL
;
537 sal_uInt16 nError
= RID_SVXSTR_WARN_NAME_DUPLICATE
;
539 while( pDlg
->Execute() == RET_OK
)
541 pDlg
->GetName( aName
);
543 bDifferent
= sal_True
;
545 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
546 if( aName
== pHatchingList
->GetHatch( i
)->GetName() )
547 bDifferent
= sal_False
;
556 pWarnBox
= new WarningBox( DLGWIN
,
557 WinBits( WB_OK_CANCEL
),
558 String( ResId( nError
, rMgr
) ) );
559 pWarnBox
->SetHelpId( HID_WARN_NAME_DUPLICATE
);
562 if( pWarnBox
->Execute() != RET_OK
)
565 //Rectangle aDlgRect( pDlg->GetPosPixel(), pDlg->GetSizePixel() );
571 XHatch
aXHatch( aLbLineColor
.GetSelectEntryColor(),
572 (XHatchStyle
) aLbLineType
.GetSelectEntryPos(),
573 GetCoreValue( aMtrDistance
, ePoolUnit
),
574 static_cast<long>(aMtrAngle
.GetValue() * 10) );
575 XHatchEntry
* pEntry
= new XHatchEntry( aXHatch
, aName
);
577 pHatchingList
->Insert( pEntry
, nCount
);
579 aLbHatchings
.Append( pEntry
);
581 aLbHatchings
.SelectEntryPos( aLbHatchings
.GetEntryCount() - 1 );
584 // hack: #31355# W.P.
585 Rectangle
aRect( aLbHatchings
.GetPosPixel(), aLbHatchings
.GetSizePixel() );
586 if( sal_True
) { // ??? overlapped with pDlg
589 //aLbHatchings.Invalidate();
593 // Flag fuer modifiziert setzen
594 *pnHatchingListState
|= CT_MODIFIED
;
596 ChangeHatchHdl_Impl( this );
599 // Status der Buttons ermitteln
600 if( pHatchingList
->Count() )
609 //------------------------------------------------------------------------
611 IMPL_LINK( SvxHatchTabPage
, ClickModifyHdl_Impl
, void *, EMPTYARG
)
613 sal_uInt16 nPos
= aLbHatchings
.GetSelectEntryPos();
615 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
617 ResMgr
& rMgr
= CUI_MGR();
618 String
aNewName( SVX_RES( RID_SVXSTR_HATCH
) );
619 String
aDesc( CUI_RES( RID_SVXSTR_DESC_HATCH
) );
620 String
aName( pHatchingList
->GetHatch( nPos
)->GetName() );
621 String aOldName
= aName
;
623 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
624 DBG_ASSERT(pFact
, "Dialogdiet fail!");//CHINA001
625 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( DLGWIN
, aName
, aDesc
);
626 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
628 long nCount
= pHatchingList
->Count();
629 sal_Bool bDifferent
= sal_False
;
630 sal_Bool bLoop
= sal_True
;
631 while( bLoop
&& pDlg
->Execute() == RET_OK
)
633 pDlg
->GetName( aName
);
634 bDifferent
= sal_True
;
636 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
638 if( aName
== pHatchingList
->GetHatch( i
)->GetName() &&
640 bDifferent
= sal_False
;
646 XHatch
aXHatch( aLbLineColor
.GetSelectEntryColor(),
647 (XHatchStyle
) aLbLineType
.GetSelectEntryPos(),
648 GetCoreValue( aMtrDistance
, ePoolUnit
),
649 static_cast<long>(aMtrAngle
.GetValue() * 10) );
651 XHatchEntry
* pEntry
= new XHatchEntry( aXHatch
, aName
);
653 delete pHatchingList
->Replace( pEntry
, nPos
);
655 aLbHatchings
.Modify( pEntry
, nPos
);
657 aLbHatchings
.SelectEntryPos( nPos
);
659 // Werte sichern fuer Changes-Erkennung ( -> Methode )
660 aMtrDistance
.SaveValue();
661 aMtrAngle
.SaveValue();
662 aLbLineType
.SaveValue();
663 aLbLineColor
.SaveValue();
664 aLbHatchings
.SaveValue();
666 // Flag fuer modifiziert setzen
667 *pnHatchingListState
|= CT_MODIFIED
;
671 WarningBox
aBox( DLGWIN
, WinBits( WB_OK
),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE
, rMgr
) ) );
672 aBox
.SetHelpId( HID_WARN_NAME_DUPLICATE
);
681 //------------------------------------------------------------------------
683 IMPL_LINK( SvxHatchTabPage
, ClickDeleteHdl_Impl
, void *, EMPTYARG
)
685 sal_uInt16 nPos
= aLbHatchings
.GetSelectEntryPos();
687 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
689 QueryBox
aQueryBox( DLGWIN
, WinBits( WB_YES_NO
| WB_DEF_NO
),
690 String( CUI_RES( RID_SVXSTR_ASK_DEL_HATCH
) ) );
692 if( aQueryBox
.Execute() == RET_YES
)
694 delete pHatchingList
->Remove( nPos
);
695 aLbHatchings
.RemoveEntry( nPos
);
696 aLbHatchings
.SelectEntryPos( 0 );
698 aCtlPreview
.Invalidate();
700 ChangeHatchHdl_Impl( this );
702 // Flag fuer modifiziert setzen
703 *pnHatchingListState
|= CT_MODIFIED
;
706 // Status der Buttons ermitteln
707 if( !pHatchingList
->Count() )
709 aBtnModify
.Disable();
710 aBtnDelete
.Disable();
716 // -----------------------------------------------------------------------
718 IMPL_LINK( SvxHatchTabPage
, ClickLoadHdl_Impl
, void *, EMPTYARG
)
720 ResMgr
& rMgr
= CUI_MGR();
721 sal_uInt16 nReturn
= RET_YES
;
723 if ( *pnHatchingListState
& CT_MODIFIED
)
725 nReturn
= WarningBox( DLGWIN
, WinBits( WB_YES_NO_CANCEL
),
726 String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE
, rMgr
) ) ).Execute();
728 if ( nReturn
== RET_YES
)
729 pHatchingList
->Save();
732 if ( nReturn
!= RET_CANCEL
)
734 ::sfx2::FileDialogHelper
aDlg(
735 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
737 String
aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soh" ) );
738 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
739 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
740 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
742 if( aDlg
.Execute() == ERRCODE_NONE
)
744 INetURLObject
aURL( aDlg
.GetPath() );
745 INetURLObject
aPathURL( aURL
);
747 aPathURL
.removeSegment();
748 aPathURL
.removeFinalSlash();
751 XHatchList
* pHatchList
= new XHatchList( aPathURL
.GetMainURL( INetURLObject::NO_DECODE
), pXPool
);
752 pHatchList
->SetName( aURL
.getName() );
753 if( pHatchList
->Load() )
757 // Pruefen, ob Tabelle geloescht werden darf:
758 if( pHatchingList
!= ( (SvxAreaTabDialog
*) DLGWIN
)->GetHatchingList() )
759 delete pHatchingList
;
761 pHatchingList
= pHatchList
;
762 ( (SvxAreaTabDialog
*) DLGWIN
)->SetNewHatchingList( pHatchingList
);
764 aLbHatchings
.Clear();
765 aLbHatchings
.Fill( pHatchingList
);
768 pHatchingList
->SetName( aURL
.getName() );
770 // Ermitteln (evtl. abschneiden) des Namens und in
771 // der GroupBox darstellen
772 String
aString( ResId( RID_SVXSTR_TABLE
, rMgr
) );
773 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
775 if ( aURL
.getBase().getLength() > 18 )
777 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
778 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
781 aString
+= String(aURL
.getBase());
783 // Flag fuer gewechselt setzen
784 *pnHatchingListState
|= CT_CHANGED
;
785 // Flag fuer modifiziert entfernen
786 *pnHatchingListState
&= ~CT_MODIFIED
;
790 ErrorBox( DLGWIN
, WinBits( WB_OK
),
791 String( ResId( RID_SVXSTR_READ_DATA_ERROR
, rMgr
) ) ).Execute();
795 // Status der Buttons ermitteln
796 if ( pHatchingList
->Count() )
804 aBtnModify
.Disable();
805 aBtnDelete
.Disable();
811 // -----------------------------------------------------------------------
813 IMPL_LINK( SvxHatchTabPage
, ClickSaveHdl_Impl
, void *, EMPTYARG
)
815 ::sfx2::FileDialogHelper
aDlg(
816 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE
, 0 );
817 String
aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soh" ) );
818 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
820 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
821 DBG_ASSERT( aFile
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
823 if( pHatchingList
->GetName().Len() )
825 aFile
.Append( pHatchingList
->GetName() );
827 if( !aFile
.getExtension().getLength() )
828 aFile
.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "soh" ) ) );
831 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
832 if ( aDlg
.Execute() == ERRCODE_NONE
)
834 INetURLObject
aURL( aDlg
.GetPath() );
835 INetURLObject
aPathURL( aURL
);
837 aPathURL
.removeSegment();
838 aPathURL
.removeFinalSlash();
840 pHatchingList
->SetName( aURL
.getName() );
841 pHatchingList
->SetPath( aPathURL
.GetMainURL( INetURLObject::NO_DECODE
) );
843 if( pHatchingList
->Save() )
845 // Ermitteln (evtl. abschneiden) des Namens und in
846 // der GroupBox darstellen
847 String
aString( CUI_RES( RID_SVXSTR_TABLE
) );
848 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
850 if ( aURL
.getBase().getLength() > 18 )
852 aString
+= String(aURL
.getBase()).Copy( 0, 15 );
853 aString
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
856 aString
+= String(aURL
.getBase());
858 // Flag fuer gespeichert setzen
859 *pnHatchingListState
|= CT_SAVED
;
860 // Flag fuer modifiziert entfernen
861 *pnHatchingListState
&= ~CT_MODIFIED
;
865 ErrorBox( DLGWIN
, WinBits( WB_OK
),
866 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR
) ) ).Execute();
873 //------------------------------------------------------------------------
875 void SvxHatchTabPage::PointChanged( Window
* pWindow
, RECT_POINT eRcPt
)
877 if( pWindow
== &aCtlAngle
)
881 case RP_LT
: aMtrAngle
.SetValue( 135 ); break;
882 case RP_MT
: aMtrAngle
.SetValue( 90 ); break;
883 case RP_RT
: aMtrAngle
.SetValue( 45 ); break;
884 case RP_LM
: aMtrAngle
.SetValue( 180 ); break;
885 case RP_RM
: aMtrAngle
.SetValue( 0 ); break;
886 case RP_LB
: aMtrAngle
.SetValue( 225 ); break;
887 case RP_MB
: aMtrAngle
.SetValue( 270 ); break;
888 case RP_RB
: aMtrAngle
.SetValue( 315 ); break;
891 ModifiedHdl_Impl( this );
896 void SvxHatchTabPage::DataChanged( const DataChangedEvent
& rDCEvt
)
898 if ( ( rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && ( rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
899 aCtlPreview
.SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST
: OUTPUT_DRAWMODE_COLOR
);
901 SvxTabPage::DataChanged( rDCEvt
);