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 .
21 #pragma optimize ("", off)
24 #include <sfx2/request.hxx>
27 #include "tabvwsh.hxx"
30 #include "inputhdl.hxx"
31 #include "inputwin.hxx"
32 #include "document.hxx"
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();
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
74 rReq
.SetSlot(SID_CURSORDOWN_SEL
);
77 rReq
.SetSlot(SID_CURSORUP_SEL
);
80 rReq
.SetSlot(SID_CURSORRIGHT_SEL
);
83 rReq
.SetSlot(SID_CURSORLEFT_SEL
);
85 case SID_CURSORPAGEDOWN
:
86 rReq
.SetSlot(SID_CURSORPAGEDOWN_SEL
);
88 case SID_CURSORPAGEUP
:
89 rReq
.SetSlot(SID_CURSORPAGEUP_SEL
);
91 case SID_CURSORPAGERIGHT
:
92 rReq
.SetSlot(SID_CURSORPAGERIGHT_SEL
);
94 case SID_CURSORPAGELEFT
:
95 rReq
.SetSlot(SID_CURSORPAGELEFT_SEL
);
97 case SID_CURSORBLKDOWN
:
98 rReq
.SetSlot(SID_CURSORBLKDOWN_SEL
);
100 case SID_CURSORBLKUP
:
101 rReq
.SetSlot(SID_CURSORBLKUP_SEL
);
103 case SID_CURSORBLKRIGHT
:
104 rReq
.SetSlot(SID_CURSORBLKRIGHT_SEL
);
106 case SID_CURSORBLKLEFT
:
107 rReq
.SetSlot(SID_CURSORBLKLEFT_SEL
);
112 ExecuteCursorSel(rReq
);
116 SCsCOLROW nRTLSign
= 1;
117 if ( pData
->GetDocument()->IsLayoutRTL( pData
->GetTabNo() ) )
119 //! evaluate cursor movement option?
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();
131 pTabViewShell
->MoveCursorRel( 0, nRepeat
, SC_FOLLOW_LINE
, bSel
, bKeep
);
134 case SID_CURSORBLKDOWN
:
135 pTabViewShell
->MoveCursorArea( 0, nRepeat
, SC_FOLLOW_JUMP
, bSel
, bKeep
);
139 pTabViewShell
->MoveCursorRel( 0, -nRepeat
, SC_FOLLOW_LINE
, bSel
, bKeep
);
142 case SID_CURSORBLKUP
:
143 pTabViewShell
->MoveCursorArea( 0, -nRepeat
, SC_FOLLOW_JUMP
, bSel
, bKeep
);
147 pTabViewShell
->MoveCursorRel( static_cast<SCsCOL
>(-nRepeat
* nRTLSign
), 0, SC_FOLLOW_LINE
, bSel
, bKeep
);
150 case SID_CURSORBLKLEFT
:
151 pTabViewShell
->MoveCursorArea( static_cast<SCsCOL
>(-nRepeat
* nRTLSign
), 0, SC_FOLLOW_JUMP
, bSel
, bKeep
);
154 case SID_CURSORRIGHT
:
155 pTabViewShell
->MoveCursorRel( static_cast<SCsCOL
>(nRepeat
* nRTLSign
), 0, SC_FOLLOW_LINE
, bSel
, bKeep
);
158 case SID_CURSORBLKRIGHT
:
159 pTabViewShell
->MoveCursorArea( static_cast<SCsCOL
>(nRepeat
* nRTLSign
), 0, SC_FOLLOW_JUMP
, bSel
, bKeep
);
162 case SID_CURSORPAGEDOWN
:
163 pTabViewShell
->MoveCursorPage( 0, nRepeat
, SC_FOLLOW_FIX
, bSel
, bKeep
);
166 case SID_CURSORPAGEUP
:
167 pTabViewShell
->MoveCursorPage( 0, -nRepeat
, SC_FOLLOW_FIX
, bSel
, bKeep
);
170 case SID_CURSORPAGERIGHT_
: //XXX !!!
171 pTabViewShell
->MoveCursorPage( static_cast<SCsCOL
>(nRepeat
), 0, SC_FOLLOW_FIX
, bSel
, bKeep
);
174 case SID_CURSORPAGELEFT_
: //XXX !!!
175 pTabViewShell
->MoveCursorPage( static_cast<SCsCOL
>(-nRepeat
), 0, SC_FOLLOW_FIX
, bSel
, bKeep
);
179 OSL_FAIL("Unknown message in ViewShell (Cursor)");
183 pTabViewShell
->ShowAllCursors();
185 rReq
.AppendItem( SfxInt16Item(FN_PARAM_1
, static_cast<sal_Int16
>(nRepeat
)) );
186 rReq
.AppendItem( SfxBoolItem(FN_PARAM_2
, bSel
) );
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();
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.
227 case SID_CURSORDOWN_SEL
:
228 pViewShell
->ExpandBlock(0, nMovY
, SC_FOLLOW_LINE
);
230 case SID_CURSORUP_SEL
:
231 pViewShell
->ExpandBlock(0, -nMovY
, SC_FOLLOW_LINE
);
233 case SID_CURSORRIGHT_SEL
:
234 pViewShell
->ExpandBlock(nMovX
, 0, SC_FOLLOW_LINE
);
236 case SID_CURSORLEFT_SEL
:
237 pViewShell
->ExpandBlock(-nMovX
, 0, SC_FOLLOW_LINE
);
239 case SID_CURSORPAGEUP_SEL
:
240 pViewShell
->ExpandBlockPage(0, -nMovY
);
242 case SID_CURSORPAGEDOWN_SEL
:
243 pViewShell
->ExpandBlockPage(0, nMovY
);
245 case SID_CURSORPAGERIGHT_SEL
:
246 pViewShell
->ExpandBlockPage(nMovX
, 0);
248 case SID_CURSORPAGELEFT_SEL
:
249 pViewShell
->ExpandBlockPage(-nMovX
, 0);
251 case SID_CURSORBLKDOWN_SEL
:
252 pViewShell
->ExpandBlockArea(0, nMovY
);
254 case SID_CURSORBLKUP_SEL
:
255 pViewShell
->ExpandBlockArea(0, -nMovY
);
257 case SID_CURSORBLKRIGHT_SEL
:
258 pViewShell
->ExpandBlockArea(nMovX
, 0);
260 case SID_CURSORBLKLEFT_SEL
:
261 pViewShell
->ExpandBlockArea(-nMovX
, 0);
266 pViewShell
->ShowAllCursors();
268 rReq
.AppendItem( SfxInt16Item(FN_PARAM_1
,static_cast<sal_Int16
>(nRepeat
)) );
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();
282 case SID_NEXT_TABLE_SEL
:
283 pTabViewShell
->SelectNextTab( 1, (nSlotId
== SID_NEXT_TABLE_SEL
) );
287 case SID_PREV_TABLE_SEL
:
288 pTabViewShell
->SelectNextTab( -1, (nSlotId
== SID_PREV_TABLE_SEL
) );
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() );
298 case SID_PREV_UNPROTECT
:
299 pTabViewShell
->FindNextUnprot( sal_True
, !rReq
.IsAPI() );
302 case SID_CURSORENTERUP
:
304 pTabViewShell
->MoveCursorRel( 0, -1, SC_FOLLOW_LINE
, false );
306 pTabViewShell
->MoveCursorEnter( sal_True
);
309 case SID_CURSORENTERDOWN
:
311 pTabViewShell
->MoveCursorRel( 0, 1, SC_FOLLOW_LINE
, false );
313 pTabViewShell
->MoveCursorEnter( false );
317 pTabViewShell
->MarkColumns();
321 pTabViewShell
->MarkRows();
324 case SID_SELECT_NONE
:
325 pTabViewShell
->Unmark();
328 case SID_ALIGNCURSOR
:
329 pTabViewShell
->AlignToCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), SC_FOLLOW_JUMP
);
332 case SID_MARKDATAAREA
:
333 pTabViewShell
->MarkDataArea();
336 case SID_MARKARRAYFORMULA
:
337 pTabViewShell
->MarkMatrixFormula();
340 case SID_SETINPUTMODE
:
341 SC_MOD()->SetInputMode( SC_INPUT_TABLE
);
344 case SID_FOCUS_INPUTLINE
:
346 ScInputHandler
* pHdl
= SC_MOD()->GetInputHdl( pTabViewShell
);
349 ScInputWindow
* pWin
= pHdl
->GetInputWindow();
351 pWin
->SwitchToTextWin();
356 case SID_CURSORTOPOFSCREEN
:
357 pTabViewShell
->MoveCursorScreen( 0, -1, SC_FOLLOW_LINE
, false );
360 case SID_CURSORENDOFSCREEN
:
361 pTabViewShell
->MoveCursorScreen( 0, 1, SC_FOLLOW_LINE
, false );
365 OSL_FAIL("Unknown message in ViewShell (Cursor)");
372 void ScCellShell::ExecutePageSel( SfxRequest
& rReq
)
374 sal_uInt16 nSlotId
= rReq
.GetSlot();
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;
382 OSL_FAIL("Unknown message in ViewShell (ExecutePageSel)");
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();
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
417 pTabViewShell
->ExecuteInputDirect();
421 pTabViewShell
->MoveCursorEnd( -1, 0, SC_FOLLOW_LINE
, bSel
, bKeep
);
425 pTabViewShell
->MoveCursorEnd( 1, 0, SC_FOLLOW_JUMP
, bSel
, bKeep
);
428 case SID_CURSORTOPOFFILE
:
429 pTabViewShell
->MoveCursorEnd( -1, -1, SC_FOLLOW_LINE
, bSel
, bKeep
);
432 case SID_CURSORENDOFFILE
:
433 pTabViewShell
->MoveCursorEnd( 1, 1, SC_FOLLOW_JUMP
, bSel
, bKeep
);
437 OSL_FAIL("Unknown message in ViewShell (ExecutePage)");
441 rReq
.AppendItem( SfxBoolItem(FN_PARAM_2
, bSel
) );
448 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */