1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cellsh4.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------
39 #pragma optimize ("", off)
42 // INCLUDE ---------------------------------------------------------------
44 #include <sfx2/request.hxx>
47 #include "tabvwsh.hxx"
50 #include "inputhdl.hxx"
51 #include "inputwin.hxx"
52 #include "document.hxx"
55 #include "vcl/svapp.hxx"
57 //------------------------------------------------------------------
59 #define IS_AVAILABLE(WhichId,ppItem) \
60 (pReqArgs->GetItemState((WhichId), TRUE, ppItem ) == SFX_ITEM_SET)
63 void ScCellShell::ExecuteCursor( SfxRequest
& rReq
)
65 ScViewData
* pData
= GetViewData();
66 ScTabViewShell
* pTabViewShell
= pData
->GetViewShell();
67 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
68 USHORT nSlotId
= rReq
.GetSlot();
69 SCsCOLROW nRepeat
= 1;
73 if ( pReqArgs
!= NULL
)
75 const SfxPoolItem
* pItem
;
76 if( IS_AVAILABLE( FN_PARAM_1
, &pItem
) )
77 nRepeat
= static_cast<SCsCOLROW
>(((const SfxInt16Item
*)pItem
)->GetValue());
78 if( IS_AVAILABLE( FN_PARAM_2
, &pItem
) )
79 bSel
= ((const SfxBoolItem
*)pItem
)->GetValue();
83 // evaluate locked selection mode
85 USHORT nLocked
= pTabViewShell
->GetLockedModifiers();
86 if ( nLocked
& KEY_SHIFT
)
88 else if ( nLocked
& KEY_MOD1
)
90 // ADD mode: keep the selection, start a new block when marking with shift again
100 rReq
.SetSlot(SID_CURSORDOWN_SEL
);
103 rReq
.SetSlot(SID_CURSORUP_SEL
);
105 case SID_CURSORRIGHT
:
106 rReq
.SetSlot(SID_CURSORRIGHT_SEL
);
109 rReq
.SetSlot(SID_CURSORLEFT_SEL
);
111 case SID_CURSORPAGEDOWN
:
112 rReq
.SetSlot(SID_CURSORPAGEDOWN_SEL
);
114 case SID_CURSORPAGEUP
:
115 rReq
.SetSlot(SID_CURSORPAGEUP_SEL
);
117 case SID_CURSORPAGERIGHT
:
118 rReq
.SetSlot(SID_CURSORPAGERIGHT_SEL
);
120 case SID_CURSORPAGELEFT
:
121 rReq
.SetSlot(SID_CURSORPAGELEFT_SEL
);
123 case SID_CURSORBLKDOWN
:
124 rReq
.SetSlot(SID_CURSORBLKDOWN_SEL
);
126 case SID_CURSORBLKUP
:
127 rReq
.SetSlot(SID_CURSORBLKUP_SEL
);
129 case SID_CURSORBLKRIGHT
:
130 rReq
.SetSlot(SID_CURSORBLKRIGHT_SEL
);
132 case SID_CURSORBLKLEFT
:
133 rReq
.SetSlot(SID_CURSORBLKLEFT_SEL
);
138 ExecuteCursorSel(rReq
);
142 SCsCOLROW nRTLSign
= 1;
143 if ( pData
->GetDocument()->IsLayoutRTL( pData
->GetTabNo() ) )
145 //! evaluate cursor movement option?
149 // einmal extra, damit der Cursor bei ExecuteInputDirect nicht zuoft gemalt wird:
150 pTabViewShell
->HideAllCursors();
152 //OS: einmal fuer alle wird doch reichen!
153 pTabViewShell
->ExecuteInputDirect();
157 pTabViewShell
->MoveCursorRel( 0, nRepeat
, SC_FOLLOW_LINE
, bSel
, bKeep
);
160 case SID_CURSORBLKDOWN
:
161 pTabViewShell
->MoveCursorArea( 0, nRepeat
, SC_FOLLOW_JUMP
, bSel
, bKeep
);
165 pTabViewShell
->MoveCursorRel( 0, -nRepeat
, SC_FOLLOW_LINE
, bSel
, bKeep
);
168 case SID_CURSORBLKUP
:
169 pTabViewShell
->MoveCursorArea( 0, -nRepeat
, SC_FOLLOW_JUMP
, bSel
, bKeep
);
173 pTabViewShell
->MoveCursorRel( static_cast<SCsCOL
>(-nRepeat
* nRTLSign
), 0, SC_FOLLOW_LINE
, bSel
, bKeep
);
176 case SID_CURSORBLKLEFT
:
177 pTabViewShell
->MoveCursorArea( static_cast<SCsCOL
>(-nRepeat
* nRTLSign
), 0, SC_FOLLOW_JUMP
, bSel
, bKeep
);
180 case SID_CURSORRIGHT
:
181 pTabViewShell
->MoveCursorRel( static_cast<SCsCOL
>(nRepeat
* nRTLSign
), 0, SC_FOLLOW_LINE
, bSel
, bKeep
);
184 case SID_CURSORBLKRIGHT
:
185 pTabViewShell
->MoveCursorArea( static_cast<SCsCOL
>(nRepeat
* nRTLSign
), 0, SC_FOLLOW_JUMP
, bSel
, bKeep
);
188 case SID_CURSORPAGEDOWN
:
189 pTabViewShell
->MoveCursorPage( 0, nRepeat
, SC_FOLLOW_FIX
, bSel
, bKeep
);
192 case SID_CURSORPAGEUP
:
193 pTabViewShell
->MoveCursorPage( 0, -nRepeat
, SC_FOLLOW_FIX
, bSel
, bKeep
);
196 case SID_CURSORPAGERIGHT_
: //XXX !!!
197 pTabViewShell
->MoveCursorPage( static_cast<SCsCOL
>(nRepeat
), 0, SC_FOLLOW_FIX
, bSel
, bKeep
);
200 case SID_CURSORPAGELEFT_
: //XXX !!!
201 pTabViewShell
->MoveCursorPage( static_cast<SCsCOL
>(-nRepeat
), 0, SC_FOLLOW_FIX
, bSel
, bKeep
);
205 DBG_ERROR("Unbekannte Message bei ViewShell (Cursor)");
209 pTabViewShell
->ShowAllCursors();
211 rReq
.AppendItem( SfxInt16Item(FN_PARAM_1
, static_cast<sal_Int16
>(nRepeat
)) );
212 rReq
.AppendItem( SfxBoolItem(FN_PARAM_2
, bSel
) );
216 void ScCellShell::GetStateCursor( SfxItemSet
& /* rSet */ )
220 void ScCellShell::ExecuteCursorSel( SfxRequest
& rReq
)
222 sal_uInt16 nSlotId
= rReq
.GetSlot();
223 ScTabViewShell
* pViewShell
= GetViewData()->GetViewShell();
224 ScInputHandler
* pInputHdl
= pViewShell
->GetInputHandler();
225 pViewShell
->HideAllCursors();
226 if (pInputHdl
&& pInputHdl
->IsInputMode())
228 // the current cell is in edit mode. Commit the text before moving on.
229 pViewShell
->ExecuteInputDirect();
232 // Horizontal direction depends on whether or not the UI language is RTL.
233 SCsCOL nMovX
= Application::GetSettings().GetLayoutRTL() ? -1 : 1;
237 case SID_CURSORDOWN_SEL
:
238 pViewShell
->ExpandBlock(0, 1, SC_FOLLOW_LINE
);
240 case SID_CURSORUP_SEL
:
241 pViewShell
->ExpandBlock(0, -1, SC_FOLLOW_LINE
);
243 case SID_CURSORRIGHT_SEL
:
244 pViewShell
->ExpandBlock(nMovX
, 0, SC_FOLLOW_LINE
);
246 case SID_CURSORLEFT_SEL
:
247 pViewShell
->ExpandBlock(-nMovX
, 0, SC_FOLLOW_LINE
);
249 case SID_CURSORPAGEUP_SEL
:
250 pViewShell
->ExpandBlockPage(0, -1);
252 case SID_CURSORPAGEDOWN_SEL
:
253 pViewShell
->ExpandBlockPage(0, 1);
255 case SID_CURSORPAGERIGHT_SEL
:
256 pViewShell
->ExpandBlockPage(nMovX
, 0);
258 case SID_CURSORPAGELEFT_SEL
:
259 pViewShell
->ExpandBlockPage(-nMovX
, 0);
261 case SID_CURSORBLKDOWN_SEL
:
262 pViewShell
->ExpandBlockArea(0, 1);
264 case SID_CURSORBLKUP_SEL
:
265 pViewShell
->ExpandBlockArea(0, -1);
267 case SID_CURSORBLKRIGHT_SEL
:
268 pViewShell
->ExpandBlockArea(nMovX
, 0);
270 case SID_CURSORBLKLEFT_SEL
:
271 pViewShell
->ExpandBlockArea(-nMovX
, 0);
276 pViewShell
->ShowAllCursors();
279 void ScCellShell::ExecuteMove( SfxRequest
& rReq
)
281 ScTabViewShell
* pTabViewShell
= GetViewData()->GetViewShell();
282 USHORT nSlotId
= rReq
.GetSlot();
284 if(nSlotId
!= SID_CURSORTOPOFSCREEN
&& nSlotId
!= SID_CURSORENDOFSCREEN
)
285 pTabViewShell
->ExecuteInputDirect();
289 case SID_NEXT_TABLE_SEL
:
290 pTabViewShell
->SelectNextTab( 1, (nSlotId
== SID_NEXT_TABLE_SEL
) );
294 case SID_PREV_TABLE_SEL
:
295 pTabViewShell
->SelectNextTab( -1, (nSlotId
== SID_PREV_TABLE_SEL
) );
298 // Cursorbewegungen in Bloecken gehen nicht von Basic aus,
299 // weil das ScSbxRange-Objekt bei Eingaben die Markierung veraendert
301 case SID_NEXT_UNPROTECT
:
302 pTabViewShell
->FindNextUnprot( FALSE
, !rReq
.IsAPI() );
305 case SID_PREV_UNPROTECT
:
306 pTabViewShell
->FindNextUnprot( TRUE
, !rReq
.IsAPI() );
309 case SID_CURSORENTERUP
:
311 pTabViewShell
->MoveCursorRel( 0, -1, SC_FOLLOW_LINE
, FALSE
);
313 pTabViewShell
->MoveCursorEnter( TRUE
);
316 case SID_CURSORENTERDOWN
:
318 pTabViewShell
->MoveCursorRel( 0, 1, SC_FOLLOW_LINE
, FALSE
);
320 pTabViewShell
->MoveCursorEnter( FALSE
);
324 pTabViewShell
->MarkColumns();
328 pTabViewShell
->MarkRows();
331 case SID_SELECT_NONE
:
332 pTabViewShell
->Unmark();
335 case SID_ALIGNCURSOR
:
336 pTabViewShell
->AlignToCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), SC_FOLLOW_JUMP
);
339 case SID_MARKDATAAREA
:
340 pTabViewShell
->MarkDataArea();
343 case SID_MARKARRAYFORMULA
:
344 pTabViewShell
->MarkMatrixFormula();
347 case SID_SETINPUTMODE
:
348 SC_MOD()->SetInputMode( SC_INPUT_TABLE
);
351 case SID_FOCUS_INPUTLINE
:
353 ScInputHandler
* pHdl
= SC_MOD()->GetInputHdl( pTabViewShell
);
356 ScInputWindow
* pWin
= pHdl
->GetInputWindow();
358 pWin
->SwitchToTextWin();
363 case SID_CURSORTOPOFSCREEN
:
364 pTabViewShell
->MoveCursorScreen( 0, -1, SC_FOLLOW_LINE
, FALSE
);
367 case SID_CURSORENDOFSCREEN
:
368 pTabViewShell
->MoveCursorScreen( 0, 1, SC_FOLLOW_LINE
, FALSE
);
372 DBG_ERROR("Unbekannte Message bei ViewShell (Cursor)");
379 void ScCellShell::ExecutePageSel( SfxRequest
& rReq
)
381 USHORT nSlotId
= rReq
.GetSlot();
384 case SID_CURSORHOME_SEL
: rReq
.SetSlot( SID_CURSORHOME
); break;
385 case SID_CURSOREND_SEL
: rReq
.SetSlot( SID_CURSOREND
); break;
386 case SID_CURSORTOPOFFILE_SEL
: rReq
.SetSlot( SID_CURSORTOPOFFILE
); break;
387 case SID_CURSORENDOFFILE_SEL
: rReq
.SetSlot( SID_CURSORENDOFFILE
); break;
389 DBG_ERROR("Unbekannte Message bei ViewShell (ExecutePageSel)");
392 rReq
.AppendItem( SfxBoolItem(FN_PARAM_2
, TRUE
) );
393 ExecuteSlot( rReq
, GetInterface() );
396 void ScCellShell::ExecutePage( SfxRequest
& rReq
)
398 ScTabViewShell
* pTabViewShell
= GetViewData()->GetViewShell();
399 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
400 USHORT nSlotId
= rReq
.GetSlot();
404 if ( pReqArgs
!= NULL
)
406 const SfxPoolItem
* pItem
;
407 if( IS_AVAILABLE( FN_PARAM_2
, &pItem
) )
408 bSel
= ((const SfxBoolItem
*)pItem
)->GetValue();
412 // evaluate locked selection mode
414 USHORT nLocked
= pTabViewShell
->GetLockedModifiers();
415 if ( nLocked
& KEY_SHIFT
)
417 else if ( nLocked
& KEY_MOD1
)
419 // ADD mode: keep the selection, start a new block when marking with shift again
424 pTabViewShell
->ExecuteInputDirect();
428 pTabViewShell
->MoveCursorEnd( -1, 0, SC_FOLLOW_LINE
, bSel
, bKeep
);
432 pTabViewShell
->MoveCursorEnd( 1, 0, SC_FOLLOW_JUMP
, bSel
, bKeep
);
435 case SID_CURSORTOPOFFILE
:
436 pTabViewShell
->MoveCursorEnd( -1, -1, SC_FOLLOW_LINE
, bSel
, bKeep
);
439 case SID_CURSORENDOFFILE
:
440 pTabViewShell
->MoveCursorEnd( 1, 1, SC_FOLLOW_JUMP
, bSel
, bKeep
);
444 DBG_ERROR("Unbekannte Message bei ViewShell (ExecutePage)");
448 rReq
.AppendItem( SfxBoolItem(FN_PARAM_2
, bSel
) );