update credits
[LibreOffice.git] / sw / source / ui / shells / listsh.cxx
blobddbc1b371dd7e4838ac7bf85da3b502311aa3583
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 "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 <svl/stritem.hxx>
29 #include <svl/eitem.hxx>
30 #include <svl/whiter.hxx>
31 #include <svl/intitem.hxx>
32 #include <tools/shl.hxx>
33 #include <svl/srchitem.hxx>
35 #include <numrule.hxx>
36 #include <fmtornt.hxx>
37 #include "wrtsh.hxx"
38 #include "swmodule.hxx"
39 #include "frmatr.hxx"
40 #include "helpid.h"
41 #include "globals.hrc"
42 #include "shells.hrc"
43 #include "uinums.hxx"
44 #include "listsh.hxx"
45 #include "poolfmt.hxx"
46 #include "view.hxx"
47 #include "edtwin.hxx"
49 #define SwListShell
50 #include <sfx2/msg.hxx>
51 #include "swslots.hxx"
53 #include <IDocumentOutlineNodes.hxx>
55 SFX_IMPL_INTERFACE(SwListShell, SwBaseShell, SW_RES(STR_SHELLNAME_LIST))
57 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_NUM_TOOLBOX));
61 TYPEINIT1(SwListShell,SwBaseShell)
63 // #i35572# Functionality of Numbering/Bullet toolbar
64 // for outline numbered paragraphs should match the functions for outlines
65 // available in the navigator. Therefore the code in the following
66 // function is quite similar the code in SwContentTree::ExecCommand.
67 static void lcl_OutlineUpDownWithSubPoints( SwWrtShell& rSh, bool bMove, bool bUp )
69 const sal_uInt16 nActPos = rSh.GetOutlinePos();
70 if ( nActPos < USHRT_MAX && rSh.IsOutlineMovable( nActPos ) )
72 rSh.Push();
73 rSh.MakeOutlineSel( nActPos, nActPos, sal_True );
75 if ( bMove )
77 const IDocumentOutlineNodes* pIDoc( rSh.getIDocumentOutlineNodesAccess() );
78 const sal_uInt16 nActLevel = static_cast<sal_uInt16>(pIDoc->getOutlineLevel( nActPos ));
79 sal_uInt16 nActEndPos = nActPos + 1;
80 sal_Int16 nDir = 0;
82 if ( !bUp )
84 // Move down with subpoints:
85 while ( nActEndPos < pIDoc->getOutlineNodesCount() &&
86 pIDoc->getOutlineLevel( nActEndPos ) > nActLevel )
87 ++nActEndPos;
89 if ( nActEndPos < pIDoc->getOutlineNodesCount() )
91 // The current subpoint which should be moved
92 // starts at nActPos and ends at nActEndPos - 1
93 --nActEndPos;
94 sal_uInt16 nDest = nActEndPos + 2;
95 while ( nDest < pIDoc->getOutlineNodesCount() &&
96 pIDoc->getOutlineLevel( nDest ) > nActLevel )
97 ++nDest;
99 nDir = nDest - 1 - nActEndPos;
102 else
104 // Move up with subpoints:
105 if ( nActPos > 0 )
107 --nActEndPos;
108 sal_uInt16 nDest = nActPos - 1;
109 while ( nDest > 0 && pIDoc->getOutlineLevel( nDest ) > nActLevel )
110 --nDest;
112 nDir = nDest - nActPos;
116 if ( nDir )
118 rSh.MoveOutlinePara( nDir );
119 rSh.GotoOutline( nActPos + nDir );
122 else
124 // Up/down with subpoints:
125 rSh.OutlineUpDown( bUp ? -1 : 1 );
128 rSh.ClearMark();
129 rSh.Pop( sal_False );
133 void SwListShell::Execute(SfxRequest &rReq)
135 const SfxItemSet* pArgs = rReq.GetArgs();
136 sal_uInt16 nSlot = rReq.GetSlot();
137 SwWrtShell& rSh = GetShell();
139 // #i35572#
140 const SwNumRule* pCurRule = rSh.GetCurNumRule();
141 OSL_ENSURE( pCurRule, "SwListShell::Execute without NumRule" );
142 bool bOutline = pCurRule && pCurRule->IsOutlineRule();
144 switch (nSlot)
146 case FN_NUM_BULLET_DOWN:
147 case FN_NUM_BULLET_UP:
149 SfxViewFrame * pFrame = GetView().GetViewFrame();
151 rReq.Done();
152 rSh.NumUpDown( nSlot == FN_NUM_BULLET_DOWN );
153 pFrame->GetBindings().Invalidate( SID_TABLE_CELL ); // Update status line!
155 break;
157 case FN_NUM_BULLET_NEXT:
158 rSh.GotoNextNum();
159 rReq.Done();
160 break;
162 case FN_NUM_BULLET_NONUM:
163 rSh.NoNum();
164 rReq.Done();
165 break;
167 case FN_NUM_BULLET_OFF:
169 rReq.Ignore();
170 SfxRequest aReq( GetView().GetViewFrame(), FN_NUM_BULLET_ON );
171 aReq.AppendItem( SfxBoolItem( FN_PARAM_1, sal_False ) );
172 aReq.Done();
173 rSh.DelNumRules();
174 break;
177 case FN_NUM_BULLET_OUTLINE_DOWN:
178 if ( bOutline )
179 lcl_OutlineUpDownWithSubPoints( rSh, false, false );
180 else
181 rSh.MoveNumParas(false, false);
182 rReq.Done();
183 break;
185 case FN_NUM_BULLET_OUTLINE_MOVEDOWN:
186 if ( bOutline )
187 lcl_OutlineUpDownWithSubPoints( rSh, true, false );
188 else
189 rSh.MoveNumParas(true, false);
190 rReq.Done();
191 break;
193 case FN_NUM_BULLET_OUTLINE_MOVEUP:
194 if ( bOutline )
195 lcl_OutlineUpDownWithSubPoints( rSh, true, true );
196 else
197 rSh.MoveNumParas(true, true);
198 rReq.Done();
199 break;
201 case FN_NUM_BULLET_OUTLINE_UP:
202 if ( bOutline )
203 lcl_OutlineUpDownWithSubPoints( rSh, false, true );
204 else
205 rSh.MoveNumParas(false, true);
206 rReq.Done();
207 break;
209 case FN_NUM_BULLET_PREV:
210 rSh.GotoPrevNum();
211 rReq.Done();
212 break;
214 case FN_NUM_OR_NONUM:
216 sal_Bool bApi = rReq.IsAPI();
217 sal_Bool bDelete = !rSh.IsNoNum(!bApi);
218 if(pArgs )
219 bDelete = ((SfxBoolItem &)pArgs->Get(rReq.GetSlot())).GetValue();
220 rSh.NumOrNoNum( bDelete, !bApi );
221 rReq.AppendItem( SfxBoolItem( nSlot, bDelete ) );
222 rReq.Done();
224 break;
225 default:
226 OSL_ENSURE(!this, "wrong dispatcher");
227 return;
231 void SwListShell::GetState(SfxItemSet &rSet)
233 SfxWhichIter aIter( rSet );
234 sal_uInt16 nWhich = aIter.FirstWhich();
235 SwWrtShell& rSh = GetShell();
236 sal_uInt8 nCurrentNumLevel = rSh.GetNumLevel();
237 while ( nWhich )
239 switch( nWhich )
241 case FN_NUM_OR_NONUM:
242 rSet.Put(SfxBoolItem(nWhich, GetShell().IsNoNum(sal_False)));
243 break;
244 case FN_NUM_BULLET_OUTLINE_UP:
245 case FN_NUM_BULLET_UP:
246 if(!nCurrentNumLevel)
247 rSet.DisableItem(nWhich);
248 break;
249 case FN_NUM_BULLET_OUTLINE_DOWN :
251 sal_uInt8 nUpper = 0;
252 sal_uInt8 nLower = 0;
253 rSh.GetCurrentOutlineLevels( nUpper, nLower );
254 if(nLower == (MAXLEVEL - 1))
255 rSet.DisableItem(nWhich);
257 break;
258 case FN_NUM_BULLET_DOWN:
259 if(nCurrentNumLevel == (MAXLEVEL - 1))
260 rSet.DisableItem(nWhich);
261 break;
263 nWhich = aIter.NextWhich();
267 SwListShell::SwListShell(SwView &_rView) :
268 SwBaseShell(_rView)
270 SetName(OUString("List"));
271 SetHelpId(SW_LISTSHELL);
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */