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 5670
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  sal_uInt16 nWhich = rPool.GetWhich(SID_ATTR_PARA_ULSPACE);
78  m_eUnit = rPool.GetMetric(nWhich);
79 
82 }
83 
85 {
86  sal_Int64 nVal = pItem->GetUpper();
87  nVal = m_xAboveSpacing->normalize(nVal);
88  m_xAboveSpacing->set_value(nVal, FieldUnit::MM_100TH);
89 
90  nVal = pItem->GetLower();
91  nVal = m_xBelowSpacing->normalize(nVal);
92  m_xBelowSpacing->set_value(nVal, FieldUnit::MM_100TH);
93 }
94 
96 {
98  if(pDisp)
99  {
100  SvxULSpaceItem aMargin(SID_ATTR_PARA_ULSPACE);
101  aMargin.SetUpper(m_xAboveSpacing->GetCoreValue(m_eUnit));
102  aMargin.SetLower(m_xBelowSpacing->GetCoreValue(m_eUnit));
103  pDisp->ExecuteList(SID_ATTR_PARA_ULSPACE, SfxCallMode::RECORD, {&aMargin});
104  }
105 }
106 
107 // ParaAboveSpacingWindow
108 
110  : ParaULSpacingWindow(pParent)
111 {
112  m_xAboveContainer->show();
113  m_xBelowContainer->hide();
114 
115  SetSizePixel(get_preferred_size());
116 }
117 
119 {
120  if (m_xAboveSpacing)
121  m_xAboveSpacing->grab_focus();
123 }
124 
125 // ParaBelowSpacingWindow
126 
128  : ParaULSpacingWindow(pParent)
129 {
130  m_xAboveContainer->hide();
131  m_xBelowContainer->show();
132 
133  SetSizePixel(get_preferred_size());
134 }
135 
137 {
138  if (m_xBelowSpacing)
139  m_xBelowSpacing->grab_focus();
141 }
142 
143 // ParaLRSpacingWindow
144 
146  : InterimItemWindow(pParent, "svx/ui/paralrspacing.ui", "ParaLRSpacingWindow")
147  , m_eUnit(MapUnit::MapTwip)
148 {
149  m_xBeforeSpacing = std::make_unique<SvxRelativeField>(m_xBuilder->weld_metric_spin_button("beforetextindent", FieldUnit::CM));
150  m_xAfterSpacing = std::make_unique<SvxRelativeField>(m_xBuilder->weld_metric_spin_button("aftertextindent", FieldUnit::CM));
151  m_xFLSpacing = std::make_unique<SvxRelativeField>(m_xBuilder->weld_metric_spin_button("firstlineindent", FieldUnit::CM));
152  m_xBeforeContainer = m_xBuilder->weld_container("before");
153  m_xAfterContainer = m_xBuilder->weld_container("after");
154  m_xFirstLineContainer = m_xBuilder->weld_container("firstline");
155 
156  Link<weld::MetricSpinButton&,void> aLink = LINK(this, ParaLRSpacingWindow, ModifySpacingHdl);
157  m_xBeforeSpacing->connect_value_changed(aLink);
158  m_xAfterSpacing->connect_value_changed(aLink);
159  m_xFLSpacing->connect_value_changed(aLink);
160 
162  m_xBeforeSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
163  m_xAfterSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
164  m_xFLSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
165 }
166 
168 {
169  disposeOnce();
170 }
171 
173 {
174  m_xBeforeSpacing.reset();
175  m_xAfterSpacing.reset();
176  m_xFLSpacing.reset();
177  m_xBeforeContainer.reset();
178  m_xAfterContainer.reset();
179  m_xFirstLineContainer.reset();
180 
182 }
183 
185 {
186  m_aContext = eContext;
187 }
188 
190 {
192  {
193 
194  case CombinedEnumContext(Application::WriterVariants, Context::DrawText):
195  case CombinedEnumContext(Application::WriterVariants, Context::Annotation):
196  case CombinedEnumContext(Application::Calc, Context::DrawText):
197  case CombinedEnumContext(Application::DrawImpress, Context::DrawText):
198  case CombinedEnumContext(Application::DrawImpress, Context::Draw):
199  case CombinedEnumContext(Application::DrawImpress, Context::TextObject):
200  case CombinedEnumContext(Application::DrawImpress, Context::Graphic):
201  case CombinedEnumContext(Application::DrawImpress, Context::Table):
202  {
203  m_xBeforeSpacing->set_min(DEFAULT_VALUE, FieldUnit::NONE);
204  m_xAfterSpacing->set_min(DEFAULT_VALUE, FieldUnit::NONE);
205  m_xFLSpacing->set_min(DEFAULT_VALUE, FieldUnit::NONE);
206  }
207  break;
208  case CombinedEnumContext(Application::WriterVariants, Context::Default):
209  case CombinedEnumContext(Application::WriterVariants, Context::Text):
210  case CombinedEnumContext(Application::WriterVariants, Context::Table):
211  {
212  m_xBeforeSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
213  m_xAfterSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
214  m_xFLSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
215  }
216  break;
217  }
218 
219  if(pState && eState >= SfxItemState::DEFAULT)
220  {
221  m_xBeforeSpacing->set_sensitive(true);
222  m_xAfterSpacing->set_sensitive(true);
223  m_xFLSpacing->set_sensitive(true);
224 
225  const SvxLRSpaceItem* pSpace = static_cast<const SvxLRSpaceItem*>(pState);
226  long aTxtLeft = pSpace->GetTextLeft();
227  long aTxtRight = pSpace->GetRight();
228  long aTxtFirstLineOfst = pSpace->GetTextFirstLineOffset();
229 
230  aTxtLeft = m_xBeforeSpacing->normalize(aTxtLeft);
231 
232  if(m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Text)
233  && m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Default)
234  && m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Table))
235  {
236  m_xFLSpacing->set_min(aTxtLeft*-1, FieldUnit::MM_100TH);
237  }
238 
239  aTxtRight = m_xAfterSpacing->normalize(aTxtRight);
240 
242  {
243  case CombinedEnumContext(Application::WriterVariants, Context::DrawText):
244  case CombinedEnumContext(Application::WriterVariants, Context::Text):
245  case CombinedEnumContext(Application::WriterVariants, Context::Default):
246  case CombinedEnumContext(Application::WriterVariants, Context::Table):
247  case CombinedEnumContext(Application::WriterVariants, Context::Annotation):
248  {
249  m_xBeforeSpacing->set_max(MAX_SW - aTxtRight, FieldUnit::MM_100TH);
250  m_xAfterSpacing->set_max(MAX_SW - aTxtLeft, FieldUnit::MM_100TH);
251  m_xFLSpacing->set_max(MAX_SW - aTxtLeft - aTxtRight, FieldUnit::MM_100TH);
252  }
253  break;
254  case CombinedEnumContext(Application::DrawImpress, Context::DrawText):
255  case CombinedEnumContext(Application::DrawImpress, Context::Draw):
256  case CombinedEnumContext(Application::DrawImpress, Context::Table):
257  case CombinedEnumContext(Application::DrawImpress, Context::TextObject):
258  case CombinedEnumContext(Application::DrawImpress, Context::Graphic):
259  {
260  m_xBeforeSpacing->set_max(MAX_SC_SD - aTxtRight, FieldUnit::MM_100TH);
261  m_xAfterSpacing->set_max(MAX_SC_SD - aTxtLeft, FieldUnit::MM_100TH);
262  m_xFLSpacing->set_max(MAX_SC_SD - aTxtLeft - aTxtRight, FieldUnit::MM_100TH);
263  }
264  }
265 
266  m_xBeforeSpacing->set_value(aTxtLeft, FieldUnit::MM_100TH);
267  m_xAfterSpacing->set_value(aTxtRight, FieldUnit::MM_100TH);
268 
269  aTxtFirstLineOfst = m_xFLSpacing->normalize(aTxtFirstLineOfst);
270  m_xFLSpacing->set_value(aTxtFirstLineOfst, FieldUnit::MM_100TH);
271  }
272  else if(eState == SfxItemState::DISABLED)
273  {
274  m_xBeforeSpacing->set_sensitive(false);
275  m_xAfterSpacing->set_sensitive(false);
276  m_xFLSpacing->set_sensitive(false);
277  }
278  else
279  {
280  m_xBeforeSpacing->set_text("");
281  m_xAfterSpacing->set_text("");
282  m_xFLSpacing->set_text("");
283  }
284 }
285 
287 {
288  m_xBeforeSpacing->SetFieldUnit(eUnit);
289  m_xAfterSpacing->SetFieldUnit(eUnit);
290  m_xFLSpacing->SetFieldUnit(eUnit);
291 
292  SfxItemPool &rPool = SfxGetpApp()->GetPool();
293  sal_uInt16 nWhich = rPool.GetWhich(SID_ATTR_PARA_LRSPACE);
294  m_eUnit = rPool.GetMetric(nWhich);
295 }
296 
298 {
300  if(pDisp)
301  {
302  SvxLRSpaceItem aMargin(SID_ATTR_PARA_LRSPACE);
303  aMargin.SetTextLeft(m_xBeforeSpacing->GetCoreValue(m_eUnit));
304  aMargin.SetRight(m_xAfterSpacing->GetCoreValue(m_eUnit));
305  aMargin.SetTextFirstLineOffset(m_xFLSpacing->GetCoreValue(m_eUnit));
306 
307  pDisp->ExecuteList(SID_ATTR_PARA_LRSPACE, SfxCallMode::RECORD, {&aMargin});
308  }
309 }
310 
311 // ParaLeftSpacingWindow
312 
314  : ParaLRSpacingWindow(pParent)
315 {
316  m_xBeforeContainer->show();
317  m_xAfterContainer->hide();
318  m_xFirstLineContainer->hide();
319 
320  SetSizePixel(get_preferred_size());
321 }
322 
324 {
325  if (m_xBeforeSpacing)
326  m_xBeforeSpacing->grab_focus();
328 }
329 
330 // ParaRightSpacingWindow
331 
333  : ParaLRSpacingWindow(pParent)
334 {
335  m_xBeforeContainer->hide();
336  m_xAfterContainer->show();
337  m_xFirstLineContainer->hide();
338 
339  SetSizePixel(get_preferred_size());
340 }
341 
343 {
344  if (m_xAfterSpacing)
345  m_xAfterSpacing->grab_focus();
347 }
348 
349 // ParaFirstLineSpacingWindow
350 
352  : ParaLRSpacingWindow(pParent)
353 {
354  m_xBeforeContainer->hide();
355  m_xAfterContainer->hide();
356  m_xFirstLineContainer->show();
357 
358  SetSizePixel(get_preferred_size());
359 }
360 
362 {
363  if (m_xFLSpacing)
364  m_xFLSpacing->grab_focus();
366 }
367 
368 /* 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
ParaBelowSpacingWindow(vcl::Window *pParent)
IMPL_LINK_NOARG(SuggestionDisplay, SelectSuggestionValueSetHdl, SvtValueSet *, void)
sal_uInt16 GetLower() const
ParaLRSpacingWindow(vcl::Window *pParent)
#define MAX_DURCH
std::unique_ptr< SvxRelativeField > m_xAfterSpacing
void SetTextLeft(const long nL, const sal_uInt16 nProp=100)
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)
virtual ~ParaULSpacingWindow() override
#define DEFAULT_VALUE
virtual void GetFocus() override
virtual void GetFocus() override
virtual void GetFocus() override
std::unique_ptr< SvxRelativeField > m_xBeforeSpacing
sal_Int32 GetCombinedContext_DI() const
virtual void GetFocus() override
void SetLower(const sal_uInt16 nL, const sal_uInt16 nProp=100)
SfxItemPool & GetPool() const
std::unique_ptr< weld::Container > m_xAfterContainer
void SetRight(const long nR, const sal_uInt16 nProp=100)
SfxBindings & GetBindings()
void SetTextFirstLineOffset(const short nF, const sal_uInt16 nProp=100)
#define MAX_SW
virtual ~ParaLRSpacingWindow() override
short GetTextFirstLineOffset() const
ParaLeftSpacingWindow(vcl::Window *pParent)
virtual void GetFocus() override
std::unique_ptr< weld::Container > m_xFirstLineContainer
static SfxViewFrame * Current()
SfxItemState
std::unique_ptr< weld::Container > m_xBeforeContainer
std::unique_ptr< SvxRelativeField > m_xAboveSpacing
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
virtual void GetFocus() override
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
long GetRight() const
FieldUnit MapToFieldUnit(const MapUnit eUnit)
SfxDispatcher * GetDispatcher() const
std::unique_ptr< SvxRelativeField > m_xFLSpacing
MapUnit
#define NEGA_MAXVALUE
virtual void dispose() override
long GetTextLeft() const
void SetUpper(const sal_uInt16 nU, const sal_uInt16 nProp=100)
ParaRightSpacingWindow(vcl::Window *pParent)
ParaFirstLineSpacingWindow(vcl::Window *pParent)
#define CombinedEnumContext(a, e)
std::unique_ptr< weld::Container > m_xBelowContainer
ParaULSpacingWindow(vcl::Window *pParent)
sal_uInt16 GetUpper() const