LibreOffice Module svx (master)  1
ParaSpacingWindow.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 "ParaSpacingWindow.hxx"
21 #include <editeng/editids.hrc>
22 #include <editeng/lrspitem.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <sfx2/app.hxx>
25 #include <sfx2/viewfrm.hxx>
26 #include <svl/itempool.hxx>
27 
28 using namespace svx;
29 
30 #define DEFAULT_VALUE 0
31 #define MAX_DURCH 31680 // tdf#68335: 1584 pt for UX interoperability with Word
32 #define MAX_SW 1709400
33 #define MAX_SC_SD 116220200
34 #define NEGA_MAXVALUE -10000000
35 
36 // ParaULSpacingWindow
37 
39  : InterimItemWindow(pParent, "svx/ui/paraulspacing.ui", "ParaULSpacingWindow")
40  , m_eUnit(MapUnit::MapTwip)
41 {
42  m_xAboveSpacing = std::make_unique<SvxRelativeField>(m_xBuilder->weld_metric_spin_button("aboveparaspacing", FieldUnit::CM));
43  m_xBelowSpacing = std::make_unique<SvxRelativeField>(m_xBuilder->weld_metric_spin_button("belowparaspacing", FieldUnit::CM));
44  m_xAboveContainer = m_xBuilder->weld_container("above");
45  m_xBelowContainer = m_xBuilder->weld_container("below");
46 
47  Link<weld::MetricSpinButton&,void> aLink = LINK(this, ParaULSpacingWindow, ModifySpacingHdl);
48  m_xAboveSpacing->connect_value_changed(aLink);
49  m_xBelowSpacing->connect_value_changed(aLink);
50 
52  m_xAboveSpacing->set_max(m_xAboveSpacing->normalize(MAX_DURCH), FieldUnit::CM);
53  m_xBelowSpacing->set_max(m_xBelowSpacing->normalize(MAX_DURCH), FieldUnit::CM);
54 }
55 
57 {
58  disposeOnce();
59 }
60 
62 {
63  m_xAboveSpacing.reset();
64  m_xBelowSpacing.reset();
65  m_xAboveContainer.reset();
66  m_xBelowContainer.reset();
67 
69 }
70 
72 {
73  m_xAboveSpacing->SetFieldUnit(eUnit);
74  m_xBelowSpacing->SetFieldUnit(eUnit);
75 
76  SfxItemPool &rPool = SfxGetpApp()->GetPool();
77  m_eUnit = rPool.GetMetric(SID_ATTR_PARA_ULSPACE);
78 
81 }
82 
84 {
85  sal_Int64 nVal = pItem->GetUpper();
86  nVal = m_xAboveSpacing->normalize(nVal);
87  m_xAboveSpacing->set_value(nVal, FieldUnit::MM_100TH);
88 
89  nVal = pItem->GetLower();
90  nVal = m_xBelowSpacing->normalize(nVal);
91  m_xBelowSpacing->set_value(nVal, FieldUnit::MM_100TH);
92 }
93 
95 {
97  if (!pFrame)
98  return;
99  SfxDispatcher* pDisp = pFrame->GetBindings().GetDispatcher();
100  if(pDisp)
101  {
102  SvxULSpaceItem aMargin(SID_ATTR_PARA_ULSPACE);
103  aMargin.SetUpper(m_xAboveSpacing->GetCoreValue(m_eUnit));
104  aMargin.SetLower(m_xBelowSpacing->GetCoreValue(m_eUnit));
105  pDisp->ExecuteList(SID_ATTR_PARA_ULSPACE, SfxCallMode::RECORD, {&aMargin});
106  }
107 }
108 
109 // ParaAboveSpacingWindow
111  : ParaULSpacingWindow(pParent)
112 {
113  InitControlBase(&m_xAboveSpacing->get_widget());
114 
115  m_xAboveContainer->show();
116  m_xBelowContainer->hide();
117 
119 }
120 
121 // ParaBelowSpacingWindow
123  : ParaULSpacingWindow(pParent)
124 {
125  InitControlBase(&m_xBelowSpacing->get_widget());
126 
127  m_xAboveContainer->hide();
128  m_xBelowContainer->show();
129 
131 }
132 
133 // ParaLRSpacingWindow
135  : InterimItemWindow(pParent, "svx/ui/paralrspacing.ui", "ParaLRSpacingWindow")
136  , m_eUnit(MapUnit::MapTwip)
137 {
138  m_xBeforeSpacing = std::make_unique<SvxRelativeField>(m_xBuilder->weld_metric_spin_button("beforetextindent", FieldUnit::CM));
139  m_xAfterSpacing = std::make_unique<SvxRelativeField>(m_xBuilder->weld_metric_spin_button("aftertextindent", FieldUnit::CM));
140  m_xFLSpacing = std::make_unique<SvxRelativeField>(m_xBuilder->weld_metric_spin_button("firstlineindent", FieldUnit::CM));
141  m_xBeforeContainer = m_xBuilder->weld_container("before");
142  m_xAfterContainer = m_xBuilder->weld_container("after");
143  m_xFirstLineContainer = m_xBuilder->weld_container("firstline");
144 
145  Link<weld::MetricSpinButton&,void> aLink = LINK(this, ParaLRSpacingWindow, ModifySpacingHdl);
146  m_xBeforeSpacing->connect_value_changed(aLink);
147  m_xAfterSpacing->connect_value_changed(aLink);
148  m_xFLSpacing->connect_value_changed(aLink);
149 
151  m_xBeforeSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
152  m_xAfterSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
153  m_xFLSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
154 }
155 
157 {
158  disposeOnce();
159 }
160 
162 {
163  m_xBeforeSpacing.reset();
164  m_xAfterSpacing.reset();
165  m_xFLSpacing.reset();
166  m_xBeforeContainer.reset();
167  m_xAfterContainer.reset();
168  m_xFirstLineContainer.reset();
169 
171 }
172 
174 {
175  m_aContext = eContext;
176 }
177 
179 {
181  {
182 
183  case CombinedEnumContext(Application::WriterVariants, Context::DrawText):
184  case CombinedEnumContext(Application::WriterVariants, Context::Annotation):
185  case CombinedEnumContext(Application::Calc, Context::DrawText):
186  case CombinedEnumContext(Application::DrawImpress, Context::DrawText):
187  case CombinedEnumContext(Application::DrawImpress, Context::Draw):
188  case CombinedEnumContext(Application::DrawImpress, Context::TextObject):
189  case CombinedEnumContext(Application::DrawImpress, Context::Graphic):
190  case CombinedEnumContext(Application::DrawImpress, Context::Table):
191  {
192  m_xBeforeSpacing->set_min(DEFAULT_VALUE, FieldUnit::NONE);
193  m_xAfterSpacing->set_min(DEFAULT_VALUE, FieldUnit::NONE);
194  m_xFLSpacing->set_min(DEFAULT_VALUE, FieldUnit::NONE);
195  }
196  break;
197  case CombinedEnumContext(Application::WriterVariants, Context::Default):
198  case CombinedEnumContext(Application::WriterVariants, Context::Text):
199  case CombinedEnumContext(Application::WriterVariants, Context::Table):
200  {
201  m_xBeforeSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
202  m_xAfterSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
203  m_xFLSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
204  }
205  break;
206  }
207 
208  if(pState && eState >= SfxItemState::DEFAULT)
209  {
210  m_xBeforeSpacing->set_sensitive(true);
211  m_xAfterSpacing->set_sensitive(true);
212  m_xFLSpacing->set_sensitive(true);
213 
214  const SvxLRSpaceItem* pSpace = static_cast<const SvxLRSpaceItem*>(pState);
215  tools::Long aTxtLeft = pSpace->GetTextLeft();
216  tools::Long aTxtRight = pSpace->GetRight();
217  tools::Long aTxtFirstLineOfst = pSpace->GetTextFirstLineOffset();
218 
219  aTxtLeft = m_xBeforeSpacing->normalize(aTxtLeft);
220 
221  if(m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Text)
222  && m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Default)
223  && m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Table))
224  {
225  m_xFLSpacing->set_min(aTxtLeft*-1, FieldUnit::MM_100TH);
226  }
227 
228  aTxtRight = m_xAfterSpacing->normalize(aTxtRight);
229 
231  {
232  case CombinedEnumContext(Application::WriterVariants, Context::DrawText):
233  case CombinedEnumContext(Application::WriterVariants, Context::Text):
234  case CombinedEnumContext(Application::WriterVariants, Context::Default):
235  case CombinedEnumContext(Application::WriterVariants, Context::Table):
236  case CombinedEnumContext(Application::WriterVariants, Context::Annotation):
237  {
238  m_xBeforeSpacing->set_max(MAX_SW - aTxtRight, FieldUnit::MM_100TH);
239  m_xAfterSpacing->set_max(MAX_SW - aTxtLeft, FieldUnit::MM_100TH);
240  m_xFLSpacing->set_max(MAX_SW - aTxtLeft - aTxtRight, FieldUnit::MM_100TH);
241  }
242  break;
243  case CombinedEnumContext(Application::DrawImpress, Context::DrawText):
244  case CombinedEnumContext(Application::DrawImpress, Context::Draw):
245  case CombinedEnumContext(Application::DrawImpress, Context::Table):
246  case CombinedEnumContext(Application::DrawImpress, Context::TextObject):
247  case CombinedEnumContext(Application::DrawImpress, Context::Graphic):
248  {
249  m_xBeforeSpacing->set_max(MAX_SC_SD - aTxtRight, FieldUnit::MM_100TH);
250  m_xAfterSpacing->set_max(MAX_SC_SD - aTxtLeft, FieldUnit::MM_100TH);
251  m_xFLSpacing->set_max(MAX_SC_SD - aTxtLeft - aTxtRight, FieldUnit::MM_100TH);
252  }
253  }
254 
255  m_xBeforeSpacing->set_value(aTxtLeft, FieldUnit::MM_100TH);
256  m_xAfterSpacing->set_value(aTxtRight, FieldUnit::MM_100TH);
257 
258  aTxtFirstLineOfst = m_xFLSpacing->normalize(aTxtFirstLineOfst);
259  m_xFLSpacing->set_value(aTxtFirstLineOfst, FieldUnit::MM_100TH);
260  }
261  else if(eState == SfxItemState::DISABLED)
262  {
263  m_xBeforeSpacing->set_sensitive(false);
264  m_xAfterSpacing->set_sensitive(false);
265  m_xFLSpacing->set_sensitive(false);
266  }
267  else
268  {
269  m_xBeforeSpacing->set_text("");
270  m_xAfterSpacing->set_text("");
271  m_xFLSpacing->set_text("");
272  }
273 }
274 
276 {
277  m_xBeforeSpacing->SetFieldUnit(eUnit);
278  m_xAfterSpacing->SetFieldUnit(eUnit);
279  m_xFLSpacing->SetFieldUnit(eUnit);
280 
281  SfxItemPool &rPool = SfxGetpApp()->GetPool();
282  m_eUnit = rPool.GetMetric(SID_ATTR_PARA_LRSPACE);
283 }
284 
286 {
288  if (!pFrame)
289  return;
290  SfxDispatcher* pDisp = pFrame->GetBindings().GetDispatcher();
291  if(pDisp)
292  {
293  SvxLRSpaceItem aMargin(SID_ATTR_PARA_LRSPACE);
294  aMargin.SetTextLeft(m_xBeforeSpacing->GetCoreValue(m_eUnit));
295  aMargin.SetRight(m_xAfterSpacing->GetCoreValue(m_eUnit));
296  aMargin.SetTextFirstLineOffset(m_xFLSpacing->GetCoreValue(m_eUnit));
297 
298  pDisp->ExecuteList(SID_ATTR_PARA_LRSPACE, SfxCallMode::RECORD, {&aMargin});
299  }
300 }
301 
302 // ParaLeftSpacingWindow
304  : ParaLRSpacingWindow(pParent)
305 {
306  InitControlBase(&m_xBeforeSpacing->get_widget());
307 
308  m_xBeforeContainer->show();
309  m_xAfterContainer->hide();
310  m_xFirstLineContainer->hide();
311 
313 }
314 
315 // ParaRightSpacingWindow
317  : ParaLRSpacingWindow(pParent)
318 {
319  InitControlBase(&m_xAfterSpacing->get_widget());
320 
321  m_xBeforeContainer->hide();
322  m_xAfterContainer->show();
323  m_xFirstLineContainer->hide();
324 
326 }
327 
328 // ParaFirstLineSpacingWindow
330  : ParaLRSpacingWindow(pParent)
331 {
332  InitControlBase(&m_xFLSpacing->get_widget());
333 
334  m_xBeforeContainer->hide();
335  m_xAfterContainer->hide();
336  m_xFirstLineContainer->show();
337 
339 }
340 
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< SvxRelativeField > m_xBelowSpacing
void SetValue(SfxItemState eState, const SfxPoolItem *pState)
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
FieldUnit
void SetRight(const tools::Long nR, const sal_uInt16 nProp=100)
ParaBelowSpacingWindow(vcl::Window *pParent)
sal_uInt16 GetLower() const
ParaLRSpacingWindow(vcl::Window *pParent)
#define MAX_DURCH
long Long
tools::Long GetRight() const
std::unique_ptr< SvxRelativeField > m_xAfterSpacing
virtual void SetSizePixel(const Size &rNewSize)
std::unique_ptr< weld::Container > m_xAboveContainer
#define MAX_SC_SD
SfxApplication * SfxGetpApp()
virtual void dispose() override
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
void SetContext(const vcl::EnumContext &eContext)
void SetTextLeft(const tools::Long nL, const sal_uInt16 nProp=100)
virtual ~ParaULSpacingWindow() override
#define DEFAULT_VALUE
std::unique_ptr< SvxRelativeField > m_xBeforeSpacing
sal_Int32 GetCombinedContext_DI() const
void SetLower(const sal_uInt16 nL, const sal_uInt16 nProp=100)
SfxItemPool & GetPool() const
std::unique_ptr< weld::Container > m_xAfterContainer
IMPL_LINK_NOARG(SuggestionDisplay, SelectSuggestionValueSetHdl, ValueSet *, void)
tools::Long GetTextLeft() const
SfxBindings & GetBindings()
void SetTextFirstLineOffset(const short nF, const sal_uInt16 nProp=100)
#define MAX_SW
virtual ~ParaLRSpacingWindow() override
Size get_preferred_size() const
short GetTextFirstLineOffset() const
ParaLeftSpacingWindow(vcl::Window *pParent)
std::unique_ptr< weld::Container > m_xFirstLineContainer
static SfxViewFrame * Current()
SfxItemState
std::unique_ptr< weld::Container > m_xBeforeContainer
std::unique_ptr< SvxRelativeField > m_xAboveSpacing
virtual void dispose() override
void SetUnit(FieldUnit eUnit)
ParaAboveSpacingWindow(vcl::Window *pParent)
void SetUnit(FieldUnit eUnit)
void SetValue(const SvxULSpaceItem *pItem)
std::unique_ptr< weld::Builder > m_xBuilder
FieldUnit MapToFieldUnit(const MapUnit eUnit)
SfxDispatcher * GetDispatcher() const
std::unique_ptr< SvxRelativeField > m_xFLSpacing
MapUnit
#define NEGA_MAXVALUE
virtual void dispose() override
void SetUpper(const sal_uInt16 nU, const sal_uInt16 nProp=100)
ParaRightSpacingWindow(vcl::Window *pParent)
ParaFirstLineSpacingWindow(vcl::Window *pParent)
void InitControlBase(weld::Widget *pWidget)
#define CombinedEnumContext(a, e)
std::unique_ptr< weld::Container > m_xBelowContainer
ParaULSpacingWindow(vcl::Window *pParent)
sal_uInt16 GetUpper() const