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 <sfx2/dispatch.hxx>
23 #include <sfx2/app.hxx>
24 #include <sfx2/viewfrm.hxx>
25 #include <svl/itempool.hxx>
26 #include <svl/intitem.hxx>
27 #include <vcl/builderfactory.hxx>
28 
29 using namespace svx;
30 
31 #define DEFAULT_VALUE 0
32 #define MAX_DURCH 5670
33 #define MAX_SW 1709400
34 #define MAX_SC_SD 116220200
35 #define NEGA_MAXVALUE -10000000
36 
37 // ParaULSpacingWindow
38 
39 ParaULSpacingWindow::ParaULSpacingWindow(vcl::Window* pParent, css::uno::Reference<css::frame::XFrame> const & xFrame)
40  : VclVBox(pParent)
41  , m_eUnit(MapUnit::MapTwip)
42 {
43  m_pUIBuilder.reset(new VclBuilder(this, getUIRootDir(),
44  "svx/ui/paraulspacing.ui",
45  "ParaULSpacingWindow",
46  xFrame));
47 
48  get(m_pAboveSpacing, "aboveparaspacing");
49  get(m_pBelowSpacing, "belowparaspacing");
50  get(m_pAboveContainer, "above");
51  get(m_pBelowContainer, "below");
52 
53  Link<Edit&,void> aLink = LINK(this, ParaULSpacingWindow, ModifySpacingHdl);
56 }
57 
59 {
60  disposeOnce();
61 }
62 
64 {
69 
72 }
73 
75 {
78 
79  SfxItemPool &rPool = SfxGetpApp()->GetPool();
80  sal_uInt16 nWhich = rPool.GetWhich(SID_ATTR_PARA_ULSPACE);
81  m_eUnit = rPool.GetMetric(nWhich);
82 
85 }
86 
88 {
89  sal_Int64 nVal = pItem->GetUpper();
90  nVal = m_pAboveSpacing->Normalize(nVal);
91  m_pAboveSpacing->SetValue(nVal, FieldUnit::MM_100TH);
92 
93  nVal = pItem->GetLower();
94  nVal = m_pBelowSpacing->Normalize(nVal);
95  m_pBelowSpacing->SetValue(nVal, FieldUnit::MM_100TH);
96 }
97 
98 IMPL_LINK_NOARG(ParaULSpacingWindow, ModifySpacingHdl, Edit&, void)
99 {
101  if(pDisp)
102  {
103  SvxULSpaceItem aMargin(SID_ATTR_PARA_ULSPACE);
104  aMargin.SetUpper(static_cast<sal_uInt16>(GetCoreValue(*m_pAboveSpacing, m_eUnit)));
105  aMargin.SetLower(static_cast<sal_uInt16>(GetCoreValue(*m_pBelowSpacing, m_eUnit)));
106  pDisp->ExecuteList(SID_ATTR_PARA_ULSPACE, SfxCallMode::RECORD, {&aMargin});
107  }
108 }
109 
110 // ParaAboveSpacingWindow
111 
112 ParaAboveSpacingWindow::ParaAboveSpacingWindow(vcl::Window* pParent, css::uno::Reference<css::frame::XFrame> const & xFrame)
113  : ParaULSpacingWindow(pParent, xFrame)
114 {
117 }
118 
120 {
122 }
123 
124 // ParaBelowSpacingWindow
125 
126 ParaBelowSpacingWindow::ParaBelowSpacingWindow(vcl::Window* pParent, css::uno::Reference<css::frame::XFrame> const & xFrame)
127  : ParaULSpacingWindow(pParent, xFrame)
128 {
131 }
132 
134 {
136 }
137 
138 // ParaLRSpacingWindow
139 
140 ParaLRSpacingWindow::ParaLRSpacingWindow(vcl::Window* pParent, css::uno::Reference<css::frame::XFrame> const & xFrame)
141  : VclVBox(pParent)
142  , m_eUnit(MapUnit::MapTwip)
143 {
144  m_pUIBuilder.reset(new VclBuilder(this, getUIRootDir(),
145  "svx/ui/paralrspacing.ui",
146  "ParaLRSpacingWindow",
147  xFrame));
148 
149  get(m_pBeforeSpacing, "beforetextindent");
150  get(m_pAfterSpacing, "aftertextindent");
151  get(m_pFLSpacing, "firstlineindent");
152  get(m_pBeforeContainer, "before");
153  get(m_pAfterContainer, "after");
154  get(m_pFirstLineContainer, "firstline");
155 
156  Link<Edit&,void> aLink = LINK(this, ParaLRSpacingWindow, ModifySpacingHdl);
159  m_pFLSpacing->SetModifyHdl(aLink);
160 }
161 
163 {
164  disposeOnce();
165 }
166 
168 {
175 
176  disposeBuilder();
178 }
179 
181 {
182  m_aContext = eContext;
183 }
184 
186 {
188  {
189 
190  case CombinedEnumContext(Application::WriterVariants, Context::DrawText):
191  case CombinedEnumContext(Application::WriterVariants, Context::Annotation):
192  case CombinedEnumContext(Application::Calc, Context::DrawText):
193  case CombinedEnumContext(Application::DrawImpress, Context::DrawText):
194  case CombinedEnumContext(Application::DrawImpress, Context::Draw):
195  case CombinedEnumContext(Application::DrawImpress, Context::TextObject):
196  case CombinedEnumContext(Application::DrawImpress, Context::Graphic):
197  case CombinedEnumContext(Application::DrawImpress, Context::Table):
198  {
202  }
203  break;
204  case CombinedEnumContext(Application::WriterVariants, Context::Default):
205  case CombinedEnumContext(Application::WriterVariants, Context::Text):
206  case CombinedEnumContext(Application::WriterVariants, Context::Table):
207  {
208  m_pBeforeSpacing->SetMin(NEGA_MAXVALUE, FieldUnit::MM_100TH);
209  m_pAfterSpacing->SetMin(NEGA_MAXVALUE, FieldUnit::MM_100TH);
210  m_pFLSpacing->SetMin(NEGA_MAXVALUE, FieldUnit::MM_100TH);
211  }
212  break;
213  }
214 
215  if(pState && eState >= SfxItemState::DEFAULT)
216  {
219  m_pFLSpacing->Enable();
220 
221  const SvxLRSpaceItem* pSpace = static_cast<const SvxLRSpaceItem*>(pState);
222  long aTxtLeft = pSpace->GetTextLeft();
223  long aTxtRight = pSpace->GetRight();
224  long aTxtFirstLineOfst = pSpace->GetTextFirstLineOfst();
225 
226  aTxtLeft = static_cast<long>(m_pBeforeSpacing->Normalize(aTxtLeft));
227 
228  if(m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Text)
229  && m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Default)
230  && m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Table))
231  {
232  m_pFLSpacing->SetMin(aTxtLeft*-1, FieldUnit::MM_100TH);
233  }
234 
235  aTxtRight = static_cast<long>(m_pAfterSpacing->Normalize(aTxtRight));
236 
238  {
239  case CombinedEnumContext(Application::WriterVariants, Context::DrawText):
240  case CombinedEnumContext(Application::WriterVariants, Context::Text):
241  case CombinedEnumContext(Application::WriterVariants, Context::Default):
242  case CombinedEnumContext(Application::WriterVariants, Context::Table):
243  case CombinedEnumContext(Application::WriterVariants, Context::Annotation):
244  {
245  m_pBeforeSpacing->SetMax(MAX_SW - aTxtRight, FieldUnit::MM_100TH);
246  m_pAfterSpacing->SetMax(MAX_SW - aTxtLeft, FieldUnit::MM_100TH);
247  m_pFLSpacing->SetMax(MAX_SW - aTxtLeft - aTxtRight, FieldUnit::MM_100TH);
248  }
249  break;
250  case CombinedEnumContext(Application::DrawImpress, Context::DrawText):
251  case CombinedEnumContext(Application::DrawImpress, Context::Draw):
252  case CombinedEnumContext(Application::DrawImpress, Context::Table):
253  case CombinedEnumContext(Application::DrawImpress, Context::TextObject):
254  case CombinedEnumContext(Application::DrawImpress, Context::Graphic):
255  {
256  m_pBeforeSpacing->SetMax(MAX_SC_SD - aTxtRight, FieldUnit::MM_100TH);
257  m_pAfterSpacing->SetMax(MAX_SC_SD - aTxtLeft, FieldUnit::MM_100TH);
258  m_pFLSpacing->SetMax(MAX_SC_SD - aTxtLeft - aTxtRight, FieldUnit::MM_100TH);
259  }
260  }
261 
262  m_pBeforeSpacing->SetValue(aTxtLeft, FieldUnit::MM_100TH);
263  m_pAfterSpacing->SetValue(aTxtRight, FieldUnit::MM_100TH);
264 
265  aTxtFirstLineOfst = static_cast<long>(m_pFLSpacing->Normalize(aTxtFirstLineOfst));
266  m_pFLSpacing->SetValue(aTxtFirstLineOfst, FieldUnit::MM_100TH);
267  }
268  else if(eState == SfxItemState::DISABLED)
269  {
273  }
274  else
275  {
279  }
280 }
281 
283 {
285  SetFieldUnit(*m_pAfterSpacing, eUnit);
286  SetFieldUnit(*m_pFLSpacing, eUnit);
287 
288  SfxItemPool &rPool = SfxGetpApp()->GetPool();
289  sal_uInt16 nWhich = rPool.GetWhich(SID_ATTR_PARA_LRSPACE);
290  m_eUnit = rPool.GetMetric(nWhich);
291 }
292 
293 IMPL_LINK_NOARG(ParaLRSpacingWindow, ModifySpacingHdl, Edit&, void)
294 {
296  if(pDisp)
297  {
298  SvxLRSpaceItem aMargin(SID_ATTR_PARA_LRSPACE);
299  aMargin.SetTextLeft(GetCoreValue(*m_pBeforeSpacing, m_eUnit));
300  aMargin.SetRight(GetCoreValue(*m_pAfterSpacing, m_eUnit));
301  aMargin.SetTextFirstLineOfst(static_cast<short>(GetCoreValue(*m_pFLSpacing, m_eUnit)));
302 
303  pDisp->ExecuteList(SID_ATTR_PARA_LRSPACE, SfxCallMode::RECORD, {&aMargin});
304  }
305 }
306 
307 // ParaLeftSpacingWindow
308 
309 ParaLeftSpacingWindow::ParaLeftSpacingWindow(vcl::Window* pParent, css::uno::Reference<css::frame::XFrame> const & xFrame)
310  : ParaLRSpacingWindow(pParent, xFrame)
311 {
315 }
316 
318 {
320 }
321 
322 // ParaRightSpacingWindow
323 
324 ParaRightSpacingWindow::ParaRightSpacingWindow(vcl::Window* pParent, css::uno::Reference<css::frame::XFrame> const & xFrame)
325  : ParaLRSpacingWindow(pParent, xFrame)
326 {
330 }
331 
333 {
335 }
336 
337 // ParaFirstLineSpacingWindow
338 
339 ParaFirstLineSpacingWindow::ParaFirstLineSpacingWindow(vcl::Window* pParent, css::uno::Reference<css::frame::XFrame> const & xFrame)
340  : ParaLRSpacingWindow(pParent, xFrame)
341 {
345 }
346 
348 {
350 }
351 
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
VclPtr< SvxRelativeField > m_pFLSpacing
void SetFieldUnit(weld::MetricSpinButton &rField, FieldUnit eUnit, bool bAll)
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
IMPL_LINK_NOARG(SuggestionDisplay, SelectSuggestionValueSetHdl, SvtValueSet *, void)
VclPtr< VclHBox > m_pFirstLineContainer
VclPtr< VclHBox > m_pAboveContainer
sal_uInt16 GetLower() const
short GetTextFirstLineOfst() const
#define MAX_DURCH
void SetMin(sal_Int64 nNewMin, FieldUnit eInUnit)
ParaLRSpacingWindow(vcl::Window *pParent, css::uno::Reference< css::frame::XFrame > const &xFrame)
ParaAboveSpacingWindow(vcl::Window *pParent, css::uno::Reference< css::frame::XFrame > const &xFrame)
void SetEmptyFieldValue()
void SetTextLeft(const long nL, const sal_uInt16 nProp=100)
void SetMax(sal_Int64 nNewMax, FieldUnit eInUnit)
virtual void dispose() override
ParaFirstLineSpacingWindow(vcl::Window *pParent, css::uno::Reference< css::frame::XFrame > const &xFrame)
#define MAX_SC_SD
SfxApplication * SfxGetpApp()
virtual void dispose() override
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
VclPtr< SvxRelativeField > m_pAboveSpacing
void SetContext(const vcl::EnumContext &eContext)
virtual ~ParaULSpacingWindow() override
#define DEFAULT_VALUE
virtual void SetModifyHdl(const Link< Edit &, void > &rLink)
void Enable(bool bEnable=true, bool bChild=true)
virtual void GetFocus() override
virtual void GetFocus() override
VclPtr< VclHBox > m_pAfterContainer
sal_Int32 GetCombinedContext_DI() const
virtual void GetFocus() override
void SetLower(const sal_uInt16 nL, const sal_uInt16 nProp=100)
SfxItemPool & GetPool() const
VclPtr< VclHBox > m_pBeforeContainer
void SetRight(const long nR, const sal_uInt16 nProp=100)
void clear()
SfxBindings & GetBindings()
sal_Int64 Normalize(sal_Int64 nValue) const
int GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
ParaLeftSpacingWindow(vcl::Window *pParent, css::uno::Reference< css::frame::XFrame > const &xFrame)
#define MAX_SW
virtual ~ParaLRSpacingWindow() override
std::unique_ptr< VclBuilder > m_pUIBuilder
static OUString getUIRootDir()
void GrabFocus()
void Disable(bool bChild=true)
VclPtr< SvxRelativeField > m_pAfterSpacing
virtual void GetFocus() override
static SfxViewFrame * Current()
ParaRightSpacingWindow(vcl::Window *pParent, css::uno::Reference< css::frame::XFrame > const &xFrame)
SfxItemState
void SetTextFirstLineOfst(const short nF, const sal_uInt16 nProp=100)
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
virtual void GetFocus() override
VclPtr< SvxRelativeField > m_pBelowSpacing
VclPtr< VclHBox > m_pBelowContainer
void SetUnit(FieldUnit eUnit)
VclPtr< SvxRelativeField > m_pBeforeSpacing
void SetUnit(FieldUnit eUnit)
void SetValue(const SvxULSpaceItem *pItem)
virtual void SetValue(sal_Int64 nNewValue, FieldUnit eInUnit)
ParaBelowSpacingWindow(vcl::Window *pParent, css::uno::Reference< css::frame::XFrame > const &xFrame)
long GetRight() const
ParaULSpacingWindow(vcl::Window *pParent, css::uno::Reference< css::frame::XFrame > const &xFrame)
FieldUnit MapToFieldUnit(const MapUnit eUnit)
SfxDispatcher * GetDispatcher() const
MapUnit
#define NEGA_MAXVALUE
virtual void dispose() override
long GetTextLeft() const
void SetUpper(const sal_uInt16 nU, const sal_uInt16 nProp=100)
#define CombinedEnumContext(a, e)
sal_uInt16 GetUpper() const
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)