bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / func / fucopy.cxx
blobf59cd73cdd1ff8f10607ad43f209fbf03bc37d14
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "fucopy.hxx"
21 #include <sfx2/progress.hxx>
22 #include <svx/svxids.hrc>
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 {
43 TYPEINIT1( FuCopy, FuPoor );
46 FuCopy::FuCopy (
47 ViewShell* pViewSh,
48 ::sd::Window* pWin,
49 ::sd::View* pView,
50 SdDrawDocument* pDoc,
51 SfxRequest& rReq)
52 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
56 FunctionReference FuCopy::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
58 FunctionReference xFunc( new FuCopy( pViewSh, pWin, pView, pDoc, rReq ) );
59 xFunc->DoExecute(rReq);
60 return xFunc;
63 void FuCopy::DoExecute( SfxRequest& rReq )
65 if( mpView->AreObjectsMarked() )
67 // Undo
68 String aString( mpView->GetDescriptionOfMarkedObjects() );
69 aString.Append( sal_Unicode(' ') );
70 aString.Append( String( SdResId( STR_UNDO_COPYOBJECTS ) ) );
71 mpView->BegUndo( aString );
73 const SfxItemSet* pArgs = rReq.GetArgs();
75 if( !pArgs )
77 SfxItemSet aSet( mpViewShell->GetPool(),
78 ATTR_COPY_START, ATTR_COPY_END, 0 );
80 // indicate color attribute
81 SfxItemSet aAttr( mpDoc->GetPool() );
82 mpView->GetAttributes( aAttr );
83 const SfxPoolItem* pPoolItem = NULL;
85 if( SFX_ITEM_SET == aAttr.GetItemState( XATTR_FILLSTYLE, sal_True, &pPoolItem ) )
87 XFillStyle eStyle = ( ( const XFillStyleItem* ) pPoolItem )->GetValue();
89 if( eStyle == XFILL_SOLID &&
90 SFX_ITEM_SET == aAttr.GetItemState( XATTR_FILLCOLOR, sal_True, &pPoolItem ) )
92 const XFillColorItem* pItem = ( const XFillColorItem* ) pPoolItem;
93 XColorItem aXColorItem( ATTR_COPY_START_COLOR, pItem->GetName(),
94 pItem->GetColorValue() );
95 aSet.Put( aXColorItem );
100 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
101 if( pFact )
103 AbstractCopyDlg* pDlg = pFact->CreateCopyDlg(NULL, aSet, mpDoc->GetColorList(), mpView );
104 if( pDlg )
106 sal_uInt16 nResult = pDlg->Execute();
108 switch( nResult )
110 case RET_OK:
111 pDlg->GetAttr( aSet );
112 rReq.Done( aSet );
113 pArgs = rReq.GetArgs();
114 break;
116 default:
118 delete pDlg;
119 mpView->EndUndo();
121 return; // Cancel
123 delete( pDlg );
128 Rectangle aRect;
129 sal_Int32 lWidth = 0, lHeight = 0, lSizeX = 0L, lSizeY = 0L, lAngle = 0L;
130 sal_uInt16 nNumber = 0;
131 Color aStartColor, aEndColor;
132 sal_Bool bColor = sal_False;
133 const SfxPoolItem* pPoolItem = NULL;
135 // Count
136 if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_NUMBER, sal_True, &pPoolItem ) )
137 nNumber = ( ( const SfxUInt16Item* ) pPoolItem )->GetValue();
139 // translation
140 if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_MOVE_X, sal_True, &pPoolItem ) )
141 lSizeX = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
142 if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_MOVE_Y, sal_True, &pPoolItem ) )
143 lSizeY = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
144 if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_ANGLE, sal_True, &pPoolItem ) )
145 lAngle = ( ( const SfxInt32Item* )pPoolItem )->GetValue();
147 // scale
148 if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_WIDTH, sal_True, &pPoolItem ) )
149 lWidth = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
150 if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_HEIGHT, sal_True, &pPoolItem ) )
151 lHeight = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
153 // start/end color
154 if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_START_COLOR, sal_True, &pPoolItem ) )
156 aStartColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
157 bColor = sal_True;
159 if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_END_COLOR, sal_True, &pPoolItem ) )
161 aEndColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
162 if( aStartColor == aEndColor )
163 bColor = sal_False;
165 else
166 bColor = sal_False;
168 // remove handles
169 //HMHmpView->HideMarkHdl();
171 SfxProgress* pProgress = NULL;
172 sal_Bool bWaiting = sal_False;
174 if( nNumber > 1 )
176 String aStr( SdResId( STR_OBJECTS ) );
177 aStr.Append( sal_Unicode(' ') );
178 aStr.Append( String( SdResId( STR_UNDO_COPYOBJECTS ) ) );
180 pProgress = new SfxProgress( mpDocSh, aStr, nNumber );
181 mpDocSh->SetWaitCursor( sal_True );
182 bWaiting = sal_True;
185 const SdrMarkList aMarkList( mpView->GetMarkedObjectList() );
186 const sal_uLong nMarkCount = aMarkList.GetMarkCount();
187 SdrObject* pObj = NULL;
189 // calculate number of possible copies
190 aRect = mpView->GetAllMarkedRect();
192 if( lWidth < 0L )
194 long nTmp = ( aRect.Right() - aRect.Left() ) / -lWidth;
195 nNumber = (sal_uInt16) std::min( nTmp, (long)nNumber );
198 if( lHeight < 0L )
200 long nTmp = ( aRect.Bottom() - aRect.Top() ) / -lHeight;
201 nNumber = (sal_uInt16) std::min( nTmp, (long)nNumber );
204 for( sal_uInt16 i = 1; i <= nNumber; i++ )
206 if( pProgress )
207 pProgress->SetState( i );
209 aRect = mpView->GetAllMarkedRect();
211 if( ( 1 == i ) && bColor )
213 SfxItemSet aNewSet( mpViewShell->GetPool(), XATTR_FILLSTYLE, XATTR_FILLCOLOR, 0L );
214 aNewSet.Put( XFillStyleItem( XFILL_SOLID ) );
215 aNewSet.Put( XFillColorItem( String(), aStartColor ) );
216 mpView->SetAttributes( aNewSet );
219 // make a copy of selected objects
220 mpView->CopyMarked();
222 // get newly selected objects
223 SdrMarkList aCopyMarkList( mpView->GetMarkedObjectList() );
224 sal_uLong j, nCopyMarkCount = aMarkList.GetMarkCount();
226 // set protection flags at marked copies to null
227 for( j = 0; j < nCopyMarkCount; j++ )
229 pObj = aCopyMarkList.GetMark( j )->GetMarkedSdrObj();
231 if( pObj )
233 pObj->SetMoveProtect( sal_False );
234 pObj->SetResizeProtect( sal_False );
238 Fraction aWidth( aRect.Right() - aRect.Left() + lWidth, aRect.Right() - aRect.Left() );
239 Fraction aHeight( aRect.Bottom() - aRect.Top() + lHeight, aRect.Bottom() - aRect.Top() );
241 if( mpView->IsResizeAllowed() )
242 mpView->ResizeAllMarked( aRect.TopLeft(), aWidth, aHeight );
244 if( mpView->IsRotateAllowed() )
245 mpView->RotateAllMarked( aRect.Center(), lAngle * 100 );
247 if( mpView->IsMoveAllowed() )
248 mpView->MoveAllMarked( Size( lSizeX, lSizeY ) );
250 // set protection flags at marked copies to original values
251 if( nMarkCount == nCopyMarkCount )
253 for( j = 0; j < nMarkCount; j++ )
255 SdrObject* pSrcObj = aMarkList.GetMark( j )->GetMarkedSdrObj();
256 SdrObject* pDstObj = aCopyMarkList.GetMark( j )->GetMarkedSdrObj();
258 if( pSrcObj && pDstObj &&
259 ( pSrcObj->GetObjInventor() == pDstObj->GetObjInventor() ) &&
260 ( pSrcObj->GetObjIdentifier() == pDstObj->GetObjIdentifier() ) )
262 pDstObj->SetMoveProtect( pSrcObj->IsMoveProtect() );
263 pDstObj->SetResizeProtect( pSrcObj->IsResizeProtect() );
268 if( bColor )
270 // probably room for optimizations, but may can lead to rounding errors
271 sal_uInt8 nRed = aStartColor.GetRed() + (sal_uInt8) ( ( (long) aEndColor.GetRed() - (long) aStartColor.GetRed() ) * (long) i / (long) nNumber );
272 sal_uInt8 nGreen = aStartColor.GetGreen() + (sal_uInt8) ( ( (long) aEndColor.GetGreen() - (long) aStartColor.GetGreen() ) * (long) i / (long) nNumber );
273 sal_uInt8 nBlue = aStartColor.GetBlue() + (sal_uInt8) ( ( (long) aEndColor.GetBlue() - (long) aStartColor.GetBlue() ) * (long) i / (long) nNumber );
274 Color aNewColor( nRed, nGreen, nBlue );
275 SfxItemSet aNewSet( mpViewShell->GetPool(), XATTR_FILLSTYLE, XATTR_FILLCOLOR, 0L );
276 aNewSet.Put( XFillStyleItem( XFILL_SOLID ) );
277 aNewSet.Put( XFillColorItem( String(), aNewColor ) );
278 mpView->SetAttributes( aNewSet );
282 if ( pProgress )
283 delete pProgress;
285 if ( bWaiting )
286 mpDocSh->SetWaitCursor( sal_False );
288 // show handles
289 mpView->AdjustMarkHdl(); //HMH sal_True );
290 //HMHpView->ShowMarkHdl();
292 mpView->EndUndo();
296 } // end of namespace
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */