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 <boost/scoped_ptr.hpp>
42 :
43 : using namespace com::sun::star;
44 :
45 : namespace sd {
46 :
47 0 : TYPEINIT1( FuCopy, FuPoor );
48 :
49 0 : FuCopy::FuCopy (
50 : ViewShell* pViewSh,
51 : ::sd::Window* pWin,
52 : ::sd::View* pView,
53 : SdDrawDocument* pDoc,
54 : SfxRequest& rReq)
55 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
56 : {
57 0 : }
58 :
59 0 : rtl::Reference<FuPoor> FuCopy::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
60 : {
61 0 : rtl::Reference<FuPoor> xFunc( new FuCopy( pViewSh, pWin, pView, pDoc, rReq ) );
62 0 : xFunc->DoExecute(rReq);
63 0 : return xFunc;
64 : }
65 :
66 0 : void FuCopy::DoExecute( SfxRequest& rReq )
67 : {
68 0 : if( mpView->AreObjectsMarked() )
69 : {
70 : // Undo
71 0 : OUString aString( mpView->GetDescriptionOfMarkedObjects() );
72 0 : aString += " " + SD_RESSTR( STR_UNDO_COPYOBJECTS );
73 0 : mpView->BegUndo( aString );
74 :
75 0 : const SfxItemSet* pArgs = rReq.GetArgs();
76 :
77 0 : if( !pArgs )
78 : {
79 0 : SfxItemSet aSet( mpViewShell->GetPool(),
80 0 : ATTR_COPY_START, ATTR_COPY_END, 0 );
81 :
82 : // indicate color attribute
83 0 : SfxItemSet aAttr( mpDoc->GetPool() );
84 0 : mpView->GetAttributes( aAttr );
85 0 : const SfxPoolItem* pPoolItem = NULL;
86 :
87 0 : if( SfxItemState::SET == aAttr.GetItemState( XATTR_FILLSTYLE, true, &pPoolItem ) )
88 : {
89 0 : drawing::FillStyle eStyle = static_cast<const XFillStyleItem*>(pPoolItem)->GetValue();
90 :
91 0 : if( eStyle == drawing::FillStyle_SOLID &&
92 0 : SfxItemState::SET == aAttr.GetItemState( XATTR_FILLCOLOR, true, &pPoolItem ) )
93 : {
94 0 : const XFillColorItem* pItem = static_cast<const XFillColorItem*>(pPoolItem);
95 : XColorItem aXColorItem( ATTR_COPY_START_COLOR, pItem->GetName(),
96 0 : pItem->GetColorValue() );
97 0 : aSet.Put( aXColorItem );
98 :
99 : }
100 : }
101 :
102 0 : SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
103 0 : if( pFact )
104 : {
105 0 : boost::scoped_ptr<AbstractCopyDlg> pDlg(pFact->CreateCopyDlg(NULL, aSet, mpDoc->GetColorList(), mpView ));
106 0 : if (!pDlg)
107 0 : return;
108 :
109 0 : sal_uInt16 nResult = pDlg->Execute();
110 :
111 0 : switch( nResult )
112 : {
113 : case RET_OK:
114 0 : pDlg->GetAttr( aSet );
115 0 : rReq.Done( aSet );
116 0 : pArgs = rReq.GetArgs();
117 0 : break;
118 :
119 : default:
120 : {
121 0 : pDlg.reset();
122 0 : mpView->EndUndo();
123 : }
124 0 : return; // Cancel
125 0 : }
126 0 : }
127 : }
128 :
129 0 : Rectangle aRect;
130 0 : sal_Int32 lWidth = 0, lHeight = 0, lSizeX = 0L, lSizeY = 0L, lAngle = 0L;
131 0 : sal_uInt16 nNumber = 0;
132 0 : Color aStartColor, aEndColor;
133 0 : bool bColor = false;
134 0 : const SfxPoolItem* pPoolItem = NULL;
135 :
136 : // Count
137 0 : if( pArgs && SfxItemState::SET == pArgs->GetItemState( ATTR_COPY_NUMBER, true, &pPoolItem ) )
138 0 : nNumber = static_cast<const SfxUInt16Item*>( pPoolItem )->GetValue();
139 :
140 : // translation
141 0 : if( pArgs && SfxItemState::SET == pArgs->GetItemState( ATTR_COPY_MOVE_X, true, &pPoolItem ) )
142 0 : lSizeX = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
143 0 : if( pArgs && SfxItemState::SET == pArgs->GetItemState( ATTR_COPY_MOVE_Y, true, &pPoolItem ) )
144 0 : lSizeY = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
145 0 : if( pArgs && SfxItemState::SET == pArgs->GetItemState( ATTR_COPY_ANGLE, true, &pPoolItem ) )
146 0 : lAngle = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
147 :
148 : // scale
149 0 : if( pArgs && SfxItemState::SET == pArgs->GetItemState( ATTR_COPY_WIDTH, true, &pPoolItem ) )
150 0 : lWidth = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
151 0 : if( pArgs && SfxItemState::SET == pArgs->GetItemState( ATTR_COPY_HEIGHT, true, &pPoolItem ) )
152 0 : lHeight = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
153 :
154 : // start/end color
155 0 : if( pArgs && SfxItemState::SET == pArgs->GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
156 : {
157 0 : aStartColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
158 0 : bColor = true;
159 : }
160 0 : if( pArgs && SfxItemState::SET == pArgs->GetItemState( ATTR_COPY_END_COLOR, true, &pPoolItem ) )
161 : {
162 0 : aEndColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
163 0 : if( aStartColor == aEndColor )
164 0 : bColor = false;
165 : }
166 : else
167 0 : bColor = false;
168 :
169 : // remove handles
170 : //HMHmpView->HideMarkHdl();
171 :
172 0 : boost::scoped_ptr<SfxProgress> pProgress;
173 0 : bool bWaiting = false;
174 :
175 0 : if( nNumber > 1 )
176 : {
177 0 : OUString aStr( SD_RESSTR( STR_OBJECTS ) );
178 0 : aStr += " " + SD_RESSTR( STR_UNDO_COPYOBJECTS );
179 :
180 0 : pProgress.reset(new SfxProgress( mpDocSh, aStr, nNumber ));
181 0 : mpDocSh->SetWaitCursor( true );
182 0 : bWaiting = true;
183 : }
184 :
185 0 : const SdrMarkList aMarkList( mpView->GetMarkedObjectList() );
186 0 : const size_t 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( drawing::FillStyle_SOLID ) );
215 0 : aNewSet.Put( XFillColorItem( OUString(), 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 : const size_t nCopyMarkCount = aMarkList.GetMarkCount();
225 :
226 : // set protection flags at marked copies to null
227 0 : for( size_t j = 0; j < nCopyMarkCount; ++j )
228 : {
229 0 : pObj = aCopyMarkList.GetMark( j )->GetMarkedSdrObj();
230 :
231 0 : if( pObj )
232 : {
233 0 : pObj->SetMoveProtect( false );
234 0 : pObj->SetResizeProtect( 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( size_t 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( drawing::FillStyle_SOLID ) );
277 0 : aNewSet.Put( XFillColorItem( OUString(), aNewColor ) );
278 0 : mpView->SetAttributes( aNewSet );
279 : }
280 0 : }
281 :
282 0 : pProgress.reset();
283 :
284 0 : if ( bWaiting )
285 0 : mpDocSh->SetWaitCursor( false );
286 :
287 : // show handles
288 0 : mpView->AdjustMarkHdl(); //HMH sal_True );
289 : //HMHpView->ShowMarkHdl();
290 :
291 0 : mpView->EndUndo();
292 : }
293 : }
294 :
295 66 : } // end of namespace
296 :
297 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|