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