LibreOffice Module svx (master) 1
optgrid.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 <svl/intitem.hxx>
21#include <svtools/unitconv.hxx>
22
23#include <svx/svxids.hrc>
24#include <svx/optgrid.hxx>
25#include <svx/dlgutil.hxx>
26
27// local functions
28static void lcl_GetMinMax(weld::MetricSpinButton const& rField, sal_Int64& nMin, sal_Int64& nMax)
29{
30 rField.get_range(nMin, nMax, FieldUnit::TWIP);
31 nMin = rField.denormalize(nMin);
32 nMax = rField.denormalize(nMax);
33}
34
35static void lcl_SetMinMax(weld::MetricSpinButton& rField, sal_Int64 nMin, sal_Int64 nMax)
36{
37 rField.set_range(rField.normalize(nMin), rField.normalize(nMax), FieldUnit::TWIP);
38}
39
41 nFldDrawX ( 100 ),
42 nFldDivisionX ( 0 ),
43 nFldDrawY ( 100 ),
44 nFldDivisionY ( 0 ),
45 nFldSnapX ( 100 ),
46 nFldSnapY ( 100 ),
47 bUseGridsnap ( false ),
48 bSynchronize ( true ),
49 bGridVisible ( false ),
50 bEqualGrid ( true )
51{
52}
53
55{
56 return new SvxGridItem( *this );
57}
58
59bool SvxGridItem::operator==( const SfxPoolItem& rAttr ) const
60{
61 assert(SfxPoolItem::operator==(rAttr));
62
63 const SvxGridItem& rItem = static_cast<const SvxGridItem&>(rAttr);
64
65 return ( bUseGridsnap == rItem.bUseGridsnap &&
66 bSynchronize == rItem.bSynchronize &&
67 bGridVisible == rItem.bGridVisible &&
68 bEqualGrid == rItem.bEqualGrid &&
69 nFldDrawX == rItem.nFldDrawX &&
71 nFldDrawY == rItem.nFldDrawY &&
73 nFldSnapX == rItem.nFldSnapX &&
74 nFldSnapY == rItem.nFldSnapY );
75}
76
78(
79 SfxItemPresentation /*ePres*/,
80 MapUnit /*eCoreUnit*/,
81 MapUnit /*ePresUnit*/,
82 OUString& rText, const IntlWrapper&
83) const
84{
85 rText = "SvxGridItem";
86 return true;
87}
88
89// TabPage Screen Settings
91 : SfxTabPage(pPage, pController, "svx/ui/optgridpage.ui", "OptGridPage", &rCoreSet)
92 , bAttrModified(false)
93 , m_xCbxUseGridsnap(m_xBuilder->weld_check_button("usegridsnap"))
94 , m_xCbxGridVisible(m_xBuilder->weld_check_button("gridvisible"))
95 , m_xMtrFldDrawX(m_xBuilder->weld_metric_spin_button("mtrflddrawx", FieldUnit::CM))
96 , m_xMtrFldDrawY(m_xBuilder->weld_metric_spin_button("mtrflddrawy", FieldUnit::CM))
97 , m_xNumFldDivisionX(m_xBuilder->weld_spin_button("numflddivisionx"))
98 , m_xNumFldDivisionY(m_xBuilder->weld_spin_button("numflddivisiony"))
99 , m_xCbxSynchronize(m_xBuilder->weld_check_button("synchronize"))
100 , m_xSnapFrames(m_xBuilder->weld_widget("snapframes"))
101 , m_xCbxSnapHelplines(m_xBuilder->weld_check_button("snaphelplines"))
102 , m_xCbxSnapBorder(m_xBuilder->weld_check_button("snapborder"))
103 , m_xCbxSnapFrame(m_xBuilder->weld_check_button("snapframe"))
104 , m_xCbxSnapPoints(m_xBuilder->weld_check_button("snappoints"))
105 , m_xMtrFldSnapArea(m_xBuilder->weld_metric_spin_button("mtrfldsnaparea", FieldUnit::PIXEL))
106 , m_xCbxOrtho(m_xBuilder->weld_check_button("ortho"))
107 , m_xCbxBigOrtho(m_xBuilder->weld_check_button("bigortho"))
108 , m_xCbxRotate(m_xBuilder->weld_check_button("rotate"))
109 , m_xMtrFldAngle(m_xBuilder->weld_metric_spin_button("mtrfldangle", FieldUnit::DEGREE))
110 , m_xMtrFldBezAngle(m_xBuilder->weld_metric_spin_button("mtrfldbezangle", FieldUnit::DEGREE))
111{
112 // This page requires exchange Support
114
115 // Set Metrics
116 FieldUnit eFUnit = GetModuleFieldUnit( rCoreSet );
117 sal_Int64 nMin, nMax;
118
119 lcl_GetMinMax(*m_xMtrFldDrawX, nMin, nMax);
120 SetFieldUnit( *m_xMtrFldDrawX, eFUnit, true );
121 lcl_SetMinMax(*m_xMtrFldDrawX, nMin, nMax);
122
123 lcl_GetMinMax(*m_xMtrFldDrawY, nMin, nMax);
124 SetFieldUnit( *m_xMtrFldDrawY, eFUnit, true );
125 lcl_SetMinMax(*m_xMtrFldDrawY, nMin, nMax);
126
127
128 m_xCbxRotate->connect_toggled(LINK(this, SvxGridTabPage, ClickRotateHdl_Impl));
129 Link<weld::Toggleable&,void> aLink = LINK(this, SvxGridTabPage, ChangeGridsnapHdl_Impl);
130 m_xCbxUseGridsnap->connect_toggled(aLink);
131 m_xCbxSynchronize->connect_toggled(aLink);
132 m_xCbxGridVisible->connect_toggled(aLink);
133 m_xMtrFldDrawX->connect_value_changed(
134 LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
135 m_xMtrFldDrawY->connect_value_changed(
136 LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
137 m_xNumFldDivisionX->connect_value_changed(
138 LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
139 m_xNumFldDivisionY->connect_value_changed(
140 LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
141}
142
144{
145}
146
147std::unique_ptr<SfxTabPage> SvxGridTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttrSet)
148{
149 return std::make_unique<SvxGridTabPage>(pPage, pController, rAttrSet);
150}
151
153{
154 if ( bAttrModified )
155 {
156 SvxGridItem aGridItem( SID_ATTR_GRID_OPTIONS );
157
158 aGridItem.bUseGridsnap = m_xCbxUseGridsnap->get_active();
159 aGridItem.bSynchronize = m_xCbxSynchronize->get_active();
160 aGridItem.bGridVisible = m_xCbxGridVisible->get_active();
161
162 MapUnit eUnit = rCoreSet->GetPool()->GetMetric( SID_ATTR_GRID_OPTIONS );
165
166 aGridItem.nFldDrawX = static_cast<sal_uInt32>(nX);
167 aGridItem.nFldDrawY = static_cast<sal_uInt32>(nY);
168 aGridItem.nFldDivisionX = static_cast<tools::Long>(m_xNumFldDivisionX->get_value() - 1);
169 aGridItem.nFldDivisionY = static_cast<tools::Long>(m_xNumFldDivisionY->get_value() - 1);
170
171 rCoreSet->Put( aGridItem );
172 }
173 return bAttrModified;
174}
175
177{
178 const SvxGridItem* pGridAttr = nullptr;
179
180 if( (pGridAttr = rSet->GetItemIfSet( SID_ATTR_GRID_OPTIONS , false )) )
181 {
182 m_xCbxUseGridsnap->set_active(pGridAttr->bUseGridsnap);
183 m_xCbxSynchronize->set_active(pGridAttr->bSynchronize);
184 m_xCbxGridVisible->set_active(pGridAttr->bGridVisible);
185
186 MapUnit eUnit = rSet->GetPool()->GetMetric( SID_ATTR_GRID_OPTIONS );
187 SetMetricValue( *m_xMtrFldDrawX , pGridAttr->nFldDrawX, eUnit );
188 SetMetricValue( *m_xMtrFldDrawY , pGridAttr->nFldDrawY, eUnit );
189
190 m_xNumFldDivisionX->set_value(pGridAttr->nFldDivisionX + 1);
191 m_xNumFldDivisionY->set_value(pGridAttr->nFldDivisionY + 1);
192 }
193
194 ChangeGridsnapHdl_Impl(*m_xCbxUseGridsnap);
195 bAttrModified = false;
196}
197
199{
200 const SvxGridItem* pGridAttr = nullptr;
201 if( (pGridAttr = rSet.GetItemIfSet( SID_ATTR_GRID_OPTIONS , false )) )
202 {
203 m_xCbxUseGridsnap->set_active(pGridAttr->bUseGridsnap);
204
205 ChangeGridsnapHdl_Impl(*m_xCbxUseGridsnap);
206 }
207
208 // Metric Change if necessary (as TabPage is in the dialog, where the
209 // metric can be set
210 const SfxUInt16Item* pItem = rSet.GetItemIfSet( SID_ATTR_METRIC , false );
211 if( !pItem )
212 return;
213
214
215 FieldUnit eFUnit = static_cast<FieldUnit>(static_cast<tools::Long>(pItem->GetValue()));
216
217 if (eFUnit == m_xMtrFldDrawX->get_unit())
218 return;
219
220 // Set Metrics
221 sal_Int64 nMin, nMax;
222 int nVal = m_xMtrFldDrawX->denormalize(m_xMtrFldDrawX->get_value(FieldUnit::TWIP));
223
224 lcl_GetMinMax(*m_xMtrFldDrawX, nMin, nMax);
225 SetFieldUnit(*m_xMtrFldDrawX, eFUnit, true);
226 lcl_SetMinMax(*m_xMtrFldDrawX, nMin, nMax);
227
228 m_xMtrFldDrawX->set_value(m_xMtrFldDrawX->normalize(nVal), FieldUnit::TWIP);
229
230 nVal = m_xMtrFldDrawY->denormalize(m_xMtrFldDrawY->get_value(FieldUnit::TWIP));
231 lcl_GetMinMax(*m_xMtrFldDrawY, nMin, nMax);
232 SetFieldUnit(*m_xMtrFldDrawY, eFUnit, true);
233 lcl_SetMinMax(*m_xMtrFldDrawY, nMin, nMax);
234 m_xMtrFldDrawY->set_value(m_xMtrFldDrawY->normalize(nVal), FieldUnit::TWIP);
235}
236
238{
239 if ( _pSet )
240 FillItemSet( _pSet );
241 return DeactivateRC::LeavePage;
242}
243
244IMPL_LINK(SvxGridTabPage, ChangeDrawHdl_Impl, weld::MetricSpinButton&, rField, void)
245{
246 bAttrModified = true;
247 if (m_xCbxSynchronize->get_active())
248 {
249 if (&rField == m_xMtrFldDrawX.get())
250 m_xMtrFldDrawY->set_value(m_xMtrFldDrawX->get_value(FieldUnit::NONE), FieldUnit::NONE);
251 else
252 m_xMtrFldDrawX->set_value(m_xMtrFldDrawY->get_value(FieldUnit::NONE), FieldUnit::NONE);
253 }
254}
255
257{
258 if (m_xCbxRotate->get_active())
259 m_xMtrFldAngle->set_sensitive(true);
260 else
261 m_xMtrFldAngle->set_sensitive(false);
262}
263
264IMPL_LINK(SvxGridTabPage, ChangeDivisionHdl_Impl, weld::SpinButton&, rField, void)
265{
266 bAttrModified = true;
267 if (m_xCbxSynchronize->get_active())
268 {
269 if (m_xNumFldDivisionX.get() == &rField)
270 m_xNumFldDivisionY->set_value(m_xNumFldDivisionX->get_value());
271 else
272 m_xNumFldDivisionX->set_value(m_xNumFldDivisionY->get_value());
273 }
274}
275
276IMPL_LINK_NOARG(SvxGridTabPage, ChangeGridsnapHdl_Impl, weld::Toggleable&, void)
277{
278 bAttrModified = true;
279}
280
281/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetValue() const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void SetExchangeSupport()
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText, const IntlWrapper &) const override
Definition: optgrid.cxx:78
virtual SvxGridItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: optgrid.cxx:54
SvxGridItem(TypedWhichId< SvxGridItem > _nWhich)
Definition: optgrid.hxx:77
virtual bool operator==(const SfxPoolItem &) const override
Definition: optgrid.cxx:59
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: optgrid.cxx:198
std::unique_ptr< weld::CheckButton > m_xCbxSynchronize
Definition: optgrid.hxx:112
std::unique_ptr< weld::SpinButton > m_xNumFldDivisionX
Definition: optgrid.hxx:110
std::unique_ptr< weld::CheckButton > m_xCbxUseGridsnap
Definition: optgrid.hxx:106
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rAttrSet)
Definition: optgrid.cxx:147
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldDrawY
Definition: optgrid.hxx:109
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldDrawX
Definition: optgrid.hxx:108
std::unique_ptr< weld::CheckButton > m_xCbxRotate
Definition: optgrid.hxx:123
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: optgrid.cxx:237
bool bAttrModified
Definition: optgrid.hxx:104
std::unique_ptr< weld::SpinButton > m_xNumFldDivisionY
Definition: optgrid.hxx:111
virtual ~SvxGridTabPage() override
Definition: optgrid.cxx:143
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optgrid.cxx:152
virtual void Reset(const SfxItemSet *rSet) override
Definition: optgrid.cxx:176
SvxGridTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: optgrid.cxx:90
std::unique_ptr< weld::CheckButton > m_xCbxGridVisible
Definition: optgrid.hxx:107
sal_uInt32 nFldSnapY
Definition: optgrid.hxx:39
bool bUseGridsnap
Definition: optgrid.hxx:40
sal_uInt32 nFldDrawX
Definition: optgrid.hxx:34
sal_uInt32 nFldSnapX
Definition: optgrid.hxx:38
sal_uInt32 nFldDrawY
Definition: optgrid.hxx:36
bool bEqualGrid
Definition: optgrid.hxx:43
bool bGridVisible
Definition: optgrid.hxx:42
bool bSynchronize
Definition: optgrid.hxx:41
sal_uInt32 nFldDivisionY
Definition: optgrid.hxx:37
sal_uInt32 nFldDivisionX
Definition: optgrid.hxx:35
sal_Int64 normalize(sal_Int64 nValue) const
void set_range(sal_Int64 min, sal_Int64 max, FieldUnit eValueUnit)
sal_Int64 denormalize(sal_Int64 nValue) const
void get_range(sal_Int64 &min, sal_Int64 &max, FieldUnit eDestUnit) const
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
Definition: dlgutil.cxx:31
FieldUnit
MapUnit
long Long
IMPL_LINK_NOARG(SvxGridTabPage, ClickRotateHdl_Impl, weld::Toggleable &, void)
Definition: optgrid.cxx:256
IMPL_LINK(SvxGridTabPage, ChangeDrawHdl_Impl, weld::MetricSpinButton &, rField, void)
Definition: optgrid.cxx:244
static void lcl_GetMinMax(weld::MetricSpinButton const &rField, sal_Int64 &nMin, sal_Int64 &nMax)
Definition: optgrid.cxx:28
static void lcl_SetMinMax(weld::MetricSpinButton &rField, sal_Int64 nMin, sal_Int64 nMax)
Definition: optgrid.cxx:35
SfxItemPresentation
static SfxItemSet & rSet
DeactivateRC
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)