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
28 static void lcl_GetMinMax(weld::MetricSpinButton const& rField, int& nMin, int& nMax)
29 {
30  rField.get_range(nMin, nMax, FieldUnit::TWIP);
31  nMin = rField.denormalize(nMin);
32  nMax = rField.denormalize(nMax);
33 }
34 
35 static void lcl_SetMinMax(weld::MetricSpinButton& rField, int nMin, int 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 
59 bool 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  int 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::ToggleButton&,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 
147 std::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 =
163  rCoreSet->GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
164  long nX = GetCoreValue( *m_xMtrFldDrawX, eUnit );
165  long nY = GetCoreValue( *m_xMtrFldDrawY, eUnit );
166 
167  aGridItem.nFldDrawX = static_cast<sal_uInt32>(nX);
168  aGridItem.nFldDrawY = static_cast<sal_uInt32>(nY);
169  aGridItem.nFldDivisionX = static_cast<long>(m_xNumFldDivisionX->get_value() - 1);
170  aGridItem.nFldDivisionY = static_cast<long>(m_xNumFldDivisionY->get_value() - 1);
171 
172  rCoreSet->Put( aGridItem );
173  }
174  return bAttrModified;
175 }
176 
178 {
179  const SfxPoolItem* pAttr = nullptr;
180 
181  if( SfxItemState::SET == rSet->GetItemState( SID_ATTR_GRID_OPTIONS , false,
182  &pAttr ))
183  {
184  const SvxGridItem* pGridAttr = static_cast<const SvxGridItem*>(pAttr);
185  m_xCbxUseGridsnap->set_active(pGridAttr->bUseGridsnap);
186  m_xCbxSynchronize->set_active(pGridAttr->bSynchronize);
187  m_xCbxGridVisible->set_active(pGridAttr->bGridVisible);
188 
189  MapUnit eUnit =
190  rSet->GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
191  SetMetricValue( *m_xMtrFldDrawX , pGridAttr->nFldDrawX, eUnit );
192  SetMetricValue( *m_xMtrFldDrawY , pGridAttr->nFldDrawY, eUnit );
193 
194  m_xNumFldDivisionX->set_value(pGridAttr->nFldDivisionX + 1);
195  m_xNumFldDivisionY->set_value(pGridAttr->nFldDivisionY + 1);
196  }
197 
198  ChangeGridsnapHdl_Impl(*m_xCbxUseGridsnap);
199  bAttrModified = false;
200 }
201 
203 {
204  const SfxPoolItem* pAttr = nullptr;
205  if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , false,
206  &pAttr ))
207  {
208  const SvxGridItem* pGridAttr = static_cast<const SvxGridItem*>(pAttr);
209  m_xCbxUseGridsnap->set_active(pGridAttr->bUseGridsnap);
210 
211  ChangeGridsnapHdl_Impl(*m_xCbxUseGridsnap);
212  }
213 
214  // Metric Change if necessary (as TabPage is in the dialog, where the
215  // metric can be set
216  if( SfxItemState::SET != rSet.GetItemState( SID_ATTR_METRIC , false,
217  &pAttr ))
218  return;
219 
220  const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pAttr);
221 
222  FieldUnit eFUnit = static_cast<FieldUnit>(static_cast<long>(pItem->GetValue()));
223 
224  if (eFUnit == m_xMtrFldDrawX->get_unit())
225  return;
226 
227  // Set Metrics
228  int nMin, nMax;
229  int nVal = m_xMtrFldDrawX->denormalize(m_xMtrFldDrawX->get_value(FieldUnit::TWIP));
230 
231  lcl_GetMinMax(*m_xMtrFldDrawX, nMin, nMax);
232  SetFieldUnit(*m_xMtrFldDrawX, eFUnit, true);
233  lcl_SetMinMax(*m_xMtrFldDrawX, nMin, nMax);
234 
235  m_xMtrFldDrawX->set_value(m_xMtrFldDrawX->normalize(nVal), FieldUnit::TWIP);
236 
237  nVal = m_xMtrFldDrawY->denormalize(m_xMtrFldDrawY->get_value(FieldUnit::TWIP));
238  lcl_GetMinMax(*m_xMtrFldDrawY, nMin, nMax);
239  SetFieldUnit(*m_xMtrFldDrawY, eFUnit, true);
240  lcl_SetMinMax(*m_xMtrFldDrawY, nMin, nMax);
241  m_xMtrFldDrawY->set_value(m_xMtrFldDrawY->normalize(nVal), FieldUnit::TWIP);
242 }
243 
245 {
246  if ( _pSet )
247  FillItemSet( _pSet );
248  return DeactivateRC::LeavePage;
249 }
250 
251 IMPL_LINK(SvxGridTabPage, ChangeDrawHdl_Impl, weld::MetricSpinButton&, rField, void)
252 {
253  bAttrModified = true;
254  if (m_xCbxSynchronize->get_active())
255  {
256  if (&rField == m_xMtrFldDrawX.get())
257  m_xMtrFldDrawY->set_value(m_xMtrFldDrawX->get_value(FieldUnit::NONE), FieldUnit::NONE);
258  else
259  m_xMtrFldDrawX->set_value(m_xMtrFldDrawY->get_value(FieldUnit::NONE), FieldUnit::NONE);
260  }
261 }
262 
263 IMPL_LINK_NOARG(SvxGridTabPage, ClickRotateHdl_Impl, weld::ToggleButton&, void)
264 {
265  if (m_xCbxRotate->get_active())
266  m_xMtrFldAngle->set_sensitive(true);
267  else
268  m_xMtrFldAngle->set_sensitive(false);
269 }
270 
271 IMPL_LINK(SvxGridTabPage, ChangeDivisionHdl_Impl, weld::SpinButton&, rField, void)
272 {
273  bAttrModified = true;
274  if (m_xCbxSynchronize->get_active())
275  {
276  if (m_xNumFldDivisionX.get() == &rField)
277  m_xNumFldDivisionY->set_value(m_xNumFldDivisionX->get_value());
278  else
279  m_xNumFldDivisionX->set_value(m_xNumFldDivisionY->get_value());
280  }
281 }
282 
283 IMPL_LINK_NOARG(SvxGridTabPage, ChangeGridsnapHdl_Impl, weld::ToggleButton&, void)
284 {
285  bAttrModified = true;
286 }
287 
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~SvxGridTabPage() override
Definition: optgrid.cxx:143
bool bUseGridsnap
Definition: optgrid.hxx:40
void SetFieldUnit(weld::MetricSpinButton &rField, FieldUnit eUnit, bool bAll)
SvxGridTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: optgrid.cxx:90
std::unique_ptr< weld::SpinButton > m_xNumFldDivisionY
Definition: optgrid.hxx:111
FieldUnit
std::unique_ptr< weld::CheckButton > m_xCbxRotate
Definition: optgrid.hxx:123
sal_uInt32 nFldDivisionY
Definition: optgrid.hxx:37
sal_uInt32 nFldDivisionX
Definition: optgrid.hxx:35
sal_uInt16 GetValue() const
virtual bool operator==(const SfxPoolItem &) const override
Definition: optgrid.cxx:59
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText, const IntlWrapper &) const override
Definition: optgrid.cxx:78
IMPL_LINK_NOARG(SvxGridTabPage, ClickRotateHdl_Impl, weld::ToggleButton &, void)
Definition: optgrid.cxx:263
void get_range(int &min, int &max, FieldUnit eDestUnit) const
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldDrawY
Definition: optgrid.hxx:109
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
Definition: dlgutil.cxx:31
int normalize(int nValue) const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
std::unique_ptr< weld::CheckButton > m_xCbxGridVisible
Definition: optgrid.hxx:107
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void SetExchangeSupport()
virtual SvxGridItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: optgrid.cxx:54
virtual void Reset(const SfxItemSet *rSet) override
Definition: optgrid.cxx:177
bool bAttrModified
Definition: optgrid.hxx:104
sal_uInt32 nFldSnapY
Definition: optgrid.hxx:39
void set_range(int min, int max, FieldUnit eValueUnit)
bool bSynchronize
Definition: optgrid.hxx:41
SvxGridItem(sal_uInt16 _nWhich)
Definition: optgrid.hxx:77
std::unique_ptr< weld::SpinButton > m_xNumFldDivisionX
Definition: optgrid.hxx:110
SfxItemPresentation
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
int GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rAttrSet)
Definition: optgrid.cxx:147
sal_uInt32 nFldDrawX
Definition: optgrid.hxx:34
void SetMetricValue(weld::MetricSpinButton &rField, int nCoreValue, MapUnit eUnit)
SfxItemPool * GetPool() const
bool bEqualGrid
Definition: optgrid.hxx:43
IMPL_LINK(SvxGridTabPage, ChangeDrawHdl_Impl, weld::MetricSpinButton &, rField, void)
Definition: optgrid.cxx:251
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optgrid.cxx:152
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldDrawX
Definition: optgrid.hxx:108
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: optgrid.cxx:202
bool bGridVisible
Definition: optgrid.hxx:42
static void lcl_SetMinMax(weld::MetricSpinButton &rField, int nMin, int nMax)
Definition: optgrid.cxx:35
sal_uInt32 nFldSnapX
Definition: optgrid.hxx:38
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: optgrid.cxx:244
sal_uInt32 nFldDrawY
Definition: optgrid.hxx:36
static void lcl_GetMinMax(weld::MetricSpinButton const &rField, int &nMin, int &nMax)
Definition: optgrid.cxx:28
std::unique_ptr< weld::CheckButton > m_xCbxSynchronize
Definition: optgrid.hxx:112
DeactivateRC
MapUnit
std::unique_ptr< weld::CheckButton > m_xCbxUseGridsnap
Definition: optgrid.hxx:106
int denormalize(int nValue) const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const