LCOV - code coverage report
Current view: top level - sc/source/ui/drawfunc - futext3.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 58 1.7 %
Date: 2014-11-03 Functions: 2 4 50.0 %
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 <editeng/editeng.hxx>
      21             : #include <editeng/outlobj.hxx>
      22             : #include <svx/svdocapt.hxx>
      23             : #include <svx/svdpage.hxx>
      24             : #include <svx/svdundo.hxx>
      25             : #include <svx/svdview.hxx>
      26             : #include <editeng/editobj.hxx>
      27             : #include <vcl/cursor.hxx>
      28             : #include <sfx2/objsh.hxx>
      29             : #include <editeng/writingmodeitem.hxx>
      30             : 
      31             : #include "global.hxx"
      32             : #include "drwlayer.hxx"
      33             : #include "userdat.hxx"
      34             : #include "tabvwsh.hxx"
      35             : #include "document.hxx"
      36             : #include "editutil.hxx"
      37             : #include "futext.hxx"
      38             : #include "docsh.hxx"
      39             : #include "postit.hxx"
      40             : #include "globstr.hrc"
      41             : #include "attrib.hxx"
      42             : #include "scitems.hxx"
      43             : #include "drawview.hxx"
      44             : #include "undocell.hxx"
      45             : 
      46             : //  Editieren von Notiz-Legendenobjekten muss immer ueber StopEditMode beendet werden,
      47             : //  damit die Aenderungen ins Dokument uebernommen werden!
      48             : //  (Fontwork-Execute in drawsh und drtxtob passiert nicht fuer Legendenobjekte)
      49             : //  bTextDirection=sal_True means that this function is called from SID_TEXTDIRECTION_XXX(drtxtob.cxx).
      50             : 
      51           0 : void FuText::StopEditMode(bool /*bTextDirection*/)
      52             : {
      53           0 :     SdrObject* pObject = pView->GetTextEditObject();
      54           0 :     if( !pObject ) return;
      55             : 
      56             :     // relock the internal layer that has been unlocked in FuText::SetInEditMode()
      57           0 :     if ( pObject->GetLayer() == SC_LAYER_INTERN )
      58           0 :         pView->LockInternalLayer();
      59             : 
      60           0 :     ScViewData& rViewData = pViewShell->GetViewData();
      61           0 :     ScDocument& rDoc = *rViewData.GetDocument();
      62           0 :     ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
      63             :     OSL_ENSURE( pDrawLayer && (pDrawLayer == pDrDoc), "FuText::StopEditMode - missing or different drawing layers" );
      64             : 
      65           0 :     ScAddress aNotePos;
      66           0 :     ScPostIt* pNote = 0;
      67           0 :     if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObject, rViewData.GetTabNo() ) )
      68             :     {
      69           0 :         aNotePos = pCaptData->maStart;
      70           0 :         pNote = rDoc.GetNote( aNotePos );
      71             :         OSL_ENSURE( pNote && (pNote->GetCaption() == pObject), "FuText::StopEditMode - missing or invalid cell note" );
      72             :     }
      73             : 
      74           0 :     ScDocShell* pDocShell = rViewData.GetDocShell();
      75           0 :     ::svl::IUndoManager* pUndoMgr = rDoc.IsUndoEnabled() ? pDocShell->GetUndoManager() : 0;
      76           0 :     bool bNewNote = false;
      77           0 :     if( pNote && pUndoMgr )
      78             :     {
      79             :         /*  Put all undo actions already collected (e.g. create caption object)
      80             :             and all following undo actions (text changed) together into a ListAction. */
      81           0 :         SdrUndoGroup* pCalcUndo = pDrawLayer->GetCalcUndo();
      82             : 
      83           0 :         if(pCalcUndo)
      84             :         {
      85           0 :             const OUString aUndoStr = ScGlobal::GetRscString( STR_UNDO_EDITNOTE );
      86           0 :             pUndoMgr->EnterListAction( aUndoStr, aUndoStr );
      87             : 
      88             :             /*  Note has been created before editing, if first undo action is
      89             :                 an insert action. Needed below to decide whether to drop the
      90             :                 undo if editing a new note has been cancelled. */
      91           0 :             bNewNote = (pCalcUndo->GetActionCount() > 0) && pCalcUndo->GetAction( 0 )->ISA( SdrUndoNewObj );
      92             : 
      93             :             // create a "insert note" undo action if needed
      94           0 :             if( bNewNote )
      95           0 :                 pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, aNotePos, pNote->GetNoteData(), true, pCalcUndo ) );
      96             :             else
      97           0 :                 pUndoMgr->AddUndoAction( pCalcUndo );
      98             :         }
      99             :     }
     100             : 
     101           0 :     if( pNote )
     102           0 :         rDoc.LockStreamValid(true);     // only the affected sheet is invalidated below
     103             : 
     104             :     /*  SdrObjEditView::SdrEndTextEdit() may try to delete the entire drawing
     105             :         object, if it does not contain text and has invisible border and fill.
     106             :         This must not happen for note caption objects. They will be removed
     107             :         below together with the cell note if the text is empty (independent of
     108             :         border and area formatting). It is possible to prevent automatic
     109             :         deletion by passing sal_True to this function. The return value changes
     110             :         from SDRENDTEXTEDIT_DELETED to SDRENDTEXTEDIT_SHOULDBEDELETED in this
     111             :         case. */
     112           0 :     /*SdrEndTextEditKind eResult =*/ pView->SdrEndTextEdit( pNote != 0 );
     113             : 
     114             :     // or ScEndTextEdit (with drawview.hxx)
     115           0 :     pViewShell->SetDrawTextUndo( 0 );
     116             : 
     117           0 :     vcl::Cursor* pCur = pWindow->GetCursor();
     118           0 :     if( pCur && pCur->IsVisible() )
     119           0 :         pCur->Hide();
     120             : 
     121           0 :     if( pNote )
     122             :     {
     123             :         // hide the caption object if it is in hidden state
     124           0 :         pNote->ShowCaptionTemp( aNotePos, false );
     125             : 
     126             :         // update author and date
     127           0 :         pNote->AutoStamp();
     128             : 
     129             :         /*  If the entire text has been cleared, the cell note and its caption
     130             :             object have to be removed. */
     131           0 :         SdrTextObj* pTextObject = dynamic_cast< SdrTextObj* >( pObject );
     132           0 :         bool bDeleteNote = !pTextObject || !pTextObject->HasText();
     133           0 :         if( bDeleteNote )
     134             :         {
     135           0 :             if( pUndoMgr )
     136             :             {
     137             :                 // collect the "remove object" drawing undo action created by DeleteNote()
     138           0 :                 pDrawLayer->BeginCalcUndo(false);
     139             :                 // rescue note data before deletion
     140           0 :                 ScNoteData aNoteData( pNote->GetNoteData() );
     141             :                 // delete note from document (removes caption, but does not delete it)
     142           0 :                 rDoc.ReleaseNote(aNotePos);
     143             :                 // create undo action for removed note
     144           0 :                 pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, aNotePos, aNoteData, false, pDrawLayer->GetCalcUndo() ) );
     145             :             }
     146             :             else
     147             :             {
     148           0 :                 rDoc.ReleaseNote(aNotePos);
     149             :             }
     150             :             // ScDocument::DeleteNote has deleted the note that pNote points to
     151           0 :             pNote = 0;
     152             :         }
     153             : 
     154             :         // finalize the undo list action
     155           0 :         if( pUndoMgr )
     156             :         {
     157           0 :             pUndoMgr->LeaveListAction();
     158             : 
     159             :             /*  #i94039# Update the default name "Edit Note" of the undo action
     160             :                 if the note has been created before editing or is deleted due
     161             :                 to deleted text. If the note has been created *and* is deleted,
     162             :                 the last undo action can be removed completely. Note: The
     163             :                 function LeaveListAction() removes the last action by itself,
     164             :                 if it is empty (when result is SDRENDTEXTEDIT_UNCHANGED). */
     165           0 :             if( bNewNote && bDeleteNote )
     166             :             {
     167           0 :                 pUndoMgr->RemoveLastUndoAction();
     168             :             }
     169           0 :             else if( bNewNote || bDeleteNote )
     170             :             {
     171           0 :                 SfxListUndoAction* pAction = dynamic_cast< SfxListUndoAction* >( pUndoMgr->GetUndoAction() );
     172             :                 OSL_ENSURE( pAction, "FuText::StopEditMode - list undo action expected" );
     173           0 :                 if( pAction )
     174           0 :                     pAction->SetComment( ScGlobal::GetRscString( bNewNote ? STR_UNDO_INSERTNOTE : STR_UNDO_DELETENOTE ) );
     175             :             }
     176             :         }
     177             : 
     178             :         // invalidate stream positions only for the affected sheet
     179           0 :         rDoc.LockStreamValid(false);
     180           0 :         if (rDoc.IsStreamValid(aNotePos.Tab()))
     181           0 :             rDoc.SetStreamValid(aNotePos.Tab(), false);
     182             :     }
     183             : }
     184             : 
     185             : // Called following an EndDragObj() to update the new note rectangle position
     186           0 : void FuText::StopDragMode(SdrObject* /*pObject*/)
     187             : {
     188         228 : }
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10