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 <svl/intitem.hxx>
25 #include <sdresid.hxx>
26 #include <strings.hrc>
27 #include <ViewShell.hxx>
29 #include <drawdoc.hxx>
30 #include <DrawDocShell.hxx>
31 #include <svx/svdobj.hxx>
32 #include <svx/xcolit.hxx>
33 #include <svx/xflclit.hxx>
34 #include <svx/xdef.hxx>
35 #include <svx/xfillit0.hxx>
36 #include <svx/sdangitm.hxx>
37 #include <sfx2/request.hxx>
38 #include <sdabstdlg.hxx>
41 using namespace com::sun::star
;
52 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
56 rtl::Reference
<FuPoor
> FuCopy::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
58 rtl::Reference
<FuPoor
> xFunc( new FuCopy( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
59 xFunc
->DoExecute(rReq
);
63 void FuCopy::DoExecute( SfxRequest
& rReq
)
65 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
66 if( rMarkList
.GetMarkCount() == 0 )
70 OUString aString
= rMarkList
.GetMarkDescription() +
71 " " + SdResId( STR_UNDO_COPYOBJECTS
);
72 mpView
->BegUndo( aString
);
74 const SfxItemSet
* pArgs
= rReq
.GetArgs();
78 SfxItemSetFixed
<ATTR_COPY_START
, ATTR_COPY_END
> aSet( mpViewShell
->GetPool() );
80 // indicate color attribute
81 SfxItemSet
aAttr( mpDoc
->GetPool() );
82 mpView
->GetAttributes( aAttr
);
84 if( const XFillStyleItem
* pFillStyleItem
= aAttr
.GetItemIfSet( XATTR_FILLSTYLE
) )
86 drawing::FillStyle eStyle
= pFillStyleItem
->GetValue();
88 const XFillColorItem
* pFillColorItem
;
89 if( eStyle
== drawing::FillStyle_SOLID
&&
90 (pFillColorItem
= aAttr
.GetItemIfSet( XATTR_FILLCOLOR
)) )
92 XColorItem
aXColorItem( ATTR_COPY_START_COLOR
, pFillColorItem
->GetName(),
93 pFillColorItem
->GetColorValue() );
94 aSet
.Put( aXColorItem
);
99 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
100 ScopedVclPtr
<AbstractCopyDlg
> pDlg(pFact
->CreateCopyDlg(mpViewShell
->GetFrameWeld(), aSet
, mpView
));
102 sal_uInt16 nResult
= pDlg
->Execute();
107 pDlg
->GetAttr( aSet
);
109 pArgs
= rReq
.GetArgs();
114 pDlg
.disposeAndClear();
121 ::tools::Rectangle aRect
;
122 sal_Int32 lWidth
= 0, lHeight
= 0, lSizeX
= 0, lSizeY
= 0;
124 sal_uInt16 nNumber
= 0;
125 Color aStartColor
, aEndColor
;
131 if( const SfxUInt16Item
* pPoolItem
= pArgs
->GetItemIfSet( ATTR_COPY_NUMBER
) )
132 nNumber
= pPoolItem
->GetValue();
135 if( const SfxInt32Item
* pPoolItem
= pArgs
->GetItemIfSet( ATTR_COPY_MOVE_X
) )
136 lSizeX
= pPoolItem
->GetValue();
137 if( const SfxInt32Item
* pPoolItem
= pArgs
->GetItemIfSet( ATTR_COPY_MOVE_Y
) )
138 lSizeY
= pPoolItem
->GetValue();
139 if( const SdrAngleItem
* pPoolItem
= pArgs
->GetItemIfSet( ATTR_COPY_ANGLE
) )
140 lAngle
= pPoolItem
->GetValue();
143 if( const SfxInt32Item
* pPoolItem
= pArgs
->GetItemIfSet( ATTR_COPY_WIDTH
) )
144 lWidth
= pPoolItem
->GetValue();
145 if( const SfxInt32Item
* pPoolItem
= pArgs
->GetItemIfSet( ATTR_COPY_HEIGHT
) )
146 lHeight
= pPoolItem
->GetValue();
149 if( const XColorItem
* pPoolItem
= pArgs
->GetItemIfSet( ATTR_COPY_START_COLOR
) )
151 aStartColor
= pPoolItem
->GetColorValue();
154 if( const XColorItem
* pPoolItem
= pArgs
->GetItemIfSet( ATTR_COPY_END_COLOR
) )
156 aEndColor
= pPoolItem
->GetColorValue();
157 if( aStartColor
== aEndColor
)
163 //HMHmpView->HideMarkHdl();
165 std::unique_ptr
<SfxProgress
> pProgress
;
166 bool bWaiting
= false;
170 OUString aStr
= SdResId( STR_OBJECTS
) +
171 " " + SdResId( STR_UNDO_COPYOBJECTS
);
173 pProgress
.reset(new SfxProgress( mpDocSh
, aStr
, nNumber
));
174 mpDocSh
->SetWaitCursor( true );
178 const size_t nMarkCount
= rMarkList
.GetMarkCount();
179 SdrObject
* pObj
= nullptr;
181 // calculate number of possible copies
182 aRect
= mpView
->GetAllMarkedRect();
186 ::tools::Long nTmp
= ( aRect
.Right() - aRect
.Left() ) / -lWidth
;
187 nNumber
= static_cast<sal_uInt16
>(std::min( nTmp
, static_cast<::tools::Long
>(nNumber
) ));
192 ::tools::Long nTmp
= ( aRect
.Bottom() - aRect
.Top() ) / -lHeight
;
193 nNumber
= static_cast<sal_uInt16
>(std::min( nTmp
, static_cast<::tools::Long
>(nNumber
) ));
196 for( sal_uInt16 i
= 1; i
<= nNumber
; i
++ )
199 pProgress
->SetState( i
);
201 aRect
= mpView
->GetAllMarkedRect();
203 if( ( 1 == i
) && bColor
)
205 SfxItemSetFixed
<XATTR_FILLSTYLE
, XATTR_FILLCOLOR
> aNewSet( mpViewShell
->GetPool() );
206 aNewSet
.Put( XFillStyleItem( drawing::FillStyle_SOLID
) );
207 aNewSet
.Put( XFillColorItem( OUString(), aStartColor
) );
208 mpView
->SetAttributes( aNewSet
);
211 // make a copy of selected objects
212 mpView
->CopyMarked();
214 // get newly selected objects
215 SdrMarkList
aCopyMarkList( rMarkList
);
216 const size_t nCopyMarkCount
= rMarkList
.GetMarkCount();
218 // set protection flags at marked copies to null
219 for( size_t j
= 0; j
< nCopyMarkCount
; ++j
)
221 pObj
= aCopyMarkList
.GetMark( j
)->GetMarkedSdrObj();
225 pObj
->SetMoveProtect( false );
226 pObj
->SetResizeProtect( false );
230 Fraction
aWidth( aRect
.Right() - aRect
.Left() + lWidth
, aRect
.Right() - aRect
.Left() );
231 Fraction
aHeight( aRect
.Bottom() - aRect
.Top() + lHeight
, aRect
.Bottom() - aRect
.Top() );
233 if( mpView
->IsResizeAllowed() )
234 mpView
->ResizeAllMarked( aRect
.TopLeft(), aWidth
, aHeight
);
236 if( mpView
->IsRotateAllowed() )
237 mpView
->RotateAllMarked( aRect
.Center(), lAngle
);
239 if( mpView
->IsMoveAllowed() )
240 mpView
->MoveAllMarked( Size( lSizeX
, lSizeY
) );
242 // set protection flags at marked copies to original values
243 if( nMarkCount
== nCopyMarkCount
)
245 for( size_t j
= 0; j
< nMarkCount
; ++j
)
247 SdrObject
* pSrcObj
= rMarkList
.GetMark( j
)->GetMarkedSdrObj();
248 SdrObject
* pDstObj
= aCopyMarkList
.GetMark( j
)->GetMarkedSdrObj();
250 if( pSrcObj
&& pDstObj
&&
251 ( pSrcObj
->GetObjInventor() == pDstObj
->GetObjInventor() ) &&
252 ( pSrcObj
->GetObjIdentifier() == pDstObj
->GetObjIdentifier() ) )
254 pDstObj
->SetMoveProtect( pSrcObj
->IsMoveProtect() );
255 pDstObj
->SetResizeProtect( pSrcObj
->IsResizeProtect() );
262 // probably room for optimizations, but may can lead to rounding errors
263 sal_uInt8 nRed
= aStartColor
.GetRed() + static_cast<sal_uInt8
>( ( static_cast<::tools::Long
>(aEndColor
.GetRed()) - static_cast<::tools::Long
>(aStartColor
.GetRed()) ) * static_cast<::tools::Long
>(i
) / static_cast<::tools::Long
>(nNumber
) );
264 sal_uInt8 nGreen
= aStartColor
.GetGreen() + static_cast<sal_uInt8
>( ( static_cast<::tools::Long
>(aEndColor
.GetGreen()) - static_cast<::tools::Long
>(aStartColor
.GetGreen()) ) * static_cast<::tools::Long
>(i
) / static_cast<::tools::Long
>(nNumber
) );
265 sal_uInt8 nBlue
= aStartColor
.GetBlue() + static_cast<sal_uInt8
>( ( static_cast<::tools::Long
>(aEndColor
.GetBlue()) - static_cast<::tools::Long
>(aStartColor
.GetBlue()) ) * static_cast<::tools::Long
>(i
) / static_cast<::tools::Long
>(nNumber
) );
266 Color
aNewColor( nRed
, nGreen
, nBlue
);
267 SfxItemSetFixed
<XATTR_FILLSTYLE
, XATTR_FILLCOLOR
> aNewSet( mpViewShell
->GetPool() );
268 aNewSet
.Put( XFillStyleItem( drawing::FillStyle_SOLID
) );
269 aNewSet
.Put( XFillColorItem( OUString(), aNewColor
) );
270 mpView
->SetAttributes( aNewSet
);
277 mpDocSh
->SetWaitCursor( false );
280 mpView
->AdjustMarkHdl(); //HMH sal_True );
281 //HMHpView->ShowMarkHdl();
286 } // end of namespace
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */