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 <svl/intitem.hxx>
21 #include <svtools/unitconv.hxx>
23 #include <svx/svxids.hrc>
24 #include <svx/optgrid.hxx>
25 #include <svx/dlgutil.hxx>
28 static void lcl_GetMinMax(weld::MetricSpinButton
const& rField
, sal_Int64
& nMin
, sal_Int64
& nMax
)
30 rField
.get_range(nMin
, nMax
, FieldUnit::TWIP
);
31 nMin
= rField
.denormalize(nMin
);
32 nMax
= rField
.denormalize(nMax
);
35 static void lcl_SetMinMax(weld::MetricSpinButton
& rField
, sal_Int64 nMin
, sal_Int64 nMax
)
37 rField
.set_range(rField
.normalize(nMin
), rField
.normalize(nMax
), FieldUnit::TWIP
);
40 SvxOptionsGrid::SvxOptionsGrid() :
47 bUseGridsnap ( false ),
48 bSynchronize ( true ),
49 bGridVisible ( false ),
54 SvxGridItem
* SvxGridItem::Clone( SfxItemPool
* ) const
56 return new SvxGridItem( *this );
59 bool SvxGridItem::operator==( const SfxPoolItem
& rAttr
) const
61 assert(SfxPoolItem::operator==(rAttr
));
63 const SvxGridItem
& rItem
= static_cast<const SvxGridItem
&>(rAttr
);
65 return ( bUseGridsnap
== rItem
.bUseGridsnap
&&
66 bSynchronize
== rItem
.bSynchronize
&&
67 bGridVisible
== rItem
.bGridVisible
&&
68 bEqualGrid
== rItem
.bEqualGrid
&&
69 nFldDrawX
== rItem
.nFldDrawX
&&
70 nFldDivisionX
== rItem
.nFldDivisionX
&&
71 nFldDrawY
== rItem
.nFldDrawY
&&
72 nFldDivisionY
== rItem
.nFldDivisionY
&&
73 nFldSnapX
== rItem
.nFldSnapX
&&
74 nFldSnapY
== rItem
.nFldSnapY
);
77 bool SvxGridItem::GetPresentation
79 SfxItemPresentation
/*ePres*/,
80 MapUnit
/*eCoreUnit*/,
81 MapUnit
/*ePresUnit*/,
82 OUString
& rText
, const IntlWrapper
&
85 rText
= "SvxGridItem";
89 // TabPage Screen Settings
90 SvxGridTabPage::SvxGridTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rCoreSet
)
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
))
112 // This page requires exchange Support
113 SetExchangeSupport();
116 FieldUnit eFUnit
= GetModuleFieldUnit( rCoreSet
);
117 sal_Int64 nMin
, nMax
;
119 lcl_GetMinMax(*m_xMtrFldDrawX
, nMin
, nMax
);
120 SetFieldUnit( *m_xMtrFldDrawX
, eFUnit
, true );
121 lcl_SetMinMax(*m_xMtrFldDrawX
, nMin
, nMax
);
123 lcl_GetMinMax(*m_xMtrFldDrawY
, nMin
, nMax
);
124 SetFieldUnit( *m_xMtrFldDrawY
, eFUnit
, true );
125 lcl_SetMinMax(*m_xMtrFldDrawY
, nMin
, nMax
);
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
) );
143 SvxGridTabPage::~SvxGridTabPage()
147 std::unique_ptr
<SfxTabPage
> SvxGridTabPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rAttrSet
)
149 return std::make_unique
<SvxGridTabPage
>(pPage
, pController
, rAttrSet
);
152 bool SvxGridTabPage::FillItemSet( SfxItemSet
* rCoreSet
)
156 SvxGridItem
aGridItem( SID_ATTR_GRID_OPTIONS
);
158 aGridItem
.bUseGridsnap
= m_xCbxUseGridsnap
->get_active();
159 aGridItem
.bSynchronize
= m_xCbxSynchronize
->get_active();
160 aGridItem
.bGridVisible
= m_xCbxGridVisible
->get_active();
162 MapUnit eUnit
= rCoreSet
->GetPool()->GetMetric( SID_ATTR_GRID_OPTIONS
);
163 tools::Long nX
= GetCoreValue( *m_xMtrFldDrawX
, eUnit
);
164 tools::Long nY
= GetCoreValue( *m_xMtrFldDrawY
, eUnit
);
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);
171 rCoreSet
->Put( aGridItem
);
173 return bAttrModified
;
176 void SvxGridTabPage::Reset( const SfxItemSet
* rSet
)
178 const SvxGridItem
* pGridAttr
= nullptr;
180 if( (pGridAttr
= rSet
->GetItemIfSet( SID_ATTR_GRID_OPTIONS
, false )) )
182 m_xCbxUseGridsnap
->set_active(pGridAttr
->bUseGridsnap
);
183 m_xCbxSynchronize
->set_active(pGridAttr
->bSynchronize
);
184 m_xCbxGridVisible
->set_active(pGridAttr
->bGridVisible
);
186 MapUnit eUnit
= rSet
->GetPool()->GetMetric( SID_ATTR_GRID_OPTIONS
);
187 SetMetricValue( *m_xMtrFldDrawX
, pGridAttr
->nFldDrawX
, eUnit
);
188 SetMetricValue( *m_xMtrFldDrawY
, pGridAttr
->nFldDrawY
, eUnit
);
190 m_xNumFldDivisionX
->set_value(pGridAttr
->nFldDivisionX
+ 1);
191 m_xNumFldDivisionY
->set_value(pGridAttr
->nFldDivisionY
+ 1);
194 ChangeGridsnapHdl_Impl(*m_xCbxUseGridsnap
);
195 bAttrModified
= false;
198 void SvxGridTabPage::ActivatePage( const SfxItemSet
& rSet
)
200 const SvxGridItem
* pGridAttr
= nullptr;
201 if( (pGridAttr
= rSet
.GetItemIfSet( SID_ATTR_GRID_OPTIONS
, false )) )
203 m_xCbxUseGridsnap
->set_active(pGridAttr
->bUseGridsnap
);
205 ChangeGridsnapHdl_Impl(*m_xCbxUseGridsnap
);
208 // Metric Change if necessary (as TabPage is in the dialog, where the
210 const SfxUInt16Item
* pItem
= rSet
.GetItemIfSet( SID_ATTR_METRIC
, false );
215 FieldUnit eFUnit
= static_cast<FieldUnit
>(static_cast<tools::Long
>(pItem
->GetValue()));
217 if (eFUnit
== m_xMtrFldDrawX
->get_unit())
221 sal_Int64 nMin
, nMax
;
222 int nVal
= m_xMtrFldDrawX
->denormalize(m_xMtrFldDrawX
->get_value(FieldUnit::TWIP
));
224 lcl_GetMinMax(*m_xMtrFldDrawX
, nMin
, nMax
);
225 SetFieldUnit(*m_xMtrFldDrawX
, eFUnit
, true);
226 lcl_SetMinMax(*m_xMtrFldDrawX
, nMin
, nMax
);
228 m_xMtrFldDrawX
->set_value(m_xMtrFldDrawX
->normalize(nVal
), FieldUnit::TWIP
);
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
);
237 DeactivateRC
SvxGridTabPage::DeactivatePage( SfxItemSet
* _pSet
)
240 FillItemSet( _pSet
);
241 return DeactivateRC::LeavePage
;
244 IMPL_LINK(SvxGridTabPage
, ChangeDrawHdl_Impl
, weld::MetricSpinButton
&, rField
, void)
246 bAttrModified
= true;
247 if (m_xCbxSynchronize
->get_active())
249 if (&rField
== m_xMtrFldDrawX
.get())
250 m_xMtrFldDrawY
->set_value(m_xMtrFldDrawX
->get_value(FieldUnit::NONE
), FieldUnit::NONE
);
252 m_xMtrFldDrawX
->set_value(m_xMtrFldDrawY
->get_value(FieldUnit::NONE
), FieldUnit::NONE
);
256 IMPL_LINK_NOARG(SvxGridTabPage
, ClickRotateHdl_Impl
, weld::Toggleable
&, void)
258 if (m_xCbxRotate
->get_active())
259 m_xMtrFldAngle
->set_sensitive(true);
261 m_xMtrFldAngle
->set_sensitive(false);
264 IMPL_LINK(SvxGridTabPage
, ChangeDivisionHdl_Impl
, weld::SpinButton
&, rField
, void)
266 bAttrModified
= true;
267 if (m_xCbxSynchronize
->get_active())
269 if (m_xNumFldDivisionX
.get() == &rField
)
270 m_xNumFldDivisionY
->set_value(m_xNumFldDivisionX
->get_value());
272 m_xNumFldDivisionX
->set_value(m_xNumFldDivisionY
->get_value());
276 IMPL_LINK_NOARG(SvxGridTabPage
, ChangeGridsnapHdl_Impl
, weld::Toggleable
&, void)
278 bAttrModified
= true;
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */