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
!= nullptr )
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
!= nullptr )
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();
278 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
280 if(nSlotId
!= SID_CURSORTOPOFSCREEN
&& nSlotId
!= SID_CURSORENDOFSCREEN
)
281 pTabViewShell
->ExecuteInputDirect();
285 case SID_NEXT_TABLE_SEL
:
286 pTabViewShell
->SelectNextTab( 1, (nSlotId
== SID_NEXT_TABLE_SEL
) );
290 case SID_PREV_TABLE_SEL
:
291 pTabViewShell
->SelectNextTab( -1, (nSlotId
== SID_PREV_TABLE_SEL
) );
294 // cursor movements in range do not originate from Basic,
295 // because the ScSbxRange-object changes the marking at input
297 case SID_NEXT_UNPROTECT
:
298 pTabViewShell
->FindNextUnprot( false, !rReq
.IsAPI() );
301 case SID_PREV_UNPROTECT
:
302 pTabViewShell
->FindNextUnprot( true, !rReq
.IsAPI() );
305 case SID_CURSORENTERUP
:
307 pTabViewShell
->MoveCursorRel( 0, -1, SC_FOLLOW_LINE
, false );
309 pTabViewShell
->MoveCursorEnter( true );
312 case SID_CURSORENTERDOWN
:
314 pTabViewShell
->MoveCursorRel( 0, 1, SC_FOLLOW_LINE
, false );
316 pTabViewShell
->MoveCursorEnter( false );
321 const SfxPoolItem
* pColItem
;
322 const SfxPoolItem
* pModifierItem
;
323 if ( pReqArgs
&& pReqArgs
->HasItem( FN_PARAM_1
, &pColItem
) &&
324 pReqArgs
->HasItem( FN_PARAM_2
, &pModifierItem
) )
326 SCCOL nCol
= static_cast<SCCOL
>(static_cast<const SfxInt32Item
*>(pColItem
)->GetValue());;
327 sal_Int16 nModifier
= static_cast<sal_Int16
>(static_cast<const SfxInt16Item
*>(pModifierItem
)->GetValue());
329 pTabViewShell
->MarkColumns( nCol
, nModifier
);
332 pTabViewShell
->MarkColumns();
338 const SfxPoolItem
* pRowItem
;
339 const SfxPoolItem
* pModifierItem
;
340 if ( pReqArgs
&& pReqArgs
->HasItem( FN_PARAM_1
, &pRowItem
) &&
341 pReqArgs
->HasItem( FN_PARAM_2
, &pModifierItem
) )
343 SCROW nRow
= static_cast<SCROW
>(static_cast<const SfxInt32Item
*>(pRowItem
)->GetValue());;
344 sal_Int16 nModifier
= static_cast<sal_Int16
>(static_cast<const SfxInt16Item
*>(pModifierItem
)->GetValue());
346 pTabViewShell
->MarkRows( nRow
, nModifier
);
349 pTabViewShell
->MarkRows();
353 case SID_SELECT_NONE
:
354 pTabViewShell
->Unmark();
357 case SID_ALIGNCURSOR
:
358 pTabViewShell
->AlignToCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), SC_FOLLOW_JUMP
);
361 case SID_MARKDATAAREA
:
362 pTabViewShell
->MarkDataArea();
365 case SID_MARKARRAYFORMULA
:
366 pTabViewShell
->MarkMatrixFormula();
369 case SID_SETINPUTMODE
:
370 SC_MOD()->SetInputMode( SC_INPUT_TABLE
);
373 case SID_FOCUS_INPUTLINE
:
375 ScInputHandler
* pHdl
= SC_MOD()->GetInputHdl( pTabViewShell
);
378 ScInputWindow
* pWin
= pHdl
->GetInputWindow();
380 pWin
->SwitchToTextWin();
385 case SID_CURSORTOPOFSCREEN
:
386 pTabViewShell
->MoveCursorScreen( 0, -1, SC_FOLLOW_LINE
, false );
389 case SID_CURSORENDOFSCREEN
:
390 pTabViewShell
->MoveCursorScreen( 0, 1, SC_FOLLOW_LINE
, false );
394 OSL_FAIL("Unknown message in ViewShell (Cursor)");
401 void ScCellShell::ExecutePageSel( SfxRequest
& rReq
)
403 sal_uInt16 nSlotId
= rReq
.GetSlot();
406 case SID_CURSORHOME_SEL
: rReq
.SetSlot( SID_CURSORHOME
); break;
407 case SID_CURSOREND_SEL
: rReq
.SetSlot( SID_CURSOREND
); break;
408 case SID_CURSORTOPOFFILE_SEL
: rReq
.SetSlot( SID_CURSORTOPOFFILE
); break;
409 case SID_CURSORENDOFFILE_SEL
: rReq
.SetSlot( SID_CURSORENDOFFILE
); break;
411 OSL_FAIL("Unknown message in ViewShell (ExecutePageSel)");
414 rReq
.AppendItem( SfxBoolItem(FN_PARAM_2
, true) );
415 ExecuteSlot( rReq
, GetInterface() );
418 void ScCellShell::ExecutePage( SfxRequest
& rReq
)
420 ScTabViewShell
* pTabViewShell
= GetViewData()->GetViewShell();
421 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
422 sal_uInt16 nSlotId
= rReq
.GetSlot();
426 if ( pReqArgs
!= nullptr )
428 const SfxPoolItem
* pItem
;
429 if (pReqArgs
->HasItem(FN_PARAM_2
, &pItem
))
430 bSel
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
434 // evaluate locked selection mode
436 sal_uInt16 nLocked
= pTabViewShell
->GetLockedModifiers();
437 if ( nLocked
& KEY_SHIFT
)
439 else if ( nLocked
& KEY_MOD1
)
441 // ADD mode: keep the selection, start a new block when marking with shift again
446 pTabViewShell
->ExecuteInputDirect();
450 pTabViewShell
->MoveCursorEnd( -1, 0, SC_FOLLOW_LINE
, bSel
, bKeep
);
454 pTabViewShell
->MoveCursorEnd( 1, 0, SC_FOLLOW_JUMP
, bSel
, bKeep
);
457 case SID_CURSORTOPOFFILE
:
458 pTabViewShell
->MoveCursorEnd( -1, -1, SC_FOLLOW_LINE
, bSel
, bKeep
);
461 case SID_CURSORENDOFFILE
:
462 pTabViewShell
->MoveCursorEnd( 1, 1, SC_FOLLOW_JUMP
, bSel
, bKeep
);
466 OSL_FAIL("Unknown message in ViewShell (ExecutePage)");
470 rReq
.AppendItem( SfxBoolItem(FN_PARAM_2
, bSel
) );
474 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */