LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/drawfunc - futext3.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 58 1.7 %
Date: 2012-12-27 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             : 
      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"          // oder GetDocument irgendwo
      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(sal_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.GetNotes( aNotePos.Tab() )->findByAddress( 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 :         String aUndoStr = ScGlobal::GetRscString( STR_UNDO_EDITNOTE );
      85           0 :         pUndoMgr->EnterListAction( aUndoStr, aUndoStr );
      86           0 :         if( SdrUndoGroup* pCalcUndo = pDrawLayer->GetCalcUndo() )
      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             :             // create a "insert note" undo action if needed
      93           0 :             if( bNewNote )
      94           0 :                 pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, aNotePos, pNote->GetNoteData(), true, pCalcUndo ) );
      95             :             else
      96           0 :                 pUndoMgr->AddUndoAction( pCalcUndo );
      97           0 :         }
      98             :     }
      99             : 
     100           0 :     if( pNote )
     101           0 :         rDoc.LockStreamValid(true);     // only the affected sheet is invalidated below
     102             : 
     103             :     /*  SdrObjEditView::SdrEndTextEdit() may try to delete the entire drawing
     104             :         object, if it does not contain text and has invisible border and fill.
     105             :         This must not happen for note caption objects. They will be removed
     106             :         below together with the cell note if the text is empty (independent of
     107             :         border and area formatting). It is possible to prevent automatic
     108             :         deletion by passing sal_True to this function. The return value changes
     109             :         from SDRENDTEXTEDIT_DELETED to SDRENDTEXTEDIT_SHOULDBEDELETED in this
     110             :         case. */
     111           0 :     /*SdrEndTextEditKind eResult =*/ pView->SdrEndTextEdit( pNote != 0 );
     112             : 
     113             :     // or ScEndTextEdit (with drawview.hxx)
     114           0 :     pViewShell->SetDrawTextUndo( 0 );
     115             : 
     116           0 :     Cursor* pCur = pWindow->GetCursor();
     117           0 :     if( pCur && pCur->IsVisible() )
     118           0 :         pCur->Hide();
     119             : 
     120           0 :     if( pNote )
     121             :     {
     122             :         // hide the caption object if it is in hidden state
     123           0 :         pNote->ShowCaptionTemp( aNotePos, false );
     124             : 
     125             :         // update author and date
     126           0 :         pNote->AutoStamp();
     127             : 
     128             :         /*  If the entire text has been cleared, the cell note and its caption
     129             :             object have to be removed. */
     130           0 :         SdrTextObj* pTextObject = dynamic_cast< SdrTextObj* >( pObject );
     131           0 :         bool bDeleteNote = !pTextObject || !pTextObject->HasText();
     132           0 :         if( bDeleteNote )
     133             :         {
     134           0 :             if( pUndoMgr )
     135             :             {
     136             :                 // collect the "remove object" drawing undo action created by DeleteNote()
     137           0 :                 pDrawLayer->BeginCalcUndo();
     138             :                 // rescue note data before deletion
     139           0 :                 ScNoteData aNoteData( pNote->GetNoteData() );
     140             :                 // delete note from document (removes caption, but does not delete it)
     141           0 :                 rDoc.GetNotes( aNotePos.Tab() )->erase( aNotePos );
     142             :                 // create undo action for removed note
     143           0 :                 pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, aNotePos, aNoteData, false, pDrawLayer->GetCalcUndo() ) );
     144             :             }
     145             :             else
     146             :             {
     147           0 :                 rDoc.GetNotes( aNotePos.Tab() )->erase( aNotePos );
     148             :             }
     149             :             // ScDocument::DeleteNote has deleted the note that pNote points to
     150           0 :             pNote = 0;
     151             :         }
     152             : 
     153             :         // finalize the undo list action
     154           0 :         if( pUndoMgr )
     155             :         {
     156           0 :             pUndoMgr->LeaveListAction();
     157             : 
     158             :             /*  #i94039# Update the default name "Edit Note" of the undo action
     159             :                 if the note has been created before editing or is deleted due
     160             :                 to deleted text. If the note has been created *and* is deleted,
     161             :                 the last undo action can be removed completely. Note: The
     162             :                 function LeaveListAction() removes the last action by itself,
     163             :                 if it is empty (when result is SDRENDTEXTEDIT_UNCHANGED). */
     164           0 :             if( bNewNote && bDeleteNote )
     165             :             {
     166           0 :                 pUndoMgr->RemoveLastUndoAction();
     167             :             }
     168           0 :             else if( bNewNote || bDeleteNote )
     169             :             {
     170           0 :                 SfxListUndoAction* pAction = dynamic_cast< SfxListUndoAction* >( pUndoMgr->GetUndoAction() );
     171             :                 OSL_ENSURE( pAction, "FuText::StopEditMode - list undo action expected" );
     172           0 :                 if( pAction )
     173           0 :                     pAction->SetComment( ScGlobal::GetRscString( bNewNote ? STR_UNDO_INSERTNOTE : STR_UNDO_DELETENOTE ) );
     174             :             }
     175             :         }
     176             : 
     177             :         // invalidate stream positions only for the affected sheet
     178           0 :         rDoc.LockStreamValid(false);
     179           0 :         if (rDoc.IsStreamValid(aNotePos.Tab()))
     180           0 :             rDoc.SetStreamValid(aNotePos.Tab(), false);
     181             :     }
     182             : }
     183             : 
     184             : // Called following an EndDragObj() to update the new note rectangle position
     185           0 : void FuText::StopDragMode(SdrObject* /*pObject*/)
     186             : {
     187          15 : }
     188             : 
     189             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10