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