LCOV - code coverage report
Current view: top level - cui/source/tabpages - tplnedef.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 470 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 38 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <tools/urlobj.hxx>
      21             : #include <vcl/msgbox.hxx>
      22             : #include <vcl/settings.hxx>
      23             : #include <unotools/pathoptions.hxx>
      24             : #include <sfx2/app.hxx>
      25             : #include <sfx2/module.hxx>
      26             : #include <sfx2/filedlghelper.hxx>
      27             : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
      28             : 
      29             : #include <cuires.hrc>
      30             : #include "helpid.hrc"
      31             : 
      32             : #include "svx/xattr.hxx"
      33             : #include <svx/xpool.hxx>
      34             : #include <svx/xtable.hxx>
      35             : 
      36             : #include "svx/drawitem.hxx"
      37             : #include "cuitabline.hxx"
      38             : #include "dlgname.hxx"
      39             : #include "defdlgname.hxx"
      40             : #include <svx/svxdlg.hxx>
      41             : #include <dialmgr.hxx>
      42             : #include "svx/dlgutil.hxx"
      43             : #include <svx/dialmgr.hxx>
      44             : #include <svx/dialogs.hrc>
      45             : #include <boost/scoped_ptr.hpp>
      46             : 
      47             : #define XOUT_WIDTH    150
      48             : 
      49             : using namespace com::sun::star;
      50             : 
      51             : 
      52           0 : SvxLineDefTabPage::SvxLineDefTabPage
      53             : (
      54             :     vcl::Window* pParent,
      55             :     const SfxItemSet& rInAttrs
      56             : ) :
      57             : 
      58             :     SfxTabPage( pParent
      59             :               , "LineStylePage"
      60             :               , "cui/ui/linestyletabpage.ui"
      61             :               , &rInAttrs ),
      62             :     rOutAttrs       ( rInAttrs ),
      63             :     bObjSelected    ( false ),
      64             : 
      65           0 :     pXPool              ( static_cast<XOutdevItemPool*>(rInAttrs.GetPool()) ),
      66             :     aXLStyle            ( drawing::LineStyle_DASH ),
      67             :     aXWidth             ( XOUT_WIDTH ),
      68             :     aXDash              ( OUString(), XDash( css::drawing::DashStyle_RECT, 3, 7, 2, 40, 15 ) ),
      69             :     aXColor             ( OUString(), COL_BLACK ),
      70             :     aXLineAttr          ( pXPool ),
      71           0 :     rXLSet              ( aXLineAttr.GetItemSet() ),
      72             :     pnDashListState(0),
      73             :     pPageType(0),
      74             :     nDlgType(0),
      75           0 :     pPosDashLb(0)
      76             : {
      77             : 
      78           0 :    get(m_pLbLineStyles   ,"LB_LINESTYLES");
      79           0 :    get(m_pLbType1        ,"LB_TYPE_1");
      80           0 :    get(m_pLbType2        ,"LB_TYPE_2");
      81           0 :    get(m_pNumFldNumber1  ,"NUM_FLD_1");
      82           0 :    get(m_pNumFldNumber2  ,"NUM_FLD_2");
      83           0 :    get(m_pMtrLength1     ,"MTR_FLD_LENGTH_1");
      84           0 :    m_pMtrLength1->SetCustomUnitText("%");
      85           0 :    get(m_pMtrLength2     ,"MTR_FLD_LENGTH_2");
      86           0 :    m_pMtrLength2->SetCustomUnitText("%");
      87           0 :    get(m_pMtrDistance    ,"MTR_FLD_DISTANCE");
      88           0 :    m_pMtrDistance->SetCustomUnitText("%");
      89           0 :    get(m_pCbxSynchronize ,"CBX_SYNCHRONIZE");
      90           0 :    get(m_pBtnAdd         ,"BTN_ADD");
      91           0 :    get(m_pBtnModify      ,"BTN_MODIFY");
      92           0 :    get(m_pBtnDelete      ,"BTN_DELETE");
      93           0 :    get(m_pBtnLoad        ,"BTN_LOAD");
      94           0 :    get(m_pBtnSave        ,"BTN_SAVE");
      95           0 :    get(m_pCtlPreview     ,"CTL_PREVIEW");
      96             : 
      97             :     // this page needs ExchangeSupport
      98           0 :     SetExchangeSupport();
      99             : 
     100             :     // adjust metric
     101           0 :     eFUnit = GetModuleFieldUnit( rInAttrs );
     102             : 
     103           0 :     switch ( eFUnit )
     104             :     {
     105             :         case FUNIT_M:
     106             :         case FUNIT_KM:
     107           0 :             eFUnit = FUNIT_MM;
     108           0 :             break;
     109             :         default: ; //prevent warning
     110             :     }
     111           0 :     SetFieldUnit( *m_pMtrDistance, eFUnit );
     112           0 :     SetFieldUnit( *m_pMtrLength1, eFUnit );
     113           0 :     SetFieldUnit( *m_pMtrLength2, eFUnit );
     114             : 
     115             :     // determine PoolUnit
     116           0 :     SfxItemPool* pPool = rOutAttrs.GetPool();
     117             :     DBG_ASSERT( pPool, "Wo ist der Pool?" );
     118           0 :     ePoolUnit = pPool->GetMetric( SID_ATTR_LINE_WIDTH );
     119             : 
     120           0 :     rXLSet.Put( aXLStyle );
     121           0 :     rXLSet.Put( aXWidth );
     122           0 :     rXLSet.Put( aXDash );
     123           0 :     rXLSet.Put( aXColor );
     124             : 
     125             :     // #i34740#
     126           0 :     m_pCtlPreview->SetLineAttributes(aXLineAttr.GetItemSet());
     127             : 
     128           0 :     m_pBtnAdd->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickAddHdl_Impl ) );
     129           0 :     m_pBtnModify->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickModifyHdl_Impl ) );
     130           0 :     m_pBtnDelete->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickDeleteHdl_Impl ) );
     131           0 :     m_pBtnLoad->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickLoadHdl_Impl ) );
     132           0 :     m_pBtnSave->SetClickHdl( LINK( this, SvxLineDefTabPage, ClickSaveHdl_Impl ) );
     133             : 
     134           0 :     m_pNumFldNumber1->SetModifyHdl( LINK( this, SvxLineDefTabPage, ChangeNumber1Hdl_Impl ) );
     135           0 :     m_pNumFldNumber2->SetModifyHdl( LINK( this, SvxLineDefTabPage, ChangeNumber2Hdl_Impl ) );
     136           0 :     m_pLbLineStyles->SetSelectHdl( LINK( this, SvxLineDefTabPage, SelectLinestyleHdl_Impl ) );
     137             : 
     138             :     // #i122042# switch off default adding of 'none' and 'solid' entries
     139             :     // for this ListBox; we want to select only editable/dashed styles
     140           0 :     m_pLbLineStyles->setAddStandardFields(false);
     141             : 
     142             :     // absolute (in mm) or relative (in %)
     143           0 :     m_pCbxSynchronize->SetClickHdl(  LINK( this, SvxLineDefTabPage, ChangeMetricHdl_Impl ) );
     144             : 
     145             :     // preview must be updated when there's something changed
     146           0 :     Link<> aLink = LINK( this, SvxLineDefTabPage, SelectTypeHdl_Impl );
     147           0 :     m_pLbType1->SetSelectHdl( aLink );
     148           0 :     m_pLbType2->SetSelectHdl( aLink );
     149           0 :     aLink = LINK( this, SvxLineDefTabPage, ChangePreviewHdl_Impl );
     150           0 :     m_pMtrLength1->SetModifyHdl( aLink );
     151           0 :     m_pMtrLength2->SetModifyHdl( aLink );
     152           0 :     m_pMtrDistance->SetModifyHdl( aLink );
     153             : 
     154           0 :     pDashList = NULL;
     155           0 : }
     156             : 
     157           0 : SvxLineDefTabPage::~SvxLineDefTabPage()
     158             : {
     159           0 :     disposeOnce();
     160           0 : }
     161             : 
     162           0 : void SvxLineDefTabPage::dispose()
     163             : {
     164           0 :     m_pLbLineStyles.clear();
     165           0 :     m_pLbType1.clear();
     166           0 :     m_pLbType2.clear();
     167           0 :     m_pNumFldNumber1.clear();
     168           0 :     m_pNumFldNumber2.clear();
     169           0 :     m_pMtrLength1.clear();
     170           0 :     m_pMtrLength2.clear();
     171           0 :     m_pMtrDistance.clear();
     172           0 :     m_pCbxSynchronize.clear();
     173           0 :     m_pBtnAdd.clear();
     174           0 :     m_pBtnModify.clear();
     175           0 :     m_pBtnDelete.clear();
     176           0 :     m_pBtnLoad.clear();
     177           0 :     m_pBtnSave.clear();
     178           0 :     m_pCtlPreview.clear();
     179           0 :     SfxTabPage::dispose();
     180           0 : }
     181             : 
     182           0 : void SvxLineDefTabPage::Construct()
     183             : {
     184             :     // Line style fill; do *not* add default fields here
     185           0 :     m_pLbLineStyles->Fill( pDashList );
     186           0 : }
     187             : 
     188             : 
     189             : 
     190           0 : void SvxLineDefTabPage::ActivatePage( const SfxItemSet& )
     191             : {
     192           0 :     if( nDlgType == 0 ) // area dialog
     193             :     {
     194             :         // ActivatePage() is called before the dialog receives PageCreated() !!!
     195           0 :         if( pDashList.is() )
     196             :         {
     197           0 :             if( *pPageType == 1 &&
     198           0 :                 *pPosDashLb != LISTBOX_ENTRY_NOTFOUND )
     199             :             {
     200           0 :                 m_pLbLineStyles->SelectEntryPos( *pPosDashLb );
     201             :             }
     202             :             // so that a possibly existing line style is discarded
     203           0 :             SelectLinestyleHdl_Impl( this );
     204             : 
     205             :             // determining (and possibly cutting) the name
     206             :             // and displaying it in the GroupBox
     207             : //             OUString        aString( CUI_RES( RID_SVXSTR_TABLE ) );
     208             : //             aString         += ": ";
     209           0 :             INetURLObject   aURL( pDashList->GetPath() );
     210             : 
     211           0 :             aURL.Append( pDashList->GetName() );
     212             :             DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
     213             : 
     214           0 :             *pPageType = 0; // 2
     215           0 :             *pPosDashLb = LISTBOX_ENTRY_NOTFOUND;
     216             :         }
     217             :     }
     218           0 : }
     219             : 
     220             : 
     221             : 
     222           0 : SfxTabPage::sfxpg SvxLineDefTabPage::DeactivatePage( SfxItemSet* _pSet )
     223             : {
     224           0 :     CheckChanges_Impl();
     225             : 
     226           0 :     if( _pSet )
     227           0 :         FillItemSet( _pSet );
     228             : 
     229           0 :     return LEAVE_PAGE;
     230             : }
     231             : 
     232             : 
     233             : 
     234           0 : void SvxLineDefTabPage::CheckChanges_Impl()
     235             : {
     236             :     // is here used to NOT lose changes
     237             :     //css::drawing::DashStyle eXDS;
     238             : 
     239           0 :     if( m_pNumFldNumber1->IsValueChangedFromSaved() ||
     240           0 :         m_pMtrLength1->IsValueChangedFromSaved() ||
     241           0 :         m_pLbType1->IsValueChangedFromSaved() ||
     242           0 :         m_pNumFldNumber2->IsValueChangedFromSaved() ||
     243           0 :         m_pMtrLength2->IsValueChangedFromSaved() ||
     244           0 :         m_pLbType2->IsValueChangedFromSaved() ||
     245           0 :         m_pMtrDistance->IsValueChangedFromSaved() )
     246             :     {
     247           0 :         ResMgr& rMgr = CUI_MGR();
     248           0 :         Image aWarningBoxImage = WarningBox::GetStandardImage();
     249           0 :         ScopedVclPtrInstance<SvxMessDialog> aMessDlg( GetParentDialog(),
     250           0 :                                                       SVX_RESSTR( RID_SVXSTR_LINESTYLE ),
     251             :                                                       OUString( ResId( RID_SVXSTR_ASK_CHANGE_LINESTYLE, rMgr ) ),
     252           0 :                                                       &aWarningBoxImage );
     253             :         DBG_ASSERT(aMessDlg, "Dialog creation failed!");
     254           0 :         aMessDlg->SetButtonText( MESS_BTN_1, OUString( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
     255           0 :         aMessDlg->SetButtonText( MESS_BTN_2, OUString( ResId( RID_SVXSTR_ADD, rMgr ) ) );
     256             : 
     257           0 :         short nRet = aMessDlg->Execute();
     258             : 
     259           0 :         switch( nRet )
     260             :         {
     261             :             case RET_BTN_1:
     262             :             {
     263           0 :                 ClickModifyHdl_Impl( this );
     264             :             }
     265           0 :             break;
     266             : 
     267             :             case RET_BTN_2:
     268             :             {
     269           0 :                 ClickAddHdl_Impl( this );
     270             :             }
     271           0 :             break;
     272             : 
     273             :             case RET_CANCEL:
     274           0 :             break;
     275           0 :         }
     276             :     }
     277             : 
     278             : 
     279             : 
     280           0 :     sal_Int32 nPos = m_pLbLineStyles->GetSelectEntryPos();
     281           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     282             :     {
     283           0 :         *pPosDashLb = nPos;
     284             :     }
     285           0 : }
     286             : 
     287             : 
     288             : 
     289           0 : bool SvxLineDefTabPage::FillItemSet( SfxItemSet* rAttrs )
     290             : {
     291           0 :     if( nDlgType == 0 ) // line dialog
     292             :     {
     293           0 :         if( *pPageType == 2 )
     294             :         {
     295           0 :             FillDash_Impl();
     296             : 
     297           0 :             OUString aString( m_pLbLineStyles->GetSelectEntry() );
     298           0 :             rAttrs->Put( XLineStyleItem( drawing::LineStyle_DASH ) );
     299           0 :             rAttrs->Put( XLineDashItem( aString, aDash ) );
     300             :         }
     301             :     }
     302           0 :     return true;
     303             : }
     304             : 
     305             : 
     306             : 
     307           0 : void SvxLineDefTabPage::Reset( const SfxItemSet* rAttrs )
     308             : {
     309           0 :     if( rAttrs->GetItemState( GetWhich( XATTR_LINESTYLE ) ) != SfxItemState::DONTCARE )
     310             :     {
     311           0 :         drawing::LineStyle eXLS = (drawing::LineStyle) static_cast<const XLineStyleItem&>( rAttrs->Get( GetWhich( XATTR_LINESTYLE ) ) ).GetValue();
     312             : 
     313           0 :         switch( eXLS )
     314             :         {
     315             :             case drawing::LineStyle_NONE:
     316             :             case drawing::LineStyle_SOLID:
     317           0 :                 m_pLbLineStyles->SelectEntryPos( 0 );
     318           0 :                 break;
     319             : 
     320             :             case drawing::LineStyle_DASH:
     321             :             {
     322           0 :                 const XLineDashItem& rDashItem = static_cast<const XLineDashItem&>( rAttrs->Get( XATTR_LINEDASH ) );
     323           0 :                 aDash = rDashItem.GetDashValue();
     324             : 
     325           0 :                 m_pLbLineStyles->SetNoSelection();
     326           0 :                 m_pLbLineStyles->SelectEntry( rDashItem.GetName() );
     327             :             }
     328           0 :                 break;
     329             : 
     330             :             default:
     331           0 :                 break;
     332             :         }
     333             :     }
     334           0 :     SelectLinestyleHdl_Impl( NULL );
     335             : 
     336             :     // determine button state
     337           0 :     if( pDashList->Count() )
     338             :     {
     339           0 :         m_pBtnModify->Enable();
     340           0 :         m_pBtnDelete->Enable();
     341           0 :         m_pBtnSave->Enable();
     342             :     }
     343             :     else
     344             :     {
     345           0 :         m_pBtnModify->Disable();
     346           0 :         m_pBtnDelete->Disable();
     347           0 :         m_pBtnSave->Disable();
     348             :     }
     349           0 : }
     350             : 
     351             : 
     352             : 
     353           0 : VclPtr<SfxTabPage> SvxLineDefTabPage::Create( vcl::Window* pWindow, const SfxItemSet* rOutAttrs )
     354             : {
     355           0 :     return VclPtr<SvxLineDefTabPage>::Create( pWindow, *rOutAttrs );
     356             : }
     357             : 
     358             : 
     359             : 
     360           0 : IMPL_LINK( SvxLineDefTabPage, SelectLinestyleHdl_Impl, void *, p )
     361             : {
     362           0 :     if(pDashList->Count())
     363             :     {
     364           0 :         int nTmp = m_pLbLineStyles->GetSelectEntryPos();
     365             : 
     366           0 :         if(LISTBOX_ENTRY_NOTFOUND == nTmp)
     367             :         {
     368             :             OSL_ENSURE(false, "OOps, non-existent LineDash selected (!)");
     369           0 :             nTmp = 1;
     370             :         }
     371             : 
     372           0 :         aDash = pDashList->GetDash( nTmp )->GetDash();
     373             : 
     374           0 :         FillDialog_Impl();
     375             : 
     376           0 :         rXLSet.Put( XLineDashItem( OUString(), aDash ) );
     377             : 
     378             :         // #i34740#
     379           0 :         m_pCtlPreview->SetLineAttributes(aXLineAttr.GetItemSet());
     380             : 
     381           0 :         m_pCtlPreview->Invalidate();
     382             : 
     383             :         // Is not set before, in order to take the new style
     384             :         // only if there was an entry selected in the ListBox.
     385             :         // If it was called via Reset(), then p is == NULL
     386           0 :         if( p )
     387           0 :             *pPageType = 2;
     388             :     }
     389           0 :     return 0L;
     390             : }
     391             : 
     392             : 
     393             : 
     394           0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ChangePreviewHdl_Impl)
     395             : {
     396           0 :     FillDash_Impl();
     397           0 :     m_pCtlPreview->Invalidate();
     398             : 
     399           0 :     return 0L;
     400             : }
     401             : 
     402           0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ChangeNumber1Hdl_Impl)
     403             : {
     404           0 :     if( m_pNumFldNumber1->GetValue() == 0L )
     405             :     {
     406           0 :         m_pNumFldNumber2->SetMin( 1L );
     407           0 :         m_pNumFldNumber2->SetFirst( 1L );
     408             :     }
     409             :     else
     410             :     {
     411           0 :         m_pNumFldNumber2->SetMin( 0L );
     412           0 :         m_pNumFldNumber2->SetFirst( 0L );
     413             :     }
     414             : 
     415           0 :     ChangePreviewHdl_Impl( this );
     416             : 
     417           0 :     return 0L;
     418             : }
     419             : 
     420             : 
     421             : 
     422           0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ChangeNumber2Hdl_Impl)
     423             : {
     424           0 :     if( m_pNumFldNumber2->GetValue() == 0L )
     425             :     {
     426           0 :         m_pNumFldNumber1->SetMin( 1L );
     427           0 :         m_pNumFldNumber1->SetFirst( 1L );
     428             :     }
     429             :     else
     430             :     {
     431           0 :         m_pNumFldNumber1->SetMin( 0L );
     432           0 :         m_pNumFldNumber1->SetFirst( 0L );
     433             :     }
     434             : 
     435           0 :     ChangePreviewHdl_Impl( this );
     436             : 
     437           0 :     return 0L;
     438             : }
     439             : 
     440             : 
     441             : 
     442             : 
     443           0 : IMPL_LINK( SvxLineDefTabPage, ChangeMetricHdl_Impl, void *, p )
     444             : {
     445           0 :     if( !m_pCbxSynchronize->IsChecked() && m_pMtrLength1->GetUnit() != eFUnit )
     446             :     {
     447             :         long nTmp1, nTmp2, nTmp3;
     448             : 
     449             :         // was changed with Control
     450           0 :         if( p )
     451             :         {
     452           0 :             nTmp1 = GetCoreValue( *m_pMtrLength1, ePoolUnit ) * XOUT_WIDTH / 100;
     453           0 :             nTmp2 = GetCoreValue( *m_pMtrLength2, ePoolUnit ) * XOUT_WIDTH / 100;
     454           0 :             nTmp3 = GetCoreValue( *m_pMtrDistance, ePoolUnit ) * XOUT_WIDTH / 100;
     455             :         }
     456             :         else
     457             :         {
     458           0 :             nTmp1 = GetCoreValue( *m_pMtrLength1, ePoolUnit );
     459           0 :             nTmp2 = GetCoreValue( *m_pMtrLength2, ePoolUnit );
     460           0 :             nTmp3 = GetCoreValue( *m_pMtrDistance, ePoolUnit );
     461             :         }
     462           0 :         m_pMtrLength1->SetDecimalDigits( 2 );
     463           0 :         m_pMtrLength2->SetDecimalDigits( 2 );
     464           0 :         m_pMtrDistance->SetDecimalDigits( 2 );
     465             : 
     466             :         // adjust metric
     467           0 :         m_pMtrLength1->SetUnit( eFUnit );
     468           0 :         m_pMtrLength2->SetUnit( eFUnit );
     469           0 :         m_pMtrDistance->SetUnit( eFUnit );
     470             : 
     471           0 :         SetMetricValue( *m_pMtrLength1, nTmp1, ePoolUnit );
     472           0 :         SetMetricValue( *m_pMtrLength2, nTmp2, ePoolUnit );
     473           0 :         SetMetricValue( *m_pMtrDistance, nTmp3, ePoolUnit );
     474             :     }
     475           0 :     else if( m_pCbxSynchronize->IsChecked() && m_pMtrLength1->GetUnit() != FUNIT_PERCENT )
     476             :     {
     477             :         long nTmp1, nTmp2, nTmp3;
     478             : 
     479             :         // was changed with Control
     480           0 :         if( p )
     481             :         {
     482           0 :             nTmp1 = GetCoreValue( *m_pMtrLength1, ePoolUnit ) * 100 / XOUT_WIDTH;
     483           0 :             nTmp2 = GetCoreValue( *m_pMtrLength2, ePoolUnit ) * 100 / XOUT_WIDTH;
     484           0 :             nTmp3 = GetCoreValue( *m_pMtrDistance, ePoolUnit ) * 100 / XOUT_WIDTH;
     485             :         }
     486             :         else
     487             :         {
     488           0 :             nTmp1 = GetCoreValue( *m_pMtrLength1, ePoolUnit );
     489           0 :             nTmp2 = GetCoreValue( *m_pMtrLength2, ePoolUnit );
     490           0 :             nTmp3 = GetCoreValue( *m_pMtrDistance, ePoolUnit );
     491             :         }
     492             : 
     493           0 :         m_pMtrLength1->SetDecimalDigits( 0 );
     494           0 :         m_pMtrLength2->SetDecimalDigits( 0 );
     495           0 :         m_pMtrDistance->SetDecimalDigits( 0 );
     496             : 
     497           0 :         m_pMtrLength1->SetUnit( FUNIT_PERCENT );
     498           0 :         m_pMtrLength2->SetUnit( FUNIT_PERCENT );
     499           0 :         m_pMtrDistance->SetUnit( FUNIT_PERCENT );
     500             : 
     501           0 :         SetMetricValue( *m_pMtrLength1, nTmp1, ePoolUnit );
     502           0 :         SetMetricValue( *m_pMtrLength2, nTmp2, ePoolUnit );
     503           0 :         SetMetricValue( *m_pMtrDistance, nTmp3, ePoolUnit );
     504             : 
     505             :     }
     506           0 :     SelectTypeHdl_Impl( NULL );
     507             : 
     508           0 :     return 0L;
     509             : }
     510             : 
     511             : 
     512             : 
     513           0 : IMPL_LINK( SvxLineDefTabPage, SelectTypeHdl_Impl, void *, p )
     514             : {
     515           0 :     if ( p == m_pLbType1 || !p )
     516             :     {
     517           0 :         if ( m_pLbType1->GetSelectEntryPos() == 0 )
     518             :         {
     519           0 :             m_pMtrLength1->Disable();
     520           0 :             m_pMtrLength1->SetText( "" );
     521             :         }
     522           0 :         else if ( !m_pMtrLength1->IsEnabled() )
     523             :         {
     524           0 :             m_pMtrLength1->Enable();
     525           0 :             m_pMtrLength1->Reformat();
     526             :         }
     527             :     }
     528             : 
     529           0 :     if ( p == m_pLbType2 || !p )
     530             :     {
     531           0 :         if ( m_pLbType2->GetSelectEntryPos() == 0 )
     532             :         {
     533           0 :             m_pMtrLength2->Disable();
     534           0 :             m_pMtrLength2->SetText( "" );
     535             :         }
     536           0 :         else if ( !m_pMtrLength2->IsEnabled() )
     537             :         {
     538           0 :             m_pMtrLength2->Enable();
     539           0 :             m_pMtrLength2->Reformat();
     540             :         }
     541             :     }
     542           0 :     ChangePreviewHdl_Impl( p );
     543           0 :     return 0L;
     544             : }
     545             : 
     546             : 
     547             : 
     548           0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ClickAddHdl_Impl)
     549             : {
     550           0 :     ResMgr& rMgr = CUI_MGR();
     551           0 :     OUString aNewName( SVX_RES( RID_SVXSTR_LINESTYLE ) );
     552           0 :     OUString aDesc( ResId( RID_SVXSTR_DESC_LINESTYLE, rMgr ) );
     553           0 :     OUString aName;
     554             :     XDashEntry* pEntry;
     555             : 
     556           0 :     long nCount = pDashList->Count();
     557           0 :     long j = 1;
     558           0 :     bool bDifferent = false;
     559             : 
     560           0 :     while ( !bDifferent )
     561             :     {
     562           0 :         aName = aNewName;
     563           0 :         aName += " ";
     564           0 :         aName += OUString::number( j++ );
     565           0 :         bDifferent = true;
     566             : 
     567           0 :         for ( long i = 0; i < nCount && bDifferent; i++ )
     568           0 :             if ( aName == pDashList->GetDash( i )->GetName() )
     569           0 :                 bDifferent = false;
     570             :     }
     571             : 
     572           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     573             :     DBG_ASSERT(pFact, "Dialog creation failed!");
     574           0 :     boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ));
     575             :     DBG_ASSERT(pDlg, "Dialog creation failed!");
     576           0 :     bool bLoop = true;
     577             : 
     578           0 :     while ( bLoop && pDlg->Execute() == RET_OK )
     579             :     {
     580           0 :         pDlg->GetName( aName );
     581           0 :         bDifferent = true;
     582             : 
     583           0 :         for( long i = 0; i < nCount && bDifferent; i++ )
     584             :         {
     585           0 :             if( aName == pDashList->GetDash( i )->GetName() )
     586           0 :                 bDifferent = false;
     587             :         }
     588             : 
     589           0 :         if( bDifferent )
     590             :         {
     591           0 :             bLoop = false;
     592           0 :             FillDash_Impl();
     593             : 
     594           0 :             pEntry = new XDashEntry( aDash, aName );
     595             : 
     596           0 :             long nDashCount = pDashList->Count();
     597           0 :             pDashList->Insert( pEntry, nDashCount );
     598           0 :             const Bitmap aBitmap = pDashList->GetUiBitmap( nDashCount );
     599           0 :             m_pLbLineStyles->Append( *pEntry, pDashList->GetUiBitmap( nDashCount ) );
     600             : 
     601           0 :             m_pLbLineStyles->SelectEntryPos( m_pLbLineStyles->GetEntryCount() - 1 );
     602             : 
     603           0 :             *pnDashListState |= ChangeType::MODIFIED;
     604             : 
     605           0 :             *pPageType = 2;
     606             : 
     607             :             // save values for changes recognition (-> method)
     608           0 :             m_pNumFldNumber1->SaveValue();
     609           0 :             m_pMtrLength1->SaveValue();
     610           0 :             m_pLbType1->SaveValue();
     611           0 :             m_pNumFldNumber2->SaveValue();
     612           0 :             m_pMtrLength2->SaveValue();
     613           0 :             m_pLbType2->SaveValue();
     614           0 :             m_pMtrDistance->SaveValue();
     615             :         }
     616             :         else
     617             :         {
     618           0 :             ScopedVclPtrInstance<MessageDialog> aBox( GetParentDialog()
     619             :                                                       ,"DuplicateNameDialog"
     620           0 :                                                       ,"cui/ui/queryduplicatedialog.ui" );
     621           0 :             aBox->Execute();
     622             :         }
     623             :     }
     624           0 :     pDlg.reset();
     625             : 
     626             :     // determine button state
     627           0 :     if ( pDashList->Count() )
     628             :     {
     629           0 :         m_pBtnModify->Enable();
     630           0 :         m_pBtnDelete->Enable();
     631           0 :         m_pBtnSave->Enable();
     632             :     }
     633           0 :     return 0L;
     634             : }
     635             : 
     636             : 
     637             : 
     638           0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ClickModifyHdl_Impl)
     639             : {
     640           0 :     sal_Int32 nPos = m_pLbLineStyles->GetSelectEntryPos();
     641             : 
     642           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     643             :     {
     644           0 :         ResMgr& rMgr = CUI_MGR();
     645           0 :         OUString aDesc( ResId( RID_SVXSTR_DESC_LINESTYLE, rMgr ) );
     646           0 :         OUString aName( pDashList->GetDash( nPos )->GetName() );
     647           0 :         OUString aOldName = aName;
     648             : 
     649           0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     650             :         DBG_ASSERT(pFact, "Dialog creation failed!");
     651           0 :         boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ));
     652             :         DBG_ASSERT(pDlg, "Dialog creation failed!");
     653             : 
     654           0 :         long nCount = pDashList->Count();
     655           0 :         bool bLoop = true;
     656             : 
     657           0 :         while ( bLoop && pDlg->Execute() == RET_OK )
     658             :         {
     659           0 :             pDlg->GetName( aName );
     660           0 :             bool bDifferent = true;
     661             : 
     662           0 :             for( long i = 0; i < nCount && bDifferent; i++ )
     663             :             {
     664           0 :                 if( aName == pDashList->GetDash( i )->GetName() &&
     665           0 :                     aName != aOldName )
     666           0 :                     bDifferent = false;
     667             :             }
     668             : 
     669           0 :             if ( bDifferent )
     670             :             {
     671           0 :                 bLoop = false;
     672           0 :                 FillDash_Impl();
     673             : 
     674           0 :                 XDashEntry* pEntry = new XDashEntry( aDash, aName );
     675             : 
     676           0 :                 delete pDashList->Replace( pEntry, nPos );
     677           0 :                 m_pLbLineStyles->Modify( *pEntry, nPos, pDashList->GetUiBitmap( nPos ) );
     678             : 
     679           0 :                 m_pLbLineStyles->SelectEntryPos( nPos );
     680             : 
     681           0 :                 *pnDashListState |= ChangeType::MODIFIED;
     682             : 
     683           0 :                 *pPageType = 2;
     684             : 
     685             :                 // save values for changes recognition (-> method)
     686           0 :                 m_pNumFldNumber1->SaveValue();
     687           0 :                 m_pMtrLength1->SaveValue();
     688           0 :                 m_pLbType1->SaveValue();
     689           0 :                 m_pNumFldNumber2->SaveValue();
     690           0 :                 m_pMtrLength2->SaveValue();
     691           0 :                 m_pLbType2->SaveValue();
     692           0 :                 m_pMtrDistance->SaveValue();
     693             :             }
     694             :             else
     695             :             {
     696           0 :                 ScopedVclPtrInstance<MessageDialog> aBox( GetParentDialog()
     697             :                                                           ,"DuplicateNameDialog"
     698           0 :                                                           ,"cui/ui/queryduplicatedialog.ui" );
     699           0 :                 aBox->Execute();
     700             :             }
     701           0 :         }
     702             :     }
     703           0 :     return 0L;
     704             : }
     705             : 
     706             : 
     707             : 
     708           0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ClickDeleteHdl_Impl)
     709             : {
     710           0 :     sal_Int32 nPos = m_pLbLineStyles->GetSelectEntryPos();
     711             : 
     712           0 :     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
     713             :     {
     714           0 :         ScopedVclPtrInstance<MessageDialog> aQueryBox( GetParentDialog()
     715             :                                                        ,"AskDelLineStyleDialog"
     716           0 :                                                        ,"cui/ui/querydeletelinestyledialog.ui" );
     717             : 
     718           0 :         if ( aQueryBox->Execute() == RET_YES )
     719             :         {
     720           0 :             delete pDashList->Remove( nPos );
     721           0 :             m_pLbLineStyles->RemoveEntry( nPos );
     722           0 :             m_pLbLineStyles->SelectEntryPos( 0 );
     723             : 
     724           0 :             SelectLinestyleHdl_Impl( this );
     725           0 :             *pPageType = 0; // style should not be taken
     726             : 
     727           0 :             *pnDashListState |= ChangeType::MODIFIED;
     728             : 
     729           0 :             ChangePreviewHdl_Impl( this );
     730           0 :         }
     731             :     }
     732             : 
     733             :     // determine button state
     734           0 :     if ( !pDashList->Count() )
     735             :     {
     736           0 :         m_pBtnModify->Disable();
     737           0 :         m_pBtnDelete->Disable();
     738           0 :         m_pBtnSave->Disable();
     739             :     }
     740           0 :     return 0L;
     741             : }
     742             : 
     743             : 
     744             : 
     745           0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ClickLoadHdl_Impl)
     746             : {
     747           0 :     sal_uInt16 nReturn = RET_YES;
     748             : 
     749           0 :     if ( *pnDashListState & ChangeType::MODIFIED )
     750             :     {
     751           0 :         nReturn = ScopedVclPtrInstance<MessageDialog>::Create( GetParentDialog()
     752             :                                 ,"AskSaveList"
     753           0 :                                 ,"cui/ui/querysavelistdialog.ui")->Execute();
     754             : 
     755           0 :         if ( nReturn == RET_YES )
     756           0 :             pDashList->Save();
     757             :     }
     758             : 
     759           0 :     if ( nReturn != RET_CANCEL )
     760             :     {
     761           0 :         ::sfx2::FileDialogHelper aDlg( com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
     762           0 :         OUString aStrFilterType( "*.sod" );
     763           0 :         aDlg.AddFilter( aStrFilterType, aStrFilterType );
     764           0 :         OUString aPalettePath(SvtPathOptions().GetPalettePath());
     765           0 :         OUString aLastDir;
     766           0 :         sal_Int32 nIndex = 0;
     767           0 :         do
     768             :         {
     769           0 :             aLastDir = aPalettePath.getToken(0, ';', nIndex);
     770             :         }
     771           0 :         while (nIndex >= 0);
     772             : 
     773           0 :         INetURLObject aFile(aLastDir);
     774           0 :         aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
     775             : 
     776           0 :         if( aDlg.Execute() == ERRCODE_NONE )
     777             :         {
     778           0 :             INetURLObject aURL( aDlg.GetPath() );
     779           0 :             INetURLObject aPathURL( aURL );
     780             : 
     781           0 :             aPathURL.removeSegment();
     782           0 :             aPathURL.removeFinalSlash();
     783             : 
     784           0 :             XDashListRef pDshLst = XPropertyList::AsDashList(XPropertyList::CreatePropertyList( XDASH_LIST, aPathURL.GetMainURL( INetURLObject::NO_DECODE ), "" ));
     785           0 :             pDshLst->SetName( aURL.getName() );
     786             : 
     787           0 :             if( pDshLst->Load() )
     788             :             {
     789           0 :                 pDashList = pDshLst;
     790           0 :                 static_cast<SvxLineTabDialog*>( GetParentDialog() )->SetNewDashList( pDashList );
     791             : 
     792           0 :                 m_pLbLineStyles->Clear();
     793           0 :                 m_pLbLineStyles->Fill( pDashList );
     794           0 :                 Reset( &rOutAttrs );
     795             : 
     796           0 :                 pDashList->SetName( aURL.getName() );
     797             : 
     798           0 :                 *pnDashListState |= ChangeType::CHANGED;
     799           0 :                 *pnDashListState &= ~ChangeType::MODIFIED;
     800             :             }
     801             :             else
     802             :                 //aIStream.Close();
     803           0 :                 ScopedVclPtrInstance<MessageDialog>::Create( GetParentDialog()
     804             :                               ,"NoLoadedFileDialog"
     805           0 :                               ,"cui/ui/querynoloadedfiledialog.ui")->Execute();
     806           0 :         }
     807             :     }
     808             : 
     809             :     // determine button state
     810           0 :     if ( pDashList->Count() )
     811             :     {
     812           0 :         m_pBtnModify->Enable();
     813           0 :         m_pBtnDelete->Enable();
     814           0 :         m_pBtnSave->Enable();
     815             :     }
     816             :     else
     817             :     {
     818           0 :         m_pBtnModify->Disable();
     819           0 :         m_pBtnDelete->Disable();
     820           0 :         m_pBtnSave->Disable();
     821             :     }
     822           0 :     return 0L;
     823             : }
     824             : 
     825             : 
     826             : 
     827           0 : IMPL_LINK_NOARG(SvxLineDefTabPage, ClickSaveHdl_Impl)
     828             : {
     829           0 :     ::sfx2::FileDialogHelper aDlg( com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
     830           0 :     OUString aStrFilterType( "*.sod" );
     831           0 :     aDlg.AddFilter( aStrFilterType, aStrFilterType );
     832             : 
     833           0 :     OUString aPalettePath(SvtPathOptions().GetPalettePath());
     834           0 :     OUString aLastDir;
     835           0 :     sal_Int32 nIndex = 0;
     836           0 :     do
     837             :     {
     838           0 :         aLastDir = aPalettePath.getToken(0, ';', nIndex);
     839             :     }
     840           0 :     while (nIndex >= 0);
     841             : 
     842           0 :     INetURLObject aFile(aLastDir);
     843             :     DBG_ASSERT( aFile.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
     844             : 
     845           0 :     if( !pDashList->GetName().isEmpty() )
     846             :     {
     847           0 :         aFile.Append( pDashList->GetName() );
     848             : 
     849           0 :         if( aFile.getExtension().isEmpty() )
     850           0 :             aFile.SetExtension( OUString("sod") );
     851             :     }
     852             : 
     853           0 :     aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
     854           0 :     if ( aDlg.Execute() == ERRCODE_NONE )
     855             :     {
     856           0 :         INetURLObject aURL( aDlg.GetPath() );
     857           0 :         INetURLObject aPathURL( aURL );
     858             : 
     859           0 :         aPathURL.removeSegment();
     860           0 :         aPathURL.removeFinalSlash();
     861             : 
     862           0 :         pDashList->SetName( aURL.getName() );
     863           0 :         pDashList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
     864             : 
     865           0 :         if( pDashList->Save() )
     866             :         {
     867           0 :             *pnDashListState |= ChangeType::SAVED;
     868           0 :             *pnDashListState &= ~ChangeType::MODIFIED;
     869             :         }
     870             :         else
     871             :         {
     872           0 :             ScopedVclPtrInstance<MessageDialog>::Create( GetParentDialog()
     873             :                          ,"NoSaveFileDialog"
     874           0 :                          ,"cui/ui/querynosavefiledialog.ui")->Execute();
     875           0 :         }
     876             :     }
     877             : 
     878           0 :     return 0L;
     879             : }
     880             : 
     881             : 
     882             : 
     883           0 : void SvxLineDefTabPage::FillDash_Impl()
     884             : {
     885             :     css::drawing::DashStyle eXDS;
     886             : 
     887           0 :     if( m_pCbxSynchronize->IsChecked() )
     888           0 :         eXDS = css::drawing::DashStyle_RECTRELATIVE;
     889             :     else
     890           0 :         eXDS = css::drawing::DashStyle_RECT;
     891             : 
     892           0 :     aDash.SetDashStyle( eXDS );
     893           0 :     aDash.SetDots( (sal_uInt8) m_pNumFldNumber1->GetValue() );
     894           0 :     aDash.SetDotLen( m_pLbType1->GetSelectEntryPos() == 0 ? 0 : GetCoreValue( *m_pMtrLength1, ePoolUnit ) );
     895           0 :     aDash.SetDashes( (sal_uInt8) m_pNumFldNumber2->GetValue() );
     896           0 :     aDash.SetDashLen( m_pLbType2->GetSelectEntryPos() == 0 ? 0 : GetCoreValue( *m_pMtrLength2, ePoolUnit ) );
     897           0 :     aDash.SetDistance( GetCoreValue( *m_pMtrDistance, ePoolUnit ) );
     898             : 
     899           0 :     rXLSet.Put( XLineDashItem( OUString(), aDash ) );
     900             : 
     901             :     // #i34740#
     902           0 :     m_pCtlPreview->SetLineAttributes(aXLineAttr.GetItemSet());
     903           0 : }
     904             : 
     905             : 
     906             : 
     907           0 : void SvxLineDefTabPage::FillDialog_Impl()
     908             : {
     909           0 :     css::drawing::DashStyle eXDS = aDash.GetDashStyle(); // css::drawing::DashStyle_RECT, css::drawing::DashStyle_ROUND
     910           0 :     if( eXDS == css::drawing::DashStyle_RECTRELATIVE )
     911           0 :         m_pCbxSynchronize->Check();
     912             :     else
     913           0 :         m_pCbxSynchronize->Check( false );
     914             : 
     915           0 :     m_pNumFldNumber1->SetValue( aDash.GetDots() );
     916           0 :     SetMetricValue( *m_pMtrLength1, aDash.GetDotLen(), ePoolUnit );
     917           0 :     m_pLbType1->SelectEntryPos( aDash.GetDotLen() == 0 ? 0 : 1 );
     918           0 :     m_pNumFldNumber2->SetValue( aDash.GetDashes() );
     919           0 :     SetMetricValue( *m_pMtrLength2, aDash.GetDashLen(), ePoolUnit );
     920           0 :     m_pLbType2->SelectEntryPos( aDash.GetDashLen() == 0 ? 0 : 1 );
     921           0 :     SetMetricValue( *m_pMtrDistance, aDash.GetDistance(), ePoolUnit );
     922             : 
     923           0 :     ChangeMetricHdl_Impl( NULL );
     924             : 
     925             :     // save values for changes recognition (-> method)
     926           0 :     m_pNumFldNumber1->SaveValue();
     927           0 :     m_pMtrLength1->SaveValue();
     928           0 :     m_pLbType1->SaveValue();
     929           0 :     m_pNumFldNumber2->SaveValue();
     930           0 :     m_pMtrLength2->SaveValue();
     931           0 :     m_pLbType2->SaveValue();
     932           0 :     m_pMtrDistance->SaveValue();
     933           0 : }
     934             : 
     935             : 
     936           0 : void SvxLineDefTabPage::DataChanged( const DataChangedEvent& rDCEvt )
     937             : {
     938           0 :     SfxTabPage::DataChanged( rDCEvt );
     939             : 
     940           0 :     if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
     941             :     {
     942           0 :         sal_Int32 nOldSelect = m_pLbLineStyles->GetSelectEntryPos();
     943           0 :         m_pLbLineStyles->Clear();
     944           0 :         m_pLbLineStyles->Fill( pDashList );
     945           0 :         m_pLbLineStyles->SelectEntryPos( nOldSelect );
     946             :     }
     947           0 : }
     948             : 
     949             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11