LibreOffice Module sw (master) 1
listsh.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 <cmdid.h>
21#include <sfx2/request.hxx>
22#include <sfx2/objface.hxx>
23#include <sfx2/bindings.hxx>
24#include <sfx2/viewfrm.hxx>
25#include <svl/eitem.hxx>
26#include <svl/whiter.hxx>
27#include <osl/diagnose.h>
28
29#include <numrule.hxx>
30#include <wrtsh.hxx>
31#include <listsh.hxx>
32#include <view.hxx>
33
34#define ShellClass_SwListShell
35#include <sfx2/msg.hxx>
36#include <swslots.hxx>
37
39
41
42void SwListShell::InitInterface_Impl()
43{
44 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Num_Toolbox);
45}
46
47
48// #i35572# Functionality of Numbering/Bullet toolbar
49// for outline numbered paragraphs should match the functions for outlines
50// available in the navigator. Therefore the code in the following
51// function is quite similar the code in SwContentTree::ExecCommand.
52static void lcl_OutlineUpDownWithSubPoints( SwWrtShell& rSh, bool bMove, bool bUp )
53{
54 const SwOutlineNodes::size_type nActPos = rSh.GetOutlinePos();
55 if ( !(nActPos < SwOutlineNodes::npos && rSh.IsOutlineMovable( nActPos )) )
56 return;
57
58 rSh.Push();
59 rSh.MakeOutlineSel( nActPos, nActPos, true );
60
61 if ( bMove )
62 {
64 const int nActLevel = pIDoc->getOutlineLevel( nActPos );
66
67 if ( !bUp )
68 {
69 // Move down with subpoints:
70 SwOutlineNodes::size_type nActEndPos = nActPos + 1;
71 while ( nActEndPos < pIDoc->getOutlineNodesCount() &&
72 (!pIDoc->isOutlineInLayout(nActEndPos, *rSh.GetLayout())
73 || nActLevel < pIDoc->getOutlineLevel(nActEndPos)))
74 {
75 ++nActEndPos;
76 }
77
78 if ( nActEndPos < pIDoc->getOutlineNodesCount() )
79 {
80 // The current subpoint which should be moved
81 // starts at nActPos and ends at nActEndPos - 1
82 --nActEndPos;
83 SwOutlineNodes::size_type nDest = nActEndPos + 2;
84 while ( nDest < pIDoc->getOutlineNodesCount() &&
85 (!pIDoc->isOutlineInLayout(nDest, *rSh.GetLayout())
86 || nActLevel < pIDoc->getOutlineLevel(nDest)))
87 {
88 ++nDest;
89 }
90
91 nDir = nDest - 1 - nActEndPos;
92 }
93 }
94 else
95 {
96 // Move up with subpoints:
97 if ( nActPos > 0 )
98 {
99 SwOutlineNodes::size_type nDest = nActPos - 1;
100 while (nDest > 0 &&
101 (!pIDoc->isOutlineInLayout(nDest, *rSh.GetLayout())
102 || nActLevel < pIDoc->getOutlineLevel(nDest)))
103 {
104 --nDest;
105 }
106
107 nDir = nDest - nActPos;
108 }
109 }
110
111 if ( nDir )
112 {
113 rSh.MoveOutlinePara( nDir );
114 rSh.GotoOutline( nActPos + nDir );
115 }
116 }
117 else
118 {
119 // Up/down with subpoints:
120 rSh.OutlineUpDown( bUp ? -1 : 1 );
121 }
122
123 rSh.ClearMark();
125}
126
128{
129 const SfxItemSet* pArgs = rReq.GetArgs();
130 const sal_uInt16 nSlot = rReq.GetSlot();
131 SwWrtShell& rSh = GetShell();
132
133 // #i35572#
134 const SwNumRule* pCurRule = rSh.GetNumRuleAtCurrCursorPos();
135 OSL_ENSURE( pCurRule, "SwListShell::Execute without NumRule" );
136 bool bOutline = pCurRule && pCurRule->IsOutlineRule();
137
138 switch (nSlot)
139 {
141 case FN_NUM_BULLET_UP:
142 {
143 SfxViewFrame& rFrame = GetView().GetViewFrame();
144
145 rReq.Done();
146 rSh.NumUpDown( nSlot == FN_NUM_BULLET_DOWN );
147 rFrame.GetBindings().Invalidate( SID_TABLE_CELL ); // Update status line!
148 }
149 break;
150
152 rSh.GotoNextNum();
153 rReq.Done();
154 break;
155
157 rSh.NoNum();
158 rReq.Done();
159 break;
160
162 if ( bOutline )
163 lcl_OutlineUpDownWithSubPoints( rSh, false, false );
164 else
165 rSh.MoveNumParas(false, false);
166 rReq.Done();
167 break;
168
170 if ( bOutline )
171 lcl_OutlineUpDownWithSubPoints( rSh, true, false );
172 else
173 rSh.MoveNumParas(true, false);
174 rReq.Done();
175 break;
176
178 if ( bOutline )
179 lcl_OutlineUpDownWithSubPoints( rSh, true, true );
180 else
181 rSh.MoveNumParas(true, true);
182 rReq.Done();
183 break;
184
186 if ( bOutline )
187 lcl_OutlineUpDownWithSubPoints( rSh, false, true );
188 else
189 rSh.MoveNumParas(false, true);
190 rReq.Done();
191 break;
192
194 rSh.GotoPrevNum();
195 rReq.Done();
196 break;
197
198 case FN_NUM_OR_NONUM:
199 {
200 bool bApi = rReq.IsAPI();
201 bool bDelete = !rSh.IsNoNum(!bApi);
202 if(pArgs )
203 bDelete = static_cast<const SfxBoolItem &>(pArgs->Get(rReq.GetSlot())).GetValue();
204 rSh.NumOrNoNum( bDelete, !bApi );
205 rReq.AppendItem( SfxBoolItem( nSlot, bDelete ) );
206 rReq.Done();
207 }
208 break;
209 default:
210 OSL_ENSURE(false, "wrong dispatcher");
211 return;
212 }
213}
214
216{
217 SfxWhichIter aIter( rSet );
218 sal_uInt16 nWhich = aIter.FirstWhich();
219 SwWrtShell& rSh = GetShell();
220 sal_uInt8 nCurrentNumLevel = rSh.GetNumLevel();
221 while ( nWhich )
222 {
223 switch( nWhich )
224 {
225 case FN_NUM_OR_NONUM:
226 rSet.Put(SfxBoolItem(nWhich, GetShell().IsNoNum(false)));
227 break;
229 case FN_NUM_BULLET_UP:
230 if(!nCurrentNumLevel)
231 rSet.DisableItem(nWhich);
232 break;
234 {
235 sal_uInt8 nUpper = 0;
236 sal_uInt8 nLower = 0;
237 rSh.GetCurrentOutlineLevels( nUpper, nLower );
238 if(nLower == (MAXLEVEL - 1))
239 rSet.DisableItem(nWhich);
240 }
241 break;
243 if(nCurrentNumLevel == (MAXLEVEL - 1))
244 rSet.DisableItem(nWhich);
245 break;
246
248 if ( rSh.CursorInsideInputField() )
249 {
250 rSet.DisableItem(nWhich);
251 }
252 break;
253 }
254 nWhich = aIter.NextWhich();
255 }
256}
257
259 SwBaseShell(_rView)
260{
261 SetName("List");
262}
263
264/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides outline nodes of a document.
virtual int getOutlineLevel(const tSortedOutlineNodeList::size_type nIdx) const =0
virtual bool isOutlineInLayout(tSortedOutlineNodeList::size_type nIdx, SwRootFrame const &rLayout) const =0
void Invalidate(sal_uInt16 nId)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
void DisableItem(sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
const SfxItemSet * GetArgs() const
void AppendItem(const SfxPoolItem &)
bool IsAPI() const
void Done(bool bRemove=false)
void SetName(const OUString &rName)
SfxBindings & GetBindings()
SfxViewFrame & GetViewFrame() const
sal_uInt16 FirstWhich()
sal_uInt16 NextWhich()
SwWrtShell & GetShell()
Definition: basesh.cxx:3001
SwView & GetView()
Definition: basesh.hxx:59
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2550
bool CursorInsideInputField() const
Definition: crstrvl.cxx:1094
void GotoPrevNum()
Definition: crstrvl.cxx:124
void MakeOutlineSel(SwOutlineNodes::size_type nSttPos, SwOutlineNodes::size_type nEndPos, bool bWithChildren, bool bKillPams=true)
Definition: crstrvl.cxx:1348
void GotoNextNum()
go to next/previous point on the same level
Definition: crstrvl.cxx:117
void ClearMark()
Definition: crsrsh.cxx:1225
SwOutlineNodes::size_type GetOutlinePos(sal_uInt8 nLevel=UCHAR_MAX, SwPaM *pPaM=nullptr)
search "outline position" before previous outline node at given level
Definition: crstrvl.cxx:1319
bool IsNoNum(bool bChkStart=true) const
Definition: ednumber.cxx:650
void NoNum()
Paragraphs without enumeration but with indents.
Definition: ednumber.cxx:126
bool NumOrNoNum(bool bDelete=false, bool bChkStart=true)
Switch on/off of numbering via Delete/Backspace.
Definition: ednumber.cxx:632
sal_uInt8 GetNumLevel() const
Definition: ednumber.cxx:669
const SwNumRule * GetNumRuleAtCurrCursorPos() const
Definition: ednumber.cxx:694
bool OutlineUpDown(short nOffset=1)
Definition: ednumber.cxx:520
void NumUpDown(bool bDown=true)
Definition: ednumber.cxx:277
bool IsOutlineMovable(SwOutlineNodes::size_type nIdx) const
May an outline be moved or copied? Check whether it's in text body, not in table, and not read-only (...
Definition: ednumber.cxx:622
bool MoveOutlinePara(SwOutlineNodes::difference_type nOffset)
Definition: ednumber.cxx:543
void GetCurrentOutlineLevels(sal_uInt8 &rUpper, sal_uInt8 &rLower)
Detect highest and lowest level to check moving of outline levels.
Definition: ednumber.cxx:388
bool MoveNumParas(bool bUpperLower, bool bUpperLeft)
Definition: ednumber.cxx:398
SwListShell(SwView &rView)
Definition: listsh.cxx:258
void GetState(SfxItemSet &)
Definition: listsh.cxx:215
void Execute(SfxRequest &)
Definition: listsh.cxx:127
bool IsOutlineRule() const
Definition: numrule.hxx:241
static constexpr auto npos
Definition: ndarr.hxx:81
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2163
const IDocumentOutlineNodes * getIDocumentOutlineNodesAccess() const
Definition: viewsh.cxx:2844
Definition: view.hxx:146
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
void GotoOutline(SwOutlineNodes::size_type nIdx)
Definition: move.cxx:655
bool Pop(SwCursorShell::PopMode, ::std::optional< SwCallLink > &roLink)
Definition: wrtsh1.cxx:2047
std::vector< Value >::difference_type difference_type
#define FN_NUM_BULLET_DOWN
Definition: cmdid.h:89
#define FN_NUM_BULLET_NONUM
Definition: cmdid.h:95
#define FN_NUM_BULLET_OUTLINE_UP
Definition: cmdid.h:101
#define FN_NUM_BULLET_OUTLINE_MOVEDOWN
Definition: cmdid.h:103
#define FN_NUM_BULLET_PREV
Definition: cmdid.h:91
#define FN_NUM_OR_NONUM
Definition: cmdid.h:106
#define FN_NUM_BULLET_UP
Definition: cmdid.h:90
#define FN_NUM_BULLET_OUTLINE_MOVEUP
Definition: cmdid.h:102
#define FN_NUM_BULLET_OUTLINE_DOWN
Definition: cmdid.h:100
#define FN_NUM_BULLET_NEXT
Definition: cmdid.h:92
static void lcl_OutlineUpDownWithSubPoints(SwWrtShell &rSh, bool bMove, bool bUp)
Definition: listsh.cxx:52
#define SFX_OBJECTBAR_OBJECT
const char GetValue[]
static SfxItemSet & rSet
#define SFX_IMPL_INTERFACE(Class, SuperClass)
constexpr sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:92
unsigned char sal_uInt8