xref: /aoo41x/main/sc/source/ui/view/cellsh4.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 
33 //------------------------------------------------------------------
34 
35 #ifdef _MSC_VER
36 #pragma optimize ("", off)
37 #endif
38 
39 // INCLUDE ---------------------------------------------------------------
40 
41 #include <sfx2/request.hxx>
42 
43 #include "cellsh.hxx"
44 #include "tabvwsh.hxx"
45 #include "global.hxx"
46 #include "scmod.hxx"
47 #include "inputhdl.hxx"
48 #include "inputwin.hxx"
49 #include "document.hxx"
50 #include "sc.hrc"
51 
52 
53 //------------------------------------------------------------------
54 
55 #define IS_AVAILABLE(WhichId,ppItem) \
56     (pReqArgs->GetItemState((WhichId), sal_True, ppItem ) == SFX_ITEM_SET)
57 
58 
59 void ScCellShell::ExecuteCursor( SfxRequest& rReq )
60 {
61 	ScViewData* pData = GetViewData();
62 	ScTabViewShell*	pTabViewShell  	= pData->GetViewShell();
63 	const SfxItemSet*	pReqArgs = rReq.GetArgs();
64 	sal_uInt16				nSlotId  = rReq.GetSlot();
65 	SCsCOLROW	        nRepeat = 1;
66 	sal_Bool				bSel = sal_False;
67 	sal_Bool				bKeep = sal_False;
68 
69 	if ( pReqArgs != NULL )
70 	{
71 		const	SfxPoolItem* pItem;
72 		if( IS_AVAILABLE( FN_PARAM_1, &pItem ) )
73 			nRepeat = static_cast<SCsCOLROW>(((const SfxInt16Item*)pItem)->GetValue());
74 		if( IS_AVAILABLE( FN_PARAM_2, &pItem ) )
75 			bSel = ((const SfxBoolItem*)pItem)->GetValue();
76 	}
77 	else
78 	{
79 		//	evaluate locked selection mode
80 
81 		sal_uInt16 nLocked = pTabViewShell->GetLockedModifiers();
82 		if ( nLocked & KEY_SHIFT )
83 			bSel = sal_True;				// EXT
84 		else if ( nLocked & KEY_MOD1 )
85 		{
86 			// ADD mode: keep the selection, start a new block when marking with shift again
87 			bKeep = sal_True;
88 			pTabViewShell->SetNewStartIfMarking();
89 		}
90 	}
91 
92 	SCsCOLROW nRTLSign = 1;
93 	if ( pData->GetDocument()->IsLayoutRTL( pData->GetTabNo() ) )
94 	{
95 		//!	evaluate cursor movement option?
96 		nRTLSign = -1;
97 	}
98 
99 	// einmal extra, damit der Cursor bei ExecuteInputDirect nicht zuoft gemalt wird:
100 	pTabViewShell->HideAllCursors();
101 
102 	//OS: einmal fuer alle wird doch reichen!
103 	pTabViewShell->ExecuteInputDirect();
104 	switch ( nSlotId )
105 	{
106 		case SID_CURSORDOWN:
107 			pTabViewShell->MoveCursorRel(	0,	nRepeat, SC_FOLLOW_LINE, bSel, bKeep );
108 			break;
109 
110 		case SID_CURSORBLKDOWN:
111 			pTabViewShell->MoveCursorArea( 0, nRepeat, SC_FOLLOW_JUMP, bSel, bKeep );
112 			break;
113 
114 		case SID_CURSORUP:
115 			pTabViewShell->MoveCursorRel(	0,	-nRepeat, SC_FOLLOW_LINE, bSel, bKeep );
116 			break;
117 
118 		case SID_CURSORBLKUP:
119 			pTabViewShell->MoveCursorArea( 0, -nRepeat, SC_FOLLOW_JUMP, bSel, bKeep );
120 			break;
121 
122 		case SID_CURSORLEFT:
123 			pTabViewShell->MoveCursorRel( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep );
124 			break;
125 
126 		case SID_CURSORBLKLEFT:
127 			pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
128 			break;
129 
130 		case SID_CURSORRIGHT:
131 			pTabViewShell->MoveCursorRel(	static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep );
132 			break;
133 
134 		case SID_CURSORBLKRIGHT:
135 			pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
136 			break;
137 
138 		case SID_CURSORPAGEDOWN:
139 			pTabViewShell->MoveCursorPage(	0, nRepeat, SC_FOLLOW_FIX, bSel, bKeep );
140 			break;
141 
142 		case SID_CURSORPAGEUP:
143 			pTabViewShell->MoveCursorPage(	0, -nRepeat, SC_FOLLOW_FIX, bSel, bKeep );
144 			break;
145 
146 		case SID_CURSORPAGERIGHT_: //XXX !!!
147 			pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep );
148 			break;
149 
150 		case SID_CURSORPAGELEFT_: //XXX !!!
151 			pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(-nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep );
152 			break;
153 
154 		default:
155 			DBG_ERROR("Unbekannte Message bei ViewShell (Cursor)");
156 			return;
157 	}
158 
159 	pTabViewShell->ShowAllCursors();
160 
161 	rReq.AppendItem( SfxInt16Item(FN_PARAM_1, static_cast<sal_Int16>(nRepeat)) );
162 	rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) );
163 	rReq.Done();
164 }
165 
166 void ScCellShell::GetStateCursor( SfxItemSet& /* rSet */ )
167 {
168 }
169 
170 void ScCellShell::ExecuteCursorSel( SfxRequest& rReq )
171 {
172 	const SfxItemSet*	pReqArgs = rReq.GetArgs();
173 	sal_uInt16				nSlotId  = rReq.GetSlot();
174 	short				nRepeat = 1;
175 
176 	if ( pReqArgs != NULL )
177 	{
178 		const	SfxPoolItem* pItem;
179 		if( IS_AVAILABLE( FN_PARAM_1, &pItem ) )
180 			nRepeat = ((const SfxInt16Item*)pItem)->GetValue();
181 	}
182 
183 	switch ( nSlotId )
184 	{
185 		case SID_CURSORDOWN_SEL:		rReq.SetSlot( SID_CURSORDOWN );  break;
186 		case SID_CURSORBLKDOWN_SEL:		rReq.SetSlot( SID_CURSORBLKDOWN );  break;
187 		case SID_CURSORUP_SEL:			rReq.SetSlot( SID_CURSORUP );  break;
188 		case SID_CURSORBLKUP_SEL:		rReq.SetSlot( SID_CURSORBLKUP );  break;
189 		case SID_CURSORLEFT_SEL:		rReq.SetSlot( SID_CURSORLEFT );  break;
190 		case SID_CURSORBLKLEFT_SEL:		rReq.SetSlot( SID_CURSORBLKLEFT );  break;
191 		case SID_CURSORRIGHT_SEL:		rReq.SetSlot( SID_CURSORRIGHT );  break;
192 		case SID_CURSORBLKRIGHT_SEL:	rReq.SetSlot( SID_CURSORBLKRIGHT );  break;
193 		case SID_CURSORPAGEDOWN_SEL:	rReq.SetSlot( SID_CURSORPAGEDOWN );  break;
194 		case SID_CURSORPAGEUP_SEL:		rReq.SetSlot( SID_CURSORPAGEUP );  break;
195 		case SID_CURSORPAGERIGHT_SEL:	rReq.SetSlot( SID_CURSORPAGERIGHT_ );  break;
196 		case SID_CURSORPAGELEFT_SEL:	rReq.SetSlot( SID_CURSORPAGELEFT_ );  break;
197 		default:
198 			DBG_ERROR("Unbekannte Message bei ViewShell (CursorSel)");
199 			return;
200 	}
201 	rReq.AppendItem( SfxInt16Item(FN_PARAM_1, nRepeat ) );
202 	rReq.AppendItem( SfxBoolItem(FN_PARAM_2, sal_True) );
203 	ExecuteSlot( rReq, GetInterface() );
204 }
205 
206 void ScCellShell::ExecuteMove( SfxRequest& rReq )
207 {
208 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
209 	sal_uInt16 nSlotId  = rReq.GetSlot();
210 
211 	if(nSlotId != SID_CURSORTOPOFSCREEN && nSlotId != SID_CURSORENDOFSCREEN)
212 		pTabViewShell->ExecuteInputDirect();
213 	switch ( nSlotId )
214 	{
215 		case SID_NEXT_TABLE:
216         case SID_NEXT_TABLE_SEL:
217             pTabViewShell->SelectNextTab( 1, (nSlotId == SID_NEXT_TABLE_SEL) );
218 			break;
219 
220 		case SID_PREV_TABLE:
221         case SID_PREV_TABLE_SEL:
222             pTabViewShell->SelectNextTab( -1, (nSlotId == SID_PREV_TABLE_SEL) );
223 			break;
224 
225 		//	Cursorbewegungen in Bloecken gehen nicht von Basic aus,
226 		//	weil das ScSbxRange-Objekt bei Eingaben die Markierung veraendert
227 
228 		case SID_NEXT_UNPROTECT:
229 			pTabViewShell->FindNextUnprot( sal_False, !rReq.IsAPI() );
230 			break;
231 
232 		case SID_PREV_UNPROTECT:
233 			pTabViewShell->FindNextUnprot( sal_True, !rReq.IsAPI() );
234 			break;
235 
236 		case SID_CURSORENTERUP:
237 			if (rReq.IsAPI())
238 				pTabViewShell->MoveCursorRel( 0, -1, SC_FOLLOW_LINE, sal_False );
239 			else
240 				pTabViewShell->MoveCursorEnter( sal_True );
241 			break;
242 
243 		case SID_CURSORENTERDOWN:
244 			if (rReq.IsAPI())
245 				pTabViewShell->MoveCursorRel( 0, 1, SC_FOLLOW_LINE, sal_False );
246 			else
247 				pTabViewShell->MoveCursorEnter( sal_False );
248 			break;
249 
250 		case SID_SELECT_COL:
251 			pTabViewShell->MarkColumns();
252 			break;
253 
254 		case SID_SELECT_ROW:
255 			pTabViewShell->MarkRows();
256 			break;
257 
258 		case SID_SELECT_NONE:
259 			pTabViewShell->Unmark();
260 			break;
261 
262 		case SID_ALIGNCURSOR:
263 			pTabViewShell->AlignToCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), SC_FOLLOW_JUMP );
264 			break;
265 
266 		case SID_MARKDATAAREA:
267 			pTabViewShell->MarkDataArea();
268 			break;
269 
270 		case SID_MARKARRAYFORMULA:
271 			pTabViewShell->MarkMatrixFormula();
272 			break;
273 
274 		case SID_SETINPUTMODE:
275 			SC_MOD()->SetInputMode( SC_INPUT_TABLE );
276 			break;
277 
278 		case SID_FOCUS_INPUTLINE:
279 			{
280 				ScInputHandler* pHdl = SC_MOD()->GetInputHdl( pTabViewShell );
281 				if (pHdl)
282 				{
283 					ScInputWindow* pWin = pHdl->GetInputWindow();
284 					if (pWin)
285 						pWin->SwitchToTextWin();
286 				}
287 			}
288 			break;
289 
290 		case SID_CURSORTOPOFSCREEN:
291 			pTabViewShell->MoveCursorScreen( 0, -1, SC_FOLLOW_LINE, sal_False );
292 			break;
293 
294 		case SID_CURSORENDOFSCREEN:
295 			pTabViewShell->MoveCursorScreen( 0, 1, SC_FOLLOW_LINE, sal_False );
296 			break;
297 
298 		default:
299 			DBG_ERROR("Unbekannte Message bei ViewShell (Cursor)");
300 			return;
301 	}
302 
303 	rReq.Done();
304 }
305 
306 void ScCellShell::ExecutePageSel( SfxRequest& rReq )
307 {
308 	sal_uInt16				nSlotId  = rReq.GetSlot();
309 	switch ( nSlotId )
310 	{
311 		case SID_CURSORHOME_SEL:		rReq.SetSlot( SID_CURSORHOME );  break;
312 		case SID_CURSOREND_SEL:			rReq.SetSlot( SID_CURSOREND );  break;
313 		case SID_CURSORTOPOFFILE_SEL:	rReq.SetSlot( SID_CURSORTOPOFFILE );  break;
314 		case SID_CURSORENDOFFILE_SEL:	rReq.SetSlot( SID_CURSORENDOFFILE );  break;
315 		default:
316 			DBG_ERROR("Unbekannte Message bei ViewShell (ExecutePageSel)");
317 			return;
318 	}
319 	rReq.AppendItem( SfxBoolItem(FN_PARAM_2, sal_True) );
320 	ExecuteSlot( rReq, GetInterface() );
321 }
322 
323 void ScCellShell::ExecutePage( SfxRequest& rReq )
324 {
325 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
326 	const SfxItemSet*	pReqArgs = rReq.GetArgs();
327 	sal_uInt16				nSlotId  = rReq.GetSlot();
328 	sal_Bool				bSel = sal_False;
329 	sal_Bool				bKeep = sal_False;
330 
331 	if ( pReqArgs != NULL )
332 	{
333 		const	SfxPoolItem* pItem;
334 		if( IS_AVAILABLE( FN_PARAM_2, &pItem ) )
335 			bSel = ((const SfxBoolItem*)pItem)->GetValue();
336 	}
337 	else
338 	{
339 		//	evaluate locked selection mode
340 
341 		sal_uInt16 nLocked = pTabViewShell->GetLockedModifiers();
342 		if ( nLocked & KEY_SHIFT )
343 			bSel = sal_True;				// EXT
344 		else if ( nLocked & KEY_MOD1 )
345 		{
346 			// ADD mode: keep the selection, start a new block when marking with shift again
347 			bKeep = sal_True;
348 			pTabViewShell->SetNewStartIfMarking();
349 		}
350 	}
351 
352 	pTabViewShell->ExecuteInputDirect();
353 	switch ( nSlotId )
354 	{
355 		case SID_CURSORHOME:
356 			pTabViewShell->MoveCursorEnd( -1, 0, SC_FOLLOW_LINE, bSel, bKeep );
357 			break;
358 
359 		case SID_CURSOREND:
360 			pTabViewShell->MoveCursorEnd( 1, 0, SC_FOLLOW_JUMP, bSel, bKeep );
361 			break;
362 
363 		case SID_CURSORTOPOFFILE:
364 			pTabViewShell->MoveCursorEnd( -1, -1, SC_FOLLOW_LINE, bSel, bKeep );
365 			break;
366 
367 		case SID_CURSORENDOFFILE:
368 			pTabViewShell->MoveCursorEnd( 1, 1, SC_FOLLOW_JUMP, bSel, bKeep );
369 			break;
370 
371 		default:
372 			DBG_ERROR("Unbekannte Message bei ViewShell (ExecutePage)");
373 			return;
374 	}
375 
376 	rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) );
377 	rReq.Done();
378 }
379 
380 
381 
382 
383