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