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