LibreOffice Module sw (master)  1
txtnum.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 <sfx2/request.hxx>
21 #include <svl/eitem.hxx>
22 #include <svl/stritem.hxx>
23 #include <editeng/numitem.hxx>
24 #include <editeng/brushitem.hxx>
25 #include <numrule.hxx>
26 
27 #include <cmdid.h>
28 #include <wrtsh.hxx>
29 #include <view.hxx>
30 #include <viewopt.hxx>
31 #include <wdocsh.hxx>
32 #include <poolfmt.hxx>
33 #include <textsh.hxx>
34 #include <swabstdlg.hxx>
35 #include <SwStyleNameMapper.hxx>
36 #include <sfx2/tabdlg.hxx>
37 #include <svx/nbdtmg.hxx>
38 #include <svx/nbdtmgfact.hxx>
39 #include <sfx2/viewfrm.hxx>
40 #include <sfx2/bindings.hxx>
41 #include <memory>
42 
44 {
45  //Because the record before any shell exchange.
46  switch(rReq.GetSlot())
47  {
48  case FN_NUM_NUMBERING_ON:
49  {
51  const SfxBoolItem* pItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_1);
52  bool bMode = !GetShell().SelectionHasNumber(); // #i29560#
53  if ( pItem )
54  bMode = pItem->GetValue();
55  else
56  rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
57 
58  if ( bMode != (GetShell().SelectionHasNumber()) ) // #i29560#
59  {
60  rReq.Done();
61  if( bMode )
62  GetShell().NumOn();
63  else
64  GetShell().NumOrBulletOff(); // #i29560#
65  }
66  bool bNewResult = GetShell().SelectionHasNumber();
67  if (bNewResult!=bMode) {
68  SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
69  SfxBoolItem aItem(FN_NUM_NUMBERING_ON,!bNewResult);
70  rBindings.SetState(aItem);
71  SfxBoolItem aNewItem(FN_NUM_NUMBERING_ON,bNewResult);
72  rBindings.SetState(aNewItem);
73  }
75  }
76  break;
77  case FN_NUM_BULLET_ON:
78  {
80  const SfxBoolItem* pItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_1);
81  bool bMode = !GetShell().SelectionHasBullet(); // #i29560#
82  if ( pItem )
83  bMode = pItem->GetValue();
84  else
85  rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
86 
87  if ( bMode != (GetShell().SelectionHasBullet()) ) // #i29560#
88  {
89  rReq.Done();
90  if( bMode )
91  GetShell().BulletOn();
92  else
93  GetShell().NumOrBulletOff(); // #i29560#
94  }
95  bool bNewResult = GetShell().SelectionHasBullet();
96  if (bNewResult!=bMode) {
97  SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
98  SfxBoolItem aItem(FN_NUM_BULLET_ON,!bNewResult);
99  rBindings.SetState(aItem);
100  SfxBoolItem aNewItem(FN_NUM_BULLET_ON,bNewResult);
101  rBindings.SetState(aNewItem);
102  }
104  }
105  break;
106 
107  case FN_NUMBER_BULLETS:
108  case SID_OUTLINE_BULLET:
109  {
110  SfxItemSet aSet( GetPool(),
111  svl::Items<SID_HTML_MODE, SID_HTML_MODE,
112  SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL>{} );
113  SwDocShell* pDocSh = GetView().GetDocShell();
114  const bool bHtml = dynamic_cast<SwWebDocShell*>( pDocSh ) != nullptr;
115  const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
116  if ( pNumRuleAtCurrentSelection != nullptr )
117  {
118  SvxNumRule aRule = pNumRuleAtCurrentSelection->MakeSvxNumRule();
119 
120  //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
121  for ( sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++ )
122  {
123  SvxNumberFormat aFormat( aRule.GetLevel( i ) );
124  if ( SVX_NUM_BITMAP == aFormat.GetNumberingType() )
125  {
126  const SvxBrushItem* pBrush = aFormat.GetBrush();
127  if(pBrush && !pBrush->GetGraphicLink().isEmpty())
128  aFormat.SetNumberingType(SvxNumType(SVX_NUM_BITMAP|LINK_TOKEN));
129  aRule.SetLevel(i, aFormat, aRule.Get(i) != nullptr);
130  }
131  }
132  if(bHtml)
133  aRule.SetFeatureFlag(SvxNumRuleFlags::ENABLE_EMBEDDED_BMP, false);
134 
135  aSet.Put(SvxNumBulletItem(aRule));
136  OSL_ENSURE( GetShell().GetNumLevel() < MAXLEVEL,
137  "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect." );
138  sal_uInt16 nLevel = GetShell().GetNumLevel();
139  if( nLevel < MAXLEVEL )
140  {
141  nLevel = 1 << nLevel;
142  aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
143  }
144  }
145  else
146  {
147  SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
148  // #i89178#
150  SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
151  const bool bRightToLeft = GetShell().IsInRightToLeftText();
152 
153  if ( bHtml || bRightToLeft )
154  {
155  for ( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
156  {
157  SvxNumberFormat aFormat( aSvxRule.GetLevel( n ) );
158  if ( n && bHtml )
159  {
160  // 1/2" for HTML
161  aFormat.SetAbsLSpace(n * 720);
162  }
163  // #i38904# Default alignment for
164  // numbering/bullet should be rtl in rtl paragraph:
165  if ( bRightToLeft )
166  {
167  aFormat.SetNumAdjust( SvxAdjust::Right );
168  }
169  aSvxRule.SetLevel( n, aFormat, false );
170  }
171  aSvxRule.SetFeatureFlag(SvxNumRuleFlags::ENABLE_EMBEDDED_BMP, false);
172  }
173  aSet.Put( SvxNumBulletItem( aSvxRule ) );
174  }
175 
176  aSet.Put( SfxBoolItem( SID_PARAM_NUM_PRESET,false ));
177 
178  // Before the dialogue of the HTML mode will be dropped at the Docshell.
179  pDocSh->PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(pDocSh)));
180 
182  weld::Window *pParent = rReq.GetFrameWeld();
183  VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxNumBulletTabDialog(pParent, &aSet, GetShell()));
184  const SfxStringItem* pPageItem = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
185  if ( pPageItem )
186  pDlg->SetCurPageId( OUStringToOString( pPageItem->GetValue(), RTL_TEXTENCODING_UTF8 ) );
187 
188  auto pRequest = std::make_shared<SfxRequest>(rReq);
189  rReq.Ignore(); // the 'old' request is not relevant any more
190 
191  pDlg->StartExecuteAsync([aSet, pDlg, pNumRuleAtCurrentSelection, pRequest, this](sal_Int32 nResult){
192  if (RET_OK == nResult)
193  {
194  const SfxPoolItem* pItem;
195  if (SfxItemState::SET == pDlg->GetOutputItemSet()->GetItemState(SID_ATTR_NUMBERING_RULE, false, &pItem))
196  {
197  pRequest->AppendItem(*pItem);
198  pRequest->Done();
199  SvxNumRule* pSetRule = static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule();
200  pSetRule->UnLinkGraphics();
201  SwNumRule aSetRule(pNumRuleAtCurrentSelection != nullptr
202  ? pNumRuleAtCurrentSelection->GetName()
205  aSetRule.SetSvxRule(*pSetRule, GetShell().GetDoc());
206  aSetRule.SetAutoRule(true);
207  // No start of new list, if an existing list style is edited.
208  // Otherwise start a new list.
209  const bool bCreateList = (pNumRuleAtCurrentSelection == nullptr);
210  GetShell().SetCurNumRule(aSetRule, bCreateList);
211  }
212  // If the Dialog was leaved with OK but nothing was chosen then the
213  // numbering must be at least activated, if it is not already.
214  else if (pNumRuleAtCurrentSelection == nullptr
215  && SfxItemState::SET == aSet.GetItemState(SID_ATTR_NUMBERING_RULE, false, &pItem))
216  {
217  pRequest->AppendItem(*pItem);
218  pRequest->Done();
219  SvxNumRule* pSetRule = static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule();
220  SwNumRule aSetRule(
221  GetShell().GetUniqueNumRuleName(),
223  aSetRule.SetSvxRule(*pSetRule, GetShell().GetDoc());
224  aSetRule.SetAutoRule(true);
225  // start new list
226  GetShell().SetCurNumRule(aSetRule, true);
227  }
228  }
229  else if (RET_USER == nResult)
230  GetShell().DelNumRules();
231  pDlg->disposeOnce();
232  });
233  }
234  break;
235 
236  default:
237  OSL_FAIL("wrong dispatcher");
238  return;
239  }
240 }
241 
242 
244 {
245  const sal_uInt16 nSlot = rReq.GetSlot();
246  switch ( nSlot )
247  {
248  case FN_SVX_SET_NUMBER:
249  case FN_SVX_SET_BULLET:
250  case FN_SVX_SET_OUTLINE:
251  {
252  const SfxUInt16Item* pItem = rReq.GetArg<SfxUInt16Item>(nSlot);
253  if ( pItem != nullptr )
254  {
255  const sal_uInt16 nChosenItemIdx = pItem->GetValue();
257  if ( nSlot == FN_SVX_SET_NUMBER )
259  else if ( nSlot == FN_SVX_SET_OUTLINE )
261 
263 
264  if ( pNBOTypeMgr != nullptr )
265  {
266  const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
267  sal_uInt16 nActNumLvl = USHRT_MAX;
268  if ( pNumRuleAtCurrentSelection != nullptr )
269  {
270  const sal_uInt16 nLevel = GetShell().GetNumLevel();
271  if ( nLevel < MAXLEVEL )
272  {
273  nActNumLvl = 1 << nLevel;
274  }
275  }
276  SwNumRule aNewNumRule(
277  pNumRuleAtCurrentSelection != nullptr ? pNumRuleAtCurrentSelection->GetName() : GetShell().GetUniqueNumRuleName(),
279  SvxNumRule aNewSvxNumRule = pNumRuleAtCurrentSelection != nullptr
280  ? pNumRuleAtCurrentSelection->MakeSvxNumRule()
281  : aNewNumRule.MakeSvxNumRule();
282 
283  OUString aNumCharFormat, aBulletCharFormat;
286 
287  SfxAllItemSet aSet( GetPool() );
288  aSet.Put( SfxStringItem( SID_NUM_CHAR_FMT, aNumCharFormat ) );
289  aSet.Put( SfxStringItem( SID_BULLET_CHAR_FMT, aBulletCharFormat ) );
290  aSet.Put( SvxNumBulletItem( aNewSvxNumRule, SID_ATTR_NUMBERING_RULE ) );
291 
292  pNBOTypeMgr->SetItems( &aSet );
293  pNBOTypeMgr->ApplyNumRule( aNewSvxNumRule, nChosenItemIdx - 1, nActNumLvl );
294 
295  aNewNumRule.SetSvxRule( aNewSvxNumRule, GetShell().GetDoc() );
296  aNewNumRule.SetAutoRule( true );
297  const bool bCreateNewList = ( pNumRuleAtCurrentSelection == nullptr );
298  GetShell().SetCurNumRule( aNewNumRule, bCreateNewList );
299  }
300  }
301  }
302  break;
303 
304  default:
305  OSL_ENSURE(false, "wrong Dispatcher");
306  return;
307  }
308 }
309 
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void UnLinkGraphics()
SfxViewFrame * GetViewFrame() const
bool GetValue() const
SwView & GetView()
Definition: basesh.hxx:57
void BulletOn()
Definition: wrtsh1.cxx:1393
void SetState(const SfxItemSet &rSet)
void SetAutoRule(bool bFlag)
Definition: numrule.hxx:229
OUString GetUniqueNumRuleName() const
Definition: ednumber.cxx:812
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
SwWrtShell & GetShell()
Definition: basesh.cxx:2687
sal_Int64 n
const SvxNumberFormat * Get(sal_uInt16 nLevel) const
sal_uInt16 GetValue() const
bool SelectionHasNumber() const
Definition: ednumber.cxx:148
const OUString & GetName() const
Definition: numrule.hxx:223
void Done(bool bRemove=false)
NBOTypeMgrBase * CreateInstance(const NBOType aType)
void EndAllAction()
Definition: edws.cxx:97
sal_uInt8 GetNumLevel() const
Definition: ednumber.cxx:698
SvxNumType
void SetCurNumRule(const SwNumRule &, const bool bCreateNewList, const OUString &sContinuedListId=OUString(), const bool bResetIndentAttrs=false)
Optional parameter (default value false).
Definition: ednumber.cxx:767
#define FN_NUMBER_BULLETS
Definition: cmdid.h:73
virtual VclPtr< SfxAbstractTabDialog > CreateSvxNumBulletTabDialog(weld::Window *pParent, const SfxItemSet *pSwItemSet, SwWrtShell &)=0
const sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:95
Numbering symbols.
Definition: poolfmt.hxx:117
void DelNumRules()
Delete, split enumeration list.
Definition: ednumber.cxx:276
SfxItemPool & GetPool() const
SvxNumRule MakeSvxNumRule() const
Definition: number.cxx:892
void NumOn()
Definition: wrtsh1.cxx:1342
void SetFeatureFlag(SvxNumRuleFlags nFlag, bool bSet=true)
SVX_NUM_BITMAP
bool IsInRightToLeftText() const
Definition: crsrsh.cxx:3404
int i
void ExecEnterNum(SfxRequest &)
Definition: txtnum.cxx:43
SfxBindings & GetBindings()
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:337
const T * GetArg(sal_uInt16 nSlotId) const
const SvxNumberFormat & GetLevel(sal_uInt16 nLevel) const
sal_uInt16 GetLevelCount() const
void NumOrBulletOff()
Definition: wrtsh1.cxx:1347
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
SwDocShell * GetDocShell()
Definition: view.cxx:1108
const SwNumRule * GetNumRuleAtCurrentSelection() const
Returns the numbering rule found at the paragraphs of the current selection, if all paragraphs of the...
Definition: ednumber.cxx:729
bool SelectionHasBullet() const
Definition: ednumber.cxx:197
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
const OUString & GetGraphicLink() const
weld::Window * GetFrameWeld() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
#define RET_USER
SvxNumberFormat::SvxNumPositionAndSpaceMode GetDefaultPositionAndSpaceMode()
Definition: number.cxx:1486
#define LINK_TOKEN
unsigned char sal_uInt8
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:254
RET_OK
void SetSvxRule(const SvxNumRule &, SwDoc *pDoc)
Definition: number.cxx:880
void ExecSetNumber(SfxRequest const &)
Definition: txtnum.cxx:243
void AppendItem(const SfxPoolItem &)
void SetAbsLSpace(sal_Int32 nSet)
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
void Ignore()
SwNumRule * GetNumRule(SwTextFormatColl &rTextFormatColl)
determines the list style, which directly set at the given paragraph style
Definition: fmtcol.cxx:74
virtual void ApplyNumRule(SvxNumRule &aNum, sal_uInt16 nIndex, sal_uInt16 mLevel, bool isDefault=false, bool isResetSize=false)=0
void SetLevel(sal_uInt16 nLevel, const SvxNumberFormat &rFmt, bool bIsValid=true)
void SetItems(const SfxItemSet *pArg)