LCOV - code coverage report
Current view: top level - sd/source/ui/dlg - copydlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 151 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 14 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 "copydlg.hxx"
      21             : #include <comphelper/string.hxx>
      22             : #include <svx/dlgutil.hxx>
      23             : #include <sfx2/module.hxx>
      24             : #include <svx/xcolit.hxx>
      25             : #include <svx/xflclit.hxx>
      26             : #include <svx/xdef.hxx>
      27             : #include <svx/xfillit0.hxx>
      28             : #include <svx/xenum.hxx>
      29             : 
      30             : #include <sfx2/app.hxx>
      31             : 
      32             : #include "sdattr.hxx"
      33             : 
      34             : #include "View.hxx"
      35             : #include "sdresid.hxx"
      36             : #include "drawdoc.hxx"
      37             : #include "res_bmp.hrc"
      38             : 
      39             : namespace sd {
      40             : 
      41             : #define TOKEN ';'
      42             : 
      43           0 : CopyDlg::CopyDlg(vcl::Window* pWindow, const SfxItemSet& rInAttrs,
      44             :     const XColorListRef &pColList, ::sd::View* pInView)
      45             :     : SfxModalDialog(pWindow, "DuplicateDialog", "modules/sdraw/ui/copydlg.ui")
      46             :     , mrOutAttrs(rInAttrs)
      47             :     , mpColorList(pColList)
      48           0 :     , maUIScale(pInView->GetDoc().GetUIScale())
      49           0 :     , mpView(pInView)
      50             : {
      51           0 :     get(m_pNumFldCopies, "copies");
      52           0 :     get(m_pBtnSetViewData, "viewdata");
      53           0 :     get(m_pMtrFldMoveX, "x");
      54           0 :     get(m_pMtrFldMoveY, "y");
      55           0 :     get(m_pMtrFldAngle, "angle");
      56           0 :     get(m_pMtrFldWidth, "width");
      57           0 :     get(m_pMtrFldHeight, "height");
      58           0 :     get(m_pLbStartColor, "start");
      59           0 :     get(m_pFtEndColor, "endlabel");
      60           0 :     get(m_pLbEndColor, "end");
      61           0 :     get(m_pBtnSetDefault, "default");
      62             : 
      63             :     // Set up the view data button (image and accessible name).
      64           0 :     m_pBtnSetViewData->SetAccessibleName (m_pBtnSetViewData->GetQuickHelpText());
      65             : 
      66             :     // color tables
      67             :     DBG_ASSERT( mpColorList.is(), "No colortable available !" );
      68           0 :     m_pLbStartColor->Fill( mpColorList );
      69           0 :     m_pLbEndColor->CopyEntries( *m_pLbStartColor );
      70             : 
      71           0 :     m_pLbStartColor->SetSelectHdl( LINK( this, CopyDlg, SelectColorHdl ) );
      72           0 :     m_pBtnSetViewData->SetClickHdl( LINK( this, CopyDlg, SetViewData ) );
      73           0 :     m_pBtnSetDefault->SetClickHdl( LINK( this, CopyDlg, SetDefault ) );
      74             : 
      75           0 :     FieldUnit eFUnit( SfxModule::GetCurrentFieldUnit() );
      76             : 
      77           0 :     SetFieldUnit( *m_pMtrFldMoveX, eFUnit, true );
      78           0 :     SetFieldUnit( *m_pMtrFldMoveY, eFUnit, true );
      79           0 :     SetFieldUnit( *m_pMtrFldWidth, eFUnit, true );
      80           0 :     SetFieldUnit( *m_pMtrFldHeight, eFUnit, true );
      81             : 
      82           0 :     Reset();
      83           0 : }
      84             : 
      85           0 : CopyDlg::~CopyDlg()
      86             : {
      87           0 :     disposeOnce();
      88           0 : }
      89             : 
      90           0 : void CopyDlg::dispose()
      91             : {
      92           0 :     m_pNumFldCopies.clear();
      93           0 :     m_pBtnSetViewData.clear();
      94           0 :     m_pMtrFldMoveX.clear();
      95           0 :     m_pMtrFldMoveY.clear();
      96           0 :     m_pMtrFldAngle.clear();
      97           0 :     m_pMtrFldWidth.clear();
      98           0 :     m_pMtrFldHeight.clear();
      99           0 :     m_pLbStartColor.clear();
     100           0 :     m_pFtEndColor.clear();
     101           0 :     m_pLbEndColor.clear();
     102           0 :     m_pBtnSetDefault.clear();
     103           0 :     SfxModalDialog::dispose();
     104           0 : }
     105             : 
     106             : /**
     107             :  * reads provided item set or evaluate ini string
     108             :  */
     109           0 : void CopyDlg::Reset()
     110             : {
     111           0 :     const SfxPoolItem* pPoolItem = NULL;
     112           0 :     OUString aStr( GetExtraData() );
     113             : 
     114           0 :     if (comphelper::string::getTokenCount(aStr, TOKEN) < 8)
     115             :     {
     116           0 :         if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_NUMBER, true, &pPoolItem ) )
     117           0 :             m_pNumFldCopies->SetValue( static_cast<const SfxUInt16Item*>( pPoolItem )->GetValue() );
     118             :         else
     119           0 :             m_pNumFldCopies->SetValue( 1L );
     120             : 
     121           0 :         long nMoveX = 500L;
     122           0 :         if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_X, true, &pPoolItem ) )
     123           0 :             nMoveX = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
     124           0 :         SetMetricValue( *m_pMtrFldMoveX, Fraction(nMoveX) / maUIScale, SFX_MAPUNIT_100TH_MM);
     125             : 
     126           0 :         long nMoveY = 500L;
     127           0 :         if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_Y, true, &pPoolItem ) )
     128           0 :             nMoveY = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
     129           0 :         SetMetricValue( *m_pMtrFldMoveY, Fraction(nMoveY) / maUIScale, SFX_MAPUNIT_100TH_MM);
     130             : 
     131           0 :         if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_ANGLE, true, &pPoolItem ) )
     132           0 :             m_pMtrFldAngle->SetValue( static_cast<const SfxInt32Item*>( pPoolItem )->GetValue() );
     133             :         else
     134           0 :             m_pMtrFldAngle->SetValue( 0L );
     135             : 
     136           0 :         long nWidth = 0L;
     137           0 :         if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_WIDTH, true, &pPoolItem ) )
     138           0 :             nWidth = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
     139           0 :         SetMetricValue( *m_pMtrFldWidth, Fraction(nWidth) / maUIScale, SFX_MAPUNIT_100TH_MM);
     140             : 
     141           0 :         long nHeight = 0L;
     142           0 :         if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_HEIGHT, true, &pPoolItem ) )
     143           0 :             nHeight = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
     144           0 :         SetMetricValue( *m_pMtrFldHeight, Fraction(nHeight) / maUIScale, SFX_MAPUNIT_100TH_MM);
     145             : 
     146           0 :         if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
     147             :         {
     148           0 :             Color aColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
     149           0 :             m_pLbStartColor->SelectEntry( aColor );
     150           0 :             m_pLbEndColor->SelectEntry( aColor );
     151             :         }
     152             :         else
     153             :         {
     154           0 :             m_pLbStartColor->SetNoSelection();
     155           0 :             m_pLbEndColor->SetNoSelection();
     156           0 :             m_pLbEndColor->Disable();
     157           0 :             m_pFtEndColor->Disable();
     158             :         }
     159             :     }
     160             :     else
     161             :     {
     162             :         long nTmp;
     163           0 :         nTmp = (long)aStr.getToken( 0, TOKEN ).toInt32();
     164           0 :         m_pNumFldCopies->SetValue( nTmp );
     165             : 
     166           0 :         nTmp = (long)aStr.getToken( 1, TOKEN ).toInt32();
     167           0 :         m_pMtrFldMoveX->SetValue( nTmp );
     168             : 
     169           0 :         nTmp = (long)aStr.getToken( 2, TOKEN ).toInt32();
     170           0 :         m_pMtrFldMoveY->SetValue( nTmp );
     171             : 
     172           0 :         nTmp = (long)aStr.getToken( 3, TOKEN ).toInt32();
     173           0 :         m_pMtrFldAngle->SetValue( nTmp );
     174             : 
     175           0 :         nTmp = (long)aStr.getToken( 4, TOKEN ).toInt32();
     176           0 :         m_pMtrFldWidth->SetValue( nTmp );
     177             : 
     178           0 :         nTmp = (long)aStr.getToken( 5, TOKEN ).toInt32();
     179           0 :         m_pMtrFldHeight->SetValue( nTmp );
     180             : 
     181           0 :         nTmp = (long)aStr.getToken( 6, TOKEN ).toInt32();
     182           0 :         m_pLbStartColor->SelectEntry( Color( nTmp ) );
     183             : 
     184           0 :         nTmp = (long)aStr.getToken( 7, TOKEN ).toInt32();
     185           0 :         m_pLbEndColor->SelectEntry( Color( nTmp ) );
     186           0 :     }
     187             : 
     188           0 : }
     189             : 
     190             : /**
     191             :  * fills provided item set with dialog box attributes
     192             :  */
     193           0 : void CopyDlg::GetAttr( SfxItemSet& rOutAttrs )
     194             : {
     195           0 :     long nMoveX = Fraction( GetCoreValue( *m_pMtrFldMoveX, SFX_MAPUNIT_100TH_MM) ) * maUIScale;
     196           0 :     long nMoveY = Fraction( GetCoreValue( *m_pMtrFldMoveY, SFX_MAPUNIT_100TH_MM) ) * maUIScale;
     197           0 :     long nHeight = Fraction( GetCoreValue( *m_pMtrFldHeight, SFX_MAPUNIT_100TH_MM) ) * maUIScale;
     198           0 :     long nWidth  = Fraction( GetCoreValue( *m_pMtrFldWidth, SFX_MAPUNIT_100TH_MM) ) * maUIScale;
     199             : 
     200           0 :     rOutAttrs.Put( SfxUInt16Item( ATTR_COPY_NUMBER, (sal_uInt16) m_pNumFldCopies->GetValue() ) );
     201           0 :     rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_X, nMoveX ) );
     202           0 :     rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_Y, nMoveY ) );
     203           0 :     rOutAttrs.Put( SfxInt32Item( ATTR_COPY_ANGLE, static_cast<sal_Int32>(m_pMtrFldAngle->GetValue()) ) );
     204           0 :     rOutAttrs.Put( SfxInt32Item( ATTR_COPY_WIDTH, nWidth ) );
     205           0 :     rOutAttrs.Put( SfxInt32Item( ATTR_COPY_HEIGHT, nHeight ) );
     206             : 
     207           0 :     if( m_pLbStartColor->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
     208             :     {
     209           0 :         XColorItem aXColorItem( ATTR_COPY_START_COLOR, m_pLbStartColor->GetSelectEntry(),
     210           0 :                                     m_pLbStartColor->GetSelectEntryColor() );
     211           0 :         rOutAttrs.Put( aXColorItem );
     212             :     }
     213           0 :     if( m_pLbEndColor->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
     214             :     {
     215           0 :         XColorItem aXColorItem( ATTR_COPY_END_COLOR, m_pLbEndColor->GetSelectEntry(),
     216           0 :                                     m_pLbEndColor->GetSelectEntryColor() );
     217           0 :         rOutAttrs.Put( aXColorItem );
     218             :     }
     219           0 : }
     220             : 
     221             : /**
     222             :  * enables and selects end color LB
     223             :  */
     224           0 : IMPL_LINK_NOARG(CopyDlg, SelectColorHdl)
     225             : {
     226           0 :     sal_Int32 nPos = m_pLbStartColor->GetSelectEntryPos();
     227             : 
     228           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND &&
     229           0 :         !m_pLbEndColor->IsEnabled() )
     230             :     {
     231           0 :         m_pLbEndColor->SelectEntryPos( nPos );
     232           0 :         m_pLbEndColor->Enable();
     233           0 :         m_pFtEndColor->Enable();
     234             :     }
     235           0 :     return 0;
     236             : }
     237             : 
     238             : /**
     239             :  * sets values of selection
     240             :  */
     241           0 : IMPL_LINK_NOARG(CopyDlg, SetViewData)
     242             : {
     243           0 :     Rectangle aRect = mpView->GetAllMarkedRect();
     244             : 
     245           0 :     SetMetricValue( *m_pMtrFldMoveX, Fraction( aRect.GetWidth() ) /
     246           0 :                                     maUIScale, SFX_MAPUNIT_100TH_MM);
     247           0 :     SetMetricValue( *m_pMtrFldMoveY, Fraction( aRect.GetHeight() ) /
     248           0 :                                     maUIScale, SFX_MAPUNIT_100TH_MM);
     249             : 
     250             :     // sets color attribute
     251           0 :     const SfxPoolItem*  pPoolItem = NULL;
     252           0 :     if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
     253             :     {
     254           0 :         Color aColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
     255           0 :         m_pLbStartColor->SelectEntry( aColor );
     256             :     }
     257             : 
     258           0 :     return 0;
     259             : }
     260             : 
     261             : /**
     262             :  * resets values to default
     263             :  */
     264           0 : IMPL_LINK_NOARG(CopyDlg, SetDefault)
     265             : {
     266           0 :     m_pNumFldCopies->SetValue( 1L );
     267             : 
     268           0 :     long nValue = 500L;
     269           0 :     SetMetricValue( *m_pMtrFldMoveX, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM);
     270           0 :     SetMetricValue( *m_pMtrFldMoveY, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM);
     271             : 
     272           0 :     nValue = 0L;
     273           0 :     m_pMtrFldAngle->SetValue( nValue );
     274           0 :     SetMetricValue( *m_pMtrFldWidth, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM);
     275           0 :     SetMetricValue( *m_pMtrFldHeight, Fraction(nValue) / maUIScale, SFX_MAPUNIT_100TH_MM);
     276             : 
     277             :     // set color attribute
     278           0 :     const SfxPoolItem*  pPoolItem = NULL;
     279           0 :     if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
     280             :     {
     281           0 :         Color aColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
     282           0 :         m_pLbStartColor->SelectEntry( aColor );
     283           0 :         m_pLbEndColor->SelectEntry( aColor );
     284             :     }
     285             : 
     286           0 :     return 0;
     287             : }
     288             : 
     289           0 : } // end of namespace sd
     290             : 
     291             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11