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

Generated by: LCOV version 1.10