bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / dlg / copydlg.cxx
blob7d747ba8675e08b458e6f8294ea2eecb987d2d19
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 <svx/colorbox.hxx>
22 #include <sfx2/module.hxx>
23 #include <svx/xcolit.hxx>
24 #include <svl/intitem.hxx>
26 #include <unotools/viewoptions.hxx>
27 #include <svtools/unitconv.hxx>
29 #include <sdattr.hrc>
30 #include <View.hxx>
31 #include <drawdoc.hxx>
34 namespace sd {
36 #define TOKEN ';'
38 CopyDlg::CopyDlg(weld::Window* pWindow, const SfxItemSet& rInAttrs, ::sd::View* pInView)
39 : SfxDialogController(pWindow, "modules/sdraw/ui/copydlg.ui", "DuplicateDialog")
40 , mrOutAttrs(rInAttrs)
41 , maUIScale(pInView->GetDoc().GetUIScale())
42 , mpView(pInView)
43 , m_xNumFldCopies(m_xBuilder->weld_spin_button("copies"))
44 , m_xBtnSetViewData(m_xBuilder->weld_button("viewdata"))
45 , m_xMtrFldMoveX(m_xBuilder->weld_metric_spin_button("x", FieldUnit::CM))
46 , m_xMtrFldMoveY(m_xBuilder->weld_metric_spin_button("y", FieldUnit::CM))
47 , m_xMtrFldAngle(m_xBuilder->weld_metric_spin_button("angle", FieldUnit::DEGREE))
48 , m_xMtrFldWidth(m_xBuilder->weld_metric_spin_button("width", FieldUnit::CM))
49 , m_xMtrFldHeight(m_xBuilder->weld_metric_spin_button("height", FieldUnit::CM))
50 , m_xFtEndColor(m_xBuilder->weld_label("endlabel"))
51 , m_xBtnSetDefault(m_xBuilder->weld_button("default"))
52 , m_xLbStartColor(new ColorListBox(m_xBuilder->weld_menu_button("start"), pWindow))
53 , m_xLbEndColor(new ColorListBox(m_xBuilder->weld_menu_button("end"), pWindow))
55 m_xLbStartColor->SetSelectHdl( LINK( this, CopyDlg, SelectColorHdl ) );
56 m_xBtnSetViewData->connect_clicked( LINK( this, CopyDlg, SetViewData ) );
57 m_xBtnSetDefault->connect_clicked( LINK( this, CopyDlg, SetDefault ) );
59 FieldUnit eFUnit( SfxModule::GetCurrentFieldUnit() );
61 SetFieldUnit( *m_xMtrFldMoveX, eFUnit, true );
62 SetFieldUnit( *m_xMtrFldMoveY, eFUnit, true );
63 SetFieldUnit( *m_xMtrFldWidth, eFUnit, true );
64 SetFieldUnit( *m_xMtrFldHeight, eFUnit, true );
66 Reset();
69 CopyDlg::~CopyDlg()
71 SvtViewOptions aDlgOpt(EViewType::Dialog, OStringToOUString(m_xDialog->get_help_id(), RTL_TEXTENCODING_UTF8));
72 OUString sStr =
73 OUString::number(m_xNumFldCopies->get_value()) + OUString(TOKEN) +
74 OUString::number(m_xMtrFldMoveX->get_value(FieldUnit::NONE)) + OUString(TOKEN) +
75 OUString::number(m_xMtrFldMoveY->get_value(FieldUnit::NONE)) + OUString(TOKEN) +
76 OUString::number(m_xMtrFldAngle->get_value(FieldUnit::NONE)) + OUString(TOKEN) +
77 OUString::number(m_xMtrFldWidth->get_value(FieldUnit::NONE)) + OUString(TOKEN) +
78 OUString::number(m_xMtrFldHeight->get_value(FieldUnit::NONE)) + OUString(TOKEN) +
79 OUString::number(static_cast<sal_uInt32>(m_xLbStartColor->GetSelectEntryColor())) + OUString(TOKEN) +
80 OUString::number(static_cast<sal_uInt32>(m_xLbEndColor->GetSelectEntryColor()));
81 aDlgOpt.SetUserItem("UserItem", css::uno::makeAny(sStr));
84 /**
85 * reads provided item set or evaluate ini string
87 void CopyDlg::Reset()
89 // Set Min/Max values
90 ::tools::Rectangle aRect = mpView->GetAllMarkedRect();
91 Size aPageSize = mpView->GetSdrPageView()->GetPage()->GetSize();
93 // tdf#125011 draw/impress sizes are in mm_100th already, "normalize" to
94 // decimal shift by number of decimal places the widgets are using (2) then
95 // scale by the ui scaling factor
96 auto nPageWidth = long(m_xMtrFldMoveX->normalize(aPageSize.Width()) / maUIScale);
97 auto nPageHeight = long(m_xMtrFldMoveX->normalize(aPageSize.Height()) / maUIScale);
98 auto nRectWidth = long(m_xMtrFldMoveX->normalize(aRect.GetWidth()) / maUIScale);
99 auto nRectHeight = long(m_xMtrFldMoveX->normalize(aRect.GetHeight()) / maUIScale);
101 m_xMtrFldMoveX->set_range(-nPageWidth, nPageWidth, FieldUnit::MM_100TH);
102 m_xMtrFldMoveY->set_range(-nPageHeight, nPageHeight, FieldUnit::MM_100TH);
103 m_xMtrFldWidth->set_range(-nRectWidth, nPageWidth, FieldUnit::MM_100TH);
104 m_xMtrFldHeight->set_range(-nRectHeight, nPageHeight, FieldUnit::MM_100TH);
106 const SfxPoolItem* pPoolItem = nullptr;
107 OUString aStr;
108 SvtViewOptions aDlgOpt(EViewType::Dialog, OStringToOUString(m_xDialog->get_help_id(), RTL_TEXTENCODING_UTF8));
109 if (aDlgOpt.Exists())
111 css::uno::Any aUserItem = aDlgOpt.GetUserItem("UserItem");
112 aUserItem >>= aStr;
115 if (aStr.isEmpty())
117 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_NUMBER, true, &pPoolItem ) )
118 m_xNumFldCopies->set_value(static_cast<const SfxUInt16Item*>(pPoolItem)->GetValue());
119 else
120 m_xNumFldCopies->set_value(1);
122 long nMoveX = 500;
123 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_X, true, &pPoolItem ) )
124 nMoveX = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
125 SetMetricValue( *m_xMtrFldMoveX, long(nMoveX / maUIScale), MapUnit::Map100thMM);
127 long nMoveY = 500;
128 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_Y, true, &pPoolItem ) )
129 nMoveY = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
130 SetMetricValue( *m_xMtrFldMoveY, long(nMoveY / maUIScale), MapUnit::Map100thMM);
132 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_ANGLE, true, &pPoolItem ) )
133 m_xMtrFldAngle->set_value(static_cast<const SfxInt32Item*>( pPoolItem )->GetValue(), FieldUnit::NONE);
134 else
135 m_xMtrFldAngle->set_value(0, FieldUnit::NONE);
137 long nWidth = 0;
138 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_WIDTH, true, &pPoolItem ) )
139 nWidth = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
140 SetMetricValue( *m_xMtrFldWidth, long(nWidth / maUIScale), MapUnit::Map100thMM);
142 long nHeight = 0;
143 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_HEIGHT, true, &pPoolItem ) )
144 nHeight = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
145 SetMetricValue( *m_xMtrFldHeight, long(nHeight / maUIScale), MapUnit::Map100thMM);
147 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
149 Color aColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
150 m_xLbStartColor->SelectEntry( aColor );
151 m_xLbEndColor->SelectEntry( aColor );
153 else
155 m_xLbStartColor->SetNoSelection();
156 m_xLbEndColor->SetNoSelection();
157 m_xLbEndColor->set_sensitive(false);
158 m_xFtEndColor->set_sensitive(false);
161 else
163 sal_Int32 nIdx {0};
164 m_xNumFldCopies->set_value(aStr.getToken(0, TOKEN, nIdx).toInt64());
165 m_xMtrFldMoveX->set_value(aStr.getToken(0, TOKEN, nIdx).toInt64(), FieldUnit::NONE);
166 m_xMtrFldMoveY->set_value(aStr.getToken(0, TOKEN, nIdx).toInt64(), FieldUnit::NONE);
167 m_xMtrFldAngle->set_value(aStr.getToken(0, TOKEN, nIdx).toInt64(), FieldUnit::NONE);
168 m_xMtrFldWidth->set_value(aStr.getToken(0, TOKEN, nIdx).toInt64(), FieldUnit::NONE);
169 m_xMtrFldHeight->set_value(aStr.getToken(0, TOKEN, nIdx).toInt64(), FieldUnit::NONE);
170 m_xLbStartColor->SelectEntry( Color( aStr.getToken(0, TOKEN, nIdx).toUInt32() ) );
171 m_xLbEndColor->SelectEntry( Color( aStr.getToken(0, TOKEN, nIdx).toUInt32() ) );
177 * fills provided item set with dialog box attributes
179 void CopyDlg::GetAttr( SfxItemSet& rOutAttrs )
181 long nMoveX = long( GetCoreValue( *m_xMtrFldMoveX, MapUnit::Map100thMM) * maUIScale);
182 long nMoveY = long( GetCoreValue( *m_xMtrFldMoveY, MapUnit::Map100thMM) * maUIScale);
183 long nHeight = long( GetCoreValue( *m_xMtrFldHeight, MapUnit::Map100thMM) * maUIScale);
184 long nWidth = long( GetCoreValue( *m_xMtrFldWidth, MapUnit::Map100thMM) * maUIScale);
186 rOutAttrs.Put( SfxUInt16Item( ATTR_COPY_NUMBER, static_cast<sal_uInt16>(m_xNumFldCopies->get_value()) ) );
187 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_X, nMoveX ) );
188 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_Y, nMoveY ) );
189 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_ANGLE, static_cast<sal_Int32>(m_xMtrFldAngle->get_value(FieldUnit::DEGREE)) ) );
190 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_WIDTH, nWidth ) );
191 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_HEIGHT, nHeight ) );
193 NamedColor aColor = m_xLbStartColor->GetSelectedEntry();
194 rOutAttrs.Put(XColorItem(ATTR_COPY_START_COLOR, aColor.second, aColor.first));
195 aColor = m_xLbEndColor->GetSelectedEntry();
196 rOutAttrs.Put(XColorItem(ATTR_COPY_END_COLOR, aColor.second, aColor.first));
200 * enables and selects end color LB
202 IMPL_LINK_NOARG(CopyDlg, SelectColorHdl, ColorListBox&, void)
204 const Color aColor = m_xLbStartColor->GetSelectEntryColor();
206 if (!m_xLbEndColor->get_sensitive())
208 m_xLbEndColor->SelectEntry(aColor);
209 m_xLbEndColor->set_sensitive(true);
210 m_xFtEndColor->set_sensitive(true);
215 * sets values of selection
217 IMPL_LINK_NOARG(CopyDlg, SetViewData, weld::Button&, void)
219 ::tools::Rectangle aRect = mpView->GetAllMarkedRect();
221 SetMetricValue( *m_xMtrFldMoveX, long( aRect.GetWidth() /
222 maUIScale ), MapUnit::Map100thMM);
223 SetMetricValue( *m_xMtrFldMoveY, long( aRect.GetHeight() /
224 maUIScale ), MapUnit::Map100thMM);
226 // sets color attribute
227 const SfxPoolItem* pPoolItem = nullptr;
228 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
230 Color aColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
231 m_xLbStartColor->SelectEntry( aColor );
236 * resets values to default
238 IMPL_LINK_NOARG(CopyDlg, SetDefault, weld::Button&, void)
240 m_xNumFldCopies->set_value(1);
242 long nValue = 500;
243 SetMetricValue( *m_xMtrFldMoveX, long(nValue / maUIScale), MapUnit::Map100thMM);
244 SetMetricValue( *m_xMtrFldMoveY, long(nValue / maUIScale), MapUnit::Map100thMM);
246 nValue = 0;
247 m_xMtrFldAngle->set_value(nValue, FieldUnit::DEGREE);
248 SetMetricValue( *m_xMtrFldWidth, long(nValue / maUIScale), MapUnit::Map100thMM);
249 SetMetricValue( *m_xMtrFldHeight, long(nValue / maUIScale), MapUnit::Map100thMM);
251 // set color attribute
252 const SfxPoolItem* pPoolItem = nullptr;
253 if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
255 Color aColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
256 m_xLbStartColor->SelectEntry( aColor );
257 m_xLbEndColor->SelectEntry( aColor );
261 } // end of namespace sd
263 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */