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 <sfx2/request.hxx>
22 #include <sfx2/objface.hxx>
23 #include <sfx2/bindings.hxx>
24 #include <sfx2/viewfrm.hxx>
25 #include <svl/eitem.hxx>
26 #include <svl/whiter.hxx>
27 #include <osl/diagnose.h>
29 #include <numrule.hxx>
34 #define ShellClass_SwListShell
35 #include <sfx2/msg.hxx>
36 #include <swslots.hxx>
38 #include <IDocumentOutlineNodes.hxx>
40 SFX_IMPL_INTERFACE(SwListShell
, SwBaseShell
)
42 void SwListShell::InitInterface_Impl()
44 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT
, SfxVisibilityFlags::Invisible
, ToolbarId::Num_Toolbox
);
48 // #i35572# Functionality of Numbering/Bullet toolbar
49 // for outline numbered paragraphs should match the functions for outlines
50 // available in the navigator. Therefore the code in the following
51 // function is quite similar the code in SwContentTree::ExecCommand.
52 static void lcl_OutlineUpDownWithSubPoints( SwWrtShell
& rSh
, bool bMove
, bool bUp
)
54 const SwOutlineNodes::size_type nActPos
= rSh
.GetOutlinePos();
55 if ( !(nActPos
< SwOutlineNodes::npos
&& rSh
.IsOutlineMovable( nActPos
)) )
59 rSh
.MakeOutlineSel( nActPos
, nActPos
, true );
63 const IDocumentOutlineNodes
* pIDoc( rSh
.getIDocumentOutlineNodesAccess() );
64 const int nActLevel
= pIDoc
->getOutlineLevel( nActPos
);
65 SwOutlineNodes::difference_type nDir
= 0;
69 // Move down with subpoints:
70 SwOutlineNodes::size_type nActEndPos
= nActPos
+ 1;
71 while ( nActEndPos
< pIDoc
->getOutlineNodesCount() &&
72 (!pIDoc
->isOutlineInLayout(nActEndPos
, *rSh
.GetLayout())
73 || nActLevel
< pIDoc
->getOutlineLevel(nActEndPos
)))
78 if ( nActEndPos
< pIDoc
->getOutlineNodesCount() )
80 // The current subpoint which should be moved
81 // starts at nActPos and ends at nActEndPos - 1
83 SwOutlineNodes::size_type nDest
= nActEndPos
+ 2;
84 while ( nDest
< pIDoc
->getOutlineNodesCount() &&
85 (!pIDoc
->isOutlineInLayout(nDest
, *rSh
.GetLayout())
86 || nActLevel
< pIDoc
->getOutlineLevel(nDest
)))
91 nDir
= nDest
- 1 - nActEndPos
;
96 // Move up with subpoints:
99 SwOutlineNodes::size_type nDest
= nActPos
- 1;
101 (!pIDoc
->isOutlineInLayout(nDest
, *rSh
.GetLayout())
102 || nActLevel
< pIDoc
->getOutlineLevel(nDest
)))
107 nDir
= nDest
- nActPos
;
113 rSh
.MoveOutlinePara( nDir
);
114 rSh
.GotoOutline( nActPos
+ nDir
);
119 // Up/down with subpoints:
120 rSh
.OutlineUpDown( bUp
? -1 : 1 );
124 rSh
.Pop(SwCursorShell::PopMode::DeleteCurrent
);
127 void SwListShell::Execute(SfxRequest
&rReq
)
129 const SfxItemSet
* pArgs
= rReq
.GetArgs();
130 const sal_uInt16 nSlot
= rReq
.GetSlot();
131 SwWrtShell
& rSh
= GetShell();
134 const SwNumRule
* pCurRule
= rSh
.GetNumRuleAtCurrCursorPos();
135 OSL_ENSURE( pCurRule
, "SwListShell::Execute without NumRule" );
136 bool bOutline
= pCurRule
&& pCurRule
->IsOutlineRule();
140 case FN_NUM_BULLET_DOWN
:
141 case FN_NUM_BULLET_UP
:
143 SfxViewFrame
& rFrame
= GetView().GetViewFrame();
146 rSh
.NumUpDown( nSlot
== FN_NUM_BULLET_DOWN
);
147 rFrame
.GetBindings().Invalidate( SID_TABLE_CELL
); // Update status line!
151 case FN_NUM_BULLET_NEXT
:
156 case FN_NUM_BULLET_NONUM
:
161 case FN_NUM_BULLET_OUTLINE_DOWN
:
163 lcl_OutlineUpDownWithSubPoints( rSh
, false, false );
165 rSh
.MoveNumParas(false, false);
169 case FN_NUM_BULLET_OUTLINE_MOVEDOWN
:
171 lcl_OutlineUpDownWithSubPoints( rSh
, true, false );
173 rSh
.MoveNumParas(true, false);
177 case FN_NUM_BULLET_OUTLINE_MOVEUP
:
179 lcl_OutlineUpDownWithSubPoints( rSh
, true, true );
181 rSh
.MoveNumParas(true, true);
185 case FN_NUM_BULLET_OUTLINE_UP
:
187 lcl_OutlineUpDownWithSubPoints( rSh
, false, true );
189 rSh
.MoveNumParas(false, true);
193 case FN_NUM_BULLET_PREV
:
198 case FN_NUM_OR_NONUM
:
200 bool bApi
= rReq
.IsAPI();
201 bool bDelete
= !rSh
.IsNoNum(!bApi
);
203 bDelete
= static_cast<const SfxBoolItem
&>(pArgs
->Get(rReq
.GetSlot())).GetValue();
204 rSh
.NumOrNoNum( bDelete
, !bApi
);
205 rReq
.AppendItem( SfxBoolItem( nSlot
, bDelete
) );
210 OSL_ENSURE(false, "wrong dispatcher");
215 void SwListShell::GetState(SfxItemSet
&rSet
)
217 SfxWhichIter
aIter( rSet
);
218 sal_uInt16 nWhich
= aIter
.FirstWhich();
219 SwWrtShell
& rSh
= GetShell();
220 sal_uInt8 nCurrentNumLevel
= rSh
.GetNumLevel();
225 case FN_NUM_OR_NONUM
:
226 rSet
.Put(SfxBoolItem(nWhich
, GetShell().IsNoNum(false)));
228 case FN_NUM_BULLET_OUTLINE_UP
:
229 case FN_NUM_BULLET_UP
:
230 if(!nCurrentNumLevel
)
231 rSet
.DisableItem(nWhich
);
233 case FN_NUM_BULLET_OUTLINE_DOWN
:
235 sal_uInt8 nUpper
= 0;
236 sal_uInt8 nLower
= 0;
237 rSh
.GetCurrentOutlineLevels( nUpper
, nLower
);
238 if(nLower
== (MAXLEVEL
- 1))
239 rSet
.DisableItem(nWhich
);
242 case FN_NUM_BULLET_DOWN
:
243 if(nCurrentNumLevel
== (MAXLEVEL
- 1))
244 rSet
.DisableItem(nWhich
);
247 case FN_NUM_BULLET_NONUM
:
248 if ( rSh
.CursorInsideInputField() )
250 rSet
.DisableItem(nWhich
);
254 nWhich
= aIter
.NextWhich();
258 SwListShell::SwListShell(SwView
&_rView
) :
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */