LCOV - code coverage report
Current view: top level - sd/source/ui/func - fucopy.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 138 0.0 %
Date: 2014-04-14 Functions: 0 10 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 "fucopy.hxx"
      21             : #include <sfx2/progress.hxx>
      22             : #include <svx/svxids.hrc>
      23             : 
      24             : #include "sdresid.hxx"
      25             : #include "sdattr.hxx"
      26             : #include "strings.hrc"
      27             : #include "ViewShell.hxx"
      28             : #include "View.hxx"
      29             : #include "drawdoc.hxx"
      30             : #include "DrawDocShell.hxx"
      31             : #include <vcl/wrkwin.hxx>
      32             : #include <svx/svdobj.hxx>
      33             : #include <vcl/msgbox.hxx>
      34             : #include <sfx2/app.hxx>
      35             : #include <svx/xcolit.hxx>
      36             : #include <svx/xflclit.hxx>
      37             : #include <svx/xdef.hxx>
      38             : #include <svx/xfillit0.hxx>
      39             : #include <sfx2/request.hxx>
      40             : #include "sdabstdlg.hxx"
      41             : namespace sd {
      42             : 
      43           0 : TYPEINIT1( FuCopy, FuPoor );
      44             : 
      45             : 
      46           0 : FuCopy::FuCopy (
      47             :     ViewShell* pViewSh,
      48             :     ::sd::Window* pWin,
      49             :     ::sd::View* pView,
      50             :     SdDrawDocument* pDoc,
      51             :     SfxRequest& rReq)
      52           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
      53             : {
      54           0 : }
      55             : 
      56           0 : rtl::Reference<FuPoor> FuCopy::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
      57             : {
      58           0 :     rtl::Reference<FuPoor> xFunc( new FuCopy( pViewSh, pWin, pView, pDoc, rReq ) );
      59           0 :     xFunc->DoExecute(rReq);
      60           0 :     return xFunc;
      61             : }
      62             : 
      63           0 : void FuCopy::DoExecute( SfxRequest& rReq )
      64             : {
      65           0 :     if( mpView->AreObjectsMarked() )
      66             :     {
      67             :         // Undo
      68           0 :         OUString aString( mpView->GetDescriptionOfMarkedObjects() );
      69           0 :         aString += " " + SD_RESSTR( STR_UNDO_COPYOBJECTS );
      70           0 :         mpView->BegUndo( aString );
      71             : 
      72           0 :         const SfxItemSet* pArgs = rReq.GetArgs();
      73             : 
      74           0 :         if( !pArgs )
      75             :         {
      76           0 :             SfxItemSet aSet( mpViewShell->GetPool(),
      77           0 :                                 ATTR_COPY_START, ATTR_COPY_END, 0 );
      78             : 
      79             :             // indicate color attribute
      80           0 :             SfxItemSet aAttr( mpDoc->GetPool() );
      81           0 :             mpView->GetAttributes( aAttr );
      82           0 :             const SfxPoolItem*  pPoolItem = NULL;
      83             : 
      84           0 :             if( SFX_ITEM_SET == aAttr.GetItemState( XATTR_FILLSTYLE, true, &pPoolItem ) )
      85             :             {
      86           0 :                 XFillStyle eStyle = ( ( const XFillStyleItem* ) pPoolItem )->GetValue();
      87             : 
      88           0 :                 if( eStyle == XFILL_SOLID &&
      89           0 :                     SFX_ITEM_SET == aAttr.GetItemState( XATTR_FILLCOLOR, true, &pPoolItem ) )
      90             :                 {
      91           0 :                     const XFillColorItem* pItem = ( const XFillColorItem* ) pPoolItem;
      92             :                     XColorItem aXColorItem( ATTR_COPY_START_COLOR, pItem->GetName(),
      93           0 :                                                         pItem->GetColorValue() );
      94           0 :                     aSet.Put( aXColorItem );
      95             : 
      96             :                 }
      97             :             }
      98             : 
      99           0 :             SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
     100           0 :             if( pFact )
     101             :             {
     102           0 :                 AbstractCopyDlg* pDlg = pFact->CreateCopyDlg(NULL, aSet, mpDoc->GetColorList(), mpView );
     103           0 :                 if (!pDlg)
     104           0 :                     return;
     105             : 
     106           0 :                 sal_uInt16 nResult = pDlg->Execute();
     107             : 
     108           0 :                 switch( nResult )
     109             :                 {
     110             :                     case RET_OK:
     111           0 :                         pDlg->GetAttr( aSet );
     112           0 :                         rReq.Done( aSet );
     113           0 :                         pArgs = rReq.GetArgs();
     114           0 :                     break;
     115             : 
     116             :                     default:
     117             :                     {
     118           0 :                         delete pDlg;
     119           0 :                         mpView->EndUndo();
     120             :                     }
     121           0 :                     return; // Cancel
     122             :                 }
     123           0 :                 delete pDlg;
     124           0 :             }
     125             :         }
     126             : 
     127           0 :         Rectangle           aRect;
     128           0 :         sal_Int32               lWidth = 0, lHeight = 0, lSizeX = 0L, lSizeY = 0L, lAngle = 0L;
     129           0 :         sal_uInt16              nNumber = 0;
     130           0 :         Color               aStartColor, aEndColor;
     131           0 :         sal_Bool                bColor = sal_False;
     132           0 :         const SfxPoolItem*  pPoolItem = NULL;
     133             : 
     134             :         // Count
     135           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_NUMBER, true, &pPoolItem ) )
     136           0 :             nNumber = ( ( const SfxUInt16Item* ) pPoolItem )->GetValue();
     137             : 
     138             :         // translation
     139           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_MOVE_X, true, &pPoolItem ) )
     140           0 :             lSizeX = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
     141           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_MOVE_Y, true, &pPoolItem ) )
     142           0 :             lSizeY = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
     143           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_ANGLE, true, &pPoolItem ) )
     144           0 :             lAngle = ( ( const SfxInt32Item* )pPoolItem )->GetValue();
     145             : 
     146             :         // scale
     147           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_WIDTH, true, &pPoolItem ) )
     148           0 :             lWidth = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
     149           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_HEIGHT, true, &pPoolItem ) )
     150           0 :             lHeight = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
     151             : 
     152             :         // start/end color
     153           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
     154             :         {
     155           0 :             aStartColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
     156           0 :             bColor = sal_True;
     157             :         }
     158           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_END_COLOR, true, &pPoolItem ) )
     159             :         {
     160           0 :             aEndColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
     161           0 :             if( aStartColor == aEndColor )
     162           0 :                 bColor = sal_False;
     163             :         }
     164             :         else
     165           0 :             bColor = sal_False;
     166             : 
     167             :         // remove handles
     168             :         //HMHmpView->HideMarkHdl();
     169             : 
     170           0 :         SfxProgress*    pProgress = NULL;
     171           0 :         sal_Bool            bWaiting = sal_False;
     172             : 
     173           0 :         if( nNumber > 1 )
     174             :         {
     175           0 :             OUString aStr( SD_RESSTR( STR_OBJECTS ) );
     176           0 :             aStr += " " + SD_RESSTR( STR_UNDO_COPYOBJECTS );
     177             : 
     178           0 :             pProgress = new SfxProgress( mpDocSh, aStr, nNumber );
     179           0 :             mpDocSh->SetWaitCursor( true );
     180           0 :             bWaiting = sal_True;
     181             :         }
     182             : 
     183           0 :         const SdrMarkList   aMarkList( mpView->GetMarkedObjectList() );
     184           0 :         const sal_uLong         nMarkCount = aMarkList.GetMarkCount();
     185           0 :         SdrObject*          pObj = NULL;
     186             : 
     187             :         // calculate number of possible copies
     188           0 :         aRect = mpView->GetAllMarkedRect();
     189             : 
     190           0 :         if( lWidth < 0L )
     191             :         {
     192           0 :             long nTmp = ( aRect.Right() - aRect.Left() ) / -lWidth;
     193           0 :             nNumber = (sal_uInt16) std::min( nTmp, (long)nNumber );
     194             :         }
     195             : 
     196           0 :         if( lHeight < 0L )
     197             :         {
     198           0 :             long nTmp = ( aRect.Bottom() - aRect.Top() ) / -lHeight;
     199           0 :             nNumber = (sal_uInt16) std::min( nTmp, (long)nNumber );
     200             :         }
     201             : 
     202           0 :         for( sal_uInt16 i = 1; i <= nNumber; i++ )
     203             :         {
     204           0 :             if( pProgress )
     205           0 :                 pProgress->SetState( i );
     206             : 
     207           0 :             aRect = mpView->GetAllMarkedRect();
     208             : 
     209           0 :             if( ( 1 == i ) && bColor )
     210             :             {
     211           0 :                 SfxItemSet aNewSet( mpViewShell->GetPool(), XATTR_FILLSTYLE, XATTR_FILLCOLOR, 0L );
     212           0 :                 aNewSet.Put( XFillStyleItem( XFILL_SOLID ) );
     213           0 :                 aNewSet.Put( XFillColorItem( OUString(), aStartColor ) );
     214           0 :                 mpView->SetAttributes( aNewSet );
     215             :             }
     216             : 
     217             :             // make a copy of selected objects
     218           0 :             mpView->CopyMarked();
     219             : 
     220             :             // get newly selected objects
     221           0 :             SdrMarkList aCopyMarkList( mpView->GetMarkedObjectList() );
     222           0 :             sal_uLong       j, nCopyMarkCount = aMarkList.GetMarkCount();
     223             : 
     224             :             // set protection flags at marked copies to null
     225           0 :             for( j = 0; j < nCopyMarkCount; j++ )
     226             :             {
     227           0 :                 pObj = aCopyMarkList.GetMark( j )->GetMarkedSdrObj();
     228             : 
     229           0 :                 if( pObj )
     230             :                 {
     231           0 :                     pObj->SetMoveProtect( false );
     232           0 :                     pObj->SetResizeProtect( false );
     233             :                 }
     234             :             }
     235             : 
     236           0 :             Fraction aWidth( aRect.Right() - aRect.Left() + lWidth, aRect.Right() - aRect.Left() );
     237           0 :             Fraction aHeight( aRect.Bottom() - aRect.Top() + lHeight, aRect.Bottom() - aRect.Top() );
     238             : 
     239           0 :             if( mpView->IsResizeAllowed() )
     240           0 :                 mpView->ResizeAllMarked( aRect.TopLeft(), aWidth, aHeight );
     241             : 
     242           0 :             if( mpView->IsRotateAllowed() )
     243           0 :                 mpView->RotateAllMarked( aRect.Center(), lAngle * 100 );
     244             : 
     245           0 :             if( mpView->IsMoveAllowed() )
     246           0 :                 mpView->MoveAllMarked( Size( lSizeX, lSizeY ) );
     247             : 
     248             :             // set protection flags at marked copies to original values
     249           0 :             if( nMarkCount == nCopyMarkCount )
     250             :             {
     251           0 :                 for( j = 0; j < nMarkCount; j++ )
     252             :                 {
     253           0 :                     SdrObject* pSrcObj = aMarkList.GetMark( j )->GetMarkedSdrObj();
     254           0 :                     SdrObject* pDstObj = aCopyMarkList.GetMark( j )->GetMarkedSdrObj();
     255             : 
     256           0 :                     if( pSrcObj && pDstObj &&
     257           0 :                         ( pSrcObj->GetObjInventor() == pDstObj->GetObjInventor() ) &&
     258           0 :                         ( pSrcObj->GetObjIdentifier() == pDstObj->GetObjIdentifier() ) )
     259             :                     {
     260           0 :                         pDstObj->SetMoveProtect( pSrcObj->IsMoveProtect() );
     261           0 :                         pDstObj->SetResizeProtect( pSrcObj->IsResizeProtect() );
     262             :                     }
     263             :                 }
     264             :             }
     265             : 
     266           0 :             if( bColor )
     267             :             {
     268             :                 // probably room for optimizations, but may can lead to rounding errors
     269           0 :                 sal_uInt8 nRed = aStartColor.GetRed() + (sal_uInt8) ( ( (long) aEndColor.GetRed() - (long) aStartColor.GetRed() ) * (long) i / (long) nNumber  );
     270           0 :                 sal_uInt8 nGreen = aStartColor.GetGreen() + (sal_uInt8) ( ( (long) aEndColor.GetGreen() - (long) aStartColor.GetGreen() ) *  (long) i / (long) nNumber );
     271           0 :                 sal_uInt8 nBlue = aStartColor.GetBlue() + (sal_uInt8) ( ( (long) aEndColor.GetBlue() - (long) aStartColor.GetBlue() ) * (long) i / (long) nNumber );
     272           0 :                 Color aNewColor( nRed, nGreen, nBlue );
     273           0 :                 SfxItemSet aNewSet( mpViewShell->GetPool(), XATTR_FILLSTYLE, XATTR_FILLCOLOR, 0L );
     274           0 :                 aNewSet.Put( XFillStyleItem( XFILL_SOLID ) );
     275           0 :                 aNewSet.Put( XFillColorItem( OUString(), aNewColor ) );
     276           0 :                 mpView->SetAttributes( aNewSet );
     277             :             }
     278           0 :         }
     279             : 
     280           0 :         if ( pProgress )
     281           0 :             delete pProgress;
     282             : 
     283           0 :         if ( bWaiting )
     284           0 :             mpDocSh->SetWaitCursor( false );
     285             : 
     286             :         // show handles
     287           0 :         mpView->AdjustMarkHdl(); //HMH sal_True );
     288             :         //HMHpView->ShowMarkHdl();
     289             : 
     290           0 :         mpView->EndUndo();
     291             :     }
     292             : }
     293             : 
     294           0 : } // end of namespace
     295             : 
     296             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10