LCOV - code coverage report
Current view: top level - sc/source/ui/view - viewfun6.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 172 0.0 %
Date: 2012-08-25 Functions: 0 15 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 292 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <svx/svdundo.hxx>
      31                 :            : #include <svx/svdocapt.hxx>
      32                 :            : #include <sfx2/bindings.hxx>
      33                 :            : #include <sfx2/dispatch.hxx>
      34                 :            : #include <vcl/msgbox.hxx>
      35                 :            : #include "svl/zforlist.hxx"
      36                 :            : #include "svl/zformat.hxx"
      37                 :            : 
      38                 :            : #include "viewfunc.hxx"
      39                 :            : #include "detfunc.hxx"
      40                 :            : #include "detdata.hxx"
      41                 :            : #include "viewdata.hxx"
      42                 :            : #include "drwlayer.hxx"
      43                 :            : #include "docsh.hxx"
      44                 :            : #include "undocell.hxx"
      45                 :            : #include "futext.hxx"
      46                 :            : #include "docfunc.hxx"
      47                 :            : #include "globstr.hrc"
      48                 :            : #include "sc.hrc"
      49                 :            : #include "fusel.hxx"
      50                 :            : #include "reftokenhelper.hxx"
      51                 :            : #include "externalrefmgr.hxx"
      52                 :            : #include "cell.hxx"
      53                 :            : #include "markdata.hxx"
      54                 :            : 
      55                 :            : #include <vector>
      56                 :            : 
      57                 :            : using ::rtl::OUString;
      58                 :            : using ::rtl::OUStringBuffer;
      59                 :            : using ::std::vector;
      60                 :            : 
      61                 :            : #define D_TIMEFACTOR              86400.0
      62                 :            : 
      63                 :            : //==================================================================
      64                 :            : 
      65                 :          0 : void ScViewFunc::DetectiveAddPred()
      66                 :            : {
      67                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
      68         [ #  # ]:          0 :     pDocSh->GetDocFunc().DetectiveAddPred( GetViewData()->GetCurPos() );
      69                 :          0 :     RecalcPPT();    //! use broadcast in DocFunc instead?
      70                 :          0 : }
      71                 :            : 
      72                 :          0 : void ScViewFunc::DetectiveDelPred()
      73                 :            : {
      74                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
      75         [ #  # ]:          0 :     pDocSh->GetDocFunc().DetectiveDelPred( GetViewData()->GetCurPos() );
      76                 :          0 :     RecalcPPT();
      77                 :          0 : }
      78                 :            : 
      79                 :          0 : void ScViewFunc::DetectiveAddSucc()
      80                 :            : {
      81                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
      82         [ #  # ]:          0 :     pDocSh->GetDocFunc().DetectiveAddSucc( GetViewData()->GetCurPos() );
      83                 :          0 :     RecalcPPT();
      84                 :          0 : }
      85                 :            : 
      86                 :          0 : void ScViewFunc::DetectiveDelSucc()
      87                 :            : {
      88                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
      89         [ #  # ]:          0 :     pDocSh->GetDocFunc().DetectiveDelSucc( GetViewData()->GetCurPos() );
      90                 :          0 :     RecalcPPT();
      91                 :          0 : }
      92                 :            : 
      93                 :          0 : void ScViewFunc::DetectiveAddError()
      94                 :            : {
      95                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
      96         [ #  # ]:          0 :     pDocSh->GetDocFunc().DetectiveAddError( GetViewData()->GetCurPos() );
      97                 :          0 :     RecalcPPT();
      98                 :          0 : }
      99                 :            : 
     100                 :          0 : void ScViewFunc::DetectiveDelAll()
     101                 :            : {
     102                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     103                 :          0 :     pDocSh->GetDocFunc().DetectiveDelAll( GetViewData()->GetTabNo() );
     104                 :          0 :     RecalcPPT();
     105                 :          0 : }
     106                 :            : 
     107                 :          0 : void ScViewFunc::DetectiveMarkInvalid()
     108                 :            : {
     109                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     110                 :          0 :     pDocSh->GetDocFunc().DetectiveMarkInvalid( GetViewData()->GetTabNo() );
     111                 :          0 :     RecalcPPT();
     112                 :          0 : }
     113                 :            : 
     114                 :          0 : void ScViewFunc::DetectiveRefresh()
     115                 :            : {
     116                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     117                 :          0 :     pDocSh->GetDocFunc().DetectiveRefresh();
     118                 :          0 :     RecalcPPT();
     119                 :          0 : }
     120                 :            : 
     121                 :          0 : static void lcl_jumpToRange(const ScRange& rRange, ScViewData* pView, ScDocument* pDoc)
     122                 :            : {
     123         [ #  # ]:          0 :     String aAddrText;
     124         [ #  # ]:          0 :     rRange.Format(aAddrText, SCR_ABS_3D, pDoc);
     125         [ #  # ]:          0 :     SfxStringItem aPosItem(SID_CURRENTCELL, aAddrText);
     126         [ #  # ]:          0 :     SfxBoolItem aUnmarkItem(FN_PARAM_1, true);        // remove existing selection
     127         [ #  # ]:          0 :     pView->GetDispatcher().Execute(
     128                 :            :         SID_CURRENTCELL, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD,
     129 [ #  # ][ #  # ]:          0 :         &aPosItem, &aUnmarkItem, 0L);
         [ #  # ][ #  # ]
     130                 :          0 : }
     131                 :            : 
     132                 :          0 : void ScViewFunc::MarkAndJumpToRanges(const ScRangeList& rRanges)
     133                 :            : {
     134                 :          0 :     ScViewData* pView = GetViewData();
     135                 :          0 :     ScDocShell* pDocSh = pView->GetDocShell();
     136                 :            : 
     137         [ #  # ]:          0 :     ScRangeList aRanges(rRanges);
     138         [ #  # ]:          0 :     ScRange* p = aRanges.front();
     139         [ #  # ]:          0 :     ScRangeList aRangesToMark;
     140         [ #  # ]:          0 :     ScAddress aCurPos = pView->GetCurPos();
     141         [ #  # ]:          0 :     size_t ListSize = aRanges.size();
     142         [ #  # ]:          0 :     for ( size_t i = 0; i < ListSize; ++i )
     143                 :            :     {
     144         [ #  # ]:          0 :         p = aRanges[i];
     145                 :            :         // Collect only those ranges that are on the same sheet as the current
     146                 :            :         // cursor.
     147         [ #  # ]:          0 :         if (p->aStart.Tab() == aCurPos.Tab())
     148         [ #  # ]:          0 :             aRangesToMark.Append(*p);
     149                 :            :     }
     150                 :            : 
     151 [ #  # ][ #  # ]:          0 :     if (aRangesToMark.empty())
     152                 :          0 :         return;
     153                 :            : 
     154                 :            :     // Jump to the first range of all precedent ranges.
     155         [ #  # ]:          0 :     p = aRangesToMark.front();
     156         [ #  # ]:          0 :     lcl_jumpToRange(*p, pView, pDocSh->GetDocument());
     157                 :            : 
     158         [ #  # ]:          0 :     ListSize = aRangesToMark.size();
     159         [ #  # ]:          0 :     for ( size_t i = 0; i < ListSize; ++i )
     160                 :            :     {
     161         [ #  # ]:          0 :         p = aRangesToMark[i];
     162         [ #  # ]:          0 :         MarkRange(*p, false, true);
     163 [ #  # ][ #  # ]:          0 :     }
         [ #  # ][ #  # ]
     164                 :            : }
     165                 :            : 
     166                 :          0 : void ScViewFunc::DetectiveMarkPred()
     167                 :            : {
     168                 :          0 :     ScViewData* pView = GetViewData();
     169                 :          0 :     ScDocShell* pDocSh = pView->GetDocShell();
     170                 :          0 :     ScDocument* pDoc = pDocSh->GetDocument();
     171         [ #  # ]:          0 :     ScMarkData& rMarkData = pView->GetMarkData();
     172         [ #  # ]:          0 :     ScAddress aCurPos = pView->GetCurPos();
     173         [ #  # ]:          0 :     ScRangeList aRanges;
     174 [ #  # ][ #  # ]:          0 :     if (rMarkData.IsMarked() || rMarkData.IsMultiMarked())
                 [ #  # ]
     175         [ #  # ]:          0 :         rMarkData.FillRangeListWithMarks(&aRanges, false);
     176                 :            :     else
     177         [ #  # ]:          0 :         aRanges.Append(aCurPos);
     178                 :            : 
     179         [ #  # ]:          0 :     vector<ScTokenRef> aRefTokens;
     180         [ #  # ]:          0 :     pDocSh->GetDocFunc().DetectiveCollectAllPreds(aRanges, aRefTokens);
     181                 :            : 
     182         [ #  # ]:          0 :     if (aRefTokens.empty())
     183                 :            :         // No precedents found.  Nothing to do.
     184                 :            :         return;
     185                 :            : 
     186         [ #  # ]:          0 :     ScTokenRef p = aRefTokens.front();
     187 [ #  # ][ #  # ]:          0 :     if (ScRefTokenHelper::isExternalRef(p))
     188                 :            :     {
     189                 :            :         // This is external.  Open the external document if available, and
     190                 :            :         // jump to the destination.
     191                 :            : 
     192         [ #  # ]:          0 :         sal_uInt16 nFileId = p->GetIndex();
     193         [ #  # ]:          0 :         ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
     194         [ #  # ]:          0 :         const OUString* pPath = pRefMgr->getExternalFileName(nFileId);
     195                 :            : 
     196                 :          0 :         ScRange aRange;
     197 [ #  # ][ #  # ]:          0 :         if (pPath && ScRefTokenHelper::getRangeFromToken(aRange, p, true))
         [ #  # ][ #  # ]
     198                 :            :         {
     199         [ #  # ]:          0 :             const String& rTabName = p->GetString();
     200                 :          0 :             OUStringBuffer aBuf;
     201         [ #  # ]:          0 :             aBuf.append(*pPath);
     202         [ #  # ]:          0 :             aBuf.append(sal_Unicode('#'));
     203 [ #  # ][ #  # ]:          0 :             aBuf.append(rTabName);
     204         [ #  # ]:          0 :             aBuf.append(sal_Unicode('.'));
     205                 :            : 
     206         [ #  # ]:          0 :             String aRangeStr;
     207         [ #  # ]:          0 :             aRange.Format(aRangeStr, SCA_VALID);
     208 [ #  # ][ #  # ]:          0 :             aBuf.append(aRangeStr);
     209                 :            : 
     210 [ #  # ][ #  # ]:          0 :             ScGlobal::OpenURL(aBuf.makeStringAndClear(), String());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     211                 :            :         }
     212                 :            :         return;
     213                 :            :     }
     214                 :            :     else
     215                 :            :     {
     216                 :          0 :         ScRange aRange;
     217         [ #  # ]:          0 :         ScRefTokenHelper::getRangeFromToken(aRange, p, false);
     218         [ #  # ]:          0 :         if (aRange.aStart.Tab() != aCurPos.Tab())
     219                 :            :         {
     220                 :            :             // The first precedent range is on a different sheet.  Jump to it
     221                 :            :             // immediately and forget the rest.
     222         [ #  # ]:          0 :             lcl_jumpToRange(aRange, pView, pDoc);
     223                 :            :             return;
     224                 :            :         }
     225                 :            :     }
     226                 :            : 
     227         [ #  # ]:          0 :     ScRangeList aDestRanges;
     228         [ #  # ]:          0 :     ScRefTokenHelper::getRangeListFromTokens(aDestRanges, aRefTokens);
     229 [ #  # ][ #  # ]:          0 :     MarkAndJumpToRanges(aDestRanges);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     230                 :            : }
     231                 :            : 
     232                 :          0 : void ScViewFunc::DetectiveMarkSucc()
     233                 :            : {
     234                 :          0 :     ScViewData* pView = GetViewData();
     235                 :          0 :     ScDocShell* pDocSh = pView->GetDocShell();
     236         [ #  # ]:          0 :     ScMarkData& rMarkData = pView->GetMarkData();
     237         [ #  # ]:          0 :     ScAddress aCurPos = pView->GetCurPos();
     238         [ #  # ]:          0 :     ScRangeList aRanges;
     239 [ #  # ][ #  # ]:          0 :     if (rMarkData.IsMarked() || rMarkData.IsMultiMarked())
                 [ #  # ]
     240         [ #  # ]:          0 :         rMarkData.FillRangeListWithMarks(&aRanges, false);
     241                 :            :     else
     242         [ #  # ]:          0 :         aRanges.Append(aCurPos);
     243                 :            : 
     244         [ #  # ]:          0 :     vector<ScTokenRef> aRefTokens;
     245         [ #  # ]:          0 :     pDocSh->GetDocFunc().DetectiveCollectAllSuccs(aRanges, aRefTokens);
     246                 :            : 
     247         [ #  # ]:          0 :     if (aRefTokens.empty())
     248                 :            :         // No dependants found.  Nothing to do.
     249                 :          0 :         return;
     250                 :            : 
     251         [ #  # ]:          0 :     ScRangeList aDestRanges;
     252         [ #  # ]:          0 :     ScRefTokenHelper::getRangeListFromTokens(aDestRanges, aRefTokens);
     253 [ #  # ][ #  # ]:          0 :     MarkAndJumpToRanges(aDestRanges);
         [ #  # ][ #  # ]
                 [ #  # ]
     254                 :            : }
     255                 :            : 
     256                 :          0 : void ScViewFunc::InsertCurrentTime(short nCellFmt, const OUString& rUndoStr)
     257                 :            : {
     258                 :          0 :     ScViewData* pViewData = GetViewData();
     259         [ #  # ]:          0 :     ScAddress aCurPos = pViewData->GetCurPos();
     260                 :          0 :     ScDocShell* pDocSh = pViewData->GetDocShell();
     261                 :          0 :     ScDocument* pDoc = pDocSh->GetDocument();
     262         [ #  # ]:          0 :     ::svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager();
     263         [ #  # ]:          0 :     SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
     264         [ #  # ]:          0 :     Date aActDate( Date::SYSTEM );
     265 [ #  # ][ #  # ]:          0 :     double fDate = aActDate - *pFormatter->GetNullDate();
     266         [ #  # ]:          0 :     Time aActTime( Time::SYSTEM );
     267                 :            :     double fTime =
     268                 :          0 :         aActTime.Get100Sec() / 100.0 + aActTime.GetSec() +
     269                 :          0 :         (aActTime.GetMin() * 60.0) + (aActTime.GetHour() * 3600.0);
     270                 :          0 :     fTime /= D_TIMEFACTOR;
     271 [ #  # ][ #  # ]:          0 :     pUndoMgr->EnterListAction(rUndoStr, rUndoStr);
         [ #  # ][ #  # ]
                 [ #  # ]
     272 [ #  # ][ #  # ]:          0 :     pDocSh->GetDocFunc().PutCell(aCurPos, new ScValueCell(fDate+fTime), false);
                 [ #  # ]
     273                 :            : 
     274                 :            :     // Set the new cell format only when it differs from the current cell
     275                 :            :     // format type.
     276         [ #  # ]:          0 :     sal_uInt32 nCurNumFormat = pDoc->GetNumberFormat(aCurPos);
     277         [ #  # ]:          0 :     const SvNumberformat* pEntry = pFormatter->GetEntry(nCurNumFormat);
     278 [ #  # ][ #  # ]:          0 :     if (!pEntry || !(pEntry->GetType() & nCellFmt))
                 [ #  # ]
     279         [ #  # ]:          0 :         SetNumberFormat(nCellFmt);
     280         [ #  # ]:          0 :     pUndoMgr->LeaveListAction();
     281                 :          0 : }
     282                 :            : 
     283                 :            : //---------------------------------------------------------------------------
     284                 :            : 
     285                 :          0 : void ScViewFunc::ShowNote( bool bShow )
     286                 :            : {
     287         [ #  # ]:          0 :     if( bShow )
     288         [ #  # ]:          0 :         HideNoteMarker();
     289                 :          0 :     const ScViewData& rViewData = *GetViewData();
     290                 :          0 :     ScAddress aPos( rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo() );
     291                 :            :     // show note moved to ScDocFunc, to be able to use it in notesuno.cxx
     292         [ #  # ]:          0 :     rViewData.GetDocShell()->GetDocFunc().ShowNote( aPos, bShow );
     293                 :          0 : }
     294                 :            : 
     295                 :          0 : void ScViewFunc::EditNote()
     296                 :            : {
     297                 :            :     //  zum Editieren einblenden und aktivieren
     298                 :            : 
     299                 :          0 :     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     300                 :          0 :     ScDocument* pDoc = pDocSh->GetDocument();
     301                 :          0 :     SCCOL nCol = GetViewData()->GetCurX();
     302                 :          0 :     SCROW nRow = GetViewData()->GetCurY();
     303                 :          0 :     SCTAB nTab = GetViewData()->GetTabNo();
     304                 :          0 :     ScAddress aPos( nCol, nRow, nTab );
     305                 :            : 
     306                 :            :     // start drawing undo to catch undo action for insertion of the caption object
     307         [ #  # ]:          0 :     pDocSh->MakeDrawLayer();
     308         [ #  # ]:          0 :     ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
     309         [ #  # ]:          0 :     pDrawLayer->BeginCalcUndo();
     310                 :            :     // generated undo action is processed in FuText::StopEditMode
     311                 :            : 
     312                 :            :     // get existing note or create a new note (including caption drawing object)
     313 [ #  # ][ #  # ]:          0 :     if( ScPostIt* pNote = pDoc->GetNotes(aPos.Tab())->GetOrCreateNote( aPos ) )
                 [ #  # ]
     314                 :            :     {
     315                 :            :         // hide temporary note caption
     316         [ #  # ]:          0 :         HideNoteMarker();
     317                 :            :         // show caption object without changing internal visibility state
     318         [ #  # ]:          0 :         pNote->ShowCaptionTemp( aPos );
     319                 :            : 
     320                 :            :         /*  Drawing object has been created in ScDocument::GetOrCreateNote() or
     321                 :            :             in ScPostIt::ShowCaptionTemp(), so ScPostIt::GetCaption() should
     322                 :            :             return a caption object. */
     323         [ #  # ]:          0 :         if( SdrCaptionObj* pCaption = pNote->GetCaption() )
     324                 :            :         {
     325                 :            :             // #i33764# enable the resize handles before starting edit mode
     326         [ #  # ]:          0 :             if( FuPoor* pDraw = GetDrawFuncPtr() )
     327         [ #  # ]:          0 :                 static_cast< FuSelection* >( pDraw )->ActivateNoteHandles( pCaption );
     328                 :            : 
     329                 :            :             // activate object (as in FuSelection::TestComment)
     330 [ #  # ][ #  # ]:          0 :             GetViewData()->GetDispatcher().Execute( SID_DRAW_NOTEEDIT, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
     331                 :            :             // jetzt den erzeugten FuText holen und in den EditModus setzen
     332                 :          0 :             FuPoor* pPoor = GetDrawFuncPtr();
     333 [ #  # ][ #  # ]:          0 :             if ( pPoor && (pPoor->GetSlotID() == SID_DRAW_NOTEEDIT) )    // hat keine RTTI
                 [ #  # ]
     334                 :            :             {
     335         [ #  # ]:          0 :                 ScrollToObject( pCaption );         // Objekt komplett sichtbar machen
     336         [ #  # ]:          0 :                 static_cast< FuText* >( pPoor )->SetInEditMode( pCaption );
     337                 :            :             }
     338                 :            :         }
     339                 :            :     }
     340                 :          0 : }
     341                 :            : 
     342                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10