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 <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>
43 
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>
53 
54 static bool bLastRelative = false;
55 
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
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))
93 {
95 
96  m_xLevelLB->set_selection_mode(SelectionMode::Multiple);
97 
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)
102  {
103  m_xAlign2LB->append_text(m_xAlignLB->get_text(i));
104  }
105  m_xAlign2FT->set_label(m_xAlignFT->get_label());
106 
108  m_xDistBorderMF->connect_value_changed(aLk);
109  m_xDistNumMF->connect_value_changed(aLk);
110  m_xIndentMF->connect_value_changed(aLk);
111 
112  m_xLabelFollowedByLB->connect_changed( LINK(this, SwNumPositionTabPage, LabelFollowedByHdl_Impl) );
113 
114  aLk = LINK(this, SwNumPositionTabPage, ListtabPosHdl_Impl);
115  m_xListtabMF->connect_value_changed(aLk);
116 
117  aLk = LINK(this, SwNumPositionTabPage, AlignAtHdl_Impl);
118  m_xAlignedAtMF->connect_value_changed(aLk);
119 
120  aLk = LINK(this, SwNumPositionTabPage, IndentAtHdl_Impl);
121  m_xIndentAtMF->connect_value_changed(aLk);
122 
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));
126 
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);
133 
134  m_xRelativeCB->set_active(bLastRelative);
136 }
137 
139 {
140  pActNum.reset();
141  pOutlineDlg = nullptr;
142 }
143 
145 {
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 &&
151 
153  ( bSingleSelection || bRelative || pOutlineDlg != nullptr ) );
155  ( bSingleSelection || bRelative || pOutlineDlg != nullptr ) );
156 
157  bool bSetDistEmpty = false;
158  bool bSameDistBorderNum = !bLabelAlignmentPosAndSpaceModeActive;
159  bool bSameDist = !bLabelAlignmentPosAndSpaceModeActive;
160  bool bSameIndent = !bLabelAlignmentPosAndSpaceModeActive;
161  bool bSameAdjust = true;
162 
163  bool bSameLabelFollowedBy = bLabelAlignmentPosAndSpaceModeActive;
164  bool bSameListtab = bLabelAlignmentPosAndSpaceModeActive;
165  bool bSameAlignAt = bLabelAlignmentPosAndSpaceModeActive;
166  bool bSameIndentAt = bLabelAlignmentPosAndSpaceModeActive;
167 
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++)
173  {
174  aNumFormatArr[i] = &pActNum->Get(i);
175  if(nActNumLvl & nMask)
176  {
177  if(USHRT_MAX == nLvl)
178  {
179  nLvl = i;
180  }
181 
182  if( i > nLvl)
183  {
184  bSameAdjust &= aNumFormatArr[i]->GetNumAdjust() == aNumFormatArr[nLvl]->GetNumAdjust();
186  {
187  if(bRelative)
188  {
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;
196  }
197  else
198  {
199  bSameDistBorderNum &=
200  aNumFormatArr[i]->GetAbsLSpace() - aNumFormatArr[i]->GetFirstLineOffset() ==
201  aNumFormatArr[i - 1]->GetAbsLSpace() - aNumFormatArr[i - 1]->GetFirstLineOffset();
202  }
203 
204  bSameDist &= aNumFormatArr[i]->GetCharTextDistance() == aNumFormatArr[nLvl]->GetCharTextDistance();
205  bSameIndent &= aNumFormatArr[i]->GetFirstLineOffset() == aNumFormatArr[nLvl]->GetFirstLineOffset();
206  }
207  else
208  {
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();
218  }
219  }
220  }
221  nMask <<= 1;
222 
223  }
224  if (MAXLEVEL <= nLvl)
225  {
226  OSL_ENSURE(false, "cannot happen.");
227  return;
228  }
229  if(bSameDistBorderNum)
230  {
231  long nDistBorderNum;
232  if(bRelative)
233  {
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();
237  }
238  else
239  {
240  nDistBorderNum = static_cast<long>(aNumFormatArr[nLvl]->GetAbsLSpace())+ aNumFormatArr[nLvl]->GetFirstLineOffset();
241  }
242  m_xDistBorderMF->set_value(m_xDistBorderMF->normalize(nDistBorderNum),FieldUnit::TWIP);
243  }
244  else
245  bSetDistEmpty = true;
246 
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());
255 
256  if(bSameAdjust)
257  {
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 );
265  }
266  else
267  {
268  m_xAlignLB->set_active(-1);
269  m_xAlign2LB->set_active(-1);
270  }
271 
272  if ( bSameLabelFollowedBy )
273  {
274  sal_Int32 nPos = 0; // LISTTAB
275  if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::SPACE )
276  {
277  nPos = 1;
278  }
279  else if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::NOTHING )
280  {
281  nPos = 2;
282  }
283  else if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::NEWLINE )
284  {
285  nPos = 3;
286  }
287  m_xLabelFollowedByLB->set_active(nPos);
288  }
289  else
290  {
291  m_xLabelFollowedByLB->set_active(-1);
292  }
293 
294  if ( aNumFormatArr[nLvl]->GetLabelFollowedBy() == SvxNumberFormat::LISTTAB )
295  {
296  m_xListtabFT->set_sensitive(true);
297  m_xListtabMF->set_sensitive(true);
298  if ( bSameListtab )
299  {
300  m_xListtabMF->set_value(m_xListtabMF->normalize(aNumFormatArr[nLvl]->GetListtabPos()),FieldUnit::TWIP);
301  }
302  else
303  {
304  m_xListtabMF->set_text(OUString());
305  }
306  }
307  else
308  {
309  m_xListtabFT->set_sensitive( false );
310  m_xListtabMF->set_sensitive( false );
311  m_xListtabMF->set_text(OUString());
312  }
313 
314  if ( bSameAlignAt )
315  {
316  m_xAlignedAtMF->set_value(
317  m_xAlignedAtMF->normalize( aNumFormatArr[nLvl]->GetIndentAt() +
318  aNumFormatArr[nLvl]->GetFirstLineIndent()),
319  FieldUnit::TWIP );
320  }
321  else
322  {
323  m_xAlignedAtMF->set_text(OUString());
324  }
325 
326  if ( bSameIndentAt )
327  {
328  m_xIndentAtMF->set_value(
329  m_xIndentAtMF->normalize( aNumFormatArr[nLvl]->GetIndentAt()), FieldUnit::TWIP );
330  }
331  else
332  {
333  m_xIndentAtMF->set_text(OUString());
334  }
335 
336  if (bSetDistEmpty)
337  m_xDistBorderMF->set_text(OUString());
338 
339  bInInintControl = false;
340 }
341 
343 {
344  const SfxPoolItem* pItem;
345  sal_uInt16 nTmpNumLvl =
347  const SfxItemSet* pExampleSet = GetDialogExampleSet();
348  if(pExampleSet && pExampleSet->GetItemState(FN_PARAM_NUM_PRESET, false, &pItem) != SfxItemState::UNKNOWN)
349  {
350  bPreset = static_cast<const SfxBoolItem*>(pItem)->GetValue();
351  }
352  bModified = (!pActNum->GetNumFormat( 0 ) || bPreset);
353  if(*pActNum != *pSaveNum ||
354  nActNumLvl != nTmpNumLvl )
355  {
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
363  {
364  for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
365  {
366  if (nActNumLvl & nMask)
367  m_xLevelLB->select(i);
368  nMask <<= 1 ;
369  }
370  }
371 
374 
375  InitControls();
376  }
377  m_xRelativeCB->set_sensitive(1 != nActNumLvl);
379 }
380 
382 {
384  if(_pSet)
385  FillItemSet(_pSet);
386  return DeactivateRC::LeavePage;
387 
388 }
389 
391 {
392  if(pOutlineDlg)
394  else if(bModified && pActNum)
395  {
396  *pSaveNum = *pActNum;
397  rSet->Put(SwUINumRuleItem( *pSaveNum ));
398  rSet->Put(SfxBoolItem(FN_PARAM_NUM_PRESET, false));
399  }
400  return bModified;
401 }
402 
404 {
405  const SfxPoolItem* pItem;
406  if (pOutlineDlg)
407  {
409  m_xLevelLB->set_selection_mode(SelectionMode::Single);
410  }
411  else if(SfxItemState::SET == rSet->GetItemState(FN_PARAM_ACT_NUMBER, false, &pItem))
412  pSaveNum = const_cast<SwUINumRuleItem*>(static_cast<const SwUINumRuleItem*>(pItem))->GetNumRule();
413 
415  sal_uInt16 nMask = 1;
416  m_xLevelLB->unselect_all();
417  if(nActNumLvl == USHRT_MAX)
418  {
419  m_xLevelLB->select(MAXLEVEL);
420  }
421  else
422  {
423  for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
424  {
425  if (nActNumLvl & nMask)
426  m_xLevelLB->select(i);
427  nMask <<= 1;
428  }
429  }
430 
431  if(!pActNum)
432  pActNum.reset(new SwNumRule(*pSaveNum));
433  else if(*pSaveNum != *pActNum)
434  *pActNum = *pSaveNum;
438  InitControls();
439  bModified = false;
440 }
441 
443 {
444  if ( pActNum == nullptr )
445  {
446  OSL_FAIL( "<SwNumPositionTabPage::InitPosAndSpaceMode()> - misusage of method -> <pAktNum> has to be already set!" );
447  return;
448  }
449 
452  sal_uInt16 nMask = 1;
453  for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
454  {
455  if(nActNumLvl & nMask)
456  {
457  SvxNumberFormat aNumFormat( pActNum->Get(i) );
458  ePosAndSpaceMode = aNumFormat.GetPositionAndSpaceMode();
459  if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
460  {
461  break;
462  }
463  }
464  nMask <<= 1;
465  }
466 
468  ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT;
469 }
470 
472 {
482 
493 }
494 
495 std::unique_ptr<SfxTabPage> SwNumPositionTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
496  const SfxItemSet* rAttrSet)
497 {
498  return std::make_unique<SwNumPositionTabPage>(pPage, pController, *rAttrSet);
499 }
500 
502 {
503  pWrtSh = pSh;
504 
506 
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 );
513 
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)
518  {
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);
525  }
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 );
532 }
533 
535 {
536  sal_uInt16 nMask = 1;
537  for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
538  {
539  if(nActNumLvl & nMask)
540  {
541  SwNumFormat aNumFormat(pActNum->Get(i));
542 
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);
553  }
554  nMask <<= 1;
555  }
556  SetModified();
557 }
558 
560 {
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))
566  {
567  nActNumLvl = 0xFFFF;
568  for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
569  rBox.unselect(i);
570  }
571  else if (!aRows.empty())
572  {
573  sal_uInt16 nMask = 1;
574  for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
575  {
576  if (std::find(aRows.begin(), aRows.end(), i) != aRows.end())
577  nActNumLvl |= nMask;
578  nMask <<= 1;
579  }
580  rBox.unselect(MAXLEVEL);
581  }
582  else
583  {
584  nActNumLvl = nSaveNumLvl;
585  sal_uInt16 nMask = 1;
586  for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
587  {
588  if(nActNumLvl & nMask)
589  {
590  rBox.select(i);
591  break;
592  }
593  nMask <<=1;
594  }
595  }
596  m_xRelativeCB->set_sensitive(1 != nActNumLvl);
597  SetModified();
598  InitPosAndSpaceMode();
599  ShowControlsDependingOnPosAndSpaceMode();
600  InitControls();
601 }
602 
604 {
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++)
610  {
611  if(nActNumLvl & nMask)
612  {
613  SwNumFormat aNumFormat( pActNum->Get( i ) );
614  if (&rField == m_xDistBorderMF.get())
615  {
616 
617  if (m_xRelativeCB->get_active() && m_xRelativeCB->get_sensitive())
618  {
619  if(0 == i)
620  {
621  auto const nTmp = aNumFormat.GetFirstLineOffset();
622  aNumFormat.SetAbsLSpace( nValue - nTmp );
623  }
624  else
625  {
626  long nTmp = pActNum->Get( i - 1 ).GetAbsLSpace() +
627  pActNum->Get( i - 1 ).GetFirstLineOffset() -
628  pActNum->Get( i ).GetFirstLineOffset();
629 
630  aNumFormat.SetAbsLSpace( nValue + nTmp );
631  }
632  }
633  else
634  {
635  aNumFormat.SetAbsLSpace( nValue - aNumFormat.GetFirstLineOffset());
636  }
637  }
638  else if (&rField == m_xDistNumMF.get())
639  {
640  aNumFormat.SetCharTextDistance( nValue );
641  }
642  else if (&rField == m_xIndentMF.get())
643  {
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 );
649  }
650 
651  pActNum->Set( i, aNumFormat );
652  }
653  nMask <<= 1;
654  }
655 
656  SetModified();
657  if(!m_xDistBorderMF->get_sensitive())
658  m_xDistBorderMF->set_text(OUString());
659 }
660 
661 IMPL_LINK( SwNumPositionTabPage, RelativeHdl, weld::ToggleButton&, rBox, void )
662 {
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)
668  {
669  sal_uInt16 nMask = 1;
670  bool bFirst = true;
671  bSetValue = true;
672  for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
673  {
674  if(nActNumLvl & nMask)
675  {
676  const SwNumFormat &rNumFormat = pActNum->Get(i);
677  if(bFirst)
678  {
679  nValue = rNumFormat.GetAbsLSpace();
680  if(bOn && i)
681  nValue -= pActNum->Get(i - 1).GetAbsLSpace();
682  }
683  else
684  bSetValue = nValue == rNumFormat.GetAbsLSpace() - pActNum->Get(i - 1).GetAbsLSpace();
685  bFirst = false;
686  }
687  nMask <<= 1;
688  }
689 
690  }
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;
697 }
698 
699 IMPL_LINK_NOARG(SwNumPositionTabPage, LabelFollowedByHdl_Impl, weld::ComboBox&, void)
700 {
701  // determine value to be set at the chosen list levels
703  {
704  const int nPos = m_xLabelFollowedByLB->get_active();
705  if ( nPos == 1 )
706  {
707  eLabelFollowedBy = SvxNumberFormat::SPACE;
708  }
709  else if ( nPos == 2 )
710  {
711  eLabelFollowedBy = SvxNumberFormat::NOTHING;
712  }
713  else if ( nPos == 3 )
714  {
715  eLabelFollowedBy = SvxNumberFormat::NEWLINE;
716  }
717  }
718 
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 )
724  {
725  if ( nActNumLvl & nMask )
726  {
727  SwNumFormat aNumFormat( pActNum->Get(i) );
728  aNumFormat.SetLabelFollowedBy( eLabelFollowedBy );
729  pActNum->Set( i, aNumFormat );
730 
731  if ( nFirstLvl == USHRT_MAX )
732  {
733  nFirstLvl = i;
734  }
735  else
736  {
737  bSameListtabPos &= aNumFormat.GetListtabPos() ==
738  pActNum->Get( nFirstLvl ).GetListtabPos();
739  }
740  }
741  nMask <<= 1;
742  }
743 
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 )
749  {
750  m_xListtabMF->set_value(
751  m_xListtabMF->normalize( pActNum->Get( nFirstLvl ).GetListtabPos() ),
752  FieldUnit::TWIP );
753  }
754  else
755  {
756  m_xListtabMF->set_text(OUString());
757  }
758 
759  SetModified();
760 }
761 
762 IMPL_LINK( SwNumPositionTabPage, ListtabPosHdl_Impl, weld::MetricSpinButton&, rField, void )
763 {
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)));
766 
767  // set value at the chosen list levels
768  sal_uInt16 nMask = 1;
769  for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
770  {
771  if ( nActNumLvl & nMask )
772  {
773  SwNumFormat aNumFormat( pActNum->Get(i) );
774  aNumFormat.SetListtabPos( nValue );
775  pActNum->Set( i, aNumFormat );
776  }
777  nMask <<= 1;
778  }
779 
780  SetModified();
781 }
782 
783 IMPL_LINK( SwNumPositionTabPage, AlignAtHdl_Impl, weld::MetricSpinButton&, rField, void )
784 {
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)));
787 
788  // set value at the chosen list levels
789  sal_uInt16 nMask = 1;
790  for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
791  {
792  if ( nActNumLvl & nMask )
793  {
794  SwNumFormat aNumFormat( pActNum->Get(i) );
795  const long nFirstLineIndent = nValue - aNumFormat.GetIndentAt();
796  aNumFormat.SetFirstLineIndent( nFirstLineIndent );
797  pActNum->Set( i, aNumFormat );
798  }
799  nMask <<= 1;
800  }
801 
802  SetModified();
803 }
804 
805 IMPL_LINK( SwNumPositionTabPage, IndentAtHdl_Impl, weld::MetricSpinButton&, rField, void )
806 {
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)));
809 
810  // set value at the chosen list levels
811  sal_uInt16 nMask = 1;
812  for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
813  {
814  if ( nActNumLvl & nMask )
815  {
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 );
823  }
824  nMask <<= 1;
825  }
826 
827  SetModified();
828 }
829 
831 {
832  sal_uInt16 nMask = 1;
833  for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
834  {
835  if(nActNumLvl & nMask)
836  {
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 )
844  {
845  aNumFormat.SetAbsLSpace( aTempFormat.GetAbsLSpace());
846  aNumFormat.SetCharTextDistance( aTempFormat.GetCharTextDistance() );
847  aNumFormat.SetFirstLineOffset( aTempFormat.GetFirstLineOffset() );
848  }
849  else if ( aTempFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
850  {
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() );
856  }
857  pActNum->Set( i, aNumFormat );
858  }
859  nMask <<= 1;
860  }
861 
862  InitControls();
863  SetModified();
864 }
865 
866 #ifdef DBG_UTIL
868 {
869  bModified = true;
872 }
873 #endif
874 
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"))
881 {
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 );
889 
891  {
892  RemoveTabPage("customize");
893  }
894  else
895  {
896  AddTabPage("customize", RID_SVXPAGE_NUM_OPTIONS );
897  }
898 
899  AddTabPage("position", RID_SVXPAGE_NUM_POSITION );
900 }
901 
903 {
904 }
905 
906 void SwSvxNumBulletTabDialog::PageCreated(const OString& rPageId, SfxTabPage& rPage)
907 {
908  // set styles' names and metric
909  OUString sNumCharFormat, sBulletCharFormat;
912 
913  if (rPageId == "singlenum")
914  {
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);
919  }
920  else if (rPageId == "bullets")
921  {
922  SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
923  aSet.Put (SfxStringItem(SID_BULLET_CHAR_FMT,sBulletCharFormat));
924  rPage.PageCreated(aSet);
925  }
926  else if (rPageId == "customize")
927  {
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();
936 
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));
941 
942  aSet.Put( SfxStringListItem( SID_CHAR_FMT_LIST_BOX,&aList ) ) ;
943 
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);
947  }
948  else if (rPageId == "position")
949  {
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);
955  }
956 }
957 
959 {
960  short nRet = SfxTabDialogController::Ok();
961  m_xExampleSet->ClearItem(SID_PARAM_NUM_PRESET);
962  return nRet;
963 }
964 
966 {
967  m_xDialog->response(RET_USER);
968 }
969 
970 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: num.cxx:342
void SetWrtShell(SwWrtShell *pSh)
Definition: num.cxx:501
virtual short Ok() override
Definition: num.cxx:958
FieldUnit
void SetLabelFollowedBy(const LabelFollowedBy eLabelFollowedBy)
IMPL_LINK(SwNumPositionTabPage, LevelHdl, weld::TreeView &, rBox, void)
Definition: num.cxx:559
SwWrtShell * pWrtSh
Definition: num.hxx:34
long GetFirstLineIndent() const
NumberingPreview m_aPreviewWIN
Definition: num.hxx:44
virtual void PageCreated(const SfxAllItemSet &aSet)
static ShellResource * GetShellRes()
Definition: viewsh.cxx:2493
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:734
void SetModified()
Definition: num.cxx:867
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:92
void SetLevel(sal_uInt16 nSet)
Definition: numprevw.hxx:62
std::unique_ptr< SfxItemSet > m_xExampleSet
void InitPosAndSpaceMode()
Definition: num.cxx:442
void RemoveTabPage(const OString &rName)
long SwTwips
Definition: swtypes.hxx:49
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:906
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:90
std::unique_ptr< weld::ComboBox > m_xAlignLB
Definition: num.hxx:59
virtual short Ok()
const SwView & GetView() const
Definition: wrtsh.hxx:428
virtual void Reset(const SfxItemSet *rSet) override
Definition: num.cxx:403
std::unique_ptr< weld::Label > m_xIndentAtFT
Definition: num.hxx:71
void SetExchangeSupport()
SwOutlineTabDialog * pOutlineDlg
Definition: num.hxx:36
const sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:95
short GetCharTextDistance() const
#define FN_PARAM_NUM_PRESET
Definition: cmdid.h:781
IMPL_LINK_NOARG(SwNumPositionTabPage, EditModifyHdl, weld::ComboBox &, void)
Definition: num.cxx:534
Numbering symbols.
Definition: poolfmt.hxx:118
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)
void SetListtabPos(const long nListtabPos)
std::unique_ptr< weld::Label > m_xAlign2FT
Definition: num.hxx:67
SwSvxNumBulletTabDialog(weld::Window *pParent, const SfxItemSet *pSwItemSet, SwWrtShell &)
Definition: num.cxx:875
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:138
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:709
SvxAdjust
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:495
std::unique_ptr< weld::Label > m_xAlignFT
Definition: num.hxx:58
int i
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
#define FN_PARAM_ACT_NUMBER
Definition: cmdid.h:779
std::unique_ptr< weld::MetricSpinButton > m_xDistNumMF
Definition: num.hxx:57
static void SetActNumLevel(sal_uInt16 nSet)
Definition: outline.hxx:63
void SetPageWidth(long nPgWidth)
Definition: numprevw.hxx:56
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: num.cxx:390
SvxAdjust GetNumAdjust() const
bool bLabelAlignmentPosAndSpaceModeActive
Definition: num.hxx:42
SvxNumPositionAndSpaceMode GetPositionAndSpaceMode() const
const SfxItemSet * GetDialogExampleSet() const
SwDocShell * GetDocShell()
Definition: view.cxx:1127
SwNumPositionTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: num.cxx:60
SwWrtShell & rWrtSh
Definition: num.hxx:122
Rect of current page.
long GetIndentAt() const
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:381
void Width(long nNew)
Definition: swrect.hxx:185
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
void AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
void InitControls()
Definition: num.cxx:144
long GetListtabPos() const
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:902
std::unique_ptr< weld::ComboBox > m_xLabelFollowedByLB
Definition: num.hxx:64
static bool bLastRelative
Definition: num.cxx:54
weld::Button * GetUserButton() const
std::unique_ptr< weld::ComboBox > m_xAlign2LB
Definition: num.hxx:68
sal_Int32 nPos
SwNumRule * GetNumRule(SwTextFormatColl &rTextFormatColl)
determines the list style, which directly set at the given paragraph style
Definition: fmtcol.cxx:74
std::unique_ptr< weld::Label > m_xAlignedAtFT
Definition: num.hxx:69
virtual void set_sensitive(bool sensitive)=0
bool bInInintControl
Definition: num.hxx:41
Rect of current frame.
void ShowControlsDependingOnPosAndSpaceMode()
Definition: num.cxx:471
static sal_uInt16 GetActNumLevel()
Definition: outline.hxx:62