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"
41 #include <boost/scoped_ptr.hpp>
43 using namespace com::sun::star
;
47 TYPEINIT1( FuCopy
, FuPoor
);
55 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
59 rtl::Reference
<FuPoor
> FuCopy::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
61 rtl::Reference
<FuPoor
> xFunc( new FuCopy( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
62 xFunc
->DoExecute(rReq
);
66 void FuCopy::DoExecute( SfxRequest
& rReq
)
68 if( mpView
->AreObjectsMarked() )
71 OUString
aString( mpView
->GetDescriptionOfMarkedObjects() );
72 aString
+= " " + SD_RESSTR( STR_UNDO_COPYOBJECTS
);
73 mpView
->BegUndo( aString
);
75 const SfxItemSet
* pArgs
= rReq
.GetArgs();
79 SfxItemSet
aSet( mpViewShell
->GetPool(),
80 ATTR_COPY_START
, ATTR_COPY_END
, 0 );
82 // indicate color attribute
83 SfxItemSet
aAttr( mpDoc
->GetPool() );
84 mpView
->GetAttributes( aAttr
);
85 const SfxPoolItem
* pPoolItem
= NULL
;
87 if( SfxItemState::SET
== aAttr
.GetItemState( XATTR_FILLSTYLE
, true, &pPoolItem
) )
89 drawing::FillStyle eStyle
= static_cast<const XFillStyleItem
*>(pPoolItem
)->GetValue();
91 if( eStyle
== drawing::FillStyle_SOLID
&&
92 SfxItemState::SET
== aAttr
.GetItemState( XATTR_FILLCOLOR
, true, &pPoolItem
) )
94 const XFillColorItem
* pItem
= static_cast<const XFillColorItem
*>(pPoolItem
);
95 XColorItem
aXColorItem( ATTR_COPY_START_COLOR
, pItem
->GetName(),
96 pItem
->GetColorValue() );
97 aSet
.Put( aXColorItem
);
102 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
105 boost::scoped_ptr
<AbstractCopyDlg
> pDlg(pFact
->CreateCopyDlg(NULL
, aSet
, mpDoc
->GetColorList(), mpView
));
109 sal_uInt16 nResult
= pDlg
->Execute();
114 pDlg
->GetAttr( aSet
);
116 pArgs
= rReq
.GetArgs();
130 sal_Int32 lWidth
= 0, lHeight
= 0, lSizeX
= 0L, lSizeY
= 0L, lAngle
= 0L;
131 sal_uInt16 nNumber
= 0;
132 Color aStartColor
, aEndColor
;
134 const SfxPoolItem
* pPoolItem
= NULL
;
137 if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( ATTR_COPY_NUMBER
, true, &pPoolItem
) )
138 nNumber
= static_cast<const SfxUInt16Item
*>( pPoolItem
)->GetValue();
141 if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( ATTR_COPY_MOVE_X
, true, &pPoolItem
) )
142 lSizeX
= static_cast<const SfxInt32Item
*>( pPoolItem
)->GetValue();
143 if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( ATTR_COPY_MOVE_Y
, true, &pPoolItem
) )
144 lSizeY
= static_cast<const SfxInt32Item
*>( pPoolItem
)->GetValue();
145 if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( ATTR_COPY_ANGLE
, true, &pPoolItem
) )
146 lAngle
= static_cast<const SfxInt32Item
*>( pPoolItem
)->GetValue();
149 if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( ATTR_COPY_WIDTH
, true, &pPoolItem
) )
150 lWidth
= static_cast<const SfxInt32Item
*>( pPoolItem
)->GetValue();
151 if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( ATTR_COPY_HEIGHT
, true, &pPoolItem
) )
152 lHeight
= static_cast<const SfxInt32Item
*>( pPoolItem
)->GetValue();
155 if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( ATTR_COPY_START_COLOR
, true, &pPoolItem
) )
157 aStartColor
= static_cast<const XColorItem
*>( pPoolItem
)->GetColorValue();
160 if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( ATTR_COPY_END_COLOR
, true, &pPoolItem
) )
162 aEndColor
= static_cast<const XColorItem
*>( pPoolItem
)->GetColorValue();
163 if( aStartColor
== aEndColor
)
170 //HMHmpView->HideMarkHdl();
172 boost::scoped_ptr
<SfxProgress
> pProgress
;
173 bool bWaiting
= false;
177 OUString
aStr( SD_RESSTR( STR_OBJECTS
) );
178 aStr
+= " " + SD_RESSTR( STR_UNDO_COPYOBJECTS
);
180 pProgress
.reset(new SfxProgress( mpDocSh
, aStr
, nNumber
));
181 mpDocSh
->SetWaitCursor( true );
185 const SdrMarkList
aMarkList( mpView
->GetMarkedObjectList() );
186 const size_t 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( drawing::FillStyle_SOLID
) );
215 aNewSet
.Put( XFillColorItem( OUString(), 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 const size_t nCopyMarkCount
= aMarkList
.GetMarkCount();
226 // set protection flags at marked copies to null
227 for( size_t j
= 0; j
< nCopyMarkCount
; ++j
)
229 pObj
= aCopyMarkList
.GetMark( j
)->GetMarkedSdrObj();
233 pObj
->SetMoveProtect( false );
234 pObj
->SetResizeProtect( 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( size_t 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( drawing::FillStyle_SOLID
) );
277 aNewSet
.Put( XFillColorItem( OUString(), aNewColor
) );
278 mpView
->SetAttributes( aNewSet
);
285 mpDocSh
->SetWaitCursor( false );
288 mpView
->AdjustMarkHdl(); //HMH sal_True );
289 //HMHpView->ShowMarkHdl();
295 } // end of namespace
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */