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