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 <hintids.hxx>
22 #include <editeng/sizeitem.hxx>
23 #include <editeng/brushitem.hxx>
24 #include <sfx2/app.hxx>
25 #include <sfx2/request.hxx>
26 #include <sfx2/objface.hxx>
27 #include <sfx2/bindings.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <svl/stritem.hxx>
30 #include <svl/eitem.hxx>
31 #include <svl/whiter.hxx>
32 #include <svl/intitem.hxx>
33 #include <svl/srchitem.hxx>
34 #include <svx/svxids.hrc>
35 
36 #include <numrule.hxx>
37 #include <fmtornt.hxx>
38 #include <wrtsh.hxx>
39 #include <swmodule.hxx>
40 #include <frmatr.hxx>
41 #include <globals.hrc>
42 #include <uinums.hxx>
43 #include <listsh.hxx>
44 #include <poolfmt.hxx>
45 #include <view.hxx>
46 #include <edtwin.hxx>
47 
48 #define ShellClass_SwListShell
49 #include <sfx2/msg.hxx>
50 #include <swslots.hxx>
51 
53 
55 
56 void SwListShell::InitInterface_Impl()
57 {
58  GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Num_Toolbox);
59 }
60 
61 
62 // #i35572# Functionality of Numbering/Bullet toolbar
63 // for outline numbered paragraphs should match the functions for outlines
64 // available in the navigator. Therefore the code in the following
65 // function is quite similar the code in SwContentTree::ExecCommand.
66 static void lcl_OutlineUpDownWithSubPoints( SwWrtShell& rSh, bool bMove, bool bUp )
67 {
68  const SwOutlineNodes::size_type nActPos = rSh.GetOutlinePos();
69  if ( nActPos < SwOutlineNodes::npos && rSh.IsOutlineMovable( nActPos ) )
70  {
71  rSh.Push();
72  rSh.MakeOutlineSel( nActPos, nActPos, true );
73 
74  if ( bMove )
75  {
77  const int nActLevel = pIDoc->getOutlineLevel( nActPos );
78  SwOutlineNodes::size_type nActEndPos = nActPos + 1;
80 
81  if ( !bUp )
82  {
83  // Move down with subpoints:
84  while ( nActEndPos < pIDoc->getOutlineNodesCount() &&
85  (!pIDoc->isOutlineInLayout(nActEndPos, *rSh.GetLayout())
86  || nActLevel < pIDoc->getOutlineLevel(nActEndPos)))
87  {
88  ++nActEndPos;
89  }
90 
91  if ( nActEndPos < pIDoc->getOutlineNodesCount() )
92  {
93  // The current subpoint which should be moved
94  // starts at nActPos and ends at nActEndPos - 1
95  --nActEndPos;
96  SwOutlineNodes::size_type nDest = nActEndPos + 2;
97  while ( nDest < pIDoc->getOutlineNodesCount() &&
98  (!pIDoc->isOutlineInLayout(nDest, *rSh.GetLayout())
99  || nActLevel < pIDoc->getOutlineLevel(nDest)))
100  {
101  ++nDest;
102  }
103 
104  nDir = nDest - 1 - nActEndPos;
105  }
106  }
107  else
108  {
109  // Move up with subpoints:
110  if ( nActPos > 0 )
111  {
112  nActEndPos = nActPos;
113  SwOutlineNodes::size_type nDest = nActPos - 1;
114  while (nDest > 0 &&
115  (!pIDoc->isOutlineInLayout(nDest, *rSh.GetLayout())
116  || nActLevel < pIDoc->getOutlineLevel(nDest)))
117  {
118  --nDest;
119  }
120 
121  nDir = nDest - nActPos;
122  }
123  }
124 
125  if ( nDir )
126  {
127  rSh.MoveOutlinePara( nDir );
128  rSh.GotoOutline( nActPos + nDir );
129  }
130  }
131  else
132  {
133  // Up/down with subpoints:
134  rSh.OutlineUpDown( bUp ? -1 : 1 );
135  }
136 
137  rSh.ClearMark();
139  }
140 }
141 
143 {
144  const SfxItemSet* pArgs = rReq.GetArgs();
145  const sal_uInt16 nSlot = rReq.GetSlot();
146  SwWrtShell& rSh = GetShell();
147 
148  // #i35572#
149  const SwNumRule* pCurRule = rSh.GetNumRuleAtCurrCursorPos();
150  OSL_ENSURE( pCurRule, "SwListShell::Execute without NumRule" );
151  bool bOutline = pCurRule && pCurRule->IsOutlineRule();
152 
153  switch (nSlot)
154  {
155  case FN_NUM_BULLET_DOWN:
156  case FN_NUM_BULLET_UP:
157  {
158  SfxViewFrame * pFrame = GetView().GetViewFrame();
159 
160  rReq.Done();
161  rSh.NumUpDown( nSlot == FN_NUM_BULLET_DOWN );
162  pFrame->GetBindings().Invalidate( SID_TABLE_CELL ); // Update status line!
163  }
164  break;
165 
166  case FN_NUM_BULLET_NEXT:
167  rSh.GotoNextNum();
168  rReq.Done();
169  break;
170 
171  case FN_NUM_BULLET_NONUM:
172  rSh.NoNum();
173  rReq.Done();
174  break;
175 
176  case FN_NUM_BULLET_OFF:
177  {
178  rReq.Ignore();
179  SfxRequest aReq( GetView().GetViewFrame(), FN_NUM_BULLET_ON );
180  aReq.AppendItem( SfxBoolItem( FN_PARAM_1, false ) );
181  aReq.Done();
182  rSh.DelNumRules();
183  break;
184  }
185 
187  if ( bOutline )
188  lcl_OutlineUpDownWithSubPoints( rSh, false, false );
189  else
190  rSh.MoveNumParas(false, false);
191  rReq.Done();
192  break;
193 
195  if ( bOutline )
196  lcl_OutlineUpDownWithSubPoints( rSh, true, false );
197  else
198  rSh.MoveNumParas(true, false);
199  rReq.Done();
200  break;
201 
203  if ( bOutline )
204  lcl_OutlineUpDownWithSubPoints( rSh, true, true );
205  else
206  rSh.MoveNumParas(true, true);
207  rReq.Done();
208  break;
209 
211  if ( bOutline )
212  lcl_OutlineUpDownWithSubPoints( rSh, false, true );
213  else
214  rSh.MoveNumParas(false, true);
215  rReq.Done();
216  break;
217 
218  case FN_NUM_BULLET_PREV:
219  rSh.GotoPrevNum();
220  rReq.Done();
221  break;
222 
223  case FN_NUM_OR_NONUM:
224  {
225  bool bApi = rReq.IsAPI();
226  bool bDelete = !rSh.IsNoNum(!bApi);
227  if(pArgs )
228  bDelete = static_cast<const SfxBoolItem &>(pArgs->Get(rReq.GetSlot())).GetValue();
229  rSh.NumOrNoNum( bDelete, !bApi );
230  rReq.AppendItem( SfxBoolItem( nSlot, bDelete ) );
231  rReq.Done();
232  }
233  break;
234  default:
235  OSL_ENSURE(false, "wrong dispatcher");
236  return;
237  }
238 }
239 
241 {
242  SfxWhichIter aIter( rSet );
243  sal_uInt16 nWhich = aIter.FirstWhich();
244  SwWrtShell& rSh = GetShell();
245  sal_uInt8 nCurrentNumLevel = rSh.GetNumLevel();
246  while ( nWhich )
247  {
248  switch( nWhich )
249  {
250  case FN_NUM_OR_NONUM:
251  rSet.Put(SfxBoolItem(nWhich, GetShell().IsNoNum(false)));
252  break;
254  case FN_NUM_BULLET_UP:
255  if(!nCurrentNumLevel)
256  rSet.DisableItem(nWhich);
257  break;
259  {
260  sal_uInt8 nUpper = 0;
261  sal_uInt8 nLower = 0;
262  rSh.GetCurrentOutlineLevels( nUpper, nLower );
263  if(nLower == (MAXLEVEL - 1))
264  rSet.DisableItem(nWhich);
265  }
266  break;
267  case FN_NUM_BULLET_DOWN:
268  if(nCurrentNumLevel == (MAXLEVEL - 1))
269  rSet.DisableItem(nWhich);
270  break;
271 
272  case FN_NUM_BULLET_NONUM:
273  if ( rSh.CursorInsideInputField() )
274  {
275  rSet.DisableItem(nWhich);
276  }
277  break;
278  }
279  nWhich = aIter.NextWhich();
280  }
281 }
282 
284  SwBaseShell(_rView)
285 {
286  SetName("List");
287 }
288 
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
bool GetValue() const
#define FN_NUM_OR_NONUM
Definition: cmdid.h:97
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:2618
SwWrtShell & GetShell()
Definition: basesh.cxx:2651
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:91
sal_uInt16 FirstWhich()
#define FN_NUM_BULLET_DOWN
Definition: cmdid.h:80
void Done(bool bRemove=false)
#define FN_NUM_BULLET_OUTLINE_MOVEUP
Definition: cmdid.h:93
#define FN_NUM_BULLET_NEXT
Definition: cmdid.h:83
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:283
#define FN_NUM_BULLET_OFF
Definition: cmdid.h:88
#define FN_NUM_BULLET_PREV
Definition: cmdid.h:82
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:142
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:66
static constexpr auto npos
Definition: ndarr.hxx:80
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2221
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:94
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:92
unsigned char sal_uInt8
Provides outline nodes of a document.
void GotoOutline(SwOutlineNodes::size_type nIdx)
Definition: move.cxx:608
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:926
#define FN_NUM_BULLET_UP
Definition: cmdid.h:81
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:2075
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:86
void GetState(SfxItemSet &)
Definition: listsh.cxx:240
bool IsOutlineRule() const
Definition: numrule.hxx:238
Definition: view.hxx:146
bool MoveNumParas(bool bUpperLower, bool bUpperLeft)
Definition: ednumber.cxx:429
bool CursorInsideInputField() const
Definition: crstrvl.cxx:948