LibreOffice Module sw (master)  1
numpara.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 <cmdid.h>
21 #include <swtypes.hxx>
22 #include <hintids.hxx>
23 #include <strings.hrc>
24 #include <sfx2/objsh.hxx>
25 #include <sfx2/htmlmode.hxx>
26 #include <svl/eitem.hxx>
27 #include <svl/stritem.hxx>
28 #include <svl/intitem.hxx>
29 #include <fmtline.hxx>
30 #include <numpara.hxx>
31 
32 #include <sfx2/dispatch.hxx>
33 #include <sfx2/viewsh.hxx>
34 
35 const WhichRangesContainer SwParagraphNumTabPage::aPageRg(svl::Items<FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART_AT>);
36 
38  : SfxTabPage(pPage, pController, "modules/swriter/ui/numparapage.ui", "NumParaPage", &rAttr)
39  , msOutlineNumbering(SwResId(STR_OUTLINE_NUMBERING ))
40  , bModified(false)
41  , bCurNumrule(false)
42  , m_xOutlineStartBX(m_xBuilder->weld_widget("boxOUTLINE"))
43  , m_xOutlineLvLB(m_xBuilder->weld_combo_box("comboLB_OUTLINE_LEVEL"))
44  , m_xNumberStyleBX(m_xBuilder->weld_widget("boxNUMBER_STYLE"))
45  , m_xNumberStyleLB(m_xBuilder->weld_combo_box("comboLB_NUMBER_STYLE"))
46  , m_xEditNumStyleBtn(m_xBuilder->weld_button("editnumstyle"))
47  , m_xNewStartCB(m_xBuilder->weld_check_button("checkCB_NEW_START"))
48  , m_xNewStartBX(m_xBuilder->weld_widget("boxNEW_START"))
49  , m_xNewStartNumberCB(m_xBuilder->weld_check_button("checkCB_NUMBER_NEW_START"))
50  , m_xNewStartNF(m_xBuilder->weld_spin_button("spinNF_NEW_START"))
51  , m_xCountParaFram(m_xBuilder->weld_widget("frameFL_COUNT_PARA"))
52  , m_xCountParaCB(m_xBuilder->weld_check_button("checkCB_COUNT_PARA"))
53  , m_xRestartParaCountCB(m_xBuilder->weld_check_button("checkCB_RESTART_PARACOUNT"))
54  , m_xRestartBX(m_xBuilder->weld_widget("boxRESTART_NO"))
55  , m_xRestartNF(m_xBuilder->weld_spin_button("spinNF_RESTART_PARA"))
56 {
57  m_xNewStartCB->set_state(TRISTATE_FALSE);
59  m_xCountParaCB->set_state(TRISTATE_FALSE);
61  m_xEditNumStyleBtn->set_sensitive(false);
62 
63  const SfxPoolItem* pItem;
64  SfxObjectShell* pObjSh;
65  if(SfxItemState::SET == rAttr.GetItemState(SID_HTML_MODE, false, &pItem) ||
66  ( nullptr != ( pObjSh = SfxObjectShell::Current()) &&
67  nullptr != (pItem = pObjSh->GetItem(SID_HTML_MODE))))
68  {
69  const sal_uInt16 nHtmlMode = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
70 
71  if (HTMLMODE_ON & nHtmlMode)
72  m_xCountParaFram->hide();
73  }
74 
75  m_xNewStartCB->connect_toggled(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
76  m_xNewStartNumberCB->connect_toggled(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
77  m_xNumberStyleLB->connect_changed(LINK(this, SwParagraphNumTabPage, StyleHdl_Impl));
78  m_xCountParaCB->connect_toggled(LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
79  m_xRestartParaCountCB->connect_toggled(LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
80  m_xNumberStyleLB->connect_changed(LINK(this, SwParagraphNumTabPage, EditNumStyleSelectHdl_Impl));
81  m_xEditNumStyleBtn->connect_clicked(LINK(this, SwParagraphNumTabPage, EditNumStyleHdl_Impl));
82 }
83 
85 {
86 }
87 
88 std::unique_ptr<SfxTabPage> SwParagraphNumTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
89 {
90  return std::make_unique<SwParagraphNumTabPage>(pPage, pController, *rSet);
91 }
92 
94 {
95  if (m_xOutlineLvLB->get_value_changed_from_saved())
96  {
97  const sal_uInt16 aOutlineLv = m_xOutlineLvLB->get_active();
98  const SfxUInt16Item* pOldOutlineLv = static_cast<const SfxUInt16Item*>(GetOldItem( *rSet, SID_ATTR_PARA_OUTLINE_LEVEL));
99  if (pOldOutlineLv)
100  {
101  std::unique_ptr<SfxUInt16Item> pOutlineLv(pOldOutlineLv->Clone());
102  pOutlineLv->SetValue( aOutlineLv );
103  rSet->Put(std::move(pOutlineLv));
104  bModified = true;
105  }
106  }
107 
108  if (m_xNumberStyleLB->get_value_changed_from_saved())
109  {
110  OUString aStyle;
111  if (m_xNumberStyleLB->get_active())
112  aStyle = m_xNumberStyleLB->get_active_text();
113  const SfxStringItem* pOldRule = static_cast<const SfxStringItem*>(GetOldItem( *rSet, SID_ATTR_PARA_NUMRULE));
114  if (pOldRule)
115  {
116  std::unique_ptr<SfxStringItem> pRule(pOldRule->Clone());
117  pRule->SetValue(aStyle);
118  rSet->Put(std::move(pRule));
119  bModified = true;
120  }
121  }
122  if (m_xNewStartCB->get_state_changed_from_saved() ||
123  m_xNewStartNumberCB->get_state_changed_from_saved()||
124  m_xNewStartNF->get_value_changed_from_saved())
125  {
126  bModified = true;
127  bool bNewStartChecked = TRISTATE_TRUE == m_xNewStartCB->get_state();
128  bool bNumberNewStartChecked = TRISTATE_TRUE == m_xNewStartNumberCB->get_state();
129  rSet->Put(SfxBoolItem(FN_NUMBER_NEWSTART, bNewStartChecked));
131  bNumberNewStartChecked && bNewStartChecked ? o3tl::narrowing<sal_uInt16>(m_xNewStartNF->get_value()) : USHRT_MAX));
132  }
133 
134  if (m_xCountParaCB->get_state_changed_from_saved()||
135  m_xRestartParaCountCB->get_state_changed_from_saved() ||
136  m_xRestartNF->get_value_changed_from_saved())
137  {
138  SwFormatLineNumber aFormat;
139  aFormat.SetStartValue( static_cast< sal_uLong >(m_xRestartParaCountCB->get_state() == TRISTATE_TRUE ?
140  m_xRestartNF->get_value() : 0 ));
141  aFormat.SetCountLines(m_xCountParaCB->get_active());
142  rSet->Put(aFormat);
143  bModified = true;
144  }
145  return bModified;
146 }
147 
149 {
150  m_xOutlineLvLB->save_value();
151  m_xNumberStyleLB->save_value();
152  m_xNewStartCB->save_state();
153  m_xNewStartNumberCB->save_state();
154  m_xCountParaCB->save_state();
155  m_xRestartParaCountCB->save_state();
156  m_xRestartNF->save_value();
157 }
158 
160 {
161  bool bHasNumberStyle = false;
162 
163  SfxItemState eItemState = rSet->GetItemState( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) );
164 
165  if( eItemState >= SfxItemState::DEFAULT )
166  {
167  sal_Int16 nOutlineLv = static_cast<const SfxUInt16Item &>(rSet->Get( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) )).GetValue();
168  m_xOutlineLvLB->set_active(nOutlineLv) ;
169  }
170  else
171  {
172  m_xOutlineLvLB->set_active(-1);
173  }
174  m_xOutlineLvLB->save_value();
175 
176  eItemState = rSet->GetItemState( GetWhich(SID_ATTR_PARA_NUMRULE) );
177 
178  if( eItemState >= SfxItemState::DEFAULT )
179  {
180  OUString aStyle = static_cast<const SfxStringItem &>(rSet->Get( GetWhich(SID_ATTR_PARA_NUMRULE) )).GetValue();
181  if(aStyle.isEmpty())
182  aStyle = m_xNumberStyleLB->get_text(0);
183 
184  if( aStyle == "Outline")
185  {
186  //add it, select it, remove it ? do we really want set_active(-1) instead ?
187  m_xNumberStyleLB->append_text(msOutlineNumbering);
188  m_xNumberStyleLB->set_active_text(msOutlineNumbering);
189  m_xNumberStyleLB->remove_text(msOutlineNumbering);
190  m_xNumberStyleLB->save_value();
191  }
192  else
193  m_xNumberStyleLB->set_active_text(aStyle);
194 
195  bHasNumberStyle = true;
196  }
197  else
198  {
199  m_xNumberStyleLB->set_active(-1);
200  }
201 
202  EditNumStyleSelectHdl_Impl(*m_xNumberStyleLB);
203 
204  m_xNumberStyleLB->save_value();
205 
206  eItemState = rSet->GetItemState( FN_NUMBER_NEWSTART );
207  if(eItemState > SfxItemState::DEFAULT )
208  {
209  bCurNumrule = true;
210  const SfxBoolItem& rStart = static_cast<const SfxBoolItem&>(rSet->Get(FN_NUMBER_NEWSTART));
211 
212  m_xNewStartCB->set_state(rStart.GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
213  }
214  else
215  m_xNewStartCB->set_state(bHasNumberStyle ? TRISTATE_FALSE : TRISTATE_INDET);
216 
217  m_xNewStartCB->save_state();
218 
219  eItemState = rSet->GetItemState( FN_NUMBER_NEWSTART_AT);
220  if( eItemState > SfxItemState::DEFAULT )
221  {
222  const sal_uInt16 nNewStart = static_cast<const SfxUInt16Item&>(rSet->Get(FN_NUMBER_NEWSTART_AT)).GetValue();
223  const bool bNotMax = USHRT_MAX != nNewStart;
224  m_xNewStartNumberCB->set_active(bNotMax);
225  m_xNewStartNF->set_value(bNotMax ? nNewStart : 1);
226  }
227  else
228  m_xNewStartCB->set_state(TRISTATE_INDET);
229  NewStartHdl_Impl(*m_xNewStartCB);
230  m_xNewStartNF->save_value();
231  m_xNewStartNumberCB->save_state();
232  StyleHdl_Impl(*m_xNumberStyleLB);
233  if( SfxItemState::DEFAULT <= rSet->GetItemState(RES_LINENUMBER))
234  {
235  const SwFormatLineNumber& rNum = rSet->Get(RES_LINENUMBER);
236  sal_uLong nStartValue = rNum.GetStartValue();
237  bool bCount = rNum.IsCount();
238  m_xCountParaCB->set_state(bCount ? TRISTATE_TRUE : TRISTATE_FALSE);
239  m_xRestartParaCountCB->set_state(0 != nStartValue ? TRISTATE_TRUE : TRISTATE_FALSE);
240  m_xRestartNF->set_value(nStartValue == 0 ? 1 : nStartValue);
241  LineCountHdl_Impl(*m_xCountParaCB);
242  }
243  else
244  {
245  m_xCountParaCB->set_state(TRISTATE_INDET);
246  m_xRestartParaCountCB->set_state(TRISTATE_INDET);
247  }
248  m_xCountParaCB->save_state();
249  m_xRestartParaCountCB->save_state();
250  m_xRestartNF->save_value();
251 
252  bModified = false;
253 }
254 
256 {
257  m_xOutlineStartBX->set_sensitive(false);
258  m_xOutlineStartBX->set_tooltip_text( SwResId(STR_OUTLINENUMBERING_DISABLED) );
259 }
260 
262 {
263  m_xNumberStyleBX->set_sensitive(false);
264  m_xNumberStyleBX->set_tooltip_text( SwResId(STR_OUTLINENUMBERING_DISABLED) );
265 }
266 
268 {
269  m_xNewStartCB->show();
270  m_xNewStartBX->show();
271 }
272 
274 {
275  bool bEnable = m_xNewStartCB->get_active();
276  m_xNewStartNumberCB->set_sensitive(bEnable);
277  m_xNewStartNF->set_sensitive(bEnable && m_xNewStartNumberCB->get_active());
278 }
279 
281 {
282  m_xRestartParaCountCB->set_sensitive(m_xCountParaCB->get_active());
283 
284  bool bEnableRestartValue = m_xRestartParaCountCB->get_sensitive() &&
285  m_xRestartParaCountCB->get_active();
286  m_xRestartBX->set_sensitive(bEnableRestartValue);
287 }
288 
289 IMPL_LINK_NOARG(SwParagraphNumTabPage, EditNumStyleSelectHdl_Impl, weld::ComboBox&, void)
290 {
291  int numSelectPos = m_xNumberStyleLB->get_active();
292  // 0 is "None" and -1 is unselected state
293  if (numSelectPos == 0 || numSelectPos == -1)
294  m_xEditNumStyleBtn->set_sensitive(false);
295  else
296  m_xEditNumStyleBtn->set_sensitive(true);
297 }
298 
299 IMPL_LINK_NOARG(SwParagraphNumTabPage, EditNumStyleHdl_Impl, weld::Button&, void)
300 {
301  OUString aTemplName(m_xNumberStyleLB->get_active_text());
302  ExecuteEditNumStyle_Impl( SID_STYLE_EDIT, aTemplName, SfxStyleFamily::Pseudo );
303 }
304 
305 // Internal: Perform functions through the Dispatcher
307  sal_uInt16 nId, const OUString &rStr, SfxStyleFamily nFamily)
308 {
309 
311  SfxStringItem aItem(nId, rStr);
312  SfxUInt16Item aFamily(SID_STYLE_FAMILY, static_cast<sal_uInt16>(nFamily));
313  const SfxPoolItem* pItems[ 3 ];
314  sal_uInt16 nCount = 0;
315  if( !rStr.isEmpty() )
316  pItems[ nCount++ ] = &aItem;
317  pItems[ nCount++ ] = &aFamily;
318 
319  pItems[ nCount++ ] = nullptr;
320 
321  const SfxPoolItem* pItem = rDispatcher.Execute(
322  nId, SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
323  pItems );
324 
325  return pItem != nullptr;
326 
327 }
328 
329 IMPL_LINK(SwParagraphNumTabPage, StyleHdl_Impl, weld::ComboBox&, rBox, void)
330 {
331  bool bEnable = bCurNumrule || rBox.get_active() > 0;
332  m_xNewStartCB->set_sensitive(bEnable);
333  NewStartHdl_Impl(*m_xNewStartCB);
334 }
335 
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool GetValue() const
virtual ~SwParagraphNumTabPage() override
Definition: numpara.cxx:84
std::unique_ptr< weld::SpinButton > m_xNewStartNF
Definition: numpara.hxx:44
std::unique_ptr< weld::Button > m_xEditNumStyleBtn
Definition: numpara.hxx:39
std::string GetValue
std::unique_ptr< weld::Widget > m_xCountParaFram
Definition: numpara.hxx:46
std::unique_ptr< weld::Widget > m_xNewStartBX
Definition: numpara.hxx:42
std::unique_ptr< weld::CheckButton > m_xNewStartCB
Definition: numpara.hxx:41
sal_uIntPtr sal_uLong
virtual void Reset(const SfxItemSet *rSet) override
Definition: numpara.cxx:159
static SfxObjectShell * Current()
std::unique_ptr< weld::CheckButton > m_xCountParaCB
Definition: numpara.hxx:47
TRISTATE_TRUE
void SetValue(sal_uInt16 nTheValue)
const OUString msOutlineNumbering
Definition: numpara.hxx:30
static const WhichRangesContainer aPageRg
Definition: numpara.hxx:59
void SetValue(const OUString &rTheValue)
int nCount
static SfxViewShell * Current()
virtual SfxStringItem * Clone(SfxItemPool *=nullptr) const override
sal_uLong GetStartValue() const
Definition: fmtline.hxx:57
SfxStyleFamily
virtual void ChangesApplied() override
Definition: numpara.cxx:148
TRISTATE_INDET
std::unique_ptr< weld::Widget > m_xNumberStyleBX
Definition: numpara.hxx:37
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
const SfxPoolItem * GetOldItem(const SfxItemSet &rSet, sal_uInt16 nSlot, bool bDeep=true)
std::unique_ptr< weld::ComboBox > m_xOutlineLvLB
Definition: numpara.hxx:36
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
SfxDispatcher * GetDispatcher() const
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: numpara.cxx:93
std::unique_ptr< weld::Widget > m_xOutlineStartBX
Definition: numpara.hxx:35
TRISTATE_FALSE
HTMLMODE_ON
std::unique_ptr< weld::CheckButton > m_xNewStartNumberCB
Definition: numpara.hxx:43
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: numpara.cxx:88
void SetCountLines(bool b)
Definition: fmtline.hxx:61
std::unique_ptr< weld::SpinButton > m_xRestartNF
Definition: numpara.hxx:51
std::unique_ptr< weld::CheckButton > m_xRestartParaCountCB
Definition: numpara.hxx:48
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxItemState
#define FN_NUMBER_NEWSTART
Definition: cmdid.h:456
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
static bool ExecuteEditNumStyle_Impl(sal_uInt16 nId, const OUString &rStr, SfxStyleFamily nFamily)
Definition: numpara.cxx:306
IMPL_LINK_NOARG(SwParagraphNumTabPage, NewStartHdl_Impl, weld::Toggleable &, void)
Definition: numpara.cxx:273
std::unique_ptr< weld::ComboBox > m_xNumberStyleLB
Definition: numpara.hxx:38
virtual SfxUInt16Item * Clone(SfxItemPool *=nullptr) const override
constexpr TypedWhichId< SwFormatLineNumber > RES_LINENUMBER(116)
void SetStartValue(sal_uLong nNew)
Definition: fmtline.hxx:60
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
bool IsCount() const
Definition: fmtline.hxx:58
OUString SwResId(std::string_view aId)
Definition: swmodule.cxx:165
#define FN_NUMBER_NEWSTART_AT
Definition: cmdid.h:457
SwParagraphNumTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: numpara.cxx:37
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
IMPL_LINK(SwParagraphNumTabPage, StyleHdl_Impl, weld::ComboBox &, rBox, void)
Definition: numpara.cxx:329