LibreOffice Module sd (master) 1
fucopy.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <fucopy.hxx>
21#include <sfx2/progress.hxx>
22#include <svl/intitem.hxx>
23
24#include <sdattr.hrc>
25#include <sdresid.hxx>
26#include <strings.hrc>
27#include <ViewShell.hxx>
28#include <View.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>
39#include <memory>
40
41using namespace com::sun::star;
42
43namespace sd {
44
45
47 ViewShell* pViewSh,
48 ::sd::Window* pWin,
49 ::sd::View* pView,
50 SdDrawDocument* pDoc,
51 SfxRequest& rReq)
52 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
53{
54}
55
57{
58 rtl::Reference<FuPoor> xFunc( new FuCopy( pViewSh, pWin, pView, pDoc, rReq ) );
59 xFunc->DoExecute(rReq);
60 return xFunc;
61}
62
64{
65 if( !mpView->AreObjectsMarked() )
66 return;
67
68 // Undo
69 OUString aString = mpView->GetDescriptionOfMarkedObjects() +
70 " " + SdResId( STR_UNDO_COPYOBJECTS );
71 mpView->BegUndo( aString );
72
73 const SfxItemSet* pArgs = rReq.GetArgs();
74
75 if( !pArgs )
76 {
78
79 // indicate color attribute
80 SfxItemSet aAttr( mpDoc->GetPool() );
81 mpView->GetAttributes( aAttr );
82
83 if( const XFillStyleItem* pFillStyleItem = aAttr.GetItemIfSet( XATTR_FILLSTYLE ) )
84 {
85 drawing::FillStyle eStyle = pFillStyleItem->GetValue();
86
87 const XFillColorItem* pFillColorItem;
88 if( eStyle == drawing::FillStyle_SOLID &&
89 (pFillColorItem = aAttr.GetItemIfSet( XATTR_FILLCOLOR )) )
90 {
91 XColorItem aXColorItem( ATTR_COPY_START_COLOR, pFillColorItem->GetName(),
92 pFillColorItem->GetColorValue() );
93 aSet.Put( aXColorItem );
94
95 }
96 }
97
100
101 sal_uInt16 nResult = pDlg->Execute();
102
103 switch( nResult )
104 {
105 case RET_OK:
106 pDlg->GetAttr( aSet );
107 rReq.Done( aSet );
108 pArgs = rReq.GetArgs();
109 break;
110
111 default:
112 {
113 pDlg.disposeAndClear();
114 mpView->EndUndo();
115 return; // Cancel
116 }
117 }
118 }
119
120 ::tools::Rectangle aRect;
121 sal_Int32 lWidth = 0, lHeight = 0, lSizeX = 0, lSizeY = 0;
122 Degree100 lAngle(0);
123 sal_uInt16 nNumber = 0;
124 Color aStartColor, aEndColor;
125 bool bColor = false;
126
127 if (pArgs)
128 {
129 // Count
130 if( const SfxUInt16Item* pPoolItem = pArgs->GetItemIfSet( ATTR_COPY_NUMBER ) )
131 nNumber = pPoolItem->GetValue();
132
133 // translation
134 if( const SfxInt32Item* pPoolItem = pArgs->GetItemIfSet( ATTR_COPY_MOVE_X ) )
135 lSizeX = pPoolItem->GetValue();
136 if( const SfxInt32Item* pPoolItem = pArgs->GetItemIfSet( ATTR_COPY_MOVE_Y ) )
137 lSizeY = pPoolItem->GetValue();
138 if( const SdrAngleItem* pPoolItem = pArgs->GetItemIfSet( ATTR_COPY_ANGLE ) )
139 lAngle = pPoolItem->GetValue();
140
141 // scale
142 if( const SfxInt32Item* pPoolItem = pArgs->GetItemIfSet( ATTR_COPY_WIDTH ) )
143 lWidth = pPoolItem->GetValue();
144 if( const SfxInt32Item* pPoolItem = pArgs->GetItemIfSet( ATTR_COPY_HEIGHT ) )
145 lHeight = pPoolItem->GetValue();
146
147 // start/end color
148 if( const XColorItem* pPoolItem = pArgs->GetItemIfSet( ATTR_COPY_START_COLOR ) )
149 {
150 aStartColor = pPoolItem->GetColorValue();
151 bColor = true;
152 }
153 if( const XColorItem* pPoolItem = pArgs->GetItemIfSet( ATTR_COPY_END_COLOR ) )
154 {
155 aEndColor = pPoolItem->GetColorValue();
156 if( aStartColor == aEndColor )
157 bColor = false;
158 }
159 }
160
161 // remove handles
162 //HMHmpView->HideMarkHdl();
163
164 std::unique_ptr<SfxProgress> pProgress;
165 bool bWaiting = false;
166
167 if( nNumber > 1 )
168 {
169 OUString aStr = SdResId( STR_OBJECTS ) +
170 " " + SdResId( STR_UNDO_COPYOBJECTS );
171
172 pProgress.reset(new SfxProgress( mpDocSh, aStr, nNumber ));
173 mpDocSh->SetWaitCursor( true );
174 bWaiting = true;
175 }
176
177 const SdrMarkList aMarkList( mpView->GetMarkedObjectList() );
178 const size_t nMarkCount = aMarkList.GetMarkCount();
179 SdrObject* pObj = nullptr;
180
181 // calculate number of possible copies
182 aRect = mpView->GetAllMarkedRect();
183
184 if( lWidth < 0 )
185 {
186 ::tools::Long nTmp = ( aRect.Right() - aRect.Left() ) / -lWidth;
187 nNumber = static_cast<sal_uInt16>(std::min( nTmp, static_cast<::tools::Long>(nNumber) ));
188 }
189
190 if( lHeight < 0 )
191 {
192 ::tools::Long nTmp = ( aRect.Bottom() - aRect.Top() ) / -lHeight;
193 nNumber = static_cast<sal_uInt16>(std::min( nTmp, static_cast<::tools::Long>(nNumber) ));
194 }
195
196 for( sal_uInt16 i = 1; i <= nNumber; i++ )
197 {
198 if( pProgress )
199 pProgress->SetState( i );
200
201 aRect = mpView->GetAllMarkedRect();
202
203 if( ( 1 == i ) && bColor )
204 {
206 aNewSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) );
207 aNewSet.Put( XFillColorItem( OUString(), aStartColor ) );
208 mpView->SetAttributes( aNewSet );
209 }
210
211 // make a copy of selected objects
213
214 // get newly selected objects
215 SdrMarkList aCopyMarkList( mpView->GetMarkedObjectList() );
216 const size_t nCopyMarkCount = aMarkList.GetMarkCount();
217
218 // set protection flags at marked copies to null
219 for( size_t j = 0; j < nCopyMarkCount; ++j )
220 {
221 pObj = aCopyMarkList.GetMark( j )->GetMarkedSdrObj();
222
223 if( pObj )
224 {
225 pObj->SetMoveProtect( false );
226 pObj->SetResizeProtect( false );
227 }
228 }
229
230 Fraction aWidth( aRect.Right() - aRect.Left() + lWidth, aRect.Right() - aRect.Left() );
231 Fraction aHeight( aRect.Bottom() - aRect.Top() + lHeight, aRect.Bottom() - aRect.Top() );
232
233 if( mpView->IsResizeAllowed() )
234 mpView->ResizeAllMarked( aRect.TopLeft(), aWidth, aHeight );
235
236 if( mpView->IsRotateAllowed() )
237 mpView->RotateAllMarked( aRect.Center(), lAngle );
238
239 if( mpView->IsMoveAllowed() )
240 mpView->MoveAllMarked( Size( lSizeX, lSizeY ) );
241
242 // set protection flags at marked copies to original values
243 if( nMarkCount == nCopyMarkCount )
244 {
245 for( size_t j = 0; j < nMarkCount; ++j )
246 {
247 SdrObject* pSrcObj = aMarkList.GetMark( j )->GetMarkedSdrObj();
248 SdrObject* pDstObj = aCopyMarkList.GetMark( j )->GetMarkedSdrObj();
249
250 if( pSrcObj && pDstObj &&
251 ( pSrcObj->GetObjInventor() == pDstObj->GetObjInventor() ) &&
252 ( pSrcObj->GetObjIdentifier() == pDstObj->GetObjIdentifier() ) )
253 {
254 pDstObj->SetMoveProtect( pSrcObj->IsMoveProtect() );
255 pDstObj->SetResizeProtect( pSrcObj->IsResizeProtect() );
256 }
257 }
258 }
259
260 if( bColor )
261 {
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 );
268 aNewSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) );
269 aNewSet.Put( XFillColorItem( OUString(), aNewColor ) );
270 mpView->SetAttributes( aNewSet );
271 }
272 }
273
274 pProgress.reset();
275
276 if ( bWaiting )
277 mpDocSh->SetWaitCursor( false );
278
279 // show handles
280 mpView->AdjustMarkHdl(); //HMH sal_True );
281 //HMHpView->ShowMarkHdl();
282
283 mpView->EndUndo();
284}
285
286} // end of namespace
287
288/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 GetBlue() const
sal_uInt8 GetRed() const
sal_uInt8 GetGreen() const
OUString const & GetName() const
virtual VclPtr< AbstractCopyDlg > CreateCopyDlg(weld::Window *pWindow, const SfxItemSet &rInAttrs, ::sd::View *pView)=0
static SD_DLLPUBLIC SdAbstractDialogFactory * Create()
Definition: sdabstdlg.cxx:38
SAL_DLLPRIVATE SfxItemPool & GetPool()
Definition: drawdoc.hxx:237
bool IsResizeAllowed(bool bProp=false) const
bool IsMoveAllowed() const
void BegUndo()
void ResizeAllMarked(const Point &rRef, const Fraction &xFact, const Fraction &yFact)
void RotateAllMarked(const Point &rRef, Degree100 nAngle)
void MoveAllMarked(const Size &rSiz, bool bCopy=false)
bool IsRotateAllowed(bool b90Deg=false) const
void CopyMarked()
void EndUndo()
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
bool AreObjectsMarked() const
OUString const & GetDescriptionOfMarkedObjects() const
void AdjustMarkHdl(SfxViewShell *pOtherShell=nullptr)
const tools::Rectangle & GetAllMarkedRect() const
SdrObject * GetMarkedSdrObj() const
bool IsResizeProtect() const
bool IsMoveProtect() const
virtual SdrInventor GetObjInventor() const
void SetResizeProtect(bool bProt)
void SetMoveProtect(bool bProt)
virtual SdrObjKind GetObjIdentifier() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void SetWaitCursor(bool bSet) const
const SfxItemSet * GetArgs() const
void Done(bool bRemove=false)
SfxItemPool & GetPool() const
void disposeAndClear()
const Color & GetColorValue() const
static rtl::Reference< FuPoor > Create(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fucopy.cxx:56
FuCopy(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fucopy.cxx:46
virtual void DoExecute(SfxRequest &rReq) override
Definition: fucopy.cxx:63
Base class for all functions.
Definition: fupoor.hxx:48
SdDrawDocument * mpDoc
Definition: fupoor.hxx:148
ViewShell * mpViewShell
Definition: fupoor.hxx:145
DrawDocShell * mpDocSh
Definition: fupoor.hxx:147
::sd::View * mpView
Definition: fupoor.hxx:144
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
SD_DLLPUBLIC weld::Window * GetFrameWeld() const
Definition: viewshel.cxx:1582
virtual bool SetAttributes(const SfxItemSet &rSet, bool bReplaceAll=false, bool bSlide=false, bool bMaster=false)
Definition: sdview.cxx:509
virtual void GetAttributes(SfxItemSet &rTargetSet, bool bOnlyHardAttr=false) const
Definition: sdview.cxx:515
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
constexpr Point Center() const
constexpr tools::Long Top() const
constexpr Point TopLeft() const
constexpr tools::Long Right() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
aStr
int i
long Long
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
unsigned char sal_uInt8
RET_OK
constexpr TypedWhichId< XFillColorItem > XATTR_FILLCOLOR(XATTR_FILL_FIRST+1)
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)