Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / dlg / copydlg.cxx
blob5cd238bba6059bcbefe4e820e70b2e99d3ea8b0a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <copydlg.hxx>
21 #include <comphelper/string.hxx>
22 #include <svx/colorbox.hxx>
23 #include <svx/dlgutil.hxx>
24 #include <sfx2/module.hxx>
25 #include <svx/xcolit.hxx>
26 #include <svx/xflclit.hxx>
27 #include <svx/xdef.hxx>
28 #include <svx/xfillit0.hxx>
29 #include <svx/xenum.hxx>
31 #include <sfx2/app.hxx>
33 #include <sdattr.hxx>
35 #include <View.hxx>
36 #include <drawdoc.hxx>
39 namespace sd {
41 #define TOKEN ';'
43 CopyDlg::CopyDlg(vcl::Window* pWindow, const SfxItemSet& rInAttrs, ::sd::View* pInView)
44 : SfxModalDialog(pWindow, "DuplicateDialog", "modules/sdraw/ui/copydlg.ui")
45 , mrOutAttrs(rInAttrs)
46 , maUIScale(pInView->GetDoc().GetUIScale())
47 , mpView(pInView)
49 get(m_pNumFldCopies, "copies");
50 get(m_pBtnSetViewData, "viewdata");
51 get(m_pMtrFldMoveX, "x");
52 get(m_pMtrFldMoveY, "y");
53 get(m_pMtrFldAngle, "angle");
54 get(m_pMtrFldWidth, "width");
55 get(m_pMtrFldHeight, "height");
56 get(m_pLbStartColor, "start");
57 get(m_pFtEndColor, "endlabel");
58 get(m_pLbEndColor, "end");
59 get(m_pBtnSetDefault, "default");
61 m_pLbStartColor->SetSelectHdl( LINK( this, CopyDlg, SelectColorHdl ) );
62 m_pBtnSetViewData->SetClickHdl( LINK( this, CopyDlg, SetViewData ) );
63 m_pBtnSetDefault->SetClickHdl( LINK( this, CopyDlg, SetDefault ) );
65 FieldUnit eFUnit( SfxModule::GetCurrentFieldUnit() );
67 SetFieldUnit( *m_pMtrFldMoveX, eFUnit, true );
68 SetFieldUnit( *m_pMtrFldMoveY, eFUnit, true );
69 SetFieldUnit( *m_pMtrFldWidth, eFUnit, true );
70 SetFieldUnit( *m_pMtrFldHeight, eFUnit, true );
72 Reset();
75 CopyDlg::~CopyDlg()
77 disposeOnce();
80 void CopyDlg::dispose()
82 OUString& rStr = GetExtraData();
84 rStr = OUString::number(m_pNumFldCopies->GetValue());
85 rStr += OUString(TOKEN);
87 rStr += OUString::number(m_pMtrFldMoveX->GetValue());
88 rStr += OUString( TOKEN );
90 rStr += OUString::number(m_pMtrFldMoveY->GetValue());
91 rStr += OUString( TOKEN );
93 rStr += OUString::number(m_pMtrFldAngle->GetValue());
94 rStr += OUString( TOKEN );
96 rStr += OUString::number(m_pMtrFldWidth->GetValue());
97 rStr += OUString( TOKEN );
99 rStr += OUString::number(m_pMtrFldHeight->GetValue());
100 rStr += OUString( TOKEN );
102 rStr += OUString::number( sal_uInt32(m_pLbStartColor->GetSelectEntryColor()) );
103 rStr += OUString( TOKEN );
105 rStr += OUString::number( sal_uInt32(m_pLbEndColor->GetSelectEntryColor()) );
107 m_pNumFldCopies.clear();
108 m_pBtnSetViewData.clear();
109 m_pMtrFldMoveX.clear();
110 m_pMtrFldMoveY.clear();
111 m_pMtrFldAngle.clear();
112 m_pMtrFldWidth.clear();
113 m_pMtrFldHeight.clear();
114 m_pLbStartColor.clear();
115 m_pFtEndColor.clear();
116 m_pLbEndColor.clear();
117 m_pBtnSetDefault.clear();
118 SfxModalDialog::dispose();
122 * reads provided item set or evaluate ini string
124 void CopyDlg::Reset()
126 // Set Min/Max values
127 ::tools::Rectangle aRect = mpView->GetAllMarkedRect();
128 Size aPageSize = mpView->GetSdrPageView()->GetPage()->GetSize();
129 SetMetricValue( *m_pMtrFldMoveX, long(1000000 / maUIScale), MapUnit::Map100thMM);
130 double fScaleFactor = m_pMtrFldMoveX->GetValue()/1000000.0;
132 long nPageWidth = aPageSize.Width() * fScaleFactor;
133 long nPageHeight = aPageSize.Height() * fScaleFactor;
134 long nRectWidth = aRect.GetWidth() * fScaleFactor;
135 long nRectHeight = aRect.GetHeight() * fScaleFactor;
136 m_pMtrFldMoveX->SetMin( -nPageWidth );
137 m_pMtrFldMoveX->SetMax( nPageWidth );
138 m_pMtrFldMoveY->SetMin( -nPageHeight );
139 m_pMtrFldMoveY->SetMax( nPageHeight );
140 m_pMtrFldWidth->SetMin( -nRectWidth );
141 m_pMtrFldWidth->SetMax( nPageWidth );
142 m_pMtrFldHeight->SetMin( -nRectHeight );
143 m_pMtrFldHeight->SetMax( nPageHeight );
145 const SfxPoolItem* pPoolItem = nullptr;
146 OUString aStr( GetExtraData() );
148 if (comphelper::string::getTokenCount(aStr, TOKEN) < 8)
150 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_NUMBER, true, &pPoolItem ) )
151 m_pNumFldCopies->SetValue( static_cast<const SfxUInt16Item*>( pPoolItem )->GetValue() );
152 else
153 m_pNumFldCopies->SetValue( 1 );
155 long nMoveX = 500;
156 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_X, true, &pPoolItem ) )
157 nMoveX = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
158 SetMetricValue( *m_pMtrFldMoveX, long(nMoveX / maUIScale), MapUnit::Map100thMM);
160 long nMoveY = 500;
161 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_Y, true, &pPoolItem ) )
162 nMoveY = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
163 SetMetricValue( *m_pMtrFldMoveY, long(nMoveY / maUIScale), MapUnit::Map100thMM);
165 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_ANGLE, true, &pPoolItem ) )
166 m_pMtrFldAngle->SetValue( static_cast<const SfxInt32Item*>( pPoolItem )->GetValue() );
167 else
168 m_pMtrFldAngle->SetValue( 0 );
170 long nWidth = 0;
171 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_WIDTH, true, &pPoolItem ) )
172 nWidth = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
173 SetMetricValue( *m_pMtrFldWidth, long(nWidth / maUIScale), MapUnit::Map100thMM);
175 long nHeight = 0;
176 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_HEIGHT, true, &pPoolItem ) )
177 nHeight = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
178 SetMetricValue( *m_pMtrFldHeight, long(nHeight / maUIScale), MapUnit::Map100thMM);
180 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
182 Color aColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
183 m_pLbStartColor->SelectEntry( aColor );
184 m_pLbEndColor->SelectEntry( aColor );
186 else
188 m_pLbStartColor->SetNoSelection();
189 m_pLbEndColor->SetNoSelection();
190 m_pLbEndColor->Disable();
191 m_pFtEndColor->Disable();
194 else
196 sal_Int32 nTmp;
197 nTmp = static_cast<long>(aStr.getToken( 0, TOKEN ).toInt32());
198 m_pNumFldCopies->SetValue( nTmp );
200 nTmp = static_cast<long>(aStr.getToken( 1, TOKEN ).toInt32());
201 m_pMtrFldMoveX->SetValue( nTmp );
203 nTmp = static_cast<long>(aStr.getToken( 2, TOKEN ).toInt32());
204 m_pMtrFldMoveY->SetValue( nTmp );
206 nTmp = static_cast<long>(aStr.getToken( 3, TOKEN ).toInt32());
207 m_pMtrFldAngle->SetValue( nTmp );
209 nTmp = static_cast<long>(aStr.getToken( 4, TOKEN ).toInt32());
210 m_pMtrFldWidth->SetValue( nTmp );
212 nTmp = static_cast<long>(aStr.getToken( 5, TOKEN ).toInt32());
213 m_pMtrFldHeight->SetValue( nTmp );
215 nTmp = static_cast<long>(aStr.getToken( 6, TOKEN ).toInt32());
216 m_pLbStartColor->SelectEntry( Color( nTmp ) );
218 nTmp = static_cast<long>(aStr.getToken( 7, TOKEN ).toInt32());
219 m_pLbEndColor->SelectEntry( Color( nTmp ) );
225 * fills provided item set with dialog box attributes
227 void CopyDlg::GetAttr( SfxItemSet& rOutAttrs )
229 long nMoveX = long( GetCoreValue( *m_pMtrFldMoveX, MapUnit::Map100thMM) * maUIScale);
230 long nMoveY = long( GetCoreValue( *m_pMtrFldMoveY, MapUnit::Map100thMM) * maUIScale);
231 long nHeight = long( GetCoreValue( *m_pMtrFldHeight, MapUnit::Map100thMM) * maUIScale);
232 long nWidth = long( GetCoreValue( *m_pMtrFldWidth, MapUnit::Map100thMM) * maUIScale);
234 rOutAttrs.Put( SfxUInt16Item( ATTR_COPY_NUMBER, static_cast<sal_uInt16>(m_pNumFldCopies->GetValue()) ) );
235 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_X, nMoveX ) );
236 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_Y, nMoveY ) );
237 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_ANGLE, static_cast<sal_Int32>(m_pMtrFldAngle->GetValue()) ) );
238 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_WIDTH, nWidth ) );
239 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_HEIGHT, nHeight ) );
241 NamedColor aColor = m_pLbStartColor->GetSelectedEntry();
242 rOutAttrs.Put(XColorItem(ATTR_COPY_START_COLOR, aColor.second, aColor.first));
243 aColor = m_pLbEndColor->GetSelectedEntry();
244 rOutAttrs.Put(XColorItem(ATTR_COPY_END_COLOR, aColor.second, aColor.first));
248 * enables and selects end color LB
250 IMPL_LINK_NOARG(CopyDlg, SelectColorHdl, SvxColorListBox&, void)
252 const Color aColor = m_pLbStartColor->GetSelectEntryColor();
254 if (!m_pLbEndColor->IsEnabled())
256 m_pLbEndColor->SelectEntry(aColor);
257 m_pLbEndColor->Enable();
258 m_pFtEndColor->Enable();
263 * sets values of selection
265 IMPL_LINK_NOARG(CopyDlg, SetViewData, Button*, void)
267 ::tools::Rectangle aRect = mpView->GetAllMarkedRect();
269 SetMetricValue( *m_pMtrFldMoveX, long( aRect.GetWidth() /
270 maUIScale ), MapUnit::Map100thMM);
271 SetMetricValue( *m_pMtrFldMoveY, long( aRect.GetHeight() /
272 maUIScale ), MapUnit::Map100thMM);
274 // sets color attribute
275 const SfxPoolItem* pPoolItem = nullptr;
276 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
278 Color aColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
279 m_pLbStartColor->SelectEntry( aColor );
284 * resets values to default
286 IMPL_LINK_NOARG(CopyDlg, SetDefault, Button*, void)
288 m_pNumFldCopies->SetValue( 1 );
290 long nValue = 500;
291 SetMetricValue( *m_pMtrFldMoveX, long(nValue / maUIScale), MapUnit::Map100thMM);
292 SetMetricValue( *m_pMtrFldMoveY, long(nValue / maUIScale), MapUnit::Map100thMM);
294 nValue = 0;
295 m_pMtrFldAngle->SetValue( nValue );
296 SetMetricValue( *m_pMtrFldWidth, long(nValue / maUIScale), MapUnit::Map100thMM);
297 SetMetricValue( *m_pMtrFldHeight, long(nValue / maUIScale), MapUnit::Map100thMM);
299 // set color attribute
300 const SfxPoolItem* pPoolItem = nullptr;
301 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
303 Color aColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
304 m_pLbStartColor->SelectEntry( aColor );
305 m_pLbEndColor->SelectEntry( aColor );
309 } // end of namespace sd
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */