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