1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <sfx2/progress.hxx>
22 #include <svx/svxids.hrc>
24 #include "sdresid.hxx"
26 #include "strings.hrc"
27 #include "ViewShell.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"
43 TYPEINIT1( FuCopy
, FuPoor
);
52 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
56 FunctionReference
FuCopy::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
58 FunctionReference
xFunc( new FuCopy( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
59 xFunc
->DoExecute(rReq
);
63 void FuCopy::DoExecute( SfxRequest
& rReq
)
65 if( mpView
->AreObjectsMarked() )
68 String
aString( mpView
->GetDescriptionOfMarkedObjects() );
69 aString
.Append( sal_Unicode(' ') );
70 aString
.Append( String( SdResId( STR_UNDO_COPYOBJECTS
) ) );
71 mpView
->BegUndo( aString
);
73 const SfxItemSet
* pArgs
= rReq
.GetArgs();
77 SfxItemSet
aSet( mpViewShell
->GetPool(),
78 ATTR_COPY_START
, ATTR_COPY_END
, 0 );
80 // indicate color attribute
81 SfxItemSet
aAttr( mpDoc
->GetPool() );
82 mpView
->GetAttributes( aAttr
);
83 const SfxPoolItem
* pPoolItem
= NULL
;
85 if( SFX_ITEM_SET
== aAttr
.GetItemState( XATTR_FILLSTYLE
, sal_True
, &pPoolItem
) )
87 XFillStyle eStyle
= ( ( const XFillStyleItem
* ) pPoolItem
)->GetValue();
89 if( eStyle
== XFILL_SOLID
&&
90 SFX_ITEM_SET
== aAttr
.GetItemState( XATTR_FILLCOLOR
, sal_True
, &pPoolItem
) )
92 const XFillColorItem
* pItem
= ( const XFillColorItem
* ) pPoolItem
;
93 XColorItem
aXColorItem( ATTR_COPY_START_COLOR
, pItem
->GetName(),
94 pItem
->GetColorValue() );
95 aSet
.Put( aXColorItem
);
100 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
103 AbstractCopyDlg
* pDlg
= pFact
->CreateCopyDlg(NULL
, aSet
, mpDoc
->GetColorList(), mpView
);
106 sal_uInt16 nResult
= pDlg
->Execute();
111 pDlg
->GetAttr( aSet
);
113 pArgs
= rReq
.GetArgs();
129 sal_Int32 lWidth
= 0, lHeight
= 0, lSizeX
= 0L, lSizeY
= 0L, lAngle
= 0L;
130 sal_uInt16 nNumber
= 0;
131 Color aStartColor
, aEndColor
;
132 sal_Bool bColor
= sal_False
;
133 const SfxPoolItem
* pPoolItem
= NULL
;
136 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_NUMBER
, sal_True
, &pPoolItem
) )
137 nNumber
= ( ( const SfxUInt16Item
* ) pPoolItem
)->GetValue();
140 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_MOVE_X
, sal_True
, &pPoolItem
) )
141 lSizeX
= ( ( const SfxInt32Item
* ) pPoolItem
)->GetValue();
142 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_MOVE_Y
, sal_True
, &pPoolItem
) )
143 lSizeY
= ( ( const SfxInt32Item
* ) pPoolItem
)->GetValue();
144 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_ANGLE
, sal_True
, &pPoolItem
) )
145 lAngle
= ( ( const SfxInt32Item
* )pPoolItem
)->GetValue();
148 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_WIDTH
, sal_True
, &pPoolItem
) )
149 lWidth
= ( ( const SfxInt32Item
* ) pPoolItem
)->GetValue();
150 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_HEIGHT
, sal_True
, &pPoolItem
) )
151 lHeight
= ( ( const SfxInt32Item
* ) pPoolItem
)->GetValue();
154 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_START_COLOR
, sal_True
, &pPoolItem
) )
156 aStartColor
= ( ( const XColorItem
* ) pPoolItem
)->GetColorValue();
159 if( SFX_ITEM_SET
== pArgs
->GetItemState( ATTR_COPY_END_COLOR
, sal_True
, &pPoolItem
) )
161 aEndColor
= ( ( const XColorItem
* ) pPoolItem
)->GetColorValue();
162 if( aStartColor
== aEndColor
)
169 //HMHmpView->HideMarkHdl();
171 SfxProgress
* pProgress
= NULL
;
172 sal_Bool bWaiting
= sal_False
;
176 String
aStr( SdResId( STR_OBJECTS
) );
177 aStr
.Append( sal_Unicode(' ') );
178 aStr
.Append( String( SdResId( STR_UNDO_COPYOBJECTS
) ) );
180 pProgress
= new SfxProgress( mpDocSh
, aStr
, nNumber
);
181 mpDocSh
->SetWaitCursor( sal_True
);
185 const SdrMarkList
aMarkList( mpView
->GetMarkedObjectList() );
186 const sal_uLong nMarkCount
= aMarkList
.GetMarkCount();
187 SdrObject
* pObj
= NULL
;
189 // calculate number of possible copies
190 aRect
= mpView
->GetAllMarkedRect();
194 long nTmp
= ( aRect
.Right() - aRect
.Left() ) / -lWidth
;
195 nNumber
= (sal_uInt16
) std::min( nTmp
, (long)nNumber
);
200 long nTmp
= ( aRect
.Bottom() - aRect
.Top() ) / -lHeight
;
201 nNumber
= (sal_uInt16
) std::min( nTmp
, (long)nNumber
);
204 for( sal_uInt16 i
= 1; i
<= nNumber
; i
++ )
207 pProgress
->SetState( i
);
209 aRect
= mpView
->GetAllMarkedRect();
211 if( ( 1 == i
) && bColor
)
213 SfxItemSet
aNewSet( mpViewShell
->GetPool(), XATTR_FILLSTYLE
, XATTR_FILLCOLOR
, 0L );
214 aNewSet
.Put( XFillStyleItem( XFILL_SOLID
) );
215 aNewSet
.Put( XFillColorItem( String(), aStartColor
) );
216 mpView
->SetAttributes( aNewSet
);
219 // make a copy of selected objects
220 mpView
->CopyMarked();
222 // get newly selected objects
223 SdrMarkList
aCopyMarkList( mpView
->GetMarkedObjectList() );
224 sal_uLong j
, nCopyMarkCount
= aMarkList
.GetMarkCount();
226 // set protection flags at marked copies to null
227 for( j
= 0; j
< nCopyMarkCount
; j
++ )
229 pObj
= aCopyMarkList
.GetMark( j
)->GetMarkedSdrObj();
233 pObj
->SetMoveProtect( sal_False
);
234 pObj
->SetResizeProtect( sal_False
);
238 Fraction
aWidth( aRect
.Right() - aRect
.Left() + lWidth
, aRect
.Right() - aRect
.Left() );
239 Fraction
aHeight( aRect
.Bottom() - aRect
.Top() + lHeight
, aRect
.Bottom() - aRect
.Top() );
241 if( mpView
->IsResizeAllowed() )
242 mpView
->ResizeAllMarked( aRect
.TopLeft(), aWidth
, aHeight
);
244 if( mpView
->IsRotateAllowed() )
245 mpView
->RotateAllMarked( aRect
.Center(), lAngle
* 100 );
247 if( mpView
->IsMoveAllowed() )
248 mpView
->MoveAllMarked( Size( lSizeX
, lSizeY
) );
250 // set protection flags at marked copies to original values
251 if( nMarkCount
== nCopyMarkCount
)
253 for( j
= 0; j
< nMarkCount
; j
++ )
255 SdrObject
* pSrcObj
= aMarkList
.GetMark( j
)->GetMarkedSdrObj();
256 SdrObject
* pDstObj
= aCopyMarkList
.GetMark( j
)->GetMarkedSdrObj();
258 if( pSrcObj
&& pDstObj
&&
259 ( pSrcObj
->GetObjInventor() == pDstObj
->GetObjInventor() ) &&
260 ( pSrcObj
->GetObjIdentifier() == pDstObj
->GetObjIdentifier() ) )
262 pDstObj
->SetMoveProtect( pSrcObj
->IsMoveProtect() );
263 pDstObj
->SetResizeProtect( pSrcObj
->IsResizeProtect() );
270 // probably room for optimizations, but may can lead to rounding errors
271 sal_uInt8 nRed
= aStartColor
.GetRed() + (sal_uInt8
) ( ( (long) aEndColor
.GetRed() - (long) aStartColor
.GetRed() ) * (long) i
/ (long) nNumber
);
272 sal_uInt8 nGreen
= aStartColor
.GetGreen() + (sal_uInt8
) ( ( (long) aEndColor
.GetGreen() - (long) aStartColor
.GetGreen() ) * (long) i
/ (long) nNumber
);
273 sal_uInt8 nBlue
= aStartColor
.GetBlue() + (sal_uInt8
) ( ( (long) aEndColor
.GetBlue() - (long) aStartColor
.GetBlue() ) * (long) i
/ (long) nNumber
);
274 Color
aNewColor( nRed
, nGreen
, nBlue
);
275 SfxItemSet
aNewSet( mpViewShell
->GetPool(), XATTR_FILLSTYLE
, XATTR_FILLCOLOR
, 0L );
276 aNewSet
.Put( XFillStyleItem( XFILL_SOLID
) );
277 aNewSet
.Put( XFillColorItem( String(), aNewColor
) );
278 mpView
->SetAttributes( aNewSet
);
286 mpDocSh
->SetWaitCursor( sal_False
);
289 mpView
->AdjustMarkHdl(); //HMH sal_True );
290 //HMHpView->ShowMarkHdl();
296 } // end of namespace
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */