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
109  : ParaULSpacingWindow(pParent)
110 {
111  InitControlBase(&m_xAboveSpacing->get_widget());
112 
113  m_xAboveContainer->show();
114  m_xBelowContainer->hide();
115 
117 }
118 
119 // ParaBelowSpacingWindow
121  : ParaULSpacingWindow(pParent)
122 {
123  InitControlBase(&m_xBelowSpacing->get_widget());
124 
125  m_xAboveContainer->hide();
126  m_xBelowContainer->show();
127 
129 }
130 
131 // ParaLRSpacingWindow
133  : InterimItemWindow(pParent, "svx/ui/paralrspacing.ui", "ParaLRSpacingWindow")
134  , m_eUnit(MapUnit::MapTwip)
135 {
136  m_xBeforeSpacing = std::make_unique<SvxRelativeField>(m_xBuilder->weld_metric_spin_button("beforetextindent", FieldUnit::CM));
137  m_xAfterSpacing = std::make_unique<SvxRelativeField>(m_xBuilder->weld_metric_spin_button("aftertextindent", FieldUnit::CM));
138  m_xFLSpacing = std::make_unique<SvxRelativeField>(m_xBuilder->weld_metric_spin_button("firstlineindent", FieldUnit::CM));
139  m_xBeforeContainer = m_xBuilder->weld_container("before");
140  m_xAfterContainer = m_xBuilder->weld_container("after");
141  m_xFirstLineContainer = m_xBuilder->weld_container("firstline");
142 
143  Link<weld::MetricSpinButton&,void> aLink = LINK(this, ParaLRSpacingWindow, ModifySpacingHdl);
144  m_xBeforeSpacing->connect_value_changed(aLink);
145  m_xAfterSpacing->connect_value_changed(aLink);
146  m_xFLSpacing->connect_value_changed(aLink);
147 
149  m_xBeforeSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
150  m_xAfterSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
151  m_xFLSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
152 }
153 
155 {
156  disposeOnce();
157 }
158 
160 {
161  m_xBeforeSpacing.reset();
162  m_xAfterSpacing.reset();
163  m_xFLSpacing.reset();
164  m_xBeforeContainer.reset();
165  m_xAfterContainer.reset();
166  m_xFirstLineContainer.reset();
167 
169 }
170 
172 {
173  m_aContext = eContext;
174 }
175 
177 {
179  {
180 
181  case CombinedEnumContext(Application::WriterVariants, Context::DrawText):
182  case CombinedEnumContext(Application::WriterVariants, Context::Annotation):
183  case CombinedEnumContext(Application::Calc, Context::DrawText):
184  case CombinedEnumContext(Application::DrawImpress, Context::DrawText):
185  case CombinedEnumContext(Application::DrawImpress, Context::Draw):
186  case CombinedEnumContext(Application::DrawImpress, Context::TextObject):
187  case CombinedEnumContext(Application::DrawImpress, Context::Graphic):
188  case CombinedEnumContext(Application::DrawImpress, Context::Table):
189  {
190  m_xBeforeSpacing->set_min(DEFAULT_VALUE, FieldUnit::NONE);
191  m_xAfterSpacing->set_min(DEFAULT_VALUE, FieldUnit::NONE);
192  m_xFLSpacing->set_min(DEFAULT_VALUE, FieldUnit::NONE);
193  }
194  break;
195  case CombinedEnumContext(Application::WriterVariants, Context::Default):
196  case CombinedEnumContext(Application::WriterVariants, Context::Text):
197  case CombinedEnumContext(Application::WriterVariants, Context::Table):
198  {
199  m_xBeforeSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
200  m_xAfterSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
201  m_xFLSpacing->set_min(NEGA_MAXVALUE, FieldUnit::MM_100TH);
202  }
203  break;
204  }
205 
206  if(pState && eState >= SfxItemState::DEFAULT)
207  {
208  m_xBeforeSpacing->set_sensitive(true);
209  m_xAfterSpacing->set_sensitive(true);
210  m_xFLSpacing->set_sensitive(true);
211 
212  const SvxLRSpaceItem* pSpace = static_cast<const SvxLRSpaceItem*>(pState);
213  long aTxtLeft = pSpace->GetTextLeft();
214  long aTxtRight = pSpace->GetRight();
215  long aTxtFirstLineOfst = pSpace->GetTextFirstLineOffset();
216 
217  aTxtLeft = m_xBeforeSpacing->normalize(aTxtLeft);
218 
219  if(m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Text)
220  && m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Default)
221  && m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Table))
222  {
223  m_xFLSpacing->set_min(aTxtLeft*-1, FieldUnit::MM_100TH);
224  }
225 
226  aTxtRight = m_xAfterSpacing->normalize(aTxtRight);
227 
229  {
230  case CombinedEnumContext(Application::WriterVariants, Context::DrawText):
231  case CombinedEnumContext(Application::WriterVariants, Context::Text):
232  case CombinedEnumContext(Application::WriterVariants, Context::Default):
233  case CombinedEnumContext(Application::WriterVariants, Context::Table):
234  case CombinedEnumContext(Application::WriterVariants, Context::Annotation):
235  {
236  m_xBeforeSpacing->set_max(MAX_SW - aTxtRight, FieldUnit::MM_100TH);
237  m_xAfterSpacing->set_max(MAX_SW - aTxtLeft, FieldUnit::MM_100TH);
238  m_xFLSpacing->set_max(MAX_SW - aTxtLeft - aTxtRight, FieldUnit::MM_100TH);
239  }
240  break;
241  case CombinedEnumContext(Application::DrawImpress, Context::DrawText):
242  case CombinedEnumContext(Application::DrawImpress, Context::Draw):
243  case CombinedEnumContext(Application::DrawImpress, Context::Table):
244  case CombinedEnumContext(Application::DrawImpress, Context::TextObject):
245  case CombinedEnumContext(Application::DrawImpress, Context::Graphic):
246  {
247  m_xBeforeSpacing->set_max(MAX_SC_SD - aTxtRight, FieldUnit::MM_100TH);
248  m_xAfterSpacing->set_max(MAX_SC_SD - aTxtLeft, FieldUnit::MM_100TH);
249  m_xFLSpacing->set_max(MAX_SC_SD - aTxtLeft - aTxtRight, FieldUnit::MM_100TH);
250  }
251  }
252 
253  m_xBeforeSpacing->set_value(aTxtLeft, FieldUnit::MM_100TH);
254  m_xAfterSpacing->set_value(aTxtRight, FieldUnit::MM_100TH);
255 
256  aTxtFirstLineOfst = m_xFLSpacing->normalize(aTxtFirstLineOfst);
257  m_xFLSpacing->set_value(aTxtFirstLineOfst, FieldUnit::MM_100TH);
258  }
259  else if(eState == SfxItemState::DISABLED)
260  {
261  m_xBeforeSpacing->set_sensitive(false);
262  m_xAfterSpacing->set_sensitive(false);
263  m_xFLSpacing->set_sensitive(false);
264  }
265  else
266  {
267  m_xBeforeSpacing->set_text("");
268  m_xAfterSpacing->set_text("");
269  m_xFLSpacing->set_text("");
270  }
271 }
272 
274 {
275  m_xBeforeSpacing->SetFieldUnit(eUnit);
276  m_xAfterSpacing->SetFieldUnit(eUnit);
277  m_xFLSpacing->SetFieldUnit(eUnit);
278 
279  SfxItemPool &rPool = SfxGetpApp()->GetPool();
280  sal_uInt16 nWhich = rPool.GetWhich(SID_ATTR_PARA_LRSPACE);
281  m_eUnit = rPool.GetMetric(nWhich);
282 }
283 
285 {
287  if(pDisp)
288  {
289  SvxLRSpaceItem aMargin(SID_ATTR_PARA_LRSPACE);
290  aMargin.SetTextLeft(m_xBeforeSpacing->GetCoreValue(m_eUnit));
291  aMargin.SetRight(m_xAfterSpacing->GetCoreValue(m_eUnit));
292  aMargin.SetTextFirstLineOffset(m_xFLSpacing->GetCoreValue(m_eUnit));
293 
294  pDisp->ExecuteList(SID_ATTR_PARA_LRSPACE, SfxCallMode::RECORD, {&aMargin});
295  }
296 }
297 
298 // ParaLeftSpacingWindow
300  : ParaLRSpacingWindow(pParent)
301 {
302  InitControlBase(&m_xBeforeSpacing->get_widget());
303 
304  m_xBeforeContainer->show();
305  m_xAfterContainer->hide();
306  m_xFirstLineContainer->hide();
307 
309 }
310 
311 // ParaRightSpacingWindow
313  : ParaLRSpacingWindow(pParent)
314 {
315  InitControlBase(&m_xAfterSpacing->get_widget());
316 
317  m_xBeforeContainer->hide();
318  m_xAfterContainer->show();
319  m_xFirstLineContainer->hide();
320 
322 }
323 
324 // ParaFirstLineSpacingWindow
326  : ParaLRSpacingWindow(pParent)
327 {
328  InitControlBase(&m_xFLSpacing->get_widget());
329 
330  m_xBeforeContainer->hide();
331  m_xAfterContainer->hide();
332  m_xFirstLineContainer->show();
333 
335 }
336 
337 /* 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)
sal_uInt16 GetLower() const
ParaLRSpacingWindow(vcl::Window *pParent)
#define MAX_DURCH
std::unique_ptr< SvxRelativeField > m_xAfterSpacing
virtual void SetSizePixel(const Size &rNewSize)
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
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)
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
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
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
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)
void InitControlBase(weld::Widget *pWidget)
#define CombinedEnumContext(a, e)
std::unique_ptr< weld::Container > m_xBelowContainer
ParaULSpacingWindow(vcl::Window *pParent)
sal_uInt16 GetUpper() const