Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / ui / chrdlg / numpara.cxx
blobe002a6db16400e9a6b2c9db7a11ab3a947f3ab24
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
32 #include <officecfg/Office/Common.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/frame.hxx>
35 #include <sfx2/viewsh.hxx>
37 const WhichRangesContainer SwParagraphNumTabPage::s_aPageRg(svl::Items<FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART_AT>);
39 SwParagraphNumTabPage::SwParagraphNumTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttr)
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"))
61 m_xNewStartCB->set_state(TRISTATE_FALSE);
62 m_xNewStartNumberCB->set_state(TRISTATE_FALSE);
63 m_xCountParaCB->set_state(TRISTATE_FALSE);
64 m_xRestartParaCountCB->set_state(TRISTATE_FALSE);
65 m_xEditNumStyleBtn->set_sensitive(false);
67 const SfxUInt16Item* pItem = rAttr.GetItemIfSet(SID_HTML_MODE, false);
68 if (!pItem)
70 if (SfxObjectShell* pObjSh = SfxObjectShell::Current())
71 pItem = pObjSh->GetItem(SID_HTML_MODE);
73 if(pItem)
75 const sal_uInt16 nHtmlMode = pItem->GetValue();
77 if (HTMLMODE_ON & nHtmlMode)
78 m_xCountParaFram->hide();
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));
89 if (officecfg::Office::Common::Misc::ExperimentalMode::get())
90 m_xListLvBX->show();
91 else
92 m_xListLvBX->hide();
95 SwParagraphNumTabPage::~SwParagraphNumTabPage()
99 std::unique_ptr<SfxTabPage> SwParagraphNumTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
101 return std::make_unique<SwParagraphNumTabPage>(pPage, pController, *rSet);
104 bool SwParagraphNumTabPage::FillItemSet( SfxItemSet* rSet )
106 if (m_xOutlineLvLB->get_value_changed_from_saved())
108 const sal_uInt16 aOutlineLv = m_xOutlineLvLB->get_active();
109 const SfxUInt16Item* pOldOutlineLv = GetOldItem( *rSet, SID_ATTR_PARA_OUTLINE_LEVEL);
110 if (pOldOutlineLv)
112 std::unique_ptr<SfxUInt16Item> pOutlineLv(pOldOutlineLv->Clone());
113 pOutlineLv->SetValue( aOutlineLv );
114 rSet->Put(std::move(pOutlineLv));
115 m_bModified = true;
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())
121 sal_Int16 nListLevel = std::max<sal_Int16>(1, aOutlineLv);
122 --nListLevel; // Outline Level is 1 based. List Level is zero based.
123 rSet->Put(SfxInt16Item(RES_PARATR_LIST_LEVEL, nListLevel));
128 if (m_xListLvLB->get_value_changed_from_saved())
130 if (m_xListLvBX->get_visible())
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)
136 nListLevel = std::max<sal_Int16>(1, m_xOutlineLvLB->get_active());
138 --nListLevel; // List Level is zero based, but both listboxes are 1-based.
140 rSet->Put(SfxInt16Item(RES_PARATR_LIST_LEVEL, nListLevel));
141 m_bModified = true;
145 if (m_xNumberStyleLB->get_value_changed_from_saved())
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)
153 std::unique_ptr<SfxStringItem> pRule(pOldRule->Clone());
154 pRule->SetValue(aStyle);
155 rSet->Put(std::move(pRule));
156 m_bModified = true;
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())
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));
167 rSet->Put(SfxUInt16Item(FN_NUMBER_NEWSTART_AT,
168 bNumberNewStartChecked && bNewStartChecked ? o3tl::narrowing<sal_uInt16>(m_xNewStartNF->get_value()) : USHRT_MAX));
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())
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;
182 return m_bModified;
185 void SwParagraphNumTabPage::ChangesApplied()
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();
197 void SwParagraphNumTabPage::Reset(const SfxItemSet* rSet)
199 bool bHasNumberStyle = false;
201 SfxItemState eItemState = rSet->GetItemState( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) );
203 sal_Int16 nOutlineLv = 1; // 0 is Text Body, 1 is level 1
204 if( eItemState >= SfxItemState::DEFAULT )
206 nOutlineLv = rSet->Get( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) ).GetValue();
207 m_xOutlineLvLB->set_active(nOutlineLv) ;
209 else
211 m_xOutlineLvLB->set_active(-1);
213 m_xOutlineLvLB->save_value();
215 eItemState = rSet->GetItemState(RES_PARATR_LIST_LEVEL);
216 if (eItemState >= SfxItemState::DEFAULT)
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);
229 else
231 m_xListLvBX->hide();
233 m_xListLvLB->save_value();
235 eItemState = rSet->GetItemState( GetWhich(SID_ATTR_PARA_NUMRULE) );
237 if( eItemState >= SfxItemState::DEFAULT )
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);
243 if( aStyle == "Outline")
245 if (m_xNumberStyleLB->find_id("pseudo") == -1)
247 // tdf#145804 show "Chapter Numbering"
248 m_xNumberStyleLB->append("pseudo", msOutlineNumbering);
250 m_xNumberStyleLB->set_active_id("pseudo");
251 m_xNumberStyleLB->save_value();
253 else
254 m_xNumberStyleLB->set_active_text(aStyle);
256 bHasNumberStyle = true;
258 else
260 m_xNumberStyleLB->set_active(-1);
263 if (m_xNumberStyleBX->get_sensitive())
264 EditNumStyleSelectHdl_Impl(*m_xNumberStyleLB);
266 m_xNumberStyleLB->save_value();
268 eItemState = rSet->GetItemState( FN_NUMBER_NEWSTART );
269 if(eItemState > SfxItemState::DEFAULT )
271 m_bCurNumrule = true;
272 const SfxBoolItem& rStart = static_cast<const SfxBoolItem&>(rSet->Get(FN_NUMBER_NEWSTART));
274 m_xNewStartCB->set_state(rStart.GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
276 else
277 m_xNewStartCB->set_state(bHasNumberStyle ? TRISTATE_FALSE : TRISTATE_INDET);
279 m_xNewStartCB->save_state();
281 eItemState = rSet->GetItemState( FN_NUMBER_NEWSTART_AT);
282 if( eItemState > SfxItemState::DEFAULT )
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);
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))
297 const SwFormatLineNumber& rNum = rSet->Get(RES_LINENUMBER);
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);
305 else
307 m_xCountParaCB->set_state(TRISTATE_INDET);
308 m_xRestartParaCountCB->set_state(TRISTATE_INDET);
310 m_xCountParaCB->save_state();
311 m_xRestartParaCountCB->save_state();
312 m_xRestartNF->save_value();
314 m_bModified = false;
317 void SwParagraphNumTabPage::DisableOutline()
319 m_xOutlineStartBX->set_sensitive(false);
320 m_xOutlineStartBX->set_tooltip_text( SwResId(STR_OUTLINENUMBERING_DISABLED) );
323 void SwParagraphNumTabPage::DisableNumbering()
325 m_xNumberStyleBX->set_sensitive(false);
326 m_xNumberStyleBX->set_tooltip_text( SwResId(STR_OUTLINENUMBERING_DISABLED) );
327 m_xListLvBX->set_sensitive(false);
330 void SwParagraphNumTabPage::EnableNewStart()
332 m_xNewStartCB->show();
333 m_xNewStartBX->show();
336 IMPL_LINK_NOARG(SwParagraphNumTabPage, NewStartHdl_Impl, weld::Toggleable&, void)
338 bool bEnable = m_xNewStartCB->get_active();
339 m_xNewStartNumberCB->set_sensitive(bEnable);
340 m_xNewStartNF->set_sensitive(bEnable && m_xNewStartNumberCB->get_active());
343 IMPL_LINK_NOARG(SwParagraphNumTabPage, LineCountHdl_Impl, weld::Toggleable&, void)
345 m_xRestartParaCountCB->set_sensitive(m_xCountParaCB->get_active());
347 bool bEnableRestartValue = m_xRestartParaCountCB->get_sensitive() &&
348 m_xRestartParaCountCB->get_active();
349 m_xRestartBX->set_sensitive(bEnableRestartValue);
352 IMPL_LINK_NOARG(SwParagraphNumTabPage, EditNumStyleSelectHdl_Impl, weld::ComboBox&, void)
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")
358 m_xEditNumStyleBtn->set_sensitive(false);
359 m_xListLvBX->set_sensitive(false);
361 else
363 m_xEditNumStyleBtn->set_sensitive(true);
364 m_xListLvBX->set_sensitive(true);
368 IMPL_LINK_NOARG(SwParagraphNumTabPage, EditNumStyleHdl_Impl, weld::Button&, void)
370 OUString aTemplName(m_xNumberStyleLB->get_active_text());
371 ExecuteEditNumStyle_Impl( SID_STYLE_EDIT, aTemplName, SfxStyleFamily::Pseudo );
374 // Internal: Perform functions through the Dispatcher
375 void SwParagraphNumTabPage::ExecuteEditNumStyle_Impl(
376 sal_uInt16 nId, const OUString &rStr, SfxStyleFamily nFamily)
378 SfxViewShell* pViewShell = SfxViewShell::Current();
380 if( !pViewShell)
381 return;
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;
392 pItems[ nCount++ ] = nullptr;
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;
402 pDispatcher->Execute(
403 nId, SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
404 pItems, 0, pInternalItems);
407 IMPL_LINK(SwParagraphNumTabPage, StyleHdl_Impl, weld::ComboBox&, rBox, void)
409 bool bEnable = m_bCurNumrule || rBox.get_active() > 0;
410 m_xNewStartCB->set_sensitive(bEnable);
411 NewStartHdl_Impl(*m_xNewStartCB);
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */