xref: /AOO41X/main/cui/source/tabpages/tphatch.cxx (revision 3ce09a58b0d6873449cda31e55c66dba2dbc8f7f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <tools/shl.hxx>
29 #include <tools/urlobj.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <unotools/pathoptions.hxx>
32 #include <sfx2/app.hxx>
33 #include <sfx2/module.hxx>
34 #include <sfx2/filedlghelper.hxx>
35 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
36 
37 #define _SVX_TPHATCH_CXX
38 
39 #include <cuires.hrc>
40 #include "tabarea.hrc"
41 //#include "dlgname.hrc"
42 #include "helpid.hrc"
43 #include "svx/xattr.hxx"
44 #include <svx/xpool.hxx>
45 #include <svx/xtable.hxx>
46 #include "svx/drawitem.hxx"
47 #include "cuitabarea.hxx"
48 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx"
49 #include <svx/svxdlg.hxx> //CHINA001
50 #include <dialmgr.hxx>
51 #include "svx/dlgutil.hxx"
52 #include <svx/dialmgr.hxx>
53 #include "paragrph.hrc"
54 #include <svx/dialogs.hrc>
55 
56 #define DLGWIN this->GetParent()->GetParent()
57 
58 #define BITMAP_WIDTH  32
59 #define BITMAP_HEIGHT 12
60 
61 /*************************************************************************
62 |*
63 |*  Dialog zum Aendern und Definieren der Schraffuren
64 |*
65 \************************************************************************/
66 
SvxHatchTabPage(Window * pParent,const SfxItemSet & rInAttrs)67 SvxHatchTabPage::SvxHatchTabPage
68 (
69     Window* pParent,
70     const SfxItemSet& rInAttrs
71 ) :
72 
73     SvxTabPage          ( pParent, CUI_RES( RID_SVXPAGE_HATCH ), rInAttrs ),
74 
75     aFtDistance         ( this, CUI_RES( FT_LINE_DISTANCE ) ),
76     aMtrDistance        ( this, CUI_RES( MTR_FLD_DISTANCE ) ),
77     aFtAngle            ( this, CUI_RES( FT_LINE_ANGLE ) ),
78     aMtrAngle           ( this, CUI_RES( MTR_FLD_ANGLE ) ),
79     aCtlAngle           ( this, CUI_RES( CTL_ANGLE ),
80                                     RP_RB, 200, 80, CS_ANGLE ),
81     aFlProp             ( this, CUI_RES( FL_PROP ) ),
82     aFtLineType         ( this, CUI_RES( FT_LINE_TYPE ) ),
83     aLbLineType         ( this, CUI_RES( LB_LINE_TYPE ) ),
84     aFtLineColor        ( this, CUI_RES( FT_LINE_COLOR ) ),
85     aLbLineColor        ( this, CUI_RES( LB_LINE_COLOR ) ),
86     aLbHatchings        ( this, CUI_RES( LB_HATCHINGS ) ),
87     aCtlPreview         ( this, CUI_RES( CTL_PREVIEW ) ),
88     aBtnAdd             ( this, CUI_RES( BTN_ADD ) ),
89     aBtnModify          ( this, CUI_RES( BTN_MODIFY ) ),
90     aBtnDelete          ( this, CUI_RES( BTN_DELETE ) ),
91     aBtnLoad            ( this, CUI_RES( BTN_LOAD ) ),
92     aBtnSave            ( this, CUI_RES( BTN_SAVE ) ),
93 
94     rOutAttrs           ( rInAttrs ),
95     maColorTab(),
96     maHatchingList(),
97 
98     pXPool              ( (XOutdevItemPool*) rInAttrs.GetPool() ),
99     aXFStyleItem        ( XFILL_HATCH ),
100     aXHatchItem         ( String(), XHatch() ),
101     aXFillAttr          ( pXPool ),
102     rXFSet              ( aXFillAttr.GetItemSet() )
103 
104 {
105     aBtnLoad.SetModeImage( Image( CUI_RES( RID_SVXIMG_LOAD_H ) ), BMP_COLOR_HIGHCONTRAST );
106     aBtnSave.SetModeImage( Image( CUI_RES( RID_SVXIMG_SAVE_H ) ), BMP_COLOR_HIGHCONTRAST );
107 
108     FreeResource();
109 
110     // diese Page braucht ExchangeSupport
111     SetExchangeSupport();
112 
113     // Metrik einstellen
114     FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
115 
116     switch ( eFUnit )
117     {
118         case FUNIT_M:
119         case FUNIT_KM:
120             eFUnit = FUNIT_MM;
121             break;
122         default: ;//prevent warning
123     }
124     SetFieldUnit( aMtrDistance, eFUnit );
125 
126     // PoolUnit ermitteln
127     SfxItemPool* pPool = rOutAttrs.GetPool();
128     DBG_ASSERT( pPool, "Wo ist der Pool?" );
129     ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
130 
131     // Setzen des Output-Devices
132     rXFSet.Put( aXFStyleItem );
133     rXFSet.Put( aXHatchItem );
134     aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
135 
136     aLbHatchings.SetSelectHdl( LINK( this, SvxHatchTabPage, ChangeHatchHdl_Impl ) );
137 
138     Link aLink = LINK( this, SvxHatchTabPage, ModifiedHdl_Impl );
139     aMtrDistance.SetModifyHdl( aLink );
140     aMtrAngle.SetModifyHdl( aLink );
141     aLbLineType.SetSelectHdl( aLink );
142     aLbLineColor.SetSelectHdl( aLink );
143 
144     aBtnAdd.SetClickHdl( LINK( this, SvxHatchTabPage, ClickAddHdl_Impl ) );
145     aBtnModify.SetClickHdl(
146         LINK( this, SvxHatchTabPage, ClickModifyHdl_Impl ) );
147     aBtnDelete.SetClickHdl(
148         LINK( this, SvxHatchTabPage, ClickDeleteHdl_Impl ) );
149     aBtnLoad.SetClickHdl( LINK( this, SvxHatchTabPage, ClickLoadHdl_Impl ) );
150     aBtnSave.SetClickHdl( LINK( this, SvxHatchTabPage, ClickSaveHdl_Impl ) );
151 
152     aCtlPreview.SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
153 
154     aCtlPreview.SetAccessibleName(String(CUI_RES(STR_EXAMPLE)));
155     aLbHatchings.SetAccessibleName( String(CUI_RES(STR_LB_HATCHINGSTYLE)) );
156     aCtlAngle.SetAccessibleRelationMemberOf( &aFlProp );
157     aLbHatchings.SetAccessibleRelationMemberOf( &aFlProp );
158     aBtnAdd.SetAccessibleRelationMemberOf( &aFlProp );
159     aBtnModify.SetAccessibleRelationMemberOf( &aFlProp );
160     aBtnDelete.SetAccessibleRelationMemberOf( &aFlProp );
161     aLbHatchings.SetAccessibleRelationLabeledBy(&aLbHatchings);
162 }
163 
164 // -----------------------------------------------------------------------
165 
Construct()166 void SvxHatchTabPage::Construct()
167 {
168     // Farbtabelle
169     aLbLineColor.Fill( maColorTab );
170 
171     // Schraffurentabelle
172     aLbHatchings.Fill( maHatchingList );
173 }
174 
175 // -----------------------------------------------------------------------
176 
ActivatePage(const SfxItemSet & rSet)177 void SvxHatchTabPage::ActivatePage( const SfxItemSet& rSet )
178 {
179     sal_uInt16 nPos;
180     sal_uInt16 nCount;
181 
182     if( *pDlgType == 0 ) // Flaechen-Dialog
183     {
184         *pbAreaTP = sal_False;
185 
186         if( maColorTab.get() )
187         {
188             // ColorTable
189             if( *pnColorTableState & CT_CHANGED ||
190                 *pnColorTableState & CT_MODIFIED )
191             {
192                 if( *pnColorTableState & CT_CHANGED )
193                     maColorTab = ( (SvxAreaTabDialog*) DLGWIN )->GetNewColorTable();
194 
195                 // LbLineColor
196                 nPos = aLbLineColor.GetSelectEntryPos();
197                 aLbLineColor.Clear();
198                 aLbLineColor.Fill( maColorTab );
199                 nCount = aLbLineColor.GetEntryCount();
200                 if( nCount == 0 )
201                     ; // Dieser Fall sollte nicht auftreten
202                 else if( nCount <= nPos )
203                     aLbLineColor.SelectEntryPos( 0 );
204                 else
205                     aLbLineColor.SelectEntryPos( nPos );
206 
207                 ModifiedHdl_Impl( this );
208             }
209 
210             // Ermitteln (evtl. abschneiden) des Namens und in
211             // der GroupBox darstellen
212             String          aString( CUI_RES( RID_SVXSTR_TABLE ) ); aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
213             INetURLObject   aURL( maHatchingList->GetPath() );
214 
215             aURL.Append( maHatchingList->GetName() );
216             DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
217 
218             if ( aURL.getBase().getLength() > 18 )
219             {
220                 aString += String(aURL.getBase()).Copy( 0, 15 );
221                 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
222             }
223             else
224                 aString += String(aURL.getBase());
225 
226             if( *pPageType == PT_HATCH && *pPos != LISTBOX_ENTRY_NOTFOUND )
227             {
228                 aLbHatchings.SelectEntryPos( *pPos );
229             }
230             // Farben koennten geloescht worden sein
231             ChangeHatchHdl_Impl( this );
232 
233             *pPageType = PT_HATCH;
234             *pPos = LISTBOX_ENTRY_NOTFOUND;
235         }
236     }
237 
238     rXFSet.Put ( ( XFillColorItem& )    rSet.Get(XATTR_FILLCOLOR) );
239     rXFSet.Put ( ( XFillBackgroundItem&)rSet.Get(XATTR_FILLBACKGROUND) );
240     aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
241     aCtlPreview.Invalidate();
242 }
243 
244 // -----------------------------------------------------------------------
245 
DeactivatePage(SfxItemSet * _pSet)246 int SvxHatchTabPage::DeactivatePage( SfxItemSet* _pSet )
247 {
248     if ( CheckChanges_Impl() == -1L )
249         return KEEP_PAGE;
250 
251     if( _pSet )
252         FillItemSet( *_pSet );
253 
254     return LEAVE_PAGE;
255 }
256 
257 // -----------------------------------------------------------------------
258 
CheckChanges_Impl()259 long SvxHatchTabPage::CheckChanges_Impl()
260 {
261     if( aMtrDistance.GetText()           != aMtrDistance.GetSavedValue() ||
262         aMtrAngle.GetText()              != aMtrAngle.GetSavedValue() ||
263         aLbLineType.GetSelectEntryPos()  != aLbLineType.GetSavedValue()  ||
264         aLbLineColor.GetSelectEntryPos() != aLbLineColor.GetSavedValue() ||
265         aLbHatchings.GetSelectEntryPos() != aLbHatchings.GetSavedValue() )
266     {
267         ResMgr& rMgr = CUI_MGR();
268         Image aWarningBoxImage = WarningBox::GetStandardImage();
269         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
270         DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
271         AbstractSvxMessDialog* aMessDlg = pFact->CreateSvxMessDialog( DLGWIN, RID_SVXDLG_MESSBOX,
272                                                         SVX_RESSTR( RID_SVXSTR_HATCH ),
273                                                         CUI_RESSTR( RID_SVXSTR_ASK_CHANGE_HATCH ),
274                                                         &aWarningBoxImage );
275         DBG_ASSERT(aMessDlg, "Dialogdiet fail!");//CHINA001
276         aMessDlg->SetButtonText( MESS_BTN_1, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1,
277                                 String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
278         aMessDlg->SetButtonText( MESS_BTN_2, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2,
279                                 String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
280 
281         short nRet = aMessDlg->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
282 
283         switch( nRet )
284         {
285             case RET_BTN_1: // Aendern
286             {
287                 ClickModifyHdl_Impl( this );
288             }
289             break;
290 
291             case RET_BTN_2: // Hinzufuegen
292             {
293                 ClickAddHdl_Impl( this );
294             }
295             break;
296 
297             case RET_CANCEL:
298                 // return( -1L ); <-- wuerde die Seite nicht verlassen
299             break;
300             // return( sal_True ); // Abbruch
301         }
302         delete aMessDlg; //add by CHINA001
303     }
304 
305     sal_uInt16 nPos = aLbHatchings.GetSelectEntryPos();
306     if( nPos != LISTBOX_ENTRY_NOTFOUND )
307         *pPos = nPos;
308     return 0L;
309 }
310 
311 // -----------------------------------------------------------------------
312 
FillItemSet(SfxItemSet & rSet)313 sal_Bool SvxHatchTabPage::FillItemSet( SfxItemSet& rSet )
314 {
315     if( *pDlgType == 0 && *pbAreaTP == sal_False ) // Flaechen-Dialog
316     {
317         if( *pPageType == PT_HATCH )
318         {
319             // CheckChanges(); <-- doppelte Abfrage ?
320 
321             XHatch* pXHatch = NULL;
322             String  aString;
323             sal_uInt16  nPos = aLbHatchings.GetSelectEntryPos();
324             if( nPos != LISTBOX_ENTRY_NOTFOUND )
325             {
326                 pXHatch = new XHatch( maHatchingList->GetHatch( nPos )->GetHatch() );
327                 aString = aLbHatchings.GetSelectEntry();
328             }
329             // Farbverlauf wurde (unbekannt) uebergeben
330             else
331             {
332                 pXHatch = new XHatch( aLbLineColor.GetSelectEntryColor(),
333                                  (XHatchStyle) aLbLineType.GetSelectEntryPos(),
334                                  GetCoreValue( aMtrDistance, ePoolUnit ),
335                                  static_cast<long>(aMtrAngle.GetValue() * 10) );
336             }
337             DBG_ASSERT( pXHatch, "XHatch konnte nicht erzeugt werden" );
338             rSet.Put( XFillStyleItem( XFILL_HATCH ) );
339             rSet.Put( XFillHatchItem( aString, *pXHatch ) );
340 
341             delete pXHatch;
342         }
343     }
344     return sal_True;
345 }
346 
347 // -----------------------------------------------------------------------
348 
Reset(const SfxItemSet & rSet)349 void SvxHatchTabPage::Reset( const SfxItemSet& rSet )
350 {
351     // aLbHatchings.SelectEntryPos( 0 );
352     ChangeHatchHdl_Impl( this );
353 
354     // Status der Buttons ermitteln
355     if( maHatchingList.get() && maHatchingList->Count() )
356     {
357         aBtnModify.Enable();
358         aBtnDelete.Enable();
359         aBtnSave.Enable();
360     }
361     else
362     {
363         aBtnModify.Disable();
364         aBtnDelete.Disable();
365         aBtnSave.Disable();
366     }
367 
368     rXFSet.Put ( ( XFillColorItem& )    rSet.Get(XATTR_FILLCOLOR) );
369     rXFSet.Put ( ( XFillBackgroundItem&)rSet.Get(XATTR_FILLBACKGROUND) );
370     aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
371     aCtlPreview.Invalidate();
372 }
373 
374 // -----------------------------------------------------------------------
375 
Create(Window * pWindow,const SfxItemSet & rSet)376 SfxTabPage* SvxHatchTabPage::Create( Window* pWindow,
377                 const SfxItemSet& rSet )
378 {
379     return new SvxHatchTabPage( pWindow, rSet );
380 }
381 
382 //------------------------------------------------------------------------
383 
IMPL_LINK(SvxHatchTabPage,ModifiedHdl_Impl,void *,p)384 IMPL_LINK( SvxHatchTabPage, ModifiedHdl_Impl, void *, p )
385 {
386     if( p == &aMtrAngle )
387     {
388         // Setzen des Winkels im AngleControl
389         switch( aMtrAngle.GetValue() )
390         {
391             case 135: aCtlAngle.SetActualRP( RP_LT ); break;
392             case  90: aCtlAngle.SetActualRP( RP_MT ); break;
393             case  45: aCtlAngle.SetActualRP( RP_RT ); break;
394             case 180: aCtlAngle.SetActualRP( RP_LM ); break;
395             case   0: aCtlAngle.SetActualRP( RP_RM ); break;
396             case 225: aCtlAngle.SetActualRP( RP_LB ); break;
397             case 270: aCtlAngle.SetActualRP( RP_MB ); break;
398             case 315: aCtlAngle.SetActualRP( RP_RB ); break;
399             default:  aCtlAngle.SetActualRP( RP_MM ); break;
400         }
401     }
402 
403     XHatch aXHatch( aLbLineColor.GetSelectEntryColor(),
404                     (XHatchStyle) aLbLineType.GetSelectEntryPos(),
405                     GetCoreValue( aMtrDistance, ePoolUnit ),
406                     static_cast<long>(aMtrAngle.GetValue() * 10) );
407 
408     rXFSet.Put( XFillHatchItem( String(), aXHatch ) );
409     aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
410 
411     aCtlPreview.Invalidate();
412 
413     return 0L;
414 }
415 
416 //------------------------------------------------------------------------
417 
IMPL_LINK(SvxHatchTabPage,ChangeHatchHdl_Impl,void *,EMPTYARG)418 IMPL_LINK( SvxHatchTabPage, ChangeHatchHdl_Impl, void *, EMPTYARG )
419 {
420     XHatch* pHatch = NULL;
421     int nPos = aLbHatchings.GetSelectEntryPos();
422 
423     if( nPos != LISTBOX_ENTRY_NOTFOUND )
424         pHatch = new XHatch( ( (XHatchEntry*) maHatchingList->GetHatch( nPos ) )->GetHatch() );
425     else
426     {
427         const SfxPoolItem* pPoolItem = NULL;
428         if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), sal_True, &pPoolItem ) )
429         {
430             if( ( XFILL_HATCH == (XFillStyle) ( ( const XFillStyleItem* ) pPoolItem )->GetValue() ) &&
431                 ( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLHATCH ), sal_True, &pPoolItem ) ) )
432             {
433                 pHatch = new XHatch( ( ( const XFillHatchItem* ) pPoolItem )->GetHatchValue() );
434             }
435         }
436         if( !pHatch )
437         {
438             aLbHatchings.SelectEntryPos( 0 );
439             nPos = aLbHatchings.GetSelectEntryPos();
440             if( nPos != LISTBOX_ENTRY_NOTFOUND )
441                 pHatch = new XHatch( ( (XHatchEntry*) maHatchingList->GetHatch( nPos ) )->GetHatch() );
442         }
443     }
444     if( pHatch )
445     {
446         aLbLineType.SelectEntryPos(
447             sal::static_int_cast< sal_uInt16 >( pHatch->GetHatchStyle() ) );
448         // Wenn der Eintrag nicht in der Listbox ist, wird die Farbe
449         // temporaer hinzugenommen
450         aLbLineColor.SetNoSelection();
451         aLbLineColor.SelectEntry( pHatch->GetColor() );
452         if( aLbLineColor.GetSelectEntryCount() == 0 )
453         {
454             aLbLineColor.InsertEntry( pHatch->GetColor(), String() );
455             aLbLineColor.SelectEntry( pHatch->GetColor() );
456         }
457         SetMetricValue( aMtrDistance, pHatch->GetDistance(), ePoolUnit );
458         aMtrAngle.SetValue( pHatch->GetAngle() / 10 );
459 
460         // Setzen des Winkels im AngleControl
461         switch( aMtrAngle.GetValue() )
462         {
463             case 135: aCtlAngle.SetActualRP( RP_LT ); break;
464             case  90: aCtlAngle.SetActualRP( RP_MT ); break;
465             case  45: aCtlAngle.SetActualRP( RP_RT ); break;
466             case 180: aCtlAngle.SetActualRP( RP_LM ); break;
467             case   0: aCtlAngle.SetActualRP( RP_RM ); break;
468             case 225: aCtlAngle.SetActualRP( RP_LB ); break;
469             case 270: aCtlAngle.SetActualRP( RP_MB ); break;
470             case 315: aCtlAngle.SetActualRP( RP_RB ); break;
471             default:  aCtlAngle.SetActualRP( RP_MM ); break;
472         }
473 
474         // Backgroundcolor
475         /*
476         const SfxPoolItem* pPoolItem = NULL;
477         if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLBACKGROUND ), sal_True, &pPoolItem ) )
478         {
479             rXFSet.Put ( XFillBackgroundItem( ( ( XFillBackgroundItem* )pPoolItem)->GetValue() ) );
480             if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), sal_True, &pPoolItem ) )
481             {
482                 Color aColor( ( ( const XFillColorItem* ) pPoolItem )->GetValue() );
483                 rXFSet.Put( XFillColorItem( String(), aColor ) );
484             }
485         }
486         */
487         // ItemSet fuellen und an aCtlPreview weiterleiten
488         rXFSet.Put( XFillHatchItem( String(), *pHatch ) );
489         aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
490 
491         aCtlPreview.Invalidate();
492         delete pHatch;
493     }
494     aMtrDistance.SaveValue();
495     aMtrAngle.SaveValue();
496     aLbLineType.SaveValue();
497     aLbLineColor.SaveValue();
498     aLbHatchings.SaveValue();
499 
500     return 0L;
501 }
502 
503 //------------------------------------------------------------------------
504 
IMPL_LINK(SvxHatchTabPage,ClickAddHdl_Impl,void *,EMPTYARG)505 IMPL_LINK( SvxHatchTabPage, ClickAddHdl_Impl, void *, EMPTYARG )
506 {
507     ResMgr& rMgr = CUI_MGR();
508     String aNewName( SVX_RES( RID_SVXSTR_HATCH ) );
509     String aDesc( CUI_RES( RID_SVXSTR_DESC_HATCH ) );
510     String aName;
511 
512     long nCount = maHatchingList.get() ? maHatchingList->Count() : 0;
513     long j = 1;
514     sal_Bool bDifferent = sal_False;
515 
516     while( !bDifferent )
517     {
518         aName  = aNewName;
519         aName += sal_Unicode(' ');
520         aName += UniString::CreateFromInt32( j++ );
521         bDifferent = sal_True;
522 
523         for( long i = 0; i < nCount && bDifferent; i++ )
524             if( aName == maHatchingList->GetHatch( i )->GetName() )
525                 bDifferent = sal_False;
526     }
527 
528     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
529     DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
530     AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
531     DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
532     WarningBox*    pWarnBox = NULL;
533     sal_uInt16         nError   = RID_SVXSTR_WARN_NAME_DUPLICATE;
534 
535     while( pDlg->Execute() == RET_OK )
536     {
537         pDlg->GetName( aName );
538 
539         bDifferent = sal_True;
540 
541         for( long i = 0; i < nCount && bDifferent; i++ )
542             if( aName == maHatchingList->GetHatch( i )->GetName() )
543                 bDifferent = sal_False;
544 
545         if( bDifferent ) {
546             nError = 0;
547             break;
548         }
549 
550         if( !pWarnBox )
551         {
552             pWarnBox = new WarningBox( DLGWIN,
553                                        WinBits( WB_OK_CANCEL ),
554                                        String( ResId( nError, rMgr ) ) );
555             pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
556         }
557 
558         if( pWarnBox->Execute() != RET_OK )
559             break;
560     }
561     //Rectangle aDlgRect( pDlg->GetPosPixel(), pDlg->GetSizePixel() );
562     delete pDlg;
563     delete pWarnBox;
564 
565     if( !nError )
566     {
567         XHatch aXHatch( aLbLineColor.GetSelectEntryColor(),
568                         (XHatchStyle) aLbLineType.GetSelectEntryPos(),
569                         GetCoreValue( aMtrDistance, ePoolUnit ),
570                         static_cast<long>(aMtrAngle.GetValue() * 10) );
571         XHatchEntry* pEntry = new XHatchEntry( aXHatch, aName );
572 
573         maHatchingList->Insert( pEntry, nCount );
574 
575         aLbHatchings.Append( *pEntry, maHatchingList->GetUiBitmap( nCount ) );
576 
577         aLbHatchings.SelectEntryPos( aLbHatchings.GetEntryCount() - 1 );
578 
579 #ifdef WNT
580         // hack: #31355# W.P.
581         Rectangle aRect( aLbHatchings.GetPosPixel(), aLbHatchings.GetSizePixel() );
582         if( sal_True ) {                // ??? overlapped with pDlg
583                                     // and srolling
584             Invalidate( aRect );
585             //aLbHatchings.Invalidate();
586         }
587 #endif
588 
589         // Flag fuer modifiziert setzen
590         *pnHatchingListState |= CT_MODIFIED;
591 
592         ChangeHatchHdl_Impl( this );
593     }
594 
595     // Status der Buttons ermitteln
596     if( maHatchingList.get() && maHatchingList->Count() )
597     {
598         aBtnModify.Enable();
599         aBtnDelete.Enable();
600         aBtnSave.Enable();
601     }
602     return 0L;
603 }
604 
605 //------------------------------------------------------------------------
606 
IMPL_LINK(SvxHatchTabPage,ClickModifyHdl_Impl,void *,EMPTYARG)607 IMPL_LINK( SvxHatchTabPage, ClickModifyHdl_Impl, void *, EMPTYARG )
608 {
609     sal_uInt16 nPos = aLbHatchings.GetSelectEntryPos();
610 
611     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
612     {
613         ResMgr& rMgr = CUI_MGR();
614         String aNewName( SVX_RES( RID_SVXSTR_HATCH ) );
615         String aDesc( CUI_RES( RID_SVXSTR_DESC_HATCH ) );
616         String aName( maHatchingList->GetHatch( nPos )->GetName() );
617         String aOldName = aName;
618 
619         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
620         DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
621         AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
622         DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
623 
624         long nCount = maHatchingList.get() ? maHatchingList->Count() : 0;
625         sal_Bool bDifferent = sal_False;
626         sal_Bool bLoop = sal_True;
627         while( bLoop && pDlg->Execute() == RET_OK )
628         {
629             pDlg->GetName( aName );
630             bDifferent = sal_True;
631 
632             for( long i = 0; i < nCount && bDifferent; i++ )
633             {
634                 if( aName == maHatchingList->GetHatch( i )->GetName() &&
635                     aName != aOldName )
636                     bDifferent = sal_False;
637             }
638 
639             if( bDifferent )
640             {
641                 bLoop = sal_False;
642                 XHatch aXHatch( aLbLineColor.GetSelectEntryColor(),
643                                 (XHatchStyle) aLbLineType.GetSelectEntryPos(),
644                                  GetCoreValue( aMtrDistance, ePoolUnit ),
645                                 static_cast<long>(aMtrAngle.GetValue() * 10) );
646 
647                 XHatchEntry* pEntry = new XHatchEntry( aXHatch, aName );
648 
649                 delete maHatchingList->Replace( pEntry, nPos );
650 
651                 aLbHatchings.Modify( *pEntry, nPos, maHatchingList->GetUiBitmap( nPos ) );
652 
653                 aLbHatchings.SelectEntryPos( nPos );
654 
655                 // Werte sichern fuer Changes-Erkennung ( -> Methode )
656                 aMtrDistance.SaveValue();
657                 aMtrAngle.SaveValue();
658                 aLbLineType.SaveValue();
659                 aLbLineColor.SaveValue();
660                 aLbHatchings.SaveValue();
661 
662                 // Flag fuer modifiziert setzen
663                 *pnHatchingListState |= CT_MODIFIED;
664             }
665             else
666             {
667                 WarningBox aBox( DLGWIN, WinBits( WB_OK ),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
668                 aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
669                 aBox.Execute();
670             }
671         }
672         delete( pDlg );
673     }
674     return 0L;
675 }
676 
677 //------------------------------------------------------------------------
678 
IMPL_LINK(SvxHatchTabPage,ClickDeleteHdl_Impl,void *,EMPTYARG)679 IMPL_LINK( SvxHatchTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG )
680 {
681     sal_uInt16 nPos = aLbHatchings.GetSelectEntryPos();
682 
683     if( nPos != LISTBOX_ENTRY_NOTFOUND )
684     {
685         QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ),
686             String( CUI_RES( RID_SVXSTR_ASK_DEL_HATCH ) ) );
687 
688         if( aQueryBox.Execute() == RET_YES )
689         {
690             delete maHatchingList->Remove( nPos );
691             aLbHatchings.RemoveEntry( nPos );
692             aLbHatchings.SelectEntryPos( 0 );
693 
694             aCtlPreview.Invalidate();
695 
696             ChangeHatchHdl_Impl( this );
697 
698             // Flag fuer modifiziert setzen
699             *pnHatchingListState |= CT_MODIFIED;
700         }
701     }
702     // Status der Buttons ermitteln
703     if( !maHatchingList.get() || !maHatchingList->Count() )
704     {
705         aBtnModify.Disable();
706         aBtnDelete.Disable();
707         aBtnSave.Disable();
708     }
709     return 0L;
710 }
711 
712 // -----------------------------------------------------------------------
713 
IMPL_LINK(SvxHatchTabPage,ClickLoadHdl_Impl,void *,EMPTYARG)714 IMPL_LINK( SvxHatchTabPage, ClickLoadHdl_Impl, void *, EMPTYARG )
715 {
716     ResMgr& rMgr = CUI_MGR();
717     sal_uInt16 nReturn = RET_YES;
718 
719     if ( *pnHatchingListState & CT_MODIFIED )
720     {
721         nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ),
722             String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
723 
724         if ( nReturn == RET_YES )
725             maHatchingList->Save();
726     }
727 
728     if ( nReturn != RET_CANCEL )
729     {
730         ::sfx2::FileDialogHelper aDlg(
731             com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
732             0 );
733         String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soh" ) );
734         aDlg.AddFilter( aStrFilterType, aStrFilterType );
735         INetURLObject aFile( SvtPathOptions().GetPalettePath() );
736         aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
737 
738         if( aDlg.Execute() == ERRCODE_NONE )
739         {
740             INetURLObject aURL( aDlg.GetPath() );
741             INetURLObject aPathURL( aURL );
742 
743             aPathURL.removeSegment();
744             aPathURL.removeFinalSlash();
745 
746             // Liste speichern
747             XHatchListSharedPtr aHatchList(XPropertyListFactory::CreateSharedXHatchList(aPathURL.GetMainURL(INetURLObject::NO_DECODE)));
748             aHatchList->SetName( aURL.getName() );
749             if( aHatchList->Load() )
750             {
751                 if( aHatchList.get() )
752                 {
753                     maHatchingList = aHatchList;
754                     ( (SvxAreaTabDialog*) DLGWIN )->SetNewHatchingList( maHatchingList );
755 
756                     aLbHatchings.Clear();
757                     aLbHatchings.Fill( maHatchingList );
758                     Reset( rOutAttrs );
759 
760                     maHatchingList->SetName( aURL.getName() );
761 
762                     // Ermitteln (evtl. abschneiden) des Namens und in
763                     // der GroupBox darstellen
764                     String aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
765                     aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
766 
767                     if ( aURL.getBase().getLength() > 18 )
768                     {
769                         aString += String(aURL.getBase()).Copy( 0, 15 );
770                         aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
771                     }
772                     else
773                         aString += String(aURL.getBase());
774 
775                     // Flag fuer gewechselt setzen
776                     *pnHatchingListState |= CT_CHANGED;
777                     // Flag fuer modifiziert entfernen
778                     *pnHatchingListState &= ~CT_MODIFIED;
779                 }
780             }
781             else
782                 ErrorBox( DLGWIN, WinBits( WB_OK ),
783                     String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
784         }
785     }
786 
787     // Status der Buttons ermitteln
788     if ( maHatchingList.get() && maHatchingList->Count() )
789     {
790         aBtnModify.Enable();
791         aBtnDelete.Enable();
792         aBtnSave.Enable();
793     }
794     else
795     {
796         aBtnModify.Disable();
797         aBtnDelete.Disable();
798         aBtnSave.Disable();
799     }
800     return 0L;
801 }
802 
803 // -----------------------------------------------------------------------
804 
IMPL_LINK(SvxHatchTabPage,ClickSaveHdl_Impl,void *,EMPTYARG)805 IMPL_LINK( SvxHatchTabPage, ClickSaveHdl_Impl, void *, EMPTYARG )
806 {
807     ::sfx2::FileDialogHelper aDlg(
808         com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
809     String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.soh" ) );
810     aDlg.AddFilter( aStrFilterType, aStrFilterType );
811 
812     INetURLObject aFile( SvtPathOptions().GetPalettePath() );
813     DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
814 
815     if( maHatchingList.get() && maHatchingList->GetName().Len() )
816     {
817         aFile.Append( maHatchingList->GetName() );
818 
819         if( !aFile.getExtension().getLength() )
820             aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "soh" ) ) );
821     }
822 
823     aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
824     if ( aDlg.Execute() == ERRCODE_NONE )
825     {
826         INetURLObject aURL( aDlg.GetPath() );
827         INetURLObject aPathURL( aURL );
828 
829         aPathURL.removeSegment();
830         aPathURL.removeFinalSlash();
831 
832         maHatchingList->SetName( aURL.getName() );
833         maHatchingList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
834 
835         if( maHatchingList->Save() )
836         {
837             // Ermitteln (evtl. abschneiden) des Namens und in
838             // der GroupBox darstellen
839             String aString( CUI_RES( RID_SVXSTR_TABLE ) );
840             aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
841 
842             if ( aURL.getBase().getLength() > 18 )
843             {
844                 aString += String(aURL.getBase()).Copy( 0, 15 );
845                 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
846             }
847             else
848                 aString += String(aURL.getBase());
849 
850             // Flag fuer gespeichert setzen
851             *pnHatchingListState |= CT_SAVED;
852             // Flag fuer modifiziert entfernen
853             *pnHatchingListState &= ~CT_MODIFIED;
854         }
855         else
856         {
857             ErrorBox( DLGWIN, WinBits( WB_OK ),
858                 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
859         }
860     }
861 
862     return 0L;
863 }
864 
865 //------------------------------------------------------------------------
866 
PointChanged(Window * pWindow,RECT_POINT eRcPt)867 void SvxHatchTabPage::PointChanged( Window* pWindow, RECT_POINT eRcPt )
868 {
869     if( pWindow == &aCtlAngle )
870     {
871         switch( eRcPt )
872         {
873             case RP_LT: aMtrAngle.SetValue( 135 ); break;
874             case RP_MT: aMtrAngle.SetValue( 90 );  break;
875             case RP_RT: aMtrAngle.SetValue( 45 );  break;
876             case RP_LM: aMtrAngle.SetValue( 180 ); break;
877             case RP_RM: aMtrAngle.SetValue( 0 );   break;
878             case RP_LB: aMtrAngle.SetValue( 225 ); break;
879             case RP_MB: aMtrAngle.SetValue( 270 ); break;
880             case RP_RB: aMtrAngle.SetValue( 315 ); break;
881             case RP_MM: break;
882         }
883         ModifiedHdl_Impl( this );
884     }
885 }
886 
887 
DataChanged(const DataChangedEvent & rDCEvt)888 void SvxHatchTabPage::DataChanged( const DataChangedEvent& rDCEvt )
889 {
890     if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
891         aCtlPreview.SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
892 
893     SvxTabPage::DataChanged( rDCEvt );
894 }
895 
896