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/frame.hxx>
34#include <sfx2/viewsh.hxx>
35
36const WhichRangesContainer SwParagraphNumTabPage::s_aPageRg(svl::Items<FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART_AT>);
37
39 : SfxTabPage(pPage, pController, "modules/swriter/ui/numparapage.ui", "NumParaPage", &rAttr)
40 , msOutlineNumbering(SwResId(STR_OUTLINE_NUMBERING ))
41 , m_bModified(false)
42 , m_bCurNumrule(false)
43 , m_xOutlineStartBX(m_xBuilder->weld_widget("boxOUTLINE"))
44 , m_xOutlineLvLB(m_xBuilder->weld_combo_box("comboLB_OUTLINE_LEVEL"))
45 , m_xNumberStyleBX(m_xBuilder->weld_widget("boxNUMBER_STYLE"))
46 , m_xNumberStyleLB(m_xBuilder->weld_combo_box("comboLB_NUMBER_STYLE"))
47 , m_xEditNumStyleBtn(m_xBuilder->weld_button("editnumstyle"))
48 , m_xNewStartCB(m_xBuilder->weld_check_button("checkCB_NEW_START"))
49 , m_xNewStartBX(m_xBuilder->weld_widget("boxNEW_START"))
50 , m_xNewStartNumberCB(m_xBuilder->weld_check_button("checkCB_NUMBER_NEW_START"))
51 , m_xNewStartNF(m_xBuilder->weld_spin_button("spinNF_NEW_START"))
52 , m_xCountParaFram(m_xBuilder->weld_widget("frameFL_COUNT_PARA"))
53 , m_xCountParaCB(m_xBuilder->weld_check_button("checkCB_COUNT_PARA"))
54 , m_xRestartParaCountCB(m_xBuilder->weld_check_button("checkCB_RESTART_PARACOUNT"))
55 , m_xRestartBX(m_xBuilder->weld_widget("boxRESTART_NO"))
56 , m_xRestartNF(m_xBuilder->weld_spin_button("spinNF_RESTART_PARA"))
57{
58 m_xNewStartCB->set_state(TRISTATE_FALSE);
62 m_xEditNumStyleBtn->set_sensitive(false);
63
64 const SfxUInt16Item* pItem = rAttr.GetItemIfSet(SID_HTML_MODE, false);
65 if (!pItem)
66 {
68 pItem = pObjSh->GetItem(SID_HTML_MODE);
69 }
70 if(pItem)
71 {
72 const sal_uInt16 nHtmlMode = 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
91std::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 = 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 m_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 m_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 m_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 ? o3tl::narrowing<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 m_bModified = true;
147 }
148 return m_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 = 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 if (m_xNumberStyleLB->find_id("pseudo") == -1)
190 {
191 // tdf#145804 show "Chapter Numbering"
192 m_xNumberStyleLB->append("pseudo", msOutlineNumbering);
193 }
194 m_xNumberStyleLB->set_active_id("pseudo");
195 m_xNumberStyleLB->save_value();
196 }
197 else
198 m_xNumberStyleLB->set_active_text(aStyle);
199
200 bHasNumberStyle = true;
201 }
202 else
203 {
204 m_xNumberStyleLB->set_active(-1);
205 }
206
207 if (m_xNumberStyleBX->get_sensitive())
208 EditNumStyleSelectHdl_Impl(*m_xNumberStyleLB);
209
210 m_xNumberStyleLB->save_value();
211
212 eItemState = rSet->GetItemState( FN_NUMBER_NEWSTART );
213 if(eItemState > SfxItemState::DEFAULT )
214 {
215 m_bCurNumrule = true;
216 const SfxBoolItem& rStart = static_cast<const SfxBoolItem&>(rSet->Get(FN_NUMBER_NEWSTART));
217
218 m_xNewStartCB->set_state(rStart.GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
219 }
220 else
221 m_xNewStartCB->set_state(bHasNumberStyle ? TRISTATE_FALSE : TRISTATE_INDET);
222
223 m_xNewStartCB->save_state();
224
226 if( eItemState > SfxItemState::DEFAULT )
227 {
228 const sal_uInt16 nNewStart = static_cast<const SfxUInt16Item&>(rSet->Get(FN_NUMBER_NEWSTART_AT)).GetValue();
229 const bool bNotMax = USHRT_MAX != nNewStart;
230 m_xNewStartNumberCB->set_active(bNotMax);
231 m_xNewStartNF->set_value(bNotMax ? nNewStart : 1);
232 }
233 else
234 m_xNewStartCB->set_state(TRISTATE_INDET);
235 NewStartHdl_Impl(*m_xNewStartCB);
236 m_xNewStartNF->save_value();
237 m_xNewStartNumberCB->save_state();
238 StyleHdl_Impl(*m_xNumberStyleLB);
239 if( SfxItemState::DEFAULT <= rSet->GetItemState(RES_LINENUMBER))
240 {
242 sal_uLong nStartValue = rNum.GetStartValue();
243 bool bCount = rNum.IsCount();
244 m_xCountParaCB->set_state(bCount ? TRISTATE_TRUE : TRISTATE_FALSE);
245 m_xRestartParaCountCB->set_state(0 != nStartValue ? TRISTATE_TRUE : TRISTATE_FALSE);
246 m_xRestartNF->set_value(nStartValue == 0 ? 1 : nStartValue);
247 LineCountHdl_Impl(*m_xCountParaCB);
248 }
249 else
250 {
251 m_xCountParaCB->set_state(TRISTATE_INDET);
253 }
254 m_xCountParaCB->save_state();
255 m_xRestartParaCountCB->save_state();
256 m_xRestartNF->save_value();
257
258 m_bModified = false;
259}
260
262{
263 m_xOutlineStartBX->set_sensitive(false);
264 m_xOutlineStartBX->set_tooltip_text( SwResId(STR_OUTLINENUMBERING_DISABLED) );
265}
266
268{
269 m_xNumberStyleBX->set_sensitive(false);
270 m_xNumberStyleBX->set_tooltip_text( SwResId(STR_OUTLINENUMBERING_DISABLED) );
271}
272
274{
275 m_xNewStartCB->show();
276 m_xNewStartBX->show();
277}
278
280{
281 bool bEnable = m_xNewStartCB->get_active();
282 m_xNewStartNumberCB->set_sensitive(bEnable);
283 m_xNewStartNF->set_sensitive(bEnable && m_xNewStartNumberCB->get_active());
284}
285
287{
288 m_xRestartParaCountCB->set_sensitive(m_xCountParaCB->get_active());
289
290 bool bEnableRestartValue = m_xRestartParaCountCB->get_sensitive() &&
291 m_xRestartParaCountCB->get_active();
292 m_xRestartBX->set_sensitive(bEnableRestartValue);
293}
294
295IMPL_LINK_NOARG(SwParagraphNumTabPage, EditNumStyleSelectHdl_Impl, weld::ComboBox&, void)
296{
297 int numSelectPos = m_xNumberStyleLB->get_active();
298 // 0 is "None" and -1 is unselected state and a "pseudo" is uneditable "Chapter Numbering"
299 if (numSelectPos == 0 || numSelectPos == -1 || m_xNumberStyleLB->get_active_id() == "pseudo")
300 m_xEditNumStyleBtn->set_sensitive(false);
301 else
302 m_xEditNumStyleBtn->set_sensitive(true);
303}
304
306{
307 OUString aTemplName(m_xNumberStyleLB->get_active_text());
308 ExecuteEditNumStyle_Impl( SID_STYLE_EDIT, aTemplName, SfxStyleFamily::Pseudo );
309}
310
311// Internal: Perform functions through the Dispatcher
313 sal_uInt16 nId, const OUString &rStr, SfxStyleFamily nFamily)
314{
315 SfxViewShell* pViewShell = SfxViewShell::Current();
316
317 if( !pViewShell)
318 return;
319
320 SfxDispatcher* pDispatcher = pViewShell->GetDispatcher();
321 SfxStringItem aItem(nId, rStr);
322 SfxUInt16Item aFamily(SID_STYLE_FAMILY, static_cast<sal_uInt16>(nFamily));
323 const SfxPoolItem* pItems[ 3 ];
324 sal_uInt16 nCount = 0;
325 if( !rStr.isEmpty() )
326 pItems[ nCount++ ] = &aItem;
327 pItems[ nCount++ ] = &aFamily;
328
329 pItems[ nCount++ ] = nullptr;
330
331 // tdf#145363 we want the current dialog to be the parent of the new dialog
332 weld::Window* pDialogParent = GetFrameWeld();
333 css::uno::Any aAny(pDialogParent->GetXWindow());
334 SfxUnoAnyItem aDialogParent(SID_DIALOG_PARENT, aAny);
335 const SfxPoolItem* pInternalItems[ 2 ];
336 pInternalItems[ 0 ] = &aDialogParent;
337 pInternalItems[ 1 ] = nullptr;
338
339 pDispatcher->Execute(
340 nId, SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
341 pItems, 0, pInternalItems);
342}
343
344IMPL_LINK(SwParagraphNumTabPage, StyleHdl_Impl, weld::ComboBox&, rBox, void)
345{
346 bool bEnable = m_bCurNumrule || rBox.get_active() > 0;
347 m_xNewStartCB->set_sensitive(bEnable);
348 NewStartHdl_Impl(*m_xNewStartCB);
349}
350
351/* 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 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 SfxViewShell * Current()
bool IsCount() const
Definition: fmtline.hxx:58
sal_uLong GetStartValue() const
Definition: fmtline.hxx:57
void SetCountLines(bool b)
Definition: fmtline.hxx:61
void SetStartValue(sal_uLong nNew)
Definition: fmtline.hxx:60
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:44
std::unique_ptr< weld::Widget > m_xCountParaFram
Definition: numpara.hxx:46
std::unique_ptr< weld::CheckButton > m_xCountParaCB
Definition: numpara.hxx:47
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: numpara.cxx:91
std::unique_ptr< weld::CheckButton > m_xNewStartCB
Definition: numpara.hxx:41
std::unique_ptr< weld::ComboBox > m_xOutlineLvLB
Definition: numpara.hxx:36
virtual ~SwParagraphNumTabPage() override
Definition: numpara.cxx:87
virtual void Reset(const SfxItemSet *rSet) override
Definition: numpara.cxx:162
std::unique_ptr< weld::Widget > m_xNumberStyleBX
Definition: numpara.hxx:37
std::unique_ptr< weld::CheckButton > m_xNewStartNumberCB
Definition: numpara.hxx:43
std::unique_ptr< weld::CheckButton > m_xRestartParaCountCB
Definition: numpara.hxx:48
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: numpara.cxx:96
void ExecuteEditNumStyle_Impl(sal_uInt16 nId, const OUString &rStr, SfxStyleFamily nFamily)
Definition: numpara.cxx:312
static const WhichRangesContainer s_aPageRg
Definition: numpara.hxx:59
const OUString msOutlineNumbering
Definition: numpara.hxx:30
std::unique_ptr< weld::Button > m_xEditNumStyleBtn
Definition: numpara.hxx:39
virtual void ChangesApplied() override
Definition: numpara.cxx:151
std::unique_ptr< weld::Widget > m_xNewStartBX
Definition: numpara.hxx:42
std::unique_ptr< weld::SpinButton > m_xRestartNF
Definition: numpara.hxx:51
SwParagraphNumTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: numpara.cxx:38
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
#define FN_NUMBER_NEWSTART
Definition: cmdid.h:473
#define FN_NUMBER_NEWSTART_AT
Definition: cmdid.h:474
int nCount
TRISTATE_FALSE
TRISTATE_INDET
TRISTATE_TRUE
constexpr TypedWhichId< SwFormatLineNumber > RES_LINENUMBER(116)
HTMLMODE_ON
IMPL_LINK_NOARG(SwParagraphNumTabPage, NewStartHdl_Impl, weld::Toggleable &, void)
Definition: numpara.cxx:279
IMPL_LINK(SwParagraphNumTabPage, StyleHdl_Impl, weld::ComboBox &, rBox, void)
Definition: numpara.cxx:344
sal_Int16 nId
const char GetValue[]
SfxItemState
static SfxItemSet & rSet
sal_uIntPtr sal_uLong
SfxStyleFamily
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:165