LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/view - viewfun6.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 177 0.6 %
Date: 2013-07-09 Functions: 2 17 11.8 %
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             : 
      21             : #include <svx/svdundo.hxx>
      22             : #include <svx/svdocapt.hxx>
      23             : #include <sfx2/bindings.hxx>
      24             : #include <sfx2/dispatch.hxx>
      25             : #include <vcl/msgbox.hxx>
      26             : #include "svl/zforlist.hxx"
      27             : #include "svl/zformat.hxx"
      28             : 
      29             : #include "viewfunc.hxx"
      30             : #include "detfunc.hxx"
      31             : #include "detdata.hxx"
      32             : #include "viewdata.hxx"
      33             : #include "drwlayer.hxx"
      34             : #include "docsh.hxx"
      35             : #include "undocell.hxx"
      36             : #include "futext.hxx"
      37             : #include "docfunc.hxx"
      38             : #include "globstr.hrc"
      39             : #include "sc.hrc"
      40             : #include "fusel.hxx"
      41             : #include "reftokenhelper.hxx"
      42             : #include "externalrefmgr.hxx"
      43             : #include "formulacell.hxx"
      44             : #include "markdata.hxx"
      45             : #include "drawview.hxx"
      46             : #include "globalnames.hxx"
      47             : 
      48             : #include <vector>
      49             : 
      50             : using ::std::vector;
      51             : 
      52           0 : void ScViewFunc::DetectiveAddPred()
      53             : {
      54           0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
      55           0 :     pDocSh->GetDocFunc().DetectiveAddPred( GetViewData()->GetCurPos() );
      56           0 :     RecalcPPT();    //! use broadcast in DocFunc instead?
      57           0 : }
      58             : 
      59           0 : void ScViewFunc::DetectiveDelPred()
      60             : {
      61           0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
      62           0 :     pDocSh->GetDocFunc().DetectiveDelPred( GetViewData()->GetCurPos() );
      63           0 :     RecalcPPT();
      64           0 : }
      65             : 
      66           0 : void ScViewFunc::DetectiveAddSucc()
      67             : {
      68           0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
      69           0 :     pDocSh->GetDocFunc().DetectiveAddSucc( GetViewData()->GetCurPos() );
      70           0 :     RecalcPPT();
      71           0 : }
      72             : 
      73           0 : void ScViewFunc::DetectiveDelSucc()
      74             : {
      75           0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
      76           0 :     pDocSh->GetDocFunc().DetectiveDelSucc( GetViewData()->GetCurPos() );
      77           0 :     RecalcPPT();
      78           0 : }
      79             : 
      80           0 : void ScViewFunc::DetectiveAddError()
      81             : {
      82           0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
      83           0 :     pDocSh->GetDocFunc().DetectiveAddError( GetViewData()->GetCurPos() );
      84           0 :     RecalcPPT();
      85           0 : }
      86             : 
      87           0 : void ScViewFunc::DetectiveDelAll()
      88             : {
      89           0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
      90           0 :     pDocSh->GetDocFunc().DetectiveDelAll( GetViewData()->GetTabNo() );
      91           0 :     RecalcPPT();
      92           0 : }
      93             : 
      94           0 : void ScViewFunc::DetectiveMarkInvalid()
      95             : {
      96           0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
      97           0 :     pDocSh->GetDocFunc().DetectiveMarkInvalid( GetViewData()->GetTabNo() );
      98           0 :     RecalcPPT();
      99           0 : }
     100             : 
     101           0 : void ScViewFunc::DetectiveRefresh()
     102             : {
     103           0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     104           0 :     pDocSh->GetDocFunc().DetectiveRefresh();
     105           0 :     RecalcPPT();
     106           0 : }
     107             : 
     108           0 : static void lcl_jumpToRange(const ScRange& rRange, ScViewData* pView, ScDocument* pDoc)
     109             : {
     110           0 :     String aAddrText;
     111           0 :     rRange.Format(aAddrText, SCR_ABS_3D, pDoc);
     112           0 :     SfxStringItem aPosItem(SID_CURRENTCELL, aAddrText);
     113           0 :     SfxBoolItem aUnmarkItem(FN_PARAM_1, true);        // remove existing selection
     114           0 :     pView->GetDispatcher().Execute(
     115             :         SID_CURRENTCELL, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD,
     116           0 :         &aPosItem, &aUnmarkItem, 0L);
     117           0 : }
     118             : 
     119           0 : void ScViewFunc::MarkAndJumpToRanges(const ScRangeList& rRanges)
     120             : {
     121           0 :     ScViewData* pView = GetViewData();
     122           0 :     ScDocShell* pDocSh = pView->GetDocShell();
     123             : 
     124           0 :     ScRangeList aRanges(rRanges);
     125           0 :     ScRangeList aRangesToMark;
     126           0 :     ScAddress aCurPos = pView->GetCurPos();
     127           0 :     size_t ListSize = aRanges.size();
     128           0 :     for ( size_t i = 0; i < ListSize; ++i )
     129             :     {
     130           0 :         const ScRange* p = aRanges[i];
     131             :         // Collect only those ranges that are on the same sheet as the current
     132             :         // cursor.
     133           0 :         if (p->aStart.Tab() == aCurPos.Tab())
     134           0 :             aRangesToMark.Append(*p);
     135             :     }
     136             : 
     137           0 :     if (aRangesToMark.empty())
     138           0 :         return;
     139             : 
     140             :     // Jump to the first range of all precedent ranges.
     141           0 :     const ScRange* p = aRangesToMark.front();
     142           0 :     lcl_jumpToRange(*p, pView, pDocSh->GetDocument());
     143             : 
     144           0 :     ListSize = aRangesToMark.size();
     145           0 :     for ( size_t i = 0; i < ListSize; ++i )
     146             :     {
     147           0 :         p = aRangesToMark[i];
     148           0 :         MarkRange(*p, false, true);
     149           0 :     }
     150             : }
     151             : 
     152           0 : void ScViewFunc::DetectiveMarkPred()
     153             : {
     154           0 :     ScViewData* pView = GetViewData();
     155           0 :     ScDocShell* pDocSh = pView->GetDocShell();
     156           0 :     ScDocument* pDoc = pDocSh->GetDocument();
     157           0 :     ScMarkData& rMarkData = pView->GetMarkData();
     158           0 :     ScAddress aCurPos = pView->GetCurPos();
     159           0 :     ScRangeList aRanges;
     160           0 :     if (rMarkData.IsMarked() || rMarkData.IsMultiMarked())
     161           0 :         rMarkData.FillRangeListWithMarks(&aRanges, false);
     162             :     else
     163           0 :         aRanges.Append(aCurPos);
     164             : 
     165           0 :     vector<ScTokenRef> aRefTokens;
     166           0 :     pDocSh->GetDocFunc().DetectiveCollectAllPreds(aRanges, aRefTokens);
     167             : 
     168           0 :     if (aRefTokens.empty())
     169             :         // No precedents found.  Nothing to do.
     170           0 :         return;
     171             : 
     172           0 :     ScTokenRef p = aRefTokens.front();
     173           0 :     if (ScRefTokenHelper::isExternalRef(p))
     174             :     {
     175             :         // This is external.  Open the external document if available, and
     176             :         // jump to the destination.
     177             : 
     178           0 :         sal_uInt16 nFileId = p->GetIndex();
     179           0 :         ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
     180           0 :         const OUString* pPath = pRefMgr->getExternalFileName(nFileId);
     181             : 
     182           0 :         ScRange aRange;
     183           0 :         if (pPath && ScRefTokenHelper::getRangeFromToken(aRange, p, true))
     184             :         {
     185           0 :             const String& rTabName = p->GetString();
     186           0 :             OUStringBuffer aBuf;
     187           0 :             aBuf.append(*pPath);
     188           0 :             aBuf.append(sal_Unicode('#'));
     189           0 :             aBuf.append(rTabName);
     190           0 :             aBuf.append(sal_Unicode('.'));
     191             : 
     192           0 :             String aRangeStr;
     193           0 :             aRange.Format(aRangeStr, SCA_VALID);
     194           0 :             aBuf.append(aRangeStr);
     195             : 
     196           0 :             ScGlobal::OpenURL(aBuf.makeStringAndClear(), String());
     197             :         }
     198           0 :         return;
     199             :     }
     200             :     else
     201             :     {
     202           0 :         ScRange aRange;
     203           0 :         ScRefTokenHelper::getRangeFromToken(aRange, p, false);
     204           0 :         if (aRange.aStart.Tab() != aCurPos.Tab())
     205             :         {
     206             :             // The first precedent range is on a different sheet.  Jump to it
     207             :             // immediately and forget the rest.
     208           0 :             lcl_jumpToRange(aRange, pView, pDoc);
     209           0 :             return;
     210             :         }
     211             :     }
     212             : 
     213           0 :     ScRangeList aDestRanges;
     214           0 :     ScRefTokenHelper::getRangeListFromTokens(aDestRanges, aRefTokens);
     215           0 :     MarkAndJumpToRanges(aDestRanges);
     216             : }
     217             : 
     218           0 : void ScViewFunc::DetectiveMarkSucc()
     219             : {
     220           0 :     ScViewData* pView = GetViewData();
     221           0 :     ScDocShell* pDocSh = pView->GetDocShell();
     222           0 :     ScMarkData& rMarkData = pView->GetMarkData();
     223           0 :     ScAddress aCurPos = pView->GetCurPos();
     224           0 :     ScRangeList aRanges;
     225           0 :     if (rMarkData.IsMarked() || rMarkData.IsMultiMarked())
     226           0 :         rMarkData.FillRangeListWithMarks(&aRanges, false);
     227             :     else
     228           0 :         aRanges.Append(aCurPos);
     229             : 
     230           0 :     vector<ScTokenRef> aRefTokens;
     231           0 :     pDocSh->GetDocFunc().DetectiveCollectAllSuccs(aRanges, aRefTokens);
     232             : 
     233           0 :     if (aRefTokens.empty())
     234             :         // No dependants found.  Nothing to do.
     235           0 :         return;
     236             : 
     237           0 :     ScRangeList aDestRanges;
     238           0 :     ScRefTokenHelper::getRangeListFromTokens(aDestRanges, aRefTokens);
     239           0 :     MarkAndJumpToRanges(aDestRanges);
     240             : }
     241             : 
     242           0 : void ScViewFunc::InsertCurrentTime(short nCellFmt, const OUString& rUndoStr)
     243             : {
     244           0 :     ScViewData* pViewData = GetViewData();
     245           0 :     ScAddress aCurPos = pViewData->GetCurPos();
     246           0 :     ScDocShell* pDocSh = pViewData->GetDocShell();
     247           0 :     ScDocument* pDoc = pDocSh->GetDocument();
     248           0 :     ::svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager();
     249           0 :     SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
     250           0 :     Date aActDate( Date::SYSTEM );
     251           0 :     double fDate = aActDate - *pFormatter->GetNullDate();
     252           0 :     Time aActTime( Time::SYSTEM );
     253           0 :     double fTime = aActTime.GetHour()    / static_cast<double>(::Time::hourPerDay)   +
     254           0 :                    aActTime.GetMin()     / static_cast<double>(::Time::minutePerDay) +
     255           0 :                    aActTime.GetSec()     / static_cast<double>(::Time::secondPerDay) +
     256           0 :                    aActTime.GetNanoSec() / static_cast<double>(::Time::nanoSecPerDay);
     257           0 :     pUndoMgr->EnterListAction(rUndoStr, rUndoStr);
     258           0 :     pDocSh->GetDocFunc().SetValueCell(aCurPos, fDate+fTime, true);
     259             : 
     260             :     // Set the new cell format only when it differs from the current cell
     261             :     // format type.
     262           0 :     sal_uInt32 nCurNumFormat = pDoc->GetNumberFormat(aCurPos);
     263           0 :     const SvNumberformat* pEntry = pFormatter->GetEntry(nCurNumFormat);
     264           0 :     if (!pEntry || !(pEntry->GetType() & nCellFmt))
     265           0 :         SetNumberFormat(nCellFmt);
     266           0 :     pUndoMgr->LeaveListAction();
     267           0 : }
     268             : 
     269           0 : void ScViewFunc::ShowNote( bool bShow )
     270             : {
     271           0 :     if( bShow )
     272           0 :         HideNoteMarker();
     273           0 :     const ScViewData& rViewData = *GetViewData();
     274           0 :     ScAddress aPos( rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo() );
     275             :     // show note moved to ScDocFunc, to be able to use it in notesuno.cxx
     276           0 :     rViewData.GetDocShell()->GetDocFunc().ShowNote( aPos, bShow );
     277           0 : }
     278             : 
     279           0 : void ScViewFunc::EditNote()
     280             : {
     281             :     // for editing display and activate
     282             : 
     283           0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     284           0 :     ScDocument* pDoc = pDocSh->GetDocument();
     285           0 :     SCCOL nCol = GetViewData()->GetCurX();
     286           0 :     SCROW nRow = GetViewData()->GetCurY();
     287           0 :     SCTAB nTab = GetViewData()->GetTabNo();
     288           0 :     ScAddress aPos( nCol, nRow, nTab );
     289             : 
     290             :     // start drawing undo to catch undo action for insertion of the caption object
     291           0 :     pDocSh->MakeDrawLayer();
     292           0 :     ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
     293           0 :     pDrawLayer->BeginCalcUndo(true);
     294             :     // generated undo action is processed in FuText::StopEditMode
     295             : 
     296             :     // get existing note or create a new note (including caption drawing object)
     297           0 :     if( ScPostIt* pNote = pDoc->GetNotes(aPos.Tab())->GetOrCreateNote( aPos ) )
     298             :     {
     299             :         // hide temporary note caption
     300           0 :         HideNoteMarker();
     301             :         // show caption object without changing internal visibility state
     302           0 :         pNote->ShowCaptionTemp( aPos );
     303             : 
     304             :         /*  Drawing object has been created in ScDocument::GetOrCreateNote() or
     305             :             in ScPostIt::ShowCaptionTemp(), so ScPostIt::GetCaption() should
     306             :             return a caption object. */
     307           0 :         if( SdrCaptionObj* pCaption = pNote->GetCaption() )
     308             :         {
     309           0 :             if ( ScDrawView* pScDrawView = GetScDrawView() )
     310           0 :                pScDrawView->SyncForGrid( pCaption );
     311             :             // #i33764# enable the resize handles before starting edit mode
     312           0 :             if( FuPoor* pDraw = GetDrawFuncPtr() )
     313           0 :                 static_cast< FuSelection* >( pDraw )->ActivateNoteHandles( pCaption );
     314             : 
     315             :             // activate object (as in FuSelection::TestComment)
     316           0 :             GetViewData()->GetDispatcher().Execute( SID_DRAW_NOTEEDIT, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
     317             :             // now get the created FuText and set into EditMode
     318           0 :             FuPoor* pPoor = GetDrawFuncPtr();
     319           0 :             if ( pPoor && (pPoor->GetSlotID() == SID_DRAW_NOTEEDIT) )    // has no RTTI
     320             :             {
     321           0 :                 ScrollToObject( pCaption );         // make object fully visible
     322           0 :                 static_cast< FuText* >( pPoor )->SetInEditMode( pCaption );
     323             :             }
     324             :         }
     325             :     }
     326          93 : }
     327             : 
     328             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10