LibreOffice Module sw (master)  1
num.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 <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>
32 
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>
41 
42 static bool bLastRelative = false;
43 
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
49  : SfxTabPage(pPage, pController, "modules/swriter/ui/outlinepositionpage.ui", "OutlinePositionPage", &rSet)
50  , pSaveNum(nullptr)
51  , pWrtSh(nullptr)
52  , pOutlineDlg(nullptr)
53  , nActNumLvl(0)
54  , bModified(false)
55  , bPreset(false)
56  , bInInintControl(false)
57  , 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))
81 {
83 
84  m_xLevelLB->set_selection_mode(SelectionMode::Multiple);
85 
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)
90  {
91  m_xAlign2LB->append_text(m_xAlignLB->get_text(i));
92  }
93  m_xAlign2FT->set_label(m_xAlignFT->get_label());
94 
96  m_xDistBorderMF->connect_value_changed(aLk);
97  m_xDistNumMF->connect_value_changed(aLk);
98  m_xIndentMF->connect_value_changed(aLk);
99 
100  m_xLabelFollowedByLB->connect_changed( LINK(this, SwNumPositionTabPage, LabelFollowedByHdl_Impl) );
101 
102  aLk = LINK(this, SwNumPositionTabPage, ListtabPosHdl_Impl);
103  m_xListtabMF->connect_value_changed(aLk);
104 
105  aLk = LINK(this, SwNumPositionTabPage, AlignAtHdl_Impl);
106  m_xAlignedAtMF->connect_value_changed(aLk);
107 
108  aLk = LINK(this, SwNumPositionTabPage, IndentAtHdl_Impl);
109  m_xIndentAtMF->connect_value_changed(aLk);
110 
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));
114 
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);
121 
122  m_xRelativeCB->set_active(bLastRelative);
124 }
125 
127 {
128  pActNum.reset();
129  pOutlineDlg = nullptr;
130 }
131 
133 {
134  bInInintControl = true;
135  const bool bRelative = !bLabelAlignmentPosAndSpaceModeActive &&
136  m_xRelativeCB->get_sensitive() && m_xRelativeCB->get_active();
137  const bool bSingleSelection = m_xLevelLB->count_selected_rows() == 1 &&
138  USHRT_MAX != nActNumLvl;
139 
141  ( bSingleSelection || bRelative || pOutlineDlg != nullptr ) );
143  ( bSingleSelection || bRelative || pOutlineDlg != nullptr ) );
144 
145  bool bSetDistEmpty = false;
146  bool bSameDistBorderNum = !bLabelAlignmentPosAndSpaceModeActive;
147  bool bSameDist = !bLabelAlignmentPosAndSpaceModeActive;
148  bool bSameIndent = !bLabelAlignmentPosAndSpaceModeActive;
149  bool bSameAdjust = true;
150 
151  bool bSameLabelFollowedBy = bLabelAlignmentPosAndSpaceModeActive;
152  bool bSameListtab = bLabelAlignmentPosAndSpaceModeActive;
153  bool bSameAlignAt = bLabelAlignmentPosAndSpaceModeActive;
154  bool bSameIndentAt = bLabelAlignmentPosAndSpaceModeActive;
155 
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++)
161  {
162  aNumFormatArr[i] = &pActNum->Get(i);
163  if(nActNumLvl & nMask)
164  {
165  if(USHRT_MAX == nLvl)
166  {
167  nLvl = i;
168  }
169 
170  if( i > nLvl)
171  {
172  bSameAdjust &= aNumFormatArr[i]->GetNumAdjust() == aNumFormatArr[nLvl]->GetNumAdjust();
174  {
175  if(bRelative)
176  {
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;
184  }
185  else
186  {
187  bSameDistBorderNum &=
188  aNumFormatArr[i]->GetAbsLSpace() - aNumFormatArr[i]->GetFirstLineOffset() ==
189  aNumFormatArr[i - 1]->GetAbsLSpace() - aNumFormatArr[i - 1]->GetFirstLineOffset();
190  }
191 
192  bSameDist &= aNumFormatArr[i]->GetCharTextDistance() == aNumFormatArr[nLvl]->GetCharTextDistance();
193  bSameIndent &= aNumFormatArr[i]->GetFirstLineOffset() == aNumFormatArr[nLvl]->GetFirstLineOffset();
194  }
195  else
196  {
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();
206  }
207  }
208  }
209  nMask <<= 1;
210 
211  }
212  if (MAXLEVEL <= nLvl)
213  {
214  OSL_ENSURE(false, "cannot happen.");
215  return;
216  }
217  if(bSameDistBorderNum)
218  {
219  tools::Long nDistBorderNum;
220  if(bRelative)
221  {
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();
225  }
226  else
227  {
228  nDistBorderNum = static_cast<tools::Long>(aNumFormatArr[nLvl]->GetAbsLSpace())+ aNumFormatArr[nLvl]->GetFirstLineOffset();
229  }
230  m_xDistBorderMF->set_value(m_xDistBorderMF->normalize(nDistBorderNum),FieldUnit::TWIP);
231  }
232  else
233  bSetDistEmpty = true;
234 
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());
243 
244  if(bSameAdjust)
245  {
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 );
253  }
254  else
255  {
256  m_xAlignLB->set_active(-1);
257  m_xAlign2LB->set_active(-1);
258  }
259 
260  if ( bSameLabelFollowedBy )
261  {
262  sal_Int32 nPos = 0; // LISTTAB
263  if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::SPACE )
264  {
265  nPos = 1;
266  }
267  else if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::NOTHING )
268  {
269  nPos = 2;
270  }
271  else if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::NEWLINE )
272  {
273  nPos = 3;
274  }
275  m_xLabelFollowedByLB->set_active(nPos);
276  }
277  else
278  {
279  m_xLabelFollowedByLB->set_active(-1);
280  }
281 
282  if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::LISTTAB )
283  {
284  m_xListtabFT->set_sensitive(true);
285  m_xListtabMF->set_sensitive(true);
286  if ( bSameListtab )
287  {
288  m_xListtabMF->set_value(m_xListtabMF->normalize(aNumFormatArr[nLvl]->GetListtabPos()),FieldUnit::TWIP);
289  }
290  else
291  {
292  m_xListtabMF->set_text(OUString());
293  }
294  }
295  else
296  {
297  m_xListtabFT->set_sensitive( false );
298  m_xListtabMF->set_sensitive( false );
299  m_xListtabMF->set_text(OUString());
300  }
301 
302  if ( bSameAlignAt )
303  {
304  m_xAlignedAtMF->set_value(
305  m_xAlignedAtMF->normalize( aNumFormatArr[nLvl]->GetIndentAt() +
306  aNumFormatArr[nLvl]->GetFirstLineIndent()),
307  FieldUnit::TWIP );
308  }
309  else
310  {
311  m_xAlignedAtMF->set_text(OUString());
312  }
313 
314  if ( bSameIndentAt )
315  {
316  m_xIndentAtMF->set_value(
317  m_xIndentAtMF->normalize( aNumFormatArr[nLvl]->GetIndentAt()), FieldUnit::TWIP );
318  }
319  else
320  {
321  m_xIndentAtMF->set_text(OUString());
322  }
323 
324  if (bSetDistEmpty)
325  m_xDistBorderMF->set_text(OUString());
326 
327  bInInintControl = false;
328 }
329 
331 {
332  const SfxPoolItem* pItem;
333  sal_uInt16 nTmpNumLvl =
335  const SfxItemSet* pExampleSet = GetDialogExampleSet();
336  if(pExampleSet && pExampleSet->GetItemState(FN_PARAM_NUM_PRESET, false, &pItem) != SfxItemState::UNKNOWN)
337  {
338  bPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue();
339  }
340  bModified = (!pActNum->GetNumFormat( 0 ) || bPreset);
341  if(*pActNum != *pSaveNum ||
342  nActNumLvl != nTmpNumLvl )
343  {
344  *pActNum = *pSaveNum;
345  nActNumLvl = nTmpNumLvl;
346  sal_uInt16 nMask = 1;
347  m_xLevelLB->unselect_all();
348  if (nActNumLvl == USHRT_MAX)
349  m_xLevelLB->select(MAXLEVEL);
350  else
351  {
352  for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
353  {
354  if (nActNumLvl & nMask)
355  m_xLevelLB->select(i);
356  nMask <<= 1 ;
357  }
358  }
359 
362 
363  InitControls();
364  }
365  m_xRelativeCB->set_sensitive(1 != nActNumLvl);
367 }
368 
370 {
372  if(_pSet)
373  FillItemSet(_pSet);
374  return DeactivateRC::LeavePage;
375 
376 }
377 
379 {
380  if(pOutlineDlg)
382  else if(bModified && pActNum)
383  {
384  *pSaveNum = *pActNum;
385  rSet->Put(SwUINumRuleItem( *pSaveNum ));
386  rSet->Put(SfxBoolItem(FN_PARAM_NUM_PRESET, false));
387  }
388  return bModified;
389 }
390 
392 {
393  const SfxPoolItem* pItem;
394  if (pOutlineDlg)
395  {
397  m_xLevelLB->set_selection_mode(SelectionMode::Single);
398  }
399  else if(SfxItemState::SET == rSet->GetItemState(FN_PARAM_ACT_NUMBER, false, &pItem))
400  pSaveNum = const_cast<SwUINumRuleItem*>(static_cast<const SwUINumRuleItem*>(pItem))->GetNumRule();
401 
403  sal_uInt16 nMask = 1;
404  m_xLevelLB->unselect_all();
405  if(nActNumLvl == USHRT_MAX)
406  {
407  m_xLevelLB->select(MAXLEVEL);
408  }
409  else
410  {
411  for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
412  {
413  if (nActNumLvl & nMask)
414  m_xLevelLB->select(i);
415  nMask <<= 1;
416  }
417  }
418 
419  if(!pActNum)
420  pActNum.reset(new SwNumRule(*pSaveNum));
421  else if(*pSaveNum != *pActNum)
422  *pActNum = *pSaveNum;
426  InitControls();
427  bModified = false;
428 }
429 
431 {
432  if ( pActNum == nullptr )
433  {
434  OSL_FAIL( "<SwNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" );
435  return;
436  }
437 
440  sal_uInt16 nMask = 1;
441  for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
442  {
443  if(nActNumLvl & nMask)
444  {
445  SvxNumberFormat aNumFormat( pActNum->Get(i) );
446  ePosAndSpaceMode = aNumFormat.GetPositionAndSpaceMode();
447  if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
448  {
449  break;
450  }
451  }
452  nMask <<= 1;
453  }
454 
456  ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT;
457 }
458 
460 {
470 
481 }
482 
483 std::unique_ptr<SfxTabPage> SwNumPositionTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
484  const SfxItemSet* rAttrSet)
485 {
486  return std::make_unique<SwNumPositionTabPage>(pPage, pController, *rAttrSet);
487 }
488 
490 {
491  pWrtSh = pSh;
492 
494 
495  m_xDistBorderMF->set_max(m_xDistBorderMF->normalize( nWidth ), FieldUnit::TWIP );
496  m_xDistNumMF->set_max(m_xDistNumMF->normalize( nWidth ), FieldUnit::TWIP);
497  m_xIndentMF->set_max(m_xIndentMF->normalize( nWidth ), FieldUnit::TWIP );
498  m_xListtabMF->set_max(m_xListtabMF->normalize( nWidth ), FieldUnit::TWIP );
499  m_xAlignedAtMF->set_max(m_xAlignedAtMF->normalize( nWidth ), FieldUnit::TWIP );
500  m_xIndentAtMF->set_max(m_xIndentAtMF->normalize( nWidth ), FieldUnit::TWIP );
501 
502  const SwRect& rPrtRect = pWrtSh->GetAnyCurRect(CurRectType::Page);
503  m_aPreviewWIN.SetPageWidth(rPrtRect.Width());
504  FieldUnit eMetric = ::GetDfltMetric( dynamic_cast<SwWebView*>( &pWrtSh->GetView()) != nullptr );
505  if(eMetric == FieldUnit::MM)
506  {
507  m_xDistBorderMF->set_digits(1);
508  m_xDistNumMF->set_digits(1);
509  m_xIndentMF->set_digits(1);
510  m_xListtabMF->set_digits(1);
511  m_xAlignedAtMF->set_digits(1);
512  m_xIndentAtMF->set_digits(1);
513  }
514  m_xDistBorderMF->set_unit( eMetric );
515  m_xDistNumMF->set_unit( eMetric );
516  m_xIndentMF->set_unit( eMetric );
517  m_xListtabMF->set_unit( eMetric );
518  m_xAlignedAtMF->set_unit( eMetric );
519  m_xIndentAtMF->set_unit( eMetric );
520 }
521 
523 {
524  sal_uInt16 nMask = 1;
525  for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
526  {
527  if(nActNumLvl & nMask)
528  {
529  SwNumFormat aNumFormat(pActNum->Get(i));
530 
531  const int nPos = m_xAlignLB->get_visible()
532  ? m_xAlignLB->get_active()
533  : m_xAlign2LB->get_active();
534  SvxAdjust eAdjust = SvxAdjust::Center;
535  if(nPos == 0)
536  eAdjust = SvxAdjust::Left;
537  else if(nPos == 2)
538  eAdjust = SvxAdjust::Right;
539  aNumFormat.SetNumAdjust( eAdjust );
540  pActNum->Set(i, aNumFormat);
541  }
542  nMask <<= 1;
543  }
544  SetModified();
545 }
546 
548 {
549  sal_uInt16 nSaveNumLvl = nActNumLvl;
550  nActNumLvl = 0;
551  auto aRows = rBox.get_selected_rows();
552  if ((std::find(aRows.begin(), aRows.end(), MAXLEVEL) != aRows.end()) &&
553  (aRows.size() == 1 || nSaveNumLvl != 0xffff))
554  {
555  nActNumLvl = 0xFFFF;
556  for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
557  rBox.unselect(i);
558  }
559  else if (!aRows.empty())
560  {
561  sal_uInt16 nMask = 1;
562  for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
563  {
564  if (std::find(aRows.begin(), aRows.end(), i) != aRows.end())
565  nActNumLvl |= nMask;
566  nMask <<= 1;
567  }
568  rBox.unselect(MAXLEVEL);
569  }
570  else
571  {
572  nActNumLvl = nSaveNumLvl;
573  sal_uInt16 nMask = 1;
574  for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
575  {
576  if(nActNumLvl & nMask)
577  {
578  rBox.select(i);
579  break;
580  }
581  nMask <<=1;
582  }
583  }
584  m_xRelativeCB->set_sensitive(1 != nActNumLvl);
585  SetModified();
586  InitPosAndSpaceMode();
587  ShowControlsDependingOnPosAndSpaceMode();
588  InitControls();
589 }
590 
592 {
593  if(bInInintControl)
594  return;
595  tools::Long nValue = static_cast< tools::Long >(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
596  sal_uInt16 nMask = 1;
597  for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
598  {
599  if(nActNumLvl & nMask)
600  {
601  SwNumFormat aNumFormat( pActNum->Get( i ) );
602  if (&rField == m_xDistBorderMF.get())
603  {
604 
605  if (m_xRelativeCB->get_active() && m_xRelativeCB->get_sensitive())
606  {
607  if(0 == i)
608  {
609  auto const nTmp = aNumFormat.GetFirstLineOffset();
610  aNumFormat.SetAbsLSpace( nValue - nTmp );
611  }
612  else
613  {
614  tools::Long nTmp = pActNum->Get( i - 1 ).GetAbsLSpace() +
615  pActNum->Get( i - 1 ).GetFirstLineOffset() -
616  pActNum->Get( i ).GetFirstLineOffset();
617 
618  aNumFormat.SetAbsLSpace( nValue + nTmp );
619  }
620  }
621  else
622  {
623  aNumFormat.SetAbsLSpace( nValue - aNumFormat.GetFirstLineOffset());
624  }
625  }
626  else if (&rField == m_xDistNumMF.get())
627  {
628  aNumFormat.SetCharTextDistance( nValue );
629  }
630  else if (&rField == m_xIndentMF.get())
631  {
632  // now AbsLSpace also has to be modified by FirstLineOffset
633  tools::Long nDiff = nValue + aNumFormat.GetFirstLineOffset();
634  auto const nAbsLSpace = aNumFormat.GetAbsLSpace();
635  aNumFormat.SetAbsLSpace( nAbsLSpace + nDiff );
636  aNumFormat.SetFirstLineOffset( -nValue );
637  }
638 
639  pActNum->Set( i, aNumFormat );
640  }
641  nMask <<= 1;
642  }
643 
644  SetModified();
645  if(!m_xDistBorderMF->get_sensitive())
646  m_xDistBorderMF->set_text(OUString());
647 }
648 
649 IMPL_LINK( SwNumPositionTabPage, RelativeHdl, weld::Toggleable&, rBox, void )
650 {
651  bool bOn = rBox.get_active();
652  bool bSingleSelection = m_xLevelLB->n_children() == 1 && USHRT_MAX != nActNumLvl;
653  bool bSetValue = false;
654  tools::Long nValue = 0;
655  if(bOn || bSingleSelection)
656  {
657  sal_uInt16 nMask = 1;
658  bool bFirst = true;
659  bSetValue = true;
660  for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
661  {
662  if(nActNumLvl & nMask)
663  {
664  const SwNumFormat &rNumFormat = pActNum->Get(i);
665  if(bFirst)
666  {
667  nValue = rNumFormat.GetAbsLSpace();
668  if(bOn && i)
669  nValue -= pActNum->Get(i - 1).GetAbsLSpace();
670  }
671  else
672  bSetValue = nValue == rNumFormat.GetAbsLSpace() - pActNum->Get(i - 1).GetAbsLSpace();
673  bFirst = false;
674  }
675  nMask <<= 1;
676  }
677 
678  }
679  if(bSetValue)
680  m_xDistBorderMF->set_value(m_xDistBorderMF->normalize(nValue), FieldUnit::TWIP);
681  else
682  m_xDistBorderMF->set_text(OUString());
683  m_xDistBorderMF->set_sensitive(bOn || bSingleSelection || pOutlineDlg);
684  bLastRelative = bOn;
685 }
686 
687 IMPL_LINK_NOARG(SwNumPositionTabPage, LabelFollowedByHdl_Impl, weld::ComboBox&, void)
688 {
689  // determine value to be set at the chosen list levels
691  {
692  const int nPos = m_xLabelFollowedByLB->get_active();
693  if ( nPos == 1 )
694  {
695  eLabelFollowedBy = SvxNumberFormat::SPACE;
696  }
697  else if ( nPos == 2 )
698  {
699  eLabelFollowedBy = SvxNumberFormat::NOTHING;
700  }
701  else if ( nPos == 3 )
702  {
703  eLabelFollowedBy = SvxNumberFormat::NEWLINE;
704  }
705  }
706 
707  // set value at the chosen list levels
708  bool bSameListtabPos = true;
709  sal_uInt16 nFirstLvl = USHRT_MAX;
710  sal_uInt16 nMask = 1;
711  for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
712  {
713  if ( nActNumLvl & nMask )
714  {
715  SwNumFormat aNumFormat( pActNum->Get(i) );
716  aNumFormat.SetLabelFollowedBy( eLabelFollowedBy );
717  pActNum->Set( i, aNumFormat );
718 
719  if ( nFirstLvl == USHRT_MAX )
720  {
721  nFirstLvl = i;
722  }
723  else
724  {
725  bSameListtabPos &= aNumFormat.GetListtabPos() ==
726  pActNum->Get( nFirstLvl ).GetListtabPos();
727  }
728  }
729  nMask <<= 1;
730  }
731 
732  // enable/disable metric field for list tab stop position depending on
733  // selected item following the list label.
734  m_xListtabFT->set_sensitive( eLabelFollowedBy == SvxNumberFormat::LISTTAB );
735  m_xListtabMF->set_sensitive( eLabelFollowedBy == SvxNumberFormat::LISTTAB );
736  if ( bSameListtabPos && eLabelFollowedBy == SvxNumberFormat::LISTTAB )
737  {
738  m_xListtabMF->set_value(
739  m_xListtabMF->normalize( pActNum->Get( nFirstLvl ).GetListtabPos() ),
740  FieldUnit::TWIP );
741  }
742  else
743  {
744  m_xListtabMF->set_text(OUString());
745  }
746 
747  SetModified();
748 }
749 
750 IMPL_LINK( SwNumPositionTabPage, ListtabPosHdl_Impl, weld::MetricSpinButton&, rField, void )
751 {
752  // determine value to be set at the chosen list levels
753  const tools::Long nValue = static_cast< tools::Long >(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
754 
755  // set value at the chosen list levels
756  sal_uInt16 nMask = 1;
757  for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
758  {
759  if ( nActNumLvl & nMask )
760  {
761  SwNumFormat aNumFormat( pActNum->Get(i) );
762  aNumFormat.SetListtabPos( nValue );
763  pActNum->Set( i, aNumFormat );
764  }
765  nMask <<= 1;
766  }
767 
768  SetModified();
769 }
770 
771 IMPL_LINK( SwNumPositionTabPage, AlignAtHdl_Impl, weld::MetricSpinButton&, rField, void )
772 {
773  // determine value to be set at the chosen list levels
774  const tools::Long nValue = static_cast< tools::Long >(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
775 
776  // set value at the chosen list levels
777  sal_uInt16 nMask = 1;
778  for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
779  {
780  if ( nActNumLvl & nMask )
781  {
782  SwNumFormat aNumFormat( pActNum->Get(i) );
783  const tools::Long nFirstLineIndent = nValue - aNumFormat.GetIndentAt();
784  aNumFormat.SetFirstLineIndent( nFirstLineIndent );
785  pActNum->Set( i, aNumFormat );
786  }
787  nMask <<= 1;
788  }
789 
790  SetModified();
791 }
792 
793 IMPL_LINK( SwNumPositionTabPage, IndentAtHdl_Impl, weld::MetricSpinButton&, rField, void )
794 {
795  // determine value to be set at the chosen list levels
796  const tools::Long nValue = static_cast< tools::Long >(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
797 
798  // set value at the chosen list levels
799  sal_uInt16 nMask = 1;
800  for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
801  {
802  if ( nActNumLvl & nMask )
803  {
804  SwNumFormat aNumFormat( pActNum->Get(i) );
805  const tools::Long nAlignedAt = aNumFormat.GetIndentAt() +
806  aNumFormat.GetFirstLineIndent();
807  aNumFormat.SetIndentAt( nValue );
808  const tools::Long nNewFirstLineIndent = nAlignedAt - nValue;
809  aNumFormat.SetFirstLineIndent( nNewFirstLineIndent );
810  pActNum->Set( i, aNumFormat );
811  }
812  nMask <<= 1;
813  }
814 
815  SetModified();
816 }
817 
819 {
820  sal_uInt16 nMask = 1;
821  for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
822  {
823  if(nActNumLvl & nMask)
824  {
825  SwNumFormat aNumFormat( pActNum->Get( i ) );
826  SwNumRule aTmpNumRule( pWrtSh->GetUniqueNumRuleName(),
827  aNumFormat.GetPositionAndSpaceMode(),
828  pOutlineDlg ? OUTLINE_RULE : NUM_RULE );
829  const SwNumFormat& aTempFormat(aTmpNumRule.Get( i ));
830  aNumFormat.SetPositionAndSpaceMode( aTempFormat.GetPositionAndSpaceMode() );
831  if ( aTempFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
832  {
833  aNumFormat.SetAbsLSpace( aTempFormat.GetAbsLSpace());
834  aNumFormat.SetCharTextDistance( aTempFormat.GetCharTextDistance() );
835  aNumFormat.SetFirstLineOffset( aTempFormat.GetFirstLineOffset() );
836  }
837  else if ( aTempFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
838  {
839  aNumFormat.SetNumAdjust( aTempFormat.GetNumAdjust() );
840  aNumFormat.SetLabelFollowedBy( aTempFormat.GetLabelFollowedBy() );
841  aNumFormat.SetListtabPos( aTempFormat.GetListtabPos() );
842  aNumFormat.SetFirstLineIndent( aTempFormat.GetFirstLineIndent() );
843  aNumFormat.SetIndentAt( aTempFormat.GetIndentAt() );
844  }
845  pActNum->Set( i, aNumFormat );
846  }
847  nMask <<= 1;
848  }
849 
850  InitControls();
851  SetModified();
852 }
853 
854 #ifdef DBG_UTIL
856 {
857  bModified = true;
860 }
861 #endif
862 
864  const SfxItemSet* pSwItemSet, SwWrtShell & rSh)
865  : SfxTabDialogController(pParent, "modules/swriter/ui/bulletsandnumbering.ui", "BulletsAndNumberingDialog",
866  pSwItemSet)
867  , rWrtSh(rSh)
868  , m_xDummyCombo(m_xBuilder->weld_combo_box("dummycombo"))
869 {
870  weld::Button* pButton = GetUserButton();
871  pButton->connect_clicked(LINK(this, SwSvxNumBulletTabDialog, RemoveNumberingHdl));
872  pButton->set_sensitive(rWrtSh.GetNumRuleAtCurrCursorPos() != nullptr);
873  AddTabPage("singlenum", RID_SVXPAGE_PICK_SINGLE_NUM );
874  AddTabPage("bullets", RID_SVXPAGE_PICK_BULLET );
875  AddTabPage("outlinenum", RID_SVXPAGE_PICK_NUM );
876  AddTabPage("graphics", RID_SVXPAGE_PICK_BMP );
877 
879  {
880  RemoveTabPage("customize");
881  }
882  else
883  {
884  AddTabPage("customize", RID_SVXPAGE_NUM_OPTIONS );
885  }
886 
887  AddTabPage("position", RID_SVXPAGE_NUM_POSITION );
888 }
889 
891 {
892 }
893 
894 void SwSvxNumBulletTabDialog::PageCreated(const OString& rPageId, SfxTabPage& rPage)
895 {
896  // set styles' names and metric
897  OUString sNumCharFormat, sBulletCharFormat;
900 
901  if (rPageId == "singlenum")
902  {
903  SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
904  aSet.Put (SfxStringItem(SID_NUM_CHAR_FMT,sNumCharFormat));
905  aSet.Put (SfxStringItem(SID_BULLET_CHAR_FMT,sBulletCharFormat));
906  rPage.PageCreated(aSet);
907  }
908  else if (rPageId == "bullets")
909  {
910  SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
911  aSet.Put (SfxStringItem(SID_BULLET_CHAR_FMT,sBulletCharFormat));
912  rPage.PageCreated(aSet);
913  }
914  else if (rPageId == "customize")
915  {
916  SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
917  aSet.Put (SfxStringItem(SID_NUM_CHAR_FMT,sNumCharFormat));
918  aSet.Put (SfxStringItem(SID_BULLET_CHAR_FMT,sBulletCharFormat));
919  // collect char styles
920  m_xDummyCombo->clear();
921  m_xDummyCombo->append_text(SwViewShell::GetShellRes()->aStrNone);
922  SwDocShell* pDocShell = rWrtSh.GetView().GetDocShell();
924 
925  std::vector<OUString> aList;
926  aList.reserve(m_xDummyCombo->get_count());
927  for (sal_Int32 j = 0; j < m_xDummyCombo->get_count(); j++)
928  aList.push_back(m_xDummyCombo->get_text(j));
929 
930  aSet.Put( SfxStringListItem( SID_CHAR_FMT_LIST_BOX,&aList ) ) ;
931 
932  FieldUnit eMetric = ::GetDfltMetric(dynamic_cast< const SwWebDocShell *>( pDocShell ) != nullptr);
933  aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< sal_uInt16 >(eMetric) ) );
934  rPage.PageCreated(aSet);
935  }
936  else if (rPageId == "position")
937  {
938  SwDocShell* pDocShell = rWrtSh.GetView().GetDocShell();
939  FieldUnit eMetric = ::GetDfltMetric(dynamic_cast< const SwWebDocShell *>( pDocShell ) != nullptr);
940  SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
941  aSet.Put ( SfxUInt16Item(SID_METRIC_ITEM, static_cast< sal_uInt16 >(eMetric)) );
942  rPage.PageCreated(aSet);
943  }
944 }
945 
947 {
948  short nRet = SfxTabDialogController::Ok();
949  m_xExampleSet->ClearItem(SID_PARAM_NUM_PRESET);
950  return nRet;
951 }
952 
954 {
955  m_xDialog->response(RET_USER);
956 }
957 
958 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: num.cxx:330
void SetWrtShell(SwWrtShell *pSh)
Definition: num.cxx:489
tools::Long GetFirstLineIndent() const
virtual short Ok() override
Definition: num.cxx:946
FieldUnit
void SetLabelFollowedBy(const LabelFollowedBy eLabelFollowedBy)
IMPL_LINK(SwNumPositionTabPage, LevelHdl, weld::TreeView &, rBox, void)
Definition: num.cxx:547
SwWrtShell * pWrtSh
Definition: num.hxx:34
NumberingPreview m_aPreviewWIN
Definition: num.hxx:44
virtual void PageCreated(const SfxAllItemSet &aSet)
static ShellResource * GetShellRes()
Definition: viewsh.cxx:2553
std::unique_ptr< weld::TreeView > m_xLevelLB
Definition: num.hxx:46
std::unique_ptr< weld::MetricSpinButton > m_xDistBorderMF
Definition: num.hxx:52
std::unique_ptr< weld::Label > m_xDistBorderFT
Definition: num.hxx:51
std::string GetValue
SW_DLLPUBLIC void FillCharStyleListBox(weld::ComboBox &rToFill, SwDocShell *pDocSh, bool bSorted=false, bool bWithDefault=false)
Definition: uitool.cxx:791
void SetModified()
Definition: num.cxx:855
const SwNumRule * GetNumRuleAtCurrCursorPos() const
Definition: ednumber.cxx:727
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
void SetPositionAndSpaceMode(SvxNumPositionAndSpaceMode ePositionAndSpaceMode)
const SwRect & GetAnyCurRect(CurRectType eType, const Point *pPt=nullptr, const css::uno::Reference< css::embed::XEmbeddedObject > &=css::uno::Reference< css::embed::XEmbeddedObject >()) const
Definition: fews.cxx:90
long Long
void SetLevel(sal_uInt16 nSet)
Definition: numprevw.hxx:62
std::unique_ptr< SfxItemSet > m_xExampleSet
void InitPosAndSpaceMode()
Definition: num.cxx:430
constexpr sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:93
void RemoveTabPage(const OString &rName)
tools::Long GetListtabPos() const
SwNumRule * pSaveNum
Definition: num.hxx:33
std::unique_ptr< weld::MetricSpinButton > m_xListtabMF
Definition: num.hxx:66
SfxItemSet * GetInputSetImpl()
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
virtual void PageCreated(const OString &rPageId, SfxTabPage &rPage) override
Definition: num.cxx:894
std::unique_ptr< weld::Label > m_xIndentFT
Definition: num.hxx:54
sal_uInt16 nActNumLvl
Definition: num.hxx:37
Used by the UI to modify the document model.
Definition: wrtsh.hxx:93
std::unique_ptr< weld::ComboBox > m_xAlignLB
Definition: num.hxx:59
virtual short Ok()
const SwView & GetView() const
Definition: wrtsh.hxx:431
virtual void Reset(const SfxItemSet *rSet) override
Definition: num.cxx:391
std::unique_ptr< weld::Label > m_xIndentAtFT
Definition: num.hxx:71
void SetExchangeSupport()
SwOutlineTabDialog * pOutlineDlg
Definition: num.hxx:36
short GetCharTextDistance() const
#define FN_PARAM_NUM_PRESET
Definition: cmdid.h:803
void Width(tools::Long nNew)
Definition: swrect.hxx:186
IMPL_LINK_NOARG(SwNumPositionTabPage, EditModifyHdl, weld::ComboBox &, void)
Definition: num.cxx:522
Numbering symbols.
Definition: poolfmt.hxx:117
std::unique_ptr< weld::Label > m_xLabelFollowedByFT
Definition: num.hxx:63
std::unique_ptr< weld::Label > m_xListtabFT
Definition: num.hxx:65
void connect_clicked(const Link< Button &, void > &rLink)
std::unique_ptr< weld::Label > m_xAlign2FT
Definition: num.hxx:67
SwSvxNumBulletTabDialog(weld::Window *pParent, const SfxItemSet *pSwItemSet, SwWrtShell &)
Definition: num.cxx:863
std::unique_ptr< SwNumRule > pActNum
Definition: num.hxx:32
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
virtual ~SwNumPositionTabPage() override
Definition: num.cxx:126
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:766
SvxAdjust
int i
SwNumRule * GetNumRule()
Definition: outline.hxx:58
LabelFollowedBy GetLabelFollowedBy() const
sal_Int32 GetAbsLSpace() const
std::unique_ptr< weld::Button > m_xStandardPB
Definition: num.hxx:73
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
Definition: num.cxx:483
std::unique_ptr< weld::Label > m_xAlignFT
Definition: num.hxx:58
std::unique_ptr< weld::Label > m_xDistNumFT
Definition: num.hxx:56
void SetNumRule(const SwNumRule *pNum)
Definition: numprevw.hxx:50
void SetPositionMode()
Definition: numprevw.hxx:60
void SetPageWidth(tools::Long nPgWidth)
Definition: numprevw.hxx:56
#define FN_PARAM_ACT_NUMBER
Definition: cmdid.h:801
std::unique_ptr< weld::MetricSpinButton > m_xDistNumMF
Definition: num.hxx:57
static void SetActNumLevel(sal_uInt16 nSet)
Definition: outline.hxx:63
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: num.cxx:378
SvxAdjust GetNumAdjust() const
bool bLabelAlignmentPosAndSpaceModeActive
Definition: num.hxx:42
SvxNumPositionAndSpaceMode GetPositionAndSpaceMode() const
const SfxItemSet * GetDialogExampleSet() const
tools::Long SwTwips
Definition: swtypes.hxx:52
SwDocShell * GetDocShell()
Definition: view.cxx:1122
SwNumPositionTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: num.cxx:48
SwWrtShell & rWrtSh
Definition: num.hxx:122
Rect of current page.
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
std::unique_ptr< weld::MetricSpinButton > m_xIndentMF
Definition: num.hxx:55
#define RET_USER
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: num.cxx:369
void AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
Reference< XExecutableDialog > m_xDialog
void InitControls()
Definition: num.cxx:132
std::unique_ptr< weld::CheckButton > m_xRelativeCB
Definition: num.hxx:53
sal_Int32 GetFirstLineOffset() const
std::unique_ptr< weld::ComboBox > m_xDummyCombo
Definition: num.hxx:128
DeactivateRC
std::unique_ptr< weld::MetricSpinButton > m_xAlignedAtMF
Definition: num.hxx:70
std::unique_ptr< weld::MetricSpinButton > m_xIndentAtMF
Definition: num.hxx:72
virtual ~SwSvxNumBulletTabDialog() override
Definition: num.cxx:890
std::unique_ptr< weld::ComboBox > m_xLabelFollowedByLB
Definition: num.hxx:64
static bool bLastRelative
Definition: num.cxx:42
weld::Button * GetUserButton() const
std::unique_ptr< weld::ComboBox > m_xAlign2LB
Definition: num.hxx:68
tools::Long GetIndentAt() const
SwNumRule * GetNumRule(SwTextFormatColl &rTextFormatColl)
determines the list style, which directly set at the given paragraph style
Definition: fmtcol.cxx:76
std::unique_ptr< weld::Label > m_xAlignedAtFT
Definition: num.hxx:69
sal_uInt16 nPos
virtual void set_sensitive(bool sensitive)=0
void SetListtabPos(const tools::Long nListtabPos)
sal_Int16 nValue
bool bInInintControl
Definition: num.hxx:41
Rect of current frame.
void ShowControlsDependingOnPosAndSpaceMode()
Definition: num.cxx:459
static sal_uInt16 GetActNumLevel()
Definition: outline.hxx:62