1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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
36 // ParaULSpacingWindow
38 ParaULSpacingWindow::ParaULSpacingWindow(vcl::Window
* pParent
)
39 : InterimItemWindow(pParent
, "svx/ui/paraulspacing.ui", "ParaULSpacingWindow")
40 , m_eUnit(MapUnit::MapTwip
)
42 m_xAboveSpacing
.emplace(m_xBuilder
->weld_metric_spin_button("aboveparaspacing", FieldUnit::CM
));
43 m_xBelowSpacing
.emplace(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");
47 Link
<weld::MetricSpinButton
&,void> aLink
= LINK(this, ParaULSpacingWindow
, ModifySpacingHdl
);
48 m_xAboveSpacing
->connect_value_changed(aLink
);
49 m_xBelowSpacing
->connect_value_changed(aLink
);
51 /// set the initial values of max width
52 m_xAboveSpacing
->set_max(m_xAboveSpacing
->normalize(MAX_DURCH
), FieldUnit::CM
);
53 m_xBelowSpacing
->set_max(m_xBelowSpacing
->normalize(MAX_DURCH
), FieldUnit::CM
);
56 ParaULSpacingWindow::~ParaULSpacingWindow()
61 void ParaULSpacingWindow::dispose()
63 m_xAboveSpacing
.reset();
64 m_xBelowSpacing
.reset();
65 m_xAboveContainer
.reset();
66 m_xBelowContainer
.reset();
68 InterimItemWindow::dispose();
71 void ParaULSpacingWindow::SetUnit(FieldUnit eUnit
)
73 m_xAboveSpacing
->SetFieldUnit(eUnit
);
74 m_xBelowSpacing
->SetFieldUnit(eUnit
);
76 SfxItemPool
&rPool
= SfxGetpApp()->GetPool();
77 m_eUnit
= rPool
.GetMetric(SID_ATTR_PARA_ULSPACE
);
79 m_xAboveSpacing
->set_max(m_xAboveSpacing
->normalize(MAX_DURCH
), MapToFieldUnit(m_eUnit
));
80 m_xBelowSpacing
->set_max(m_xBelowSpacing
->normalize(MAX_DURCH
), MapToFieldUnit(m_eUnit
));
83 void ParaULSpacingWindow::SetValue(const SvxULSpaceItem
* pItem
)
85 sal_Int64 nVal
= pItem
->GetUpper();
86 nVal
= m_xAboveSpacing
->normalize(nVal
);
87 m_xAboveSpacing
->set_value(nVal
, FieldUnit::MM_100TH
);
89 nVal
= pItem
->GetLower();
90 nVal
= m_xBelowSpacing
->normalize(nVal
);
91 m_xBelowSpacing
->set_value(nVal
, FieldUnit::MM_100TH
);
94 IMPL_LINK_NOARG(ParaULSpacingWindow
, ModifySpacingHdl
, weld::MetricSpinButton
&, void)
96 SfxViewFrame
* pFrame
= SfxViewFrame::Current();
99 SfxDispatcher
* pDisp
= pFrame
->GetBindings().GetDispatcher();
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
});
109 // ParaAboveSpacingWindow
110 ParaAboveSpacingWindow::ParaAboveSpacingWindow(vcl::Window
* pParent
)
111 : ParaULSpacingWindow(pParent
)
113 InitControlBase(&m_xAboveSpacing
->get_widget());
115 m_xAboveContainer
->show();
116 m_xBelowContainer
->hide();
118 SetSizePixel(get_preferred_size());
121 // ParaBelowSpacingWindow
122 ParaBelowSpacingWindow::ParaBelowSpacingWindow(vcl::Window
* pParent
)
123 : ParaULSpacingWindow(pParent
)
125 InitControlBase(&m_xBelowSpacing
->get_widget());
127 m_xAboveContainer
->hide();
128 m_xBelowContainer
->show();
130 SetSizePixel(get_preferred_size());
133 // ParaLRSpacingWindow
134 ParaLRSpacingWindow::ParaLRSpacingWindow(vcl::Window
* pParent
)
135 : InterimItemWindow(pParent
, "svx/ui/paralrspacing.ui", "ParaLRSpacingWindow")
136 , m_eUnit(MapUnit::MapTwip
)
138 m_xBeforeSpacing
.emplace(m_xBuilder
->weld_metric_spin_button("beforetextindent", FieldUnit::CM
));
139 m_xAfterSpacing
.emplace(m_xBuilder
->weld_metric_spin_button("aftertextindent", FieldUnit::CM
));
140 m_xFLSpacing
.emplace(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");
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
);
150 /// set the initial values of max width
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
);
156 ParaLRSpacingWindow::~ParaLRSpacingWindow()
161 void ParaLRSpacingWindow::dispose()
163 m_xBeforeSpacing
.reset();
164 m_xAfterSpacing
.reset();
165 m_xFLSpacing
.reset();
166 m_xBeforeContainer
.reset();
167 m_xAfterContainer
.reset();
168 m_xFirstLineContainer
.reset();
170 InterimItemWindow::dispose();
173 void ParaLRSpacingWindow::SetContext(const vcl::EnumContext
& eContext
)
175 m_aContext
= eContext
;
178 void ParaLRSpacingWindow::SetValue(SfxItemState eState
, const SfxPoolItem
* pState
)
180 switch(m_aContext
.GetCombinedContext_DI())
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
):
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
);
197 case CombinedEnumContext(Application::WriterVariants
, Context::Default
):
198 case CombinedEnumContext(Application::WriterVariants
, Context::Text
):
199 case CombinedEnumContext(Application::WriterVariants
, Context::Table
):
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
);
208 if(pState
&& eState
>= SfxItemState::DEFAULT
)
210 m_xBeforeSpacing
->set_sensitive(true);
211 m_xAfterSpacing
->set_sensitive(true);
212 m_xFLSpacing
->set_sensitive(true);
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();
219 aTxtLeft
= m_xBeforeSpacing
->normalize(aTxtLeft
);
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
))
225 m_xFLSpacing
->set_min(aTxtLeft
*-1, FieldUnit::MM_100TH
);
228 aTxtRight
= m_xAfterSpacing
->normalize(aTxtRight
);
230 switch(m_aContext
.GetCombinedContext_DI())
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
):
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
);
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
):
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
);
255 m_xBeforeSpacing
->set_value(aTxtLeft
, FieldUnit::MM_100TH
);
256 m_xAfterSpacing
->set_value(aTxtRight
, FieldUnit::MM_100TH
);
258 aTxtFirstLineOfst
= m_xFLSpacing
->normalize(aTxtFirstLineOfst
);
259 m_xFLSpacing
->set_value(aTxtFirstLineOfst
, FieldUnit::MM_100TH
);
261 else if(eState
== SfxItemState::DISABLED
)
263 m_xBeforeSpacing
->set_sensitive(false);
264 m_xAfterSpacing
->set_sensitive(false);
265 m_xFLSpacing
->set_sensitive(false);
269 m_xBeforeSpacing
->set_text("");
270 m_xAfterSpacing
->set_text("");
271 m_xFLSpacing
->set_text("");
275 void ParaLRSpacingWindow::SetUnit(FieldUnit eUnit
)
277 m_xBeforeSpacing
->SetFieldUnit(eUnit
);
278 m_xAfterSpacing
->SetFieldUnit(eUnit
);
279 m_xFLSpacing
->SetFieldUnit(eUnit
);
281 SfxItemPool
&rPool
= SfxGetpApp()->GetPool();
282 m_eUnit
= rPool
.GetMetric(SID_ATTR_PARA_LRSPACE
);
285 IMPL_LINK_NOARG(ParaLRSpacingWindow
, ModifySpacingHdl
, weld::MetricSpinButton
&, void)
287 SfxViewFrame
* pFrame
= SfxViewFrame::Current();
290 SfxDispatcher
* pDisp
= pFrame
->GetBindings().GetDispatcher();
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
));
298 pDisp
->ExecuteList(SID_ATTR_PARA_LRSPACE
, SfxCallMode::RECORD
, {&aMargin
});
302 // ParaLeftSpacingWindow
303 ParaLeftSpacingWindow::ParaLeftSpacingWindow(vcl::Window
* pParent
)
304 : ParaLRSpacingWindow(pParent
)
306 InitControlBase(&m_xBeforeSpacing
->get_widget());
308 m_xBeforeContainer
->show();
309 m_xAfterContainer
->hide();
310 m_xFirstLineContainer
->hide();
312 SetSizePixel(get_preferred_size());
315 // ParaRightSpacingWindow
316 ParaRightSpacingWindow::ParaRightSpacingWindow(vcl::Window
* pParent
)
317 : ParaLRSpacingWindow(pParent
)
319 InitControlBase(&m_xAfterSpacing
->get_widget());
321 m_xBeforeContainer
->hide();
322 m_xAfterContainer
->show();
323 m_xFirstLineContainer
->hide();
325 SetSizePixel(get_preferred_size());
328 // ParaFirstLineSpacingWindow
329 ParaFirstLineSpacingWindow::ParaFirstLineSpacingWindow(vcl::Window
* pParent
)
330 : ParaLRSpacingWindow(pParent
)
332 InitControlBase(&m_xFLSpacing
->get_widget());
334 m_xBeforeContainer
->hide();
335 m_xAfterContainer
->hide();
336 m_xFirstLineContainer
->show();
338 SetSizePixel(get_preferred_size());
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */