lok: Hide file linking in section
[LibreOffice.git] / sw / source / ui / misc / num.cxx
blob603e05bebb3e256d25c0bb548eceae407be1b677
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 <hintids.hxx>
21 #include <sfx2/app.hxx>
22 #include <svx/gallery.hxx>
23 #include <editeng/brushitem.hxx>
24 #include <editeng/lrspitem.hxx>
25 #include <editeng/numitem.hxx>
26 #include <cmdid.h>
27 #include <swmodule.hxx>
28 #include <wrtsh.hxx>
29 #include <docsh.hxx>
30 #include <wview.hxx>
31 #include <uitool.hxx>
32 #include <wdocsh.hxx>
33 #include <uiitems.hxx>
34 #include <docstyle.hxx>
35 #include <charfmt.hxx>
36 #include <uinums.hxx>
37 #include <poolfmt.hxx>
38 #include <shellres.hxx>
39 #include <outline.hxx>
40 #include <num.hxx>
41 #include <viewopt.hxx>
42 #include <frmmgr.hxx>
44 #include <globals.hrc>
45 #include <SwStyleNameMapper.hxx>
46 #include <svx/svxids.hrc>
47 #include <svx/dialogs.hrc>
48 #include <svl/stritem.hxx>
49 #include <svl/aeitem.hxx>
50 #include <svl/slstitm.hxx>
51 #include <svl/intitem.hxx>
52 #include <comphelper/lok.hxx>
54 static bool bLastRelative = false;
56 //See cui/uiconfig/ui/numberingpositionpage.ui for effectively a duplicate
57 //dialog to this one, except with a different preview window impl.
58 //TODO, determine if SwNumPositionTabPage and SvxNumPositionTabPage can be
59 //merged
60 SwNumPositionTabPage::SwNumPositionTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
61 : SfxTabPage(pPage, pController, "modules/swriter/ui/outlinepositionpage.ui", "OutlinePositionPage", &rSet)
62 , pSaveNum(nullptr)
63 , pWrtSh(nullptr)
64 , pOutlineDlg(nullptr)
65 , nActNumLvl(0)
66 , bModified(false)
67 , bPreset(false)
68 , bInInintControl(false)
69 , bLabelAlignmentPosAndSpaceModeActive(false)
70 , m_xLevelLB(m_xBuilder->weld_tree_view("levellb"))
71 , m_xPositionFrame(m_xBuilder->weld_widget("numberingframe"))
72 , m_xDistBorderFT(m_xBuilder->weld_label("indent"))
73 , m_xDistBorderMF(m_xBuilder->weld_metric_spin_button("indentmf", FieldUnit::CM))
74 , m_xRelativeCB(m_xBuilder->weld_check_button("relative"))
75 , m_xIndentFT(m_xBuilder->weld_label("numberingwidth"))
76 , m_xIndentMF(m_xBuilder->weld_metric_spin_button("numberingwidthmf", FieldUnit::CM))
77 , m_xDistNumFT(m_xBuilder->weld_label("numdist"))
78 , m_xDistNumMF(m_xBuilder->weld_metric_spin_button("numdistmf", FieldUnit::CM))
79 , m_xAlignFT(m_xBuilder->weld_label("numalign"))
80 , m_xAlignLB(m_xBuilder->weld_combo_box("numalignlb"))
81 , m_xLabelFollowedByFT(m_xBuilder->weld_label("numfollowedby"))
82 , m_xLabelFollowedByLB(m_xBuilder->weld_combo_box("numfollowedbylb"))
83 , m_xListtabFT(m_xBuilder->weld_label("at"))
84 , m_xListtabMF(m_xBuilder->weld_metric_spin_button("atmf", FieldUnit::CM))
85 , m_xAlign2FT(m_xBuilder->weld_label("num2align"))
86 , m_xAlign2LB(m_xBuilder->weld_combo_box("num2alignlb"))
87 , m_xAlignedAtFT(m_xBuilder->weld_label("alignedat"))
88 , m_xAlignedAtMF(m_xBuilder->weld_metric_spin_button("alignedatmf", FieldUnit::CM))
89 , m_xIndentAtFT(m_xBuilder->weld_label("indentat"))
90 , m_xIndentAtMF(m_xBuilder->weld_metric_spin_button("indentatmf", FieldUnit::CM))
91 , m_xStandardPB(m_xBuilder->weld_button("standard"))
92 , m_xPreviewWIN(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreviewWIN))
94 SetExchangeSupport();
96 m_xLevelLB->set_selection_mode(SelectionMode::Multiple);
98 m_xRelativeCB->set_active(true);
99 m_xAlignLB->connect_changed(LINK(this, SwNumPositionTabPage, EditModifyHdl));
100 m_xAlign2LB->connect_changed(LINK(this, SwNumPositionTabPage, EditModifyHdl));
101 for (int i = 0; i < m_xAlignLB->get_count(); ++i)
103 m_xAlign2LB->append_text(m_xAlignLB->get_text(i));
105 m_xAlign2FT->set_label(m_xAlignFT->get_label());
107 Link<weld::MetricSpinButton&, void> aLk = LINK(this, SwNumPositionTabPage, DistanceHdl);
108 m_xDistBorderMF->connect_value_changed(aLk);
109 m_xDistNumMF->connect_value_changed(aLk);
110 m_xIndentMF->connect_value_changed(aLk);
112 m_xLabelFollowedByLB->connect_changed( LINK(this, SwNumPositionTabPage, LabelFollowedByHdl_Impl) );
114 aLk = LINK(this, SwNumPositionTabPage, ListtabPosHdl_Impl);
115 m_xListtabMF->connect_value_changed(aLk);
117 aLk = LINK(this, SwNumPositionTabPage, AlignAtHdl_Impl);
118 m_xAlignedAtMF->connect_value_changed(aLk);
120 aLk = LINK(this, SwNumPositionTabPage, IndentAtHdl_Impl);
121 m_xIndentAtMF->connect_value_changed(aLk);
123 m_xLevelLB->connect_changed(LINK(this, SwNumPositionTabPage, LevelHdl));
124 m_xRelativeCB->connect_toggled(LINK(this, SwNumPositionTabPage, RelativeHdl));
125 m_xStandardPB->connect_clicked(LINK(this, SwNumPositionTabPage, StandardHdl));
127 // insert levels
128 for(sal_uInt16 i = 1; i <= MAXLEVEL; i++)
129 m_xLevelLB->append_text(OUString::number(i));
130 OUString sEntry = "1 - " + OUString::number(MAXLEVEL);
131 m_xLevelLB->append_text(sEntry);
132 m_xLevelLB->select_text(sEntry);
134 m_xRelativeCB->set_active(bLastRelative);
135 m_aPreviewWIN.SetPositionMode();
138 SwNumPositionTabPage::~SwNumPositionTabPage()
140 pActNum.reset();
141 pOutlineDlg = nullptr;
144 void SwNumPositionTabPage::InitControls()
146 bInInintControl = true;
147 const bool bRelative = !bLabelAlignmentPosAndSpaceModeActive &&
148 m_xRelativeCB->get_sensitive() && m_xRelativeCB->get_active();
149 const bool bSingleSelection = m_xLevelLB->count_selected_rows() == 1 &&
150 USHRT_MAX != nActNumLvl;
152 m_xDistBorderMF->set_sensitive( !bLabelAlignmentPosAndSpaceModeActive &&
153 ( bSingleSelection || bRelative || pOutlineDlg != nullptr ) );
154 m_xDistBorderFT->set_sensitive( !bLabelAlignmentPosAndSpaceModeActive &&
155 ( bSingleSelection || bRelative || pOutlineDlg != nullptr ) );
157 bool bSetDistEmpty = false;
158 bool bSameDistBorderNum = !bLabelAlignmentPosAndSpaceModeActive;
159 bool bSameDist = !bLabelAlignmentPosAndSpaceModeActive;
160 bool bSameIndent = !bLabelAlignmentPosAndSpaceModeActive;
161 bool bSameAdjust = true;
163 bool bSameLabelFollowedBy = bLabelAlignmentPosAndSpaceModeActive;
164 bool bSameListtab = bLabelAlignmentPosAndSpaceModeActive;
165 bool bSameAlignAt = bLabelAlignmentPosAndSpaceModeActive;
166 bool bSameIndentAt = bLabelAlignmentPosAndSpaceModeActive;
168 const SwNumFormat* aNumFormatArr[MAXLEVEL];
169 sal_uInt16 nMask = 1;
170 sal_uInt16 nLvl = USHRT_MAX;
171 long nFirstBorderTextRelative = -1;
172 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
174 aNumFormatArr[i] = &pActNum->Get(i);
175 if(nActNumLvl & nMask)
177 if(USHRT_MAX == nLvl)
179 nLvl = i;
182 if( i > nLvl)
184 bSameAdjust &= aNumFormatArr[i]->GetNumAdjust() == aNumFormatArr[nLvl]->GetNumAdjust();
185 if ( !bLabelAlignmentPosAndSpaceModeActive )
187 if(bRelative)
189 const long nBorderTextRelative =
190 aNumFormatArr[i]->GetAbsLSpace() + aNumFormatArr[i]->GetFirstLineOffset() -
191 aNumFormatArr[i - 1]->GetAbsLSpace() + aNumFormatArr[i - 1]->GetFirstLineOffset();
192 if (nFirstBorderTextRelative == -1)
193 nFirstBorderTextRelative = nBorderTextRelative;
194 else
195 bSameDistBorderNum &= nFirstBorderTextRelative == nBorderTextRelative;
197 else
199 bSameDistBorderNum &=
200 aNumFormatArr[i]->GetAbsLSpace() - aNumFormatArr[i]->GetFirstLineOffset() ==
201 aNumFormatArr[i - 1]->GetAbsLSpace() - aNumFormatArr[i - 1]->GetFirstLineOffset();
204 bSameDist &= aNumFormatArr[i]->GetCharTextDistance() == aNumFormatArr[nLvl]->GetCharTextDistance();
205 bSameIndent &= aNumFormatArr[i]->GetFirstLineOffset() == aNumFormatArr[nLvl]->GetFirstLineOffset();
207 else
209 bSameLabelFollowedBy &=
210 aNumFormatArr[i]->GetLabelFollowedBy() == aNumFormatArr[nLvl]->GetLabelFollowedBy();
211 bSameListtab &=
212 aNumFormatArr[i]->GetListtabPos() == aNumFormatArr[nLvl]->GetListtabPos();
213 bSameAlignAt &=
214 ( ( aNumFormatArr[i]->GetIndentAt() + aNumFormatArr[i]->GetFirstLineIndent() )
215 == ( aNumFormatArr[nLvl]->GetIndentAt() + aNumFormatArr[nLvl]->GetFirstLineIndent() ) );
216 bSameIndentAt &=
217 aNumFormatArr[i]->GetIndentAt() == aNumFormatArr[nLvl]->GetIndentAt();
221 nMask <<= 1;
224 if (MAXLEVEL <= nLvl)
226 OSL_ENSURE(false, "cannot happen.");
227 return;
229 if(bSameDistBorderNum)
231 long nDistBorderNum;
232 if(bRelative)
234 nDistBorderNum = static_cast<long>(aNumFormatArr[nLvl]->GetAbsLSpace())+ aNumFormatArr[nLvl]->GetFirstLineOffset();
235 if(nLvl)
236 nDistBorderNum -= static_cast<long>(aNumFormatArr[nLvl - 1]->GetAbsLSpace())+ aNumFormatArr[nLvl - 1]->GetFirstLineOffset();
238 else
240 nDistBorderNum = static_cast<long>(aNumFormatArr[nLvl]->GetAbsLSpace())+ aNumFormatArr[nLvl]->GetFirstLineOffset();
242 m_xDistBorderMF->set_value(m_xDistBorderMF->normalize(nDistBorderNum),FieldUnit::TWIP);
244 else
245 bSetDistEmpty = true;
247 if(bSameDist)
248 m_xDistNumMF->set_value(m_xDistNumMF->normalize(aNumFormatArr[nLvl]->GetCharTextDistance()), FieldUnit::TWIP);
249 else
250 m_xDistNumMF->set_text(OUString());
251 if(bSameIndent)
252 m_xIndentMF->set_value(m_xIndentMF->normalize(-aNumFormatArr[nLvl]->GetFirstLineOffset()), FieldUnit::TWIP);
253 else
254 m_xIndentMF->set_text(OUString());
256 if(bSameAdjust)
258 sal_Int32 nPos = 1; // centered
259 if(aNumFormatArr[nLvl]->GetNumAdjust() == SvxAdjust::Left)
260 nPos = 0;
261 else if(aNumFormatArr[nLvl]->GetNumAdjust() == SvxAdjust::Right)
262 nPos = 2;
263 m_xAlignLB->set_active(nPos);
264 m_xAlign2LB->set_active( nPos );
266 else
268 m_xAlignLB->set_active(-1);
269 m_xAlign2LB->set_active(-1);
272 if ( bSameLabelFollowedBy )
274 sal_Int32 nPos = 0; // LISTTAB
275 if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::SPACE )
277 nPos = 1;
279 else if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::NOTHING )
281 nPos = 2;
283 else if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::NEWLINE )
285 nPos = 3;
287 m_xLabelFollowedByLB->set_active(nPos);
289 else
291 m_xLabelFollowedByLB->set_active(-1);
294 if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::LISTTAB )
296 m_xListtabFT->set_sensitive(true);
297 m_xListtabMF->set_sensitive(true);
298 if ( bSameListtab )
300 m_xListtabMF->set_value(m_xListtabMF->normalize(aNumFormatArr[nLvl]->GetListtabPos()),FieldUnit::TWIP);
302 else
304 m_xListtabMF->set_text(OUString());
307 else
309 m_xListtabFT->set_sensitive( false );
310 m_xListtabMF->set_sensitive( false );
311 m_xListtabMF->set_text(OUString());
314 if ( bSameAlignAt )
316 m_xAlignedAtMF->set_value(
317 m_xAlignedAtMF->normalize( aNumFormatArr[nLvl]->GetIndentAt() +
318 aNumFormatArr[nLvl]->GetFirstLineIndent()),
319 FieldUnit::TWIP );
321 else
323 m_xAlignedAtMF->set_text(OUString());
326 if ( bSameIndentAt )
328 m_xIndentAtMF->set_value(
329 m_xIndentAtMF->normalize( aNumFormatArr[nLvl]->GetIndentAt()), FieldUnit::TWIP );
331 else
333 m_xIndentAtMF->set_text(OUString());
336 if (bSetDistEmpty)
337 m_xDistBorderMF->set_text(OUString());
339 bInInintControl = false;
342 void SwNumPositionTabPage::ActivatePage(const SfxItemSet& )
344 const SfxPoolItem* pItem;
345 sal_uInt16 nTmpNumLvl =
346 pOutlineDlg ? SwOutlineTabDialog::GetActNumLevel() : 0;
347 const SfxItemSet* pExampleSet = GetDialogExampleSet();
348 if(pExampleSet && pExampleSet->GetItemState(FN_PARAM_NUM_PRESET, false, &pItem) != SfxItemState::UNKNOWN)
350 bPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue();
352 bModified = (!pActNum->GetNumFormat( 0 ) || bPreset);
353 if(*pActNum != *pSaveNum ||
354 nActNumLvl != nTmpNumLvl )
356 *pActNum = *pSaveNum;
357 nActNumLvl = nTmpNumLvl;
358 sal_uInt16 nMask = 1;
359 m_xLevelLB->unselect_all();
360 if (nActNumLvl == USHRT_MAX)
361 m_xLevelLB->select(MAXLEVEL);
362 else
364 for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
366 if (nActNumLvl & nMask)
367 m_xLevelLB->select(i);
368 nMask <<= 1 ;
372 InitPosAndSpaceMode();
373 ShowControlsDependingOnPosAndSpaceMode();
375 InitControls();
377 m_xRelativeCB->set_sensitive(1 != nActNumLvl);
378 m_aPreviewWIN.Invalidate();
381 DeactivateRC SwNumPositionTabPage::DeactivatePage(SfxItemSet *_pSet)
383 SwOutlineTabDialog::SetActNumLevel(nActNumLvl);
384 if(_pSet)
385 FillItemSet(_pSet);
386 return DeactivateRC::LeavePage;
390 bool SwNumPositionTabPage::FillItemSet( SfxItemSet* rSet )
392 if(pOutlineDlg)
393 *pOutlineDlg->GetNumRule() = *pActNum;
394 else if(bModified && pActNum)
396 *pSaveNum = *pActNum;
397 rSet->Put(SwUINumRuleItem( *pSaveNum ));
398 rSet->Put(SfxBoolItem(FN_PARAM_NUM_PRESET, false));
400 return bModified;
403 void SwNumPositionTabPage::Reset( const SfxItemSet* rSet )
405 const SfxPoolItem* pItem;
406 if (pOutlineDlg)
408 pSaveNum = pOutlineDlg->GetNumRule();
409 m_xLevelLB->set_selection_mode(SelectionMode::Single);
411 else if(SfxItemState::SET == rSet->GetItemState(FN_PARAM_ACT_NUMBER, false, &pItem))
412 pSaveNum = const_cast<SwUINumRuleItem*>(static_cast<const SwUINumRuleItem*>(pItem))->GetNumRule();
414 nActNumLvl = SwOutlineTabDialog::GetActNumLevel();
415 sal_uInt16 nMask = 1;
416 m_xLevelLB->unselect_all();
417 if(nActNumLvl == USHRT_MAX)
419 m_xLevelLB->select(MAXLEVEL);
421 else
423 for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
425 if (nActNumLvl & nMask)
426 m_xLevelLB->select(i);
427 nMask <<= 1;
431 if(!pActNum)
432 pActNum.reset(new SwNumRule(*pSaveNum));
433 else if(*pSaveNum != *pActNum)
434 *pActNum = *pSaveNum;
435 m_aPreviewWIN.SetNumRule(pActNum.get());
436 InitPosAndSpaceMode();
437 ShowControlsDependingOnPosAndSpaceMode();
438 InitControls();
439 bModified = false;
442 void SwNumPositionTabPage::InitPosAndSpaceMode()
444 if ( pActNum == nullptr )
446 OSL_FAIL( "<SwNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" );
447 return;
450 SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode =
451 SvxNumberFormat::LABEL_ALIGNMENT;
452 sal_uInt16 nMask = 1;
453 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
455 if(nActNumLvl & nMask)
457 SvxNumberFormat aNumFormat( pActNum->Get(i) );
458 ePosAndSpaceMode = aNumFormat.GetPositionAndSpaceMode();
459 if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
461 break;
464 nMask <<= 1;
467 bLabelAlignmentPosAndSpaceModeActive =
468 ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT;
471 void SwNumPositionTabPage::ShowControlsDependingOnPosAndSpaceMode()
473 m_xDistBorderFT->set_visible( !bLabelAlignmentPosAndSpaceModeActive );
474 m_xDistBorderMF->set_visible( !bLabelAlignmentPosAndSpaceModeActive );
475 m_xRelativeCB->set_visible( !bLabelAlignmentPosAndSpaceModeActive );
476 m_xIndentFT->set_visible( !bLabelAlignmentPosAndSpaceModeActive );
477 m_xIndentMF->set_visible( !bLabelAlignmentPosAndSpaceModeActive );
478 m_xDistNumFT->set_visible( !bLabelAlignmentPosAndSpaceModeActive );
479 m_xDistNumMF->set_visible( !bLabelAlignmentPosAndSpaceModeActive );
480 m_xAlignFT->set_visible( !bLabelAlignmentPosAndSpaceModeActive );
481 m_xAlignLB->set_visible( !bLabelAlignmentPosAndSpaceModeActive );
483 m_xLabelFollowedByFT->set_visible( bLabelAlignmentPosAndSpaceModeActive );
484 m_xLabelFollowedByLB->set_visible( bLabelAlignmentPosAndSpaceModeActive );
485 m_xListtabFT->set_visible( bLabelAlignmentPosAndSpaceModeActive );
486 m_xListtabMF->set_visible( bLabelAlignmentPosAndSpaceModeActive );
487 m_xAlign2FT->set_visible( bLabelAlignmentPosAndSpaceModeActive );
488 m_xAlign2LB->set_visible( bLabelAlignmentPosAndSpaceModeActive );
489 m_xAlignedAtFT->set_visible( bLabelAlignmentPosAndSpaceModeActive );
490 m_xAlignedAtMF->set_visible( bLabelAlignmentPosAndSpaceModeActive );
491 m_xIndentAtFT->set_visible( bLabelAlignmentPosAndSpaceModeActive );
492 m_xIndentAtMF->set_visible( bLabelAlignmentPosAndSpaceModeActive );
495 std::unique_ptr<SfxTabPage> SwNumPositionTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
496 const SfxItemSet* rAttrSet)
498 return std::make_unique<SwNumPositionTabPage>(pPage, pController, *rAttrSet);
501 void SwNumPositionTabPage::SetWrtShell(SwWrtShell* pSh)
503 pWrtSh = pSh;
505 const SwTwips nWidth = pWrtSh->GetAnyCurRect(CurRectType::Frame).Width();
507 m_xDistBorderMF->set_max(m_xDistBorderMF->normalize( nWidth ), FieldUnit::TWIP );
508 m_xDistNumMF->set_max(m_xDistNumMF->normalize( nWidth ), FieldUnit::TWIP);
509 m_xIndentMF->set_max(m_xIndentMF->normalize( nWidth ), FieldUnit::TWIP );
510 m_xListtabMF->set_max(m_xListtabMF->normalize( nWidth ), FieldUnit::TWIP );
511 m_xAlignedAtMF->set_max(m_xAlignedAtMF->normalize( nWidth ), FieldUnit::TWIP );
512 m_xIndentAtMF->set_max(m_xIndentAtMF->normalize( nWidth ), FieldUnit::TWIP );
514 const SwRect& rPrtRect = pWrtSh->GetAnyCurRect(CurRectType::Page);
515 m_aPreviewWIN.SetPageWidth(rPrtRect.Width());
516 FieldUnit eMetric = ::GetDfltMetric( dynamic_cast<SwWebView*>( &pWrtSh->GetView()) != nullptr );
517 if(eMetric == FieldUnit::MM)
519 m_xDistBorderMF->set_digits(1);
520 m_xDistNumMF->set_digits(1);
521 m_xIndentMF->set_digits(1);
522 m_xListtabMF->set_digits(1);
523 m_xAlignedAtMF->set_digits(1);
524 m_xIndentAtMF->set_digits(1);
526 m_xDistBorderMF->set_unit( eMetric );
527 m_xDistNumMF->set_unit( eMetric );
528 m_xIndentMF->set_unit( eMetric );
529 m_xListtabMF->set_unit( eMetric );
530 m_xAlignedAtMF->set_unit( eMetric );
531 m_xIndentAtMF->set_unit( eMetric );
534 IMPL_LINK_NOARG(SwNumPositionTabPage, EditModifyHdl, weld::ComboBox&, void)
536 sal_uInt16 nMask = 1;
537 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
539 if(nActNumLvl & nMask)
541 SwNumFormat aNumFormat(pActNum->Get(i));
543 const int nPos = m_xAlignLB->get_visible()
544 ? m_xAlignLB->get_active()
545 : m_xAlign2LB->get_active();
546 SvxAdjust eAdjust = SvxAdjust::Center;
547 if(nPos == 0)
548 eAdjust = SvxAdjust::Left;
549 else if(nPos == 2)
550 eAdjust = SvxAdjust::Right;
551 aNumFormat.SetNumAdjust( eAdjust );
552 pActNum->Set(i, aNumFormat);
554 nMask <<= 1;
556 SetModified();
559 IMPL_LINK( SwNumPositionTabPage, LevelHdl, weld::TreeView&, rBox, void )
561 sal_uInt16 nSaveNumLvl = nActNumLvl;
562 nActNumLvl = 0;
563 auto aRows = rBox.get_selected_rows();
564 if ((std::find(aRows.begin(), aRows.end(), MAXLEVEL) != aRows.end()) &&
565 (aRows.size() == 1 || nSaveNumLvl != 0xffff))
567 nActNumLvl = 0xFFFF;
568 for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
569 rBox.unselect(i);
571 else if (!aRows.empty())
573 sal_uInt16 nMask = 1;
574 for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
576 if (std::find(aRows.begin(), aRows.end(), i) != aRows.end())
577 nActNumLvl |= nMask;
578 nMask <<= 1;
580 rBox.unselect(MAXLEVEL);
582 else
584 nActNumLvl = nSaveNumLvl;
585 sal_uInt16 nMask = 1;
586 for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
588 if(nActNumLvl & nMask)
590 rBox.select(i);
591 break;
593 nMask <<=1;
596 m_xRelativeCB->set_sensitive(1 != nActNumLvl);
597 SetModified();
598 InitPosAndSpaceMode();
599 ShowControlsDependingOnPosAndSpaceMode();
600 InitControls();
603 IMPL_LINK(SwNumPositionTabPage, DistanceHdl, weld::MetricSpinButton&, rField, void)
605 if(bInInintControl)
606 return;
607 long nValue = static_cast< long >(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
608 sal_uInt16 nMask = 1;
609 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
611 if(nActNumLvl & nMask)
613 SwNumFormat aNumFormat( pActNum->Get( i ) );
614 if (&rField == m_xDistBorderMF.get())
617 if (m_xRelativeCB->get_active() && m_xRelativeCB->get_sensitive())
619 if(0 == i)
621 auto const nTmp = aNumFormat.GetFirstLineOffset();
622 aNumFormat.SetAbsLSpace( nValue - nTmp );
624 else
626 long nTmp = pActNum->Get( i - 1 ).GetAbsLSpace() +
627 pActNum->Get( i - 1 ).GetFirstLineOffset() -
628 pActNum->Get( i ).GetFirstLineOffset();
630 aNumFormat.SetAbsLSpace( nValue + nTmp );
633 else
635 aNumFormat.SetAbsLSpace( nValue - aNumFormat.GetFirstLineOffset());
638 else if (&rField == m_xDistNumMF.get())
640 aNumFormat.SetCharTextDistance( nValue );
642 else if (&rField == m_xIndentMF.get())
644 // now AbsLSpace also has to be modified by FirstLineOffset
645 long nDiff = nValue + aNumFormat.GetFirstLineOffset();
646 auto const nAbsLSpace = aNumFormat.GetAbsLSpace();
647 aNumFormat.SetAbsLSpace( nAbsLSpace + nDiff );
648 aNumFormat.SetFirstLineOffset( -nValue );
651 pActNum->Set( i, aNumFormat );
653 nMask <<= 1;
656 SetModified();
657 if(!m_xDistBorderMF->get_sensitive())
658 m_xDistBorderMF->set_text(OUString());
661 IMPL_LINK( SwNumPositionTabPage, RelativeHdl, weld::ToggleButton&, rBox, void )
663 bool bOn = rBox.get_active();
664 bool bSingleSelection = m_xLevelLB->n_children() == 1 && USHRT_MAX != nActNumLvl;
665 bool bSetValue = false;
666 long nValue = 0;
667 if(bOn || bSingleSelection)
669 sal_uInt16 nMask = 1;
670 bool bFirst = true;
671 bSetValue = true;
672 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
674 if(nActNumLvl & nMask)
676 const SwNumFormat &rNumFormat = pActNum->Get(i);
677 if(bFirst)
679 nValue = rNumFormat.GetAbsLSpace();
680 if(bOn && i)
681 nValue -= pActNum->Get(i - 1).GetAbsLSpace();
683 else
684 bSetValue = nValue == rNumFormat.GetAbsLSpace() - pActNum->Get(i - 1).GetAbsLSpace();
685 bFirst = false;
687 nMask <<= 1;
691 if(bSetValue)
692 m_xDistBorderMF->set_value(m_xDistBorderMF->normalize(nValue), FieldUnit::TWIP);
693 else
694 m_xDistBorderMF->set_text(OUString());
695 m_xDistBorderMF->set_sensitive(bOn || bSingleSelection || pOutlineDlg);
696 bLastRelative = bOn;
699 IMPL_LINK_NOARG(SwNumPositionTabPage, LabelFollowedByHdl_Impl, weld::ComboBox&, void)
701 // determine value to be set at the chosen list levels
702 SvxNumberFormat::LabelFollowedBy eLabelFollowedBy = SvxNumberFormat::LISTTAB;
704 const int nPos = m_xLabelFollowedByLB->get_active();
705 if ( nPos == 1 )
707 eLabelFollowedBy = SvxNumberFormat::SPACE;
709 else if ( nPos == 2 )
711 eLabelFollowedBy = SvxNumberFormat::NOTHING;
713 else if ( nPos == 3 )
715 eLabelFollowedBy = SvxNumberFormat::NEWLINE;
719 // set value at the chosen list levels
720 bool bSameListtabPos = true;
721 sal_uInt16 nFirstLvl = USHRT_MAX;
722 sal_uInt16 nMask = 1;
723 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
725 if ( nActNumLvl & nMask )
727 SwNumFormat aNumFormat( pActNum->Get(i) );
728 aNumFormat.SetLabelFollowedBy( eLabelFollowedBy );
729 pActNum->Set( i, aNumFormat );
731 if ( nFirstLvl == USHRT_MAX )
733 nFirstLvl = i;
735 else
737 bSameListtabPos &= aNumFormat.GetListtabPos() ==
738 pActNum->Get( nFirstLvl ).GetListtabPos();
741 nMask <<= 1;
744 // enable/disable metric field for list tab stop position depending on
745 // selected item following the list label.
746 m_xListtabFT->set_sensitive( eLabelFollowedBy == SvxNumberFormat::LISTTAB );
747 m_xListtabMF->set_sensitive( eLabelFollowedBy == SvxNumberFormat::LISTTAB );
748 if ( bSameListtabPos && eLabelFollowedBy == SvxNumberFormat::LISTTAB )
750 m_xListtabMF->set_value(
751 m_xListtabMF->normalize( pActNum->Get( nFirstLvl ).GetListtabPos() ),
752 FieldUnit::TWIP );
754 else
756 m_xListtabMF->set_text(OUString());
759 SetModified();
762 IMPL_LINK( SwNumPositionTabPage, ListtabPosHdl_Impl, weld::MetricSpinButton&, rField, void )
764 // determine value to be set at the chosen list levels
765 const long nValue = static_cast< long >(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
767 // set value at the chosen list levels
768 sal_uInt16 nMask = 1;
769 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
771 if ( nActNumLvl & nMask )
773 SwNumFormat aNumFormat( pActNum->Get(i) );
774 aNumFormat.SetListtabPos( nValue );
775 pActNum->Set( i, aNumFormat );
777 nMask <<= 1;
780 SetModified();
783 IMPL_LINK( SwNumPositionTabPage, AlignAtHdl_Impl, weld::MetricSpinButton&, rField, void )
785 // determine value to be set at the chosen list levels
786 const long nValue = static_cast< long >(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
788 // set value at the chosen list levels
789 sal_uInt16 nMask = 1;
790 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
792 if ( nActNumLvl & nMask )
794 SwNumFormat aNumFormat( pActNum->Get(i) );
795 const long nFirstLineIndent = nValue - aNumFormat.GetIndentAt();
796 aNumFormat.SetFirstLineIndent( nFirstLineIndent );
797 pActNum->Set( i, aNumFormat );
799 nMask <<= 1;
802 SetModified();
805 IMPL_LINK( SwNumPositionTabPage, IndentAtHdl_Impl, weld::MetricSpinButton&, rField, void )
807 // determine value to be set at the chosen list levels
808 const long nValue = static_cast< long >(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
810 // set value at the chosen list levels
811 sal_uInt16 nMask = 1;
812 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
814 if ( nActNumLvl & nMask )
816 SwNumFormat aNumFormat( pActNum->Get(i) );
817 const long nAlignedAt = aNumFormat.GetIndentAt() +
818 aNumFormat.GetFirstLineIndent();
819 aNumFormat.SetIndentAt( nValue );
820 const long nNewFirstLineIndent = nAlignedAt - nValue;
821 aNumFormat.SetFirstLineIndent( nNewFirstLineIndent );
822 pActNum->Set( i, aNumFormat );
824 nMask <<= 1;
827 SetModified();
830 IMPL_LINK_NOARG(SwNumPositionTabPage, StandardHdl, weld::Button&, void)
832 sal_uInt16 nMask = 1;
833 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
835 if(nActNumLvl & nMask)
837 SwNumFormat aNumFormat( pActNum->Get( i ) );
838 SwNumRule aTmpNumRule( pWrtSh->GetUniqueNumRuleName(),
839 aNumFormat.GetPositionAndSpaceMode(),
840 pOutlineDlg ? OUTLINE_RULE : NUM_RULE );
841 const SwNumFormat& aTempFormat(aTmpNumRule.Get( i ));
842 aNumFormat.SetPositionAndSpaceMode( aTempFormat.GetPositionAndSpaceMode() );
843 if ( aTempFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
845 aNumFormat.SetAbsLSpace( aTempFormat.GetAbsLSpace());
846 aNumFormat.SetCharTextDistance( aTempFormat.GetCharTextDistance() );
847 aNumFormat.SetFirstLineOffset( aTempFormat.GetFirstLineOffset() );
849 else if ( aTempFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
851 aNumFormat.SetNumAdjust( aTempFormat.GetNumAdjust() );
852 aNumFormat.SetLabelFollowedBy( aTempFormat.GetLabelFollowedBy() );
853 aNumFormat.SetListtabPos( aTempFormat.GetListtabPos() );
854 aNumFormat.SetFirstLineIndent( aTempFormat.GetFirstLineIndent() );
855 aNumFormat.SetIndentAt( aTempFormat.GetIndentAt() );
857 pActNum->Set( i, aNumFormat );
859 nMask <<= 1;
862 InitControls();
863 SetModified();
866 #ifdef DBG_UTIL
867 void SwNumPositionTabPage::SetModified()
869 bModified = true;
870 m_aPreviewWIN.SetLevel(nActNumLvl);
871 m_aPreviewWIN.Invalidate();
873 #endif
875 SwSvxNumBulletTabDialog::SwSvxNumBulletTabDialog(weld::Window* pParent,
876 const SfxItemSet* pSwItemSet, SwWrtShell & rSh)
877 : SfxTabDialogController(pParent, "modules/swriter/ui/bulletsandnumbering.ui", "BulletsAndNumberingDialog",
878 pSwItemSet)
879 , rWrtSh(rSh)
880 , m_xDummyCombo(m_xBuilder->weld_combo_box("dummycombo"))
882 weld::Button* pButton = GetUserButton();
883 pButton->connect_clicked(LINK(this, SwSvxNumBulletTabDialog, RemoveNumberingHdl));
884 pButton->set_sensitive(rWrtSh.GetNumRuleAtCurrCursorPos() != nullptr);
885 AddTabPage("singlenum", RID_SVXPAGE_PICK_SINGLE_NUM );
886 AddTabPage("bullets", RID_SVXPAGE_PICK_BULLET );
887 AddTabPage("outlinenum", RID_SVXPAGE_PICK_NUM );
888 AddTabPage("graphics", RID_SVXPAGE_PICK_BMP );
890 if (comphelper::LibreOfficeKit::isActive())
892 RemoveTabPage("customize");
894 else
896 AddTabPage("customize", RID_SVXPAGE_NUM_OPTIONS );
899 AddTabPage("position", RID_SVXPAGE_NUM_POSITION );
902 SwSvxNumBulletTabDialog::~SwSvxNumBulletTabDialog()
906 void SwSvxNumBulletTabDialog::PageCreated(const OString& rPageId, SfxTabPage& rPage)
908 // set styles' names and metric
909 OUString sNumCharFormat, sBulletCharFormat;
910 SwStyleNameMapper::FillUIName( RES_POOLCHR_NUM_LEVEL, sNumCharFormat );
911 SwStyleNameMapper::FillUIName( RES_POOLCHR_BUL_LEVEL, sBulletCharFormat );
913 if (rPageId == "singlenum")
915 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
916 aSet.Put (SfxStringItem(SID_NUM_CHAR_FMT,sNumCharFormat));
917 aSet.Put (SfxStringItem(SID_BULLET_CHAR_FMT,sBulletCharFormat));
918 rPage.PageCreated(aSet);
920 else if (rPageId == "bullets")
922 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
923 aSet.Put (SfxStringItem(SID_BULLET_CHAR_FMT,sBulletCharFormat));
924 rPage.PageCreated(aSet);
926 else if (rPageId == "customize")
928 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
929 aSet.Put (SfxStringItem(SID_NUM_CHAR_FMT,sNumCharFormat));
930 aSet.Put (SfxStringItem(SID_BULLET_CHAR_FMT,sBulletCharFormat));
931 // collect char styles
932 m_xDummyCombo->clear();
933 m_xDummyCombo->append_text(SwViewShell::GetShellRes()->aStrNone);
934 SwDocShell* pDocShell = rWrtSh.GetView().GetDocShell();
935 ::FillCharStyleListBox(*m_xDummyCombo, pDocShell);
937 std::vector<OUString> aList;
938 aList.reserve(m_xDummyCombo->get_count());
939 for (sal_Int32 j = 0; j < m_xDummyCombo->get_count(); j++)
940 aList.push_back(m_xDummyCombo->get_text(j));
942 aSet.Put( SfxStringListItem( SID_CHAR_FMT_LIST_BOX,&aList ) ) ;
944 FieldUnit eMetric = ::GetDfltMetric(dynamic_cast< const SwWebDocShell *>( pDocShell ) != nullptr);
945 aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< sal_uInt16 >(eMetric) ) );
946 rPage.PageCreated(aSet);
948 else if (rPageId == "position")
950 SwDocShell* pDocShell = rWrtSh.GetView().GetDocShell();
951 FieldUnit eMetric = ::GetDfltMetric(dynamic_cast< const SwWebDocShell *>( pDocShell ) != nullptr);
952 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
953 aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< sal_uInt16 >(eMetric)) );
954 rPage.PageCreated(aSet);
958 short SwSvxNumBulletTabDialog::Ok()
960 short nRet = SfxTabDialogController::Ok();
961 m_xExampleSet->ClearItem(SID_PARAM_NUM_PRESET);
962 return nRet;
965 IMPL_LINK_NOARG(SwSvxNumBulletTabDialog, RemoveNumberingHdl, weld::Button&, void)
967 m_xDialog->response(RET_USER);
970 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */