Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / shells / listsh.cxx
blobf6100cc0a48a5c7b47799105a7e264f2cbcf0815
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
29 #include <numrule.hxx>
30 #include <wrtsh.hxx>
31 #include <listsh.hxx>
32 #include <view.hxx>
34 #define ShellClass_SwListShell
35 #include <sfx2/msg.hxx>
36 #include <swslots.hxx>
38 #include <IDocumentOutlineNodes.hxx>
40 SFX_IMPL_INTERFACE(SwListShell, SwBaseShell)
42 void SwListShell::InitInterface_Impl()
44 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Num_Toolbox);
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 )
54 const SwOutlineNodes::size_type nActPos = rSh.GetOutlinePos();
55 if ( !(nActPos < SwOutlineNodes::npos && rSh.IsOutlineMovable( nActPos )) )
56 return;
58 rSh.Push();
59 rSh.MakeOutlineSel( nActPos, nActPos, true );
61 if ( bMove )
63 const IDocumentOutlineNodes* pIDoc( rSh.getIDocumentOutlineNodesAccess() );
64 const int nActLevel = pIDoc->getOutlineLevel( nActPos );
65 SwOutlineNodes::difference_type nDir = 0;
67 if ( !bUp )
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)))
75 ++nActEndPos;
78 if ( nActEndPos < pIDoc->getOutlineNodesCount() )
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)))
88 ++nDest;
91 nDir = nDest - 1 - nActEndPos;
94 else
96 // Move up with subpoints:
97 if ( nActPos > 0 )
99 SwOutlineNodes::size_type nDest = nActPos - 1;
100 while (nDest > 0 &&
101 (!pIDoc->isOutlineInLayout(nDest, *rSh.GetLayout())
102 || nActLevel < pIDoc->getOutlineLevel(nDest)))
104 --nDest;
107 nDir = nDest - nActPos;
111 if ( nDir )
113 rSh.MoveOutlinePara( nDir );
114 rSh.GotoOutline( nActPos + nDir );
117 else
119 // Up/down with subpoints:
120 rSh.OutlineUpDown( bUp ? -1 : 1 );
123 rSh.ClearMark();
124 rSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
127 void SwListShell::Execute(SfxRequest &rReq)
129 const SfxItemSet* pArgs = rReq.GetArgs();
130 const sal_uInt16 nSlot = rReq.GetSlot();
131 SwWrtShell& rSh = GetShell();
133 // #i35572#
134 const SwNumRule* pCurRule = rSh.GetNumRuleAtCurrCursorPos();
135 OSL_ENSURE( pCurRule, "SwListShell::Execute without NumRule" );
136 bool bOutline = pCurRule && pCurRule->IsOutlineRule();
138 switch (nSlot)
140 case FN_NUM_BULLET_DOWN:
141 case FN_NUM_BULLET_UP:
143 SfxViewFrame& rFrame = GetView().GetViewFrame();
145 rReq.Done();
146 rSh.NumUpDown( nSlot == FN_NUM_BULLET_DOWN );
147 rFrame.GetBindings().Invalidate( SID_TABLE_CELL ); // Update status line!
149 break;
151 case FN_NUM_BULLET_NEXT:
152 rSh.GotoNextNum();
153 rReq.Done();
154 break;
156 case FN_NUM_BULLET_NONUM:
157 rSh.NoNum();
158 rReq.Done();
159 break;
161 case FN_NUM_BULLET_OUTLINE_DOWN:
162 if ( bOutline )
163 lcl_OutlineUpDownWithSubPoints( rSh, false, false );
164 else
165 rSh.MoveNumParas(false, false);
166 rReq.Done();
167 break;
169 case FN_NUM_BULLET_OUTLINE_MOVEDOWN:
170 if ( bOutline )
171 lcl_OutlineUpDownWithSubPoints( rSh, true, false );
172 else
173 rSh.MoveNumParas(true, false);
174 rReq.Done();
175 break;
177 case FN_NUM_BULLET_OUTLINE_MOVEUP:
178 if ( bOutline )
179 lcl_OutlineUpDownWithSubPoints( rSh, true, true );
180 else
181 rSh.MoveNumParas(true, true);
182 rReq.Done();
183 break;
185 case FN_NUM_BULLET_OUTLINE_UP:
186 if ( bOutline )
187 lcl_OutlineUpDownWithSubPoints( rSh, false, true );
188 else
189 rSh.MoveNumParas(false, true);
190 rReq.Done();
191 break;
193 case FN_NUM_BULLET_PREV:
194 rSh.GotoPrevNum();
195 rReq.Done();
196 break;
198 case FN_NUM_OR_NONUM:
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();
208 break;
209 default:
210 OSL_ENSURE(false, "wrong dispatcher");
211 return;
215 void SwListShell::GetState(SfxItemSet &rSet)
217 SfxWhichIter aIter( rSet );
218 sal_uInt16 nWhich = aIter.FirstWhich();
219 SwWrtShell& rSh = GetShell();
220 sal_uInt8 nCurrentNumLevel = rSh.GetNumLevel();
221 while ( nWhich )
223 switch( nWhich )
225 case FN_NUM_OR_NONUM:
226 rSet.Put(SfxBoolItem(nWhich, GetShell().IsNoNum(false)));
227 break;
228 case FN_NUM_BULLET_OUTLINE_UP:
229 case FN_NUM_BULLET_UP:
230 if(!nCurrentNumLevel)
231 rSet.DisableItem(nWhich);
232 break;
233 case FN_NUM_BULLET_OUTLINE_DOWN :
235 sal_uInt8 nUpper = 0;
236 sal_uInt8 nLower = 0;
237 rSh.GetCurrentOutlineLevels( nUpper, nLower );
238 if(nLower == (MAXLEVEL - 1))
239 rSet.DisableItem(nWhich);
241 break;
242 case FN_NUM_BULLET_DOWN:
243 if(nCurrentNumLevel == (MAXLEVEL - 1))
244 rSet.DisableItem(nWhich);
245 break;
247 case FN_NUM_BULLET_NONUM:
248 if ( rSh.CursorInsideInputField() )
250 rSet.DisableItem(nWhich);
252 break;
254 nWhich = aIter.NextWhich();
258 SwListShell::SwListShell(SwView &_rView) :
259 SwBaseShell(_rView)
261 SetName("List");
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */