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

Generated by: LCOV version 1.10