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 );
63  SwOutlineNodes::size_type nActEndPos = nActPos + 1;
65 
66  if ( !bUp )
67  {
68  // Move down with subpoints:
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  nActEndPos = nActPos;
98  SwOutlineNodes::size_type nDest = nActPos - 1;
99  while (nDest > 0 &&
100  (!pIDoc->isOutlineInLayout(nDest, *rSh.GetLayout())
101  || nActLevel < pIDoc->getOutlineLevel(nDest)))
102  {
103  --nDest;
104  }
105 
106  nDir = nDest - nActPos;
107  }
108  }
109 
110  if ( nDir )
111  {
112  rSh.MoveOutlinePara( nDir );
113  rSh.GotoOutline( nActPos + nDir );
114  }
115  }
116  else
117  {
118  // Up/down with subpoints:
119  rSh.OutlineUpDown( bUp ? -1 : 1 );
120  }
121 
122  rSh.ClearMark();
124  }
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 
161  case FN_NUM_BULLET_OFF:
162  {
163  rReq.Ignore();
164  SfxRequest aReq( GetView().GetViewFrame(), FN_NUM_BULLET_ON );
165  aReq.AppendItem( SfxBoolItem( FN_PARAM_1, false ) );
166  aReq.Done();
167  rSh.DelNumRules();
168  break;
169  }
170 
172  if ( bOutline )
173  lcl_OutlineUpDownWithSubPoints( rSh, false, false );
174  else
175  rSh.MoveNumParas(false, false);
176  rReq.Done();
177  break;
178 
180  if ( bOutline )
181  lcl_OutlineUpDownWithSubPoints( rSh, true, false );
182  else
183  rSh.MoveNumParas(true, false);
184  rReq.Done();
185  break;
186 
188  if ( bOutline )
189  lcl_OutlineUpDownWithSubPoints( rSh, true, true );
190  else
191  rSh.MoveNumParas(true, true);
192  rReq.Done();
193  break;
194 
196  if ( bOutline )
197  lcl_OutlineUpDownWithSubPoints( rSh, false, true );
198  else
199  rSh.MoveNumParas(false, true);
200  rReq.Done();
201  break;
202 
203  case FN_NUM_BULLET_PREV:
204  rSh.GotoPrevNum();
205  rReq.Done();
206  break;
207 
208  case FN_NUM_OR_NONUM:
209  {
210  bool bApi = rReq.IsAPI();
211  bool bDelete = !rSh.IsNoNum(!bApi);
212  if(pArgs )
213  bDelete = static_cast<const SfxBoolItem &>(pArgs->Get(rReq.GetSlot())).GetValue();
214  rSh.NumOrNoNum( bDelete, !bApi );
215  rReq.AppendItem( SfxBoolItem( nSlot, bDelete ) );
216  rReq.Done();
217  }
218  break;
219  default:
220  OSL_ENSURE(false, "wrong dispatcher");
221  return;
222  }
223 }
224 
226 {
227  SfxWhichIter aIter( rSet );
228  sal_uInt16 nWhich = aIter.FirstWhich();
229  SwWrtShell& rSh = GetShell();
230  sal_uInt8 nCurrentNumLevel = rSh.GetNumLevel();
231  while ( nWhich )
232  {
233  switch( nWhich )
234  {
235  case FN_NUM_OR_NONUM:
236  rSet.Put(SfxBoolItem(nWhich, GetShell().IsNoNum(false)));
237  break;
239  case FN_NUM_BULLET_UP:
240  if(!nCurrentNumLevel)
241  rSet.DisableItem(nWhich);
242  break;
244  {
245  sal_uInt8 nUpper = 0;
246  sal_uInt8 nLower = 0;
247  rSh.GetCurrentOutlineLevels( nUpper, nLower );
248  if(nLower == (MAXLEVEL - 1))
249  rSet.DisableItem(nWhich);
250  }
251  break;
252  case FN_NUM_BULLET_DOWN:
253  if(nCurrentNumLevel == (MAXLEVEL - 1))
254  rSet.DisableItem(nWhich);
255  break;
256 
257  case FN_NUM_BULLET_NONUM:
258  if ( rSh.CursorInsideInputField() )
259  {
260  rSet.DisableItem(nWhich);
261  }
262  break;
263  }
264  nWhich = aIter.NextWhich();
265  }
266 }
267 
269  SwBaseShell(_rView)
270 {
271  SetName("List");
272 }
273 
274 /* 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:419
const SwNumRule * GetNumRuleAtCurrCursorPos() const
Definition: ednumber.cxx:725
std::vector< SwNode * >::difference_type difference_type
const IDocumentOutlineNodes * getIDocumentOutlineNodesAccess() const
Definition: viewsh.cxx:2605
SwWrtShell & GetShell()
Definition: basesh.cxx:2673
bool MakeOutlineSel(SwOutlineNodes::size_type nSttPos, SwOutlineNodes::size_type nEndPos, bool bWithChildren)
Definition: crstrvl.cxx:1180
bool Pop(SwCursorShell::PopMode=SwCursorShell::PopMode::DeleteStack)
Definition: wrtsh1.cxx:1726
#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:700
sal_uInt16 NextWhich()
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
SwListShell(SwView &rView)
Definition: listsh.cxx:268
#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:653
const sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:95
void Execute(SfxRequest &)
Definition: listsh.cxx:127
void DelNumRules()
Delete, split enumeration list.
Definition: ednumber.cxx:277
SwOutlineNodes::size_type GetOutlinePos(sal_uInt8 nLevel=UCHAR_MAX)
search "outline position" before previous outline node at given level
Definition: crstrvl.cxx:1157
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:2229
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:663
bool OutlineUpDown(short nOffset=1)
Definition: ednumber.cxx:551
#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:681
void NumUpDown(bool bDown=true)
Definition: ednumber.cxx:307
void NoNum()
Paragraphs without enumeration but with indents.
Definition: ednumber.cxx:127
void ClearMark()
Definition: crsrsh.cxx:930
#define FN_NUM_BULLET_UP
Definition: cmdid.h:82
void GotoPrevNum()
Definition: crstrvl.cxx:119
void AppendItem(const SfxPoolItem &)
bool IsAPI() const
bool MoveOutlinePara(SwOutlineNodes::difference_type nOffset)
Definition: ednumber.cxx:574
std::vector< SwNode * >::size_type size_type
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2062
void Ignore()
void GotoNextNum()
go to next/previous point on the same level
Definition: crstrvl.cxx:112
#define FN_NUM_BULLET_NONUM
Definition: cmdid.h:87
void GetState(SfxItemSet &)
Definition: listsh.cxx:225
bool IsOutlineRule() const
Definition: numrule.hxx:239
Definition: view.hxx:146
bool MoveNumParas(bool bUpperLower, bool bUpperLeft)
Definition: ednumber.cxx:429
bool CursorInsideInputField() const
Definition: crstrvl.cxx:948