fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / cellsh4.cxx
blob0cd2a9fd64f76d95cc3cbb93b572705d268a13ef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <sfx2/request.hxx>
22 #include "cellsh.hxx"
23 #include "tabvwsh.hxx"
24 #include "global.hxx"
25 #include "scmod.hxx"
26 #include "inputhdl.hxx"
27 #include "inputwin.hxx"
28 #include "document.hxx"
29 #include "sc.hrc"
31 #include <vcl/svapp.hxx>
33 void ScCellShell::ExecuteCursor( SfxRequest& rReq )
35 ScViewData* pData = GetViewData();
36 ScTabViewShell* pTabViewShell = pData->GetViewShell();
37 const SfxItemSet* pReqArgs = rReq.GetArgs();
38 sal_uInt16 nSlotId = rReq.GetSlot();
39 SCsCOLROW nRepeat = 1;
40 bool bSel = false;
41 bool bKeep = false;
43 if ( pReqArgs != NULL )
45 const SfxPoolItem* pItem;
46 if (pReqArgs->HasItem(FN_PARAM_1, &pItem))
47 nRepeat = static_cast<SCsCOLROW>(static_cast<const SfxInt16Item*>(pItem)->GetValue());
48 if (pReqArgs->HasItem(FN_PARAM_2, &pItem))
49 bSel = static_cast<const SfxBoolItem*>(pItem)->GetValue();
51 else
53 // evaluate locked selection mode
55 sal_uInt16 nLocked = pTabViewShell->GetLockedModifiers();
56 if ( nLocked & KEY_SHIFT )
57 bSel = true; // EXT
58 else if ( nLocked & KEY_MOD1 )
60 // ADD mode: keep the selection, start a new block when marking with shift again
61 bKeep = true;
65 if (bSel)
67 switch (nSlotId)
69 case SID_CURSORDOWN:
70 rReq.SetSlot(SID_CURSORDOWN_SEL);
71 break;
72 case SID_CURSORUP:
73 rReq.SetSlot(SID_CURSORUP_SEL);
74 break;
75 case SID_CURSORRIGHT:
76 rReq.SetSlot(SID_CURSORRIGHT_SEL);
77 break;
78 case SID_CURSORLEFT:
79 rReq.SetSlot(SID_CURSORLEFT_SEL);
80 break;
81 case SID_CURSORPAGEDOWN:
82 rReq.SetSlot(SID_CURSORPAGEDOWN_SEL);
83 break;
84 case SID_CURSORPAGEUP:
85 rReq.SetSlot(SID_CURSORPAGEUP_SEL);
86 break;
87 case SID_CURSORPAGERIGHT:
88 rReq.SetSlot(SID_CURSORPAGERIGHT_SEL);
89 break;
90 case SID_CURSORPAGELEFT:
91 rReq.SetSlot(SID_CURSORPAGELEFT_SEL);
92 break;
93 case SID_CURSORBLKDOWN:
94 rReq.SetSlot(SID_CURSORBLKDOWN_SEL);
95 break;
96 case SID_CURSORBLKUP:
97 rReq.SetSlot(SID_CURSORBLKUP_SEL);
98 break;
99 case SID_CURSORBLKRIGHT:
100 rReq.SetSlot(SID_CURSORBLKRIGHT_SEL);
101 break;
102 case SID_CURSORBLKLEFT:
103 rReq.SetSlot(SID_CURSORBLKLEFT_SEL);
104 break;
105 default:
108 ExecuteCursorSel(rReq);
109 return;
112 SCsCOLROW nRTLSign = 1;
113 if ( pData->GetDocument()->IsLayoutRTL( pData->GetTabNo() ) )
115 //! evaluate cursor movement option?
116 nRTLSign = -1;
119 // once extra, so that the cursor will not be painted too often with ExecuteInputDirect:
120 pTabViewShell->HideAllCursors();
122 // #i123629#
123 if( pTabViewShell->GetCurObjectSelectionType() == OST_Editing )
124 pTabViewShell->SetForceFocusOnCurCell(true);
125 else
126 pTabViewShell->SetForceFocusOnCurCell(false);
128 //OS: once for all should do, however!
129 pTabViewShell->ExecuteInputDirect();
130 switch ( nSlotId )
132 case SID_CURSORDOWN:
133 pTabViewShell->MoveCursorRel( 0, nRepeat, SC_FOLLOW_LINE, bSel, bKeep );
134 break;
136 case SID_CURSORBLKDOWN:
137 pTabViewShell->MoveCursorArea( 0, nRepeat, SC_FOLLOW_JUMP, bSel, bKeep );
138 break;
140 case SID_CURSORUP:
141 pTabViewShell->MoveCursorRel( 0, -nRepeat, SC_FOLLOW_LINE, bSel, bKeep );
142 break;
144 case SID_CURSORBLKUP:
145 pTabViewShell->MoveCursorArea( 0, -nRepeat, SC_FOLLOW_JUMP, bSel, bKeep );
146 break;
148 case SID_CURSORLEFT:
149 pTabViewShell->MoveCursorRel( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep );
150 break;
152 case SID_CURSORBLKLEFT:
153 pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
154 break;
156 case SID_CURSORRIGHT:
157 pTabViewShell->MoveCursorRel( static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep );
158 break;
160 case SID_CURSORBLKRIGHT:
161 pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
162 break;
164 case SID_CURSORPAGEDOWN:
165 pTabViewShell->MoveCursorPage( 0, nRepeat, SC_FOLLOW_FIX, bSel, bKeep );
166 break;
168 case SID_CURSORPAGEUP:
169 pTabViewShell->MoveCursorPage( 0, -nRepeat, SC_FOLLOW_FIX, bSel, bKeep );
170 break;
172 case SID_CURSORPAGERIGHT_: //XXX !!!
173 pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep );
174 break;
176 case SID_CURSORPAGELEFT_: //XXX !!!
177 pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(-nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep );
178 break;
180 default:
181 OSL_FAIL("Unknown message in ViewShell (Cursor)");
182 return;
185 pTabViewShell->ShowAllCursors();
187 rReq.AppendItem( SfxInt16Item(FN_PARAM_1, static_cast<sal_Int16>(nRepeat)) );
188 rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) );
189 rReq.Done();
192 void ScCellShell::GetStateCursor( SfxItemSet& /* rSet */ )
196 void ScCellShell::ExecuteCursorSel( SfxRequest& rReq )
198 sal_uInt16 nSlotId = rReq.GetSlot();
199 ScTabViewShell* pViewShell = GetViewData()->GetViewShell();
200 ScInputHandler* pInputHdl = pViewShell->GetInputHandler();
201 pViewShell->HideAllCursors();
202 if (pInputHdl && pInputHdl->IsInputMode())
204 // the current cell is in edit mode. Commit the text before moving on.
205 pViewShell->ExecuteInputDirect();
208 SCsCOLROW nRepeat = 1;
209 const SfxItemSet* pReqArgs = rReq.GetArgs();
210 // get repetition
211 if ( pReqArgs != NULL )
213 const SfxPoolItem* pItem;
214 if (pReqArgs->HasItem(FN_PARAM_1, &pItem))
215 nRepeat = static_cast<SCsCOLROW>(static_cast<const SfxInt16Item*>(pItem)->GetValue());
218 SCsROW nMovY = nRepeat;
219 // Horizontal direction depends on whether or not the UI language is RTL.
220 SCsCOL nMovX = nRepeat;
221 if (GetViewData()->GetDocument()->IsLayoutRTL(GetViewData()->GetTabNo()))
223 // mirror horizontal movement for right-to-left mode.
224 nMovX = -nRepeat;
227 switch (nSlotId)
229 case SID_CURSORDOWN_SEL:
230 pViewShell->ExpandBlock(0, nMovY, SC_FOLLOW_LINE);
231 break;
232 case SID_CURSORUP_SEL:
233 pViewShell->ExpandBlock(0, -nMovY, SC_FOLLOW_LINE);
234 break;
235 case SID_CURSORRIGHT_SEL:
236 pViewShell->ExpandBlock(nMovX, 0, SC_FOLLOW_LINE);
237 break;
238 case SID_CURSORLEFT_SEL:
239 pViewShell->ExpandBlock(-nMovX, 0, SC_FOLLOW_LINE);
240 break;
241 case SID_CURSORPAGEUP_SEL:
242 pViewShell->ExpandBlockPage(0, -nMovY);
243 break;
244 case SID_CURSORPAGEDOWN_SEL:
245 pViewShell->ExpandBlockPage(0, nMovY);
246 break;
247 case SID_CURSORPAGERIGHT_SEL:
248 pViewShell->ExpandBlockPage(nMovX, 0);
249 break;
250 case SID_CURSORPAGELEFT_SEL:
251 pViewShell->ExpandBlockPage(-nMovX, 0);
252 break;
253 case SID_CURSORBLKDOWN_SEL:
254 pViewShell->ExpandBlockArea(0, nMovY);
255 break;
256 case SID_CURSORBLKUP_SEL:
257 pViewShell->ExpandBlockArea(0, -nMovY);
258 break;
259 case SID_CURSORBLKRIGHT_SEL:
260 pViewShell->ExpandBlockArea(nMovX , 0);
261 break;
262 case SID_CURSORBLKLEFT_SEL:
263 pViewShell->ExpandBlockArea(-nMovX, 0);
264 break;
265 default:
268 pViewShell->ShowAllCursors();
270 rReq.AppendItem( SfxInt16Item(FN_PARAM_1,static_cast<sal_Int16>(nRepeat)) );
271 rReq.Done();
274 void ScCellShell::ExecuteMove( SfxRequest& rReq )
276 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
277 sal_uInt16 nSlotId = rReq.GetSlot();
279 if(nSlotId != SID_CURSORTOPOFSCREEN && nSlotId != SID_CURSORENDOFSCREEN)
280 pTabViewShell->ExecuteInputDirect();
281 switch ( nSlotId )
283 case SID_NEXT_TABLE:
284 case SID_NEXT_TABLE_SEL:
285 pTabViewShell->SelectNextTab( 1, (nSlotId == SID_NEXT_TABLE_SEL) );
286 break;
288 case SID_PREV_TABLE:
289 case SID_PREV_TABLE_SEL:
290 pTabViewShell->SelectNextTab( -1, (nSlotId == SID_PREV_TABLE_SEL) );
291 break;
293 // cursor movements in range do not originate from Basic,
294 // because the ScSbxRange-object changes the marking at input
296 case SID_NEXT_UNPROTECT:
297 pTabViewShell->FindNextUnprot( false, !rReq.IsAPI() );
298 break;
300 case SID_PREV_UNPROTECT:
301 pTabViewShell->FindNextUnprot( true, !rReq.IsAPI() );
302 break;
304 case SID_CURSORENTERUP:
305 if (rReq.IsAPI())
306 pTabViewShell->MoveCursorRel( 0, -1, SC_FOLLOW_LINE, false );
307 else
308 pTabViewShell->MoveCursorEnter( true );
309 break;
311 case SID_CURSORENTERDOWN:
312 if (rReq.IsAPI())
313 pTabViewShell->MoveCursorRel( 0, 1, SC_FOLLOW_LINE, false );
314 else
315 pTabViewShell->MoveCursorEnter( false );
316 break;
318 case SID_SELECT_COL:
319 pTabViewShell->MarkColumns();
320 break;
322 case SID_SELECT_ROW:
323 pTabViewShell->MarkRows();
324 break;
326 case SID_SELECT_NONE:
327 pTabViewShell->Unmark();
328 break;
330 case SID_ALIGNCURSOR:
331 pTabViewShell->AlignToCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), SC_FOLLOW_JUMP );
332 break;
334 case SID_MARKDATAAREA:
335 pTabViewShell->MarkDataArea();
336 break;
338 case SID_MARKARRAYFORMULA:
339 pTabViewShell->MarkMatrixFormula();
340 break;
342 case SID_SETINPUTMODE:
343 SC_MOD()->SetInputMode( SC_INPUT_TABLE );
344 break;
346 case SID_FOCUS_INPUTLINE:
348 ScInputHandler* pHdl = SC_MOD()->GetInputHdl( pTabViewShell );
349 if (pHdl)
351 ScInputWindow* pWin = pHdl->GetInputWindow();
352 if (pWin)
353 pWin->SwitchToTextWin();
356 break;
358 case SID_CURSORTOPOFSCREEN:
359 pTabViewShell->MoveCursorScreen( 0, -1, SC_FOLLOW_LINE, false );
360 break;
362 case SID_CURSORENDOFSCREEN:
363 pTabViewShell->MoveCursorScreen( 0, 1, SC_FOLLOW_LINE, false );
364 break;
366 default:
367 OSL_FAIL("Unknown message in ViewShell (Cursor)");
368 return;
371 rReq.Done();
374 void ScCellShell::ExecutePageSel( SfxRequest& rReq )
376 sal_uInt16 nSlotId = rReq.GetSlot();
377 switch ( nSlotId )
379 case SID_CURSORHOME_SEL: rReq.SetSlot( SID_CURSORHOME ); break;
380 case SID_CURSOREND_SEL: rReq.SetSlot( SID_CURSOREND ); break;
381 case SID_CURSORTOPOFFILE_SEL: rReq.SetSlot( SID_CURSORTOPOFFILE ); break;
382 case SID_CURSORENDOFFILE_SEL: rReq.SetSlot( SID_CURSORENDOFFILE ); break;
383 default:
384 OSL_FAIL("Unknown message in ViewShell (ExecutePageSel)");
385 return;
387 rReq.AppendItem( SfxBoolItem(FN_PARAM_2, true) );
388 ExecuteSlot( rReq, GetInterface() );
391 void ScCellShell::ExecutePage( SfxRequest& rReq )
393 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
394 const SfxItemSet* pReqArgs = rReq.GetArgs();
395 sal_uInt16 nSlotId = rReq.GetSlot();
396 bool bSel = false;
397 bool bKeep = false;
399 if ( pReqArgs != NULL )
401 const SfxPoolItem* pItem;
402 if (pReqArgs->HasItem(FN_PARAM_2, &pItem))
403 bSel = static_cast<const SfxBoolItem*>(pItem)->GetValue();
405 else
407 // evaluate locked selection mode
409 sal_uInt16 nLocked = pTabViewShell->GetLockedModifiers();
410 if ( nLocked & KEY_SHIFT )
411 bSel = true; // EXT
412 else if ( nLocked & KEY_MOD1 )
414 // ADD mode: keep the selection, start a new block when marking with shift again
415 bKeep = true;
419 pTabViewShell->ExecuteInputDirect();
420 switch ( nSlotId )
422 case SID_CURSORHOME:
423 pTabViewShell->MoveCursorEnd( -1, 0, SC_FOLLOW_LINE, bSel, bKeep );
424 break;
426 case SID_CURSOREND:
427 pTabViewShell->MoveCursorEnd( 1, 0, SC_FOLLOW_JUMP, bSel, bKeep );
428 break;
430 case SID_CURSORTOPOFFILE:
431 pTabViewShell->MoveCursorEnd( -1, -1, SC_FOLLOW_LINE, bSel, bKeep );
432 break;
434 case SID_CURSORENDOFFILE:
435 pTabViewShell->MoveCursorEnd( 1, 1, SC_FOLLOW_JUMP, bSel, bKeep );
436 break;
438 default:
439 OSL_FAIL("Unknown message in ViewShell (ExecutePage)");
440 return;
443 rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) );
444 rReq.Done();
447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */