LibreOffice Module sd (master) 1
dlgsnap.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 <svx/svxids.hrc>
21#include <svx/svdpagv.hxx>
22#include <svl/intitem.hxx>
23#include <svl/itempool.hxx>
24#include <svtools/unitconv.hxx>
25#include <tools/debug.hxx>
26
27#include <sdattr.hrc>
28#include <View.hxx>
29#include <drawdoc.hxx>
30#include <dlgsnap.hxx>
31#include <sdenumdef.hxx>
32
36SdSnapLineDlg::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"))
48{
49 m_xRbHorz->connect_toggled(LINK(this, SdSnapLineDlg, ToggleHdl));
50 m_xRbVert->connect_toggled(LINK(this, SdSnapLineDlg, ToggleHdl));
51 m_xRbPoint->connect_toggled(LINK(this, SdSnapLineDlg, ToggleHdl));
52
53 m_xBtnDelete->connect_clicked(LINK(this, SdSnapLineDlg, ClickHdl));
54
55 FieldUnit eUIUnit = pView->GetDoc().GetUIUnit();
56 SetFieldUnit(*m_xMtrFldX, eUIUnit, true);
57 SetFieldUnit(*m_xMtrFldY, eUIUnit, true);
58
59 // get WorkArea
60 ::tools::Rectangle aWorkArea = pView->GetWorkArea();
61
62 // determine PoolUnit
63 SfxItemPool* pPool = rInAttrs.GetPool();
64 DBG_ASSERT( pPool, "Where's the Pool?" );
65 MapUnit ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
66
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);
73
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, tools::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);
81 return n4;
82 };
83 m_xMtrFldX->set_range(map(m_xMtrFldX, sal_Int32(aLeftTop.X() / aUIScale)),
84 map(m_xMtrFldX, sal_Int32(aRightBottom.X() / aUIScale)),
85 FieldUnit::NONE);
86 m_xMtrFldY->set_range(map(m_xMtrFldY, sal_Int32(aLeftTop.Y() / aUIScale)),
87 map(m_xMtrFldY, sal_Int32(aRightBottom.Y() / aUIScale)),
88 FieldUnit::NONE);
89
90 // set values
91 nXValue = rInAttrs.Get(ATTR_SNAPLINE_X).GetValue();
92 nYValue = rInAttrs.Get(ATTR_SNAPLINE_Y).GetValue();
93 nXValue = sal_Int32(nXValue / aUIScale);
94 nYValue = sal_Int32(nYValue / aUIScale);
95 SetMetricValue(*m_xMtrFldX, nXValue, MapUnit::Map100thMM);
96 SetMetricValue(*m_xMtrFldY, nYValue, MapUnit::Map100thMM);
97
98 m_xRbPoint->set_active(true);
99}
100
102{
103}
104
108IMPL_LINK(SdSnapLineDlg, ToggleHdl, weld::Toggleable&, rBtn, void)
109{
110 if (!rBtn.get_active())
111 return;
112 if (m_xRbPoint->get_active())
113 SetInputFields(true, true);
114 else if (m_xRbHorz->get_active())
115 SetInputFields(false, true);
116 else if (m_xRbVert->get_active())
117 SetInputFields(true, false);
118}
119
120IMPL_LINK( SdSnapLineDlg, ClickHdl, weld::Button&, rBtn, void )
121{
122 if (&rBtn == m_xBtnDelete.get())
123 m_xDialog->response(RET_SNAP_DELETE);
124}
125
130{
131 SnapKind eKind;
132
133 if (m_xRbHorz->get_active()) eKind = SnapKind::Horizontal;
134 else if (m_xRbVert->get_active()) eKind = SnapKind::Vertical;
135 else eKind = SnapKind::Point;
136
137 nXValue = sal_Int32(GetCoreValue(*m_xMtrFldX, MapUnit::Map100thMM) * aUIScale);
138 nYValue = sal_Int32(GetCoreValue(*m_xMtrFldY, MapUnit::Map100thMM) * aUIScale);
139
140 rOutAttrs.Put(SfxUInt16Item(ATTR_SNAPLINE_KIND, static_cast<sal_uInt16>(eKind)));
141 rOutAttrs.Put(SfxInt32Item(ATTR_SNAPLINE_X, nXValue));
142 rOutAttrs.Put(SfxInt32Item(ATTR_SNAPLINE_Y, nYValue));
143}
144
146{
147 m_xRadioGroup->hide();
148}
149
153void SdSnapLineDlg::SetInputFields(bool bEnableX, bool bEnableY)
154{
155 if ( bEnableX )
156 {
157 if (!m_xMtrFldX->get_sensitive())
158 m_xMtrFldX->set_value(nXValue, FieldUnit::NONE);
159 m_xMtrFldX->set_sensitive(true);
160 m_xFtX->set_sensitive(true);
161 }
162 else if (m_xMtrFldX->get_sensitive())
163 {
164 nXValue = m_xMtrFldX->get_value(FieldUnit::NONE);
165 m_xMtrFldX->set_text(OUString());
166 m_xMtrFldX->set_sensitive(false);
167 m_xFtX->set_sensitive(false);
168 }
169 if ( bEnableY )
170 {
171 if (!m_xMtrFldY->get_sensitive())
172 m_xMtrFldY->set_value(nYValue, FieldUnit::NONE);
173 m_xMtrFldY->set_sensitive(true);
174 m_xFtY->set_sensitive(true);
175 }
176 else if (m_xMtrFldY->get_sensitive())
177 {
178 nYValue = m_xMtrFldY->get_value(FieldUnit::NONE);
179 m_xMtrFldY->set_text(OUString());
180 m_xMtrFldY->set_sensitive(false);
181 m_xFtY->set_sensitive(false);
182 }
183}
184
185/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
constexpr tools::Long Y() const
constexpr tools::Long X() const
dialog to adjust snap- lines and points
Definition: dlgsnap.hxx:36
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldY
Definition: dlgsnap.hxx:45
std::unique_ptr< weld::RadioButton > m_xRbVert
Definition: dlgsnap.hxx:48
std::unique_ptr< weld::Button > m_xBtnDelete
Definition: dlgsnap.hxx:50
virtual ~SdSnapLineDlg() override
Definition: dlgsnap.cxx:101
std::unique_ptr< weld::Label > m_xFtX
Definition: dlgsnap.hxx:42
std::unique_ptr< weld::RadioButton > m_xRbHorz
Definition: dlgsnap.hxx:49
SdSnapLineDlg(weld::Window *pWindow, const SfxItemSet &rInAttrs, ::sd::View const *pView)
dialog to adjust grid (scarcely ESO!)
Definition: dlgsnap.cxx:36
void SetInputFields(bool bEnableX, bool bEnableY)
disable X or Y input fields
Definition: dlgsnap.cxx:153
void HideRadioGroup()
Definition: dlgsnap.cxx:145
std::unique_ptr< weld::Label > m_xFtY
Definition: dlgsnap.hxx:44
std::unique_ptr< weld::RadioButton > m_xRbPoint
Definition: dlgsnap.hxx:47
void GetAttr(SfxItemSet &rOutAttrs)
fills provided item sets with dialog box attributes
Definition: dlgsnap.cxx:129
std::unique_ptr< weld::Widget > m_xRadioGroup
Definition: dlgsnap.hxx:46
Fraction aUIScale
Definition: dlgsnap.hxx:40
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldX
Definition: dlgsnap.hxx:43
const tools::Rectangle & GetWorkArea() const
FieldUnit GetUIUnit() const
void LogicToPagePos(Point &rPnt) const
SdrPageView * GetSdrPageView() const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
SdDrawDocument & GetDoc() const
Definition: View.hxx:293
constexpr tools::Long Top() const
constexpr tools::Long Right() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
Any value
#define DBG_ASSERT(sCon, aError)
IMPL_LINK(SdSnapLineDlg, ToggleHdl, weld::Toggleable &, rBtn, void)
fills provided item sets with dialog box attributes
Definition: dlgsnap.cxx:108
FieldUnit
MapUnit
int n2
int n1
sal_uInt32 n4
sal_uInt32 n3
long Long
#define RET_SNAP_DELETE
Definition: sdenumdef.hxx:22
SnapKind
Definition: sdenumdef.hxx:25
std::map< OUString, rtl::Reference< Entity > > map
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)