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  if( eItemState >= SfxItemState::DEFAULT )
169  {
170  sal_Int16 nOutlineLv = static_cast<const SfxUInt16Item &>(rSet->Get( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) )).GetValue();
171  m_xOutlineLvLB->set_active(nOutlineLv) ;
172  }
173  else
174  {
175  m_xOutlineLvLB->set_active(-1);
176  }
177  m_xOutlineLvLB->save_value();
178 
179  eItemState = rSet->GetItemState( GetWhich(SID_ATTR_PARA_NUMRULE) );
180 
181  if( eItemState >= SfxItemState::DEFAULT )
182  {
183  OUString aStyle = static_cast<const SfxStringItem &>(rSet->Get( GetWhich(SID_ATTR_PARA_NUMRULE) )).GetValue();
184  if(aStyle.isEmpty())
185  aStyle = m_xNumberStyleLB->get_text(0);
186 
187  if( aStyle == "Outline")
188  {
189  //add it, select it, remove it ? do we really want set_active(-1) instead ?
190  m_xNumberStyleLB->append_text(msOutlineNumbering);
191  m_xNumberStyleLB->set_active_text(msOutlineNumbering);
192  m_xNumberStyleLB->remove_text(msOutlineNumbering);
193  m_xNumberStyleLB->save_value();
194  }
195  else
196  m_xNumberStyleLB->set_active_text(aStyle);
197 
198  bHasNumberStyle = true;
199  }
200  else
201  {
202  m_xNumberStyleLB->set_active(-1);
203  }
204 
205  EditNumStyleSelectHdl_Impl(*m_xNumberStyleLB);
206 
207  m_xNumberStyleLB->save_value();
208 
209  eItemState = rSet->GetItemState( FN_NUMBER_NEWSTART );
210  if(eItemState > SfxItemState::DEFAULT )
211  {
212  bCurNumrule = true;
213  const SfxBoolItem& rStart = static_cast<const SfxBoolItem&>(rSet->Get(FN_NUMBER_NEWSTART));
214 
215  m_xNewStartCB->set_state(rStart.GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
216  }
217  else
218  m_xNewStartCB->set_state(bHasNumberStyle ? TRISTATE_FALSE : TRISTATE_INDET);
219 
220  m_xNewStartCB->save_state();
221 
222  eItemState = rSet->GetItemState( FN_NUMBER_NEWSTART_AT);
223  if( eItemState > SfxItemState::DEFAULT )
224  {
225  const sal_uInt16 nNewStart = static_cast<const SfxUInt16Item&>(rSet->Get(FN_NUMBER_NEWSTART_AT)).GetValue();
226  const bool bNotMax = USHRT_MAX != nNewStart;
227  m_xNewStartNumberCB->set_active(bNotMax);
228  m_xNewStartNF->set_value(bNotMax ? nNewStart : 1);
229  }
230  else
231  m_xNewStartCB->set_state(TRISTATE_INDET);
232  NewStartHdl_Impl(*m_xNewStartCB);
233  m_xNewStartNF->save_value();
234  m_xNewStartNumberCB->save_state();
235  StyleHdl_Impl(*m_xNumberStyleLB);
236  if( SfxItemState::DEFAULT <= rSet->GetItemState(RES_LINENUMBER))
237  {
238  const SwFormatLineNumber& rNum = rSet->Get(RES_LINENUMBER);
239  sal_uLong nStartValue = rNum.GetStartValue();
240  bool bCount = rNum.IsCount();
241  m_xCountParaCB->set_state(bCount ? TRISTATE_TRUE : TRISTATE_FALSE);
242  m_xRestartParaCountCB->set_state(0 != nStartValue ? TRISTATE_TRUE : TRISTATE_FALSE);
243  m_xRestartNF->set_value(nStartValue == 0 ? 1 : nStartValue);
244  LineCountHdl_Impl(*m_xCountParaCB);
245  }
246  else
247  {
248  m_xCountParaCB->set_state(TRISTATE_INDET);
249  m_xRestartParaCountCB->set_state(TRISTATE_INDET);
250  }
251  m_xCountParaCB->save_state();
252  m_xRestartParaCountCB->save_state();
253  m_xRestartNF->save_value();
254 
255  bModified = false;
256 }
257 
259 {
260  m_xOutlineStartBX->set_sensitive(false);
261  m_xOutlineStartBX->set_tooltip_text( SwResId(STR_OUTLINENUMBERING_DISABLED) );
262 }
263 
265 {
266  m_xNumberStyleBX->set_sensitive(false);
267  m_xNumberStyleBX->set_tooltip_text( SwResId(STR_OUTLINENUMBERING_DISABLED) );
268 }
269 
271 {
272  m_xNewStartCB->show();
273  m_xNewStartBX->show();
274 }
275 
277 {
278  bool bEnable = m_xNewStartCB->get_active();
279  m_xNewStartNumberCB->set_sensitive(bEnable);
280  m_xNewStartNF->set_sensitive(bEnable && m_xNewStartNumberCB->get_active());
281 }
282 
284 {
285  m_xRestartParaCountCB->set_sensitive(m_xCountParaCB->get_active());
286 
287  bool bEnableRestartValue = m_xRestartParaCountCB->get_sensitive() &&
288  m_xRestartParaCountCB->get_active();
289  m_xRestartBX->set_sensitive(bEnableRestartValue);
290 }
291 
292 IMPL_LINK_NOARG(SwParagraphNumTabPage, EditNumStyleSelectHdl_Impl, weld::ComboBox&, void)
293 {
294  int numSelectPos = m_xNumberStyleLB->get_active();
295  // 0 is "None" and -1 is unselected state
296  if (numSelectPos == 0 || numSelectPos == -1)
297  m_xEditNumStyleBtn->set_sensitive(false);
298  else
299  m_xEditNumStyleBtn->set_sensitive(true);
300 }
301 
302 IMPL_LINK_NOARG(SwParagraphNumTabPage, EditNumStyleHdl_Impl, weld::Button&, void)
303 {
304  OUString aTemplName(m_xNumberStyleLB->get_active_text());
305  ExecuteEditNumStyle_Impl( SID_STYLE_EDIT, aTemplName, SfxStyleFamily::Pseudo );
306 }
307 
308 // Internal: Perform functions through the Dispatcher
310  sal_uInt16 nId, const OUString &rStr, SfxStyleFamily nFamily)
311 {
312 
314  SfxStringItem aItem(nId, rStr);
315  SfxUInt16Item aFamily(SID_STYLE_FAMILY, static_cast<sal_uInt16>(nFamily));
316  const SfxPoolItem* pItems[ 3 ];
317  sal_uInt16 nCount = 0;
318  if( !rStr.isEmpty() )
319  pItems[ nCount++ ] = &aItem;
320  pItems[ nCount++ ] = &aFamily;
321 
322  pItems[ nCount++ ] = nullptr;
323 
324  const SfxPoolItem* pItem = rDispatcher.Execute(
325  nId, SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
326  pItems );
327 
328  return pItem != nullptr;
329 
330 }
331 
332 IMPL_LINK(SwParagraphNumTabPage, StyleHdl_Impl, weld::ComboBox&, rBox, void)
333 {
334  bool bEnable = bCurNumrule || rBox.get_active() > 0;
335  m_xNewStartCB->set_sensitive(bEnable);
336  NewStartHdl_Impl(*m_xNewStartCB);
337 }
338 
339 /* 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:166
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:276
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:309
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:457
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:332