Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / dlg / dlgsnap.cxx
blob6e26778068655a1f4a6c430df7ec9c3ffbaf7353
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 <svx/svxids.hrc>
21 #include <svx/dlgutil.hxx>
22 #include <svl/itempool.hxx>
23 #include <svl/aeitem.hxx>
25 #include <sdattr.hxx>
26 #include <View.hxx>
27 #include <drawdoc.hxx>
28 #include <dlgsnap.hxx>
30 /**
31 * dialog to adjust grid (scarcely ESO!)
33 SdSnapLineDlg::SdSnapLineDlg(weld::Window* pWindow, const SfxItemSet& rInAttrs, ::sd::View const * pView)
34 : GenericDialogController(pWindow, "modules/sdraw/ui/dlgsnap.ui", "SnapObjectDialog")
35 , aUIScale(pView->GetDoc().GetUIScale())
36 , m_xFtX(m_xBuilder->weld_label("xlabel"))
37 , m_xMtrFldX(m_xBuilder->weld_metric_spin_button("x", FUNIT_CM))
38 , m_xFtY(m_xBuilder->weld_label("ylabel"))
39 , m_xMtrFldY(m_xBuilder->weld_metric_spin_button("y", FUNIT_CM))
40 , m_xRadioGroup(m_xBuilder->weld_widget("radiogroup"))
41 , m_xRbPoint(m_xBuilder->weld_radio_button("point"))
42 , m_xRbVert(m_xBuilder->weld_radio_button("vert"))
43 , m_xRbHorz(m_xBuilder->weld_radio_button("horz"))
44 , m_xBtnDelete(m_xBuilder->weld_button("delete"))
46 m_xRbHorz->connect_clicked(LINK(this, SdSnapLineDlg, ClickHdl));
47 m_xRbVert->connect_clicked(LINK(this, SdSnapLineDlg, ClickHdl));
48 m_xRbPoint->connect_clicked(LINK(this, SdSnapLineDlg, ClickHdl));
50 m_xBtnDelete->connect_clicked(LINK(this, SdSnapLineDlg, ClickHdl));
52 FieldUnit eUIUnit = pView->GetDoc().GetUIUnit();
53 SetFieldUnit(*m_xMtrFldX, eUIUnit, true);
54 SetFieldUnit(*m_xMtrFldY, eUIUnit, true);
56 // get WorkArea
57 ::tools::Rectangle aWorkArea = pView->GetWorkArea();
59 // determine PoolUnit
60 SfxItemPool* pPool = rInAttrs.GetPool();
61 DBG_ASSERT( pPool, "Where's the Pool?" );
62 MapUnit ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
64 // #i48497# Consider page origin
65 SdrPageView* pPV = pView->GetSdrPageView();
66 Point aLeftTop(aWorkArea.Left()+1, aWorkArea.Top()+1);
67 pPV->LogicToPagePos(aLeftTop);
68 Point aRightBottom(aWorkArea.Right()-2, aWorkArea.Bottom()-2);
69 pPV->LogicToPagePos(aRightBottom);
71 // determine max and min values depending on
72 // WorkArea, PoolUnit and FieldUnit:
73 SetMetricValue(*m_xMtrFldX, aLeftTop.X(), ePoolUnit );
75 int nValue = m_xMtrFldX->get_value(FUNIT_NONE);
76 nValue = sal_Int32(nValue / aUIScale);
77 m_xMtrFldX->set_min(nValue, FUNIT_NONE);
79 SetMetricValue(*m_xMtrFldX, aRightBottom.X(), ePoolUnit);
80 nValue = m_xMtrFldX->get_value(FUNIT_NONE);
81 nValue = sal_Int32(nValue / aUIScale);
82 m_xMtrFldX->set_max(nValue, FUNIT_NONE);
84 SetMetricValue(*m_xMtrFldY, aLeftTop.Y(), ePoolUnit);
85 nValue = m_xMtrFldY->get_value(FUNIT_NONE);
86 nValue = sal_Int32(nValue / aUIScale);
87 m_xMtrFldY->set_min(nValue, FUNIT_NONE);
89 SetMetricValue(*m_xMtrFldY, aRightBottom.Y(), ePoolUnit);
90 nValue = m_xMtrFldY->get_value(FUNIT_NONE);
91 nValue = sal_Int32(nValue / aUIScale);
92 m_xMtrFldY->set_max(nValue, FUNIT_NONE);
94 // set values
95 nXValue = static_cast<const SfxInt32Item&>( rInAttrs.Get(ATTR_SNAPLINE_X)).GetValue();
96 nYValue = static_cast<const SfxInt32Item&>( rInAttrs.Get(ATTR_SNAPLINE_Y)).GetValue();
97 nXValue = sal_Int32(nXValue / aUIScale);
98 nYValue = sal_Int32(nYValue / aUIScale);
99 SetMetricValue(*m_xMtrFldX, nXValue, MapUnit::Map100thMM);
100 SetMetricValue(*m_xMtrFldY, nYValue, MapUnit::Map100thMM);
102 m_xRbPoint->set_active(true);
105 SdSnapLineDlg::~SdSnapLineDlg()
110 * fills provided item sets with dialog box attributes
112 IMPL_LINK( SdSnapLineDlg, ClickHdl, weld::Button&, rBtn, void )
114 if (&rBtn == m_xRbPoint.get()) SetInputFields(true, true);
115 else if (&rBtn == m_xRbHorz.get()) SetInputFields(false, true);
116 else if (&rBtn == m_xRbVert.get()) SetInputFields(true, false);
117 else if (&rBtn == m_xBtnDelete.get()) m_xDialog->response(RET_SNAP_DELETE);
121 * fills provided item sets with dialog box attributes
123 void SdSnapLineDlg::GetAttr(SfxItemSet& rOutAttrs)
125 SnapKind eKind;
127 if (m_xRbHorz->get_active()) eKind = SK_HORIZONTAL;
128 else if (m_xRbVert->get_active()) eKind = SK_VERTICAL;
129 else eKind = SK_POINT;
131 nXValue = sal_Int32(GetCoreValue(*m_xMtrFldX, MapUnit::Map100thMM) * aUIScale);
132 nYValue = sal_Int32(GetCoreValue(*m_xMtrFldY, MapUnit::Map100thMM) * aUIScale);
134 rOutAttrs.Put(SfxAllEnumItem(ATTR_SNAPLINE_KIND, static_cast<sal_uInt16>(eKind)));
135 rOutAttrs.Put(SfxInt32Item(ATTR_SNAPLINE_X, nXValue));
136 rOutAttrs.Put(SfxInt32Item(ATTR_SNAPLINE_Y, nYValue));
139 void SdSnapLineDlg::HideRadioGroup()
141 m_xRadioGroup->hide();
145 * disable X or Y input fields
147 void SdSnapLineDlg::SetInputFields(bool bEnableX, bool bEnableY)
149 if ( bEnableX )
151 if (!m_xMtrFldX->get_sensitive())
152 m_xMtrFldX->set_value(nXValue, FUNIT_NONE);
153 m_xMtrFldX->set_sensitive(true);
154 m_xFtX->set_sensitive(true);
156 else if (m_xMtrFldX->get_sensitive())
158 nXValue = m_xMtrFldX->get_value(FUNIT_NONE);
159 m_xMtrFldX->set_text(OUString());
160 m_xMtrFldX->set_sensitive(false);
161 m_xFtX->set_sensitive(false);
163 if ( bEnableY )
165 if (!m_xMtrFldY->get_sensitive())
166 m_xMtrFldY->set_value(nYValue, FUNIT_NONE);
167 m_xMtrFldY->set_sensitive(true);
168 m_xFtY->set_sensitive(true);
170 else if (m_xMtrFldY->get_sensitive())
172 nYValue = m_xMtrFldY->get_value(FUNIT_NONE);
173 m_xMtrFldY->set_text(OUString());
174 m_xMtrFldY->set_sensitive(false);
175 m_xFtY->set_sensitive(false);
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */