1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include <sfx2/request.hxx>
23 #include "tabvwsh.hxx"
26 #include "inputhdl.hxx"
27 #include "inputwin.hxx"
28 #include "document.hxx"
31 #include <vcl/svapp.hxx>
33 void ScCellShell::ExecuteCursor( SfxRequest
& rReq
)
35 ScViewData
* pData
= GetViewData();
36 ScTabViewShell
* pTabViewShell
= pData
->GetViewShell();
37 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
38 sal_uInt16 nSlotId
= rReq
.GetSlot();
39 SCsCOLROW nRepeat
= 1;
43 if ( pReqArgs
!= NULL
)
45 const SfxPoolItem
* pItem
;
46 if (pReqArgs
->HasItem(FN_PARAM_1
, &pItem
))
47 nRepeat
= static_cast<SCsCOLROW
>(static_cast<const SfxInt16Item
*>(pItem
)->GetValue());
48 if (pReqArgs
->HasItem(FN_PARAM_2
, &pItem
))
49 bSel
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
53 // evaluate locked selection mode
55 sal_uInt16 nLocked
= pTabViewShell
->GetLockedModifiers();
56 if ( nLocked
& KEY_SHIFT
)
58 else if ( nLocked
& KEY_MOD1
)
60 // ADD mode: keep the selection, start a new block when marking with shift again
70 rReq
.SetSlot(SID_CURSORDOWN_SEL
);
73 rReq
.SetSlot(SID_CURSORUP_SEL
);
76 rReq
.SetSlot(SID_CURSORRIGHT_SEL
);
79 rReq
.SetSlot(SID_CURSORLEFT_SEL
);
81 case SID_CURSORPAGEDOWN
:
82 rReq
.SetSlot(SID_CURSORPAGEDOWN_SEL
);
84 case SID_CURSORPAGEUP
:
85 rReq
.SetSlot(SID_CURSORPAGEUP_SEL
);
87 case SID_CURSORPAGERIGHT
:
88 rReq
.SetSlot(SID_CURSORPAGERIGHT_SEL
);
90 case SID_CURSORPAGELEFT
:
91 rReq
.SetSlot(SID_CURSORPAGELEFT_SEL
);
93 case SID_CURSORBLKDOWN
:
94 rReq
.SetSlot(SID_CURSORBLKDOWN_SEL
);
97 rReq
.SetSlot(SID_CURSORBLKUP_SEL
);
99 case SID_CURSORBLKRIGHT
:
100 rReq
.SetSlot(SID_CURSORBLKRIGHT_SEL
);
102 case SID_CURSORBLKLEFT
:
103 rReq
.SetSlot(SID_CURSORBLKLEFT_SEL
);
108 ExecuteCursorSel(rReq
);
112 SCsCOLROW nRTLSign
= 1;
113 if ( pData
->GetDocument()->IsLayoutRTL( pData
->GetTabNo() ) )
115 //! evaluate cursor movement option?
119 // once extra, so that the cursor will not be painted too often with ExecuteInputDirect:
120 pTabViewShell
->HideAllCursors();
123 if( pTabViewShell
->GetCurObjectSelectionType() == OST_Editing
)
124 pTabViewShell
->SetForceFocusOnCurCell(true);
126 pTabViewShell
->SetForceFocusOnCurCell(false);
128 //OS: once for all should do, however!
129 pTabViewShell
->ExecuteInputDirect();
133 pTabViewShell
->MoveCursorRel( 0, nRepeat
, SC_FOLLOW_LINE
, bSel
, bKeep
);
136 case SID_CURSORBLKDOWN
:
137 pTabViewShell
->MoveCursorArea( 0, nRepeat
, SC_FOLLOW_JUMP
, bSel
, bKeep
);
141 pTabViewShell
->MoveCursorRel( 0, -nRepeat
, SC_FOLLOW_LINE
, bSel
, bKeep
);
144 case SID_CURSORBLKUP
:
145 pTabViewShell
->MoveCursorArea( 0, -nRepeat
, SC_FOLLOW_JUMP
, bSel
, bKeep
);
149 pTabViewShell
->MoveCursorRel( static_cast<SCsCOL
>(-nRepeat
* nRTLSign
), 0, SC_FOLLOW_LINE
, bSel
, bKeep
);
152 case SID_CURSORBLKLEFT
:
153 pTabViewShell
->MoveCursorArea( static_cast<SCsCOL
>(-nRepeat
* nRTLSign
), 0, SC_FOLLOW_JUMP
, bSel
, bKeep
);
156 case SID_CURSORRIGHT
:
157 pTabViewShell
->MoveCursorRel( static_cast<SCsCOL
>(nRepeat
* nRTLSign
), 0, SC_FOLLOW_LINE
, bSel
, bKeep
);
160 case SID_CURSORBLKRIGHT
:
161 pTabViewShell
->MoveCursorArea( static_cast<SCsCOL
>(nRepeat
* nRTLSign
), 0, SC_FOLLOW_JUMP
, bSel
, bKeep
);
164 case SID_CURSORPAGEDOWN
:
165 pTabViewShell
->MoveCursorPage( 0, nRepeat
, SC_FOLLOW_FIX
, bSel
, bKeep
);
168 case SID_CURSORPAGEUP
:
169 pTabViewShell
->MoveCursorPage( 0, -nRepeat
, SC_FOLLOW_FIX
, bSel
, bKeep
);
172 case SID_CURSORPAGERIGHT_
: //XXX !!!
173 pTabViewShell
->MoveCursorPage( static_cast<SCsCOL
>(nRepeat
), 0, SC_FOLLOW_FIX
, bSel
, bKeep
);
176 case SID_CURSORPAGELEFT_
: //XXX !!!
177 pTabViewShell
->MoveCursorPage( static_cast<SCsCOL
>(-nRepeat
), 0, SC_FOLLOW_FIX
, bSel
, bKeep
);
181 OSL_FAIL("Unknown message in ViewShell (Cursor)");
185 pTabViewShell
->ShowAllCursors();
187 rReq
.AppendItem( SfxInt16Item(FN_PARAM_1
, static_cast<sal_Int16
>(nRepeat
)) );
188 rReq
.AppendItem( SfxBoolItem(FN_PARAM_2
, bSel
) );
192 void ScCellShell::GetStateCursor( SfxItemSet
& /* rSet */ )
196 void ScCellShell::ExecuteCursorSel( SfxRequest
& rReq
)
198 sal_uInt16 nSlotId
= rReq
.GetSlot();
199 ScTabViewShell
* pViewShell
= GetViewData()->GetViewShell();
200 ScInputHandler
* pInputHdl
= pViewShell
->GetInputHandler();
201 pViewShell
->HideAllCursors();
202 if (pInputHdl
&& pInputHdl
->IsInputMode())
204 // the current cell is in edit mode. Commit the text before moving on.
205 pViewShell
->ExecuteInputDirect();
208 SCsCOLROW nRepeat
= 1;
209 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
211 if ( pReqArgs
!= NULL
)
213 const SfxPoolItem
* pItem
;
214 if (pReqArgs
->HasItem(FN_PARAM_1
, &pItem
))
215 nRepeat
= static_cast<SCsCOLROW
>(static_cast<const SfxInt16Item
*>(pItem
)->GetValue());
218 SCsROW nMovY
= nRepeat
;
219 // Horizontal direction depends on whether or not the UI language is RTL.
220 SCsCOL nMovX
= nRepeat
;
221 if (GetViewData()->GetDocument()->IsLayoutRTL(GetViewData()->GetTabNo()))
223 // mirror horizontal movement for right-to-left mode.
229 case SID_CURSORDOWN_SEL
:
230 pViewShell
->ExpandBlock(0, nMovY
, SC_FOLLOW_LINE
);
232 case SID_CURSORUP_SEL
:
233 pViewShell
->ExpandBlock(0, -nMovY
, SC_FOLLOW_LINE
);
235 case SID_CURSORRIGHT_SEL
:
236 pViewShell
->ExpandBlock(nMovX
, 0, SC_FOLLOW_LINE
);
238 case SID_CURSORLEFT_SEL
:
239 pViewShell
->ExpandBlock(-nMovX
, 0, SC_FOLLOW_LINE
);
241 case SID_CURSORPAGEUP_SEL
:
242 pViewShell
->ExpandBlockPage(0, -nMovY
);
244 case SID_CURSORPAGEDOWN_SEL
:
245 pViewShell
->ExpandBlockPage(0, nMovY
);
247 case SID_CURSORPAGERIGHT_SEL
:
248 pViewShell
->ExpandBlockPage(nMovX
, 0);
250 case SID_CURSORPAGELEFT_SEL
:
251 pViewShell
->ExpandBlockPage(-nMovX
, 0);
253 case SID_CURSORBLKDOWN_SEL
:
254 pViewShell
->ExpandBlockArea(0, nMovY
);
256 case SID_CURSORBLKUP_SEL
:
257 pViewShell
->ExpandBlockArea(0, -nMovY
);
259 case SID_CURSORBLKRIGHT_SEL
:
260 pViewShell
->ExpandBlockArea(nMovX
, 0);
262 case SID_CURSORBLKLEFT_SEL
:
263 pViewShell
->ExpandBlockArea(-nMovX
, 0);
268 pViewShell
->ShowAllCursors();
270 rReq
.AppendItem( SfxInt16Item(FN_PARAM_1
,static_cast<sal_Int16
>(nRepeat
)) );
274 void ScCellShell::ExecuteMove( SfxRequest
& rReq
)
276 ScTabViewShell
* pTabViewShell
= GetViewData()->GetViewShell();
277 sal_uInt16 nSlotId
= rReq
.GetSlot();
279 if(nSlotId
!= SID_CURSORTOPOFSCREEN
&& nSlotId
!= SID_CURSORENDOFSCREEN
)
280 pTabViewShell
->ExecuteInputDirect();
284 case SID_NEXT_TABLE_SEL
:
285 pTabViewShell
->SelectNextTab( 1, (nSlotId
== SID_NEXT_TABLE_SEL
) );
289 case SID_PREV_TABLE_SEL
:
290 pTabViewShell
->SelectNextTab( -1, (nSlotId
== SID_PREV_TABLE_SEL
) );
293 // cursor movements in range do not originate from Basic,
294 // because the ScSbxRange-object changes the marking at input
296 case SID_NEXT_UNPROTECT
:
297 pTabViewShell
->FindNextUnprot( false, !rReq
.IsAPI() );
300 case SID_PREV_UNPROTECT
:
301 pTabViewShell
->FindNextUnprot( true, !rReq
.IsAPI() );
304 case SID_CURSORENTERUP
:
306 pTabViewShell
->MoveCursorRel( 0, -1, SC_FOLLOW_LINE
, false );
308 pTabViewShell
->MoveCursorEnter( true );
311 case SID_CURSORENTERDOWN
:
313 pTabViewShell
->MoveCursorRel( 0, 1, SC_FOLLOW_LINE
, false );
315 pTabViewShell
->MoveCursorEnter( false );
319 pTabViewShell
->MarkColumns();
323 pTabViewShell
->MarkRows();
326 case SID_SELECT_NONE
:
327 pTabViewShell
->Unmark();
330 case SID_ALIGNCURSOR
:
331 pTabViewShell
->AlignToCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), SC_FOLLOW_JUMP
);
334 case SID_MARKDATAAREA
:
335 pTabViewShell
->MarkDataArea();
338 case SID_MARKARRAYFORMULA
:
339 pTabViewShell
->MarkMatrixFormula();
342 case SID_SETINPUTMODE
:
343 SC_MOD()->SetInputMode( SC_INPUT_TABLE
);
346 case SID_FOCUS_INPUTLINE
:
348 ScInputHandler
* pHdl
= SC_MOD()->GetInputHdl( pTabViewShell
);
351 ScInputWindow
* pWin
= pHdl
->GetInputWindow();
353 pWin
->SwitchToTextWin();
358 case SID_CURSORTOPOFSCREEN
:
359 pTabViewShell
->MoveCursorScreen( 0, -1, SC_FOLLOW_LINE
, false );
362 case SID_CURSORENDOFSCREEN
:
363 pTabViewShell
->MoveCursorScreen( 0, 1, SC_FOLLOW_LINE
, false );
367 OSL_FAIL("Unknown message in ViewShell (Cursor)");
374 void ScCellShell::ExecutePageSel( SfxRequest
& rReq
)
376 sal_uInt16 nSlotId
= rReq
.GetSlot();
379 case SID_CURSORHOME_SEL
: rReq
.SetSlot( SID_CURSORHOME
); break;
380 case SID_CURSOREND_SEL
: rReq
.SetSlot( SID_CURSOREND
); break;
381 case SID_CURSORTOPOFFILE_SEL
: rReq
.SetSlot( SID_CURSORTOPOFFILE
); break;
382 case SID_CURSORENDOFFILE_SEL
: rReq
.SetSlot( SID_CURSORENDOFFILE
); break;
384 OSL_FAIL("Unknown message in ViewShell (ExecutePageSel)");
387 rReq
.AppendItem( SfxBoolItem(FN_PARAM_2
, true) );
388 ExecuteSlot( rReq
, GetInterface() );
391 void ScCellShell::ExecutePage( SfxRequest
& rReq
)
393 ScTabViewShell
* pTabViewShell
= GetViewData()->GetViewShell();
394 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
395 sal_uInt16 nSlotId
= rReq
.GetSlot();
399 if ( pReqArgs
!= NULL
)
401 const SfxPoolItem
* pItem
;
402 if (pReqArgs
->HasItem(FN_PARAM_2
, &pItem
))
403 bSel
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
407 // evaluate locked selection mode
409 sal_uInt16 nLocked
= pTabViewShell
->GetLockedModifiers();
410 if ( nLocked
& KEY_SHIFT
)
412 else if ( nLocked
& KEY_MOD1
)
414 // ADD mode: keep the selection, start a new block when marking with shift again
419 pTabViewShell
->ExecuteInputDirect();
423 pTabViewShell
->MoveCursorEnd( -1, 0, SC_FOLLOW_LINE
, bSel
, bKeep
);
427 pTabViewShell
->MoveCursorEnd( 1, 0, SC_FOLLOW_JUMP
, bSel
, bKeep
);
430 case SID_CURSORTOPOFFILE
:
431 pTabViewShell
->MoveCursorEnd( -1, -1, SC_FOLLOW_LINE
, bSel
, bKeep
);
434 case SID_CURSORENDOFFILE
:
435 pTabViewShell
->MoveCursorEnd( 1, 1, SC_FOLLOW_JUMP
, bSel
, bKeep
);
439 OSL_FAIL("Unknown message in ViewShell (ExecutePage)");
443 rReq
.AppendItem( SfxBoolItem(FN_PARAM_2
, bSel
) );
447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */