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>
32 #include <lineinfo.hxx>
33 #include <linenum.hxx>
34 #include <swmodule.hxx>
36 #include <usrpref.hxx>
38 #include <fmtline.hxx>
39 #include <strings.hrc>
41 #include <IDocumentStylePoolAccess.hxx>
43 static rtl::Reference
<SwDocStyleSheet
> lcl_getDocStyleSheet(const OUString
& rName
, SwWrtShell
*pSh
)
45 SfxStyleSheetBasePool
* pBase
= pSh
->GetView().GetDocShell()->GetStyleSheetPool();
46 SfxStyleSheetBase
* pStyle
= pBase
->Find(rName
, SfxStyleFamily::Para
);
47 SAL_WARN_IF( !pStyle
, "sw.ui", "Style not found" );
50 return new SwDocStyleSheet(*static_cast<SwDocStyleSheet
*>(pStyle
));
53 static void lcl_setLineNumbering(const OUString
& rName
, SwWrtShell
* pSh
, bool bLineNumber
)
55 rtl::Reference
<SwDocStyleSheet
> xStyleSheet
= lcl_getDocStyleSheet(rName
, pSh
);
58 SfxItemSet
& rSet
= xStyleSheet
->GetItemSet();
59 SwFormatLineNumber aFormat
;
60 aFormat
.SetCountLines(bLineNumber
);
62 xStyleSheet
->MergeIndentAttrsOfListStyle( rSet
);
63 xStyleSheet
->SetItemSet(rSet
);
66 SwLineNumberingDlg::SwLineNumberingDlg(const SwView
& rVw
)
67 : SfxDialogController(rVw
.GetViewFrame()->GetWindow().GetFrameWeld(),
68 "modules/swriter/ui/linenumbering.ui", "LineNumberingDialog")
69 , m_pSh(rVw
.GetWrtShellPtr())
70 , m_xBodyContent(m_xBuilder
->weld_widget("content"))
71 , m_xDivIntervalFT(m_xBuilder
->weld_widget("every"))
72 , m_xDivIntervalNF(m_xBuilder
->weld_spin_button("linesspin"))
73 , m_xDivRowsFT(m_xBuilder
->weld_widget("lines"))
74 , m_xNumIntervalNF(m_xBuilder
->weld_spin_button("intervalspin"))
75 , m_xCharStyleLB(m_xBuilder
->weld_combo_box("styledropdown"))
76 , m_xFormatLB(new SwNumberingTypeListBox(m_xBuilder
->weld_combo_box("formatdropdown")))
77 , m_xPosLB(m_xBuilder
->weld_combo_box("positiondropdown"))
78 , m_xOffsetMF(m_xBuilder
->weld_metric_spin_button("spacingspin", FieldUnit::CM
))
79 , m_xDivisorED(m_xBuilder
->weld_entry("textentry"))
80 , m_xCountEmptyLinesCB(m_xBuilder
->weld_check_button("blanklines"))
81 , m_xCountFrameLinesCB(m_xBuilder
->weld_check_button("linesintextframes"))
82 , m_xRestartEachPageCB(m_xBuilder
->weld_check_button("restarteverynewpage"))
83 , m_xNumberingOnCB(m_xBuilder
->weld_check_button("shownumbering"))
84 , m_xNumberingOnFooterHeader(m_xBuilder
->weld_check_button("showfooterheadernumbering"))
85 , m_xOKButton(m_xBuilder
->weld_button("ok"))
86 , m_xNumIntervalFT(m_xBuilder
->weld_widget("interval"))
87 , m_xNumRowsFT(m_xBuilder
->weld_widget("intervallines"))
89 m_xFormatLB
->Reload(SwInsertNumTypes::Extended
);
91 OUString sIntervalName
= m_xDivIntervalFT
->get_accessible_name()
93 + m_xDivRowsFT
->get_accessible_name()
95 m_xDivIntervalNF
->set_accessible_name(sIntervalName
);
97 sIntervalName
= m_xNumIntervalFT
->get_accessible_name()
99 + m_xNumRowsFT
->get_accessible_name()
101 m_xNumIntervalNF
->set_accessible_name(sIntervalName
);
104 ::FillCharStyleListBox(*m_xCharStyleLB
, m_pSh
->GetView().GetDocShell());
106 const SwLineNumberInfo
&rInf
= m_pSh
->GetLineNumberInfo();
107 IDocumentStylePoolAccess
& rIDSPA
= m_pSh
->getIDocumentStylePoolAccess();
109 OUString
sStyleName(rInf
.GetCharFormat( rIDSPA
)->GetName());
110 const int nPos
= m_xCharStyleLB
->find_text(sStyleName
);
113 m_xCharStyleLB
->set_active(nPos
);
116 if (!sStyleName
.isEmpty())
118 m_xCharStyleLB
->append_text(sStyleName
);
119 m_xCharStyleLB
->set_active_text(sStyleName
);
124 SvxNumType nSelFormat
= rInf
.GetNumType().GetNumberingType();
126 m_xFormatLB
->SelectNumberingType(nSelFormat
);
129 m_xPosLB
->set_active(rInf
.GetPos());
132 sal_uInt16 nOffset
= rInf
.GetPosFromLeft();
133 if (nOffset
== USHRT_MAX
)
136 FieldUnit eFieldUnit
= SW_MOD()->GetUsrPref(dynamic_cast< const SwWebDocShell
*>(
137 rVw
.GetDocShell()) != nullptr)->GetMetric();
138 ::SetFieldUnit(*m_xOffsetMF
, eFieldUnit
);
139 m_xOffsetMF
->set_value(m_xOffsetMF
->normalize(nOffset
), FieldUnit::TWIP
);
142 m_xNumIntervalNF
->set_value(rInf
.GetCountBy());
145 m_xDivisorED
->set_text(rInf
.GetDivider());
148 m_xDivIntervalNF
->set_value(rInf
.GetDividerCountBy());
151 m_xCountEmptyLinesCB
->set_active(rInf
.IsCountBlankLines());
152 m_xCountFrameLinesCB
->set_active(rInf
.IsCountInFlys());
153 m_xRestartEachPageCB
->set_active(rInf
.IsRestartEachPage());
155 m_xNumberingOnCB
->set_active(rInf
.IsPaintLineNumbers());
157 // Header/Footer Line Numbering
158 rtl::Reference
< SwDocStyleSheet
> xStyleSheet
= lcl_getDocStyleSheet(SwResId(STR_POOLCOLL_FOOTER
), m_pSh
);
161 SfxItemSet
& rSet
= xStyleSheet
->GetItemSet();
162 const SwFormatLineNumber
&aFormat
= rSet
.Get(RES_LINENUMBER
);
163 if (aFormat
.IsCount())
164 m_xNumberingOnFooterHeader
->set_state(TRISTATE_TRUE
);
166 m_xNumberingOnFooterHeader
->set_state(TRISTATE_FALSE
);
170 m_xNumberingOnCB
->connect_clicked(LINK(this, SwLineNumberingDlg
, LineOnOffHdl
));
171 m_xDivisorED
->connect_changed(LINK(this, SwLineNumberingDlg
, ModifyHdl
));
172 ModifyHdl(*m_xDivisorED
);
173 LineOnOffHdl(*m_xNumberingOnCB
);
175 m_xOKButton
->connect_clicked(LINK(this, SwLineNumberingDlg
, OKHdl
));
178 SwLineNumberingDlg::~SwLineNumberingDlg()
182 IMPL_LINK_NOARG(SwLineNumberingDlg
, OKHdl
, weld::Button
&, void)
184 SwLineNumberInfo
aInf(m_pSh
->GetLineNumberInfo());
187 OUString
sCharFormatName(m_xCharStyleLB
->get_active_text());
188 SwCharFormat
*pCharFormat
= m_pSh
->FindCharFormatByName(sCharFormatName
);
192 SfxStyleSheetBasePool
* pPool
= m_pSh
->GetView().GetDocShell()->GetStyleSheetPool();
193 SfxStyleSheetBase
* pBase
;
194 pBase
= pPool
->Find(sCharFormatName
, SfxStyleFamily::Char
);
196 pBase
= &pPool
->Make(sCharFormatName
, SfxStyleFamily::Char
);
197 pCharFormat
= static_cast<SwDocStyleSheet
*>(pBase
)->GetCharFormat();
201 aInf
.SetCharFormat(pCharFormat
);
205 aType
.SetNumberingType(m_xFormatLB
->GetSelectedNumberingType());
206 aInf
.SetNumType(aType
);
209 aInf
.SetPos(static_cast<LineNumberPosition
>(m_xPosLB
->get_active()));
212 aInf
.SetPosFromLeft(static_cast<sal_uInt16
>(m_xOffsetMF
->denormalize(m_xOffsetMF
->get_value(FieldUnit::TWIP
))));
215 aInf
.SetCountBy(static_cast<sal_uInt16
>(m_xNumIntervalNF
->get_value()));
218 aInf
.SetDivider(m_xDivisorED
->get_text());
221 aInf
.SetDividerCountBy(static_cast<sal_uInt16
>(m_xDivIntervalNF
->get_value()));
224 aInf
.SetCountBlankLines(m_xCountEmptyLinesCB
->get_active());
225 aInf
.SetCountInFlys(m_xCountFrameLinesCB
->get_active());
226 aInf
.SetRestartEachPage(m_xRestartEachPageCB
->get_active());
228 aInf
.SetPaintLineNumbers(m_xNumberingOnCB
->get_active());
230 m_pSh
->SetLineNumberInfo(aInf
);
232 // Set LineNumber explicitly for Header and Footer
233 lcl_setLineNumbering(SwResId(STR_POOLCOLL_FOOTER
), m_pSh
, m_xNumberingOnFooterHeader
->get_active());
234 lcl_setLineNumbering(SwResId(STR_POOLCOLL_HEADER
), m_pSh
, m_xNumberingOnFooterHeader
->get_active());
235 if( m_xNumberingOnFooterHeader
->get_active())
236 m_xNumberingOnFooterHeader
->set_state(TRISTATE_TRUE
);
238 m_xNumberingOnFooterHeader
->set_state(TRISTATE_FALSE
);
240 m_xDialog
->response(RET_OK
);
244 IMPL_LINK_NOARG(SwLineNumberingDlg
, ModifyHdl
, weld::Entry
&, void)
246 bool bEnable
= m_xNumberingOnCB
->get_active() && !m_xDivisorED
->get_text().isEmpty();
248 m_xDivIntervalFT
->set_sensitive(bEnable
);
249 m_xDivIntervalNF
->set_sensitive(bEnable
);
250 m_xDivRowsFT
->set_sensitive(bEnable
);
254 IMPL_LINK_NOARG(SwLineNumberingDlg
, LineOnOffHdl
, weld::Button
&, void)
256 bool bEnable
= m_xNumberingOnCB
->get_active();
257 m_xBodyContent
->set_sensitive(bEnable
);
258 ModifyHdl(*m_xDivisorED
);
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */