1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fucopy.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
36 #include <sfx2/progress.hxx>
37 #include <svx/svxids.hrc>
39 #include "sdresid.hxx"
41 #include "strings.hrc"
42 #include "ViewShell.hxx"
44 #include "drawdoc.hxx"
45 #include "DrawDocShell.hxx"
46 #include <vcl/wrkwin.hxx>
47 #include <svx/svdobj.hxx>
48 #include <vcl/msgbox.hxx>
49 #include <sfx2/app.hxx>
50 #include <svx/xcolit.hxx>
51 #include <svx/xflclit.hxx>
52 #include <svx/xdef.hxx>
53 #include <svx/xfillit0.hxx>
54 #include <sfx2/request.hxx>
55 #include "sdabstdlg.hxx"
56 #include "copydlg.hrc"
59 TYPEINIT1( FuCopy
, FuPoor
);
61 /*************************************************************************
65 \************************************************************************/
73 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
77 FunctionReference
FuCopy::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
79 FunctionReference
xFunc( new FuCopy( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
80 xFunc
->DoExecute(rReq
);
84 void FuCopy::DoExecute( SfxRequest
& rReq
)
86 if( mpView
->AreObjectsMarked() )
89 String
aString( mpView
->GetDescriptionOfMarkedObjects() );
90 aString
.Append( sal_Unicode(' ') );
91 aString
.Append( String( SdResId( STR_UNDO_COPYOBJECTS
) ) );
92 mpView
->BegUndo( aString
);
94 const SfxItemSet
* pArgs
= rReq
.GetArgs();
98 SfxItemSet
aSet( mpViewShell
->GetPool(),
99 ATTR_COPY_START
, ATTR_COPY_END
, 0 );
101 // Farb-Attribut angeben
102 SfxItemSet
aAttr( mpDoc
->GetPool() );
103 mpView
->GetAttributes( aAttr
);
104 const SfxPoolItem
* pPoolItem
= NULL
;
106 if( SFX_ITEM_SET
== aAttr
.GetItemState( XATTR_FILLSTYLE
, TRUE
, &pPoolItem
) )
108 XFillStyle eStyle
= ( ( const XFillStyleItem
* ) pPoolItem
)->GetValue();
110 if( eStyle
== XFILL_SOLID
&&
111 SFX_ITEM_SET
== aAttr
.GetItemState( XATTR_FILLCOLOR
, TRUE
, &pPoolItem
) )
113 const XFillColorItem
* pItem
= ( const XFillColorItem
* ) pPoolItem
;
114 XColorItem
aXColorItem( ATTR_COPY_START_COLOR
, pItem
->GetName(),
115 pItem
->GetColorValue() );
116 aSet
.Put( aXColorItem
);
121 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
124 AbstractCopyDlg
* pDlg
= pFact
->CreateCopyDlg(NULL
, aSet
, mpDoc
->GetColorTable(), mpView
);
127 USHORT nResult
= pDlg
->Execute();
132 pDlg
->GetAttr( aSet
);
134 pArgs
= rReq
.GetArgs();
150 INT32 lWidth
= 0, lHeight
= 0, lSizeX
= 0L, lSizeY
= 0L, lAngle
= 0L;
152 Color aStartColor
, aEndColor
;
154 const SfxPoolItem
* pPoolItem
= NULL
;
157 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_NUMBER
, TRUE
, &pPoolItem
) )
158 nNumber
= ( ( const SfxUInt16Item
* ) pPoolItem
)->GetValue();
161 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_MOVE_X
, TRUE
, &pPoolItem
) )
162 lSizeX
= ( ( const SfxInt32Item
* ) pPoolItem
)->GetValue();
163 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_MOVE_Y
, TRUE
, &pPoolItem
) )
164 lSizeY
= ( ( const SfxInt32Item
* ) pPoolItem
)->GetValue();
165 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_ANGLE
, TRUE
, &pPoolItem
) )
166 lAngle
= ( ( const SfxInt32Item
* )pPoolItem
)->GetValue();
168 // Verrgroesserung / Verkleinerung
169 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_WIDTH
, TRUE
, &pPoolItem
) )
170 lWidth
= ( ( const SfxInt32Item
* ) pPoolItem
)->GetValue();
171 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_HEIGHT
, TRUE
, &pPoolItem
) )
172 lHeight
= ( ( const SfxInt32Item
* ) pPoolItem
)->GetValue();
174 // Startfarbe / Endfarbe
175 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_START_COLOR
, TRUE
, &pPoolItem
) )
177 aStartColor
= ( ( const XColorItem
* ) pPoolItem
)->GetColorValue();
180 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_END_COLOR
, TRUE
, &pPoolItem
) )
182 aEndColor
= ( ( const XColorItem
* ) pPoolItem
)->GetColorValue();
183 if( aStartColor
== aEndColor
)
190 //HMHmpView->HideMarkHdl();
192 SfxProgress
* pProgress
= NULL
;
193 BOOL bWaiting
= FALSE
;
197 String
aStr( SdResId( STR_OBJECTS
) );
198 aStr
.Append( sal_Unicode(' ') );
199 aStr
.Append( String( SdResId( STR_UNDO_COPYOBJECTS
) ) );
201 pProgress
= new SfxProgress( mpDocSh
, aStr
, nNumber
);
202 mpDocSh
->SetWaitCursor( TRUE
);
206 const SdrMarkList
aMarkList( mpView
->GetMarkedObjectList() );
207 const ULONG nMarkCount
= aMarkList
.GetMarkCount();
208 SdrObject
* pObj
= NULL
;
210 // Anzahl moeglicher Kopien berechnen
211 aRect
= mpView
->GetAllMarkedRect();
215 long nTmp
= ( aRect
.Right() - aRect
.Left() ) / -lWidth
;
216 nNumber
= (UINT16
) Min( nTmp
, (long)nNumber
);
221 long nTmp
= ( aRect
.Bottom() - aRect
.Top() ) / -lHeight
;
222 nNumber
= (UINT16
) Min( nTmp
, (long)nNumber
);
225 for( USHORT i
= 1; i
<= nNumber
; i
++ )
228 pProgress
->SetState( i
);
230 aRect
= mpView
->GetAllMarkedRect();
232 if( ( 1 == i
) && bColor
)
234 SfxItemSet
aNewSet( mpViewShell
->GetPool(), XATTR_FILLSTYLE
, XATTR_FILLCOLOR
, 0L );
235 aNewSet
.Put( XFillStyleItem( XFILL_SOLID
) );
236 aNewSet
.Put( XFillColorItem( String(), aStartColor
) );
237 mpView
->SetAttributes( aNewSet
);
240 // make a copy of selected objects
241 mpView
->CopyMarked();
243 // get newly selected objects
244 SdrMarkList
aCopyMarkList( mpView
->GetMarkedObjectList() );
245 ULONG j
, nCopyMarkCount
= aMarkList
.GetMarkCount();
247 // set protection flags at marked copies to null
248 for( j
= 0; j
< nCopyMarkCount
; j
++ )
250 pObj
= aCopyMarkList
.GetMark( j
)->GetMarkedSdrObj();
254 pObj
->SetMoveProtect( FALSE
);
255 pObj
->SetResizeProtect( FALSE
);
259 Fraction
aWidth( aRect
.Right() - aRect
.Left() + lWidth
, aRect
.Right() - aRect
.Left() );
260 Fraction
aHeight( aRect
.Bottom() - aRect
.Top() + lHeight
, aRect
.Bottom() - aRect
.Top() );
262 if( mpView
->IsResizeAllowed() )
263 mpView
->ResizeAllMarked( aRect
.TopLeft(), aWidth
, aHeight
);
265 if( mpView
->IsRotateAllowed() )
266 mpView
->RotateAllMarked( aRect
.Center(), lAngle
* 100 );
268 if( mpView
->IsMoveAllowed() )
269 mpView
->MoveAllMarked( Size( lSizeX
, lSizeY
) );
271 // set protection flags at marked copies to original values
272 if( nMarkCount
== nCopyMarkCount
)
274 for( j
= 0; j
< nMarkCount
; j
++ )
276 SdrObject
* pSrcObj
= aMarkList
.GetMark( j
)->GetMarkedSdrObj();
277 SdrObject
* pDstObj
= aCopyMarkList
.GetMark( j
)->GetMarkedSdrObj();
279 if( pSrcObj
&& pDstObj
&&
280 ( pSrcObj
->GetObjInventor() == pDstObj
->GetObjInventor() ) &&
281 ( pSrcObj
->GetObjIdentifier() == pDstObj
->GetObjIdentifier() ) )
283 pDstObj
->SetMoveProtect( pSrcObj
->IsMoveProtect() );
284 pDstObj
->SetResizeProtect( pSrcObj
->IsResizeProtect() );
291 // Koennte man sicher noch optimieren, wuerde aber u.U.
292 // zu Rundungsfehlern fuehren
293 BYTE nRed
= aStartColor
.GetRed() + (BYTE
) ( ( (long) aEndColor
.GetRed() - (long) aStartColor
.GetRed() ) * (long) i
/ (long) nNumber
);
294 BYTE nGreen
= aStartColor
.GetGreen() + (BYTE
) ( ( (long) aEndColor
.GetGreen() - (long) aStartColor
.GetGreen() ) * (long) i
/ (long) nNumber
);
295 BYTE nBlue
= aStartColor
.GetBlue() + (BYTE
) ( ( (long) aEndColor
.GetBlue() - (long) aStartColor
.GetBlue() ) * (long) i
/ (long) nNumber
);
296 Color
aNewColor( nRed
, nGreen
, nBlue
);
297 SfxItemSet
aNewSet( mpViewShell
->GetPool(), XATTR_FILLSTYLE
, XATTR_FILLCOLOR
, 0L );
298 aNewSet
.Put( XFillStyleItem( XFILL_SOLID
) );
299 aNewSet
.Put( XFillColorItem( String(), aNewColor
) );
300 mpView
->SetAttributes( aNewSet
);
308 mpDocSh
->SetWaitCursor( FALSE
);
311 mpView
->AdjustMarkHdl(); //HMH TRUE );
312 //HMHpView->ShowMarkHdl();
318 } // end of namespace