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_sc.hxx" 26 27 28 29 //------------------------------------------------------------------ 30 31 #ifdef _MSC_VER 32 #pragma optimize ("", off) 33 #endif 34 35 // INCLUDE --------------------------------------------------------------- 36 37 #include <sfx2/request.hxx> 38 39 #include "cellsh.hxx" 40 #include "tabvwsh.hxx" 41 #include "global.hxx" 42 #include "scmod.hxx" 43 #include "inputhdl.hxx" 44 #include "inputwin.hxx" 45 #include "document.hxx" 46 #include "sc.hrc" 47 48 49 //------------------------------------------------------------------ 50 51 #define IS_AVAILABLE(WhichId,ppItem) \ 52 (pReqArgs->GetItemState((WhichId), sal_True, ppItem ) == SFX_ITEM_SET) 53 54 55 void ScCellShell::ExecuteCursor( SfxRequest& rReq ) 56 { 57 ScViewData* pData = GetViewData(); 58 ScTabViewShell* pTabViewShell = pData->GetViewShell(); 59 const SfxItemSet* pReqArgs = rReq.GetArgs(); 60 sal_uInt16 nSlotId = rReq.GetSlot(); 61 SCsCOLROW nRepeat = 1; 62 sal_Bool bSel = sal_False; 63 sal_Bool bKeep = sal_False; 64 65 if ( pReqArgs != NULL ) 66 { 67 const SfxPoolItem* pItem; 68 if( IS_AVAILABLE( FN_PARAM_1, &pItem ) ) 69 nRepeat = static_cast<SCsCOLROW>(((const SfxInt16Item*)pItem)->GetValue()); 70 if( IS_AVAILABLE( FN_PARAM_2, &pItem ) ) 71 bSel = ((const SfxBoolItem*)pItem)->GetValue(); 72 } 73 else 74 { 75 // evaluate locked selection mode 76 77 sal_uInt16 nLocked = pTabViewShell->GetLockedModifiers(); 78 if ( nLocked & KEY_SHIFT ) 79 bSel = sal_True; // EXT 80 else if ( nLocked & KEY_MOD1 ) 81 { 82 // ADD mode: keep the selection, start a new block when marking with shift again 83 bKeep = sal_True; 84 pTabViewShell->SetNewStartIfMarking(); 85 } 86 } 87 88 SCsCOLROW nRTLSign = 1; 89 if ( pData->GetDocument()->IsLayoutRTL( pData->GetTabNo() ) ) 90 { 91 //! evaluate cursor movement option? 92 nRTLSign = -1; 93 } 94 95 // einmal extra, damit der Cursor bei ExecuteInputDirect nicht zuoft gemalt wird: 96 pTabViewShell->HideAllCursors(); 97 98 //OS: einmal fuer alle wird doch reichen! 99 pTabViewShell->ExecuteInputDirect(); 100 switch ( nSlotId ) 101 { 102 case SID_CURSORDOWN: 103 pTabViewShell->MoveCursorRel( 0, nRepeat, SC_FOLLOW_LINE, bSel, bKeep ); 104 break; 105 106 case SID_CURSORBLKDOWN: 107 pTabViewShell->MoveCursorArea( 0, nRepeat, SC_FOLLOW_JUMP, bSel, bKeep ); 108 break; 109 110 case SID_CURSORUP: 111 pTabViewShell->MoveCursorRel( 0, -nRepeat, SC_FOLLOW_LINE, bSel, bKeep ); 112 break; 113 114 case SID_CURSORBLKUP: 115 pTabViewShell->MoveCursorArea( 0, -nRepeat, SC_FOLLOW_JUMP, bSel, bKeep ); 116 break; 117 118 case SID_CURSORLEFT: 119 pTabViewShell->MoveCursorRel( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep ); 120 break; 121 122 case SID_CURSORBLKLEFT: 123 pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep ); 124 break; 125 126 case SID_CURSORRIGHT: 127 pTabViewShell->MoveCursorRel( static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep ); 128 break; 129 130 case SID_CURSORBLKRIGHT: 131 pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep ); 132 break; 133 134 case SID_CURSORPAGEDOWN: 135 pTabViewShell->MoveCursorPage( 0, nRepeat, SC_FOLLOW_FIX, bSel, bKeep ); 136 break; 137 138 case SID_CURSORPAGEUP: 139 pTabViewShell->MoveCursorPage( 0, -nRepeat, SC_FOLLOW_FIX, bSel, bKeep ); 140 break; 141 142 case SID_CURSORPAGERIGHT_: //XXX !!! 143 pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep ); 144 break; 145 146 case SID_CURSORPAGELEFT_: //XXX !!! 147 pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(-nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep ); 148 break; 149 150 default: 151 DBG_ERROR("Unbekannte Message bei ViewShell (Cursor)"); 152 return; 153 } 154 155 pTabViewShell->ShowAllCursors(); 156 157 rReq.AppendItem( SfxInt16Item(FN_PARAM_1, static_cast<sal_Int16>(nRepeat)) ); 158 rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) ); 159 rReq.Done(); 160 } 161 162 void ScCellShell::GetStateCursor( SfxItemSet& /* rSet */ ) 163 { 164 } 165 166 void ScCellShell::ExecuteCursorSel( SfxRequest& rReq ) 167 { 168 const SfxItemSet* pReqArgs = rReq.GetArgs(); 169 sal_uInt16 nSlotId = rReq.GetSlot(); 170 short nRepeat = 1; 171 172 if ( pReqArgs != NULL ) 173 { 174 const SfxPoolItem* pItem; 175 if( IS_AVAILABLE( FN_PARAM_1, &pItem ) ) 176 nRepeat = ((const SfxInt16Item*)pItem)->GetValue(); 177 } 178 179 switch ( nSlotId ) 180 { 181 case SID_CURSORDOWN_SEL: rReq.SetSlot( SID_CURSORDOWN ); break; 182 case SID_CURSORBLKDOWN_SEL: rReq.SetSlot( SID_CURSORBLKDOWN ); break; 183 case SID_CURSORUP_SEL: rReq.SetSlot( SID_CURSORUP ); break; 184 case SID_CURSORBLKUP_SEL: rReq.SetSlot( SID_CURSORBLKUP ); break; 185 case SID_CURSORLEFT_SEL: rReq.SetSlot( SID_CURSORLEFT ); break; 186 case SID_CURSORBLKLEFT_SEL: rReq.SetSlot( SID_CURSORBLKLEFT ); break; 187 case SID_CURSORRIGHT_SEL: rReq.SetSlot( SID_CURSORRIGHT ); break; 188 case SID_CURSORBLKRIGHT_SEL: rReq.SetSlot( SID_CURSORBLKRIGHT ); break; 189 case SID_CURSORPAGEDOWN_SEL: rReq.SetSlot( SID_CURSORPAGEDOWN ); break; 190 case SID_CURSORPAGEUP_SEL: rReq.SetSlot( SID_CURSORPAGEUP ); break; 191 case SID_CURSORPAGERIGHT_SEL: rReq.SetSlot( SID_CURSORPAGERIGHT_ ); break; 192 case SID_CURSORPAGELEFT_SEL: rReq.SetSlot( SID_CURSORPAGELEFT_ ); break; 193 default: 194 DBG_ERROR("Unbekannte Message bei ViewShell (CursorSel)"); 195 return; 196 } 197 rReq.AppendItem( SfxInt16Item(FN_PARAM_1, nRepeat ) ); 198 rReq.AppendItem( SfxBoolItem(FN_PARAM_2, sal_True) ); 199 ExecuteSlot( rReq, GetInterface() ); 200 } 201 202 void ScCellShell::ExecuteMove( SfxRequest& rReq ) 203 { 204 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell(); 205 sal_uInt16 nSlotId = rReq.GetSlot(); 206 207 if(nSlotId != SID_CURSORTOPOFSCREEN && nSlotId != SID_CURSORENDOFSCREEN) 208 pTabViewShell->ExecuteInputDirect(); 209 switch ( nSlotId ) 210 { 211 case SID_NEXT_TABLE: 212 case SID_NEXT_TABLE_SEL: 213 pTabViewShell->SelectNextTab( 1, (nSlotId == SID_NEXT_TABLE_SEL) ); 214 break; 215 216 case SID_PREV_TABLE: 217 case SID_PREV_TABLE_SEL: 218 pTabViewShell->SelectNextTab( -1, (nSlotId == SID_PREV_TABLE_SEL) ); 219 break; 220 221 // Cursorbewegungen in Bloecken gehen nicht von Basic aus, 222 // weil das ScSbxRange-Objekt bei Eingaben die Markierung veraendert 223 224 case SID_NEXT_UNPROTECT: 225 pTabViewShell->FindNextUnprot( sal_False, !rReq.IsAPI() ); 226 break; 227 228 case SID_PREV_UNPROTECT: 229 pTabViewShell->FindNextUnprot( sal_True, !rReq.IsAPI() ); 230 break; 231 232 case SID_CURSORENTERUP: 233 if (rReq.IsAPI()) 234 pTabViewShell->MoveCursorRel( 0, -1, SC_FOLLOW_LINE, sal_False ); 235 else 236 pTabViewShell->MoveCursorEnter( sal_True ); 237 break; 238 239 case SID_CURSORENTERDOWN: 240 if (rReq.IsAPI()) 241 pTabViewShell->MoveCursorRel( 0, 1, SC_FOLLOW_LINE, sal_False ); 242 else 243 pTabViewShell->MoveCursorEnter( sal_False ); 244 break; 245 246 case SID_SELECT_COL: 247 pTabViewShell->MarkColumns(); 248 break; 249 250 case SID_SELECT_ROW: 251 pTabViewShell->MarkRows(); 252 break; 253 254 case SID_SELECT_NONE: 255 pTabViewShell->Unmark(); 256 break; 257 258 case SID_ALIGNCURSOR: 259 pTabViewShell->AlignToCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), SC_FOLLOW_JUMP ); 260 break; 261 262 case SID_MARKDATAAREA: 263 pTabViewShell->MarkDataArea(); 264 break; 265 266 case SID_MARKARRAYFORMULA: 267 pTabViewShell->MarkMatrixFormula(); 268 break; 269 270 case SID_SETINPUTMODE: 271 SC_MOD()->SetInputMode( SC_INPUT_TABLE ); 272 break; 273 274 case SID_FOCUS_INPUTLINE: 275 { 276 ScInputHandler* pHdl = SC_MOD()->GetInputHdl( pTabViewShell ); 277 if (pHdl) 278 { 279 ScInputWindow* pWin = pHdl->GetInputWindow(); 280 if (pWin) 281 pWin->SwitchToTextWin(); 282 } 283 } 284 break; 285 286 case SID_CURSORTOPOFSCREEN: 287 pTabViewShell->MoveCursorScreen( 0, -1, SC_FOLLOW_LINE, sal_False ); 288 break; 289 290 case SID_CURSORENDOFSCREEN: 291 pTabViewShell->MoveCursorScreen( 0, 1, SC_FOLLOW_LINE, sal_False ); 292 break; 293 294 default: 295 DBG_ERROR("Unbekannte Message bei ViewShell (Cursor)"); 296 return; 297 } 298 299 rReq.Done(); 300 } 301 302 void ScCellShell::ExecutePageSel( SfxRequest& rReq ) 303 { 304 sal_uInt16 nSlotId = rReq.GetSlot(); 305 switch ( nSlotId ) 306 { 307 case SID_CURSORHOME_SEL: rReq.SetSlot( SID_CURSORHOME ); break; 308 case SID_CURSOREND_SEL: rReq.SetSlot( SID_CURSOREND ); break; 309 case SID_CURSORTOPOFFILE_SEL: rReq.SetSlot( SID_CURSORTOPOFFILE ); break; 310 case SID_CURSORENDOFFILE_SEL: rReq.SetSlot( SID_CURSORENDOFFILE ); break; 311 default: 312 DBG_ERROR("Unbekannte Message bei ViewShell (ExecutePageSel)"); 313 return; 314 } 315 rReq.AppendItem( SfxBoolItem(FN_PARAM_2, sal_True) ); 316 ExecuteSlot( rReq, GetInterface() ); 317 } 318 319 void ScCellShell::ExecutePage( SfxRequest& rReq ) 320 { 321 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell(); 322 const SfxItemSet* pReqArgs = rReq.GetArgs(); 323 sal_uInt16 nSlotId = rReq.GetSlot(); 324 sal_Bool bSel = sal_False; 325 sal_Bool bKeep = sal_False; 326 327 if ( pReqArgs != NULL ) 328 { 329 const SfxPoolItem* pItem; 330 if( IS_AVAILABLE( FN_PARAM_2, &pItem ) ) 331 bSel = ((const SfxBoolItem*)pItem)->GetValue(); 332 } 333 else 334 { 335 // evaluate locked selection mode 336 337 sal_uInt16 nLocked = pTabViewShell->GetLockedModifiers(); 338 if ( nLocked & KEY_SHIFT ) 339 bSel = sal_True; // EXT 340 else if ( nLocked & KEY_MOD1 ) 341 { 342 // ADD mode: keep the selection, start a new block when marking with shift again 343 bKeep = sal_True; 344 pTabViewShell->SetNewStartIfMarking(); 345 } 346 } 347 348 pTabViewShell->ExecuteInputDirect(); 349 switch ( nSlotId ) 350 { 351 case SID_CURSORHOME: 352 pTabViewShell->MoveCursorEnd( -1, 0, SC_FOLLOW_LINE, bSel, bKeep ); 353 break; 354 355 case SID_CURSOREND: 356 pTabViewShell->MoveCursorEnd( 1, 0, SC_FOLLOW_JUMP, bSel, bKeep ); 357 break; 358 359 case SID_CURSORTOPOFFILE: 360 pTabViewShell->MoveCursorEnd( -1, -1, SC_FOLLOW_LINE, bSel, bKeep ); 361 break; 362 363 case SID_CURSORENDOFFILE: 364 pTabViewShell->MoveCursorEnd( 1, 1, SC_FOLLOW_JUMP, bSel, bKeep ); 365 break; 366 367 default: 368 DBG_ERROR("Unbekannte Message bei ViewShell (ExecutePage)"); 369 return; 370 } 371 372 rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) ); 373 rReq.Done(); 374 } 375 376 377 378 379