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

Generated by: LCOV version 1.10