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

Generated by: LCOV version 1.10