android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / misc / num.cxx
blob15848bf98c4bb8c642438677d31f7f3a37334bbf
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 <editeng/numitem.hxx>
21 #include <cmdid.h>
22 #include <wrtsh.hxx>
23 #include <docsh.hxx>
24 #include <wview.hxx>
25 #include <uitool.hxx>
26 #include <wdocsh.hxx>
27 #include <uiitems.hxx>
28 #include <poolfmt.hxx>
29 #include <shellres.hxx>
30 #include <outline.hxx>
31 #include <num.hxx>
33 #include <SwStyleNameMapper.hxx>
34 #include <svx/dialogs.hrc>
35 #include <svl/stritem.hxx>
36 #include <svl/eitem.hxx>
37 #include <svl/slstitm.hxx>
38 #include <svl/intitem.hxx>
39 #include <comphelper/lok.hxx>
40 #include <osl/diagnose.h>
42 static bool bLastRelative = false;
44 //See cui/uiconfig/ui/numberingpositionpage.ui for effectively a duplicate
45 //dialog to this one, except with a different preview window impl.
46 //TODO, determine if SwNumPositionTabPage and SvxNumPositionTabPage can be
47 //merged
48 SwNumPositionTabPage::SwNumPositionTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
49 : SfxTabPage(pPage, pController, "modules/swriter/ui/outlinepositionpage.ui", "OutlinePositionPage", &rSet)
50 , m_pSaveNum(nullptr)
51 , m_pWrtSh(nullptr)
52 , m_pOutlineDlg(nullptr)
53 , m_nActNumLvl(0)
54 , m_bModified(false)
55 , m_bPreset(false)
56 , m_bInInintControl(false)
57 , m_bLabelAlignmentPosAndSpaceModeActive(false)
58 , m_xLevelLB(m_xBuilder->weld_tree_view("levellb"))
59 , m_xPositionFrame(m_xBuilder->weld_widget("numberingframe"))
60 , m_xDistBorderFT(m_xBuilder->weld_label("indent"))
61 , m_xDistBorderMF(m_xBuilder->weld_metric_spin_button("indentmf", FieldUnit::CM))
62 , m_xRelativeCB(m_xBuilder->weld_check_button("relative"))
63 , m_xIndentFT(m_xBuilder->weld_label("numberingwidth"))
64 , m_xIndentMF(m_xBuilder->weld_metric_spin_button("numberingwidthmf", FieldUnit::CM))
65 , m_xDistNumFT(m_xBuilder->weld_label("numdist"))
66 , m_xDistNumMF(m_xBuilder->weld_metric_spin_button("numdistmf", FieldUnit::CM))
67 , m_xAlignFT(m_xBuilder->weld_label("numalign"))
68 , m_xAlignLB(m_xBuilder->weld_combo_box("numalignlb"))
69 , m_xLabelFollowedByFT(m_xBuilder->weld_label("numfollowedby"))
70 , m_xLabelFollowedByLB(m_xBuilder->weld_combo_box("numfollowedbylb"))
71 , m_xListtabFT(m_xBuilder->weld_label("at"))
72 , m_xListtabMF(m_xBuilder->weld_metric_spin_button("atmf", FieldUnit::CM))
73 , m_xAlign2FT(m_xBuilder->weld_label("num2align"))
74 , m_xAlign2LB(m_xBuilder->weld_combo_box("num2alignlb"))
75 , m_xAlignedAtFT(m_xBuilder->weld_label("alignedat"))
76 , m_xAlignedAtMF(m_xBuilder->weld_metric_spin_button("alignedatmf", FieldUnit::CM))
77 , m_xIndentAtFT(m_xBuilder->weld_label("indentat"))
78 , m_xIndentAtMF(m_xBuilder->weld_metric_spin_button("indentatmf", FieldUnit::CM))
79 , m_xStandardPB(m_xBuilder->weld_button("standard"))
80 , m_xPreviewWIN(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreviewWIN))
82 SetExchangeSupport();
84 m_xLevelLB->set_selection_mode(SelectionMode::Multiple);
86 m_xRelativeCB->set_active(true);
87 m_xAlignLB->connect_changed(LINK(this, SwNumPositionTabPage, EditModifyHdl));
88 m_xAlign2LB->connect_changed(LINK(this, SwNumPositionTabPage, EditModifyHdl));
89 for (int i = 0; i < m_xAlignLB->get_count(); ++i)
91 m_xAlign2LB->append_text(m_xAlignLB->get_text(i));
93 m_xAlign2FT->set_label(m_xAlignFT->get_label());
95 Link<weld::MetricSpinButton&, void> aLk = LINK(this, SwNumPositionTabPage, DistanceHdl);
96 m_xDistBorderMF->connect_value_changed(aLk);
97 m_xDistNumMF->connect_value_changed(aLk);
98 m_xIndentMF->connect_value_changed(aLk);
100 m_xLabelFollowedByLB->connect_changed( LINK(this, SwNumPositionTabPage, LabelFollowedByHdl_Impl) );
102 aLk = LINK(this, SwNumPositionTabPage, ListtabPosHdl_Impl);
103 m_xListtabMF->connect_value_changed(aLk);
105 aLk = LINK(this, SwNumPositionTabPage, AlignAtHdl_Impl);
106 m_xAlignedAtMF->connect_value_changed(aLk);
108 aLk = LINK(this, SwNumPositionTabPage, IndentAtHdl_Impl);
109 m_xIndentAtMF->connect_value_changed(aLk);
111 m_xLevelLB->connect_changed(LINK(this, SwNumPositionTabPage, LevelHdl));
112 m_xRelativeCB->connect_toggled(LINK(this, SwNumPositionTabPage, RelativeHdl));
113 m_xStandardPB->connect_clicked(LINK(this, SwNumPositionTabPage, StandardHdl));
115 // insert levels
116 for(sal_uInt16 i = 1; i <= MAXLEVEL; i++)
117 m_xLevelLB->append_text(OUString::number(i));
118 OUString sEntry = "1 - " + OUString::number(MAXLEVEL);
119 m_xLevelLB->append_text(sEntry);
120 m_xLevelLB->select_text(sEntry);
122 m_xRelativeCB->set_active(bLastRelative);
123 m_aPreviewWIN.SetPositionMode();
126 SwNumPositionTabPage::~SwNumPositionTabPage()
128 m_pActNum.reset();
129 m_pOutlineDlg = nullptr;
132 void SwNumPositionTabPage::InitControls()
134 m_bInInintControl = true;
135 const bool bRelative = !m_bLabelAlignmentPosAndSpaceModeActive &&
136 m_xRelativeCB->get_sensitive() && m_xRelativeCB->get_active();
137 const bool bSingleSelection = m_xLevelLB->count_selected_rows() == 1 &&
138 USHRT_MAX != m_nActNumLvl;
140 m_xDistBorderMF->set_sensitive( !m_bLabelAlignmentPosAndSpaceModeActive &&
141 ( bSingleSelection || bRelative || m_pOutlineDlg != nullptr ) );
142 m_xDistBorderFT->set_sensitive( !m_bLabelAlignmentPosAndSpaceModeActive &&
143 ( bSingleSelection || bRelative || m_pOutlineDlg != nullptr ) );
145 bool bSetDistEmpty = false;
146 bool bSameDistBorderNum = !m_bLabelAlignmentPosAndSpaceModeActive;
147 bool bSameDist = !m_bLabelAlignmentPosAndSpaceModeActive;
148 bool bSameIndent = !m_bLabelAlignmentPosAndSpaceModeActive;
149 bool bSameAdjust = true;
151 bool bSameLabelFollowedBy = m_bLabelAlignmentPosAndSpaceModeActive;
152 bool bSameListtab = m_bLabelAlignmentPosAndSpaceModeActive;
153 bool bSameAlignAt = m_bLabelAlignmentPosAndSpaceModeActive;
154 bool bSameIndentAt = m_bLabelAlignmentPosAndSpaceModeActive;
156 const SwNumFormat* aNumFormatArr[MAXLEVEL];
157 sal_uInt16 nMask = 1;
158 sal_uInt16 nLvl = USHRT_MAX;
159 tools::Long nFirstBorderTextRelative = -1;
160 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
162 aNumFormatArr[i] = &m_pActNum->Get(i);
163 if(m_nActNumLvl & nMask)
165 if(USHRT_MAX == nLvl)
167 nLvl = i;
170 if( i > nLvl)
172 bSameAdjust &= aNumFormatArr[i]->GetNumAdjust() == aNumFormatArr[nLvl]->GetNumAdjust();
173 if ( !m_bLabelAlignmentPosAndSpaceModeActive )
175 if(bRelative)
177 const tools::Long nBorderTextRelative =
178 aNumFormatArr[i]->GetAbsLSpace() + aNumFormatArr[i]->GetFirstLineOffset() -
179 aNumFormatArr[i - 1]->GetAbsLSpace() + aNumFormatArr[i - 1]->GetFirstLineOffset();
180 if (nFirstBorderTextRelative == -1)
181 nFirstBorderTextRelative = nBorderTextRelative;
182 else
183 bSameDistBorderNum &= nFirstBorderTextRelative == nBorderTextRelative;
185 else
187 bSameDistBorderNum &=
188 aNumFormatArr[i]->GetAbsLSpace() - aNumFormatArr[i]->GetFirstLineOffset() ==
189 aNumFormatArr[i - 1]->GetAbsLSpace() - aNumFormatArr[i - 1]->GetFirstLineOffset();
192 bSameDist &= aNumFormatArr[i]->GetCharTextDistance() == aNumFormatArr[nLvl]->GetCharTextDistance();
193 bSameIndent &= aNumFormatArr[i]->GetFirstLineOffset() == aNumFormatArr[nLvl]->GetFirstLineOffset();
195 else
197 bSameLabelFollowedBy &=
198 aNumFormatArr[i]->GetLabelFollowedBy() == aNumFormatArr[nLvl]->GetLabelFollowedBy();
199 bSameListtab &=
200 aNumFormatArr[i]->GetListtabPos() == aNumFormatArr[nLvl]->GetListtabPos();
201 bSameAlignAt &=
202 ( ( aNumFormatArr[i]->GetIndentAt() + aNumFormatArr[i]->GetFirstLineIndent() )
203 == ( aNumFormatArr[nLvl]->GetIndentAt() + aNumFormatArr[nLvl]->GetFirstLineIndent() ) );
204 bSameIndentAt &=
205 aNumFormatArr[i]->GetIndentAt() == aNumFormatArr[nLvl]->GetIndentAt();
209 nMask <<= 1;
212 if (MAXLEVEL <= nLvl)
214 OSL_ENSURE(false, "cannot happen.");
215 return;
217 if(bSameDistBorderNum)
219 tools::Long nDistBorderNum;
220 if(bRelative)
222 nDistBorderNum = static_cast<tools::Long>(aNumFormatArr[nLvl]->GetAbsLSpace())+ aNumFormatArr[nLvl]->GetFirstLineOffset();
223 if(nLvl)
224 nDistBorderNum -= static_cast<tools::Long>(aNumFormatArr[nLvl - 1]->GetAbsLSpace())+ aNumFormatArr[nLvl - 1]->GetFirstLineOffset();
226 else
228 nDistBorderNum = static_cast<tools::Long>(aNumFormatArr[nLvl]->GetAbsLSpace())+ aNumFormatArr[nLvl]->GetFirstLineOffset();
230 m_xDistBorderMF->set_value(m_xDistBorderMF->normalize(nDistBorderNum),FieldUnit::TWIP);
232 else
233 bSetDistEmpty = true;
235 if(bSameDist)
236 m_xDistNumMF->set_value(m_xDistNumMF->normalize(aNumFormatArr[nLvl]->GetCharTextDistance()), FieldUnit::TWIP);
237 else
238 m_xDistNumMF->set_text(OUString());
239 if(bSameIndent)
240 m_xIndentMF->set_value(m_xIndentMF->normalize(-aNumFormatArr[nLvl]->GetFirstLineOffset()), FieldUnit::TWIP);
241 else
242 m_xIndentMF->set_text(OUString());
244 if(bSameAdjust)
246 sal_Int32 nPos = 1; // centered
247 if(aNumFormatArr[nLvl]->GetNumAdjust() == SvxAdjust::Left)
248 nPos = 0;
249 else if(aNumFormatArr[nLvl]->GetNumAdjust() == SvxAdjust::Right)
250 nPos = 2;
251 m_xAlignLB->set_active(nPos);
252 m_xAlign2LB->set_active( nPos );
254 else
256 m_xAlignLB->set_active(-1);
257 m_xAlign2LB->set_active(-1);
260 if ( bSameLabelFollowedBy )
262 sal_Int32 nPos = 0; // LISTTAB
263 if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::SPACE )
265 nPos = 1;
267 else if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::NOTHING )
269 nPos = 2;
271 else if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::NEWLINE )
273 nPos = 3;
275 m_xLabelFollowedByLB->set_active(nPos);
277 else
279 m_xLabelFollowedByLB->set_active(-1);
282 if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::LISTTAB )
284 m_xListtabFT->set_sensitive(true);
285 m_xListtabMF->set_sensitive(true);
286 if ( bSameListtab )
288 m_xListtabMF->set_value(m_xListtabMF->normalize(aNumFormatArr[nLvl]->GetListtabPos()),FieldUnit::TWIP);
290 else
292 m_xListtabMF->set_text(OUString());
295 else
297 m_xListtabFT->set_sensitive( false );
298 m_xListtabMF->set_sensitive( false );
299 m_xListtabMF->set_text(OUString());
302 if ( bSameAlignAt )
304 m_xAlignedAtMF->set_value(
305 m_xAlignedAtMF->normalize( aNumFormatArr[nLvl]->GetIndentAt() +
306 aNumFormatArr[nLvl]->GetFirstLineIndent()),
307 FieldUnit::TWIP );
309 else
311 m_xAlignedAtMF->set_text(OUString());
314 if ( bSameIndentAt )
316 m_xIndentAtMF->set_value(
317 m_xIndentAtMF->normalize( aNumFormatArr[nLvl]->GetIndentAt()), FieldUnit::TWIP );
319 else
321 m_xIndentAtMF->set_text(OUString());
324 if (bSetDistEmpty)
325 m_xDistBorderMF->set_text(OUString());
327 m_bInInintControl = false;
330 void SwNumPositionTabPage::ActivatePage(const SfxItemSet& )
332 const SfxPoolItem* pItem;
333 sal_uInt16 nTmpNumLvl =
334 m_pOutlineDlg ? SwOutlineTabDialog::GetActNumLevel() : 0;
335 const SfxItemSet* pExampleSet = GetDialogExampleSet();
336 if(pExampleSet && pExampleSet->GetItemState(FN_PARAM_NUM_PRESET, false, &pItem) != SfxItemState::UNKNOWN)
338 m_bPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue();
340 m_bModified = (!m_pActNum->GetNumFormat( 0 ) || m_bPreset);
341 if(*m_pActNum != *m_pSaveNum ||
342 m_nActNumLvl != nTmpNumLvl )
344 *m_pActNum = *m_pSaveNum;
345 m_nActNumLvl = nTmpNumLvl;
346 sal_uInt16 nMask = 1;
347 m_xLevelLB->unselect_all();
348 if (m_nActNumLvl == USHRT_MAX)
349 m_xLevelLB->select(MAXLEVEL);
350 else
352 for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
354 if (m_nActNumLvl & nMask)
355 m_xLevelLB->select(i);
356 nMask <<= 1 ;
360 InitPosAndSpaceMode();
361 ShowControlsDependingOnPosAndSpaceMode();
363 InitControls();
365 m_xRelativeCB->set_sensitive(1 != m_nActNumLvl);
366 m_aPreviewWIN.Invalidate();
369 DeactivateRC SwNumPositionTabPage::DeactivatePage(SfxItemSet *_pSet)
371 SwOutlineTabDialog::SetActNumLevel(m_nActNumLvl);
372 if(_pSet)
373 FillItemSet(_pSet);
374 return DeactivateRC::LeavePage;
378 bool SwNumPositionTabPage::FillItemSet( SfxItemSet* rSet )
380 if(m_pOutlineDlg)
381 *m_pOutlineDlg->GetNumRule() = *m_pActNum;
382 else if(m_bModified && m_pActNum)
384 *m_pSaveNum = *m_pActNum;
385 rSet->Put(SwUINumRuleItem( *m_pSaveNum ));
386 rSet->Put(SfxBoolItem(FN_PARAM_NUM_PRESET, false));
388 return m_bModified;
391 void SwNumPositionTabPage::Reset( const SfxItemSet* rSet )
393 if (m_pOutlineDlg)
395 m_pSaveNum = m_pOutlineDlg->GetNumRule();
396 m_xLevelLB->set_selection_mode(SelectionMode::Single);
398 else if(const SwUINumRuleItem* pNumberItem = rSet->GetItemIfSet(FN_PARAM_ACT_NUMBER, false))
399 m_pSaveNum = const_cast<SwUINumRuleItem*>(pNumberItem)->GetNumRule();
401 m_nActNumLvl = SwOutlineTabDialog::GetActNumLevel();
402 sal_uInt16 nMask = 1;
403 m_xLevelLB->unselect_all();
404 if(m_nActNumLvl == USHRT_MAX)
406 m_xLevelLB->select(MAXLEVEL);
408 else
410 for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
412 if (m_nActNumLvl & nMask)
413 m_xLevelLB->select(i);
414 nMask <<= 1;
418 if(!m_pActNum)
419 m_pActNum.reset(new SwNumRule(*m_pSaveNum));
420 else if(*m_pSaveNum != *m_pActNum)
421 *m_pActNum = *m_pSaveNum;
422 m_aPreviewWIN.SetNumRule(m_pActNum.get());
423 InitPosAndSpaceMode();
424 ShowControlsDependingOnPosAndSpaceMode();
425 InitControls();
426 m_bModified = false;
429 void SwNumPositionTabPage::InitPosAndSpaceMode()
431 if ( m_pActNum == nullptr )
433 OSL_FAIL( "<SwNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" );
434 return;
437 SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode =
438 SvxNumberFormat::LABEL_ALIGNMENT;
439 sal_uInt16 nMask = 1;
440 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
442 if(m_nActNumLvl & nMask)
444 SvxNumberFormat aNumFormat( m_pActNum->Get(i) );
445 ePosAndSpaceMode = aNumFormat.GetPositionAndSpaceMode();
446 if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
448 break;
451 nMask <<= 1;
454 m_bLabelAlignmentPosAndSpaceModeActive =
455 ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT;
458 void SwNumPositionTabPage::ShowControlsDependingOnPosAndSpaceMode()
460 m_xDistBorderFT->set_visible( !m_bLabelAlignmentPosAndSpaceModeActive );
461 m_xDistBorderMF->set_visible( !m_bLabelAlignmentPosAndSpaceModeActive );
462 m_xRelativeCB->set_visible( !m_bLabelAlignmentPosAndSpaceModeActive );
463 m_xIndentFT->set_visible( !m_bLabelAlignmentPosAndSpaceModeActive );
464 m_xIndentMF->set_visible( !m_bLabelAlignmentPosAndSpaceModeActive );
465 m_xDistNumFT->set_visible( !m_bLabelAlignmentPosAndSpaceModeActive );
466 m_xDistNumMF->set_visible( !m_bLabelAlignmentPosAndSpaceModeActive );
467 m_xAlignFT->set_visible( !m_bLabelAlignmentPosAndSpaceModeActive );
468 m_xAlignLB->set_visible( !m_bLabelAlignmentPosAndSpaceModeActive );
470 m_xLabelFollowedByFT->set_visible( m_bLabelAlignmentPosAndSpaceModeActive );
471 m_xLabelFollowedByLB->set_visible( m_bLabelAlignmentPosAndSpaceModeActive );
472 m_xListtabFT->set_visible( m_bLabelAlignmentPosAndSpaceModeActive );
473 m_xListtabMF->set_visible( m_bLabelAlignmentPosAndSpaceModeActive );
474 m_xAlign2FT->set_visible( m_bLabelAlignmentPosAndSpaceModeActive );
475 m_xAlign2LB->set_visible( m_bLabelAlignmentPosAndSpaceModeActive );
476 m_xAlignedAtFT->set_visible( m_bLabelAlignmentPosAndSpaceModeActive );
477 m_xAlignedAtMF->set_visible( m_bLabelAlignmentPosAndSpaceModeActive );
478 m_xIndentAtFT->set_visible( m_bLabelAlignmentPosAndSpaceModeActive );
479 m_xIndentAtMF->set_visible( m_bLabelAlignmentPosAndSpaceModeActive );
482 std::unique_ptr<SfxTabPage> SwNumPositionTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
483 const SfxItemSet* rAttrSet)
485 return std::make_unique<SwNumPositionTabPage>(pPage, pController, *rAttrSet);
488 void SwNumPositionTabPage::SetWrtShell(SwWrtShell* pSh)
490 m_pWrtSh = pSh;
492 const SwTwips nWidth = m_pWrtSh->GetAnyCurRect(CurRectType::Frame).Width();
494 m_xDistBorderMF->set_max(m_xDistBorderMF->normalize( nWidth ), FieldUnit::TWIP );
495 m_xDistNumMF->set_max(m_xDistNumMF->normalize( nWidth ), FieldUnit::TWIP);
496 m_xIndentMF->set_max(m_xIndentMF->normalize( nWidth ), FieldUnit::TWIP );
497 m_xListtabMF->set_max(m_xListtabMF->normalize( nWidth ), FieldUnit::TWIP );
498 m_xAlignedAtMF->set_max(m_xAlignedAtMF->normalize( nWidth ), FieldUnit::TWIP );
499 m_xIndentAtMF->set_max(m_xIndentAtMF->normalize( nWidth ), FieldUnit::TWIP );
501 const SwRect& rPrtRect = m_pWrtSh->GetAnyCurRect(CurRectType::Page);
502 m_aPreviewWIN.SetPageWidth(rPrtRect.Width());
503 FieldUnit eMetric = ::GetDfltMetric( dynamic_cast<SwWebView*>( &m_pWrtSh->GetView()) != nullptr );
504 if(eMetric == FieldUnit::MM)
506 m_xDistBorderMF->set_digits(1);
507 m_xDistNumMF->set_digits(1);
508 m_xIndentMF->set_digits(1);
509 m_xListtabMF->set_digits(1);
510 m_xAlignedAtMF->set_digits(1);
511 m_xIndentAtMF->set_digits(1);
513 m_xDistBorderMF->set_unit( eMetric );
514 m_xDistNumMF->set_unit( eMetric );
515 m_xIndentMF->set_unit( eMetric );
516 m_xListtabMF->set_unit( eMetric );
517 m_xAlignedAtMF->set_unit( eMetric );
518 m_xIndentAtMF->set_unit( eMetric );
521 IMPL_LINK_NOARG(SwNumPositionTabPage, EditModifyHdl, weld::ComboBox&, void)
523 sal_uInt16 nMask = 1;
524 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
526 if(m_nActNumLvl & nMask)
528 SwNumFormat aNumFormat(m_pActNum->Get(i));
530 const int nPos = m_xAlignLB->get_visible()
531 ? m_xAlignLB->get_active()
532 : m_xAlign2LB->get_active();
533 SvxAdjust eAdjust = SvxAdjust::Center;
534 if(nPos == 0)
535 eAdjust = SvxAdjust::Left;
536 else if(nPos == 2)
537 eAdjust = SvxAdjust::Right;
538 aNumFormat.SetNumAdjust( eAdjust );
539 m_pActNum->Set(i, aNumFormat);
541 nMask <<= 1;
543 SetModified();
546 IMPL_LINK( SwNumPositionTabPage, LevelHdl, weld::TreeView&, rBox, void )
548 sal_uInt16 nSaveNumLvl = m_nActNumLvl;
549 m_nActNumLvl = 0;
550 auto aRows = rBox.get_selected_rows();
551 if ((std::find(aRows.begin(), aRows.end(), MAXLEVEL) != aRows.end()) &&
552 (aRows.size() == 1 || nSaveNumLvl != 0xffff))
554 m_nActNumLvl = 0xFFFF;
555 for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
556 rBox.unselect(i);
558 else if (!aRows.empty())
560 sal_uInt16 nMask = 1;
561 for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
563 if (std::find(aRows.begin(), aRows.end(), i) != aRows.end())
564 m_nActNumLvl |= nMask;
565 nMask <<= 1;
567 rBox.unselect(MAXLEVEL);
569 else
571 m_nActNumLvl = nSaveNumLvl;
572 sal_uInt16 nMask = 1;
573 for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
575 if(m_nActNumLvl & nMask)
577 rBox.select(i);
578 break;
580 nMask <<=1;
583 m_xRelativeCB->set_sensitive(1 != m_nActNumLvl);
584 SetModified();
585 InitPosAndSpaceMode();
586 ShowControlsDependingOnPosAndSpaceMode();
587 InitControls();
590 IMPL_LINK(SwNumPositionTabPage, DistanceHdl, weld::MetricSpinButton&, rField, void)
592 if(m_bInInintControl)
593 return;
594 tools::Long nValue = static_cast< tools::Long >(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
595 sal_uInt16 nMask = 1;
596 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
598 if(m_nActNumLvl & nMask)
600 SwNumFormat aNumFormat( m_pActNum->Get( i ) );
601 if (&rField == m_xDistBorderMF.get())
604 if (m_xRelativeCB->get_active() && m_xRelativeCB->get_sensitive())
606 if(0 == i)
608 auto const nTmp = aNumFormat.GetFirstLineOffset();
609 aNumFormat.SetAbsLSpace( nValue - nTmp );
611 else
613 tools::Long nTmp = m_pActNum->Get( i - 1 ).GetAbsLSpace() +
614 m_pActNum->Get( i - 1 ).GetFirstLineOffset() -
615 m_pActNum->Get( i ).GetFirstLineOffset();
617 aNumFormat.SetAbsLSpace( nValue + nTmp );
620 else
622 aNumFormat.SetAbsLSpace( nValue - aNumFormat.GetFirstLineOffset());
625 else if (&rField == m_xDistNumMF.get())
627 aNumFormat.SetCharTextDistance( nValue );
629 else if (&rField == m_xIndentMF.get())
631 // now AbsLSpace also has to be modified by FirstLineOffset
632 tools::Long nDiff = nValue + aNumFormat.GetFirstLineOffset();
633 auto const nAbsLSpace = aNumFormat.GetAbsLSpace();
634 aNumFormat.SetAbsLSpace( nAbsLSpace + nDiff );
635 aNumFormat.SetFirstLineOffset( -nValue );
638 m_pActNum->Set( i, aNumFormat );
640 nMask <<= 1;
643 SetModified();
644 if(!m_xDistBorderMF->get_sensitive())
645 m_xDistBorderMF->set_text(OUString());
648 IMPL_LINK( SwNumPositionTabPage, RelativeHdl, weld::Toggleable&, rBox, void )
650 bool bOn = rBox.get_active();
651 bool bSingleSelection = m_xLevelLB->n_children() == 1 && USHRT_MAX != m_nActNumLvl;
652 bool bSetValue = false;
653 tools::Long nValue = 0;
654 if(bOn || bSingleSelection)
656 sal_uInt16 nMask = 1;
657 bool bFirst = true;
658 bSetValue = true;
659 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
661 if(m_nActNumLvl & nMask)
663 const SwNumFormat &rNumFormat = m_pActNum->Get(i);
664 if(bFirst)
666 nValue = rNumFormat.GetAbsLSpace();
667 if(bOn && i)
668 nValue -= m_pActNum->Get(i - 1).GetAbsLSpace();
670 else
671 bSetValue = nValue == rNumFormat.GetAbsLSpace() - m_pActNum->Get(i - 1).GetAbsLSpace();
672 bFirst = false;
674 nMask <<= 1;
678 if(bSetValue)
679 m_xDistBorderMF->set_value(m_xDistBorderMF->normalize(nValue), FieldUnit::TWIP);
680 else
681 m_xDistBorderMF->set_text(OUString());
682 m_xDistBorderMF->set_sensitive(bOn || bSingleSelection || m_pOutlineDlg);
683 bLastRelative = bOn;
686 IMPL_LINK_NOARG(SwNumPositionTabPage, LabelFollowedByHdl_Impl, weld::ComboBox&, void)
688 // determine value to be set at the chosen list levels
689 SvxNumberFormat::LabelFollowedBy eLabelFollowedBy = SvxNumberFormat::LISTTAB;
691 const int nPos = m_xLabelFollowedByLB->get_active();
692 if ( nPos == 1 )
694 eLabelFollowedBy = SvxNumberFormat::SPACE;
696 else if ( nPos == 2 )
698 eLabelFollowedBy = SvxNumberFormat::NOTHING;
700 else if ( nPos == 3 )
702 eLabelFollowedBy = SvxNumberFormat::NEWLINE;
706 // set value at the chosen list levels
707 bool bSameListtabPos = true;
708 sal_uInt16 nFirstLvl = USHRT_MAX;
709 sal_uInt16 nMask = 1;
710 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
712 if ( m_nActNumLvl & nMask )
714 SwNumFormat aNumFormat( m_pActNum->Get(i) );
715 aNumFormat.SetLabelFollowedBy( eLabelFollowedBy );
716 m_pActNum->Set( i, aNumFormat );
718 if ( nFirstLvl == USHRT_MAX )
720 nFirstLvl = i;
722 else
724 bSameListtabPos &= aNumFormat.GetListtabPos() ==
725 m_pActNum->Get( nFirstLvl ).GetListtabPos();
728 nMask <<= 1;
731 // enable/disable metric field for list tab stop position depending on
732 // selected item following the list label.
733 m_xListtabFT->set_sensitive( eLabelFollowedBy == SvxNumberFormat::LISTTAB );
734 m_xListtabMF->set_sensitive( eLabelFollowedBy == SvxNumberFormat::LISTTAB );
735 if ( bSameListtabPos && eLabelFollowedBy == SvxNumberFormat::LISTTAB )
737 m_xListtabMF->set_value(
738 m_xListtabMF->normalize( m_pActNum->Get( nFirstLvl ).GetListtabPos() ),
739 FieldUnit::TWIP );
741 else
743 m_xListtabMF->set_text(OUString());
746 SetModified();
749 IMPL_LINK( SwNumPositionTabPage, ListtabPosHdl_Impl, weld::MetricSpinButton&, rField, void )
751 // determine value to be set at the chosen list levels
752 const tools::Long nValue = static_cast< tools::Long >(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
754 // set value at the chosen list levels
755 sal_uInt16 nMask = 1;
756 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
758 if ( m_nActNumLvl & nMask )
760 SwNumFormat aNumFormat( m_pActNum->Get(i) );
761 aNumFormat.SetListtabPos( nValue );
762 m_pActNum->Set( i, aNumFormat );
764 nMask <<= 1;
767 SetModified();
770 IMPL_LINK( SwNumPositionTabPage, AlignAtHdl_Impl, weld::MetricSpinButton&, rField, void )
772 // determine value to be set at the chosen list levels
773 const tools::Long nValue = static_cast< tools::Long >(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
775 // set value at the chosen list levels
776 sal_uInt16 nMask = 1;
777 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
779 if ( m_nActNumLvl & nMask )
781 SwNumFormat aNumFormat( m_pActNum->Get(i) );
782 const tools::Long nFirstLineIndent = nValue - aNumFormat.GetIndentAt();
783 aNumFormat.SetFirstLineIndent( nFirstLineIndent );
784 m_pActNum->Set( i, aNumFormat );
786 nMask <<= 1;
789 SetModified();
792 IMPL_LINK( SwNumPositionTabPage, IndentAtHdl_Impl, weld::MetricSpinButton&, rField, void )
794 // determine value to be set at the chosen list levels
795 const tools::Long nValue = static_cast< tools::Long >(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
797 // set value at the chosen list levels
798 sal_uInt16 nMask = 1;
799 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
801 if ( m_nActNumLvl & nMask )
803 SwNumFormat aNumFormat( m_pActNum->Get(i) );
804 const tools::Long nAlignedAt = aNumFormat.GetIndentAt() +
805 aNumFormat.GetFirstLineIndent();
806 aNumFormat.SetIndentAt( nValue );
807 const tools::Long nNewFirstLineIndent = nAlignedAt - nValue;
808 aNumFormat.SetFirstLineIndent( nNewFirstLineIndent );
809 m_pActNum->Set( i, aNumFormat );
811 nMask <<= 1;
814 SetModified();
817 IMPL_LINK_NOARG(SwNumPositionTabPage, StandardHdl, weld::Button&, void)
819 sal_uInt16 nMask = 1;
820 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
822 if(m_nActNumLvl & nMask)
824 SwNumFormat aNumFormat( m_pActNum->Get( i ) );
825 SwNumRule aTmpNumRule( m_pWrtSh->GetUniqueNumRuleName(),
826 aNumFormat.GetPositionAndSpaceMode(),
827 m_pOutlineDlg ? OUTLINE_RULE : NUM_RULE );
828 const SwNumFormat& aTempFormat(aTmpNumRule.Get( i ));
829 aNumFormat.SetPositionAndSpaceMode( aTempFormat.GetPositionAndSpaceMode() );
830 if ( aTempFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
832 aNumFormat.SetAbsLSpace( aTempFormat.GetAbsLSpace());
833 aNumFormat.SetCharTextDistance( aTempFormat.GetCharTextDistance() );
834 aNumFormat.SetFirstLineOffset( aTempFormat.GetFirstLineOffset() );
836 else if ( aTempFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
838 aNumFormat.SetNumAdjust( aTempFormat.GetNumAdjust() );
839 aNumFormat.SetLabelFollowedBy( aTempFormat.GetLabelFollowedBy() );
840 aNumFormat.SetListtabPos( aTempFormat.GetListtabPos() );
841 aNumFormat.SetFirstLineIndent( aTempFormat.GetFirstLineIndent() );
842 aNumFormat.SetIndentAt( aTempFormat.GetIndentAt() );
844 m_pActNum->Set( i, aNumFormat );
846 nMask <<= 1;
849 InitControls();
850 SetModified();
853 #ifdef DBG_UTIL
854 void SwNumPositionTabPage::SetModified()
856 m_bModified = true;
857 m_aPreviewWIN.SetLevel(m_nActNumLvl);
858 m_aPreviewWIN.Invalidate();
860 #endif
862 SwSvxNumBulletTabDialog::SwSvxNumBulletTabDialog(weld::Window* pParent,
863 const SfxItemSet* pSwItemSet, SwWrtShell & rSh)
864 : SfxTabDialogController(pParent, "modules/swriter/ui/bulletsandnumbering.ui", "BulletsAndNumberingDialog",
865 pSwItemSet)
866 , m_rWrtSh(rSh)
867 , m_xDummyCombo(m_xBuilder->weld_combo_box("dummycombo"))
869 weld::Button* pButton = GetUserButton();
870 pButton->connect_clicked(LINK(this, SwSvxNumBulletTabDialog, RemoveNumberingHdl));
871 pButton->set_sensitive(m_rWrtSh.GetNumRuleAtCurrCursorPos() != nullptr);
872 AddTabPage("singlenum", RID_SVXPAGE_PICK_SINGLE_NUM );
873 AddTabPage("bullets", RID_SVXPAGE_PICK_BULLET );
874 AddTabPage("outlinenum", RID_SVXPAGE_PICK_NUM );
875 AddTabPage("graphics", RID_SVXPAGE_PICK_BMP );
877 if (comphelper::LibreOfficeKit::isActive())
879 RemoveTabPage("customize");
881 else
883 AddTabPage("customize", RID_SVXPAGE_NUM_OPTIONS );
886 AddTabPage("position", RID_SVXPAGE_NUM_POSITION );
889 SwSvxNumBulletTabDialog::~SwSvxNumBulletTabDialog()
893 void SwSvxNumBulletTabDialog::PageCreated(const OUString& rPageId, SfxTabPage& rPage)
895 // set styles' names and metric
896 OUString sNumCharFormat, sBulletCharFormat;
897 SwStyleNameMapper::FillUIName( RES_POOLCHR_NUM_LEVEL, sNumCharFormat );
898 SwStyleNameMapper::FillUIName( RES_POOLCHR_BULLET_LEVEL, sBulletCharFormat );
900 if (rPageId == "singlenum")
902 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
903 aSet.Put (SfxStringItem(SID_NUM_CHAR_FMT,sNumCharFormat));
904 aSet.Put (SfxStringItem(SID_BULLET_CHAR_FMT,sBulletCharFormat));
905 rPage.PageCreated(aSet);
907 else if (rPageId == "bullets")
909 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
910 aSet.Put (SfxStringItem(SID_BULLET_CHAR_FMT,sBulletCharFormat));
911 rPage.PageCreated(aSet);
913 else if (rPageId == "customize")
915 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
916 aSet.Put (SfxStringItem(SID_NUM_CHAR_FMT,sNumCharFormat));
917 aSet.Put (SfxStringItem(SID_BULLET_CHAR_FMT,sBulletCharFormat));
918 // collect char styles
919 m_xDummyCombo->clear();
920 m_xDummyCombo->append_text(SwViewShell::GetShellRes()->aStrNone);
921 SwDocShell* pDocShell = m_rWrtSh.GetView().GetDocShell();
922 ::FillCharStyleListBox(*m_xDummyCombo, pDocShell);
924 std::vector<OUString> aList;
925 aList.reserve(m_xDummyCombo->get_count());
926 for (sal_Int32 j = 0; j < m_xDummyCombo->get_count(); j++)
927 aList.push_back(m_xDummyCombo->get_text(j));
929 aSet.Put( SfxStringListItem( SID_CHAR_FMT_LIST_BOX,&aList ) ) ;
931 FieldUnit eMetric = ::GetDfltMetric(dynamic_cast< const SwWebDocShell *>( pDocShell ) != nullptr);
932 aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< sal_uInt16 >(eMetric) ) );
933 rPage.PageCreated(aSet);
935 else if (rPageId == "position")
937 SwDocShell* pDocShell = m_rWrtSh.GetView().GetDocShell();
938 FieldUnit eMetric = ::GetDfltMetric(dynamic_cast< const SwWebDocShell *>( pDocShell ) != nullptr);
939 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
940 aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< sal_uInt16 >(eMetric)) );
941 rPage.PageCreated(aSet);
945 short SwSvxNumBulletTabDialog::Ok()
947 short nRet = SfxTabDialogController::Ok();
948 m_xExampleSet->ClearItem(SID_PARAM_NUM_PRESET);
949 return nRet;
952 IMPL_LINK_NOARG(SwSvxNumBulletTabDialog, RemoveNumberingHdl, weld::Button&, void)
954 m_xDialog->response(RET_USER);
957 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */