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