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  if (pOutlineDlg)
394  {
396  m_xLevelLB->set_selection_mode(SelectionMode::Single);
397  }
398  else if(const SwUINumRuleItem* pNumberItem = rSet->GetItemIfSet(FN_PARAM_ACT_NUMBER, false))
399  pSaveNum = const_cast<SwUINumRuleItem*>(pNumberItem)->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  tools::Long nValue = static_cast< tools::Long >(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
595  sal_uInt16 nMask = 1;
596  for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
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  tools::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  tools::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::Toggleable&, 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  tools::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 tools::Long nValue = static_cast< tools::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 tools::Long nValue = static_cast< tools::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 tools::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 tools::Long nValue = static_cast< tools::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 tools::Long nAlignedAt = aNumFormat.GetIndentAt() +
805  aNumFormat.GetFirstLineIndent();
806  aNumFormat.SetIndentAt( nValue );
807  const tools::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:330
void SetWrtShell(SwWrtShell *pSh)
Definition: num.cxx:488
tools::Long GetFirstLineIndent() const
virtual short Ok() override
Definition: num.cxx:945
FieldUnit
void SetLabelFollowedBy(const LabelFollowedBy eLabelFollowedBy)
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
IMPL_LINK(SwNumPositionTabPage, LevelHdl, weld::TreeView &, rBox, void)
Definition: num.cxx:546
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:2662
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:780
void SetModified()
Definition: num.cxx:854
const SwNumRule * GetNumRuleAtCurrCursorPos() const
Definition: ednumber.cxx:716
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:429
constexpr sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:92
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: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:96
std::unique_ptr< weld::ComboBox > m_xAlignLB
Definition: num.hxx:59
virtual short Ok()
const SwView & GetView() const
Definition: wrtsh.hxx:437
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:814
void Width(tools::Long nNew)
Definition: swrect.hxx:189
IMPL_LINK_NOARG(SwNumPositionTabPage, EditModifyHdl, weld::ComboBox &, void)
Definition: num.cxx:521
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: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:126
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:755
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
void SetPageWidth(tools::Long nPgWidth)
Definition: numprevw.hxx:56
#define FN_PARAM_ACT_NUMBER
Definition: cmdid.h:812
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:51
SwDocShell * GetDocShell()
Definition: view.cxx:1132
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:889
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
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:458
bool m_bDetectedRangeSegmentation false
static sal_uInt16 GetActNumLevel()
Definition: outline.hxx:62