update dev300-m58
[ooovba.git] / sc / source / ui / view / cellsh4.cxx
blob88fb5e2424f4cdb998df3c8a2d0b2e93c57e2a4d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cellsh4.cxx,v $
10 * $Revision: 1.12 $
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 //------------------------------------------------------------------
38 #ifdef _MSC_VER
39 #pragma optimize ("", off)
40 #endif
42 // INCLUDE ---------------------------------------------------------------
44 #include <sfx2/request.hxx>
46 #include "cellsh.hxx"
47 #include "tabvwsh.hxx"
48 #include "global.hxx"
49 #include "scmod.hxx"
50 #include "inputhdl.hxx"
51 #include "inputwin.hxx"
52 #include "document.hxx"
53 #include "sc.hrc"
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;
70 BOOL bSel = FALSE;
71 BOOL bKeep = FALSE;
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();
81 else
83 // evaluate locked selection mode
85 USHORT nLocked = pTabViewShell->GetLockedModifiers();
86 if ( nLocked & KEY_SHIFT )
87 bSel = TRUE; // EXT
88 else if ( nLocked & KEY_MOD1 )
90 // ADD mode: keep the selection, start a new block when marking with shift again
91 bKeep = TRUE;
95 if (bSel)
97 switch (nSlotId)
99 case SID_CURSORDOWN:
100 rReq.SetSlot(SID_CURSORDOWN_SEL);
101 break;
102 case SID_CURSORUP:
103 rReq.SetSlot(SID_CURSORUP_SEL);
104 break;
105 case SID_CURSORRIGHT:
106 rReq.SetSlot(SID_CURSORRIGHT_SEL);
107 break;
108 case SID_CURSORLEFT:
109 rReq.SetSlot(SID_CURSORLEFT_SEL);
110 break;
111 case SID_CURSORPAGEDOWN:
112 rReq.SetSlot(SID_CURSORPAGEDOWN_SEL);
113 break;
114 case SID_CURSORPAGEUP:
115 rReq.SetSlot(SID_CURSORPAGEUP_SEL);
116 break;
117 case SID_CURSORPAGERIGHT:
118 rReq.SetSlot(SID_CURSORPAGERIGHT_SEL);
119 break;
120 case SID_CURSORPAGELEFT:
121 rReq.SetSlot(SID_CURSORPAGELEFT_SEL);
122 break;
123 case SID_CURSORBLKDOWN:
124 rReq.SetSlot(SID_CURSORBLKDOWN_SEL);
125 break;
126 case SID_CURSORBLKUP:
127 rReq.SetSlot(SID_CURSORBLKUP_SEL);
128 break;
129 case SID_CURSORBLKRIGHT:
130 rReq.SetSlot(SID_CURSORBLKRIGHT_SEL);
131 break;
132 case SID_CURSORBLKLEFT:
133 rReq.SetSlot(SID_CURSORBLKLEFT_SEL);
134 break;
135 default:
138 ExecuteCursorSel(rReq);
139 return;
142 SCsCOLROW nRTLSign = 1;
143 if ( pData->GetDocument()->IsLayoutRTL( pData->GetTabNo() ) )
145 //! evaluate cursor movement option?
146 nRTLSign = -1;
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();
154 switch ( nSlotId )
156 case SID_CURSORDOWN:
157 pTabViewShell->MoveCursorRel( 0, nRepeat, SC_FOLLOW_LINE, bSel, bKeep );
158 break;
160 case SID_CURSORBLKDOWN:
161 pTabViewShell->MoveCursorArea( 0, nRepeat, SC_FOLLOW_JUMP, bSel, bKeep );
162 break;
164 case SID_CURSORUP:
165 pTabViewShell->MoveCursorRel( 0, -nRepeat, SC_FOLLOW_LINE, bSel, bKeep );
166 break;
168 case SID_CURSORBLKUP:
169 pTabViewShell->MoveCursorArea( 0, -nRepeat, SC_FOLLOW_JUMP, bSel, bKeep );
170 break;
172 case SID_CURSORLEFT:
173 pTabViewShell->MoveCursorRel( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep );
174 break;
176 case SID_CURSORBLKLEFT:
177 pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
178 break;
180 case SID_CURSORRIGHT:
181 pTabViewShell->MoveCursorRel( static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep );
182 break;
184 case SID_CURSORBLKRIGHT:
185 pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
186 break;
188 case SID_CURSORPAGEDOWN:
189 pTabViewShell->MoveCursorPage( 0, nRepeat, SC_FOLLOW_FIX, bSel, bKeep );
190 break;
192 case SID_CURSORPAGEUP:
193 pTabViewShell->MoveCursorPage( 0, -nRepeat, SC_FOLLOW_FIX, bSel, bKeep );
194 break;
196 case SID_CURSORPAGERIGHT_: //XXX !!!
197 pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep );
198 break;
200 case SID_CURSORPAGELEFT_: //XXX !!!
201 pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(-nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep );
202 break;
204 default:
205 DBG_ERROR("Unbekannte Message bei ViewShell (Cursor)");
206 return;
209 pTabViewShell->ShowAllCursors();
211 rReq.AppendItem( SfxInt16Item(FN_PARAM_1, static_cast<sal_Int16>(nRepeat)) );
212 rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) );
213 rReq.Done();
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;
235 switch (nSlotId)
237 case SID_CURSORDOWN_SEL:
238 pViewShell->ExpandBlock(0, 1, SC_FOLLOW_LINE);
239 break;
240 case SID_CURSORUP_SEL:
241 pViewShell->ExpandBlock(0, -1, SC_FOLLOW_LINE);
242 break;
243 case SID_CURSORRIGHT_SEL:
244 pViewShell->ExpandBlock(nMovX, 0, SC_FOLLOW_LINE);
245 break;
246 case SID_CURSORLEFT_SEL:
247 pViewShell->ExpandBlock(-nMovX, 0, SC_FOLLOW_LINE);
248 break;
249 case SID_CURSORPAGEUP_SEL:
250 pViewShell->ExpandBlockPage(0, -1);
251 break;
252 case SID_CURSORPAGEDOWN_SEL:
253 pViewShell->ExpandBlockPage(0, 1);
254 break;
255 case SID_CURSORPAGERIGHT_SEL:
256 pViewShell->ExpandBlockPage(nMovX, 0);
257 break;
258 case SID_CURSORPAGELEFT_SEL:
259 pViewShell->ExpandBlockPage(-nMovX, 0);
260 break;
261 case SID_CURSORBLKDOWN_SEL:
262 pViewShell->ExpandBlockArea(0, 1);
263 break;
264 case SID_CURSORBLKUP_SEL:
265 pViewShell->ExpandBlockArea(0, -1);
266 break;
267 case SID_CURSORBLKRIGHT_SEL:
268 pViewShell->ExpandBlockArea(nMovX, 0);
269 break;
270 case SID_CURSORBLKLEFT_SEL:
271 pViewShell->ExpandBlockArea(-nMovX, 0);
272 break;
273 default:
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();
286 switch ( nSlotId )
288 case SID_NEXT_TABLE:
289 case SID_NEXT_TABLE_SEL:
290 pTabViewShell->SelectNextTab( 1, (nSlotId == SID_NEXT_TABLE_SEL) );
291 break;
293 case SID_PREV_TABLE:
294 case SID_PREV_TABLE_SEL:
295 pTabViewShell->SelectNextTab( -1, (nSlotId == SID_PREV_TABLE_SEL) );
296 break;
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() );
303 break;
305 case SID_PREV_UNPROTECT:
306 pTabViewShell->FindNextUnprot( TRUE, !rReq.IsAPI() );
307 break;
309 case SID_CURSORENTERUP:
310 if (rReq.IsAPI())
311 pTabViewShell->MoveCursorRel( 0, -1, SC_FOLLOW_LINE, FALSE );
312 else
313 pTabViewShell->MoveCursorEnter( TRUE );
314 break;
316 case SID_CURSORENTERDOWN:
317 if (rReq.IsAPI())
318 pTabViewShell->MoveCursorRel( 0, 1, SC_FOLLOW_LINE, FALSE );
319 else
320 pTabViewShell->MoveCursorEnter( FALSE );
321 break;
323 case SID_SELECT_COL:
324 pTabViewShell->MarkColumns();
325 break;
327 case SID_SELECT_ROW:
328 pTabViewShell->MarkRows();
329 break;
331 case SID_SELECT_NONE:
332 pTabViewShell->Unmark();
333 break;
335 case SID_ALIGNCURSOR:
336 pTabViewShell->AlignToCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), SC_FOLLOW_JUMP );
337 break;
339 case SID_MARKDATAAREA:
340 pTabViewShell->MarkDataArea();
341 break;
343 case SID_MARKARRAYFORMULA:
344 pTabViewShell->MarkMatrixFormula();
345 break;
347 case SID_SETINPUTMODE:
348 SC_MOD()->SetInputMode( SC_INPUT_TABLE );
349 break;
351 case SID_FOCUS_INPUTLINE:
353 ScInputHandler* pHdl = SC_MOD()->GetInputHdl( pTabViewShell );
354 if (pHdl)
356 ScInputWindow* pWin = pHdl->GetInputWindow();
357 if (pWin)
358 pWin->SwitchToTextWin();
361 break;
363 case SID_CURSORTOPOFSCREEN:
364 pTabViewShell->MoveCursorScreen( 0, -1, SC_FOLLOW_LINE, FALSE );
365 break;
367 case SID_CURSORENDOFSCREEN:
368 pTabViewShell->MoveCursorScreen( 0, 1, SC_FOLLOW_LINE, FALSE );
369 break;
371 default:
372 DBG_ERROR("Unbekannte Message bei ViewShell (Cursor)");
373 return;
376 rReq.Done();
379 void ScCellShell::ExecutePageSel( SfxRequest& rReq )
381 USHORT nSlotId = rReq.GetSlot();
382 switch ( nSlotId )
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;
388 default:
389 DBG_ERROR("Unbekannte Message bei ViewShell (ExecutePageSel)");
390 return;
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();
401 BOOL bSel = FALSE;
402 BOOL bKeep = FALSE;
404 if ( pReqArgs != NULL )
406 const SfxPoolItem* pItem;
407 if( IS_AVAILABLE( FN_PARAM_2, &pItem ) )
408 bSel = ((const SfxBoolItem*)pItem)->GetValue();
410 else
412 // evaluate locked selection mode
414 USHORT nLocked = pTabViewShell->GetLockedModifiers();
415 if ( nLocked & KEY_SHIFT )
416 bSel = TRUE; // EXT
417 else if ( nLocked & KEY_MOD1 )
419 // ADD mode: keep the selection, start a new block when marking with shift again
420 bKeep = TRUE;
424 pTabViewShell->ExecuteInputDirect();
425 switch ( nSlotId )
427 case SID_CURSORHOME:
428 pTabViewShell->MoveCursorEnd( -1, 0, SC_FOLLOW_LINE, bSel, bKeep );
429 break;
431 case SID_CURSOREND:
432 pTabViewShell->MoveCursorEnd( 1, 0, SC_FOLLOW_JUMP, bSel, bKeep );
433 break;
435 case SID_CURSORTOPOFFILE:
436 pTabViewShell->MoveCursorEnd( -1, -1, SC_FOLLOW_LINE, bSel, bKeep );
437 break;
439 case SID_CURSORENDOFFILE:
440 pTabViewShell->MoveCursorEnd( 1, 1, SC_FOLLOW_JUMP, bSel, bKeep );
441 break;
443 default:
444 DBG_ERROR("Unbekannte Message bei ViewShell (ExecutePage)");
445 return;
448 rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) );
449 rReq.Done();