1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sd.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include "fucopy.hxx" 33*cdf0e10cSrcweir #include <sfx2/progress.hxx> 34*cdf0e10cSrcweir #include <svx/svxids.hrc> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include "sdresid.hxx" 37*cdf0e10cSrcweir #include "sdattr.hxx" 38*cdf0e10cSrcweir #include "strings.hrc" 39*cdf0e10cSrcweir #include "ViewShell.hxx" 40*cdf0e10cSrcweir #include "View.hxx" 41*cdf0e10cSrcweir #include "drawdoc.hxx" 42*cdf0e10cSrcweir #include "DrawDocShell.hxx" 43*cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 44*cdf0e10cSrcweir #include <svx/svdobj.hxx> 45*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 46*cdf0e10cSrcweir #include <sfx2/app.hxx> 47*cdf0e10cSrcweir #include <svx/xcolit.hxx> 48*cdf0e10cSrcweir #include <svx/xflclit.hxx> 49*cdf0e10cSrcweir #include <svx/xdef.hxx> 50*cdf0e10cSrcweir #include <svx/xfillit0.hxx> 51*cdf0e10cSrcweir #include <sfx2/request.hxx> 52*cdf0e10cSrcweir #include "sdabstdlg.hxx" 53*cdf0e10cSrcweir #include "copydlg.hrc" 54*cdf0e10cSrcweir namespace sd { 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir TYPEINIT1( FuCopy, FuPoor ); 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir /************************************************************************* 59*cdf0e10cSrcweir |* 60*cdf0e10cSrcweir |* Konstruktor 61*cdf0e10cSrcweir |* 62*cdf0e10cSrcweir \************************************************************************/ 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir FuCopy::FuCopy ( 65*cdf0e10cSrcweir ViewShell* pViewSh, 66*cdf0e10cSrcweir ::sd::Window* pWin, 67*cdf0e10cSrcweir ::sd::View* pView, 68*cdf0e10cSrcweir SdDrawDocument* pDoc, 69*cdf0e10cSrcweir SfxRequest& rReq) 70*cdf0e10cSrcweir : FuPoor(pViewSh, pWin, pView, pDoc, rReq) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir FunctionReference FuCopy::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir FunctionReference xFunc( new FuCopy( pViewSh, pWin, pView, pDoc, rReq ) ); 77*cdf0e10cSrcweir xFunc->DoExecute(rReq); 78*cdf0e10cSrcweir return xFunc; 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir void FuCopy::DoExecute( SfxRequest& rReq ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir if( mpView->AreObjectsMarked() ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir // Undo 86*cdf0e10cSrcweir String aString( mpView->GetDescriptionOfMarkedObjects() ); 87*cdf0e10cSrcweir aString.Append( sal_Unicode(' ') ); 88*cdf0e10cSrcweir aString.Append( String( SdResId( STR_UNDO_COPYOBJECTS ) ) ); 89*cdf0e10cSrcweir mpView->BegUndo( aString ); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir const SfxItemSet* pArgs = rReq.GetArgs(); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir if( !pArgs ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir SfxItemSet aSet( mpViewShell->GetPool(), 96*cdf0e10cSrcweir ATTR_COPY_START, ATTR_COPY_END, 0 ); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir // Farb-Attribut angeben 99*cdf0e10cSrcweir SfxItemSet aAttr( mpDoc->GetPool() ); 100*cdf0e10cSrcweir mpView->GetAttributes( aAttr ); 101*cdf0e10cSrcweir const SfxPoolItem* pPoolItem = NULL; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir if( SFX_ITEM_SET == aAttr.GetItemState( XATTR_FILLSTYLE, sal_True, &pPoolItem ) ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir XFillStyle eStyle = ( ( const XFillStyleItem* ) pPoolItem )->GetValue(); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir if( eStyle == XFILL_SOLID && 108*cdf0e10cSrcweir SFX_ITEM_SET == aAttr.GetItemState( XATTR_FILLCOLOR, sal_True, &pPoolItem ) ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir const XFillColorItem* pItem = ( const XFillColorItem* ) pPoolItem; 111*cdf0e10cSrcweir XColorItem aXColorItem( ATTR_COPY_START_COLOR, pItem->GetName(), 112*cdf0e10cSrcweir pItem->GetColorValue() ); 113*cdf0e10cSrcweir aSet.Put( aXColorItem ); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); 119*cdf0e10cSrcweir if( pFact ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir AbstractCopyDlg* pDlg = pFact->CreateCopyDlg(NULL, aSet, mpDoc->GetColorTable(), mpView ); 122*cdf0e10cSrcweir if( pDlg ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir sal_uInt16 nResult = pDlg->Execute(); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir switch( nResult ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir case RET_OK: 129*cdf0e10cSrcweir pDlg->GetAttr( aSet ); 130*cdf0e10cSrcweir rReq.Done( aSet ); 131*cdf0e10cSrcweir pArgs = rReq.GetArgs(); 132*cdf0e10cSrcweir break; 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir default: 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir delete pDlg; 137*cdf0e10cSrcweir mpView->EndUndo(); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir return; // Abbruch 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir delete( pDlg ); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir Rectangle aRect; 147*cdf0e10cSrcweir sal_Int32 lWidth = 0, lHeight = 0, lSizeX = 0L, lSizeY = 0L, lAngle = 0L; 148*cdf0e10cSrcweir sal_uInt16 nNumber = 0; 149*cdf0e10cSrcweir Color aStartColor, aEndColor; 150*cdf0e10cSrcweir sal_Bool bColor = sal_False; 151*cdf0e10cSrcweir const SfxPoolItem* pPoolItem = NULL; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir // Anzahl 154*cdf0e10cSrcweir if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_NUMBER, sal_True, &pPoolItem ) ) 155*cdf0e10cSrcweir nNumber = ( ( const SfxUInt16Item* ) pPoolItem )->GetValue(); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir // Verschiebung 158*cdf0e10cSrcweir if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_MOVE_X, sal_True, &pPoolItem ) ) 159*cdf0e10cSrcweir lSizeX = ( ( const SfxInt32Item* ) pPoolItem )->GetValue(); 160*cdf0e10cSrcweir if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_MOVE_Y, sal_True, &pPoolItem ) ) 161*cdf0e10cSrcweir lSizeY = ( ( const SfxInt32Item* ) pPoolItem )->GetValue(); 162*cdf0e10cSrcweir if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_ANGLE, sal_True, &pPoolItem ) ) 163*cdf0e10cSrcweir lAngle = ( ( const SfxInt32Item* )pPoolItem )->GetValue(); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir // Verrgroesserung / Verkleinerung 166*cdf0e10cSrcweir if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_WIDTH, sal_True, &pPoolItem ) ) 167*cdf0e10cSrcweir lWidth = ( ( const SfxInt32Item* ) pPoolItem )->GetValue(); 168*cdf0e10cSrcweir if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_HEIGHT, sal_True, &pPoolItem ) ) 169*cdf0e10cSrcweir lHeight = ( ( const SfxInt32Item* ) pPoolItem )->GetValue(); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir // Startfarbe / Endfarbe 172*cdf0e10cSrcweir if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_START_COLOR, sal_True, &pPoolItem ) ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir aStartColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue(); 175*cdf0e10cSrcweir bColor = sal_True; 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_END_COLOR, sal_True, &pPoolItem ) ) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir aEndColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue(); 180*cdf0e10cSrcweir if( aStartColor == aEndColor ) 181*cdf0e10cSrcweir bColor = sal_False; 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir else 184*cdf0e10cSrcweir bColor = sal_False; 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir // Handles wegnehmen 187*cdf0e10cSrcweir //HMHmpView->HideMarkHdl(); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir SfxProgress* pProgress = NULL; 190*cdf0e10cSrcweir sal_Bool bWaiting = sal_False; 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir if( nNumber > 1 ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir String aStr( SdResId( STR_OBJECTS ) ); 195*cdf0e10cSrcweir aStr.Append( sal_Unicode(' ') ); 196*cdf0e10cSrcweir aStr.Append( String( SdResId( STR_UNDO_COPYOBJECTS ) ) ); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir pProgress = new SfxProgress( mpDocSh, aStr, nNumber ); 199*cdf0e10cSrcweir mpDocSh->SetWaitCursor( sal_True ); 200*cdf0e10cSrcweir bWaiting = sal_True; 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir const SdrMarkList aMarkList( mpView->GetMarkedObjectList() ); 204*cdf0e10cSrcweir const sal_uLong nMarkCount = aMarkList.GetMarkCount(); 205*cdf0e10cSrcweir SdrObject* pObj = NULL; 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir // Anzahl moeglicher Kopien berechnen 208*cdf0e10cSrcweir aRect = mpView->GetAllMarkedRect(); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir if( lWidth < 0L ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir long nTmp = ( aRect.Right() - aRect.Left() ) / -lWidth; 213*cdf0e10cSrcweir nNumber = (sal_uInt16) Min( nTmp, (long)nNumber ); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir if( lHeight < 0L ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir long nTmp = ( aRect.Bottom() - aRect.Top() ) / -lHeight; 219*cdf0e10cSrcweir nNumber = (sal_uInt16) Min( nTmp, (long)nNumber ); 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir for( sal_uInt16 i = 1; i <= nNumber; i++ ) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir if( pProgress ) 225*cdf0e10cSrcweir pProgress->SetState( i ); 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir aRect = mpView->GetAllMarkedRect(); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir if( ( 1 == i ) && bColor ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir SfxItemSet aNewSet( mpViewShell->GetPool(), XATTR_FILLSTYLE, XATTR_FILLCOLOR, 0L ); 232*cdf0e10cSrcweir aNewSet.Put( XFillStyleItem( XFILL_SOLID ) ); 233*cdf0e10cSrcweir aNewSet.Put( XFillColorItem( String(), aStartColor ) ); 234*cdf0e10cSrcweir mpView->SetAttributes( aNewSet ); 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir // make a copy of selected objects 238*cdf0e10cSrcweir mpView->CopyMarked(); 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir // get newly selected objects 241*cdf0e10cSrcweir SdrMarkList aCopyMarkList( mpView->GetMarkedObjectList() ); 242*cdf0e10cSrcweir sal_uLong j, nCopyMarkCount = aMarkList.GetMarkCount(); 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir // set protection flags at marked copies to null 245*cdf0e10cSrcweir for( j = 0; j < nCopyMarkCount; j++ ) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir pObj = aCopyMarkList.GetMark( j )->GetMarkedSdrObj(); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir if( pObj ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir pObj->SetMoveProtect( sal_False ); 252*cdf0e10cSrcweir pObj->SetResizeProtect( sal_False ); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir Fraction aWidth( aRect.Right() - aRect.Left() + lWidth, aRect.Right() - aRect.Left() ); 257*cdf0e10cSrcweir Fraction aHeight( aRect.Bottom() - aRect.Top() + lHeight, aRect.Bottom() - aRect.Top() ); 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir if( mpView->IsResizeAllowed() ) 260*cdf0e10cSrcweir mpView->ResizeAllMarked( aRect.TopLeft(), aWidth, aHeight ); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir if( mpView->IsRotateAllowed() ) 263*cdf0e10cSrcweir mpView->RotateAllMarked( aRect.Center(), lAngle * 100 ); 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir if( mpView->IsMoveAllowed() ) 266*cdf0e10cSrcweir mpView->MoveAllMarked( Size( lSizeX, lSizeY ) ); 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir // set protection flags at marked copies to original values 269*cdf0e10cSrcweir if( nMarkCount == nCopyMarkCount ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir for( j = 0; j < nMarkCount; j++ ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir SdrObject* pSrcObj = aMarkList.GetMark( j )->GetMarkedSdrObj(); 274*cdf0e10cSrcweir SdrObject* pDstObj = aCopyMarkList.GetMark( j )->GetMarkedSdrObj(); 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir if( pSrcObj && pDstObj && 277*cdf0e10cSrcweir ( pSrcObj->GetObjInventor() == pDstObj->GetObjInventor() ) && 278*cdf0e10cSrcweir ( pSrcObj->GetObjIdentifier() == pDstObj->GetObjIdentifier() ) ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir pDstObj->SetMoveProtect( pSrcObj->IsMoveProtect() ); 281*cdf0e10cSrcweir pDstObj->SetResizeProtect( pSrcObj->IsResizeProtect() ); 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir if( bColor ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir // Koennte man sicher noch optimieren, wuerde aber u.U. 289*cdf0e10cSrcweir // zu Rundungsfehlern fuehren 290*cdf0e10cSrcweir sal_uInt8 nRed = aStartColor.GetRed() + (sal_uInt8) ( ( (long) aEndColor.GetRed() - (long) aStartColor.GetRed() ) * (long) i / (long) nNumber ); 291*cdf0e10cSrcweir sal_uInt8 nGreen = aStartColor.GetGreen() + (sal_uInt8) ( ( (long) aEndColor.GetGreen() - (long) aStartColor.GetGreen() ) * (long) i / (long) nNumber ); 292*cdf0e10cSrcweir sal_uInt8 nBlue = aStartColor.GetBlue() + (sal_uInt8) ( ( (long) aEndColor.GetBlue() - (long) aStartColor.GetBlue() ) * (long) i / (long) nNumber ); 293*cdf0e10cSrcweir Color aNewColor( nRed, nGreen, nBlue ); 294*cdf0e10cSrcweir SfxItemSet aNewSet( mpViewShell->GetPool(), XATTR_FILLSTYLE, XATTR_FILLCOLOR, 0L ); 295*cdf0e10cSrcweir aNewSet.Put( XFillStyleItem( XFILL_SOLID ) ); 296*cdf0e10cSrcweir aNewSet.Put( XFillColorItem( String(), aNewColor ) ); 297*cdf0e10cSrcweir mpView->SetAttributes( aNewSet ); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir if ( pProgress ) 302*cdf0e10cSrcweir delete pProgress; 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir if ( bWaiting ) 305*cdf0e10cSrcweir mpDocSh->SetWaitCursor( sal_False ); 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir // Handles zeigen 308*cdf0e10cSrcweir mpView->AdjustMarkHdl(); //HMH sal_True ); 309*cdf0e10cSrcweir //HMHpView->ShowMarkHdl(); 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir mpView->EndUndo(); 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir } // end of namespace 316