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