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