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 
42 void 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.
52 static 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  {
140  case FN_NUM_BULLET_DOWN:
141  case FN_NUM_BULLET_UP:
142  {
143  SfxViewFrame * pFrame = GetView().GetViewFrame();
144 
145  rReq.Done();
146  rSh.NumUpDown( nSlot == FN_NUM_BULLET_DOWN );
147  pFrame->GetBindings().Invalidate( SID_TABLE_CELL ); // Update status line!
148  }
149  break;
150 
151  case FN_NUM_BULLET_NEXT:
152  rSh.GotoNextNum();
153  rReq.Done();
154  break;
155 
156  case FN_NUM_BULLET_NONUM:
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 
193  case FN_NUM_BULLET_PREV:
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;
242  case FN_NUM_BULLET_DOWN:
243  if(nCurrentNumLevel == (MAXLEVEL - 1))
244  rSet.DisableItem(nWhich);
245  break;
246 
247  case FN_NUM_BULLET_NONUM:
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: */
SfxViewFrame * GetViewFrame() const
bool GetValue() const
#define FN_NUM_OR_NONUM
Definition: cmdid.h:98
SwView & GetView()
Definition: basesh.hxx:59
#define SFX_IMPL_INTERFACE(Class, SuperClass)
void GetCurrentOutlineLevels(sal_uInt8 &rUpper, sal_uInt8 &rLower)
Detect highest and lowest level to check moving of outline levels.
Definition: ednumber.cxx:421
const SwNumRule * GetNumRuleAtCurrCursorPos() const
Definition: ednumber.cxx:727
std::vector< SwNode * >::difference_type difference_type
const IDocumentOutlineNodes * getIDocumentOutlineNodesAccess() const
Definition: viewsh.cxx:2695
SwWrtShell & GetShell()
Definition: basesh.cxx:2763
bool Pop(SwCursorShell::PopMode=SwCursorShell::PopMode::DeleteStack)
Definition: wrtsh1.cxx:1752
#define FN_NUM_BULLET_OUTLINE_DOWN
Definition: cmdid.h:92
constexpr sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:93
sal_uInt16 FirstWhich()
#define FN_NUM_BULLET_DOWN
Definition: cmdid.h:81
void Done(bool bRemove=false)
#define FN_NUM_BULLET_OUTLINE_MOVEUP
Definition: cmdid.h:94
#define FN_NUM_BULLET_NEXT
Definition: cmdid.h:84
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
sal_uInt8 GetNumLevel() const
Definition: ednumber.cxx:702
sal_uInt16 NextWhich()
Used by the UI to modify the document model.
Definition: wrtsh.hxx:93
SwListShell(SwView &rView)
Definition: listsh.cxx:258
#define FN_NUM_BULLET_PREV
Definition: cmdid.h:83
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:655
void Execute(SfxRequest &)
Definition: listsh.cxx:127
static void lcl_OutlineUpDownWithSubPoints(SwWrtShell &rSh, bool bMove, bool bUp)
Definition: listsh.cxx:52
static constexpr auto npos
Definition: ndarr.hxx:79
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2240
SfxBindings & GetBindings()
virtual int getOutlineLevel(const tSortedOutlineNodeList::size_type nIdx) const =0
void SetName(const OUString &rName)
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:1138
#define SFX_OBJECTBAR_OBJECT
bool NumOrNoNum(bool bDelete=false, bool bChkStart=true)
Switch on/off of numbering via Delete/Backspace.
Definition: ednumber.cxx:665
bool OutlineUpDown(short nOffset=1)
Definition: ednumber.cxx:553
#define FN_NUM_BULLET_OUTLINE_MOVEDOWN
Definition: cmdid.h:95
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
void DisableItem(sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
#define FN_NUM_BULLET_OUTLINE_UP
Definition: cmdid.h:93
unsigned char sal_uInt8
Provides outline nodes of a document.
void GotoOutline(SwOutlineNodes::size_type nIdx)
Definition: move.cxx:617
bool IsNoNum(bool bChkStart=true) const
Definition: ednumber.cxx:683
void NumUpDown(bool bDown=true)
Definition: ednumber.cxx:310
void NoNum()
Paragraphs without enumeration but with indents.
Definition: ednumber.cxx:131
void MakeOutlineSel(SwOutlineNodes::size_type nSttPos, SwOutlineNodes::size_type nEndPos, bool bWithChildren, bool bKillPams=true)
Definition: crstrvl.cxx:1167
void ClearMark()
Definition: crsrsh.cxx:939
#define FN_NUM_BULLET_UP
Definition: cmdid.h:82
void GotoPrevNum()
Definition: crstrvl.cxx:123
void AppendItem(const SfxPoolItem &)
bool IsAPI() const
bool MoveOutlinePara(SwOutlineNodes::difference_type nOffset)
Definition: ednumber.cxx:576
std::vector< SwNode * >::size_type size_type
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2074
void GotoNextNum()
go to next/previous point on the same level
Definition: crstrvl.cxx:116
#define FN_NUM_BULLET_NONUM
Definition: cmdid.h:87
void GetState(SfxItemSet &)
Definition: listsh.cxx:215
bool IsOutlineRule() const
Definition: numrule.hxx:242
Definition: view.hxx:144
bool MoveNumParas(bool bUpperLower, bool bUpperLeft)
Definition: ednumber.cxx:431
bool CursorInsideInputField() const
Definition: crstrvl.cxx:929