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