LibreOffice Module sw (master) 1
linenum.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 <sfx2/viewfrm.hxx>
21#include <svl/style.hxx>
22#include <svtools/unitconv.hxx>
23#include <sal/log.hxx>
24#include <view.hxx>
25#include <wrtsh.hxx>
26#include <docsh.hxx>
27#include <charfmt.hxx>
28
29#include <docstyle.hxx>
30
31#include <lineinfo.hxx>
32#include <linenum.hxx>
33#include <swmodule.hxx>
34#include <uitool.hxx>
35#include <usrpref.hxx>
36#include <wdocsh.hxx>
37#include <fmtline.hxx>
38#include <strings.hrc>
39
41
43{
45 SfxStyleSheetBase* pStyle = pBase->Find(rName, SfxStyleFamily::Para);
46 SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" );
47 if(!pStyle)
48 return nullptr;
49 return new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pStyle));
50}
51
52static void lcl_setLineNumbering(const OUString& rName, SwWrtShell* pSh, bool bLineNumber)
53{
55 if(!xStyleSheet.is())
56 return;
57 SfxItemSet& rSet = xStyleSheet->GetItemSet();
58 SwFormatLineNumber aFormat;
59 aFormat.SetCountLines(bLineNumber);
60 rSet.Put(aFormat);
61 xStyleSheet->MergeIndentAttrsOfListStyle( rSet );
62 xStyleSheet->SetItemSet(rSet);
63}
64
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"))
87{
89
90 OUString sIntervalName = m_xDivIntervalFT->get_accessible_name()
91 + "("
92 + m_xDivRowsFT->get_accessible_name()
93 + ")";
94 m_xDivIntervalNF->set_accessible_name(sIntervalName);
95
96 sIntervalName = m_xNumIntervalFT->get_accessible_name()
97 + "("
98 + m_xNumRowsFT->get_accessible_name()
99 + ")";
100 m_xNumIntervalNF->set_accessible_name(sIntervalName);
101
102 // char styles
104
107
108 OUString sStyleName(rInf.GetCharFormat( rIDSPA )->GetName());
109 const int nPos = m_xCharStyleLB->find_text(sStyleName);
110
111 if (nPos != -1)
112 m_xCharStyleLB->set_active(nPos);
113 else
114 {
115 if (!sStyleName.isEmpty())
116 {
117 m_xCharStyleLB->append_text(sStyleName);
118 m_xCharStyleLB->set_active_text(sStyleName);
119 }
120 }
121
122 // format
123 SvxNumType nSelFormat = rInf.GetNumType().GetNumberingType();
124
125 m_xFormatLB->SelectNumberingType(nSelFormat);
126
127 // position
128 m_xPosLB->set_active(rInf.GetPos());
129
130 // offset
131 sal_uInt16 nOffset = rInf.GetPosFromLeft();
132 if (nOffset == USHRT_MAX)
133 nOffset = 0;
134
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);
139
140 // numbering offset
141 m_xNumIntervalNF->set_value(rInf.GetCountBy());
142
143 // divider
144 m_xDivisorED->set_text(rInf.GetDivider());
145
146 // divider offset
147 m_xDivIntervalNF->set_value(rInf.GetDividerCountBy());
148
149 // count
150 m_xCountEmptyLinesCB->set_active(rInf.IsCountBlankLines());
151 m_xCountFrameLinesCB->set_active(rInf.IsCountInFlys());
152 m_xRestartEachPageCB->set_active(rInf.IsRestartEachPage());
153
154 m_xNumberingOnCB->set_active(rInf.IsPaintLineNumbers());
155
156 // Header/Footer Line Numbering
157 rtl::Reference< SwDocStyleSheet > xStyleSheet = lcl_getDocStyleSheet(SwResId(STR_POOLCOLL_FOOTER), m_pSh);
158 if(xStyleSheet.is())
159 {
160 SfxItemSet& rSet = xStyleSheet->GetItemSet();
161 const SwFormatLineNumber &aFormat = rSet.Get(RES_LINENUMBER);
162 if (aFormat.IsCount())
164 else
166 }
167
168 // Line Numbering
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);
173
174 m_xOKButton->connect_clicked(LINK(this, SwLineNumberingDlg, OKHdl));
175}
176
178{
179}
180
182{
183 SwLineNumberInfo aInf(m_pSh->GetLineNumberInfo());
184
185 // char styles
186 OUString sCharFormatName(m_xCharStyleLB->get_active_text());
187 SwCharFormat *pCharFormat = m_pSh->FindCharFormatByName(sCharFormatName);
188
189 if (!pCharFormat)
190 {
191 SfxStyleSheetBasePool* pPool = m_pSh->GetView().GetDocShell()->GetStyleSheetPool();
192 SfxStyleSheetBase* pBase;
193 pBase = pPool->Find(sCharFormatName, SfxStyleFamily::Char);
194 if(!pBase)
195 pBase = &pPool->Make(sCharFormatName, SfxStyleFamily::Char);
196 pCharFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat();
197 }
198
199 if (pCharFormat)
200 aInf.SetCharFormat(pCharFormat);
201
202 // format
203 SvxNumberType aType;
204 aType.SetNumberingType(m_xFormatLB->GetSelectedNumberingType());
205 aInf.SetNumType(aType);
206
207 // position
208 aInf.SetPos(static_cast<LineNumberPosition>(m_xPosLB->get_active()));
209
210 // offset
211 aInf.SetPosFromLeft(o3tl::narrowing<sal_uInt16>(m_xOffsetMF->denormalize(m_xOffsetMF->get_value(FieldUnit::TWIP))));
212
213 // numbering offset
214 aInf.SetCountBy(o3tl::narrowing<sal_uInt16>(m_xNumIntervalNF->get_value()));
215
216 // divider
217 aInf.SetDivider(m_xDivisorED->get_text());
218
219 // divider offset
220 aInf.SetDividerCountBy(o3tl::narrowing<sal_uInt16>(m_xDivIntervalNF->get_value()));
221
222 // count
223 aInf.SetCountBlankLines(m_xCountEmptyLinesCB->get_active());
224 aInf.SetCountInFlys(m_xCountFrameLinesCB->get_active());
225 aInf.SetRestartEachPage(m_xRestartEachPageCB->get_active());
226
227 aInf.SetPaintLineNumbers(m_xNumberingOnCB->get_active());
228
229 m_pSh->SetLineNumberInfo(aInf);
230
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);
236 else
237 m_xNumberingOnFooterHeader->set_state(TRISTATE_FALSE);
238
239 m_xDialog->response(RET_OK);
240}
241
242// modify
244{
245 bool bEnable = m_xNumberingOnCB->get_active() && !m_xDivisorED->get_text().isEmpty();
246
247 m_xDivIntervalFT->set_sensitive(bEnable);
248 m_xDivIntervalNF->set_sensitive(bEnable);
249 m_xDivRowsFT->set_sensitive(bEnable);
250}
251
252// On/Off
254{
255 bool bEnable = m_xNumberingOnCB->get_active();
256 m_xBodyContent->set_sensitive(bEnable);
257 ModifyHdl(*m_xDivisorED);
258}
259
260/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
Access to the style pool.
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
virtual SfxStyleSheetBase & Make(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits nMask=SfxStyleSearchBits::All)
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
void SetNumberingType(SvxNumType nSet)
SvxNumType GetNumberingType() const
Represents the style of a text portion.
Definition: charfmt.hxx:27
virtual SfxStyleSheetBasePool * GetStyleSheetPool() override
For Style PI.
Definition: docsh.cxx:1152
const SwLineNumberInfo & GetLineNumberInfo() const
Definition: editsh.cxx:928
Contains the line numbering properties of this paragraph.
Definition: fmtline.hxx:33
bool IsCount() const
Definition: fmtline.hxx:60
void SetCountLines(bool b)
Definition: fmtline.hxx:63
const OUString & GetName() const
Definition: format.hxx:131
< purpose of derivation from SwClient: character style for displaying the numbers.
Definition: lineinfo.hxx:39
void SetPaintLineNumbers(bool b)
Definition: lineinfo.hxx:81
void SetPos(LineNumberPosition eP)
Definition: lineinfo.hxx:78
const OUString & GetDivider() const
Definition: lineinfo.hxx:66
void SetDividerCountBy(sal_uInt16 n)
Definition: lineinfo.hxx:69
sal_uInt16 GetCountBy() const
Definition: lineinfo.hxx:74
const SvxNumberType & GetNumType() const
Definition: lineinfo.hxx:63
void SetDivider(const OUString &r)
Definition: lineinfo.hxx:67
bool IsRestartEachPage() const
Definition: lineinfo.hxx:89
void SetCharFormat(SwCharFormat *)
Definition: lineinfo.cxx:109
void SetCountBlankLines(bool b)
Definition: lineinfo.hxx:84
SwCharFormat * GetCharFormat(IDocumentStylePoolAccess &rIDSPA) const
Definition: lineinfo.cxx:99
void SetRestartEachPage(bool b)
Definition: lineinfo.hxx:90
bool IsPaintLineNumbers() const
Definition: lineinfo.hxx:80
void SetNumType(SvxNumberType aNew)
Definition: lineinfo.hxx:64
void SetCountBy(sal_uInt16 n)
Definition: lineinfo.hxx:75
bool IsCountBlankLines() const
Definition: lineinfo.hxx:83
void SetPosFromLeft(sal_uInt16 n)
Definition: lineinfo.hxx:72
sal_uInt16 GetPosFromLeft() const
Definition: lineinfo.hxx:71
bool IsCountInFlys() const
Definition: lineinfo.hxx:86
sal_uInt16 GetDividerCountBy() const
Definition: lineinfo.hxx:68
void SetCountInFlys(bool b)
Definition: lineinfo.hxx:87
LineNumberPosition GetPos() const
Definition: lineinfo.hxx:77
std::unique_ptr< weld::CheckButton > m_xCountFrameLinesCB
Definition: linenum.hxx:43
std::unique_ptr< weld::Widget > m_xDivRowsFT
Definition: linenum.hxx:35
std::unique_ptr< weld::Widget > m_xDivIntervalFT
Definition: linenum.hxx:33
virtual ~SwLineNumberingDlg() override
Definition: linenum.cxx:177
std::unique_ptr< weld::SpinButton > m_xNumIntervalNF
Definition: linenum.hxx:36
std::unique_ptr< weld::Button > m_xOKButton
Definition: linenum.hxx:47
SwLineNumberingDlg(const SwView &rVw)
Definition: linenum.cxx:65
std::unique_ptr< weld::CheckButton > m_xNumberingOnCB
Definition: linenum.hxx:45
std::unique_ptr< SwNumberingTypeListBox > m_xFormatLB
Definition: linenum.hxx:38
std::unique_ptr< weld::Widget > m_xNumRowsFT
Definition: linenum.hxx:49
std::unique_ptr< weld::CheckButton > m_xCountEmptyLinesCB
Definition: linenum.hxx:42
std::unique_ptr< weld::ComboBox > m_xPosLB
Definition: linenum.hxx:39
std::unique_ptr< weld::SpinButton > m_xDivIntervalNF
Definition: linenum.hxx:34
SwWrtShell * m_pSh
Definition: linenum.hxx:31
std::unique_ptr< weld::MetricSpinButton > m_xOffsetMF
Definition: linenum.hxx:40
std::unique_ptr< weld::Entry > m_xDivisorED
Definition: linenum.hxx:41
std::unique_ptr< weld::CheckButton > m_xRestartEachPageCB
Definition: linenum.hxx:44
std::unique_ptr< weld::Widget > m_xNumIntervalFT
Definition: linenum.hxx:48
std::unique_ptr< weld::ComboBox > m_xCharStyleLB
Definition: linenum.hxx:37
std::unique_ptr< weld::CheckButton > m_xNumberingOnFooterHeader
Definition: linenum.hxx:46
IDocumentStylePoolAccess & getIDocumentStylePoolAccess()
Provides access to the document style pool interface.
Definition: viewsh.cxx:2830
Definition: view.hxx:146
SwDocShell * GetDocShell()
Definition: view.cxx:1193
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
const SwView & GetView() const
Definition: wrtsh.hxx:443
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:19
FieldUnit
TRISTATE_FALSE
TRISTATE_TRUE
constexpr TypedWhichId< SwFormatLineNumber > RES_LINENUMBER(122)
std::unique_ptr< weld::Button > m_xOKButton
LineNumberPosition
Definition: lineinfo.hxx:30
IMPL_LINK_NOARG(SwLineNumberingDlg, OKHdl, weld::Button &, void)
Definition: linenum.cxx:181
static rtl::Reference< SwDocStyleSheet > lcl_getDocStyleSheet(const OUString &rName, SwWrtShell *pSh)
Definition: linenum.cxx:42
static void lcl_setLineNumbering(const OUString &rName, SwWrtShell *pSh, bool bLineNumber)
Definition: linenum.cxx:52
sal_uInt16 nPos
#define SAL_WARN_IF(condition, area, stream)
static SfxItemSet & rSet
SvxNumType
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
#define SW_MOD()
Definition: swmodule.hxx:254
SW_DLLPUBLIC void FillCharStyleListBox(weld::ComboBox &rToFill, SwDocShell *pDocSh, bool bSorted=false, bool bWithDefault=false)
Definition: uitool.cxx:781
RET_OK