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

Generated by: LCOV version 1.10