Line data Source code
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 <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>
34 :
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"
48 :
49 : #define SwListShell
50 : #include <sfx2/msg.hxx>
51 : #include "swslots.hxx"
52 :
53 : #include <IDocumentOutlineNodes.hxx>
54 :
55 465 : SFX_IMPL_INTERFACE(SwListShell, SwBaseShell, SW_RES(STR_SHELLNAME_LIST))
56 : {
57 37 : SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_NUM_TOOLBOX));
58 37 : }
59 :
60 630 : TYPEINIT1(SwListShell,SwBaseShell)
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 0 : static void lcl_OutlineUpDownWithSubPoints( SwWrtShell& rSh, bool bMove, bool bUp )
67 : {
68 0 : const sal_uInt16 nActPos = rSh.GetOutlinePos();
69 0 : if ( nActPos < USHRT_MAX && rSh.IsOutlineMovable( nActPos ) )
70 : {
71 0 : rSh.Push();
72 0 : rSh.MakeOutlineSel( nActPos, nActPos, sal_True );
73 :
74 0 : if ( bMove )
75 : {
76 0 : const IDocumentOutlineNodes* pIDoc( rSh.getIDocumentOutlineNodesAccess() );
77 0 : const sal_uInt16 nActLevel = static_cast<sal_uInt16>(pIDoc->getOutlineLevel( nActPos ));
78 0 : sal_uInt16 nActEndPos = nActPos + 1;
79 0 : sal_Int16 nDir = 0;
80 :
81 0 : if ( !bUp )
82 : {
83 : // Move down with subpoints:
84 0 : while ( nActEndPos < pIDoc->getOutlineNodesCount() &&
85 0 : pIDoc->getOutlineLevel( nActEndPos ) > nActLevel )
86 0 : ++nActEndPos;
87 :
88 0 : if ( nActEndPos < pIDoc->getOutlineNodesCount() )
89 : {
90 : // The current subpoint which should be moved
91 : // starts at nActPos and ends at nActEndPos - 1
92 0 : --nActEndPos;
93 0 : sal_uInt16 nDest = nActEndPos + 2;
94 0 : while ( nDest < pIDoc->getOutlineNodesCount() &&
95 0 : pIDoc->getOutlineLevel( nDest ) > nActLevel )
96 0 : ++nDest;
97 :
98 0 : nDir = nDest - 1 - nActEndPos;
99 : }
100 : }
101 : else
102 : {
103 : // Move up with subpoints:
104 0 : if ( nActPos > 0 )
105 : {
106 0 : --nActEndPos;
107 0 : sal_uInt16 nDest = nActPos - 1;
108 0 : while ( nDest > 0 && pIDoc->getOutlineLevel( nDest ) > nActLevel )
109 0 : --nDest;
110 :
111 0 : nDir = nDest - nActPos;
112 : }
113 : }
114 :
115 0 : if ( nDir )
116 : {
117 0 : rSh.MoveOutlinePara( nDir );
118 0 : rSh.GotoOutline( nActPos + nDir );
119 : }
120 : }
121 : else
122 : {
123 : // Up/down with subpoints:
124 0 : rSh.OutlineUpDown( bUp ? -1 : 1 );
125 : }
126 :
127 0 : rSh.ClearMark();
128 0 : rSh.Pop( sal_False );
129 : }
130 0 : }
131 :
132 0 : void SwListShell::Execute(SfxRequest &rReq)
133 : {
134 0 : const SfxItemSet* pArgs = rReq.GetArgs();
135 0 : sal_uInt16 nSlot = rReq.GetSlot();
136 0 : SwWrtShell& rSh = GetShell();
137 :
138 : // #i35572#
139 0 : const SwNumRule* pCurRule = rSh.GetNumRuleAtCurrCrsrPos();
140 : OSL_ENSURE( pCurRule, "SwListShell::Execute without NumRule" );
141 0 : bool bOutline = pCurRule && pCurRule->IsOutlineRule();
142 :
143 0 : switch (nSlot)
144 : {
145 : case FN_NUM_BULLET_DOWN:
146 : case FN_NUM_BULLET_UP:
147 : {
148 0 : SfxViewFrame * pFrame = GetView().GetViewFrame();
149 :
150 0 : rReq.Done();
151 0 : rSh.NumUpDown( nSlot == FN_NUM_BULLET_DOWN );
152 0 : pFrame->GetBindings().Invalidate( SID_TABLE_CELL ); // Update status line!
153 : }
154 0 : break;
155 :
156 : case FN_NUM_BULLET_NEXT:
157 0 : rSh.GotoNextNum();
158 0 : rReq.Done();
159 0 : break;
160 :
161 : case FN_NUM_BULLET_NONUM:
162 0 : rSh.NoNum();
163 0 : rReq.Done();
164 0 : break;
165 :
166 : case FN_NUM_BULLET_OFF:
167 : {
168 0 : rReq.Ignore();
169 0 : SfxRequest aReq( GetView().GetViewFrame(), FN_NUM_BULLET_ON );
170 0 : aReq.AppendItem( SfxBoolItem( FN_PARAM_1, false ) );
171 0 : aReq.Done();
172 0 : rSh.DelNumRules();
173 0 : break;
174 : }
175 :
176 : case FN_NUM_BULLET_OUTLINE_DOWN:
177 0 : if ( bOutline )
178 0 : lcl_OutlineUpDownWithSubPoints( rSh, false, false );
179 : else
180 0 : rSh.MoveNumParas(false, false);
181 0 : rReq.Done();
182 0 : break;
183 :
184 : case FN_NUM_BULLET_OUTLINE_MOVEDOWN:
185 0 : if ( bOutline )
186 0 : lcl_OutlineUpDownWithSubPoints( rSh, true, false );
187 : else
188 0 : rSh.MoveNumParas(true, false);
189 0 : rReq.Done();
190 0 : break;
191 :
192 : case FN_NUM_BULLET_OUTLINE_MOVEUP:
193 0 : if ( bOutline )
194 0 : lcl_OutlineUpDownWithSubPoints( rSh, true, true );
195 : else
196 0 : rSh.MoveNumParas(true, true);
197 0 : rReq.Done();
198 0 : break;
199 :
200 : case FN_NUM_BULLET_OUTLINE_UP:
201 0 : if ( bOutline )
202 0 : lcl_OutlineUpDownWithSubPoints( rSh, false, true );
203 : else
204 0 : rSh.MoveNumParas(false, true);
205 0 : rReq.Done();
206 0 : break;
207 :
208 : case FN_NUM_BULLET_PREV:
209 0 : rSh.GotoPrevNum();
210 0 : rReq.Done();
211 0 : break;
212 :
213 : case FN_NUM_OR_NONUM:
214 : {
215 0 : sal_Bool bApi = rReq.IsAPI();
216 0 : sal_Bool bDelete = !rSh.IsNoNum(!bApi);
217 0 : if(pArgs )
218 0 : bDelete = ((SfxBoolItem &)pArgs->Get(rReq.GetSlot())).GetValue();
219 0 : rSh.NumOrNoNum( bDelete, !bApi );
220 0 : rReq.AppendItem( SfxBoolItem( nSlot, bDelete ) );
221 0 : rReq.Done();
222 : }
223 0 : break;
224 : default:
225 : OSL_ENSURE(!this, "wrong dispatcher");
226 0 : return;
227 : }
228 : }
229 :
230 0 : void SwListShell::GetState(SfxItemSet &rSet)
231 : {
232 0 : SfxWhichIter aIter( rSet );
233 0 : sal_uInt16 nWhich = aIter.FirstWhich();
234 0 : SwWrtShell& rSh = GetShell();
235 0 : sal_uInt8 nCurrentNumLevel = rSh.GetNumLevel();
236 0 : while ( nWhich )
237 : {
238 0 : switch( nWhich )
239 : {
240 : case FN_NUM_OR_NONUM:
241 0 : rSet.Put(SfxBoolItem(nWhich, GetShell().IsNoNum(sal_False)));
242 0 : break;
243 : case FN_NUM_BULLET_OUTLINE_UP:
244 : case FN_NUM_BULLET_UP:
245 0 : if(!nCurrentNumLevel)
246 0 : rSet.DisableItem(nWhich);
247 0 : break;
248 : case FN_NUM_BULLET_OUTLINE_DOWN :
249 : {
250 0 : sal_uInt8 nUpper = 0;
251 0 : sal_uInt8 nLower = 0;
252 0 : rSh.GetCurrentOutlineLevels( nUpper, nLower );
253 0 : if(nLower == (MAXLEVEL - 1))
254 0 : rSet.DisableItem(nWhich);
255 : }
256 0 : break;
257 : case FN_NUM_BULLET_DOWN:
258 0 : if(nCurrentNumLevel == (MAXLEVEL - 1))
259 0 : rSet.DisableItem(nWhich);
260 0 : break;
261 :
262 : case FN_NUM_BULLET_NONUM:
263 0 : if ( rSh.CrsrInsideInputFld() )
264 : {
265 0 : rSet.DisableItem(nWhich);
266 : }
267 0 : break;
268 : }
269 0 : nWhich = aIter.NextWhich();
270 0 : }
271 0 : }
272 :
273 45 : SwListShell::SwListShell(SwView &_rView) :
274 45 : SwBaseShell(_rView)
275 : {
276 45 : SetName(OUString("List"));
277 45 : SetHelpId(SW_LISTSHELL);
278 45 : }
279 :
280 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|