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 <sfx2/viewfrm.hxx>
21 #include <svl/style.hxx>
22 #include <svtools/unitconv.hxx>
23 #include <sal/log.hxx>
27 #include <charfmt.hxx>
29 #include <docstyle.hxx>
31 #include <lineinfo.hxx>
32 #include <linenum.hxx>
33 #include <swmodule.hxx>
35 #include <usrpref.hxx>
37 #include <fmtline.hxx>
38 #include <strings.hrc>
40 #include <IDocumentStylePoolAccess.hxx>
42 static rtl::Reference
<SwDocStyleSheet
> lcl_getDocStyleSheet(const OUString
& rName
, SwWrtShell
*pSh
)
44 SfxStyleSheetBasePool
* pBase
= pSh
->GetView().GetDocShell()->GetStyleSheetPool();
45 SfxStyleSheetBase
* pStyle
= pBase
->Find(rName
, SfxStyleFamily::Para
);
46 SAL_WARN_IF( !pStyle
, "sw.ui", "Style not found" );
49 return new SwDocStyleSheet(*static_cast<SwDocStyleSheet
*>(pStyle
));
52 static void lcl_setLineNumbering(const OUString
& rName
, SwWrtShell
* pSh
, bool bLineNumber
)
54 rtl::Reference
<SwDocStyleSheet
> xStyleSheet
= lcl_getDocStyleSheet(rName
, pSh
);
57 SfxItemSet
& rSet
= xStyleSheet
->GetItemSet();
58 SwFormatLineNumber aFormat
;
59 aFormat
.SetCountLines(bLineNumber
);
61 xStyleSheet
->MergeIndentAttrsOfListStyle( rSet
);
62 xStyleSheet
->SetItemSet(rSet
);
65 SwLineNumberingDlg::SwLineNumberingDlg(const SwView
& rVw
)
66 : SfxDialogController(rVw
.GetViewFrame().GetFrameWeld(),
67 "modules/swriter/ui/linenumbering.ui", "LineNumberingDialog")
68 , m_pSh(rVw
.GetWrtShellPtr())
69 , m_xBodyContent(m_xBuilder
->weld_widget("content"))
70 , m_xDivIntervalFT(m_xBuilder
->weld_widget("every"))
71 , m_xDivIntervalNF(m_xBuilder
->weld_spin_button("linesspin"))
72 , m_xDivRowsFT(m_xBuilder
->weld_widget("lines"))
73 , m_xNumIntervalNF(m_xBuilder
->weld_spin_button("intervalspin"))
74 , m_xCharStyleLB(m_xBuilder
->weld_combo_box("styledropdown"))
75 , m_xFormatLB(new SwNumberingTypeListBox(m_xBuilder
->weld_combo_box("formatdropdown")))
76 , m_xPosLB(m_xBuilder
->weld_combo_box("positiondropdown"))
77 , m_xOffsetMF(m_xBuilder
->weld_metric_spin_button("spacingspin", FieldUnit::CM
))
78 , m_xDivisorED(m_xBuilder
->weld_entry("textentry"))
79 , m_xCountEmptyLinesCB(m_xBuilder
->weld_check_button("blanklines"))
80 , m_xCountFrameLinesCB(m_xBuilder
->weld_check_button("linesintextframes"))
81 , m_xRestartEachPageCB(m_xBuilder
->weld_check_button("restarteverynewpage"))
82 , m_xNumberingOnCB(m_xBuilder
->weld_check_button("shownumbering"))
83 , m_xNumberingOnFooterHeader(m_xBuilder
->weld_check_button("showfooterheadernumbering"))
84 , m_xOKButton(m_xBuilder
->weld_button("ok"))
85 , m_xNumIntervalFT(m_xBuilder
->weld_widget("interval"))
86 , m_xNumRowsFT(m_xBuilder
->weld_widget("intervallines"))
88 m_xFormatLB
->Reload(SwInsertNumTypes::Extended
);
90 OUString sIntervalName
= m_xDivIntervalFT
->get_accessible_name()
92 + m_xDivRowsFT
->get_accessible_name()
94 m_xDivIntervalNF
->set_accessible_name(sIntervalName
);
96 sIntervalName
= m_xNumIntervalFT
->get_accessible_name()
98 + m_xNumRowsFT
->get_accessible_name()
100 m_xNumIntervalNF
->set_accessible_name(sIntervalName
);
103 ::FillCharStyleListBox(*m_xCharStyleLB
, m_pSh
->GetView().GetDocShell());
105 const SwLineNumberInfo
&rInf
= m_pSh
->GetLineNumberInfo();
106 IDocumentStylePoolAccess
& rIDSPA
= m_pSh
->getIDocumentStylePoolAccess();
108 OUString
sStyleName(rInf
.GetCharFormat( rIDSPA
)->GetName());
109 const int nPos
= m_xCharStyleLB
->find_text(sStyleName
);
112 m_xCharStyleLB
->set_active(nPos
);
115 if (!sStyleName
.isEmpty())
117 m_xCharStyleLB
->append_text(sStyleName
);
118 m_xCharStyleLB
->set_active_text(sStyleName
);
123 SvxNumType nSelFormat
= rInf
.GetNumType().GetNumberingType();
125 m_xFormatLB
->SelectNumberingType(nSelFormat
);
128 m_xPosLB
->set_active(rInf
.GetPos());
131 sal_uInt16 nOffset
= rInf
.GetPosFromLeft();
132 if (nOffset
== USHRT_MAX
)
135 FieldUnit eFieldUnit
= SW_MOD()->GetUsrPref(dynamic_cast< const SwWebDocShell
*>(
136 rVw
.GetDocShell()) != nullptr)->GetMetric();
137 ::SetFieldUnit(*m_xOffsetMF
, eFieldUnit
);
138 m_xOffsetMF
->set_value(m_xOffsetMF
->normalize(nOffset
), FieldUnit::TWIP
);
141 m_xNumIntervalNF
->set_value(rInf
.GetCountBy());
144 m_xDivisorED
->set_text(rInf
.GetDivider());
147 m_xDivIntervalNF
->set_value(rInf
.GetDividerCountBy());
150 m_xCountEmptyLinesCB
->set_active(rInf
.IsCountBlankLines());
151 m_xCountFrameLinesCB
->set_active(rInf
.IsCountInFlys());
152 m_xRestartEachPageCB
->set_active(rInf
.IsRestartEachPage());
154 m_xNumberingOnCB
->set_active(rInf
.IsPaintLineNumbers());
156 // Header/Footer Line Numbering
157 rtl::Reference
< SwDocStyleSheet
> xStyleSheet
= lcl_getDocStyleSheet(SwResId(STR_POOLCOLL_FOOTER
), m_pSh
);
160 SfxItemSet
& rSet
= xStyleSheet
->GetItemSet();
161 const SwFormatLineNumber
&aFormat
= rSet
.Get(RES_LINENUMBER
);
162 if (aFormat
.IsCount())
163 m_xNumberingOnFooterHeader
->set_state(TRISTATE_TRUE
);
165 m_xNumberingOnFooterHeader
->set_state(TRISTATE_FALSE
);
169 m_xNumberingOnCB
->connect_toggled(LINK(this, SwLineNumberingDlg
, LineOnOffHdl
));
170 m_xDivisorED
->connect_changed(LINK(this, SwLineNumberingDlg
, ModifyHdl
));
171 ModifyHdl(*m_xDivisorED
);
172 LineOnOffHdl(*m_xNumberingOnCB
);
174 m_xOKButton
->connect_clicked(LINK(this, SwLineNumberingDlg
, OKHdl
));
177 SwLineNumberingDlg::~SwLineNumberingDlg()
181 IMPL_LINK_NOARG(SwLineNumberingDlg
, OKHdl
, weld::Button
&, void)
183 SwLineNumberInfo
aInf(m_pSh
->GetLineNumberInfo());
186 OUString
sCharFormatName(m_xCharStyleLB
->get_active_text());
187 SwCharFormat
*pCharFormat
= m_pSh
->FindCharFormatByName(sCharFormatName
);
191 SfxStyleSheetBasePool
* pPool
= m_pSh
->GetView().GetDocShell()->GetStyleSheetPool();
192 SfxStyleSheetBase
* pBase
;
193 pBase
= pPool
->Find(sCharFormatName
, SfxStyleFamily::Char
);
195 pBase
= &pPool
->Make(sCharFormatName
, SfxStyleFamily::Char
);
196 pCharFormat
= static_cast<SwDocStyleSheet
*>(pBase
)->GetCharFormat();
200 aInf
.SetCharFormat(pCharFormat
);
204 aType
.SetNumberingType(m_xFormatLB
->GetSelectedNumberingType());
205 aInf
.SetNumType(aType
);
208 aInf
.SetPos(static_cast<LineNumberPosition
>(m_xPosLB
->get_active()));
211 aInf
.SetPosFromLeft(o3tl::narrowing
<sal_uInt16
>(m_xOffsetMF
->denormalize(m_xOffsetMF
->get_value(FieldUnit::TWIP
))));
214 aInf
.SetCountBy(o3tl::narrowing
<sal_uInt16
>(m_xNumIntervalNF
->get_value()));
217 aInf
.SetDivider(m_xDivisorED
->get_text());
220 aInf
.SetDividerCountBy(o3tl::narrowing
<sal_uInt16
>(m_xDivIntervalNF
->get_value()));
223 aInf
.SetCountBlankLines(m_xCountEmptyLinesCB
->get_active());
224 aInf
.SetCountInFlys(m_xCountFrameLinesCB
->get_active());
225 aInf
.SetRestartEachPage(m_xRestartEachPageCB
->get_active());
227 aInf
.SetPaintLineNumbers(m_xNumberingOnCB
->get_active());
229 m_pSh
->SetLineNumberInfo(aInf
);
231 // Set LineNumber explicitly for Header and Footer
232 lcl_setLineNumbering(SwResId(STR_POOLCOLL_FOOTER
), m_pSh
, m_xNumberingOnFooterHeader
->get_active());
233 lcl_setLineNumbering(SwResId(STR_POOLCOLL_HEADER
), m_pSh
, m_xNumberingOnFooterHeader
->get_active());
234 if( m_xNumberingOnFooterHeader
->get_active())
235 m_xNumberingOnFooterHeader
->set_state(TRISTATE_TRUE
);
237 m_xNumberingOnFooterHeader
->set_state(TRISTATE_FALSE
);
239 m_xDialog
->response(RET_OK
);
243 IMPL_LINK_NOARG(SwLineNumberingDlg
, ModifyHdl
, weld::Entry
&, void)
245 bool bEnable
= m_xNumberingOnCB
->get_active() && !m_xDivisorED
->get_text().isEmpty();
247 m_xDivIntervalFT
->set_sensitive(bEnable
);
248 m_xDivIntervalNF
->set_sensitive(bEnable
);
249 m_xDivRowsFT
->set_sensitive(bEnable
);
253 IMPL_LINK_NOARG(SwLineNumberingDlg
, LineOnOffHdl
, weld::Toggleable
&, void)
255 bool bEnable
= m_xNumberingOnCB
->get_active();
256 m_xBodyContent
->set_sensitive(bEnable
);
257 ModifyHdl(*m_xDivisorED
);
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */