Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / sc / source / ui / view / cellsh4.cxx
blob59d8724e639774132fb8dc87ca17a34784ad8d46
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifdef _MSC_VER
21 #pragma optimize ("", off)
22 #endif
24 #include <sfx2/request.hxx>
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"
35 #include "vcl/svapp.hxx"
37 void ScCellShell::ExecuteCursor( SfxRequest& rReq )
39 ScViewData* pData = GetViewData();
40 ScTabViewShell* pTabViewShell = pData->GetViewShell();
41 const SfxItemSet* pReqArgs = rReq.GetArgs();
42 sal_uInt16 nSlotId = rReq.GetSlot();
43 SCsCOLROW nRepeat = 1;
44 sal_Bool bSel = false;
45 sal_Bool bKeep = false;
47 if ( pReqArgs != NULL )
49 const SfxPoolItem* pItem;
50 if (pReqArgs->HasItem(FN_PARAM_1, &pItem))
51 nRepeat = static_cast<SCsCOLROW>(((const SfxInt16Item*)pItem)->GetValue());
52 if (pReqArgs->HasItem(FN_PARAM_2, &pItem))
53 bSel = ((const SfxBoolItem*)pItem)->GetValue();
55 else
57 // evaluate locked selection mode
59 sal_uInt16 nLocked = pTabViewShell->GetLockedModifiers();
60 if ( nLocked & KEY_SHIFT )
61 bSel = sal_True; // EXT
62 else if ( nLocked & KEY_MOD1 )
64 // ADD mode: keep the selection, start a new block when marking with shift again
65 bKeep = true;
69 if (bSel)
71 switch (nSlotId)
73 case SID_CURSORDOWN:
74 rReq.SetSlot(SID_CURSORDOWN_SEL);
75 break;
76 case SID_CURSORUP:
77 rReq.SetSlot(SID_CURSORUP_SEL);
78 break;
79 case SID_CURSORRIGHT:
80 rReq.SetSlot(SID_CURSORRIGHT_SEL);
81 break;
82 case SID_CURSORLEFT:
83 rReq.SetSlot(SID_CURSORLEFT_SEL);
84 break;
85 case SID_CURSORPAGEDOWN:
86 rReq.SetSlot(SID_CURSORPAGEDOWN_SEL);
87 break;
88 case SID_CURSORPAGEUP:
89 rReq.SetSlot(SID_CURSORPAGEUP_SEL);
90 break;
91 case SID_CURSORPAGERIGHT:
92 rReq.SetSlot(SID_CURSORPAGERIGHT_SEL);
93 break;
94 case SID_CURSORPAGELEFT:
95 rReq.SetSlot(SID_CURSORPAGELEFT_SEL);
96 break;
97 case SID_CURSORBLKDOWN:
98 rReq.SetSlot(SID_CURSORBLKDOWN_SEL);
99 break;
100 case SID_CURSORBLKUP:
101 rReq.SetSlot(SID_CURSORBLKUP_SEL);
102 break;
103 case SID_CURSORBLKRIGHT:
104 rReq.SetSlot(SID_CURSORBLKRIGHT_SEL);
105 break;
106 case SID_CURSORBLKLEFT:
107 rReq.SetSlot(SID_CURSORBLKLEFT_SEL);
108 break;
109 default:
112 ExecuteCursorSel(rReq);
113 return;
116 SCsCOLROW nRTLSign = 1;
117 if ( pData->GetDocument()->IsLayoutRTL( pData->GetTabNo() ) )
119 //! evaluate cursor movement option?
120 nRTLSign = -1;
123 // once extra, so that the cursor will not be painted too often with ExecuteInputDirect:
124 pTabViewShell->HideAllCursors();
126 //OS: once for all should do, however!
127 pTabViewShell->ExecuteInputDirect();
128 switch ( nSlotId )
130 case SID_CURSORDOWN:
131 pTabViewShell->MoveCursorRel( 0, nRepeat, SC_FOLLOW_LINE, bSel, bKeep );
132 break;
134 case SID_CURSORBLKDOWN:
135 pTabViewShell->MoveCursorArea( 0, nRepeat, SC_FOLLOW_JUMP, bSel, bKeep );
136 break;
138 case SID_CURSORUP:
139 pTabViewShell->MoveCursorRel( 0, -nRepeat, SC_FOLLOW_LINE, bSel, bKeep );
140 break;
142 case SID_CURSORBLKUP:
143 pTabViewShell->MoveCursorArea( 0, -nRepeat, SC_FOLLOW_JUMP, bSel, bKeep );
144 break;
146 case SID_CURSORLEFT:
147 pTabViewShell->MoveCursorRel( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep );
148 break;
150 case SID_CURSORBLKLEFT:
151 pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
152 break;
154 case SID_CURSORRIGHT:
155 pTabViewShell->MoveCursorRel( static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep );
156 break;
158 case SID_CURSORBLKRIGHT:
159 pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
160 break;
162 case SID_CURSORPAGEDOWN:
163 pTabViewShell->MoveCursorPage( 0, nRepeat, SC_FOLLOW_FIX, bSel, bKeep );
164 break;
166 case SID_CURSORPAGEUP:
167 pTabViewShell->MoveCursorPage( 0, -nRepeat, SC_FOLLOW_FIX, bSel, bKeep );
168 break;
170 case SID_CURSORPAGERIGHT_: //XXX !!!
171 pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep );
172 break;
174 case SID_CURSORPAGELEFT_: //XXX !!!
175 pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(-nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep );
176 break;
178 default:
179 OSL_FAIL("Unknown message in ViewShell (Cursor)");
180 return;
183 pTabViewShell->ShowAllCursors();
185 rReq.AppendItem( SfxInt16Item(FN_PARAM_1, static_cast<sal_Int16>(nRepeat)) );
186 rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) );
187 rReq.Done();
190 void ScCellShell::GetStateCursor( SfxItemSet& /* rSet */ )
194 void ScCellShell::ExecuteCursorSel( SfxRequest& rReq )
196 sal_uInt16 nSlotId = rReq.GetSlot();
197 ScTabViewShell* pViewShell = GetViewData()->GetViewShell();
198 ScInputHandler* pInputHdl = pViewShell->GetInputHandler();
199 pViewShell->HideAllCursors();
200 if (pInputHdl && pInputHdl->IsInputMode())
202 // the current cell is in edit mode. Commit the text before moving on.
203 pViewShell->ExecuteInputDirect();
206 SCsCOLROW nRepeat = 1;
207 const SfxItemSet* pReqArgs = rReq.GetArgs();
208 // get repetition
209 if ( pReqArgs != NULL )
211 const SfxPoolItem* pItem;
212 if (pReqArgs->HasItem(FN_PARAM_1, &pItem))
213 nRepeat = static_cast<SCsCOLROW>(((const SfxInt16Item*)pItem)->GetValue());
216 SCsROW nMovY = nRepeat;
217 // Horizontal direction depends on whether or not the UI language is RTL.
218 SCsCOL nMovX = nRepeat;
219 if (GetViewData()->GetDocument()->IsLayoutRTL(GetViewData()->GetTabNo()))
221 // mirror horizontal movement for right-to-left mode.
222 nMovX = -nRepeat;
225 switch (nSlotId)
227 case SID_CURSORDOWN_SEL:
228 pViewShell->ExpandBlock(0, nMovY, SC_FOLLOW_LINE);
229 break;
230 case SID_CURSORUP_SEL:
231 pViewShell->ExpandBlock(0, -nMovY, SC_FOLLOW_LINE);
232 break;
233 case SID_CURSORRIGHT_SEL:
234 pViewShell->ExpandBlock(nMovX, 0, SC_FOLLOW_LINE);
235 break;
236 case SID_CURSORLEFT_SEL:
237 pViewShell->ExpandBlock(-nMovX, 0, SC_FOLLOW_LINE);
238 break;
239 case SID_CURSORPAGEUP_SEL:
240 pViewShell->ExpandBlockPage(0, -nMovY);
241 break;
242 case SID_CURSORPAGEDOWN_SEL:
243 pViewShell->ExpandBlockPage(0, nMovY);
244 break;
245 case SID_CURSORPAGERIGHT_SEL:
246 pViewShell->ExpandBlockPage(nMovX, 0);
247 break;
248 case SID_CURSORPAGELEFT_SEL:
249 pViewShell->ExpandBlockPage(-nMovX, 0);
250 break;
251 case SID_CURSORBLKDOWN_SEL:
252 pViewShell->ExpandBlockArea(0, nMovY);
253 break;
254 case SID_CURSORBLKUP_SEL:
255 pViewShell->ExpandBlockArea(0, -nMovY);
256 break;
257 case SID_CURSORBLKRIGHT_SEL:
258 pViewShell->ExpandBlockArea(nMovX , 0);
259 break;
260 case SID_CURSORBLKLEFT_SEL:
261 pViewShell->ExpandBlockArea(-nMovX, 0);
262 break;
263 default:
266 pViewShell->ShowAllCursors();
268 rReq.AppendItem( SfxInt16Item(FN_PARAM_1,static_cast<sal_Int16>(nRepeat)) );
269 rReq.Done();
272 void ScCellShell::ExecuteMove( SfxRequest& rReq )
274 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
275 sal_uInt16 nSlotId = rReq.GetSlot();
277 if(nSlotId != SID_CURSORTOPOFSCREEN && nSlotId != SID_CURSORENDOFSCREEN)
278 pTabViewShell->ExecuteInputDirect();
279 switch ( nSlotId )
281 case SID_NEXT_TABLE:
282 case SID_NEXT_TABLE_SEL:
283 pTabViewShell->SelectNextTab( 1, (nSlotId == SID_NEXT_TABLE_SEL) );
284 break;
286 case SID_PREV_TABLE:
287 case SID_PREV_TABLE_SEL:
288 pTabViewShell->SelectNextTab( -1, (nSlotId == SID_PREV_TABLE_SEL) );
289 break;
291 // cursor movements in range do not originate from Basic,
292 // because the ScSbxRange-object changes the marking at input
294 case SID_NEXT_UNPROTECT:
295 pTabViewShell->FindNextUnprot( false, !rReq.IsAPI() );
296 break;
298 case SID_PREV_UNPROTECT:
299 pTabViewShell->FindNextUnprot( sal_True, !rReq.IsAPI() );
300 break;
302 case SID_CURSORENTERUP:
303 if (rReq.IsAPI())
304 pTabViewShell->MoveCursorRel( 0, -1, SC_FOLLOW_LINE, false );
305 else
306 pTabViewShell->MoveCursorEnter( sal_True );
307 break;
309 case SID_CURSORENTERDOWN:
310 if (rReq.IsAPI())
311 pTabViewShell->MoveCursorRel( 0, 1, SC_FOLLOW_LINE, false );
312 else
313 pTabViewShell->MoveCursorEnter( false );
314 break;
316 case SID_SELECT_COL:
317 pTabViewShell->MarkColumns();
318 break;
320 case SID_SELECT_ROW:
321 pTabViewShell->MarkRows();
322 break;
324 case SID_SELECT_NONE:
325 pTabViewShell->Unmark();
326 break;
328 case SID_ALIGNCURSOR:
329 pTabViewShell->AlignToCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), SC_FOLLOW_JUMP );
330 break;
332 case SID_MARKDATAAREA:
333 pTabViewShell->MarkDataArea();
334 break;
336 case SID_MARKARRAYFORMULA:
337 pTabViewShell->MarkMatrixFormula();
338 break;
340 case SID_SETINPUTMODE:
341 SC_MOD()->SetInputMode( SC_INPUT_TABLE );
342 break;
344 case SID_FOCUS_INPUTLINE:
346 ScInputHandler* pHdl = SC_MOD()->GetInputHdl( pTabViewShell );
347 if (pHdl)
349 ScInputWindow* pWin = pHdl->GetInputWindow();
350 if (pWin)
351 pWin->SwitchToTextWin();
354 break;
356 case SID_CURSORTOPOFSCREEN:
357 pTabViewShell->MoveCursorScreen( 0, -1, SC_FOLLOW_LINE, false );
358 break;
360 case SID_CURSORENDOFSCREEN:
361 pTabViewShell->MoveCursorScreen( 0, 1, SC_FOLLOW_LINE, false );
362 break;
364 default:
365 OSL_FAIL("Unknown message in ViewShell (Cursor)");
366 return;
369 rReq.Done();
372 void ScCellShell::ExecutePageSel( SfxRequest& rReq )
374 sal_uInt16 nSlotId = rReq.GetSlot();
375 switch ( nSlotId )
377 case SID_CURSORHOME_SEL: rReq.SetSlot( SID_CURSORHOME ); break;
378 case SID_CURSOREND_SEL: rReq.SetSlot( SID_CURSOREND ); break;
379 case SID_CURSORTOPOFFILE_SEL: rReq.SetSlot( SID_CURSORTOPOFFILE ); break;
380 case SID_CURSORENDOFFILE_SEL: rReq.SetSlot( SID_CURSORENDOFFILE ); break;
381 default:
382 OSL_FAIL("Unknown message in ViewShell (ExecutePageSel)");
383 return;
385 rReq.AppendItem( SfxBoolItem(FN_PARAM_2, sal_True) );
386 ExecuteSlot( rReq, GetInterface() );
389 void ScCellShell::ExecutePage( SfxRequest& rReq )
391 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
392 const SfxItemSet* pReqArgs = rReq.GetArgs();
393 sal_uInt16 nSlotId = rReq.GetSlot();
394 sal_Bool bSel = false;
395 sal_Bool bKeep = false;
397 if ( pReqArgs != NULL )
399 const SfxPoolItem* pItem;
400 if (pReqArgs->HasItem(FN_PARAM_2, &pItem))
401 bSel = ((const SfxBoolItem*)pItem)->GetValue();
403 else
405 // evaluate locked selection mode
407 sal_uInt16 nLocked = pTabViewShell->GetLockedModifiers();
408 if ( nLocked & KEY_SHIFT )
409 bSel = sal_True; // EXT
410 else if ( nLocked & KEY_MOD1 )
412 // ADD mode: keep the selection, start a new block when marking with shift again
413 bKeep = true;
417 pTabViewShell->ExecuteInputDirect();
418 switch ( nSlotId )
420 case SID_CURSORHOME:
421 pTabViewShell->MoveCursorEnd( -1, 0, SC_FOLLOW_LINE, bSel, bKeep );
422 break;
424 case SID_CURSOREND:
425 pTabViewShell->MoveCursorEnd( 1, 0, SC_FOLLOW_JUMP, bSel, bKeep );
426 break;
428 case SID_CURSORTOPOFFILE:
429 pTabViewShell->MoveCursorEnd( -1, -1, SC_FOLLOW_LINE, bSel, bKeep );
430 break;
432 case SID_CURSORENDOFFILE:
433 pTabViewShell->MoveCursorEnd( 1, 1, SC_FOLLOW_JUMP, bSel, bKeep );
434 break;
436 default:
437 OSL_FAIL("Unknown message in ViewShell (ExecutePage)");
438 return;
441 rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) );
442 rReq.Done();
448 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */