xref: /trunk/main/cui/source/tabpages/tplnedef.cxx (revision 910823ae669d9158f41049c6cb73cb1e2d268347)
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_TPLNEDEF_CXX
38 
39 #include <cuires.hrc>
40 #include "tabline.hrc"
41 //#include "dlgname.hrc"
42 #include "helpid.hrc"
43 
44 #include "svx/xattr.hxx"
45 #include <svx/xpool.hxx>
46 #include <svx/xtable.hxx>
47 
48 #include "svx/drawitem.hxx"
49 #include "cuitabline.hxx"
50 #include "defdlgname.hxx" //CHINA001 #include "dlgname.hxx"
51 #include <svx/svxdlg.hxx> //CHINA001
52 #include <dialmgr.hxx>
53 #include "svx/dlgutil.hxx"
54 #include <svx/dialmgr.hxx>
55 #include <svx/dialogs.hrc>
56 
57 #define DLGWIN this->GetParent()->GetParent()
58 
59 #define BITMAP_WIDTH   32
60 #define BITMAP_HEIGHT  12
61 #define XOUT_WIDTH    150
62 
63 /*************************************************************************
64 |*
65 |*  Dialog zum Definieren von Linienstilen
66 |*
67 \************************************************************************/
68 
69 SvxLineDefTabPage::SvxLineDefTabPage
70 (
71     Window* pParent,
72     const SfxItemSet& rInAttrs
73 ) :
74 
75     SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_LINE_DEF ), rInAttrs ),
76 
77     aFlDefinition   ( this, CUI_RES( FL_DEFINITION ) ),
78     aFTLinestyle    ( this, CUI_RES( FT_LINESTYLE ) ),
79     aLbLineStyles   ( this, CUI_RES( LB_LINESTYLES ) ),
80     aFtType         ( this, CUI_RES( FT_TYPE ) ),
81     aLbType1        ( this, CUI_RES( LB_TYPE_1 ) ),
82     aLbType2        ( this, CUI_RES( LB_TYPE_2 ) ),
83     aFtNumber       ( this, CUI_RES( FT_NUMBER ) ),
84     aNumFldNumber1  ( this, CUI_RES( NUM_FLD_1 ) ),
85     aNumFldNumber2  ( this, CUI_RES( NUM_FLD_2 ) ),
86     aFtLength       ( this, CUI_RES( FT_LENGTH ) ),
87     aMtrLength1     ( this, CUI_RES( MTR_FLD_LENGTH_1 ) ),
88     aMtrLength2     ( this, CUI_RES( MTR_FLD_LENGTH_2 ) ),
89     aFtDistance     ( this, CUI_RES( FT_DISTANCE ) ),
90     aMtrDistance    ( this, CUI_RES( MTR_FLD_DISTANCE ) ),
91     aCbxSynchronize ( this, CUI_RES( CBX_SYNCHRONIZE ) ),
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 ) ),
97     aCtlPreview     ( this, CUI_RES( CTL_PREVIEW ) ),
98 
99     rOutAttrs       ( rInAttrs ),
100 
101     pXPool              ( (XOutdevItemPool*) rInAttrs.GetPool() ),
102     aXLStyle            ( XLINE_DASH ),
103     aXWidth             ( XOUT_WIDTH ),
104     aXDash              ( String(), XDash( XDASH_RECT, 3, 7, 2, 40, 15 ) ),
105     aXColor             ( String(), COL_BLACK ),
106     aXLineAttr          ( pXPool ),
107     rXLSet              ( aXLineAttr.GetItemSet() )
108 {
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 );
111 
112     aLbType1.SetAccessibleName(String(CUI_RES( STR_START_TYPE ) ) );
113     aLbType2.SetAccessibleName(String(CUI_RES( STR_END_TYPE ) ) );
114     aNumFldNumber1.SetAccessibleName(String(CUI_RES( STR_START_NUM ) ) );
115     aNumFldNumber2.SetAccessibleName(String(CUI_RES( STR_END_NUM ) ) );
116     aMtrLength1.SetAccessibleName(String(CUI_RES( STR_START_LENGTH ) ) );
117     aMtrLength2.SetAccessibleName(String(CUI_RES( STR_END_LENGTH ) ) );
118 
119     FreeResource();
120 
121     // diese Page braucht ExchangeSupport
122     SetExchangeSupport();
123 
124     // Metrik einstellen
125     eFUnit = GetModuleFieldUnit( rInAttrs );
126 
127     switch ( eFUnit )
128     {
129         case FUNIT_M:
130         case FUNIT_KM:
131             eFUnit = FUNIT_MM;
132             break;
133         default: ; //prevent warning
134     }
135     SetFieldUnit( aMtrDistance, eFUnit );
136     SetFieldUnit( aMtrLength1, eFUnit );
137     SetFieldUnit( aMtrLength2, eFUnit );
138 
139     // PoolUnit ermitteln
140     SfxItemPool* pPool = rOutAttrs.GetPool();
141     DBG_ASSERT( pPool, "Wo ist der Pool?" );
142     ePoolUnit = pPool->GetMetric( SID_ATTR_LINE_WIDTH );
143 
144     rXLSet.Put( aXLStyle );
145     rXLSet.Put( aXWidth );
146     rXLSet.Put( aXDash );
147     rXLSet.Put( aXColor );
148 
149     // #i34740#
150     aCtlPreview.SetLineAttributes(aXLineAttr.GetItemSet());
151 
152     aBtnAdd.SetClickHdl( LINK( this, SvxLineDefTabPage, ClickAddHdl_Impl ) );
153     aBtnModify.SetClickHdl(
154         LINK( this, SvxLineDefTabPage, ClickModifyHdl_Impl ) );
155     aBtnDelete.SetClickHdl(
156         LINK( this, SvxLineDefTabPage, ClickDeleteHdl_Impl ) );
157     aBtnLoad.SetClickHdl( LINK( this, SvxLineDefTabPage, ClickLoadHdl_Impl ) );
158     aBtnSave.SetClickHdl( LINK( this, SvxLineDefTabPage, ClickSaveHdl_Impl ) );
159 
160     aNumFldNumber1.SetModifyHdl(
161         LINK( this, SvxLineDefTabPage, ChangeNumber1Hdl_Impl ) );
162     aNumFldNumber2.SetModifyHdl(
163         LINK( this, SvxLineDefTabPage, ChangeNumber2Hdl_Impl ) );
164     aLbLineStyles.SetSelectHdl(
165         LINK( this, SvxLineDefTabPage, SelectLinestyleHdl_Impl ) );
166 
167     // #122042# switch off default adding of 'none' and 'solid' entries
168     // for this ListBox; we want to select only editable/dashed styles
169     aLbLineStyles.setAddStandardFields(false);
170 
171     // Absolut (in mm) oder Relativ (in %)
172     aCbxSynchronize.SetClickHdl(
173         LINK( this, SvxLineDefTabPage, ChangeMetricHdl_Impl ) );
174 
175     // Wenn sich etwas aendert, muss Preview upgedatet werden werden
176     Link aLink = LINK( this, SvxLineDefTabPage, SelectTypeHdl_Impl );
177     aLbType1.SetSelectHdl( aLink );
178     aLbType2.SetSelectHdl( aLink );
179     aLink = LINK( this, SvxLineDefTabPage, ChangePreviewHdl_Impl );
180     aMtrLength1.SetModifyHdl( aLink );
181     aMtrLength2.SetModifyHdl( aLink );
182     aMtrDistance.SetModifyHdl( aLink );
183 
184     pDashList = NULL;
185 
186     aBtnAdd.SetAccessibleRelationMemberOf( &aFlDefinition );
187     aBtnModify.SetAccessibleRelationMemberOf( &aFlDefinition );
188     aBtnDelete.SetAccessibleRelationMemberOf( &aFlDefinition );
189     aBtnLoad.SetAccessibleRelationMemberOf( &aFlDefinition );
190     aBtnSave.SetAccessibleRelationMemberOf( &aFlDefinition );
191 }
192 
193 
194 // -----------------------------------------------------------------------
195 
196 void SvxLineDefTabPage::Construct()
197 {
198     // Line style fill; do *not* add default fields here
199     aLbLineStyles.Fill( pDashList );
200 }
201 
202 // -----------------------------------------------------------------------
203 
204 void SvxLineDefTabPage::ActivatePage( const SfxItemSet& )
205 {
206     if( *pDlgType == 0 ) // Flaechen-Dialog
207     {
208         // ActivatePage() wird aufgerufen bevor der Dialog PageCreated() erhaelt !!!
209         if( pDashList )
210         {
211             if( *pPageType == 1 &&
212                 *pPosDashLb != LISTBOX_ENTRY_NOTFOUND )
213             {
214                 aLbLineStyles.SelectEntryPos( *pPosDashLb );
215             }
216             // Damit evtl. vorhandener Linestyle verworfen wird
217             SelectLinestyleHdl_Impl( this );
218 
219             // Ermitteln (evtl. abschneiden) des Namens und in
220             // der GroupBox darstellen
221             String          aString( CUI_RES( RID_SVXSTR_TABLE ) ); aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
222             INetURLObject   aURL( pDashList->GetPath() );
223 
224             aURL.Append( pDashList->GetName() );
225             DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
226 
227 /*          if ( aURL.getBase().Len() > 18 )
228             {
229                 aString += aURL.getBase().Copy( 0, 15 );
230                 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
231             }
232             else
233                 aString += aURL.getBase();
234 
235             aFTLinestyle.SetText( aString );
236 */
237             *pPageType = 0; // 2
238             *pPosDashLb = LISTBOX_ENTRY_NOTFOUND;
239         }
240     }
241 }
242 
243 // -----------------------------------------------------------------------
244 
245 int SvxLineDefTabPage::DeactivatePage( SfxItemSet* _pSet )
246 {
247     CheckChanges_Impl();
248 
249     if( _pSet )
250         FillItemSet( *_pSet );
251 
252     return( LEAVE_PAGE );
253 }
254 
255 // -----------------------------------------------------------------------
256 
257 void SvxLineDefTabPage::CheckChanges_Impl()
258 {
259     // wird hier benutzt, um Aenderungen NICHT zu verlieren
260     //XDashStyle eXDS;
261 
262     if( aNumFldNumber1.GetText()     != aNumFldNumber1.GetSavedValue() ||
263         aMtrLength1.GetText()        != aMtrLength1.GetSavedValue() ||
264         aLbType1.GetSelectEntryPos() != aLbType1.GetSavedValue() ||
265         aNumFldNumber2.GetText()     != aNumFldNumber2.GetSavedValue() ||
266         aMtrLength2.GetText()        != aMtrLength2.GetSavedValue() ||
267         aLbType2.GetSelectEntryPos() != aLbType2.GetSavedValue() ||
268         aMtrDistance.GetText()       != aMtrDistance.GetSavedValue() )
269     {
270         ResMgr& rMgr = CUI_MGR();
271         Image aWarningBoxImage = WarningBox::GetStandardImage();
272         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
273         DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
274         AbstractSvxMessDialog* aMessDlg = pFact->CreateSvxMessDialog( DLGWIN, RID_SVXDLG_MESSBOX,
275                                                     SVX_RESSTR( RID_SVXSTR_LINESTYLE ),
276                                                     String( ResId( RID_SVXSTR_ASK_CHANGE_LINESTYLE, rMgr ) ),
277                                                     &aWarningBoxImage );
278         DBG_ASSERT(aMessDlg, "Dialogdiet fail!");//CHINA001
279         aMessDlg->SetButtonText( MESS_BTN_1, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_1,
280                                 String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
281         aMessDlg->SetButtonText( MESS_BTN_2, //CHINA001 aMessDlg.SetButtonText( MESS_BTN_2,
282                                 String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
283 
284         short nRet = aMessDlg->Execute(); //CHINA001 short nRet = aMessDlg.Execute();
285 
286         switch( nRet )
287         {
288             case RET_BTN_1: // Aendern
289             {
290                 ClickModifyHdl_Impl( this );
291                 //aXDash = pDashList->Get( nPos )->GetDash();
292             }
293             break;
294 
295             case RET_BTN_2: // Hinzufuegen
296             {
297                 ClickAddHdl_Impl( this );
298                 //nPos = aLbLineStyles.GetSelectEntryPos();
299                 //aXDash = pDashList->Get( nPos )->GetDash();
300             }
301             break;
302 
303             case RET_CANCEL:
304             break;
305             // return( sal_True ); // Abbruch
306         }
307         delete aMessDlg; //add by CHINA001
308     }
309 
310 
311 
312     sal_uInt16 nPos = aLbLineStyles.GetSelectEntryPos();
313     if( nPos != LISTBOX_ENTRY_NOTFOUND )
314     {
315         *pPosDashLb = nPos;
316     }
317 }
318 
319 // -----------------------------------------------------------------------
320 
321 sal_Bool SvxLineDefTabPage::FillItemSet( SfxItemSet& rAttrs )
322 {
323     if( *pDlgType == 0 ) // Linien-Dialog
324     {
325         if( *pPageType == 2 )
326         {
327             //CheckChanges_Impl();
328 
329             FillDash_Impl();
330 
331             String aString( aLbLineStyles.GetSelectEntry() );
332             rAttrs.Put( XLineStyleItem( XLINE_DASH ) );
333             rAttrs.Put( XLineDashItem( aString, aDash ) );
334         }
335     }
336     return( sal_True );
337 }
338 
339 // -----------------------------------------------------------------------
340 
341 void SvxLineDefTabPage::Reset( const SfxItemSet& rAttrs )
342 {
343     if( rAttrs.GetItemState( GetWhich( XATTR_LINESTYLE ) ) != SFX_ITEM_DONTCARE )
344     {
345         XLineStyle eXLS = (XLineStyle) ( ( const XLineStyleItem& ) rAttrs.Get( GetWhich( XATTR_LINESTYLE ) ) ).GetValue();
346 
347         switch( eXLS )
348         {
349             case XLINE_NONE:
350             case XLINE_SOLID:
351                 aLbLineStyles.SelectEntryPos( 0 );
352                 break;
353 
354             case XLINE_DASH:
355             {
356                 const XLineDashItem& rDashItem = ( const XLineDashItem& ) rAttrs.Get( XATTR_LINEDASH );
357                 aDash = rDashItem.GetDashValue();
358 
359                 aLbLineStyles.SetNoSelection();
360                 aLbLineStyles.SelectEntry( rDashItem.GetName() );
361             }
362                 break;
363 
364             default:
365                 break;
366         }
367     }
368     SelectLinestyleHdl_Impl( NULL );
369 
370     // Status der Buttons ermitteln
371     if( pDashList->Count() )
372     {
373         aBtnModify.Enable();
374         aBtnDelete.Enable();
375         aBtnSave.Enable();
376     }
377     else
378     {
379         aBtnModify.Disable();
380         aBtnDelete.Disable();
381         aBtnSave.Disable();
382     }
383 }
384 
385 // -----------------------------------------------------------------------
386 
387 SfxTabPage* SvxLineDefTabPage::Create( Window* pWindow,
388                 const SfxItemSet& rOutAttrs )
389 {
390     return( new SvxLineDefTabPage( pWindow, rOutAttrs ) );
391 }
392 
393 //------------------------------------------------------------------------
394 
395 IMPL_LINK( SvxLineDefTabPage, SelectLinestyleHdl_Impl, void *, p )
396 {
397     if(pDashList->Count())
398     {
399         int nTmp = aLbLineStyles.GetSelectEntryPos();
400 
401         if(LISTBOX_ENTRY_NOTFOUND == nTmp)
402         {
403             OSL_ENSURE(false, "OOps, non-existent LineDash selected (!)");
404             nTmp = 1;
405         }
406 
407         aDash = pDashList->GetDash( nTmp )->GetDash();
408 
409         FillDialog_Impl();
410 
411         rXLSet.Put( XLineDashItem( String(), aDash ) );
412 
413         // #i34740#
414         aCtlPreview.SetLineAttributes(aXLineAttr.GetItemSet());
415 
416         aCtlPreview.Invalidate();
417 
418         // Wird erst hier gesetzt, um den Style nur dann zu uebernehmen,
419         // wenn in der ListBox ein Eintrag ausgewaehlt wurde
420         // Wenn ueber Reset() gerufen wurde ist p == NULL
421         if( p )
422             *pPageType = 2;
423     }
424     return( 0L );
425 }
426 
427 //------------------------------------------------------------------------
428 
429 IMPL_LINK_INLINE_START( SvxLineDefTabPage, ChangePreviewHdl_Impl, void *, EMPTYARG )
430 {
431     FillDash_Impl();
432     aCtlPreview.Invalidate();
433 
434     return( 0L );
435 }
436 IMPL_LINK_INLINE_END( SvxLineDefTabPage, ChangePreviewHdl_Impl, void *, EMPTYARG )
437 
438 //------------------------------------------------------------------------
439 
440 IMPL_LINK( SvxLineDefTabPage, ChangeNumber1Hdl_Impl, void *, EMPTYARG )
441 {
442     if( aNumFldNumber1.GetValue() == 0L )
443     {
444         aNumFldNumber2.SetMin( 1L );
445         aNumFldNumber2.SetFirst( 1L );
446     }
447     else
448     {
449         aNumFldNumber2.SetMin( 0L );
450         aNumFldNumber2.SetFirst( 0L );
451     }
452 
453     ChangePreviewHdl_Impl( this );
454 
455     return( 0L );
456 }
457 
458 //------------------------------------------------------------------------
459 
460 IMPL_LINK( SvxLineDefTabPage, ChangeNumber2Hdl_Impl, void *, EMPTYARG )
461 {
462     if( aNumFldNumber2.GetValue() == 0L )
463     {
464         aNumFldNumber1.SetMin( 1L );
465         aNumFldNumber1.SetFirst( 1L );
466     }
467     else
468     {
469         aNumFldNumber1.SetMin( 0L );
470         aNumFldNumber1.SetFirst( 0L );
471     }
472 
473     ChangePreviewHdl_Impl( this );
474 
475     return( 0L );
476 }
477 
478 
479 //------------------------------------------------------------------------
480 
481 IMPL_LINK( SvxLineDefTabPage, ChangeMetricHdl_Impl, void *, p )
482 {
483     if( !aCbxSynchronize.IsChecked() && aMtrLength1.GetUnit() != eFUnit )
484     {
485         long nTmp1, nTmp2, nTmp3;
486 
487         // Wurde ueber Control geaendert
488         if( p )
489         {
490             nTmp1 = GetCoreValue( aMtrLength1, ePoolUnit ) * XOUT_WIDTH / 100;
491             nTmp2 = GetCoreValue( aMtrLength2, ePoolUnit ) * XOUT_WIDTH / 100;
492             nTmp3 = GetCoreValue( aMtrDistance, ePoolUnit ) * XOUT_WIDTH / 100;
493         }
494         else
495         {
496             nTmp1 = GetCoreValue( aMtrLength1, ePoolUnit );
497             nTmp2 = GetCoreValue( aMtrLength2, ePoolUnit );
498             nTmp3 = GetCoreValue( aMtrDistance, ePoolUnit );
499         }
500         aMtrLength1.SetDecimalDigits( 2 );
501         aMtrLength2.SetDecimalDigits( 2 );
502         aMtrDistance.SetDecimalDigits( 2 );
503 
504         // Metrik einstellen
505         aMtrLength1.SetUnit( eFUnit );
506         aMtrLength2.SetUnit( eFUnit );
507         aMtrDistance.SetUnit( eFUnit );
508 
509         SetMetricValue( aMtrLength1, nTmp1, ePoolUnit );
510         SetMetricValue( aMtrLength2, nTmp2, ePoolUnit );
511         SetMetricValue( aMtrDistance, nTmp3, ePoolUnit );
512     }
513     else if( aCbxSynchronize.IsChecked() && aMtrLength1.GetUnit() != FUNIT_CUSTOM )
514     {
515         long nTmp1, nTmp2, nTmp3;
516 
517         // Wurde ueber Control geaendert
518         if( p )
519         {
520             nTmp1 = GetCoreValue( aMtrLength1, ePoolUnit ) * 100 / XOUT_WIDTH;
521             nTmp2 = GetCoreValue( aMtrLength2, ePoolUnit ) * 100 / XOUT_WIDTH;
522             nTmp3 = GetCoreValue( aMtrDistance, ePoolUnit ) * 100 / XOUT_WIDTH;
523         }
524         else
525         {
526             nTmp1 = GetCoreValue( aMtrLength1, ePoolUnit );
527             nTmp2 = GetCoreValue( aMtrLength2, ePoolUnit );
528             nTmp3 = GetCoreValue( aMtrDistance, ePoolUnit );
529         }
530 
531         aMtrLength1.SetDecimalDigits( 0 );
532         aMtrLength2.SetDecimalDigits( 0 );
533         aMtrDistance.SetDecimalDigits( 0 );
534 
535         aMtrLength1.SetUnit( FUNIT_CUSTOM );
536         aMtrLength2.SetUnit( FUNIT_CUSTOM );
537         aMtrDistance.SetUnit( FUNIT_CUSTOM );
538 
539 
540         SetMetricValue( aMtrLength1, nTmp1, ePoolUnit );
541         SetMetricValue( aMtrLength2, nTmp2, ePoolUnit );
542         SetMetricValue( aMtrDistance, nTmp3, ePoolUnit );
543     }
544     SelectTypeHdl_Impl( NULL );
545 
546     return( 0L );
547 }
548 
549 //------------------------------------------------------------------------
550 
551 IMPL_LINK( SvxLineDefTabPage, SelectTypeHdl_Impl, void *, p )
552 {
553     if ( p == &aLbType1 || !p )
554     {
555         if ( aLbType1.GetSelectEntryPos() == 0 )
556         {
557             aMtrLength1.Disable();
558             aMtrLength1.SetText( String() );
559         }
560         else if ( !aMtrLength1.IsEnabled() )
561         {
562             aMtrLength1.Enable();
563             aMtrLength1.Reformat();
564         }
565     }
566 
567     if ( p == &aLbType2 || !p )
568     {
569         if ( aLbType2.GetSelectEntryPos() == 0 )
570         {
571             aMtrLength2.Disable();
572             aMtrLength2.SetText( String() );
573         }
574         else if ( !aMtrLength2.IsEnabled() )
575         {
576             aMtrLength2.Enable();
577             aMtrLength2.Reformat();
578         }
579     }
580     ChangePreviewHdl_Impl( p );
581     return( 0L );
582 }
583 
584 //------------------------------------------------------------------------
585 
586 IMPL_LINK( SvxLineDefTabPage, ClickAddHdl_Impl, void *, EMPTYARG )
587 {
588     ResMgr& rMgr = CUI_MGR();
589     String aNewName( SVX_RES( RID_SVXSTR_LINESTYLE ) );
590     String aDesc( ResId( RID_SVXSTR_DESC_LINESTYLE, rMgr ) );
591     String aName;
592     XDashEntry* pEntry;
593 
594     long nCount = pDashList->Count();
595     long j = 1;
596     sal_Bool bDifferent = sal_False;
597 
598     while ( !bDifferent )
599     {
600         aName = aNewName;
601         aName += sal_Unicode(' ');
602         aName += UniString::CreateFromInt32( j++ );
603         bDifferent = sal_True;
604 
605         for ( long i = 0; i < nCount && bDifferent; i++ )
606             if ( aName == pDashList->GetDash( i )->GetName() )
607                 bDifferent = sal_False;
608     }
609 
610     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
611     DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
612     AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
613     DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
614     sal_Bool bLoop = sal_True;
615 
616     while ( bLoop && pDlg->Execute() == RET_OK )
617     {
618         pDlg->GetName( aName );
619         bDifferent = sal_True;
620 
621         for( long i = 0; i < nCount && bDifferent; i++ )
622         {
623             if( aName == pDashList->GetDash( i )->GetName() )
624                 bDifferent = sal_False;
625         }
626 
627         if( bDifferent )
628         {
629             bLoop = sal_False;
630             FillDash_Impl();
631 
632             pEntry = new XDashEntry( aDash, aName );
633 
634             long nDashCount = pDashList->Count();
635             pDashList->Insert( pEntry, nDashCount );
636             const Bitmap aBitmap = pDashList->GetUiBitmap( nDashCount );
637             aLbLineStyles.Append( pEntry, &aBitmap );
638 
639             aLbLineStyles.SelectEntryPos( aLbLineStyles.GetEntryCount() - 1 );
640 
641             // Flag fuer modifiziert setzen
642             *pnDashListState |= CT_MODIFIED;
643 
644             *pPageType = 2;
645 
646             // Werte sichern fuer Changes-Erkennung ( -> Methode )
647             aNumFldNumber1.SaveValue();
648             aMtrLength1.SaveValue();
649             aLbType1.SaveValue();
650             aNumFldNumber2.SaveValue();
651             aMtrLength2.SaveValue();
652             aLbType2.SaveValue();
653             aMtrDistance.SaveValue();
654         }
655         else
656         {
657             WarningBox aBox( DLGWIN, WinBits( WB_OK ),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
658             aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
659             aBox.Execute();
660         }
661     }
662     delete( pDlg );
663 
664     // Status der Buttons ermitteln
665     if ( pDashList->Count() )
666     {
667         aBtnModify.Enable();
668         aBtnDelete.Enable();
669         aBtnSave.Enable();
670     }
671     return( 0L );
672 }
673 
674 //------------------------------------------------------------------------
675 
676 IMPL_LINK( SvxLineDefTabPage, ClickModifyHdl_Impl, void *, EMPTYARG )
677 {
678     sal_uInt16 nPos = aLbLineStyles.GetSelectEntryPos();
679 
680     if( nPos != LISTBOX_ENTRY_NOTFOUND )
681     {
682         ResMgr& rMgr = CUI_MGR();
683         String aNewName( SVX_RES( RID_SVXSTR_LINESTYLE ) );
684         String aDesc( ResId( RID_SVXSTR_DESC_LINESTYLE, rMgr ) );
685         String aName( pDashList->GetDash( nPos )->GetName() );
686         String aOldName = aName;
687 
688         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
689         DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
690         AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( DLGWIN, aName, aDesc );
691         DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
692 
693         long nCount = pDashList->Count();
694         sal_Bool bDifferent = sal_False;
695         sal_Bool bLoop = sal_True;
696 
697         while ( bLoop && pDlg->Execute() == RET_OK )
698         {
699             pDlg->GetName( aName );
700             bDifferent = sal_True;
701 
702             for( long i = 0; i < nCount && bDifferent; i++ )
703             {
704                 if( aName == pDashList->GetDash( i )->GetName() &&
705                     aName != aOldName )
706                     bDifferent = sal_False;
707             }
708 
709             if ( bDifferent )
710             {
711                 bLoop = sal_False;
712                 FillDash_Impl();
713 
714                 XDashEntry* pEntry = new XDashEntry( aDash, aName );
715 
716                 delete pDashList->Replace( pEntry, nPos );
717                 const Bitmap aBitmap = pDashList->GetUiBitmap( nPos );
718                 aLbLineStyles.Modify( pEntry, nPos, &aBitmap );
719 
720                 aLbLineStyles.SelectEntryPos( nPos );
721 
722                 // Flag fuer modifiziert setzen
723                 *pnDashListState |= CT_MODIFIED;
724 
725                 *pPageType = 2;
726 
727                 // Werte sichern fuer Changes-Erkennung ( -> Methode )
728                 aNumFldNumber1.SaveValue();
729                 aMtrLength1.SaveValue();
730                 aLbType1.SaveValue();
731                 aNumFldNumber2.SaveValue();
732                 aMtrLength2.SaveValue();
733                 aLbType2.SaveValue();
734                 aMtrDistance.SaveValue();
735             }
736             else
737             {
738                 WarningBox aBox( DLGWIN, WinBits( WB_OK ), String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
739                 aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
740                 aBox.Execute();
741             }
742         }
743         delete( pDlg );
744     }
745     return( 0L );
746 }
747 
748 //------------------------------------------------------------------------
749 
750 IMPL_LINK( SvxLineDefTabPage, ClickDeleteHdl_Impl, void *, EMPTYARG )
751 {
752     sal_uInt16 nPos = aLbLineStyles.GetSelectEntryPos();
753 
754     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
755     {
756         QueryBox aQueryBox( DLGWIN, WinBits( WB_YES_NO | WB_DEF_NO ),
757             String( CUI_RES( RID_SVXSTR_ASK_DEL_LINESTYLE ) ) );
758 
759         if ( aQueryBox.Execute() == RET_YES )
760         {
761             delete pDashList->Remove( nPos );
762             aLbLineStyles.RemoveEntry( nPos );
763             aLbLineStyles.SelectEntryPos( 0 );
764 
765             SelectLinestyleHdl_Impl( this );
766             *pPageType = 0; // Style soll nicht uebernommen werden
767 
768             // Flag fuer modifiziert setzen
769             *pnDashListState |= CT_MODIFIED;
770 
771             ChangePreviewHdl_Impl( this );
772         }
773     }
774 
775     // Status der Buttons ermitteln
776     if ( !pDashList->Count() )
777     {
778         aBtnModify.Disable();
779         aBtnDelete.Disable();
780         aBtnSave.Disable();
781     }
782     return( 0L );
783 }
784 
785 // -----------------------------------------------------------------------
786 
787 IMPL_LINK( SvxLineDefTabPage, ClickLoadHdl_Impl, void *, EMPTYARG )
788 {
789     ResMgr& rMgr = CUI_MGR();
790     sal_uInt16 nReturn = RET_YES;
791 
792     if ( *pnDashListState & CT_MODIFIED )
793     {
794         nReturn = WarningBox( DLGWIN, WinBits( WB_YES_NO_CANCEL ),
795             String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
796 
797         if ( nReturn == RET_YES )
798             pDashList->Save();
799     }
800 
801     if ( nReturn != RET_CANCEL )
802     {
803         ::sfx2::FileDialogHelper aDlg(
804             com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
805             0 );
806         String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sod" ) );
807         aDlg.AddFilter( aStrFilterType, aStrFilterType );
808         INetURLObject aFile( SvtPathOptions().GetPalettePath() );
809         aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
810 
811         if( aDlg.Execute() == ERRCODE_NONE )
812         {
813             INetURLObject aURL( aDlg.GetPath() );
814             INetURLObject aPathURL( aURL );
815 
816             aPathURL.removeSegment();
817             aPathURL.removeFinalSlash();
818 
819             // Liste speichern
820             XDashList* pDshLst = new XDashList( aPathURL.GetMainURL( INetURLObject::NO_DECODE ), pXPool );
821             pDshLst->SetName( aURL.getName() );
822 
823             if( pDshLst->Load() )
824             {
825                 if( pDshLst )
826                 {
827                     // Pruefen, ob Tabelle geloescht werden darf:
828                     if( pDashList != ( (SvxLineTabDialog*) DLGWIN )->GetDashList() )
829                         delete pDashList;
830 
831                     pDashList = pDshLst;
832                     ( (SvxLineTabDialog*) DLGWIN )->SetNewDashList( pDashList );
833 
834                     aLbLineStyles.Clear();
835                     aLbLineStyles.Fill( pDashList );
836                     Reset( rOutAttrs );
837 
838                     pDashList->SetName( aURL.getName() );
839 
840 /*                  // Ermitteln (evtl. abschneiden) des Namens und in
841                     // der GroupBox darstellen
842                     String aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
843                     aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
844 
845                     if ( aURL.getBase().Len() > 18 )
846                     {
847                         aString += aURL.getBase().Copy( 0, 15 );
848                         aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
849                     }
850                     else
851                         aString += aURL.getBase();
852 
853                     aGrpLinestyles.SetText( aString );
854 */
855                     // Flag fuer gewechselt setzen
856                     *pnDashListState |= CT_CHANGED;
857                     // Flag fuer modifiziert entfernen
858                     *pnDashListState &= ~CT_MODIFIED;
859                 }
860             }
861             else
862                 //aIStream.Close();
863                 ErrorBox( DLGWIN, WinBits( WB_OK ),
864                     String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
865         }
866     }
867 
868     // Status der Buttons ermitteln
869     if ( pDashList->Count() )
870     {
871         aBtnModify.Enable();
872         aBtnDelete.Enable();
873         aBtnSave.Enable();
874     }
875     else
876     {
877         aBtnModify.Disable();
878         aBtnDelete.Disable();
879         aBtnSave.Disable();
880     }
881     return( 0L );
882 }
883 
884 // -----------------------------------------------------------------------
885 
886 IMPL_LINK( SvxLineDefTabPage, ClickSaveHdl_Impl, void *, EMPTYARG )
887 {
888     ::sfx2::FileDialogHelper aDlg(
889         com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
890     String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.sod" ) );
891     aDlg.AddFilter( aStrFilterType, aStrFilterType );
892 
893     INetURLObject aFile( SvtPathOptions().GetPalettePath() );
894     DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
895 
896     if( pDashList->GetName().Len() )
897     {
898         aFile.Append( pDashList->GetName() );
899 
900         if( !aFile.getExtension().getLength() )
901             aFile.SetExtension( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "sod" ) ) );
902     }
903 
904     aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
905     if ( aDlg.Execute() == ERRCODE_NONE )
906     {
907         INetURLObject aURL( aDlg.GetPath() );
908         INetURLObject aPathURL( aURL );
909 
910         aPathURL.removeSegment();
911         aPathURL.removeFinalSlash();
912 
913         pDashList->SetName( aURL.getName() );
914         pDashList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
915 
916         if( pDashList->Save() )
917         {
918 /*          // Ermitteln (evtl. abschneiden) des Namens und in
919             // der GroupBox darstellen
920             String aString( CUI_RES( RID_SVXSTR_TABLE ) );
921             aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
922 
923             if ( aURL.getBase().Len() > 18 )
924             {
925                 aString += aURL.getBase().Copy( 0, 15 );
926                 aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "..." ) );
927             }
928             else
929                 aString += aURL.getBase();
930 
931             aGrpLinestyles.SetText( aString );
932 */
933             // Flag fuer gespeichert setzen
934             *pnDashListState |= CT_SAVED;
935             // Flag fuer modifiziert entfernen
936             *pnDashListState &= ~CT_MODIFIED;
937         }
938         else
939         {
940             ErrorBox( DLGWIN, WinBits( WB_OK ),
941                 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
942         }
943     }
944 
945     return( 0L );
946 }
947 
948 //------------------------------------------------------------------------
949 
950 void SvxLineDefTabPage::FillDash_Impl()
951 {
952     XDashStyle eXDS;
953 
954 /*  Alle Stile werden z.Z. nicht benutzt
955     if( aRbtEnds1.IsChecked() )
956         eXDS = XDASH_ROUND;
957     else if( aRbtEnds2.IsChecked() )
958         eXDS = XDASH_RECT;
959     else
960         eXDS = XDASH_RECT;
961 */
962     if( aCbxSynchronize.IsChecked() )
963         eXDS = XDASH_RECTRELATIVE;
964     else
965         eXDS = XDASH_RECT;
966 
967     aDash.SetDashStyle( eXDS );
968     aDash.SetDots( (sal_uInt8) aNumFldNumber1.GetValue() );
969     aDash.SetDotLen( aLbType1.GetSelectEntryPos() == 0 ? 0 :
970                                 GetCoreValue( aMtrLength1, ePoolUnit ) );
971     aDash.SetDashes( (sal_uInt8) aNumFldNumber2.GetValue() );
972     aDash.SetDashLen( aLbType2.GetSelectEntryPos() == 0 ? 0 :
973                                 GetCoreValue( aMtrLength2, ePoolUnit ) );
974     aDash.SetDistance( GetCoreValue( aMtrDistance, ePoolUnit ) );
975 
976     rXLSet.Put( XLineDashItem( String(), aDash ) );
977 
978     // #i34740#
979     aCtlPreview.SetLineAttributes(aXLineAttr.GetItemSet());
980 }
981 
982 //------------------------------------------------------------------------
983 
984 void SvxLineDefTabPage::FillDialog_Impl()
985 {
986     XDashStyle eXDS = aDash.GetDashStyle(); // XDASH_RECT, XDASH_ROUND
987     if( eXDS == XDASH_RECTRELATIVE )
988         aCbxSynchronize.Check();
989     else
990         aCbxSynchronize.Check( sal_False );
991 
992     aNumFldNumber1.SetValue( aDash.GetDots() );
993     //aMtrLength1.SetValue( aDash.GetDotLen() );
994     SetMetricValue( aMtrLength1, aDash.GetDotLen(), ePoolUnit );
995     aLbType1.SelectEntryPos( aDash.GetDotLen() == 0 ? 0 : 1 );
996     aNumFldNumber2.SetValue( aDash.GetDashes() );
997     //aMtrLength2.SetValue( aDash.GetDashLen() );
998     SetMetricValue( aMtrLength2, aDash.GetDashLen(), ePoolUnit );
999     aLbType2.SelectEntryPos( aDash.GetDashLen() == 0 ? 0 : 1 );
1000     //aMtrDistance.SetValue( aDash.GetDistance() );
1001     SetMetricValue( aMtrDistance, aDash.GetDistance(), ePoolUnit );
1002 
1003     ChangeMetricHdl_Impl( NULL );
1004 
1005     // Werte sichern fuer Changes-Erkennung ( -> Methode )
1006     aNumFldNumber1.SaveValue();
1007     aMtrLength1.SaveValue();
1008     aLbType1.SaveValue();
1009     aNumFldNumber2.SaveValue();
1010     aMtrLength2.SaveValue();
1011     aLbType2.SaveValue();
1012     aMtrDistance.SaveValue();
1013 }
1014 
1015 
1016 void SvxLineDefTabPage::DataChanged( const DataChangedEvent& rDCEvt )
1017 {
1018     SfxTabPage::DataChanged( rDCEvt );
1019 
1020     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1021     {
1022         sal_uInt16 nOldSelect = aLbLineStyles.GetSelectEntryPos();
1023         aLbLineStyles.Clear();
1024         aLbLineStyles.Fill( pDashList );
1025         aLbLineStyles.SelectEntryPos( nOldSelect );
1026     }
1027 }
1028 
1029