LibreOffice Module sd (master) 1
copydlg.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 <copydlg.hxx>
21#include <svx/colorbox.hxx>
22#include <svx/svdpagv.hxx>
23#include <svx/sdangitm.hxx>
24#include <sfx2/module.hxx>
25#include <svx/xcolit.hxx>
26#include <svl/intitem.hxx>
27
29#include <svtools/unitconv.hxx>
30#include <o3tl/string_view.hxx>
31
32#include <sdattr.hrc>
33#include <View.hxx>
34#include <drawdoc.hxx>
35
36
37namespace sd {
38
39constexpr char TOKEN = ';';
40
41CopyDlg::CopyDlg(weld::Window* pWindow, const SfxItemSet& rInAttrs, ::sd::View* pInView)
42 : SfxDialogController(pWindow, "modules/sdraw/ui/copydlg.ui", "DuplicateDialog")
43 , mrOutAttrs(rInAttrs)
44 , maUIScale(pInView->GetDoc().GetUIScale())
45 , mpView(pInView)
46 , m_xNumFldCopies(m_xBuilder->weld_spin_button("copies"))
47 , m_xBtnSetViewData(m_xBuilder->weld_button("viewdata"))
48 , m_xMtrFldMoveX(m_xBuilder->weld_metric_spin_button("x", FieldUnit::CM))
49 , m_xMtrFldMoveY(m_xBuilder->weld_metric_spin_button("y", FieldUnit::CM))
50 , m_xMtrFldAngle(m_xBuilder->weld_metric_spin_button("angle", FieldUnit::DEGREE))
51 , m_xMtrFldWidth(m_xBuilder->weld_metric_spin_button("width", FieldUnit::CM))
52 , m_xMtrFldHeight(m_xBuilder->weld_metric_spin_button("height", FieldUnit::CM))
53 , m_xFtEndColor(m_xBuilder->weld_label("endlabel"))
54 , m_xBtnSetDefault(m_xBuilder->weld_button("default"))
55 , m_xLbStartColor(new ColorListBox(m_xBuilder->weld_menu_button("start"), [this]{ return m_xDialog.get(); } ))
56 , m_xLbEndColor(new ColorListBox(m_xBuilder->weld_menu_button("end"), [this]{ return m_xDialog.get(); } ))
57{
58 m_xLbStartColor->SetSelectHdl( LINK( this, CopyDlg, SelectColorHdl ) );
59 m_xBtnSetViewData->connect_clicked( LINK( this, CopyDlg, SetViewData ) );
60 m_xBtnSetDefault->connect_clicked( LINK( this, CopyDlg, SetDefault ) );
61
63
64 SetFieldUnit( *m_xMtrFldMoveX, eFUnit, true );
65 SetFieldUnit( *m_xMtrFldMoveY, eFUnit, true );
66 SetFieldUnit( *m_xMtrFldWidth, eFUnit, true );
67 SetFieldUnit( *m_xMtrFldHeight, eFUnit, true );
68
69 Reset();
70}
71
73{
74 SvtViewOptions aDlgOpt(EViewType::Dialog, m_xDialog->get_help_id());
75 OUString sStr =
76 OUString::number(m_xNumFldCopies->get_value()) + OUStringChar(TOKEN) +
77 OUString::number(m_xMtrFldMoveX->get_value(FieldUnit::NONE)) + OUStringChar(TOKEN) +
78 OUString::number(m_xMtrFldMoveY->get_value(FieldUnit::NONE)) + OUStringChar(TOKEN) +
79 OUString::number(m_xMtrFldAngle->get_value(FieldUnit::NONE)) + OUStringChar(TOKEN) +
80 OUString::number(m_xMtrFldWidth->get_value(FieldUnit::NONE)) + OUStringChar(TOKEN) +
81 OUString::number(m_xMtrFldHeight->get_value(FieldUnit::NONE)) + OUStringChar(TOKEN) +
82 OUString::number(static_cast<sal_uInt32>(m_xLbStartColor->GetSelectEntryColor())) + OUStringChar(TOKEN) +
83 OUString::number(static_cast<sal_uInt32>(m_xLbEndColor->GetSelectEntryColor()));
84 aDlgOpt.SetUserItem("UserItem", css::uno::Any(sStr));
85}
86
91{
92 // Set Min/Max values
94 Size aPageSize = mpView->GetSdrPageView()->GetPage()->GetSize();
95
96 // tdf#125011 draw/impress sizes are in mm_100th already, "normalize" to
97 // decimal shift by number of decimal places the widgets are using (2) then
98 // scale by the ui scaling factor
99 auto nPageWidth = tools::Long(m_xMtrFldMoveX->normalize(aPageSize.Width()) / maUIScale);
100 auto nPageHeight = tools::Long(m_xMtrFldMoveX->normalize(aPageSize.Height()) / maUIScale);
101 auto nRectWidth = tools::Long(m_xMtrFldMoveX->normalize(aRect.GetWidth()) / maUIScale);
102 auto nRectHeight = tools::Long(m_xMtrFldMoveX->normalize(aRect.GetHeight()) / maUIScale);
103
104 m_xMtrFldMoveX->set_range(-nPageWidth, nPageWidth, FieldUnit::MM_100TH);
105 m_xMtrFldMoveY->set_range(-nPageHeight, nPageHeight, FieldUnit::MM_100TH);
106 m_xMtrFldWidth->set_range(-nRectWidth, nPageWidth, FieldUnit::MM_100TH);
107 m_xMtrFldHeight->set_range(-nRectHeight, nPageHeight, FieldUnit::MM_100TH);
108
109 OUString aStr;
110 SvtViewOptions aDlgOpt(EViewType::Dialog, m_xDialog->get_help_id());
111 if (aDlgOpt.Exists())
112 {
113 css::uno::Any aUserItem = aDlgOpt.GetUserItem("UserItem");
114 aUserItem >>= aStr;
115 }
116
117 if (aStr.isEmpty())
118 {
119 if( const SfxUInt16Item* pPoolItem = mrOutAttrs.GetItemIfSet( ATTR_COPY_NUMBER ) )
120 m_xNumFldCopies->set_value(pPoolItem->GetValue());
121 else
122 m_xNumFldCopies->set_value(1);
123
124 tools::Long nMoveX = 500;
125 if( const SfxInt32Item* pPoolItem = mrOutAttrs.GetItemIfSet( ATTR_COPY_MOVE_X ) )
126 nMoveX = pPoolItem->GetValue();
127 SetMetricValue( *m_xMtrFldMoveX, tools::Long(nMoveX / maUIScale), MapUnit::Map100thMM);
128
129 tools::Long nMoveY = 500;
130 if( const SfxInt32Item* pPoolItem = mrOutAttrs.GetItemIfSet( ATTR_COPY_MOVE_Y ) )
131 nMoveY = pPoolItem->GetValue();
132 SetMetricValue( *m_xMtrFldMoveY, tools::Long(nMoveY / maUIScale), MapUnit::Map100thMM);
133
134 if( const SdrAngleItem* pPoolItem = mrOutAttrs.GetItemIfSet( ATTR_COPY_ANGLE ) )
135 m_xMtrFldAngle->set_value( pPoolItem->GetValue().get(), FieldUnit::NONE);
136 else
137 m_xMtrFldAngle->set_value(0, FieldUnit::NONE);
138
139 tools::Long nWidth = 0;
140 if( const SfxInt32Item* pPoolItem = mrOutAttrs.GetItemIfSet( ATTR_COPY_WIDTH ) )
141 nWidth = pPoolItem->GetValue();
142 SetMetricValue( *m_xMtrFldWidth, tools::Long(nWidth / maUIScale), MapUnit::Map100thMM);
143
144 tools::Long nHeight = 0;
145 if( const SfxInt32Item* pPoolItem = mrOutAttrs.GetItemIfSet( ATTR_COPY_HEIGHT ) )
146 nHeight = pPoolItem->GetValue();
147 SetMetricValue( *m_xMtrFldHeight, tools::Long(nHeight / maUIScale), MapUnit::Map100thMM);
148
149 if( const XColorItem* pPoolItem = mrOutAttrs.GetItemIfSet( ATTR_COPY_START_COLOR ) )
150 {
151 Color aColor = pPoolItem->GetColorValue();
152 m_xLbStartColor->SelectEntry( aColor );
153 m_xLbEndColor->SelectEntry( aColor );
154 }
155 else
156 {
157 m_xLbStartColor->SetNoSelection();
158 m_xLbEndColor->SetNoSelection();
159 m_xLbEndColor->set_sensitive(false);
160 m_xFtEndColor->set_sensitive(false);
161 }
162 }
163 else
164 {
165 sal_Int32 nIdx {0};
166 m_xNumFldCopies->set_value(o3tl::toInt64(o3tl::getToken(aStr, 0, TOKEN, nIdx)));
167 m_xMtrFldMoveX->set_value(o3tl::toInt64(o3tl::getToken(aStr, 0, TOKEN, nIdx)), FieldUnit::NONE);
168 m_xMtrFldMoveY->set_value(o3tl::toInt64(o3tl::getToken(aStr, 0, TOKEN, nIdx)), FieldUnit::NONE);
169 m_xMtrFldAngle->set_value(o3tl::toInt64(o3tl::getToken(aStr, 0, TOKEN, nIdx)), FieldUnit::NONE);
170 m_xMtrFldWidth->set_value(o3tl::toInt64(o3tl::getToken(aStr, 0, TOKEN, nIdx)), FieldUnit::NONE);
171 m_xMtrFldHeight->set_value(o3tl::toInt64(o3tl::getToken(aStr, 0, TOKEN, nIdx)), FieldUnit::NONE);
174 }
175
176}
177
181void CopyDlg::GetAttr( SfxItemSet& rOutAttrs )
182{
183 tools::Long nMoveX = tools::Long( GetCoreValue( *m_xMtrFldMoveX, MapUnit::Map100thMM) * maUIScale);
184 tools::Long nMoveY = tools::Long( GetCoreValue( *m_xMtrFldMoveY, MapUnit::Map100thMM) * maUIScale);
185 tools::Long nHeight = tools::Long( GetCoreValue( *m_xMtrFldHeight, MapUnit::Map100thMM) * maUIScale);
186 tools::Long nWidth = tools::Long( GetCoreValue( *m_xMtrFldWidth, MapUnit::Map100thMM) * maUIScale);
187
188 rOutAttrs.Put( SfxUInt16Item( ATTR_COPY_NUMBER, static_cast<sal_uInt16>(m_xNumFldCopies->get_value()) ) );
189 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_X, nMoveX ) );
190 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_Y, nMoveY ) );
191 rOutAttrs.Put( SdrAngleItem( ATTR_COPY_ANGLE, Degree100(static_cast<sal_Int32>(m_xMtrFldAngle->get_value(FieldUnit::DEGREE))) ) );
192 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_WIDTH, nWidth ) );
193 rOutAttrs.Put( SfxInt32Item( ATTR_COPY_HEIGHT, nHeight ) );
194
195 NamedColor aColor = m_xLbStartColor->GetSelectedEntry();
196 rOutAttrs.Put(XColorItem(ATTR_COPY_START_COLOR, aColor.m_aName, aColor.m_aColor));
197 aColor = m_xLbEndColor->GetSelectedEntry();
198 rOutAttrs.Put(XColorItem(ATTR_COPY_END_COLOR, aColor.m_aName, aColor.m_aColor));
199}
200
204IMPL_LINK_NOARG(CopyDlg, SelectColorHdl, ColorListBox&, void)
205{
206 const Color aColor = m_xLbStartColor->GetSelectEntryColor();
207
208 if (!m_xLbEndColor->get_sensitive())
209 {
210 m_xLbEndColor->SelectEntry(aColor);
211 m_xLbEndColor->set_sensitive(true);
212 m_xFtEndColor->set_sensitive(true);
213 }
214}
215
220{
221 ::tools::Rectangle aRect = mpView->GetAllMarkedRect();
222
223 SetMetricValue( *m_xMtrFldMoveX, tools::Long( aRect.GetWidth() /
224 maUIScale ), MapUnit::Map100thMM);
225 SetMetricValue( *m_xMtrFldMoveY, tools::Long( aRect.GetHeight() /
226 maUIScale ), MapUnit::Map100thMM);
227
228 // sets color attribute
229 if( const XColorItem* pPoolItem = mrOutAttrs.GetItemIfSet( ATTR_COPY_START_COLOR ) )
230 {
231 Color aColor = pPoolItem->GetColorValue();
232 m_xLbStartColor->SelectEntry( aColor );
233 }
234}
235
240{
241 m_xNumFldCopies->set_value(1);
242
243 tools::Long nValue = 500;
244 SetMetricValue( *m_xMtrFldMoveX, tools::Long(nValue / maUIScale), MapUnit::Map100thMM);
245 SetMetricValue( *m_xMtrFldMoveY, tools::Long(nValue / maUIScale), MapUnit::Map100thMM);
246
247 nValue = 0;
248 m_xMtrFldAngle->set_value(nValue, FieldUnit::DEGREE);
249 SetMetricValue( *m_xMtrFldWidth, tools::Long(nValue / maUIScale), MapUnit::Map100thMM);
250 SetMetricValue( *m_xMtrFldHeight, tools::Long(nValue / maUIScale), MapUnit::Map100thMM);
251
252 // set color attribute
253 if( const XColorItem* pPoolItem = mrOutAttrs.GetItemIfSet( ATTR_COPY_START_COLOR ) )
254 {
255 Color aColor = pPoolItem->GetColorValue();
256 m_xLbStartColor->SelectEntry( aColor );
257 m_xLbEndColor->SelectEntry( aColor );
258 }
259}
260
261} // end of namespace sd
262
263/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
const tools::Rectangle & GetAllMarkedRect() const
SdrPage * GetPage() const
Size GetSize() const
SdrPageView * GetSdrPageView() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
static FieldUnit GetCurrentFieldUnit()
constexpr tools::Long Height() const
constexpr tools::Long Width() const
css::uno::Any GetUserItem(const OUString &sName) const
void SetUserItem(const OUString &sName, const css::uno::Any &aValue)
bool Exists() const
dialog to adjust screen
Definition: copydlg.hxx:35
void Reset()
reads provided item set or evaluate ini string
Definition: copydlg.cxx:90
void GetAttr(SfxItemSet &rOutAttrs)
fills provided item set with dialog box attributes
Definition: copydlg.cxx:181
std::unique_ptr< weld::SpinButton > m_xNumFldCopies
Definition: copydlg.hxx:48
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldWidth
Definition: copydlg.hxx:53
std::unique_ptr< ColorListBox > m_xLbStartColor
Definition: copydlg.hxx:57
::sd::View * mpView
Definition: copydlg.hxx:46
std::unique_ptr< ColorListBox > m_xLbEndColor
Definition: copydlg.hxx:58
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldMoveY
Definition: copydlg.hxx:51
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldHeight
Definition: copydlg.hxx:54
Fraction maUIScale
Definition: copydlg.hxx:45
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldAngle
Definition: copydlg.hxx:52
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldMoveX
Definition: copydlg.hxx:50
virtual ~CopyDlg() override
Definition: copydlg.cxx:72
const SfxItemSet & mrOutAttrs
Definition: copydlg.hxx:44
CopyDlg(weld::Window *pWindow, const SfxItemSet &rInAttrs, ::sd::View *pView)
Definition: copydlg.cxx:41
std::unique_ptr< weld::Label > m_xFtEndColor
Definition: copydlg.hxx:55
constexpr tools::Long GetWidth() const
constexpr tools::Long GetHeight() const
ColorTransparency
FieldUnit
sal_Int16 nValue
aStr
sal_Int64 toInt64(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
sal_uInt32 toUInt32(std::u16string_view str, sal_Int16 radix=10)
IMPL_LINK_NOARG(MainSequence, onTimerHdl, Timer *, void)
constexpr char TOKEN
Definition: copydlg.cxx:39
long Long
UnoViewSharedPtr mpView
OUString m_aName
Color m_aColor
SVT_DLLPUBLIC sal_Int64 GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
SVT_DLLPUBLIC void SetMetricValue(weld::MetricSpinButton &rField, sal_Int64 nCoreValue, MapUnit eUnit)
SVT_DLLPUBLIC void SetFieldUnit(weld::MetricSpinButton &rCtrl, FieldUnit eUnit, bool bAll=false)