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 <sfx2/request.hxx> 29 #include <svl/eitem.hxx> 30 #ifndef __SBX_SBXVARIABLE_HXX //autogen 31 #include <basic/sbxvar.hxx> 32 #endif 33 #include <sfx2/viewfrm.hxx> 34 #include <sfx2/bindings.hxx> 35 36 #ifndef _VIEW_HXX 37 #include <view.hxx> 38 #endif 39 #include <wrtsh.hxx> 40 #ifndef _TEXTSH_HXX 41 #include <textsh.hxx> 42 #endif 43 #include <num.hxx> 44 #include <edtwin.hxx> 45 #include <crsskip.hxx> 46 #include <doc.hxx> 47 #include <docsh.hxx> 48 49 #ifndef _CMDID_H 50 #include <cmdid.h> 51 #endif 52 #include <globals.h> 53 #ifndef _GLOBALS_HRC 54 #include <globals.hrc> 55 #endif 56 57 #include <svx/svdouno.hxx> 58 #include <svx/fmshell.hxx> 59 #include <svx/sdrobjectfilter.hxx> 60 61 using namespace ::com::sun::star; 62 63 void SwTextShell::ExecBasicMove(SfxRequest &rReq) 64 { 65 SwWrtShell &rSh = GetShell(); 66 GetView().GetEditWin().FlushInBuffer(); 67 const SfxItemSet *pArgs = rReq.GetArgs(); 68 sal_Bool bSelect = sal_False; 69 sal_uInt16 nCount = 1; 70 if(pArgs) 71 { 72 const SfxPoolItem *pItem; 73 if(SFX_ITEM_SET == pArgs->GetItemState(FN_PARAM_MOVE_COUNT, sal_True, &pItem)) 74 nCount = ((const SfxInt16Item *)pItem)->GetValue(); 75 if(SFX_ITEM_SET == pArgs->GetItemState(FN_PARAM_MOVE_SELECTION, sal_True, &pItem)) 76 bSelect = ((const SfxBoolItem *)pItem)->GetValue(); 77 } 78 switch(rReq.GetSlot()) 79 { 80 case FN_CHAR_LEFT_SEL: rReq.SetSlot( FN_CHAR_LEFT ); bSelect = sal_True; break; 81 case FN_CHAR_RIGHT_SEL: rReq.SetSlot( FN_CHAR_RIGHT ); bSelect = sal_True; break; 82 case FN_LINE_UP_SEL: rReq.SetSlot( FN_LINE_UP ); bSelect = sal_True; break; 83 case FN_LINE_DOWN_SEL: rReq.SetSlot( FN_LINE_DOWN ); bSelect = sal_True; break; 84 } 85 86 uno::Reference< frame::XDispatchRecorder > xRecorder = 87 GetView().GetViewFrame()->GetBindings().GetRecorder(); 88 if ( xRecorder.is() ) 89 { 90 rReq.AppendItem( SfxInt16Item(FN_PARAM_MOVE_COUNT, nCount) ); 91 rReq.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION, bSelect) ); 92 } 93 sal_uInt16 nSlot = rReq.GetSlot(); 94 rReq.Done(); 95 // Get EditWin before calling the move functions (shell change may occur!) 96 SwEditWin& rTmpEditWin = GetView().GetEditWin(); 97 for( sal_uInt16 i = 0; i < nCount; i++ ) 98 { 99 switch(nSlot) 100 { 101 case FN_CHAR_LEFT: rSh.Left( CRSR_SKIP_CELLS, bSelect, 1, sal_False, sal_True ); break; 102 case FN_CHAR_RIGHT: rSh.Right( CRSR_SKIP_CELLS, bSelect, 1, sal_False, sal_True ); break; 103 case FN_LINE_UP: rSh.Up ( bSelect, 1 ); break; 104 case FN_LINE_DOWN: rSh.Down ( bSelect, 1 ); break; 105 default: ASSERT(sal_False, falscher Dispatcher); return; 106 } 107 } 108 109 //#i42732# - notify the edit window that from now on we do not use the input language 110 rTmpEditWin.SetUseInputLanguage( sal_False ); 111 } 112 113 void SwTextShell::ExecMove(SfxRequest &rReq) 114 { 115 SwWrtShell &rSh = GetShell(); 116 SwEditWin& rTmpEditWin = GetView().GetEditWin(); 117 rTmpEditWin.FlushInBuffer(); 118 119 sal_uInt16 nSlot = rReq.GetSlot(); 120 sal_Bool bRet = sal_False; 121 switch ( nSlot ) 122 { 123 case FN_START_OF_LINE_SEL: 124 case FN_START_OF_LINE: bRet = rSh.LeftMargin ( FN_START_OF_LINE_SEL == nSlot, sal_False ); 125 break; 126 127 case FN_END_OF_LINE_SEL: 128 case FN_END_OF_LINE: bRet = rSh.RightMargin( FN_END_OF_LINE_SEL == nSlot, sal_False ); 129 break; 130 131 case FN_START_OF_DOCUMENT_SEL: 132 case FN_START_OF_DOCUMENT: bRet = rSh.SttDoc ( FN_START_OF_DOCUMENT_SEL == nSlot); 133 break; 134 135 case FN_END_OF_DOCUMENT_SEL: 136 case FN_END_OF_DOCUMENT: bRet = rSh.EndDoc( FN_END_OF_DOCUMENT_SEL == nSlot ); 137 break; 138 139 case FN_SELECT_WORD: bRet = rSh.SelNearestWrd(); break; 140 141 case SID_SELECTALL: bRet = 0 != rSh.SelAll(); break; 142 default: ASSERT(sal_False, falscher Dispatcher); return; 143 } 144 145 if ( bRet ) 146 rReq.Done(); 147 else 148 rReq.Ignore(); 149 150 //#i42732# - notify the edit window that from now on we do not use the input language 151 rTmpEditWin.SetUseInputLanguage( sal_False ); 152 } 153 154 void SwTextShell::ExecMovePage(SfxRequest &rReq) 155 { 156 SwWrtShell &rSh = GetShell(); 157 GetView().GetEditWin().FlushInBuffer(); 158 159 sal_uInt16 nSlot = rReq.GetSlot(); 160 switch( nSlot ) 161 { 162 case FN_START_OF_NEXT_PAGE_SEL : 163 case FN_START_OF_NEXT_PAGE: rSh.SttNxtPg( FN_START_OF_NEXT_PAGE_SEL == nSlot ); break; 164 165 case FN_END_OF_NEXT_PAGE_SEL: 166 case FN_END_OF_NEXT_PAGE: rSh.EndNxtPg( FN_END_OF_NEXT_PAGE_SEL == nSlot ); break; 167 168 case FN_START_OF_PREV_PAGE_SEL: 169 case FN_START_OF_PREV_PAGE: rSh.SttPrvPg( FN_START_OF_PREV_PAGE_SEL == nSlot ); break; 170 171 case FN_END_OF_PREV_PAGE_SEL: 172 case FN_END_OF_PREV_PAGE: rSh.EndPrvPg( FN_END_OF_PREV_PAGE_SEL == nSlot ); break; 173 174 case FN_START_OF_PAGE_SEL: 175 case FN_START_OF_PAGE: rSh.SttPg ( FN_START_OF_PAGE_SEL == nSlot ); break; 176 177 case FN_END_OF_PAGE_SEL: 178 case FN_END_OF_PAGE: rSh.EndPg ( FN_END_OF_PAGE_SEL == nSlot ); break; 179 default: ASSERT(sal_False, falscher Dispatcher); return; 180 } 181 rReq.Done(); 182 } 183 184 185 void SwTextShell::ExecMoveCol(SfxRequest &rReq) 186 { 187 SwWrtShell &rSh = GetShell(); 188 switch ( rReq.GetSlot() ) 189 { 190 case FN_START_OF_COLUMN: rSh.StartOfColumn ( sal_False ); break; 191 case FN_END_OF_COLUMN: rSh.EndOfColumn ( sal_False ); break; 192 case FN_START_OF_NEXT_COLUMN: rSh.StartOfNextColumn( sal_False ) ; break; 193 case FN_END_OF_NEXT_COLUMN: rSh.EndOfNextColumn ( sal_False ); break; 194 case FN_START_OF_PREV_COLUMN: rSh.StartOfPrevColumn( sal_False ); break; 195 case FN_END_OF_PREV_COLUMN: rSh.EndOfPrevColumn ( sal_False ); break; 196 default: ASSERT(sal_False, falscher Dispatcher); return; 197 } 198 rReq.Done(); 199 } 200 201 void SwTextShell::ExecMoveLingu(SfxRequest &rReq) 202 { 203 SwWrtShell &rSh = GetShell(); 204 GetView().GetEditWin().FlushInBuffer(); 205 206 sal_uInt16 nSlot = rReq.GetSlot(); 207 sal_Bool bRet = sal_False; 208 switch ( nSlot ) 209 { 210 case FN_NEXT_WORD_SEL: 211 case FN_NEXT_WORD: bRet = rSh.NxtWrd( FN_NEXT_WORD_SEL == nSlot ); 212 break; 213 214 case FN_START_OF_PARA_SEL: 215 case FN_START_OF_PARA: bRet = rSh.SttPara( FN_START_OF_PARA_SEL == nSlot ); 216 break; 217 218 case FN_END_OF_PARA_SEL: 219 case FN_END_OF_PARA: bRet = rSh.EndPara( FN_END_OF_PARA_SEL == nSlot ); 220 break; 221 222 case FN_PREV_WORD_SEL: 223 case FN_PREV_WORD: bRet = rSh.PrvWrd( FN_PREV_WORD_SEL == nSlot ); 224 break; 225 226 case FN_NEXT_SENT_SEL: 227 case FN_NEXT_SENT: bRet = rSh.FwdSentence( FN_NEXT_SENT_SEL == nSlot ); 228 break; 229 230 case FN_PREV_SENT_SEL: 231 case FN_PREV_SENT: bRet = rSh.BwdSentence( FN_PREV_SENT_SEL == nSlot ); 232 break; 233 234 case FN_NEXT_PARA: bRet = rSh.FwdPara ( sal_False ); 235 break; 236 237 case FN_PREV_PARA: bRet = rSh.BwdPara ( sal_False ); 238 break; 239 default: ASSERT(sal_False, falscher Dispatcher); return; 240 } 241 rReq.Done(); 242 } 243 244 void SwTextShell::ExecMoveMisc(SfxRequest &rReq) 245 { 246 SwWrtShell &rSh = GetShell(); 247 sal_uInt16 nSlot = rReq.GetSlot(); 248 sal_Bool bSetRetVal = sal_True, bRet = sal_True; 249 switch ( nSlot ) 250 { 251 case SID_FM_TOGGLECONTROLFOCUS: 252 { 253 const SwDoc* pDoc = rSh.GetDoc(); 254 const SwDocShell* pDocShell = pDoc ? pDoc->GetDocShell() : NULL; 255 const SwView* pView = pDocShell ? pDocShell->GetView() : NULL; 256 const FmFormShell* pFormShell = pView ? pView->GetFormShell() : NULL; 257 SdrView* pDrawView = pView ? pView->GetDrawView() : NULL; 258 Window* pWindow = pView ? pView->GetWrtShell().GetWin() : NULL; 259 260 OSL_ENSURE( pFormShell && pDrawView && pWindow, "SwXTextView::ExecMoveMisc: no chance!" ); 261 if ( !pFormShell || !pDrawView || !pWindow ) 262 break; 263 264 ::std::auto_ptr< ::svx::ISdrObjectFilter > pFilter( pFormShell->CreateFocusableControlFilter( 265 *pDrawView, *pWindow ) ); 266 if ( !pFilter.get() ) 267 break; 268 269 const SdrObject* pNearestControl = rSh.GetBestObject( sal_True, GOTOOBJ_DRAW_CONTROL, sal_False, pFilter.get() ); 270 if ( !pNearestControl ) 271 break; 272 273 const SdrUnoObj* pUnoObject = dynamic_cast< const SdrUnoObj* >( pNearestControl ); 274 OSL_ENSURE( pUnoObject, "SwTextShell::ExecMoveMisc: GetBestObject returned nonsense!" ); 275 if ( !pUnoObject ) 276 break; 277 278 pFormShell->ToggleControlFocus( *pUnoObject, *pDrawView, *pWindow ); 279 } 280 break; 281 case FN_CNTNT_TO_NEXT_FRAME: 282 bRet = rSh.GotoObj(sal_True, GOTOOBJ_GOTO_ANY); 283 if(bRet) 284 { 285 rSh.HideCrsr(); 286 rSh.EnterSelFrmMode(); 287 } 288 break; 289 case FN_NEXT_FOOTNOTE: 290 rSh.MoveCrsr(); 291 bRet = rSh.GotoNextFtnAnchor(); 292 break; 293 case FN_PREV_FOOTNOTE: 294 rSh.MoveCrsr(); 295 bRet = rSh.GotoPrevFtnAnchor(); 296 break; 297 case FN_TO_HEADER: 298 rSh.MoveCrsr(); 299 if ( FRMTYPE_HEADER & rSh.GetFrmType(0,sal_False) ) 300 rSh.SttPg(); 301 else 302 rSh.GotoHeaderTxt(); 303 bSetRetVal = sal_False; 304 break; 305 case FN_TO_FOOTER: 306 rSh.MoveCrsr(); 307 if ( FRMTYPE_FOOTER & rSh.GetFrmType(0,sal_False) ) 308 rSh.EndPg(); 309 else 310 rSh.GotoFooterTxt(); 311 bSetRetVal = sal_False; 312 break; 313 case FN_FOOTNOTE_TO_ANCHOR: 314 rSh.MoveCrsr(); 315 if ( FRMTYPE_FOOTNOTE & rSh.GetFrmType(0,sal_False) ) 316 rSh.GotoFtnAnchor(); 317 else 318 rSh.GotoFtnTxt(); 319 bSetRetVal = sal_False; 320 break; 321 case FN_TO_FOOTNOTE_AREA : 322 rSh.GotoFtnTxt(); 323 break; 324 case FN_PREV_TABLE: 325 bRet = rSh.MoveTable( fnTablePrev, fnTableStart); 326 break; 327 case FN_NEXT_TABLE: 328 bRet = rSh.MoveTable(fnTableNext, fnTableStart); 329 break; 330 case FN_GOTO_NEXT_REGION : 331 bRet = rSh.MoveRegion(fnRegionNext, fnRegionStart); 332 break; 333 case FN_GOTO_PREV_REGION : 334 bRet = rSh.MoveRegion(fnRegionPrev, fnRegionStart); 335 break; 336 337 case FN_NEXT_TOXMARK: 338 bRet = rSh.GotoNxtPrvTOXMark( sal_True ); 339 break; 340 case FN_PREV_TOXMARK: 341 bRet = rSh.GotoNxtPrvTOXMark( sal_False ); 342 break; 343 case FN_NEXT_TBLFML: 344 bRet = rSh.GotoNxtPrvTblFormula( sal_True, sal_False ); 345 break; 346 case FN_PREV_TBLFML: 347 bRet = rSh.GotoNxtPrvTblFormula( sal_False, sal_False ); 348 break; 349 case FN_NEXT_TBLFML_ERR: 350 bRet = rSh.GotoNxtPrvTblFormula( sal_True, sal_True ); 351 break; 352 case FN_PREV_TBLFML_ERR: 353 bRet = rSh.GotoNxtPrvTblFormula( sal_False, sal_True ); 354 break; 355 356 default: 357 ASSERT(sal_False, falscher Dispatcher); 358 return; 359 } 360 361 if( bSetRetVal ) 362 rReq.SetReturnValue(SfxBoolItem( nSlot, bRet )); 363 rReq.Done(); 364 365 } 366 367