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 <officecfg/Office/Common.hxx>
33#include <sfx2/dispatch.hxx>
34#include <sfx2/frame.hxx>
35#include <sfx2/viewsh.hxx>
36
37const WhichRangesContainer SwParagraphNumTabPage::s_aPageRg(svl::Items<FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART_AT>);
38
40 : SfxTabPage(pPage, pController, "modules/swriter/ui/numparapage.ui", "NumParaPage", &rAttr)
41 , msOutlineNumbering(SwResId(STR_OUTLINE_NUMBERING ))
42 , m_bModified(false)
43 , m_bCurNumrule(false)
44 , m_xOutlineStartBX(m_xBuilder->weld_widget("boxOUTLINE"))
45 , m_xOutlineLvLB(m_xBuilder->weld_combo_box("comboLB_OUTLINE_LEVEL"))
46 , m_xNumberStyleBX(m_xBuilder->weld_widget("boxNUMBER_STYLE"))
47 , m_xNumberStyleLB(m_xBuilder->weld_combo_box("comboLB_NUMBER_STYLE"))
48 , m_xEditNumStyleBtn(m_xBuilder->weld_button("editnumstyle"))
49 , m_xListLvBX(m_xBuilder->weld_widget("boxLIST_LEVEL"))
50 , m_xListLvLB(m_xBuilder->weld_combo_box("comboLB_LIST_LEVEL"))
51 , m_xNewStartCB(m_xBuilder->weld_check_button("checkCB_NEW_START"))
52 , m_xNewStartBX(m_xBuilder->weld_widget("boxNEW_START"))
53 , m_xNewStartNumberCB(m_xBuilder->weld_check_button("checkCB_NUMBER_NEW_START"))
54 , m_xNewStartNF(m_xBuilder->weld_spin_button("spinNF_NEW_START"))
55 , m_xCountParaFram(m_xBuilder->weld_widget("frameFL_COUNT_PARA"))
56 , m_xCountParaCB(m_xBuilder->weld_check_button("checkCB_COUNT_PARA"))
57 , m_xRestartParaCountCB(m_xBuilder->weld_check_button("checkCB_RESTART_PARACOUNT"))
58 , m_xRestartBX(m_xBuilder->weld_widget("boxRESTART_NO"))
59 , m_xRestartNF(m_xBuilder->weld_spin_button("spinNF_RESTART_PARA"))
60{
61 m_xNewStartCB->set_state(TRISTATE_FALSE);
65 m_xEditNumStyleBtn->set_sensitive(false);
66
67 const SfxUInt16Item* pItem = rAttr.GetItemIfSet(SID_HTML_MODE, false);
68 if (!pItem)
69 {
71 pItem = pObjSh->GetItem(SID_HTML_MODE);
72 }
73 if(pItem)
74 {
75 const sal_uInt16 nHtmlMode = pItem->GetValue();
76
77 if (HTMLMODE_ON & nHtmlMode)
78 m_xCountParaFram->hide();
79 }
80
81 m_xNewStartCB->connect_toggled(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
82 m_xNewStartNumberCB->connect_toggled(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
83 m_xNumberStyleLB->connect_changed(LINK(this, SwParagraphNumTabPage, StyleHdl_Impl));
84 m_xCountParaCB->connect_toggled(LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
85 m_xRestartParaCountCB->connect_toggled(LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
86 m_xNumberStyleLB->connect_changed(LINK(this, SwParagraphNumTabPage, EditNumStyleSelectHdl_Impl));
87 m_xEditNumStyleBtn->connect_clicked(LINK(this, SwParagraphNumTabPage, EditNumStyleHdl_Impl));
88
90 m_xListLvBX->show();
91 else
92 m_xListLvBX->hide();
93}
94
96{
97}
98
99std::unique_ptr<SfxTabPage> SwParagraphNumTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
100{
101 return std::make_unique<SwParagraphNumTabPage>(pPage, pController, *rSet);
102}
103
105{
106 if (m_xOutlineLvLB->get_value_changed_from_saved())
107 {
108 const sal_uInt16 aOutlineLv = m_xOutlineLvLB->get_active();
109 const SfxUInt16Item* pOldOutlineLv = GetOldItem( *rSet, SID_ATTR_PARA_OUTLINE_LEVEL);
110 if (pOldOutlineLv)
111 {
112 std::unique_ptr<SfxUInt16Item> pOutlineLv(pOldOutlineLv->Clone());
113 pOutlineLv->SetValue( aOutlineLv );
114 rSet->Put(std::move(pOutlineLv));
115 m_bModified = true;
116
117 // Does List Level need to be set to be the same as Outline Level?
118 if (!m_xListLvLB->get_active() && m_xListLvBX->get_visible()
119 && !m_xListLvLB->get_value_changed_from_saved())
120 {
121 sal_Int16 nListLevel = std::max<sal_Int16>(1, aOutlineLv);
122 --nListLevel; // Outline Level is 1 based. List Level is zero based.
124 }
125 }
126 }
127
128 if (m_xListLvLB->get_value_changed_from_saved())
129 {
130 if (m_xListLvBX->get_visible())
131 {
132 sal_Int16 nListLevel = m_xListLvLB->get_active();
133 // Does List Level need to be set to be the same as Outline Level?
134 if (!nListLevel)
135 {
136 nListLevel = std::max<sal_Int16>(1, m_xOutlineLvLB->get_active());
137 }
138 --nListLevel; // List Level is zero based, but both listboxes are 1-based.
139
141 m_bModified = true;
142 }
143 }
144
145 if (m_xNumberStyleLB->get_value_changed_from_saved())
146 {
147 OUString aStyle;
148 if (m_xNumberStyleLB->get_active())
149 aStyle = m_xNumberStyleLB->get_active_text();
150 const SfxStringItem* pOldRule = static_cast<const SfxStringItem*>(GetOldItem( *rSet, SID_ATTR_PARA_NUMRULE));
151 if (pOldRule)
152 {
153 std::unique_ptr<SfxStringItem> pRule(pOldRule->Clone());
154 pRule->SetValue(aStyle);
155 rSet->Put(std::move(pRule));
156 m_bModified = true;
157 }
158 }
159 if (m_xNewStartCB->get_state_changed_from_saved() ||
160 m_xNewStartNumberCB->get_state_changed_from_saved()||
161 m_xNewStartNF->get_value_changed_from_saved())
162 {
163 m_bModified = true;
164 bool bNewStartChecked = TRISTATE_TRUE == m_xNewStartCB->get_state();
165 bool bNumberNewStartChecked = TRISTATE_TRUE == m_xNewStartNumberCB->get_state();
166 rSet->Put(SfxBoolItem(FN_NUMBER_NEWSTART, bNewStartChecked));
168 bNumberNewStartChecked && bNewStartChecked ? o3tl::narrowing<sal_uInt16>(m_xNewStartNF->get_value()) : USHRT_MAX));
169 }
170
171 if (m_xCountParaCB->get_state_changed_from_saved()||
172 m_xRestartParaCountCB->get_state_changed_from_saved() ||
173 m_xRestartNF->get_value_changed_from_saved())
174 {
175 SwFormatLineNumber aFormat;
176 aFormat.SetStartValue( static_cast< sal_uLong >(m_xRestartParaCountCB->get_state() == TRISTATE_TRUE ?
177 m_xRestartNF->get_value() : 0 ));
178 aFormat.SetCountLines(m_xCountParaCB->get_active());
179 rSet->Put(aFormat);
180 m_bModified = true;
181 }
182 return m_bModified;
183}
184
186{
187 m_xOutlineLvLB->save_value();
188 m_xNumberStyleLB->save_value();
189 m_xListLvLB->save_value();
190 m_xNewStartCB->save_state();
191 m_xNewStartNumberCB->save_state();
192 m_xCountParaCB->save_state();
193 m_xRestartParaCountCB->save_state();
194 m_xRestartNF->save_value();
195}
196
198{
199 bool bHasNumberStyle = false;
200
201 SfxItemState eItemState = rSet->GetItemState( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) );
202
203 sal_Int16 nOutlineLv = 1; // 0 is Text Body, 1 is level 1
204 if( eItemState >= SfxItemState::DEFAULT )
205 {
206 nOutlineLv = rSet->Get( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) ).GetValue();
207 m_xOutlineLvLB->set_active(nOutlineLv) ;
208 }
209 else
210 {
211 m_xOutlineLvLB->set_active(-1);
212 }
213 m_xOutlineLvLB->save_value();
214
216 if (eItemState >= SfxItemState::DEFAULT)
217 {
218 sal_Int16 nListLevel = rSet->Get(RES_PARATR_LIST_LEVEL).GetValue(); // 0 is level 1
219 // Although listLevel doesn't have outline's "Text Body" level, treat it the same as level 1
220 // so that if the outline level is either 0 or 1, it is considered equal to list level 1.
221 // This is a rather crucial discrepancy - otherwise the user will rarely see
222 // list level using the special "Same as outline level,
223 // and the highly desirable state of keeping the two in sync will rarely be achieved.
224 if ((!nOutlineLv && !nListLevel) || nListLevel == nOutlineLv - 1)
225 m_xListLvLB->set_active(0); // highly encourage using "Same as outline level"
226 else
227 m_xListLvLB->set_active(nListLevel + 1);
228 }
229 else
230 {
231 m_xListLvBX->hide();
232 }
233 m_xListLvLB->save_value();
234
235 eItemState = rSet->GetItemState( GetWhich(SID_ATTR_PARA_NUMRULE) );
236
237 if( eItemState >= SfxItemState::DEFAULT )
238 {
239 OUString aStyle = static_cast<const SfxStringItem &>(rSet->Get( GetWhich(SID_ATTR_PARA_NUMRULE) )).GetValue();
240 if(aStyle.isEmpty())
241 aStyle = m_xNumberStyleLB->get_text(0);
242
243 if( aStyle == "Outline")
244 {
245 if (m_xNumberStyleLB->find_id("pseudo") == -1)
246 {
247 // tdf#145804 show "Chapter Numbering"
248 m_xNumberStyleLB->append("pseudo", msOutlineNumbering);
249 }
250 m_xNumberStyleLB->set_active_id("pseudo");
251 m_xNumberStyleLB->save_value();
252 }
253 else
254 m_xNumberStyleLB->set_active_text(aStyle);
255
256 bHasNumberStyle = true;
257 }
258 else
259 {
260 m_xNumberStyleLB->set_active(-1);
261 }
262
263 if (m_xNumberStyleBX->get_sensitive())
264 EditNumStyleSelectHdl_Impl(*m_xNumberStyleLB);
265
266 m_xNumberStyleLB->save_value();
267
268 eItemState = rSet->GetItemState( FN_NUMBER_NEWSTART );
269 if(eItemState > SfxItemState::DEFAULT )
270 {
271 m_bCurNumrule = true;
272 const SfxBoolItem& rStart = static_cast<const SfxBoolItem&>(rSet->Get(FN_NUMBER_NEWSTART));
273
274 m_xNewStartCB->set_state(rStart.GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
275 }
276 else
277 m_xNewStartCB->set_state(bHasNumberStyle ? TRISTATE_FALSE : TRISTATE_INDET);
278
279 m_xNewStartCB->save_state();
280
282 if( eItemState > SfxItemState::DEFAULT )
283 {
284 const sal_uInt16 nNewStart = rSet->Get(FN_NUMBER_NEWSTART_AT).GetValue();
285 const bool bNotMax = USHRT_MAX != nNewStart;
286 m_xNewStartNumberCB->set_active(bNotMax);
287 m_xNewStartNF->set_value(bNotMax ? nNewStart : 1);
288 }
289 else
290 m_xNewStartCB->set_state(TRISTATE_INDET);
291 NewStartHdl_Impl(*m_xNewStartCB);
292 m_xNewStartNF->save_value();
293 m_xNewStartNumberCB->save_state();
294 StyleHdl_Impl(*m_xNumberStyleLB);
295 if( SfxItemState::DEFAULT <= rSet->GetItemState(RES_LINENUMBER))
296 {
298 sal_uLong nStartValue = rNum.GetStartValue();
299 bool bCount = rNum.IsCount();
300 m_xCountParaCB->set_state(bCount ? TRISTATE_TRUE : TRISTATE_FALSE);
301 m_xRestartParaCountCB->set_state(0 != nStartValue ? TRISTATE_TRUE : TRISTATE_FALSE);
302 m_xRestartNF->set_value(nStartValue == 0 ? 1 : nStartValue);
303 LineCountHdl_Impl(*m_xCountParaCB);
304 }
305 else
306 {
307 m_xCountParaCB->set_state(TRISTATE_INDET);
309 }
310 m_xCountParaCB->save_state();
311 m_xRestartParaCountCB->save_state();
312 m_xRestartNF->save_value();
313
314 m_bModified = false;
315}
316
318{
319 m_xOutlineStartBX->set_sensitive(false);
320 m_xOutlineStartBX->set_tooltip_text( SwResId(STR_OUTLINENUMBERING_DISABLED) );
321}
322
324{
325 m_xNumberStyleBX->set_sensitive(false);
326 m_xNumberStyleBX->set_tooltip_text( SwResId(STR_OUTLINENUMBERING_DISABLED) );
327 m_xListLvBX->set_sensitive(false);
328}
329
331{
332 m_xNewStartCB->show();
333 m_xNewStartBX->show();
334}
335
337{
338 bool bEnable = m_xNewStartCB->get_active();
339 m_xNewStartNumberCB->set_sensitive(bEnable);
340 m_xNewStartNF->set_sensitive(bEnable && m_xNewStartNumberCB->get_active());
341}
342
344{
345 m_xRestartParaCountCB->set_sensitive(m_xCountParaCB->get_active());
346
347 bool bEnableRestartValue = m_xRestartParaCountCB->get_sensitive() &&
348 m_xRestartParaCountCB->get_active();
349 m_xRestartBX->set_sensitive(bEnableRestartValue);
350}
351
352IMPL_LINK_NOARG(SwParagraphNumTabPage, EditNumStyleSelectHdl_Impl, weld::ComboBox&, void)
353{
354 int numSelectPos = m_xNumberStyleLB->get_active();
355 // 0 is "None" and -1 is unselected state and a "pseudo" is uneditable "Chapter Numbering"
356 if (numSelectPos == 0 || numSelectPos == -1 || m_xNumberStyleLB->get_active_id() == "pseudo")
357 {
358 m_xEditNumStyleBtn->set_sensitive(false);
359 m_xListLvBX->set_sensitive(false);
360 }
361 else
362 {
363 m_xEditNumStyleBtn->set_sensitive(true);
364 m_xListLvBX->set_sensitive(true);
365 }
366}
367
369{
370 OUString aTemplName(m_xNumberStyleLB->get_active_text());
371 ExecuteEditNumStyle_Impl( SID_STYLE_EDIT, aTemplName, SfxStyleFamily::Pseudo );
372}
373
374// Internal: Perform functions through the Dispatcher
376 sal_uInt16 nId, const OUString &rStr, SfxStyleFamily nFamily)
377{
378 SfxViewShell* pViewShell = SfxViewShell::Current();
379
380 if( !pViewShell)
381 return;
382
383 SfxDispatcher* pDispatcher = pViewShell->GetDispatcher();
384 SfxStringItem aItem(nId, rStr);
385 SfxUInt16Item aFamily(SID_STYLE_FAMILY, static_cast<sal_uInt16>(nFamily));
386 const SfxPoolItem* pItems[ 3 ];
387 sal_uInt16 nCount = 0;
388 if( !rStr.isEmpty() )
389 pItems[ nCount++ ] = &aItem;
390 pItems[ nCount++ ] = &aFamily;
391
392 pItems[ nCount++ ] = nullptr;
393
394 // tdf#145363 we want the current dialog to be the parent of the new dialog
395 weld::Window* pDialogParent = GetFrameWeld();
396 css::uno::Any aAny(pDialogParent->GetXWindow());
397 SfxUnoAnyItem aDialogParent(SID_DIALOG_PARENT, aAny);
398 const SfxPoolItem* pInternalItems[ 2 ];
399 pInternalItems[ 0 ] = &aDialogParent;
400 pInternalItems[ 1 ] = nullptr;
401
402 pDispatcher->Execute(
403 nId, SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
404 pItems, 0, pInternalItems);
405}
406
407IMPL_LINK(SwParagraphNumTabPage, StyleHdl_Impl, weld::ComboBox&, rBox, void)
408{
409 bool bEnable = m_bCurNumrule || rBox.get_active() > 0;
410 m_xNewStartCB->set_sensitive(bEnable);
411 NewStartHdl_Impl(*m_xNewStartCB);
412}
413
414/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetValue() const
bool GetValue() const
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
SfxDispatcher * GetDispatcher() const
virtual SfxStringItem * Clone(SfxItemPool *=nullptr) const override
const SfxPoolItem * GetOldItem(const SfxItemSet &rSet, sal_uInt16 nSlot, bool bDeep=true)
weld::Window * GetFrameWeld() const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
virtual SfxUInt16Item * Clone(SfxItemPool *=nullptr) const override
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
Contains the line numbering properties of this paragraph.
Definition: fmtline.hxx:33
bool IsCount() const
Definition: fmtline.hxx:60
sal_uLong GetStartValue() const
Definition: fmtline.hxx:59
void SetCountLines(bool b)
Definition: fmtline.hxx:63
void SetStartValue(sal_uLong nNew)
Definition: fmtline.hxx:62
std::unique_ptr< weld::Widget > m_xOutlineStartBX
Definition: numpara.hxx:35
std::unique_ptr< weld::ComboBox > m_xNumberStyleLB
Definition: numpara.hxx:38
std::unique_ptr< weld::SpinButton > m_xNewStartNF
Definition: numpara.hxx:47
std::unique_ptr< weld::Widget > m_xCountParaFram
Definition: numpara.hxx:49
std::unique_ptr< weld::CheckButton > m_xCountParaCB
Definition: numpara.hxx:50
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: numpara.cxx:99
std::unique_ptr< weld::CheckButton > m_xNewStartCB
Definition: numpara.hxx:44
std::unique_ptr< weld::ComboBox > m_xOutlineLvLB
Definition: numpara.hxx:36
virtual ~SwParagraphNumTabPage() override
Definition: numpara.cxx:95
virtual void Reset(const SfxItemSet *rSet) override
Definition: numpara.cxx:197
std::unique_ptr< weld::Widget > m_xNumberStyleBX
Definition: numpara.hxx:37
std::unique_ptr< weld::CheckButton > m_xNewStartNumberCB
Definition: numpara.hxx:46
std::unique_ptr< weld::CheckButton > m_xRestartParaCountCB
Definition: numpara.hxx:51
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: numpara.cxx:104
void ExecuteEditNumStyle_Impl(sal_uInt16 nId, const OUString &rStr, SfxStyleFamily nFamily)
Definition: numpara.cxx:375
static const WhichRangesContainer s_aPageRg
Definition: numpara.hxx:62
const OUString msOutlineNumbering
Definition: numpara.hxx:30
std::unique_ptr< weld::Button > m_xEditNumStyleBtn
Definition: numpara.hxx:39
std::unique_ptr< weld::ComboBox > m_xListLvLB
Definition: numpara.hxx:42
std::unique_ptr< weld::Widget > m_xListLvBX
Definition: numpara.hxx:41
virtual void ChangesApplied() override
Definition: numpara.cxx:185
std::unique_ptr< weld::Widget > m_xNewStartBX
Definition: numpara.hxx:45
std::unique_ptr< weld::SpinButton > m_xRestartNF
Definition: numpara.hxx:54
SwParagraphNumTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: numpara.cxx:39
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
#define FN_NUMBER_NEWSTART
Definition: cmdid.h:489
#define FN_NUMBER_NEWSTART_AT
Definition: cmdid.h:490
int nCount
TRISTATE_FALSE
TRISTATE_INDET
TRISTATE_TRUE
constexpr TypedWhichId< SfxInt16Item > RES_PARATR_LIST_LEVEL(83)
constexpr TypedWhichId< SwFormatLineNumber > RES_LINENUMBER(122)
HTMLMODE_ON
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
IMPL_LINK_NOARG(SwParagraphNumTabPage, NewStartHdl_Impl, weld::Toggleable &, void)
Definition: numpara.cxx:336
IMPL_LINK(SwParagraphNumTabPage, StyleHdl_Impl, weld::ComboBox &, rBox, void)
Definition: numpara.cxx:407
sal_Int16 nId
const char GetValue[]
SfxItemState
static SfxItemSet & rSet
sal_uIntPtr sal_uLong
SfxStyleFamily
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168