merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / shells / listsh.cxx
blob1cc1d6a14558eb83867603292c4d474e2977d548
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: listsh.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include "cmdid.h"
36 #include "hintids.hxx"
37 #include <svx/sizeitem.hxx>
38 #include <svx/brshitem.hxx>
39 #include <sfx2/app.hxx>
40 #include <sfx2/request.hxx>
41 #include <sfx2/objface.hxx>
42 #include <sfx2/bindings.hxx>
43 #include <svtools/stritem.hxx>
44 #include <svtools/eitem.hxx>
45 #include <tools/urlobj.hxx>
46 #include <svtools/whiter.hxx>
47 #include <svtools/intitem.hxx>
48 #include <tools/shl.hxx>
49 #include <svx/srchitem.hxx>
51 // --> FME 2005-01-04 #i35572#
52 #include <numrule.hxx>
53 // <--
54 #include <fmtornt.hxx>
55 #include "wrtsh.hxx"
56 #include "swmodule.hxx"
57 #include "frmatr.hxx"
58 #include "helpid.h"
59 #include "globals.hrc"
60 #include "shells.hrc"
61 #include "uinums.hxx"
62 #include "listsh.hxx"
63 #include "poolfmt.hxx"
64 #include "view.hxx"
65 #include "edtwin.hxx"
67 #define SwListShell
68 #include <sfx2/msg.hxx>
69 #include "swslots.hxx"
71 #include <IDocumentOutlineNodes.hxx>
73 SFX_IMPL_INTERFACE(SwListShell, SwBaseShell, SW_RES(STR_SHELLNAME_LIST))
75 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_NUM_TOOLBOX));
79 TYPEINIT1(SwListShell,SwBaseShell)
81 // --> FME 2005-01-04 #i35572# Functionality of Numbering/Bullet toolbar
82 // for outline numbered paragraphs should match the functions for outlines
83 // available in the navigator. Therefore the code in the following
84 // function is quite similar the the code in SwContentTree::ExecCommand.
85 void lcl_OutlineUpDownWithSubPoints( SwWrtShell& rSh, bool bMove, bool bUp )
87 const sal_uInt16 nActPos = rSh.GetOutlinePos();
88 if ( nActPos < USHRT_MAX && rSh.IsOutlineMovable( nActPos ) )
90 rSh.Push();
91 rSh.MakeOutlineSel( nActPos, nActPos, TRUE );
93 if ( bMove )
95 const IDocumentOutlineNodes* pIDoc( rSh.getIDocumentOutlineNodesAccess() );
96 const sal_uInt16 nActLevel = static_cast<sal_uInt16>(pIDoc->getOutlineLevel( nActPos ));
97 sal_uInt16 nActEndPos = nActPos + 1;
98 sal_Int16 nDir = 0;
100 if ( !bUp )
102 // Move down with subpoints:
103 while ( nActEndPos < pIDoc->getOutlineNodesCount() &&
104 pIDoc->getOutlineLevel( nActEndPos ) > nActLevel )
105 ++nActEndPos;
107 if ( nActEndPos < pIDoc->getOutlineNodesCount() )
109 // The current subpoint which should be moved
110 // starts at nActPos and ends at nActEndPos - 1
111 --nActEndPos;
112 sal_uInt16 nDest = nActEndPos + 2;
113 while ( nDest < pIDoc->getOutlineNodesCount() &&
114 pIDoc->getOutlineLevel( nDest ) > nActLevel )
115 ++nDest;
117 nDir = nDest - 1 - nActEndPos;
120 else
122 // Move up with subpoints:
123 if ( nActPos > 0 )
125 --nActEndPos;
126 sal_uInt16 nDest = nActPos - 1;
127 while ( nDest > 0 && pIDoc->getOutlineLevel( nDest ) > nActLevel )
128 --nDest;
130 nDir = nDest - nActPos;
134 if ( nDir )
136 rSh.MoveOutlinePara( nDir );
137 rSh.GotoOutline( nActPos + nDir );
140 else
142 // Up/down with subpoints:
143 rSh.OutlineUpDown( bUp ? -1 : 1 );
146 rSh.ClearMark();
147 rSh.Pop( sal_False );
150 // <--
152 void SwListShell::Execute(SfxRequest &rReq)
154 const SfxItemSet* pArgs = rReq.GetArgs();
155 USHORT nSlot = rReq.GetSlot();
156 SwWrtShell& rSh = GetShell();
158 // --> FME 2005-01-04 #i35572#
159 const SwNumRule* pCurRule = rSh.GetCurNumRule();
160 ASSERT( pCurRule, "SwListShell::Execute without NumRule" )
161 bool bOutline = pCurRule && pCurRule->IsOutlineRule();
162 // <--
164 switch (nSlot)
166 case FN_NUM_BULLET_DOWN:
167 case FN_NUM_BULLET_UP:
169 SfxViewFrame * pFrame = GetView().GetViewFrame();
171 rReq.Done();
172 rSh.NumUpDown( ( nSlot == FN_NUM_BULLET_DOWN )
173 ? TRUE
174 : FALSE );
175 pFrame->GetBindings().Invalidate( SID_TABLE_CELL ); // StatusZeile updaten!
177 break;
179 case FN_NUM_BULLET_NEXT:
180 rSh.GotoNextNum();
181 rReq.Done();
182 break;
184 case FN_NUM_BULLET_NONUM:
185 rSh.NoNum();
186 rReq.Done();
187 break;
189 case FN_NUM_BULLET_OFF:
191 rReq.Ignore();
192 SfxRequest aReq( GetView().GetViewFrame(), FN_NUM_BULLET_ON );
193 aReq.AppendItem( SfxBoolItem( FN_PARAM_1, FALSE ) );
194 aReq.Done();
195 rSh.DelNumRules();
196 break;
199 case FN_NUM_BULLET_OUTLINE_DOWN:
200 if ( bOutline )
201 lcl_OutlineUpDownWithSubPoints( rSh, false, false );
202 else
203 rSh.MoveNumParas(FALSE, FALSE);
204 rReq.Done();
205 break;
207 case FN_NUM_BULLET_OUTLINE_MOVEDOWN:
208 if ( bOutline )
209 lcl_OutlineUpDownWithSubPoints( rSh, true, false );
210 else
211 rSh.MoveNumParas(TRUE, FALSE);
212 rReq.Done();
213 break;
215 case FN_NUM_BULLET_OUTLINE_MOVEUP:
216 if ( bOutline )
217 lcl_OutlineUpDownWithSubPoints( rSh, true, true );
218 else
219 rSh.MoveNumParas(TRUE, TRUE);
220 rReq.Done();
221 break;
223 case FN_NUM_BULLET_OUTLINE_UP:
224 if ( bOutline )
225 lcl_OutlineUpDownWithSubPoints( rSh, false, true );
226 else
227 rSh.MoveNumParas(FALSE, TRUE);
228 rReq.Done();
229 break;
231 case FN_NUM_BULLET_PREV:
232 rSh.GotoPrevNum();
233 rReq.Done();
234 break;
236 case FN_NUM_OR_NONUM:
238 BOOL bApi = rReq.IsAPI();
239 BOOL bDelete = !rSh.IsNoNum(!bApi);
240 if(pArgs )
241 bDelete = ((SfxBoolItem &)pArgs->Get(rReq.GetSlot())).GetValue();
242 rSh.NumOrNoNum( bDelete, !bApi );
243 rReq.AppendItem( SfxBoolItem( nSlot, bDelete ) );
244 rReq.Done();
246 break;
247 default:
248 ASSERT(!this, falscher Dispatcher);
249 return;
254 void SwListShell::GetState(SfxItemSet &rSet)
256 SfxWhichIter aIter( rSet );
257 USHORT nWhich = aIter.FirstWhich();
258 SwWrtShell& rSh = GetShell();
259 BYTE nCurrentNumLevel = rSh.GetNumLevel();
260 while ( nWhich )
262 switch( nWhich )
264 case FN_NUM_OR_NONUM:
265 rSet.Put(SfxBoolItem(nWhich, GetShell().IsNoNum(FALSE)));
266 break;
267 case FN_NUM_BULLET_OUTLINE_UP:
268 case FN_NUM_BULLET_UP:
269 if(!nCurrentNumLevel)
270 rSet.DisableItem(nWhich);
271 break;
272 case FN_NUM_BULLET_OUTLINE_DOWN :
274 sal_uInt8 nUpper = 0;
275 sal_uInt8 nLower = 0;
276 rSh.GetCurrentOutlineLevels( nUpper, nLower );
277 if(nLower == (MAXLEVEL - 1))
278 rSet.DisableItem(nWhich);
280 break;
281 case FN_NUM_BULLET_DOWN:
282 if(nCurrentNumLevel == (MAXLEVEL - 1))
283 rSet.DisableItem(nWhich);
284 break;
286 nWhich = aIter.NextWhich();
291 SwListShell::SwListShell(SwView &_rView) :
292 SwBaseShell(_rView)
294 SetName(String::CreateFromAscii("List"));
295 SetHelpId(SW_LISTSHELL);