LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/func - fucopy.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 139 0.7 %
Date: 2012-12-27 Functions: 2 10 20.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             : #include "copydlg.hrc"
      42             : namespace sd {
      43             : 
      44           0 : TYPEINIT1( FuCopy, FuPoor );
      45             : 
      46             : /*************************************************************************
      47             : |*
      48             : |* Konstruktor
      49             : |*
      50             : \************************************************************************/
      51             : 
      52           0 : FuCopy::FuCopy (
      53             :     ViewShell* pViewSh,
      54             :     ::sd::Window* pWin,
      55             :     ::sd::View* pView,
      56             :     SdDrawDocument* pDoc,
      57             :     SfxRequest& rReq)
      58           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
      59             : {
      60           0 : }
      61             : 
      62           0 : FunctionReference FuCopy::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
      63             : {
      64           0 :     FunctionReference xFunc( new FuCopy( pViewSh, pWin, pView, pDoc, rReq ) );
      65           0 :     xFunc->DoExecute(rReq);
      66           0 :     return xFunc;
      67             : }
      68             : 
      69           0 : void FuCopy::DoExecute( SfxRequest& rReq )
      70             : {
      71           0 :     if( mpView->AreObjectsMarked() )
      72             :     {
      73             :         // Undo
      74           0 :         String aString( mpView->GetDescriptionOfMarkedObjects() );
      75           0 :         aString.Append( sal_Unicode(' ') );
      76           0 :         aString.Append( String( SdResId( STR_UNDO_COPYOBJECTS ) ) );
      77           0 :         mpView->BegUndo( aString );
      78             : 
      79           0 :         const SfxItemSet* pArgs = rReq.GetArgs();
      80             : 
      81           0 :         if( !pArgs )
      82             :         {
      83           0 :             SfxItemSet aSet( mpViewShell->GetPool(),
      84           0 :                                 ATTR_COPY_START, ATTR_COPY_END, 0 );
      85             : 
      86             :             // Farb-Attribut angeben
      87           0 :             SfxItemSet aAttr( mpDoc->GetPool() );
      88           0 :             mpView->GetAttributes( aAttr );
      89           0 :             const SfxPoolItem*  pPoolItem = NULL;
      90             : 
      91           0 :             if( SFX_ITEM_SET == aAttr.GetItemState( XATTR_FILLSTYLE, sal_True, &pPoolItem ) )
      92             :             {
      93           0 :                 XFillStyle eStyle = ( ( const XFillStyleItem* ) pPoolItem )->GetValue();
      94             : 
      95           0 :                 if( eStyle == XFILL_SOLID &&
      96           0 :                     SFX_ITEM_SET == aAttr.GetItemState( XATTR_FILLCOLOR, sal_True, &pPoolItem ) )
      97             :                 {
      98           0 :                     const XFillColorItem* pItem = ( const XFillColorItem* ) pPoolItem;
      99             :                     XColorItem aXColorItem( ATTR_COPY_START_COLOR, pItem->GetName(),
     100           0 :                                                         pItem->GetColorValue() );
     101           0 :                     aSet.Put( aXColorItem );
     102             : 
     103             :                 }
     104             :             }
     105             : 
     106           0 :             SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
     107           0 :             if( pFact )
     108             :             {
     109           0 :                 AbstractCopyDlg* pDlg = pFact->CreateCopyDlg(NULL, aSet, mpDoc->GetColorList(), mpView );
     110           0 :                 if( pDlg )
     111             :                 {
     112           0 :                     sal_uInt16 nResult = pDlg->Execute();
     113             : 
     114           0 :                     switch( nResult )
     115             :                     {
     116             :                         case RET_OK:
     117           0 :                             pDlg->GetAttr( aSet );
     118           0 :                             rReq.Done( aSet );
     119           0 :                             pArgs = rReq.GetArgs();
     120           0 :                         break;
     121             : 
     122             :                         default:
     123             :                         {
     124           0 :                             delete pDlg;
     125           0 :                             mpView->EndUndo();
     126             :                         }
     127           0 :                         return; // Abbruch
     128             :                     }
     129           0 :                     delete( pDlg );
     130             :                 }
     131           0 :             }
     132             :         }
     133             : 
     134           0 :         Rectangle           aRect;
     135           0 :         sal_Int32               lWidth = 0, lHeight = 0, lSizeX = 0L, lSizeY = 0L, lAngle = 0L;
     136           0 :         sal_uInt16              nNumber = 0;
     137           0 :         Color               aStartColor, aEndColor;
     138           0 :         sal_Bool                bColor = sal_False;
     139           0 :         const SfxPoolItem*  pPoolItem = NULL;
     140             : 
     141             :         // Anzahl
     142           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_NUMBER, sal_True, &pPoolItem ) )
     143           0 :             nNumber = ( ( const SfxUInt16Item* ) pPoolItem )->GetValue();
     144             : 
     145             :         // Verschiebung
     146           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_MOVE_X, sal_True, &pPoolItem ) )
     147           0 :             lSizeX = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
     148           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_MOVE_Y, sal_True, &pPoolItem ) )
     149           0 :             lSizeY = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
     150           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_ANGLE, sal_True, &pPoolItem ) )
     151           0 :             lAngle = ( ( const SfxInt32Item* )pPoolItem )->GetValue();
     152             : 
     153             :         // Verrgroesserung / Verkleinerung
     154           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_WIDTH, sal_True, &pPoolItem ) )
     155           0 :             lWidth = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
     156           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_HEIGHT, sal_True, &pPoolItem ) )
     157           0 :             lHeight = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
     158             : 
     159             :         // Startfarbe / Endfarbe
     160           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_START_COLOR, sal_True, &pPoolItem ) )
     161             :         {
     162           0 :             aStartColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
     163           0 :             bColor = sal_True;
     164             :         }
     165           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_END_COLOR, sal_True, &pPoolItem ) )
     166             :         {
     167           0 :             aEndColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
     168           0 :             if( aStartColor == aEndColor )
     169           0 :                 bColor = sal_False;
     170             :         }
     171             :         else
     172           0 :             bColor = sal_False;
     173             : 
     174             :         // Handles wegnehmen
     175             :         //HMHmpView->HideMarkHdl();
     176             : 
     177           0 :         SfxProgress*    pProgress = NULL;
     178           0 :         sal_Bool            bWaiting = sal_False;
     179             : 
     180           0 :         if( nNumber > 1 )
     181             :         {
     182           0 :             String aStr( SdResId( STR_OBJECTS ) );
     183           0 :             aStr.Append( sal_Unicode(' ') );
     184           0 :             aStr.Append( String( SdResId( STR_UNDO_COPYOBJECTS ) ) );
     185             : 
     186           0 :             pProgress = new SfxProgress( mpDocSh, aStr, nNumber );
     187           0 :             mpDocSh->SetWaitCursor( sal_True );
     188           0 :             bWaiting = sal_True;
     189             :         }
     190             : 
     191           0 :         const SdrMarkList   aMarkList( mpView->GetMarkedObjectList() );
     192           0 :         const sal_uLong         nMarkCount = aMarkList.GetMarkCount();
     193           0 :         SdrObject*          pObj = NULL;
     194             : 
     195             :         // Anzahl moeglicher Kopien berechnen
     196           0 :         aRect = mpView->GetAllMarkedRect();
     197             : 
     198           0 :         if( lWidth < 0L )
     199             :         {
     200           0 :             long nTmp = ( aRect.Right() - aRect.Left() ) / -lWidth;
     201           0 :             nNumber = (sal_uInt16) Min( nTmp, (long)nNumber );
     202             :         }
     203             : 
     204           0 :         if( lHeight < 0L )
     205             :         {
     206           0 :             long nTmp = ( aRect.Bottom() - aRect.Top() ) / -lHeight;
     207           0 :             nNumber = (sal_uInt16) Min( nTmp, (long)nNumber );
     208             :         }
     209             : 
     210           0 :         for( sal_uInt16 i = 1; i <= nNumber; i++ )
     211             :         {
     212           0 :             if( pProgress )
     213           0 :                 pProgress->SetState( i );
     214             : 
     215           0 :             aRect = mpView->GetAllMarkedRect();
     216             : 
     217           0 :             if( ( 1 == i ) && bColor )
     218             :             {
     219           0 :                 SfxItemSet aNewSet( mpViewShell->GetPool(), XATTR_FILLSTYLE, XATTR_FILLCOLOR, 0L );
     220           0 :                 aNewSet.Put( XFillStyleItem( XFILL_SOLID ) );
     221           0 :                 aNewSet.Put( XFillColorItem( String(), aStartColor ) );
     222           0 :                 mpView->SetAttributes( aNewSet );
     223             :             }
     224             : 
     225             :             // make a copy of selected objects
     226           0 :             mpView->CopyMarked();
     227             : 
     228             :             // get newly selected objects
     229           0 :             SdrMarkList aCopyMarkList( mpView->GetMarkedObjectList() );
     230           0 :             sal_uLong       j, nCopyMarkCount = aMarkList.GetMarkCount();
     231             : 
     232             :             // set protection flags at marked copies to null
     233           0 :             for( j = 0; j < nCopyMarkCount; j++ )
     234             :             {
     235           0 :                 pObj = aCopyMarkList.GetMark( j )->GetMarkedSdrObj();
     236             : 
     237           0 :                 if( pObj )
     238             :                 {
     239           0 :                     pObj->SetMoveProtect( sal_False );
     240           0 :                     pObj->SetResizeProtect( sal_False );
     241             :                 }
     242             :             }
     243             : 
     244           0 :             Fraction aWidth( aRect.Right() - aRect.Left() + lWidth, aRect.Right() - aRect.Left() );
     245           0 :             Fraction aHeight( aRect.Bottom() - aRect.Top() + lHeight, aRect.Bottom() - aRect.Top() );
     246             : 
     247           0 :             if( mpView->IsResizeAllowed() )
     248           0 :                 mpView->ResizeAllMarked( aRect.TopLeft(), aWidth, aHeight );
     249             : 
     250           0 :             if( mpView->IsRotateAllowed() )
     251           0 :                 mpView->RotateAllMarked( aRect.Center(), lAngle * 100 );
     252             : 
     253           0 :             if( mpView->IsMoveAllowed() )
     254           0 :                 mpView->MoveAllMarked( Size( lSizeX, lSizeY ) );
     255             : 
     256             :             // set protection flags at marked copies to original values
     257           0 :             if( nMarkCount == nCopyMarkCount )
     258             :             {
     259           0 :                 for( j = 0; j < nMarkCount; j++ )
     260             :                 {
     261           0 :                     SdrObject* pSrcObj = aMarkList.GetMark( j )->GetMarkedSdrObj();
     262           0 :                     SdrObject* pDstObj = aCopyMarkList.GetMark( j )->GetMarkedSdrObj();
     263             : 
     264           0 :                     if( pSrcObj && pDstObj &&
     265           0 :                         ( pSrcObj->GetObjInventor() == pDstObj->GetObjInventor() ) &&
     266           0 :                         ( pSrcObj->GetObjIdentifier() == pDstObj->GetObjIdentifier() ) )
     267             :                     {
     268           0 :                         pDstObj->SetMoveProtect( pSrcObj->IsMoveProtect() );
     269           0 :                         pDstObj->SetResizeProtect( pSrcObj->IsResizeProtect() );
     270             :                     }
     271             :                 }
     272             :             }
     273             : 
     274           0 :             if( bColor )
     275             :             {
     276             :                 // Koennte man sicher noch optimieren, wuerde aber u.U.
     277             :                 // zu Rundungsfehlern fuehren
     278           0 :                 sal_uInt8 nRed = aStartColor.GetRed() + (sal_uInt8) ( ( (long) aEndColor.GetRed() - (long) aStartColor.GetRed() ) * (long) i / (long) nNumber  );
     279           0 :                 sal_uInt8 nGreen = aStartColor.GetGreen() + (sal_uInt8) ( ( (long) aEndColor.GetGreen() - (long) aStartColor.GetGreen() ) *  (long) i / (long) nNumber );
     280           0 :                 sal_uInt8 nBlue = aStartColor.GetBlue() + (sal_uInt8) ( ( (long) aEndColor.GetBlue() - (long) aStartColor.GetBlue() ) * (long) i / (long) nNumber );
     281           0 :                 Color aNewColor( nRed, nGreen, nBlue );
     282           0 :                 SfxItemSet aNewSet( mpViewShell->GetPool(), XATTR_FILLSTYLE, XATTR_FILLCOLOR, 0L );
     283           0 :                 aNewSet.Put( XFillStyleItem( XFILL_SOLID ) );
     284           0 :                 aNewSet.Put( XFillColorItem( String(), aNewColor ) );
     285           0 :                 mpView->SetAttributes( aNewSet );
     286             :             }
     287           0 :         }
     288             : 
     289           0 :         if ( pProgress )
     290           0 :             delete pProgress;
     291             : 
     292           0 :         if ( bWaiting )
     293           0 :             mpDocSh->SetWaitCursor( sal_False );
     294             : 
     295             :         // Handles zeigen
     296           0 :         mpView->AdjustMarkHdl(); //HMH sal_True );
     297             :         //HMHpView->ShowMarkHdl();
     298             : 
     299           0 :         mpView->EndUndo();
     300             :     }
     301             : }
     302             : 
     303           9 : } // end of namespace
     304             : 
     305             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10