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 : FunctionReference FuCopy::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
57 : {
58 0 : FunctionReference 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 : String aString( mpView->GetDescriptionOfMarkedObjects() );
69 0 : aString.Append( sal_Unicode(' ') );
70 0 : aString.Append( String( SdResId( STR_UNDO_COPYOBJECTS ) ) );
71 0 : mpView->BegUndo( aString );
72 :
73 0 : const SfxItemSet* pArgs = rReq.GetArgs();
74 :
75 0 : if( !pArgs )
76 : {
77 0 : SfxItemSet aSet( mpViewShell->GetPool(),
78 0 : ATTR_COPY_START, ATTR_COPY_END, 0 );
79 :
80 : // indicate color attribute
81 0 : SfxItemSet aAttr( mpDoc->GetPool() );
82 0 : mpView->GetAttributes( aAttr );
83 0 : const SfxPoolItem* pPoolItem = NULL;
84 :
85 0 : if( SFX_ITEM_SET == aAttr.GetItemState( XATTR_FILLSTYLE, sal_True, &pPoolItem ) )
86 : {
87 0 : XFillStyle eStyle = ( ( const XFillStyleItem* ) pPoolItem )->GetValue();
88 :
89 0 : if( eStyle == XFILL_SOLID &&
90 0 : SFX_ITEM_SET == aAttr.GetItemState( XATTR_FILLCOLOR, sal_True, &pPoolItem ) )
91 : {
92 0 : const XFillColorItem* pItem = ( const XFillColorItem* ) pPoolItem;
93 : XColorItem aXColorItem( ATTR_COPY_START_COLOR, pItem->GetName(),
94 0 : pItem->GetColorValue() );
95 0 : aSet.Put( aXColorItem );
96 :
97 : }
98 : }
99 :
100 0 : SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
101 0 : if( pFact )
102 : {
103 0 : AbstractCopyDlg* pDlg = pFact->CreateCopyDlg(NULL, aSet, mpDoc->GetColorList(), mpView );
104 0 : if( pDlg )
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 : }
125 0 : }
126 : }
127 :
128 0 : Rectangle aRect;
129 0 : sal_Int32 lWidth = 0, lHeight = 0, lSizeX = 0L, lSizeY = 0L, lAngle = 0L;
130 0 : sal_uInt16 nNumber = 0;
131 0 : Color aStartColor, aEndColor;
132 0 : sal_Bool bColor = sal_False;
133 0 : const SfxPoolItem* pPoolItem = NULL;
134 :
135 : // Count
136 0 : if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_NUMBER, sal_True, &pPoolItem ) )
137 0 : nNumber = ( ( const SfxUInt16Item* ) pPoolItem )->GetValue();
138 :
139 : // translation
140 0 : if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_MOVE_X, sal_True, &pPoolItem ) )
141 0 : lSizeX = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
142 0 : if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_MOVE_Y, sal_True, &pPoolItem ) )
143 0 : lSizeY = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
144 0 : if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_ANGLE, sal_True, &pPoolItem ) )
145 0 : lAngle = ( ( const SfxInt32Item* )pPoolItem )->GetValue();
146 :
147 : // scale
148 0 : if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_WIDTH, sal_True, &pPoolItem ) )
149 0 : lWidth = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
150 0 : if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_HEIGHT, sal_True, &pPoolItem ) )
151 0 : lHeight = ( ( const SfxInt32Item* ) pPoolItem )->GetValue();
152 :
153 : // start/end color
154 0 : if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_START_COLOR, sal_True, &pPoolItem ) )
155 : {
156 0 : aStartColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
157 0 : bColor = sal_True;
158 : }
159 0 : if( SFX_ITEM_SET == pArgs->GetItemState( ATTR_COPY_END_COLOR, sal_True, &pPoolItem ) )
160 : {
161 0 : aEndColor = ( ( const XColorItem* ) pPoolItem )->GetColorValue();
162 0 : if( aStartColor == aEndColor )
163 0 : bColor = sal_False;
164 : }
165 : else
166 0 : bColor = sal_False;
167 :
168 : // remove handles
169 : //HMHmpView->HideMarkHdl();
170 :
171 0 : SfxProgress* pProgress = NULL;
172 0 : sal_Bool bWaiting = sal_False;
173 :
174 0 : if( nNumber > 1 )
175 : {
176 0 : String aStr( SdResId( STR_OBJECTS ) );
177 0 : aStr.Append( sal_Unicode(' ') );
178 0 : aStr.Append( String( SdResId( STR_UNDO_COPYOBJECTS ) ) );
179 :
180 0 : pProgress = new SfxProgress( mpDocSh, aStr, nNumber );
181 0 : mpDocSh->SetWaitCursor( sal_True );
182 0 : bWaiting = sal_True;
183 : }
184 :
185 0 : const SdrMarkList aMarkList( mpView->GetMarkedObjectList() );
186 0 : const sal_uLong nMarkCount = aMarkList.GetMarkCount();
187 0 : SdrObject* pObj = NULL;
188 :
189 : // calculate number of possible copies
190 0 : aRect = mpView->GetAllMarkedRect();
191 :
192 0 : if( lWidth < 0L )
193 : {
194 0 : long nTmp = ( aRect.Right() - aRect.Left() ) / -lWidth;
195 0 : nNumber = (sal_uInt16) std::min( nTmp, (long)nNumber );
196 : }
197 :
198 0 : if( lHeight < 0L )
199 : {
200 0 : long nTmp = ( aRect.Bottom() - aRect.Top() ) / -lHeight;
201 0 : nNumber = (sal_uInt16) std::min( nTmp, (long)nNumber );
202 : }
203 :
204 0 : for( sal_uInt16 i = 1; i <= nNumber; i++ )
205 : {
206 0 : if( pProgress )
207 0 : pProgress->SetState( i );
208 :
209 0 : aRect = mpView->GetAllMarkedRect();
210 :
211 0 : if( ( 1 == i ) && bColor )
212 : {
213 0 : SfxItemSet aNewSet( mpViewShell->GetPool(), XATTR_FILLSTYLE, XATTR_FILLCOLOR, 0L );
214 0 : aNewSet.Put( XFillStyleItem( XFILL_SOLID ) );
215 0 : aNewSet.Put( XFillColorItem( String(), aStartColor ) );
216 0 : mpView->SetAttributes( aNewSet );
217 : }
218 :
219 : // make a copy of selected objects
220 0 : mpView->CopyMarked();
221 :
222 : // get newly selected objects
223 0 : SdrMarkList aCopyMarkList( mpView->GetMarkedObjectList() );
224 0 : sal_uLong j, nCopyMarkCount = aMarkList.GetMarkCount();
225 :
226 : // set protection flags at marked copies to null
227 0 : for( j = 0; j < nCopyMarkCount; j++ )
228 : {
229 0 : pObj = aCopyMarkList.GetMark( j )->GetMarkedSdrObj();
230 :
231 0 : if( pObj )
232 : {
233 0 : pObj->SetMoveProtect( sal_False );
234 0 : pObj->SetResizeProtect( sal_False );
235 : }
236 : }
237 :
238 0 : Fraction aWidth( aRect.Right() - aRect.Left() + lWidth, aRect.Right() - aRect.Left() );
239 0 : Fraction aHeight( aRect.Bottom() - aRect.Top() + lHeight, aRect.Bottom() - aRect.Top() );
240 :
241 0 : if( mpView->IsResizeAllowed() )
242 0 : mpView->ResizeAllMarked( aRect.TopLeft(), aWidth, aHeight );
243 :
244 0 : if( mpView->IsRotateAllowed() )
245 0 : mpView->RotateAllMarked( aRect.Center(), lAngle * 100 );
246 :
247 0 : if( mpView->IsMoveAllowed() )
248 0 : mpView->MoveAllMarked( Size( lSizeX, lSizeY ) );
249 :
250 : // set protection flags at marked copies to original values
251 0 : if( nMarkCount == nCopyMarkCount )
252 : {
253 0 : for( j = 0; j < nMarkCount; j++ )
254 : {
255 0 : SdrObject* pSrcObj = aMarkList.GetMark( j )->GetMarkedSdrObj();
256 0 : SdrObject* pDstObj = aCopyMarkList.GetMark( j )->GetMarkedSdrObj();
257 :
258 0 : if( pSrcObj && pDstObj &&
259 0 : ( pSrcObj->GetObjInventor() == pDstObj->GetObjInventor() ) &&
260 0 : ( pSrcObj->GetObjIdentifier() == pDstObj->GetObjIdentifier() ) )
261 : {
262 0 : pDstObj->SetMoveProtect( pSrcObj->IsMoveProtect() );
263 0 : pDstObj->SetResizeProtect( pSrcObj->IsResizeProtect() );
264 : }
265 : }
266 : }
267 :
268 0 : if( bColor )
269 : {
270 : // probably room for optimizations, but may can lead to rounding errors
271 0 : sal_uInt8 nRed = aStartColor.GetRed() + (sal_uInt8) ( ( (long) aEndColor.GetRed() - (long) aStartColor.GetRed() ) * (long) i / (long) nNumber );
272 0 : sal_uInt8 nGreen = aStartColor.GetGreen() + (sal_uInt8) ( ( (long) aEndColor.GetGreen() - (long) aStartColor.GetGreen() ) * (long) i / (long) nNumber );
273 0 : sal_uInt8 nBlue = aStartColor.GetBlue() + (sal_uInt8) ( ( (long) aEndColor.GetBlue() - (long) aStartColor.GetBlue() ) * (long) i / (long) nNumber );
274 0 : Color aNewColor( nRed, nGreen, nBlue );
275 0 : SfxItemSet aNewSet( mpViewShell->GetPool(), XATTR_FILLSTYLE, XATTR_FILLCOLOR, 0L );
276 0 : aNewSet.Put( XFillStyleItem( XFILL_SOLID ) );
277 0 : aNewSet.Put( XFillColorItem( String(), aNewColor ) );
278 0 : mpView->SetAttributes( aNewSet );
279 : }
280 0 : }
281 :
282 0 : if ( pProgress )
283 0 : delete pProgress;
284 :
285 0 : if ( bWaiting )
286 0 : mpDocSh->SetWaitCursor( sal_False );
287 :
288 : // show handles
289 0 : mpView->AdjustMarkHdl(); //HMH sal_True );
290 : //HMHpView->ShowMarkHdl();
291 :
292 0 : mpView->EndUndo();
293 : }
294 : }
295 :
296 33 : } // end of namespace
297 :
298 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|