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 .
20 #include <svx/svxids.hrc>
21 #include <svl/intitem.hxx>
22 #include <svl/itempool.hxx>
23 #include <svl/aeitem.hxx>
24 #include <svtools/unitconv.hxx>
25 #include <tools/debug.hxx>
29 #include <drawdoc.hxx>
30 #include <dlgsnap.hxx>
31 #include <sdenumdef.hxx>
34 * dialog to adjust grid (scarcely ESO!)
36 SdSnapLineDlg::SdSnapLineDlg(weld::Window
* pWindow
, const SfxItemSet
& rInAttrs
, ::sd::View
const * pView
)
37 : GenericDialogController(pWindow
, "modules/sdraw/ui/dlgsnap.ui", "SnapObjectDialog")
38 , aUIScale(pView
->GetDoc().GetUIScale())
39 , m_xFtX(m_xBuilder
->weld_label("xlabel"))
40 , m_xMtrFldX(m_xBuilder
->weld_metric_spin_button("x", FieldUnit::CM
))
41 , m_xFtY(m_xBuilder
->weld_label("ylabel"))
42 , m_xMtrFldY(m_xBuilder
->weld_metric_spin_button("y", FieldUnit::CM
))
43 , m_xRadioGroup(m_xBuilder
->weld_widget("radiogroup"))
44 , m_xRbPoint(m_xBuilder
->weld_radio_button("point"))
45 , m_xRbVert(m_xBuilder
->weld_radio_button("vert"))
46 , m_xRbHorz(m_xBuilder
->weld_radio_button("horz"))
47 , m_xBtnDelete(m_xBuilder
->weld_button("delete"))
49 m_xRbHorz
->connect_clicked(LINK(this, SdSnapLineDlg
, ClickHdl
));
50 m_xRbVert
->connect_clicked(LINK(this, SdSnapLineDlg
, ClickHdl
));
51 m_xRbPoint
->connect_clicked(LINK(this, SdSnapLineDlg
, ClickHdl
));
53 m_xBtnDelete
->connect_clicked(LINK(this, SdSnapLineDlg
, ClickHdl
));
55 FieldUnit eUIUnit
= pView
->GetDoc().GetUIUnit();
56 SetFieldUnit(*m_xMtrFldX
, eUIUnit
, true);
57 SetFieldUnit(*m_xMtrFldY
, eUIUnit
, true);
60 ::tools::Rectangle aWorkArea
= pView
->GetWorkArea();
63 SfxItemPool
* pPool
= rInAttrs
.GetPool();
64 DBG_ASSERT( pPool
, "Where's the Pool?" );
65 MapUnit ePoolUnit
= pPool
->GetMetric( SID_ATTR_FILL_HATCH
);
67 // #i48497# Consider page origin
68 SdrPageView
* pPV
= pView
->GetSdrPageView();
69 Point
aLeftTop(aWorkArea
.Left()+1, aWorkArea
.Top()+1);
70 pPV
->LogicToPagePos(aLeftTop
);
71 Point
aRightBottom(aWorkArea
.Right()-2, aWorkArea
.Bottom()-2);
72 pPV
->LogicToPagePos(aRightBottom
);
74 // determine max and min values depending on
75 // WorkArea, PoolUnit and FieldUnit:
76 auto const map
= [ePoolUnit
](std::unique_ptr
<weld::MetricSpinButton
> const & msb
, long value
) {
77 auto const n1
= OutputDevice::LogicToLogic(value
, ePoolUnit
, MapUnit::Map100thMM
);
78 auto const n2
= msb
->normalize(n1
);
79 auto const n3
= msb
->convert_value_from(n2
, FieldUnit::MM_100TH
);
80 auto const n4
= msb
->convert_value_to(n3
, FieldUnit::NONE
);
83 m_xMtrFldX
->set_range(map(m_xMtrFldX
, aLeftTop
.X()), map(m_xMtrFldX
, aRightBottom
.X()),
85 m_xMtrFldY
->set_range(map(m_xMtrFldY
, aLeftTop
.Y()), map(m_xMtrFldY
, aRightBottom
.Y()),
89 nXValue
= static_cast<const SfxInt32Item
&>( rInAttrs
.Get(ATTR_SNAPLINE_X
)).GetValue();
90 nYValue
= static_cast<const SfxInt32Item
&>( rInAttrs
.Get(ATTR_SNAPLINE_Y
)).GetValue();
91 nXValue
= sal_Int32(nXValue
/ aUIScale
);
92 nYValue
= sal_Int32(nYValue
/ aUIScale
);
93 SetMetricValue(*m_xMtrFldX
, nXValue
, MapUnit::Map100thMM
);
94 SetMetricValue(*m_xMtrFldY
, nYValue
, MapUnit::Map100thMM
);
96 m_xRbPoint
->set_active(true);
99 SdSnapLineDlg::~SdSnapLineDlg()
104 * fills provided item sets with dialog box attributes
106 IMPL_LINK( SdSnapLineDlg
, ClickHdl
, weld::Button
&, rBtn
, void )
108 if (&rBtn
== m_xRbPoint
.get()) SetInputFields(true, true);
109 else if (&rBtn
== m_xRbHorz
.get()) SetInputFields(false, true);
110 else if (&rBtn
== m_xRbVert
.get()) SetInputFields(true, false);
111 else if (&rBtn
== m_xBtnDelete
.get()) m_xDialog
->response(RET_SNAP_DELETE
);
115 * fills provided item sets with dialog box attributes
117 void SdSnapLineDlg::GetAttr(SfxItemSet
& rOutAttrs
)
121 if (m_xRbHorz
->get_active()) eKind
= SK_HORIZONTAL
;
122 else if (m_xRbVert
->get_active()) eKind
= SK_VERTICAL
;
123 else eKind
= SK_POINT
;
125 nXValue
= sal_Int32(GetCoreValue(*m_xMtrFldX
, MapUnit::Map100thMM
) * aUIScale
);
126 nYValue
= sal_Int32(GetCoreValue(*m_xMtrFldY
, MapUnit::Map100thMM
) * aUIScale
);
128 rOutAttrs
.Put(SfxAllEnumItem(ATTR_SNAPLINE_KIND
, static_cast<sal_uInt16
>(eKind
)));
129 rOutAttrs
.Put(SfxInt32Item(ATTR_SNAPLINE_X
, nXValue
));
130 rOutAttrs
.Put(SfxInt32Item(ATTR_SNAPLINE_Y
, nYValue
));
133 void SdSnapLineDlg::HideRadioGroup()
135 m_xRadioGroup
->hide();
139 * disable X or Y input fields
141 void SdSnapLineDlg::SetInputFields(bool bEnableX
, bool bEnableY
)
145 if (!m_xMtrFldX
->get_sensitive())
146 m_xMtrFldX
->set_value(nXValue
, FieldUnit::NONE
);
147 m_xMtrFldX
->set_sensitive(true);
148 m_xFtX
->set_sensitive(true);
150 else if (m_xMtrFldX
->get_sensitive())
152 nXValue
= m_xMtrFldX
->get_value(FieldUnit::NONE
);
153 m_xMtrFldX
->set_text(OUString());
154 m_xMtrFldX
->set_sensitive(false);
155 m_xFtX
->set_sensitive(false);
159 if (!m_xMtrFldY
->get_sensitive())
160 m_xMtrFldY
->set_value(nYValue
, FieldUnit::NONE
);
161 m_xMtrFldY
->set_sensitive(true);
162 m_xFtY
->set_sensitive(true);
164 else if (m_xMtrFldY
->get_sensitive())
166 nYValue
= m_xMtrFldY
->get_value(FieldUnit::NONE
);
167 m_xMtrFldY
->set_text(OUString());
168 m_xMtrFldY
->set_sensitive(false);
169 m_xFtY
->set_sensitive(false);
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */