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