LCOV - code coverage report
Current view: top level - sc/source/ui/view - cellsh4.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 57 217 26.3 %
Date: 2014-11-03 Functions: 5 8 62.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <sfx2/request.hxx>
      21             : 
      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"
      30             : 
      31             : #include <vcl/svapp.hxx>
      32             : 
      33          22 : void ScCellShell::ExecuteCursor( SfxRequest& rReq )
      34             : {
      35          22 :     ScViewData* pData = GetViewData();
      36          22 :     ScTabViewShell* pTabViewShell   = pData->GetViewShell();
      37          22 :     const SfxItemSet*   pReqArgs = rReq.GetArgs();
      38          22 :     sal_uInt16              nSlotId  = rReq.GetSlot();
      39          22 :     SCsCOLROW           nRepeat = 1;
      40          22 :     bool                bSel = false;
      41          22 :     bool                bKeep = false;
      42             : 
      43          22 :     if ( pReqArgs != NULL )
      44             :     {
      45             :         const   SfxPoolItem* pItem;
      46          22 :         if (pReqArgs->HasItem(FN_PARAM_1, &pItem))
      47           0 :             nRepeat = static_cast<SCsCOLROW>(static_cast<const SfxInt16Item*>(pItem)->GetValue());
      48          22 :         if (pReqArgs->HasItem(FN_PARAM_2, &pItem))
      49           0 :             bSel = static_cast<const SfxBoolItem*>(pItem)->GetValue();
      50             :     }
      51             :     else
      52             :     {
      53             :         //  evaluate locked selection mode
      54             : 
      55           0 :         sal_uInt16 nLocked = pTabViewShell->GetLockedModifiers();
      56           0 :         if ( nLocked & KEY_SHIFT )
      57           0 :             bSel = true;                // EXT
      58           0 :         else if ( nLocked & KEY_MOD1 )
      59             :         {
      60             :             // ADD mode: keep the selection, start a new block when marking with shift again
      61           0 :             bKeep = true;
      62             :         }
      63             :     }
      64             : 
      65          22 :     if (bSel)
      66             :     {
      67           0 :         switch (nSlotId)
      68             :         {
      69             :             case SID_CURSORDOWN:
      70           0 :                 rReq.SetSlot(SID_CURSORDOWN_SEL);
      71           0 :             break;
      72             :             case SID_CURSORUP:
      73           0 :                 rReq.SetSlot(SID_CURSORUP_SEL);
      74           0 :             break;
      75             :             case SID_CURSORRIGHT:
      76           0 :                 rReq.SetSlot(SID_CURSORRIGHT_SEL);
      77           0 :             break;
      78             :             case SID_CURSORLEFT:
      79           0 :                 rReq.SetSlot(SID_CURSORLEFT_SEL);
      80           0 :             break;
      81             :             case SID_CURSORPAGEDOWN:
      82           0 :                 rReq.SetSlot(SID_CURSORPAGEDOWN_SEL);
      83           0 :             break;
      84             :             case SID_CURSORPAGEUP:
      85           0 :                 rReq.SetSlot(SID_CURSORPAGEUP_SEL);
      86           0 :             break;
      87             :             case SID_CURSORPAGERIGHT:
      88           0 :                 rReq.SetSlot(SID_CURSORPAGERIGHT_SEL);
      89           0 :             break;
      90             :             case SID_CURSORPAGELEFT:
      91           0 :                 rReq.SetSlot(SID_CURSORPAGELEFT_SEL);
      92           0 :             break;
      93             :             case SID_CURSORBLKDOWN:
      94           0 :                 rReq.SetSlot(SID_CURSORBLKDOWN_SEL);
      95           0 :             break;
      96             :             case SID_CURSORBLKUP:
      97           0 :                 rReq.SetSlot(SID_CURSORBLKUP_SEL);
      98           0 :             break;
      99             :             case SID_CURSORBLKRIGHT:
     100           0 :                 rReq.SetSlot(SID_CURSORBLKRIGHT_SEL);
     101           0 :             break;
     102             :             case SID_CURSORBLKLEFT:
     103           0 :                 rReq.SetSlot(SID_CURSORBLKLEFT_SEL);
     104           0 :             break;
     105             :             default:
     106             :                 ;
     107             :         }
     108           0 :         ExecuteCursorSel(rReq);
     109           0 :         return;
     110             :     }
     111             : 
     112          22 :     SCsCOLROW nRTLSign = 1;
     113          22 :     if ( pData->GetDocument()->IsLayoutRTL( pData->GetTabNo() ) )
     114             :     {
     115             :         //! evaluate cursor movement option?
     116           0 :         nRTLSign = -1;
     117             :     }
     118             : 
     119             :     // once extra, so that the cursor will not be painted too often with ExecuteInputDirect:
     120          22 :     pTabViewShell->HideAllCursors();
     121             : 
     122             :     // #i123629#
     123          22 :     if( pTabViewShell->GetCurObjectSelectionType() == OST_Editing )
     124           0 :         pTabViewShell->SetForceFocusOnCurCell(true);
     125             :     else
     126          22 :         pTabViewShell->SetForceFocusOnCurCell(false);
     127             : 
     128             :     //OS: once for all should do, however!
     129          22 :     pTabViewShell->ExecuteInputDirect();
     130          22 :     switch ( nSlotId )
     131             :     {
     132             :         case SID_CURSORDOWN:
     133           0 :             pTabViewShell->MoveCursorRel(   0,  nRepeat, SC_FOLLOW_LINE, bSel, bKeep );
     134           0 :             break;
     135             : 
     136             :         case SID_CURSORBLKDOWN:
     137           4 :             pTabViewShell->MoveCursorArea( 0, nRepeat, SC_FOLLOW_JUMP, bSel, bKeep );
     138           4 :             break;
     139             : 
     140             :         case SID_CURSORUP:
     141           0 :             pTabViewShell->MoveCursorRel(   0,  -nRepeat, SC_FOLLOW_LINE, bSel, bKeep );
     142           0 :             break;
     143             : 
     144             :         case SID_CURSORBLKUP:
     145           6 :             pTabViewShell->MoveCursorArea( 0, -nRepeat, SC_FOLLOW_JUMP, bSel, bKeep );
     146           6 :             break;
     147             : 
     148             :         case SID_CURSORLEFT:
     149           0 :             pTabViewShell->MoveCursorRel( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep );
     150           0 :             break;
     151             : 
     152             :         case SID_CURSORBLKLEFT:
     153           6 :             pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(-nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
     154           6 :             break;
     155             : 
     156             :         case SID_CURSORRIGHT:
     157           0 :             pTabViewShell->MoveCursorRel(   static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_LINE, bSel, bKeep );
     158           0 :             break;
     159             : 
     160             :         case SID_CURSORBLKRIGHT:
     161           6 :             pTabViewShell->MoveCursorArea( static_cast<SCsCOL>(nRepeat * nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
     162           6 :             break;
     163             : 
     164             :         case SID_CURSORPAGEDOWN:
     165           0 :             pTabViewShell->MoveCursorPage(  0, nRepeat, SC_FOLLOW_FIX, bSel, bKeep );
     166           0 :             break;
     167             : 
     168             :         case SID_CURSORPAGEUP:
     169           0 :             pTabViewShell->MoveCursorPage(  0, -nRepeat, SC_FOLLOW_FIX, bSel, bKeep );
     170           0 :             break;
     171             : 
     172             :         case SID_CURSORPAGERIGHT_: //XXX !!!
     173           0 :             pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep );
     174           0 :             break;
     175             : 
     176             :         case SID_CURSORPAGELEFT_: //XXX !!!
     177           0 :             pTabViewShell->MoveCursorPage( static_cast<SCsCOL>(-nRepeat), 0, SC_FOLLOW_FIX, bSel, bKeep );
     178           0 :             break;
     179             : 
     180             :         default:
     181             :             OSL_FAIL("Unknown message in ViewShell (Cursor)");
     182           0 :             return;
     183             :     }
     184             : 
     185          22 :     pTabViewShell->ShowAllCursors();
     186             : 
     187          22 :     rReq.AppendItem( SfxInt16Item(FN_PARAM_1, static_cast<sal_Int16>(nRepeat)) );
     188          22 :     rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) );
     189          22 :     rReq.Done();
     190             : }
     191             : 
     192          26 : void ScCellShell::GetStateCursor( SfxItemSet& /* rSet */ )
     193             : {
     194          26 : }
     195             : 
     196           4 : void ScCellShell::ExecuteCursorSel( SfxRequest& rReq )
     197             : {
     198           4 :     sal_uInt16 nSlotId  = rReq.GetSlot();
     199           4 :     ScTabViewShell* pViewShell = GetViewData()->GetViewShell();
     200           4 :     ScInputHandler* pInputHdl = pViewShell->GetInputHandler();
     201           4 :     pViewShell->HideAllCursors();
     202           4 :     if (pInputHdl && pInputHdl->IsInputMode())
     203             :     {
     204             :         // the current cell is in edit mode.  Commit the text before moving on.
     205           0 :         pViewShell->ExecuteInputDirect();
     206             :     }
     207             : 
     208           4 :     SCsCOLROW nRepeat = 1;
     209           4 :     const SfxItemSet* pReqArgs = rReq.GetArgs();
     210             :     // get repetition
     211           4 :     if ( pReqArgs != NULL )
     212             :     {
     213             :         const SfxPoolItem* pItem;
     214           4 :         if (pReqArgs->HasItem(FN_PARAM_1, &pItem))
     215           4 :             nRepeat = static_cast<SCsCOLROW>(static_cast<const SfxInt16Item*>(pItem)->GetValue());
     216             :     }
     217             : 
     218           4 :     SCsROW nMovY = nRepeat;
     219             :     // Horizontal direction depends on whether or not the UI language is RTL.
     220           4 :     SCsCOL nMovX = nRepeat;
     221           4 :     if (GetViewData()->GetDocument()->IsLayoutRTL(GetViewData()->GetTabNo()))
     222             :     {
     223             :         // mirror horizontal movement for right-to-left mode.
     224           0 :         nMovX = -nRepeat;
     225             :     }
     226             : 
     227           4 :     switch (nSlotId)
     228             :     {
     229             :         case SID_CURSORDOWN_SEL:
     230           2 :             pViewShell->ExpandBlock(0, nMovY, SC_FOLLOW_LINE);
     231           2 :         break;
     232             :         case SID_CURSORUP_SEL:
     233           0 :             pViewShell->ExpandBlock(0, -nMovY, SC_FOLLOW_LINE);
     234           0 :         break;
     235             :         case SID_CURSORRIGHT_SEL:
     236           2 :             pViewShell->ExpandBlock(nMovX, 0, SC_FOLLOW_LINE);
     237           2 :         break;
     238             :         case SID_CURSORLEFT_SEL:
     239           0 :             pViewShell->ExpandBlock(-nMovX, 0, SC_FOLLOW_LINE);
     240           0 :         break;
     241             :         case SID_CURSORPAGEUP_SEL:
     242           0 :             pViewShell->ExpandBlockPage(0, -nMovY);
     243           0 :         break;
     244             :         case SID_CURSORPAGEDOWN_SEL:
     245           0 :             pViewShell->ExpandBlockPage(0, nMovY);
     246           0 :         break;
     247             :         case SID_CURSORPAGERIGHT_SEL:
     248           0 :             pViewShell->ExpandBlockPage(nMovX, 0);
     249           0 :         break;
     250             :         case SID_CURSORPAGELEFT_SEL:
     251           0 :             pViewShell->ExpandBlockPage(-nMovX, 0);
     252           0 :         break;
     253             :         case SID_CURSORBLKDOWN_SEL:
     254           0 :             pViewShell->ExpandBlockArea(0, nMovY);
     255           0 :         break;
     256             :         case SID_CURSORBLKUP_SEL:
     257           0 :             pViewShell->ExpandBlockArea(0, -nMovY);
     258           0 :         break;
     259             :         case SID_CURSORBLKRIGHT_SEL:
     260           0 :             pViewShell->ExpandBlockArea(nMovX , 0);
     261           0 :         break;
     262             :         case SID_CURSORBLKLEFT_SEL:
     263           0 :             pViewShell->ExpandBlockArea(-nMovX, 0);
     264           0 :         break;
     265             :         default:
     266             :             ;
     267             :     }
     268           4 :     pViewShell->ShowAllCursors();
     269             : 
     270           4 :     rReq.AppendItem( SfxInt16Item(FN_PARAM_1,static_cast<sal_Int16>(nRepeat)) );
     271           4 :     rReq.Done();
     272           4 : }
     273             : 
     274           0 : void ScCellShell::ExecuteMove( SfxRequest& rReq )
     275             : {
     276           0 :     ScTabViewShell* pTabViewShell   = GetViewData()->GetViewShell();
     277           0 :     sal_uInt16 nSlotId  = rReq.GetSlot();
     278             : 
     279           0 :     if(nSlotId != SID_CURSORTOPOFSCREEN && nSlotId != SID_CURSORENDOFSCREEN)
     280           0 :         pTabViewShell->ExecuteInputDirect();
     281           0 :     switch ( nSlotId )
     282             :     {
     283             :         case SID_NEXT_TABLE:
     284             :         case SID_NEXT_TABLE_SEL:
     285           0 :             pTabViewShell->SelectNextTab( 1, (nSlotId == SID_NEXT_TABLE_SEL) );
     286           0 :             break;
     287             : 
     288             :         case SID_PREV_TABLE:
     289             :         case SID_PREV_TABLE_SEL:
     290           0 :             pTabViewShell->SelectNextTab( -1, (nSlotId == SID_PREV_TABLE_SEL) );
     291           0 :             break;
     292             : 
     293             :         //  cursor movements in range do not originate from Basic,
     294             :         //  because the ScSbxRange-object changes the marking at input
     295             : 
     296             :         case SID_NEXT_UNPROTECT:
     297           0 :             pTabViewShell->FindNextUnprot( false, !rReq.IsAPI() );
     298           0 :             break;
     299             : 
     300             :         case SID_PREV_UNPROTECT:
     301           0 :             pTabViewShell->FindNextUnprot( true, !rReq.IsAPI() );
     302           0 :             break;
     303             : 
     304             :         case SID_CURSORENTERUP:
     305           0 :             if (rReq.IsAPI())
     306           0 :                 pTabViewShell->MoveCursorRel( 0, -1, SC_FOLLOW_LINE, false );
     307             :             else
     308           0 :                 pTabViewShell->MoveCursorEnter( true );
     309           0 :             break;
     310             : 
     311             :         case SID_CURSORENTERDOWN:
     312           0 :             if (rReq.IsAPI())
     313           0 :                 pTabViewShell->MoveCursorRel( 0, 1, SC_FOLLOW_LINE, false );
     314             :             else
     315           0 :                 pTabViewShell->MoveCursorEnter( false );
     316           0 :             break;
     317             : 
     318             :         case SID_SELECT_COL:
     319           0 :             pTabViewShell->MarkColumns();
     320           0 :             break;
     321             : 
     322             :         case SID_SELECT_ROW:
     323           0 :             pTabViewShell->MarkRows();
     324           0 :             break;
     325             : 
     326             :         case SID_SELECT_NONE:
     327           0 :             pTabViewShell->Unmark();
     328           0 :             break;
     329             : 
     330             :         case SID_ALIGNCURSOR:
     331           0 :             pTabViewShell->AlignToCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), SC_FOLLOW_JUMP );
     332           0 :             break;
     333             : 
     334             :         case SID_MARKDATAAREA:
     335           0 :             pTabViewShell->MarkDataArea();
     336           0 :             break;
     337             : 
     338             :         case SID_MARKARRAYFORMULA:
     339           0 :             pTabViewShell->MarkMatrixFormula();
     340           0 :             break;
     341             : 
     342             :         case SID_SETINPUTMODE:
     343           0 :             SC_MOD()->SetInputMode( SC_INPUT_TABLE );
     344           0 :             break;
     345             : 
     346             :         case SID_FOCUS_INPUTLINE:
     347             :             {
     348           0 :                 ScInputHandler* pHdl = SC_MOD()->GetInputHdl( pTabViewShell );
     349           0 :                 if (pHdl)
     350             :                 {
     351           0 :                     ScInputWindow* pWin = pHdl->GetInputWindow();
     352           0 :                     if (pWin)
     353           0 :                         pWin->SwitchToTextWin();
     354             :                 }
     355             :             }
     356           0 :             break;
     357             : 
     358             :         case SID_CURSORTOPOFSCREEN:
     359           0 :             pTabViewShell->MoveCursorScreen( 0, -1, SC_FOLLOW_LINE, false );
     360           0 :             break;
     361             : 
     362             :         case SID_CURSORENDOFSCREEN:
     363           0 :             pTabViewShell->MoveCursorScreen( 0, 1, SC_FOLLOW_LINE, false );
     364           0 :             break;
     365             : 
     366             :         default:
     367             :             OSL_FAIL("Unknown message in ViewShell (Cursor)");
     368           0 :             return;
     369             :     }
     370             : 
     371           0 :     rReq.Done();
     372             : }
     373             : 
     374           0 : void ScCellShell::ExecutePageSel( SfxRequest& rReq )
     375             : {
     376           0 :     sal_uInt16              nSlotId  = rReq.GetSlot();
     377           0 :     switch ( nSlotId )
     378             :     {
     379           0 :         case SID_CURSORHOME_SEL:        rReq.SetSlot( SID_CURSORHOME );  break;
     380           0 :         case SID_CURSOREND_SEL:         rReq.SetSlot( SID_CURSOREND );  break;
     381           0 :         case SID_CURSORTOPOFFILE_SEL:   rReq.SetSlot( SID_CURSORTOPOFFILE );  break;
     382           0 :         case SID_CURSORENDOFFILE_SEL:   rReq.SetSlot( SID_CURSORENDOFFILE );  break;
     383             :         default:
     384             :             OSL_FAIL("Unknown message in ViewShell (ExecutePageSel)");
     385           0 :             return;
     386             :     }
     387           0 :     rReq.AppendItem( SfxBoolItem(FN_PARAM_2, true) );
     388           0 :     ExecuteSlot( rReq, GetInterface() );
     389             : }
     390             : 
     391           0 : void ScCellShell::ExecutePage( SfxRequest& rReq )
     392             : {
     393           0 :     ScTabViewShell* pTabViewShell   = GetViewData()->GetViewShell();
     394           0 :     const SfxItemSet*   pReqArgs = rReq.GetArgs();
     395           0 :     sal_uInt16              nSlotId  = rReq.GetSlot();
     396           0 :     bool                bSel = false;
     397           0 :     bool                bKeep = false;
     398             : 
     399           0 :     if ( pReqArgs != NULL )
     400             :     {
     401             :         const   SfxPoolItem* pItem;
     402           0 :         if (pReqArgs->HasItem(FN_PARAM_2, &pItem))
     403           0 :             bSel = static_cast<const SfxBoolItem*>(pItem)->GetValue();
     404             :     }
     405             :     else
     406             :     {
     407             :         //  evaluate locked selection mode
     408             : 
     409           0 :         sal_uInt16 nLocked = pTabViewShell->GetLockedModifiers();
     410           0 :         if ( nLocked & KEY_SHIFT )
     411           0 :             bSel = true;                // EXT
     412           0 :         else if ( nLocked & KEY_MOD1 )
     413             :         {
     414             :             // ADD mode: keep the selection, start a new block when marking with shift again
     415           0 :             bKeep = true;
     416             :         }
     417             :     }
     418             : 
     419           0 :     pTabViewShell->ExecuteInputDirect();
     420           0 :     switch ( nSlotId )
     421             :     {
     422             :         case SID_CURSORHOME:
     423           0 :             pTabViewShell->MoveCursorEnd( -1, 0, SC_FOLLOW_LINE, bSel, bKeep );
     424           0 :             break;
     425             : 
     426             :         case SID_CURSOREND:
     427           0 :             pTabViewShell->MoveCursorEnd( 1, 0, SC_FOLLOW_JUMP, bSel, bKeep );
     428           0 :             break;
     429             : 
     430             :         case SID_CURSORTOPOFFILE:
     431           0 :             pTabViewShell->MoveCursorEnd( -1, -1, SC_FOLLOW_LINE, bSel, bKeep );
     432           0 :             break;
     433             : 
     434             :         case SID_CURSORENDOFFILE:
     435           0 :             pTabViewShell->MoveCursorEnd( 1, 1, SC_FOLLOW_JUMP, bSel, bKeep );
     436           0 :             break;
     437             : 
     438             :         default:
     439             :             OSL_FAIL("Unknown message in ViewShell (ExecutePage)");
     440           0 :             return;
     441             :     }
     442             : 
     443           0 :     rReq.AppendItem( SfxBoolItem(FN_PARAM_2, bSel) );
     444           0 :     rReq.Done();
     445         228 : }
     446             : 
     447             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10