LCOV - code coverage report
Current view: top level - libreoffice/cui/source/tabpages - tphatch.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 426 0.2 %
Date: 2012-12-17 Functions: 2 26 7.7 %
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/shl.hxx>
      21             : #include <tools/urlobj.hxx>
      22             : #include <vcl/msgbox.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             : #define _SVX_TPHATCH_CXX
      30             : 
      31             : #include <cuires.hrc>
      32             : #include "tabarea.hrc"
      33             : #include "helpid.hrc"
      34             : #include "svx/xattr.hxx"
      35             : #include <svx/xpool.hxx>
      36             : #include <svx/xtable.hxx>
      37             : #include "svx/drawitem.hxx"
      38             : #include "cuitabarea.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 "paragrph.hrc"
      45             : #include <svx/dialogs.hrc>
      46             : 
      47           0 : SvxHatchTabPage::SvxHatchTabPage
      48             : (
      49             :     Window* pParent,
      50             :     const SfxItemSet& rInAttrs
      51             : ) :
      52             : 
      53           0 :     SvxTabPage          ( pParent, CUI_RES( RID_SVXPAGE_HATCH ), rInAttrs ),
      54             : 
      55           0 :     aFtDistance         ( this, CUI_RES( FT_LINE_DISTANCE ) ),
      56           0 :     aMtrDistance        ( this, CUI_RES( MTR_FLD_DISTANCE ) ),
      57           0 :     aFtAngle            ( this, CUI_RES( FT_LINE_ANGLE ) ),
      58           0 :     aMtrAngle           ( this, CUI_RES( MTR_FLD_ANGLE ) ),
      59           0 :     aCtlAngle           ( this, CUI_RES( CTL_ANGLE ),
      60             :                                     RP_RB, 200, 80, CS_ANGLE ),
      61           0 :     aFlProp             ( this, CUI_RES( FL_PROP ) ),
      62           0 :     aFtLineType         ( this, CUI_RES( FT_LINE_TYPE ) ),
      63           0 :     aLbLineType         ( this, CUI_RES( LB_LINE_TYPE ) ),
      64           0 :     aFtLineColor        ( this, CUI_RES( FT_LINE_COLOR ) ),
      65           0 :     aLbLineColor        ( this, CUI_RES( LB_LINE_COLOR ) ),
      66           0 :     aLbHatchings        ( this, CUI_RES( LB_HATCHINGS ) ),
      67           0 :     aCtlPreview         ( this, CUI_RES( CTL_PREVIEW ) ),
      68           0 :     aBtnAdd             ( this, CUI_RES( BTN_ADD ) ),
      69           0 :     aBtnModify          ( this, CUI_RES( BTN_MODIFY ) ),
      70           0 :     aBtnDelete          ( this, CUI_RES( BTN_DELETE ) ),
      71           0 :     aBtnLoad            ( this, CUI_RES( BTN_LOAD ) ),
      72           0 :     aBtnSave            ( this, CUI_RES( BTN_SAVE ) ),
      73             : 
      74             :     rOutAttrs           ( rInAttrs ),
      75             : 
      76           0 :     pXPool              ( (XOutdevItemPool*) rInAttrs.GetPool() ),
      77             :     aXFStyleItem        ( XFILL_HATCH ),
      78             :     aXHatchItem         ( String(), XHatch() ),
      79             :     aXFillAttr          ( pXPool ),
      80           0 :     rXFSet              ( aXFillAttr.GetItemSet() )
      81             : 
      82             : {
      83           0 :     FreeResource();
      84             : 
      85             :     // this page needs ExchangeSupport
      86           0 :     SetExchangeSupport();
      87             : 
      88             :     // adjust metric
      89           0 :     FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
      90             : 
      91           0 :     switch ( eFUnit )
      92             :     {
      93             :         case FUNIT_M:
      94             :         case FUNIT_KM:
      95           0 :             eFUnit = FUNIT_MM;
      96           0 :             break;
      97             :         default: ;//prevent warning
      98             :     }
      99           0 :     SetFieldUnit( aMtrDistance, eFUnit );
     100             : 
     101             :     // determine PoolUnit
     102           0 :     SfxItemPool* pPool = rOutAttrs.GetPool();
     103             :     DBG_ASSERT( pPool, "Wo ist der Pool?" );
     104           0 :     ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
     105             : 
     106             :     // setting the output device
     107           0 :     rXFSet.Put( aXFStyleItem );
     108           0 :     rXFSet.Put( aXHatchItem );
     109           0 :     aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
     110             : 
     111           0 :     aLbHatchings.SetSelectHdl( LINK( this, SvxHatchTabPage, ChangeHatchHdl_Impl ) );
     112             : 
     113           0 :     Link aLink = LINK( this, SvxHatchTabPage, ModifiedHdl_Impl );
     114           0 :     aMtrDistance.SetModifyHdl( aLink );
     115           0 :     aMtrAngle.SetModifyHdl( aLink );
     116           0 :     aLbLineType.SetSelectHdl( aLink );
     117           0 :     aLbLineColor.SetSelectHdl( aLink );
     118             : 
     119           0 :     aBtnAdd.SetClickHdl( LINK( this, SvxHatchTabPage, ClickAddHdl_Impl ) );
     120             :     aBtnModify.SetClickHdl(
     121           0 :         LINK( this, SvxHatchTabPage, ClickModifyHdl_Impl ) );
     122             :     aBtnDelete.SetClickHdl(
     123           0 :         LINK( this, SvxHatchTabPage, ClickDeleteHdl_Impl ) );
     124           0 :     aBtnLoad.SetClickHdl( LINK( this, SvxHatchTabPage, ClickLoadHdl_Impl ) );
     125           0 :     aBtnSave.SetClickHdl( LINK( this, SvxHatchTabPage, ClickSaveHdl_Impl ) );
     126             : 
     127           0 :     aCtlPreview.SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
     128             : 
     129           0 :     aCtlPreview.SetAccessibleName(String(CUI_RES(STR_EXAMPLE)));
     130           0 :     aLbHatchings.SetAccessibleName( String(CUI_RES(STR_LB_HATCHINGSTYLE)) );
     131           0 :     aCtlAngle.SetAccessibleRelationMemberOf( &aFlProp );
     132           0 :     aLbHatchings.SetAccessibleRelationMemberOf( &aFlProp );
     133           0 :     aBtnAdd.SetAccessibleRelationMemberOf( &aFlProp );
     134           0 :     aBtnModify.SetAccessibleRelationMemberOf( &aFlProp );
     135           0 :     aBtnDelete.SetAccessibleRelationMemberOf( &aFlProp );
     136           0 :     aLbHatchings.SetAccessibleRelationLabeledBy(&aLbHatchings);
     137           0 : }
     138             : 
     139             : // -----------------------------------------------------------------------
     140             : 
     141           0 : void SvxHatchTabPage::Construct()
     142             : {
     143           0 :     aLbLineColor.Fill( pColorList );
     144           0 :     aLbHatchings.Fill( pHatchingList );
     145           0 : }
     146             : 
     147             : // -----------------------------------------------------------------------
     148             : 
     149           0 : void SvxHatchTabPage::ActivatePage( const SfxItemSet& rSet )
     150             : {
     151             :     sal_uInt16 nPos;
     152             :     sal_uInt16 nCount;
     153             : 
     154           0 :     if( *pDlgType == 0 ) // area dialog
     155             :     {
     156           0 :         *pbAreaTP = sal_False;
     157             : 
     158           0 :         if( pColorList.is() )
     159             :         {
     160             :             // ColorList
     161           0 :             if( *pnColorListState & CT_CHANGED ||
     162             :                 *pnColorListState & CT_MODIFIED )
     163             :             {
     164           0 :                 if( *pnColorListState & CT_CHANGED )
     165           0 :                     pColorList = ( (SvxAreaTabDialog*) GetParentDialog() )->GetNewColorList();
     166             : 
     167             :                 // LbLineColor
     168           0 :                 nPos = aLbLineColor.GetSelectEntryPos();
     169           0 :                 aLbLineColor.Clear();
     170           0 :                 aLbLineColor.Fill( pColorList );
     171           0 :                 nCount = aLbLineColor.GetEntryCount();
     172           0 :                 if( nCount == 0 )
     173             :                     ; // this case should not occur
     174           0 :                 else if( nCount <= nPos )
     175           0 :                     aLbLineColor.SelectEntryPos( 0 );
     176             :                 else
     177           0 :                     aLbLineColor.SelectEntryPos( nPos );
     178             : 
     179           0 :                 ModifiedHdl_Impl( this );
     180             :             }
     181             : 
     182             :             // determining (possibly cutting) the name
     183             :             // and displaying it in the GroupBox
     184           0 :             String          aString( CUI_RES( RID_SVXSTR_TABLE ) ); aString.AppendAscii( ": " );
     185           0 :             INetURLObject   aURL( pHatchingList->GetPath() );
     186             : 
     187           0 :             aURL.Append( pHatchingList->GetName() );
     188             :             DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
     189             : 
     190           0 :             if ( aURL.getBase().getLength() > 18 )
     191             :             {
     192           0 :                 aString += String(aURL.getBase()).Copy( 0, 15 );
     193           0 :                 aString.AppendAscii( "..." );
     194             :             }
     195             :             else
     196           0 :                 aString += String(aURL.getBase());
     197             : 
     198           0 :             if( *pPageType == PT_HATCH && *pPos != LISTBOX_ENTRY_NOTFOUND )
     199             :             {
     200           0 :                 aLbHatchings.SelectEntryPos( *pPos );
     201             :             }
     202             :             // colors could have been deleted
     203           0 :             ChangeHatchHdl_Impl( this );
     204             : 
     205           0 :             *pPageType = PT_HATCH;
     206           0 :             *pPos = LISTBOX_ENTRY_NOTFOUND;
     207             :         }
     208             :     }
     209             : 
     210           0 :     rXFSet.Put ( ( XFillColorItem& )    rSet.Get(XATTR_FILLCOLOR) );
     211           0 :     rXFSet.Put ( ( XFillBackgroundItem&)rSet.Get(XATTR_FILLBACKGROUND) );
     212           0 :     aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
     213           0 :     aCtlPreview.Invalidate();
     214           0 : }
     215             : 
     216             : // -----------------------------------------------------------------------
     217             : 
     218           0 : int SvxHatchTabPage::DeactivatePage( SfxItemSet* _pSet )
     219             : {
     220           0 :     if ( CheckChanges_Impl() == -1L )
     221           0 :         return KEEP_PAGE;
     222             : 
     223           0 :     if( _pSet )
     224           0 :         FillItemSet( *_pSet );
     225             : 
     226           0 :     return LEAVE_PAGE;
     227             : }
     228             : 
     229             : // -----------------------------------------------------------------------
     230             : 
     231           0 : long SvxHatchTabPage::CheckChanges_Impl()
     232             : {
     233           0 :     if( aMtrDistance.GetText()           != aMtrDistance.GetSavedValue() ||
     234           0 :         aMtrAngle.GetText()              != aMtrAngle.GetSavedValue() ||
     235           0 :         aLbLineType.GetSelectEntryPos()  != aLbLineType.GetSavedValue()  ||
     236           0 :         aLbLineColor.GetSelectEntryPos() != aLbLineColor.GetSavedValue() ||
     237           0 :         aLbHatchings.GetSelectEntryPos() != aLbHatchings.GetSavedValue() )
     238             :     {
     239           0 :         ResMgr& rMgr = CUI_MGR();
     240           0 :         Image aWarningBoxImage = WarningBox::GetStandardImage();
     241           0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     242             :         DBG_ASSERT(pFact, "Dialogdiet fail!");
     243           0 :         AbstractSvxMessDialog* aMessDlg = pFact->CreateSvxMessDialog( GetParentDialog(), RID_SVXDLG_MESSBOX,
     244           0 :                                                         SVX_RESSTR( RID_SVXSTR_HATCH ),
     245           0 :                                                         CUI_RESSTR( RID_SVXSTR_ASK_CHANGE_HATCH ),
     246           0 :                                                         &aWarningBoxImage );
     247             :         DBG_ASSERT(aMessDlg, "Dialogdiet fail!");
     248             :         aMessDlg->SetButtonText( MESS_BTN_1,
     249           0 :                                 String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
     250             :         aMessDlg->SetButtonText( MESS_BTN_2,
     251           0 :                                 String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
     252             : 
     253           0 :         short nRet = aMessDlg->Execute();
     254             : 
     255           0 :         switch( nRet )
     256             :         {
     257             :             case RET_BTN_1:
     258             :             {
     259           0 :                 ClickModifyHdl_Impl( this );
     260             :             }
     261           0 :             break;
     262             : 
     263             :             case RET_BTN_2:
     264             :             {
     265           0 :                 ClickAddHdl_Impl( this );
     266             :             }
     267           0 :             break;
     268             : 
     269             :             case RET_CANCEL:
     270           0 :             break;
     271             :         }
     272           0 :         delete aMessDlg;
     273             :     }
     274             : 
     275           0 :     sal_uInt16 nPos = aLbHatchings.GetSelectEntryPos();
     276           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     277           0 :         *pPos = nPos;
     278           0 :     return 0L;
     279             : }
     280             : 
     281             : // -----------------------------------------------------------------------
     282             : 
     283           0 : sal_Bool SvxHatchTabPage::FillItemSet( SfxItemSet& rSet )
     284             : {
     285           0 :     if( *pDlgType == 0 && *pbAreaTP == sal_False ) // area dialog
     286             :     {
     287           0 :         if( *pPageType == PT_HATCH )
     288             :         {
     289             :             // CheckChanges(); <-- duplicate inquiry ?
     290             : 
     291           0 :             XHatch* pXHatch = NULL;
     292           0 :             String  aString;
     293           0 :             sal_uInt16  nPos = aLbHatchings.GetSelectEntryPos();
     294           0 :             if( nPos != LISTBOX_ENTRY_NOTFOUND )
     295             :             {
     296           0 :                 pXHatch = new XHatch( pHatchingList->GetHatch( nPos )->GetHatch() );
     297           0 :                 aString = aLbHatchings.GetSelectEntry();
     298             :             }
     299             :             // gradient has been (unidentifiedly) passed
     300             :             else
     301             :             {
     302           0 :                 pXHatch = new XHatch( aLbLineColor.GetSelectEntryColor(),
     303           0 :                                  (XHatchStyle) aLbLineType.GetSelectEntryPos(),
     304           0 :                                  GetCoreValue( aMtrDistance, ePoolUnit ),
     305           0 :                                  static_cast<long>(aMtrAngle.GetValue() * 10) );
     306             :             }
     307             :             DBG_ASSERT( pXHatch, "XHatch konnte nicht erzeugt werden" );
     308           0 :             rSet.Put( XFillStyleItem( XFILL_HATCH ) );
     309           0 :             rSet.Put( XFillHatchItem( aString, *pXHatch ) );
     310             : 
     311           0 :             delete pXHatch;
     312             :         }
     313             :     }
     314           0 :     return sal_True;
     315             : }
     316             : 
     317             : // -----------------------------------------------------------------------
     318             : 
     319           0 : void SvxHatchTabPage::Reset( const SfxItemSet& rSet )
     320             : {
     321           0 :     ChangeHatchHdl_Impl( this );
     322             : 
     323             :     // determine button state
     324           0 :     if( pHatchingList->Count() )
     325             :     {
     326           0 :         aBtnModify.Enable();
     327           0 :         aBtnDelete.Enable();
     328           0 :         aBtnSave.Enable();
     329             :     }
     330             :     else
     331             :     {
     332           0 :         aBtnModify.Disable();
     333           0 :         aBtnDelete.Disable();
     334           0 :         aBtnSave.Disable();
     335             :     }
     336             : 
     337           0 :     rXFSet.Put ( ( XFillColorItem& )    rSet.Get(XATTR_FILLCOLOR) );
     338           0 :     rXFSet.Put ( ( XFillBackgroundItem&)rSet.Get(XATTR_FILLBACKGROUND) );
     339           0 :     aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
     340           0 :     aCtlPreview.Invalidate();
     341           0 : }
     342             : 
     343             : // -----------------------------------------------------------------------
     344             : 
     345           0 : SfxTabPage* SvxHatchTabPage::Create( Window* pWindow,
     346             :                 const SfxItemSet& rSet )
     347             : {
     348           0 :     return new SvxHatchTabPage( pWindow, rSet );
     349             : }
     350             : 
     351             : //------------------------------------------------------------------------
     352             : 
     353           0 : IMPL_LINK( SvxHatchTabPage, ModifiedHdl_Impl, void *, p )
     354             : {
     355           0 :     if( p == &aMtrAngle )
     356             :     {
     357           0 :         switch( aMtrAngle.GetValue() )
     358             :         {
     359           0 :             case 135: aCtlAngle.SetActualRP( RP_LT ); break;
     360           0 :             case  90: aCtlAngle.SetActualRP( RP_MT ); break;
     361           0 :             case  45: aCtlAngle.SetActualRP( RP_RT ); break;
     362           0 :             case 180: aCtlAngle.SetActualRP( RP_LM ); break;
     363           0 :             case   0: aCtlAngle.SetActualRP( RP_RM ); break;
     364           0 :             case 225: aCtlAngle.SetActualRP( RP_LB ); break;
     365           0 :             case 270: aCtlAngle.SetActualRP( RP_MB ); break;
     366           0 :             case 315: aCtlAngle.SetActualRP( RP_RB ); break;
     367           0 :             default:  aCtlAngle.SetActualRP( RP_MM ); break;
     368             :         }
     369             :     }
     370             : 
     371           0 :     XHatch aXHatch( aLbLineColor.GetSelectEntryColor(),
     372           0 :                     (XHatchStyle) aLbLineType.GetSelectEntryPos(),
     373             :                     GetCoreValue( aMtrDistance, ePoolUnit ),
     374           0 :                     static_cast<long>(aMtrAngle.GetValue() * 10) );
     375             : 
     376           0 :     rXFSet.Put( XFillHatchItem( String(), aXHatch ) );
     377           0 :     aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
     378             : 
     379           0 :     aCtlPreview.Invalidate();
     380             : 
     381           0 :     return 0L;
     382             : }
     383             : 
     384             : //------------------------------------------------------------------------
     385             : 
     386           0 : IMPL_LINK_NOARG(SvxHatchTabPage, ChangeHatchHdl_Impl)
     387             : {
     388           0 :     XHatch* pHatch = NULL;
     389           0 :     int nPos = aLbHatchings.GetSelectEntryPos();
     390             : 
     391           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     392           0 :         pHatch = new XHatch( ( (XHatchEntry*) pHatchingList->GetHatch( nPos ) )->GetHatch() );
     393             :     else
     394             :     {
     395           0 :         const SfxPoolItem* pPoolItem = NULL;
     396           0 :         if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), sal_True, &pPoolItem ) )
     397             :         {
     398           0 :             if( ( XFILL_HATCH == (XFillStyle) ( ( const XFillStyleItem* ) pPoolItem )->GetValue() ) &&
     399           0 :                 ( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLHATCH ), sal_True, &pPoolItem ) ) )
     400             :             {
     401           0 :                 pHatch = new XHatch( ( ( const XFillHatchItem* ) pPoolItem )->GetHatchValue() );
     402             :             }
     403             :         }
     404           0 :         if( !pHatch )
     405             :         {
     406           0 :             aLbHatchings.SelectEntryPos( 0 );
     407           0 :             nPos = aLbHatchings.GetSelectEntryPos();
     408           0 :             if( nPos != LISTBOX_ENTRY_NOTFOUND )
     409           0 :                 pHatch = new XHatch( ( (XHatchEntry*) pHatchingList->GetHatch( nPos ) )->GetHatch() );
     410             :         }
     411             :     }
     412           0 :     if( pHatch )
     413             :     {
     414             :         aLbLineType.SelectEntryPos(
     415           0 :             sal::static_int_cast< sal_uInt16 >( pHatch->GetHatchStyle() ) );
     416             :         // if the entry is not in the listbox
     417             :         // the color is added temporarily
     418           0 :         aLbLineColor.SetNoSelection();
     419           0 :         aLbLineColor.SelectEntry( pHatch->GetColor() );
     420           0 :         if( aLbLineColor.GetSelectEntryCount() == 0 )
     421             :         {
     422           0 :             aLbLineColor.InsertEntry( pHatch->GetColor(), String() );
     423           0 :             aLbLineColor.SelectEntry( pHatch->GetColor() );
     424             :         }
     425           0 :         SetMetricValue( aMtrDistance, pHatch->GetDistance(), ePoolUnit );
     426           0 :         aMtrAngle.SetValue( pHatch->GetAngle() / 10 );
     427             : 
     428           0 :         switch( aMtrAngle.GetValue() )
     429             :         {
     430           0 :             case 135: aCtlAngle.SetActualRP( RP_LT ); break;
     431           0 :             case  90: aCtlAngle.SetActualRP( RP_MT ); break;
     432           0 :             case  45: aCtlAngle.SetActualRP( RP_RT ); break;
     433           0 :             case 180: aCtlAngle.SetActualRP( RP_LM ); break;
     434           0 :             case   0: aCtlAngle.SetActualRP( RP_RM ); break;
     435           0 :             case 225: aCtlAngle.SetActualRP( RP_LB ); break;
     436           0 :             case 270: aCtlAngle.SetActualRP( RP_MB ); break;
     437           0 :             case 315: aCtlAngle.SetActualRP( RP_RB ); break;
     438           0 :             default:  aCtlAngle.SetActualRP( RP_MM ); break;
     439             :         }
     440             : 
     441             :         // fill ItemSet and pass it on to aCtlPreview
     442           0 :         rXFSet.Put( XFillHatchItem( String(), *pHatch ) );
     443           0 :         aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
     444             : 
     445           0 :         aCtlPreview.Invalidate();
     446           0 :         delete pHatch;
     447             :     }
     448           0 :     aMtrDistance.SaveValue();
     449           0 :     aMtrAngle.SaveValue();
     450           0 :     aLbLineType.SaveValue();
     451           0 :     aLbLineColor.SaveValue();
     452           0 :     aLbHatchings.SaveValue();
     453             : 
     454           0 :     return 0L;
     455             : }
     456             : 
     457             : //------------------------------------------------------------------------
     458             : 
     459           0 : IMPL_LINK_NOARG(SvxHatchTabPage, ClickAddHdl_Impl)
     460             : {
     461           0 :     ResMgr& rMgr = CUI_MGR();
     462           0 :     String aNewName( SVX_RES( RID_SVXSTR_HATCH ) );
     463           0 :     String aDesc( CUI_RES( RID_SVXSTR_DESC_HATCH ) );
     464           0 :     String aName;
     465             : 
     466           0 :     long nCount = pHatchingList->Count();
     467           0 :     long j = 1;
     468           0 :     sal_Bool bDifferent = sal_False;
     469             : 
     470           0 :     while( !bDifferent )
     471             :     {
     472           0 :         aName  = aNewName;
     473           0 :         aName += sal_Unicode(' ');
     474           0 :         aName += OUString::valueOf( j++ );
     475           0 :         bDifferent = sal_True;
     476             : 
     477           0 :         for( long i = 0; i < nCount && bDifferent; i++ )
     478           0 :             if( aName == pHatchingList->GetHatch( i )->GetName() )
     479           0 :                 bDifferent = sal_False;
     480             :     }
     481             : 
     482           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     483             :     DBG_ASSERT(pFact, "Dialogdiet fail!");
     484           0 :     AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
     485             :     DBG_ASSERT(pDlg, "Dialogdiet fail!");
     486           0 :     WarningBox*    pWarnBox = NULL;
     487           0 :     sal_uInt16         nError   = RID_SVXSTR_WARN_NAME_DUPLICATE;
     488             : 
     489           0 :     while( pDlg->Execute() == RET_OK )
     490             :     {
     491           0 :         pDlg->GetName( aName );
     492             : 
     493           0 :         bDifferent = sal_True;
     494             : 
     495           0 :         for( long i = 0; i < nCount && bDifferent; i++ )
     496           0 :             if( aName == pHatchingList->GetHatch( i )->GetName() )
     497           0 :                 bDifferent = sal_False;
     498             : 
     499           0 :         if( bDifferent ) {
     500           0 :             nError = 0;
     501           0 :             break;
     502             :         }
     503             : 
     504           0 :         if( !pWarnBox )
     505             :         {
     506           0 :             pWarnBox = new WarningBox( GetParentDialog(),
     507             :                                        WinBits( WB_OK_CANCEL ),
     508           0 :                                        String( ResId( nError, rMgr ) ) );
     509           0 :             pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
     510             :         }
     511             : 
     512           0 :         if( pWarnBox->Execute() != RET_OK )
     513           0 :             break;
     514             :     }
     515           0 :     delete pDlg;
     516           0 :     delete pWarnBox;
     517             : 
     518           0 :     if( !nError )
     519             :     {
     520           0 :         XHatch aXHatch( aLbLineColor.GetSelectEntryColor(),
     521           0 :                         (XHatchStyle) aLbLineType.GetSelectEntryPos(),
     522             :                         GetCoreValue( aMtrDistance, ePoolUnit ),
     523           0 :                         static_cast<long>(aMtrAngle.GetValue() * 10) );
     524           0 :         XHatchEntry* pEntry = new XHatchEntry( aXHatch, aName );
     525             : 
     526           0 :         pHatchingList->Insert( pEntry, nCount );
     527             : 
     528           0 :         aLbHatchings.Append( pEntry );
     529             : 
     530           0 :         aLbHatchings.SelectEntryPos( aLbHatchings.GetEntryCount() - 1 );
     531             : 
     532             : #ifdef WNT
     533             :         // hack: #31355# W.P.
     534             :         Rectangle aRect( aLbHatchings.GetPosPixel(), aLbHatchings.GetSizePixel() );
     535             :         if( sal_True ) {                // ??? overlapped with pDlg
     536             :                                     // and srolling
     537             :             Invalidate( aRect );
     538             :         }
     539             : #endif
     540             : 
     541           0 :         *pnHatchingListState |= CT_MODIFIED;
     542             : 
     543           0 :         ChangeHatchHdl_Impl( this );
     544             :     }
     545             : 
     546             :     // determine button state
     547           0 :     if( pHatchingList->Count() )
     548             :     {
     549           0 :         aBtnModify.Enable();
     550           0 :         aBtnDelete.Enable();
     551           0 :         aBtnSave.Enable();
     552             :     }
     553           0 :     return 0L;
     554             : }
     555             : 
     556             : //------------------------------------------------------------------------
     557             : 
     558           0 : IMPL_LINK_NOARG(SvxHatchTabPage, ClickModifyHdl_Impl)
     559             : {
     560           0 :     sal_uInt16 nPos = aLbHatchings.GetSelectEntryPos();
     561             : 
     562           0 :     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
     563             :     {
     564           0 :         ResMgr& rMgr = CUI_MGR();
     565           0 :         String aNewName( SVX_RES( RID_SVXSTR_HATCH ) );
     566           0 :         String aDesc( CUI_RES( RID_SVXSTR_DESC_HATCH ) );
     567           0 :         String aName( pHatchingList->GetHatch( nPos )->GetName() );
     568           0 :         String aOldName = aName;
     569             : 
     570           0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     571             :         DBG_ASSERT(pFact, "Dialogdiet fail!");
     572           0 :         AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
     573             :         DBG_ASSERT(pDlg, "Dialogdiet fail!");
     574             : 
     575           0 :         long nCount = pHatchingList->Count();
     576           0 :         sal_Bool bDifferent = sal_False;
     577           0 :         sal_Bool bLoop = sal_True;
     578           0 :         while( bLoop && pDlg->Execute() == RET_OK )
     579             :         {
     580           0 :             pDlg->GetName( aName );
     581           0 :             bDifferent = sal_True;
     582             : 
     583           0 :             for( long i = 0; i < nCount && bDifferent; i++ )
     584             :             {
     585           0 :                 if( aName == pHatchingList->GetHatch( i )->GetName() &&
     586           0 :                     aName != aOldName )
     587           0 :                     bDifferent = sal_False;
     588             :             }
     589             : 
     590           0 :             if( bDifferent )
     591             :             {
     592           0 :                 bLoop = sal_False;
     593           0 :                 XHatch aXHatch( aLbLineColor.GetSelectEntryColor(),
     594           0 :                                 (XHatchStyle) aLbLineType.GetSelectEntryPos(),
     595             :                                  GetCoreValue( aMtrDistance, ePoolUnit ),
     596           0 :                                 static_cast<long>(aMtrAngle.GetValue() * 10) );
     597             : 
     598           0 :                 XHatchEntry* pEntry = new XHatchEntry( aXHatch, aName );
     599             : 
     600           0 :                 delete pHatchingList->Replace( pEntry, nPos );
     601             : 
     602           0 :                 aLbHatchings.Modify( pEntry, nPos );
     603             : 
     604           0 :                 aLbHatchings.SelectEntryPos( nPos );
     605             : 
     606             :                 // save values for changes recognition (-> method)
     607           0 :                 aMtrDistance.SaveValue();
     608           0 :                 aMtrAngle.SaveValue();
     609           0 :                 aLbLineType.SaveValue();
     610           0 :                 aLbLineColor.SaveValue();
     611           0 :                 aLbHatchings.SaveValue();
     612             : 
     613           0 :                 *pnHatchingListState |= CT_MODIFIED;
     614             :             }
     615             :             else
     616             :             {
     617           0 :                 WarningBox aBox( GetParentDialog(), WinBits( WB_OK ),String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
     618           0 :                 aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
     619           0 :                 aBox.Execute();
     620             :             }
     621             :         }
     622           0 :         delete( pDlg );
     623             :     }
     624           0 :     return 0L;
     625             : }
     626             : 
     627             : //------------------------------------------------------------------------
     628             : 
     629           0 : IMPL_LINK_NOARG(SvxHatchTabPage, ClickDeleteHdl_Impl)
     630             : {
     631           0 :     sal_uInt16 nPos = aLbHatchings.GetSelectEntryPos();
     632             : 
     633           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     634             :     {
     635           0 :         QueryBox aQueryBox( GetParentDialog(), WinBits( WB_YES_NO | WB_DEF_NO ),
     636           0 :             String( CUI_RES( RID_SVXSTR_ASK_DEL_HATCH ) ) );
     637             : 
     638           0 :         if( aQueryBox.Execute() == RET_YES )
     639             :         {
     640           0 :             delete pHatchingList->Remove( nPos );
     641           0 :             aLbHatchings.RemoveEntry( nPos );
     642           0 :             aLbHatchings.SelectEntryPos( 0 );
     643             : 
     644           0 :             aCtlPreview.Invalidate();
     645             : 
     646           0 :             ChangeHatchHdl_Impl( this );
     647             : 
     648           0 :             *pnHatchingListState |= CT_MODIFIED;
     649           0 :         }
     650             :     }
     651             :     // determine button state
     652           0 :     if( !pHatchingList->Count() )
     653             :     {
     654           0 :         aBtnModify.Disable();
     655           0 :         aBtnDelete.Disable();
     656           0 :         aBtnSave.Disable();
     657             :     }
     658           0 :     return 0L;
     659             : }
     660             : 
     661             : // -----------------------------------------------------------------------
     662             : 
     663           0 : IMPL_LINK_NOARG(SvxHatchTabPage, ClickLoadHdl_Impl)
     664             : {
     665           0 :     ResMgr& rMgr = CUI_MGR();
     666           0 :     sal_uInt16 nReturn = RET_YES;
     667             : 
     668           0 :     if ( *pnHatchingListState & CT_MODIFIED )
     669             :     {
     670           0 :         nReturn = WarningBox( GetParentDialog(), WinBits( WB_YES_NO_CANCEL ),
     671           0 :             String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
     672             : 
     673           0 :         if ( nReturn == RET_YES )
     674           0 :             pHatchingList->Save();
     675             :     }
     676             : 
     677           0 :     if ( nReturn != RET_CANCEL )
     678             :     {
     679             :         ::sfx2::FileDialogHelper aDlg(
     680             :             com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
     681           0 :             0 );
     682           0 :         String aStrFilterType( "*.soh" );
     683           0 :         aDlg.AddFilter( aStrFilterType, aStrFilterType );
     684           0 :         INetURLObject aFile( SvtPathOptions().GetPalettePath() );
     685           0 :         aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
     686             : 
     687           0 :         if( aDlg.Execute() == ERRCODE_NONE )
     688             :         {
     689           0 :             INetURLObject aURL( aDlg.GetPath() );
     690           0 :             INetURLObject aPathURL( aURL );
     691             : 
     692           0 :             aPathURL.removeSegment();
     693           0 :             aPathURL.removeFinalSlash();
     694             : 
     695             :             XHatchListRef pHatchList = XPropertyList::CreatePropertyList(
     696           0 :                 XHATCH_LIST, aPathURL.GetMainURL( INetURLObject::NO_DECODE ), pXPool )->AsHatchList();
     697           0 :             pHatchList->SetName( aURL.getName() );
     698           0 :             if( pHatchList->Load() )
     699             :             {
     700           0 :                 pHatchingList = pHatchList;
     701           0 :                 ( (SvxAreaTabDialog*) GetParentDialog() )->SetNewHatchingList( pHatchingList );
     702             : 
     703           0 :                 aLbHatchings.Clear();
     704           0 :                 aLbHatchings.Fill( pHatchingList );
     705           0 :                 Reset( rOutAttrs );
     706             : 
     707           0 :                 pHatchingList->SetName( aURL.getName() );
     708             : 
     709             :                 // determining (and possibly cutting) the name
     710             :                 // and displaying it in the GroupBox
     711           0 :                 String aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
     712           0 :                 aString.AppendAscii( ": " );
     713             : 
     714           0 :                 if ( aURL.getBase().getLength() > 18 )
     715             :                 {
     716           0 :                     aString += String(aURL.getBase()).Copy( 0, 15 );
     717           0 :                     aString.AppendAscii( "..." );
     718             :                 }
     719             :                 else
     720           0 :                     aString += String(aURL.getBase());
     721             : 
     722           0 :                 *pnHatchingListState |= CT_CHANGED;
     723           0 :                 *pnHatchingListState &= ~CT_MODIFIED;
     724             :             }
     725             :             else
     726           0 :                 ErrorBox( GetParentDialog(), WinBits( WB_OK ),
     727           0 :                     String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
     728           0 :         }
     729             :     }
     730             : 
     731             :     // determine button state
     732           0 :     if ( pHatchingList->Count() )
     733             :     {
     734           0 :         aBtnModify.Enable();
     735           0 :         aBtnDelete.Enable();
     736           0 :         aBtnSave.Enable();
     737             :     }
     738             :     else
     739             :     {
     740           0 :         aBtnModify.Disable();
     741           0 :         aBtnDelete.Disable();
     742           0 :         aBtnSave.Disable();
     743             :     }
     744           0 :     return 0L;
     745             : }
     746             : 
     747             : // -----------------------------------------------------------------------
     748             : 
     749           0 : IMPL_LINK_NOARG(SvxHatchTabPage, ClickSaveHdl_Impl)
     750             : {
     751             :     ::sfx2::FileDialogHelper aDlg(
     752           0 :         com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
     753           0 :     String aStrFilterType( "*.soh" );
     754           0 :     aDlg.AddFilter( aStrFilterType, aStrFilterType );
     755             : 
     756           0 :     INetURLObject aFile( SvtPathOptions().GetPalettePath() );
     757             :     DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
     758             : 
     759           0 :     if( pHatchingList->GetName().Len() )
     760             :     {
     761           0 :         aFile.Append( pHatchingList->GetName() );
     762             : 
     763           0 :         if( aFile.getExtension().isEmpty() )
     764           0 :             aFile.SetExtension( OUString("soh") );
     765             :     }
     766             : 
     767           0 :     aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
     768           0 :     if ( aDlg.Execute() == ERRCODE_NONE )
     769             :     {
     770           0 :         INetURLObject aURL( aDlg.GetPath() );
     771           0 :         INetURLObject aPathURL( aURL );
     772             : 
     773           0 :         aPathURL.removeSegment();
     774           0 :         aPathURL.removeFinalSlash();
     775             : 
     776           0 :         pHatchingList->SetName( aURL.getName() );
     777           0 :         pHatchingList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
     778             : 
     779           0 :         if( pHatchingList->Save() )
     780             :         {
     781             :             // determining (and possibly cutting) the name
     782             :             // and displaying it in the GroupBox
     783           0 :             String aString( CUI_RES( RID_SVXSTR_TABLE ) );
     784           0 :             aString.AppendAscii( ": " );
     785             : 
     786           0 :             if ( aURL.getBase().getLength() > 18 )
     787             :             {
     788           0 :                 aString += String(aURL.getBase()).Copy( 0, 15 );
     789           0 :                 aString.AppendAscii( "..." );
     790             :             }
     791             :             else
     792           0 :                 aString += String(aURL.getBase());
     793             : 
     794           0 :             *pnHatchingListState |= CT_SAVED;
     795           0 :             *pnHatchingListState &= ~CT_MODIFIED;
     796             :         }
     797             :         else
     798             :         {
     799           0 :             ErrorBox( GetParentDialog(), WinBits( WB_OK ),
     800           0 :                 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
     801           0 :         }
     802             :     }
     803             : 
     804           0 :     return 0L;
     805             : }
     806             : 
     807             : //------------------------------------------------------------------------
     808             : 
     809           0 : void SvxHatchTabPage::PointChanged( Window* pWindow, RECT_POINT eRcPt )
     810             : {
     811           0 :     if( pWindow == &aCtlAngle )
     812             :     {
     813           0 :         switch( eRcPt )
     814             :         {
     815           0 :             case RP_LT: aMtrAngle.SetValue( 135 ); break;
     816           0 :             case RP_MT: aMtrAngle.SetValue( 90 );  break;
     817           0 :             case RP_RT: aMtrAngle.SetValue( 45 );  break;
     818           0 :             case RP_LM: aMtrAngle.SetValue( 180 ); break;
     819           0 :             case RP_RM: aMtrAngle.SetValue( 0 );   break;
     820           0 :             case RP_LB: aMtrAngle.SetValue( 225 ); break;
     821           0 :             case RP_MB: aMtrAngle.SetValue( 270 ); break;
     822           0 :             case RP_RB: aMtrAngle.SetValue( 315 ); break;
     823           0 :             case RP_MM: break;
     824             :         }
     825           0 :         ModifiedHdl_Impl( this );
     826             :     }
     827           0 : }
     828             : 
     829             : 
     830           0 : void SvxHatchTabPage::DataChanged( const DataChangedEvent& rDCEvt )
     831             : {
     832           0 :     if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
     833           0 :         aCtlPreview.SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
     834             : 
     835           0 :     SvxTabPage::DataChanged( rDCEvt );
     836           6 : }
     837             : 
     838             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10