1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
38 #include "swmodule.hxx"
41 #include "globals.hrc"
45 #include "poolfmt.hxx"
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
) )
73 rSh
.MakeOutlineSel( nActPos
, nActPos
, sal_True
);
77 const IDocumentOutlineNodes
* pIDoc( rSh
.getIDocumentOutlineNodesAccess() );
78 const sal_uInt16 nActLevel
= static_cast<sal_uInt16
>(pIDoc
->getOutlineLevel( nActPos
));
79 sal_uInt16 nActEndPos
= nActPos
+ 1;
84 // Move down with subpoints:
85 while ( nActEndPos
< pIDoc
->getOutlineNodesCount() &&
86 pIDoc
->getOutlineLevel( nActEndPos
) > nActLevel
)
89 if ( nActEndPos
< pIDoc
->getOutlineNodesCount() )
91 // The current subpoint which should be moved
92 // starts at nActPos and ends at nActEndPos - 1
94 sal_uInt16 nDest
= nActEndPos
+ 2;
95 while ( nDest
< pIDoc
->getOutlineNodesCount() &&
96 pIDoc
->getOutlineLevel( nDest
) > nActLevel
)
99 nDir
= nDest
- 1 - nActEndPos
;
104 // Move up with subpoints:
108 sal_uInt16 nDest
= nActPos
- 1;
109 while ( nDest
> 0 && pIDoc
->getOutlineLevel( nDest
) > nActLevel
)
112 nDir
= nDest
- nActPos
;
118 rSh
.MoveOutlinePara( nDir
);
119 rSh
.GotoOutline( nActPos
+ nDir
);
124 // Up/down with subpoints:
125 rSh
.OutlineUpDown( bUp
? -1 : 1 );
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();
140 const SwNumRule
* pCurRule
= rSh
.GetCurNumRule();
141 OSL_ENSURE( pCurRule
, "SwListShell::Execute without NumRule" );
142 bool bOutline
= pCurRule
&& pCurRule
->IsOutlineRule();
146 case FN_NUM_BULLET_DOWN
:
147 case FN_NUM_BULLET_UP
:
149 SfxViewFrame
* pFrame
= GetView().GetViewFrame();
152 rSh
.NumUpDown( nSlot
== FN_NUM_BULLET_DOWN
);
153 pFrame
->GetBindings().Invalidate( SID_TABLE_CELL
); // Update status line!
157 case FN_NUM_BULLET_NEXT
:
162 case FN_NUM_BULLET_NONUM
:
167 case FN_NUM_BULLET_OFF
:
170 SfxRequest
aReq( GetView().GetViewFrame(), FN_NUM_BULLET_ON
);
171 aReq
.AppendItem( SfxBoolItem( FN_PARAM_1
, sal_False
) );
177 case FN_NUM_BULLET_OUTLINE_DOWN
:
179 lcl_OutlineUpDownWithSubPoints( rSh
, false, false );
181 rSh
.MoveNumParas(false, false);
185 case FN_NUM_BULLET_OUTLINE_MOVEDOWN
:
187 lcl_OutlineUpDownWithSubPoints( rSh
, true, false );
189 rSh
.MoveNumParas(true, false);
193 case FN_NUM_BULLET_OUTLINE_MOVEUP
:
195 lcl_OutlineUpDownWithSubPoints( rSh
, true, true );
197 rSh
.MoveNumParas(true, true);
201 case FN_NUM_BULLET_OUTLINE_UP
:
203 lcl_OutlineUpDownWithSubPoints( rSh
, false, true );
205 rSh
.MoveNumParas(false, true);
209 case FN_NUM_BULLET_PREV
:
214 case FN_NUM_OR_NONUM
:
216 sal_Bool bApi
= rReq
.IsAPI();
217 sal_Bool bDelete
= !rSh
.IsNoNum(!bApi
);
219 bDelete
= ((SfxBoolItem
&)pArgs
->Get(rReq
.GetSlot())).GetValue();
220 rSh
.NumOrNoNum( bDelete
, !bApi
);
221 rReq
.AppendItem( SfxBoolItem( nSlot
, bDelete
) );
226 OSL_ENSURE(!this, "wrong dispatcher");
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();
241 case FN_NUM_OR_NONUM
:
242 rSet
.Put(SfxBoolItem(nWhich
, GetShell().IsNoNum(sal_False
)));
244 case FN_NUM_BULLET_OUTLINE_UP
:
245 case FN_NUM_BULLET_UP
:
246 if(!nCurrentNumLevel
)
247 rSet
.DisableItem(nWhich
);
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
);
258 case FN_NUM_BULLET_DOWN
:
259 if(nCurrentNumLevel
== (MAXLEVEL
- 1))
260 rSet
.DisableItem(nWhich
);
263 nWhich
= aIter
.NextWhich();
267 SwListShell::SwListShell(SwView
&_rView
) :
270 SetName(OUString("List"));
271 SetHelpId(SW_LISTSHELL
);
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */