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