Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifdef _MSC_VER
21 : #pragma optimize ("", off)
22 : #endif
23 :
24 : #include <sfx2/request.hxx>
25 :
26 : #include "cellsh.hxx"
27 : #include "tabvwsh.hxx"
28 : #include "global.hxx"
29 : #include "scmod.hxx"
30 : #include "inputhdl.hxx"
31 : #include "inputwin.hxx"
32 : #include "document.hxx"
33 : #include "sc.hrc"
34 :
35 : #include "vcl/svapp.hxx"
36 :
37 0 : void ScCellShell::ExecuteCursor( SfxRequest& rReq )
38 : {
39 0 : ScViewData* pData = GetViewData();
40 0 : ScTabViewShell* pTabViewShell = pData->GetViewShell();
41 0 : const SfxItemSet* pReqArgs = rReq.GetArgs();
42 0 : sal_uInt16 nSlotId = rReq.GetSlot();
43 0 : SCsCOLROW nRepeat = 1;
44 0 : sal_Bool bSel = false;
45 0 : sal_Bool bKeep = false;
46 :
47 0 : if ( pReqArgs != NULL )
48 : {
49 : const SfxPoolItem* pItem;
50 0 : if (pReqArgs->HasItem(FN_PARAM_1, &pItem))
51 0 : nRepeat = static_cast<SCsCOLROW>(((const SfxInt16Item*)pItem)->GetValue());
52 0 : if (pReqArgs->HasItem(FN_PARAM_2, &pItem))
53 0 : bSel = ((const SfxBoolItem*)pItem)->GetValue();
54 : }
55 : else
56 : {
57 : // evaluate locked selection mode
58 :
59 0 : sal_uInt16 nLocked = pTabViewShell->GetLockedModifiers();
60 0 : if ( nLocked & KEY_SHIFT )
61 0 : bSel = sal_True; // EXT
62 0 : else if ( nLocked & KEY_MOD1 )
63 : {
64 : // ADD mode: keep the selection, start a new block when marking with shift again
65 0 : bKeep = true;
66 : }
67 : }
68 :
69 0 : if (bSel)
70 : {
71 0 : switch (nSlotId)
72 : {
73 : case SID_CURSORDOWN:
74 0 : rReq.SetSlot(SID_CURSORDOWN_SEL);
75 0 : break;
76 : case SID_CURSORUP:
77 0 : rReq.SetSlot(SID_CURSORUP_SEL);
78 0 : break;
79 : case SID_CURSORRIGHT:
80 0 : rReq.SetSlot(SID_CURSORRIGHT_SEL);
81 0 : break;
82 : case SID_CURSORLEFT:
83 0 : rReq.SetSlot(SID_CURSORLEFT_SEL);
84 0 : break;
85 : case SID_CURSORPAGEDOWN:
86 0 : rReq.SetSlot(SID_CURSORPAGEDOWN_SEL);
87 0 : break;
88 : case SID_CURSORPAGEUP:
89 0 : rReq.SetSlot(SID_CURSORPAGEUP_SEL);
90 0 : break;
91 : case SID_CURSORPAGERIGHT:
92 0 : rReq.SetSlot(SID_CURSORPAGERIGHT_SEL);
93 0 : break;
94 : case SID_CURSORPAGELEFT:
95 0 : rReq.SetSlot(SID_CURSORPAGELEFT_SEL);
96 0 : break;
97 : case SID_CURSORBLKDOWN:
98 0 : rReq.SetSlot(SID_CURSORBLKDOWN_SEL);
99 0 : break;
100 : case SID_CURSORBLKUP:
101 0 : rReq.SetSlot(SID_CURSORBLKUP_SEL);
102 0 : break;
103 : case SID_CURSORBLKRIGHT:
104 0 : rReq.SetSlot(SID_CURSORBLKRIGHT_SEL);
105 0 : break;
106 : case SID_CURSORBLKLEFT:
107 0 : rReq.SetSlot(SID_CURSORBLKLEFT_SEL);
108 0 : break;
109 : default:
110 : ;
111 : }
112 0 : ExecuteCursorSel(rReq);
113 0 : return;
114 : }
115 :
116 0 : SCsCOLROW nRTLSign = 1;
117 0 : if ( pData->GetDocument()->IsLayoutRTL( pData->GetTabNo() ) )
118 : {
119 : //! evaluate cursor movement option?
120 0 : nRTLSign = -1;
121 : }
122 :
123 : // once extra, so that the cursor will not be painted too often with ExecuteInputDirect:
124 0 : pTabViewShell->HideAllCursors();
125 :
126 : //OS: once for all should do, however!
127 0 : pTabViewShell->ExecuteInputDirect();
128 0 : switch ( nSlotId )
129 : {
130 : case SID_CURSORDOWN:
131 0 : pTabViewShell->MoveCursorRel( 0, nRepeat, SC_FOLLOW_LINE, bSel, bKeep );
132 0 : break;
133 :
134 : case SID_CURSORBLKDOWN:
135 0 : pTabViewShell->MoveCursorArea( 0, nRepeat, SC_FOLLOW_JUMP, bSel, bKeep );
136 0 : break;
137 :
138 : case SID_CURSORUP:
139 0 : pTabViewShell->MoveCursorRel( 0, -nRepeat, SC_FOLLOW_LINE, bSel, bKeep );
140 0 : break;
141 :
142 : case SID_CURSORBLKUP:
143 0 : pTabViewShell->MoveCursorArea( 0, -nRepeat, SC_FOLLOW_JUMP, bSel, bKeep );
144 0 : break;
145 :
146 : case SID_CURSORLEFT:
147 0 : pTabViewShell->MoveCursorRel( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep );
148 0 : break;
149 :
150 : case SID_CURSORBLKLEFT:
151 0 : pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
152 0 : break;
153 :
154 : case SID_CURSORRIGHT:
155 0 : pTabViewShell->MoveCursorRel( static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep );
156 0 : break;
157 :
158 : case SID_CURSORBLKRIGHT:
159 0 : pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
160 0 : break;
161 :
162 : case SID_CURSORPAGEDOWN:
163 0 : pTabViewShell->MoveCursorPage( 0, nRepeat, SC_FOLLOW_FIX, bSel, bKeep );
164 0 : break;
165 :
166 : case SID_CURSORPAGEUP:
167 0 : pTabViewShell->MoveCursorPage( 0, -nRepeat, SC_FOLLOW_FIX, bSel, bKeep );
168 0 : break;
169 :
170 : case SID_CURSORPAGERIGHT_: //XXX !!!
171 0 : pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep );
172 0 : break;
173 :
174 : case SID_CURSORPAGELEFT_: //XXX !!!
175 0 : pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(-nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep );
176 0 : break;
177 :
178 : default:
179 : OSL_FAIL("Unknown message in ViewShell (Cursor)");
180 0 : return;
181 : }
182 :
183 0 : pTabViewShell->ShowAllCursors();
184 :
185 0 : rReq.AppendItem( SfxInt16Item(FN_PARAM_1, static_cast<sal_Int16>(nRepeat)) );
186 0 : rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) );
187 0 : rReq.Done();
188 : }
189 :
190 0 : void ScCellShell::GetStateCursor( SfxItemSet& /* rSet */ )
191 : {
192 0 : }
193 :
194 0 : void ScCellShell::ExecuteCursorSel( SfxRequest& rReq )
195 : {
196 0 : sal_uInt16 nSlotId = rReq.GetSlot();
197 0 : ScTabViewShell* pViewShell = GetViewData()->GetViewShell();
198 0 : ScInputHandler* pInputHdl = pViewShell->GetInputHandler();
199 0 : pViewShell->HideAllCursors();
200 0 : if (pInputHdl && pInputHdl->IsInputMode())
201 : {
202 : // the current cell is in edit mode. Commit the text before moving on.
203 0 : pViewShell->ExecuteInputDirect();
204 : }
205 :
206 0 : SCsCOLROW nRepeat = 1;
207 0 : const SfxItemSet* pReqArgs = rReq.GetArgs();
208 : // get repetition
209 0 : if ( pReqArgs != NULL )
210 : {
211 : const SfxPoolItem* pItem;
212 0 : if (pReqArgs->HasItem(FN_PARAM_1, &pItem))
213 0 : nRepeat = static_cast<SCsCOLROW>(((const SfxInt16Item*)pItem)->GetValue());
214 : }
215 :
216 0 : SCsROW nMovY = nRepeat;
217 : // Horizontal direction depends on whether or not the UI language is RTL.
218 0 : SCsCOL nMovX = nRepeat;
219 0 : if (GetViewData()->GetDocument()->IsLayoutRTL(GetViewData()->GetTabNo()))
220 : {
221 : // mirror horizontal movement for right-to-left mode.
222 0 : nMovX = -nRepeat;
223 : }
224 :
225 0 : switch (nSlotId)
226 : {
227 : case SID_CURSORDOWN_SEL:
228 0 : pViewShell->ExpandBlock(0, nMovY, SC_FOLLOW_LINE);
229 0 : break;
230 : case SID_CURSORUP_SEL:
231 0 : pViewShell->ExpandBlock(0, -nMovY, SC_FOLLOW_LINE);
232 0 : break;
233 : case SID_CURSORRIGHT_SEL:
234 0 : pViewShell->ExpandBlock(nMovX, 0, SC_FOLLOW_LINE);
235 0 : break;
236 : case SID_CURSORLEFT_SEL:
237 0 : pViewShell->ExpandBlock(-nMovX, 0, SC_FOLLOW_LINE);
238 0 : break;
239 : case SID_CURSORPAGEUP_SEL:
240 0 : pViewShell->ExpandBlockPage(0, -nMovY);
241 0 : break;
242 : case SID_CURSORPAGEDOWN_SEL:
243 0 : pViewShell->ExpandBlockPage(0, nMovY);
244 0 : break;
245 : case SID_CURSORPAGERIGHT_SEL:
246 0 : pViewShell->ExpandBlockPage(nMovX, 0);
247 0 : break;
248 : case SID_CURSORPAGELEFT_SEL:
249 0 : pViewShell->ExpandBlockPage(-nMovX, 0);
250 0 : break;
251 : case SID_CURSORBLKDOWN_SEL:
252 0 : pViewShell->ExpandBlockArea(0, nMovY);
253 0 : break;
254 : case SID_CURSORBLKUP_SEL:
255 0 : pViewShell->ExpandBlockArea(0, -nMovY);
256 0 : break;
257 : case SID_CURSORBLKRIGHT_SEL:
258 0 : pViewShell->ExpandBlockArea(nMovX , 0);
259 0 : break;
260 : case SID_CURSORBLKLEFT_SEL:
261 0 : pViewShell->ExpandBlockArea(-nMovX, 0);
262 0 : break;
263 : default:
264 : ;
265 : }
266 0 : pViewShell->ShowAllCursors();
267 :
268 0 : rReq.AppendItem( SfxInt16Item(FN_PARAM_1,static_cast<sal_Int16>(nRepeat)) );
269 0 : rReq.Done();
270 0 : }
271 :
272 0 : void ScCellShell::ExecuteMove( SfxRequest& rReq )
273 : {
274 0 : ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
275 0 : sal_uInt16 nSlotId = rReq.GetSlot();
276 :
277 0 : if(nSlotId != SID_CURSORTOPOFSCREEN && nSlotId != SID_CURSORENDOFSCREEN)
278 0 : pTabViewShell->ExecuteInputDirect();
279 0 : switch ( nSlotId )
280 : {
281 : case SID_NEXT_TABLE:
282 : case SID_NEXT_TABLE_SEL:
283 0 : pTabViewShell->SelectNextTab( 1, (nSlotId == SID_NEXT_TABLE_SEL) );
284 0 : break;
285 :
286 : case SID_PREV_TABLE:
287 : case SID_PREV_TABLE_SEL:
288 0 : pTabViewShell->SelectNextTab( -1, (nSlotId == SID_PREV_TABLE_SEL) );
289 0 : break;
290 :
291 : // cursor movements in range do not originate from Basic,
292 : // because the ScSbxRange-object changes the marking at input
293 :
294 : case SID_NEXT_UNPROTECT:
295 0 : pTabViewShell->FindNextUnprot( false, !rReq.IsAPI() );
296 0 : break;
297 :
298 : case SID_PREV_UNPROTECT:
299 0 : pTabViewShell->FindNextUnprot( sal_True, !rReq.IsAPI() );
300 0 : break;
301 :
302 : case SID_CURSORENTERUP:
303 0 : if (rReq.IsAPI())
304 0 : pTabViewShell->MoveCursorRel( 0, -1, SC_FOLLOW_LINE, false );
305 : else
306 0 : pTabViewShell->MoveCursorEnter( sal_True );
307 0 : break;
308 :
309 : case SID_CURSORENTERDOWN:
310 0 : if (rReq.IsAPI())
311 0 : pTabViewShell->MoveCursorRel( 0, 1, SC_FOLLOW_LINE, false );
312 : else
313 0 : pTabViewShell->MoveCursorEnter( false );
314 0 : break;
315 :
316 : case SID_SELECT_COL:
317 0 : pTabViewShell->MarkColumns();
318 0 : break;
319 :
320 : case SID_SELECT_ROW:
321 0 : pTabViewShell->MarkRows();
322 0 : break;
323 :
324 : case SID_SELECT_NONE:
325 0 : pTabViewShell->Unmark();
326 0 : break;
327 :
328 : case SID_ALIGNCURSOR:
329 0 : pTabViewShell->AlignToCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), SC_FOLLOW_JUMP );
330 0 : break;
331 :
332 : case SID_MARKDATAAREA:
333 0 : pTabViewShell->MarkDataArea();
334 0 : break;
335 :
336 : case SID_MARKARRAYFORMULA:
337 0 : pTabViewShell->MarkMatrixFormula();
338 0 : break;
339 :
340 : case SID_SETINPUTMODE:
341 0 : SC_MOD()->SetInputMode( SC_INPUT_TABLE );
342 0 : break;
343 :
344 : case SID_FOCUS_INPUTLINE:
345 : {
346 0 : ScInputHandler* pHdl = SC_MOD()->GetInputHdl( pTabViewShell );
347 0 : if (pHdl)
348 : {
349 0 : ScInputWindow* pWin = pHdl->GetInputWindow();
350 0 : if (pWin)
351 0 : pWin->SwitchToTextWin();
352 : }
353 : }
354 0 : break;
355 :
356 : case SID_CURSORTOPOFSCREEN:
357 0 : pTabViewShell->MoveCursorScreen( 0, -1, SC_FOLLOW_LINE, false );
358 0 : break;
359 :
360 : case SID_CURSORENDOFSCREEN:
361 0 : pTabViewShell->MoveCursorScreen( 0, 1, SC_FOLLOW_LINE, false );
362 0 : break;
363 :
364 : default:
365 : OSL_FAIL("Unknown message in ViewShell (Cursor)");
366 0 : return;
367 : }
368 :
369 0 : rReq.Done();
370 : }
371 :
372 0 : void ScCellShell::ExecutePageSel( SfxRequest& rReq )
373 : {
374 0 : sal_uInt16 nSlotId = rReq.GetSlot();
375 0 : switch ( nSlotId )
376 : {
377 0 : case SID_CURSORHOME_SEL: rReq.SetSlot( SID_CURSORHOME ); break;
378 0 : case SID_CURSOREND_SEL: rReq.SetSlot( SID_CURSOREND ); break;
379 0 : case SID_CURSORTOPOFFILE_SEL: rReq.SetSlot( SID_CURSORTOPOFFILE ); break;
380 0 : case SID_CURSORENDOFFILE_SEL: rReq.SetSlot( SID_CURSORENDOFFILE ); break;
381 : default:
382 : OSL_FAIL("Unknown message in ViewShell (ExecutePageSel)");
383 0 : return;
384 : }
385 0 : rReq.AppendItem( SfxBoolItem(FN_PARAM_2, sal_True) );
386 0 : ExecuteSlot( rReq, GetInterface() );
387 : }
388 :
389 0 : void ScCellShell::ExecutePage( SfxRequest& rReq )
390 : {
391 0 : ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
392 0 : const SfxItemSet* pReqArgs = rReq.GetArgs();
393 0 : sal_uInt16 nSlotId = rReq.GetSlot();
394 0 : sal_Bool bSel = false;
395 0 : sal_Bool bKeep = false;
396 :
397 0 : if ( pReqArgs != NULL )
398 : {
399 : const SfxPoolItem* pItem;
400 0 : if (pReqArgs->HasItem(FN_PARAM_2, &pItem))
401 0 : bSel = ((const SfxBoolItem*)pItem)->GetValue();
402 : }
403 : else
404 : {
405 : // evaluate locked selection mode
406 :
407 0 : sal_uInt16 nLocked = pTabViewShell->GetLockedModifiers();
408 0 : if ( nLocked & KEY_SHIFT )
409 0 : bSel = sal_True; // EXT
410 0 : else if ( nLocked & KEY_MOD1 )
411 : {
412 : // ADD mode: keep the selection, start a new block when marking with shift again
413 0 : bKeep = true;
414 : }
415 : }
416 :
417 0 : pTabViewShell->ExecuteInputDirect();
418 0 : switch ( nSlotId )
419 : {
420 : case SID_CURSORHOME:
421 0 : pTabViewShell->MoveCursorEnd( -1, 0, SC_FOLLOW_LINE, bSel, bKeep );
422 0 : break;
423 :
424 : case SID_CURSOREND:
425 0 : pTabViewShell->MoveCursorEnd( 1, 0, SC_FOLLOW_JUMP, bSel, bKeep );
426 0 : break;
427 :
428 : case SID_CURSORTOPOFFILE:
429 0 : pTabViewShell->MoveCursorEnd( -1, -1, SC_FOLLOW_LINE, bSel, bKeep );
430 0 : break;
431 :
432 : case SID_CURSORENDOFFILE:
433 0 : pTabViewShell->MoveCursorEnd( 1, 1, SC_FOLLOW_JUMP, bSel, bKeep );
434 0 : break;
435 :
436 : default:
437 : OSL_FAIL("Unknown message in ViewShell (ExecutePage)");
438 0 : return;
439 : }
440 :
441 0 : rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) );
442 0 : rReq.Done();
443 15 : }
444 :
445 :
446 :
447 :
448 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|