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 
28 #include <numrule.hxx>
29 #include <wrtsh.hxx>
30 #include <listsh.hxx>
31 #include <view.hxx>
32 
33 #define ShellClass_SwListShell
34 #include <sfx2/msg.hxx>
35 #include <swslots.hxx>
36 
38 
40 
41 void SwListShell::InitInterface_Impl()
42 {
43  GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Num_Toolbox);
44 }
45 
46 
47 // #i35572# Functionality of Numbering/Bullet toolbar
48 // for outline numbered paragraphs should match the functions for outlines
49 // available in the navigator. Therefore the code in the following
50 // function is quite similar the code in SwContentTree::ExecCommand.
51 static void lcl_OutlineUpDownWithSubPoints( SwWrtShell& rSh, bool bMove, bool bUp )
52 {
53  const SwOutlineNodes::size_type nActPos = rSh.GetOutlinePos();
54  if ( nActPos < SwOutlineNodes::npos && rSh.IsOutlineMovable( nActPos ) )
55  {
56  rSh.Push();
57  rSh.MakeOutlineSel( nActPos, nActPos, true );
58 
59  if ( bMove )
60  {
62  const int nActLevel = pIDoc->getOutlineLevel( nActPos );
64 
65  if ( !bUp )
66  {
67  // Move down with subpoints:
68  SwOutlineNodes::size_type nActEndPos = nActPos + 1;
69  while ( nActEndPos < pIDoc->getOutlineNodesCount() &&
70  (!pIDoc->isOutlineInLayout(nActEndPos, *rSh.GetLayout())
71  || nActLevel < pIDoc->getOutlineLevel(nActEndPos)))
72  {
73  ++nActEndPos;
74  }
75 
76  if ( nActEndPos < pIDoc->getOutlineNodesCount() )
77  {
78  // The current subpoint which should be moved
79  // starts at nActPos and ends at nActEndPos - 1
80  --nActEndPos;
81  SwOutlineNodes::size_type nDest = nActEndPos + 2;
82  while ( nDest < pIDoc->getOutlineNodesCount() &&
83  (!pIDoc->isOutlineInLayout(nDest, *rSh.GetLayout())
84  || nActLevel < pIDoc->getOutlineLevel(nDest)))
85  {
86  ++nDest;
87  }
88 
89  nDir = nDest - 1 - nActEndPos;
90  }
91  }
92  else
93  {
94  // Move up with subpoints:
95  if ( nActPos > 0 )
96  {
97  SwOutlineNodes::size_type nDest = nActPos - 1;
98  while (nDest > 0 &&
99  (!pIDoc->isOutlineInLayout(nDest, *rSh.GetLayout())
100  || nActLevel < pIDoc->getOutlineLevel(nDest)))
101  {
102  --nDest;
103  }
104 
105  nDir = nDest - nActPos;
106  }
107  }
108 
109  if ( nDir )
110  {
111  rSh.MoveOutlinePara( nDir );
112  rSh.GotoOutline( nActPos + nDir );
113  }
114  }
115  else
116  {
117  // Up/down with subpoints:
118  rSh.OutlineUpDown( bUp ? -1 : 1 );
119  }
120 
121  rSh.ClearMark();
123  }
124 }
125 
127 {
128  const SfxItemSet* pArgs = rReq.GetArgs();
129  const sal_uInt16 nSlot = rReq.GetSlot();
130  SwWrtShell& rSh = GetShell();
131 
132  // #i35572#
133  const SwNumRule* pCurRule = rSh.GetNumRuleAtCurrCursorPos();
134  OSL_ENSURE( pCurRule, "SwListShell::Execute without NumRule" );
135  bool bOutline = pCurRule && pCurRule->IsOutlineRule();
136 
137  switch (nSlot)
138  {
139  case FN_NUM_BULLET_DOWN:
140  case FN_NUM_BULLET_UP:
141  {
142  SfxViewFrame * pFrame = GetView().GetViewFrame();
143 
144  rReq.Done();
145  rSh.NumUpDown( nSlot == FN_NUM_BULLET_DOWN );
146  pFrame->GetBindings().Invalidate( SID_TABLE_CELL ); // Update status line!
147  }
148  break;
149 
150  case FN_NUM_BULLET_NEXT:
151  rSh.GotoNextNum();
152  rReq.Done();
153  break;
154 
155  case FN_NUM_BULLET_NONUM:
156  rSh.NoNum();
157  rReq.Done();
158  break;
159 
160  case FN_NUM_BULLET_OFF:
161  {
162  rReq.Ignore();
163  SfxRequest aReq( GetView().GetViewFrame(), FN_NUM_BULLET_ON );
164  aReq.AppendItem( SfxBoolItem( FN_PARAM_1, false ) );
165  aReq.Done();
166  rSh.DelNumRules();
167  break;
168  }
169 
171  if ( bOutline )
172  lcl_OutlineUpDownWithSubPoints( rSh, false, false );
173  else
174  rSh.MoveNumParas(false, false);
175  rReq.Done();
176  break;
177 
179  if ( bOutline )
180  lcl_OutlineUpDownWithSubPoints( rSh, true, false );
181  else
182  rSh.MoveNumParas(true, false);
183  rReq.Done();
184  break;
185 
187  if ( bOutline )
188  lcl_OutlineUpDownWithSubPoints( rSh, true, true );
189  else
190  rSh.MoveNumParas(true, true);
191  rReq.Done();
192  break;
193 
195  if ( bOutline )
196  lcl_OutlineUpDownWithSubPoints( rSh, false, true );
197  else
198  rSh.MoveNumParas(false, true);
199  rReq.Done();
200  break;
201 
202  case FN_NUM_BULLET_PREV:
203  rSh.GotoPrevNum();
204  rReq.Done();
205  break;
206 
207  case FN_NUM_OR_NONUM:
208  {
209  bool bApi = rReq.IsAPI();
210  bool bDelete = !rSh.IsNoNum(!bApi);
211  if(pArgs )
212  bDelete = static_cast<const SfxBoolItem &>(pArgs->Get(rReq.GetSlot())).GetValue();
213  rSh.NumOrNoNum( bDelete, !bApi );
214  rReq.AppendItem( SfxBoolItem( nSlot, bDelete ) );
215  rReq.Done();
216  }
217  break;
218  default:
219  OSL_ENSURE(false, "wrong dispatcher");
220  return;
221  }
222 }
223 
225 {
226  SfxWhichIter aIter( rSet );
227  sal_uInt16 nWhich = aIter.FirstWhich();
228  SwWrtShell& rSh = GetShell();
229  sal_uInt8 nCurrentNumLevel = rSh.GetNumLevel();
230  while ( nWhich )
231  {
232  switch( nWhich )
233  {
234  case FN_NUM_OR_NONUM:
235  rSet.Put(SfxBoolItem(nWhich, GetShell().IsNoNum(false)));
236  break;
238  case FN_NUM_BULLET_UP:
239  if(!nCurrentNumLevel)
240  rSet.DisableItem(nWhich);
241  break;
243  {
244  sal_uInt8 nUpper = 0;
245  sal_uInt8 nLower = 0;
246  rSh.GetCurrentOutlineLevels( nUpper, nLower );
247  if(nLower == (MAXLEVEL - 1))
248  rSet.DisableItem(nWhich);
249  }
250  break;
251  case FN_NUM_BULLET_DOWN:
252  if(nCurrentNumLevel == (MAXLEVEL - 1))
253  rSet.DisableItem(nWhich);
254  break;
255 
256  case FN_NUM_BULLET_NONUM:
257  if ( rSh.CursorInsideInputField() )
258  {
259  rSet.DisableItem(nWhich);
260  }
261  break;
262  }
263  nWhich = aIter.NextWhich();
264  }
265 }
266 
268  SwBaseShell(_rView)
269 {
270  SetName("List");
271 }
272 
273 /* 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:57
#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:417
const SwNumRule * GetNumRuleAtCurrCursorPos() const
Definition: ednumber.cxx:723
std::vector< SwNode * >::difference_type difference_type
const IDocumentOutlineNodes * getIDocumentOutlineNodesAccess() const
Definition: viewsh.cxx:2612
SwWrtShell & GetShell()
Definition: basesh.cxx:2673
bool Pop(SwCursorShell::PopMode=SwCursorShell::PopMode::DeleteStack)
Definition: wrtsh1.cxx:1708
#define FN_NUM_BULLET_OUTLINE_DOWN
Definition: cmdid.h:92
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:698
sal_uInt16 NextWhich()
bool MakeOutlineSel(SwOutlineNodes::size_type nSttPos, SwOutlineNodes::size_type nEndPos, bool bWithChildren, bool bKillPams=true)
Definition: crstrvl.cxx:1192
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
SwListShell(SwView &rView)
Definition: listsh.cxx:267
#define FN_NUM_BULLET_OFF
Definition: cmdid.h:89
#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:651
const sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:95
void Execute(SfxRequest &)
Definition: listsh.cxx:126
void DelNumRules()
Delete, split enumeration list.
Definition: ednumber.cxx:276
SwOutlineNodes::size_type GetOutlinePos(sal_uInt8 nLevel=UCHAR_MAX)
search "outline position" before previous outline node at given level
Definition: crstrvl.cxx:1169
static void lcl_OutlineUpDownWithSubPoints(SwWrtShell &rSh, bool bMove, bool bUp)
Definition: listsh.cxx:51
static constexpr auto npos
Definition: ndarr.hxx:79
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2235
SfxBindings & GetBindings()
virtual int getOutlineLevel(const tSortedOutlineNodeList::size_type nIdx) const =0
void SetName(const OUString &rName)
#define SFX_OBJECTBAR_OBJECT
bool NumOrNoNum(bool bDelete=false, bool bChkStart=true)
Switch on/off of numbering via Delete/Backspace.
Definition: ednumber.cxx:661
bool OutlineUpDown(short nOffset=1)
Definition: ednumber.cxx:549
#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:612
bool IsNoNum(bool bChkStart=true) const
Definition: ednumber.cxx:679
void NumUpDown(bool bDown=true)
Definition: ednumber.cxx:306
void NoNum()
Paragraphs without enumeration but with indents.
Definition: ednumber.cxx:127
void ClearMark()
Definition: crsrsh.cxx:936
#define FN_NUM_BULLET_UP
Definition: cmdid.h:82
void GotoPrevNum()
Definition: crstrvl.cxx:120
void AppendItem(const SfxPoolItem &)
bool IsAPI() const
bool MoveOutlinePara(SwOutlineNodes::difference_type nOffset)
Definition: ednumber.cxx:572
std::vector< SwNode * >::size_type size_type
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2069
void Ignore()
void GotoNextNum()
go to next/previous point on the same level
Definition: crstrvl.cxx:113
#define FN_NUM_BULLET_NONUM
Definition: cmdid.h:87
void GetState(SfxItemSet &)
Definition: listsh.cxx:224
bool IsOutlineRule() const
Definition: numrule.hxx:239
Definition: view.hxx:146
bool MoveNumParas(bool bUpperLower, bool bUpperLeft)
Definition: ednumber.cxx:427
bool CursorInsideInputField() const
Definition: crstrvl.cxx:960