1*b3f79822SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b3f79822SAndrew Rist * distributed with this work for additional information 6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance 9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at 10*b3f79822SAndrew Rist * 11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*b3f79822SAndrew Rist * 13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b3f79822SAndrew Rist * software distributed under the License is distributed on an 15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the 17*b3f79822SAndrew Rist * specific language governing permissions and limitations 18*b3f79822SAndrew Rist * under the License. 19*b3f79822SAndrew Rist * 20*b3f79822SAndrew Rist *************************************************************/ 21*b3f79822SAndrew Rist 22*b3f79822SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sc.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <editeng/editeng.hxx> 28cdf0e10cSrcweir #include <editeng/outlobj.hxx> 29cdf0e10cSrcweir #include <svx/svdocapt.hxx> 30cdf0e10cSrcweir #include <svx/svdpage.hxx> 31cdf0e10cSrcweir #include <svx/svdundo.hxx> 32cdf0e10cSrcweir #include <svx/svdview.hxx> 33cdf0e10cSrcweir #include <editeng/editobj.hxx> 34cdf0e10cSrcweir #include <vcl/cursor.hxx> 35cdf0e10cSrcweir #include <sfx2/objsh.hxx> 36cdf0e10cSrcweir #include <editeng/writingmodeitem.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include "global.hxx" 39cdf0e10cSrcweir #include "drwlayer.hxx" 40cdf0e10cSrcweir #include "userdat.hxx" 41cdf0e10cSrcweir #include "tabvwsh.hxx" // oder GetDocument irgendwo 42cdf0e10cSrcweir #include "document.hxx" 43cdf0e10cSrcweir #include "editutil.hxx" 44cdf0e10cSrcweir #include "futext.hxx" 45cdf0e10cSrcweir #include "docsh.hxx" 46cdf0e10cSrcweir #include "postit.hxx" 47cdf0e10cSrcweir #include "globstr.hrc" 48cdf0e10cSrcweir #include "attrib.hxx" 49cdf0e10cSrcweir #include "scitems.hxx" 50cdf0e10cSrcweir #include "drawview.hxx" 51cdf0e10cSrcweir #include "undocell.hxx" 52cdf0e10cSrcweir 53cdf0e10cSrcweir // ------------------------------------------------------------------------------------ 54cdf0e10cSrcweir // Editieren von Notiz-Legendenobjekten muss immer ueber StopEditMode beendet werden, 55cdf0e10cSrcweir // damit die Aenderungen ins Dokument uebernommen werden! 56cdf0e10cSrcweir // (Fontwork-Execute in drawsh und drtxtob passiert nicht fuer Legendenobjekte) 57cdf0e10cSrcweir // bTextDirection=sal_True means that this function is called from SID_TEXTDIRECTION_XXX(drtxtob.cxx). 58cdf0e10cSrcweir // ------------------------------------------------------------------------------------ 59cdf0e10cSrcweir 60cdf0e10cSrcweir void FuText::StopEditMode(sal_Bool /*bTextDirection*/) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir SdrObject* pObject = pView->GetTextEditObject(); 63cdf0e10cSrcweir if( !pObject ) return; 64cdf0e10cSrcweir 65cdf0e10cSrcweir // relock the internal layer that has been unlocked in FuText::SetInEditMode() 66cdf0e10cSrcweir if ( pObject->GetLayer() == SC_LAYER_INTERN ) 67cdf0e10cSrcweir pView->LockInternalLayer(); 68cdf0e10cSrcweir 69cdf0e10cSrcweir ScViewData& rViewData = *pViewShell->GetViewData(); 70cdf0e10cSrcweir ScDocument& rDoc = *rViewData.GetDocument(); 71cdf0e10cSrcweir ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); 72cdf0e10cSrcweir DBG_ASSERT( pDrawLayer && (pDrawLayer == pDrDoc), "FuText::StopEditMode - missing or different drawing layers" ); 73cdf0e10cSrcweir 74cdf0e10cSrcweir ScAddress aNotePos; 75cdf0e10cSrcweir ScPostIt* pNote = 0; 76cdf0e10cSrcweir if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObject, rViewData.GetTabNo() ) ) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir aNotePos = pCaptData->maStart; 79cdf0e10cSrcweir pNote = rDoc.GetNote( aNotePos ); 80cdf0e10cSrcweir DBG_ASSERT( pNote && (pNote->GetCaption() == pObject), "FuText::StopEditMode - missing or invalid cell note" ); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir ScDocShell* pDocShell = rViewData.GetDocShell(); 84cdf0e10cSrcweir ::svl::IUndoManager* pUndoMgr = rDoc.IsUndoEnabled() ? pDocShell->GetUndoManager() : 0; 85cdf0e10cSrcweir bool bNewNote = false; 86cdf0e10cSrcweir if( pNote && pUndoMgr ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir /* Put all undo actions already collected (e.g. create caption object) 89cdf0e10cSrcweir and all following undo actions (text changed) together into a ListAction. */ 90cdf0e10cSrcweir String aUndoStr = ScGlobal::GetRscString( STR_UNDO_EDITNOTE ); 91cdf0e10cSrcweir pUndoMgr->EnterListAction( aUndoStr, aUndoStr ); 92cdf0e10cSrcweir if( SdrUndoGroup* pCalcUndo = pDrawLayer->GetCalcUndo() ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir /* Note has been created before editing, if first undo action is 95cdf0e10cSrcweir an insert action. Needed below to decide whether to drop the 96cdf0e10cSrcweir undo if editing a new note has been cancelled. */ 97cdf0e10cSrcweir bNewNote = (pCalcUndo->GetActionCount() > 0) && pCalcUndo->GetAction( 0 )->ISA( SdrUndoNewObj ); 98cdf0e10cSrcweir // create a "insert note" undo action if needed 99cdf0e10cSrcweir if( bNewNote ) 100cdf0e10cSrcweir pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, aNotePos, pNote->GetNoteData(), true, pCalcUndo ) ); 101cdf0e10cSrcweir else 102cdf0e10cSrcweir pUndoMgr->AddUndoAction( pCalcUndo ); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir if( pNote ) 107cdf0e10cSrcweir rDoc.LockStreamValid(true); // only the affected sheet is invalidated below 108cdf0e10cSrcweir 109cdf0e10cSrcweir /* SdrObjEditView::SdrEndTextEdit() may try to delete the entire drawing 110cdf0e10cSrcweir object, if it does not contain text and has invisible border and fill. 111cdf0e10cSrcweir This must not happen for note caption objects. They will be removed 112cdf0e10cSrcweir below together with the cell note if the text is empty (independent of 113cdf0e10cSrcweir border and area formatting). It is possible to prevent automatic 114cdf0e10cSrcweir deletion by passing sal_True to this function. The return value changes 115cdf0e10cSrcweir from SDRENDTEXTEDIT_DELETED to SDRENDTEXTEDIT_SHOULDBEDELETED in this 116cdf0e10cSrcweir case. */ 117cdf0e10cSrcweir /*SdrEndTextEditKind eResult =*/ pView->SdrEndTextEdit( pNote != 0 ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir // or ScEndTextEdit (with drawview.hxx) 120cdf0e10cSrcweir pViewShell->SetDrawTextUndo( 0 ); 121cdf0e10cSrcweir 122cdf0e10cSrcweir Cursor* pCur = pWindow->GetCursor(); 123cdf0e10cSrcweir if( pCur && pCur->IsVisible() ) 124cdf0e10cSrcweir pCur->Hide(); 125cdf0e10cSrcweir 126cdf0e10cSrcweir if( pNote ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir // hide the caption object if it is in hidden state 129cdf0e10cSrcweir pNote->ShowCaptionTemp( aNotePos, false ); 130cdf0e10cSrcweir 131cdf0e10cSrcweir // update author and date 132cdf0e10cSrcweir pNote->AutoStamp(); 133cdf0e10cSrcweir 134cdf0e10cSrcweir /* If the entire text has been cleared, the cell note and its caption 135cdf0e10cSrcweir object have to be removed. */ 136cdf0e10cSrcweir SdrTextObj* pTextObject = dynamic_cast< SdrTextObj* >( pObject ); 137cdf0e10cSrcweir bool bDeleteNote = !pTextObject || !pTextObject->HasText(); 138cdf0e10cSrcweir if( bDeleteNote ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir if( pUndoMgr ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir // collect the "remove object" drawing undo action created by DeleteNote() 143cdf0e10cSrcweir pDrawLayer->BeginCalcUndo(); 144cdf0e10cSrcweir // rescue note data before deletion 145cdf0e10cSrcweir ScNoteData aNoteData( pNote->GetNoteData() ); 146cdf0e10cSrcweir // delete note from document (removes caption, but does not delete it) 147cdf0e10cSrcweir rDoc.DeleteNote( aNotePos ); 148cdf0e10cSrcweir // create undo action for removed note 149cdf0e10cSrcweir pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, aNotePos, aNoteData, false, pDrawLayer->GetCalcUndo() ) ); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir else 152cdf0e10cSrcweir { 153cdf0e10cSrcweir rDoc.DeleteNote( aNotePos ); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir // ScDocument::DeleteNote has deleted the note that pNote points to 156cdf0e10cSrcweir pNote = 0; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir // finalize the undo list action 160cdf0e10cSrcweir if( pUndoMgr ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir pUndoMgr->LeaveListAction(); 163cdf0e10cSrcweir 164cdf0e10cSrcweir /* #i94039# Update the default name "Edit Note" of the undo action 165cdf0e10cSrcweir if the note has been created before editing or is deleted due 166cdf0e10cSrcweir to deleted text. If the note has been created *and* is deleted, 167cdf0e10cSrcweir the last undo action can be removed completely. Note: The 168cdf0e10cSrcweir function LeaveListAction() removes the last action by itself, 169cdf0e10cSrcweir if it is empty (when result is SDRENDTEXTEDIT_UNCHANGED). */ 170cdf0e10cSrcweir if( bNewNote && bDeleteNote ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir pUndoMgr->RemoveLastUndoAction(); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir else if( bNewNote || bDeleteNote ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir SfxListUndoAction* pAction = dynamic_cast< SfxListUndoAction* >( pUndoMgr->GetUndoAction() ); 177cdf0e10cSrcweir DBG_ASSERT( pAction, "FuText::StopEditMode - list undo action expected" ); 178cdf0e10cSrcweir if( pAction ) 179cdf0e10cSrcweir pAction->SetComment( ScGlobal::GetRscString( bNewNote ? STR_UNDO_INSERTNOTE : STR_UNDO_DELETENOTE ) ); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir // invalidate stream positions only for the affected sheet 184cdf0e10cSrcweir rDoc.LockStreamValid(false); 185cdf0e10cSrcweir if (rDoc.IsStreamValid(aNotePos.Tab())) 186cdf0e10cSrcweir rDoc.SetStreamValid(aNotePos.Tab(), sal_False); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir // Called following an EndDragObj() to update the new note rectangle position 191cdf0e10cSrcweir void FuText::StopDragMode(SdrObject* /*pObject*/) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir #if 0 // DR 194cdf0e10cSrcweir ScViewData& rViewData = *pViewShell->GetViewData(); 195cdf0e10cSrcweir if( ScDrawObjData* pData = ScDrawLayer::GetNoteCaptionData( pObject, rViewData.GetTabNo() ) ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir ScDocument& rDoc = *rViewData.GetDocument(); 198cdf0e10cSrcweir const ScAddress& rPos = pData->maStart; 199cdf0e10cSrcweir ScPostIt* pNote = rDoc.GetNote( rPos ); 200cdf0e10cSrcweir DBG_ASSERT( pNote && (pNote->GetCaption() == pObject), "FuText::StopDragMode - missing or invalid cell note" ); 201cdf0e10cSrcweir if( pNote ) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir Rectangle aOldRect = pNote->CalcRectangle( rDoc, rPos ); 204cdf0e10cSrcweir Rectangle aNewRect = pObject->GetLogicRect(); 205cdf0e10cSrcweir if( aOldRect != aNewRect ) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir pNote->UpdateFromRectangle( rDoc, rPos, aNewRect ); 208cdf0e10cSrcweir OutlinerParaObject* pPObj = pCaption->GetOutlinerParaObject(); 209cdf0e10cSrcweir bool bVertical = (pPObj && pPObj->IsVertical()); 210cdf0e10cSrcweir // The new height/width is honoured if property item is reset. 211cdf0e10cSrcweir if(!bVertical && aNewRect.Bottom() - aNewRect.Top() > aOldRect.Bottom() - aOldRect.Top()) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir if(pCaption->IsAutoGrowHeight() && !bVertical) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir pCaption->SetMergedItem( SdrTextAutoGrowHeightItem( false ) ); 216cdf0e10cSrcweir aNote.SetItemSet( *pDoc, pCaption->GetMergedItemSet() ); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir } 219cdf0e10cSrcweir else if(bVertical && aNewRect.Right() - aNewRect.Left() > aOldRect.Right() - aOldRect.Left()) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir if(pCaption->IsAutoGrowWidth() && bVertical) 222cdf0e10cSrcweir { 223cdf0e10cSrcweir pCaption->SetMergedItem( SdrTextAutoGrowWidthItem( false ) ); 224cdf0e10cSrcweir aNote.SetItemSet( *pDoc, pCaption->GetMergedItemSet() ); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir } 227cdf0e10cSrcweir pViewShell->SetNote( aTabPos.Col(), aTabPos.Row(), aTabPos.Tab(), aNote ); 228cdf0e10cSrcweir 229cdf0e10cSrcweir // This repaint should not be necessary but it cleans 230cdf0e10cSrcweir // up the 'marks' left behind by the note handles 231cdf0e10cSrcweir // now that notes can simultaineously have handles and edit active. 232cdf0e10cSrcweir ScRange aDrawRange = rDoc.GetRange( rPos.Tab(), aOldRect ); 233cdf0e10cSrcweir // Set Start/End Row to previous/next row to allow for handles. 234cdf0e10cSrcweir if( aDrawRange.aStart.Row() > 0 ) 235cdf0e10cSrcweir aDrawRange.aStart.IncRow( -1 ); 236cdf0e10cSrcweir if( aDrawRange.aEnd.Row() < MAXROW ) 237cdf0e10cSrcweir aDrawRange.aEnd.IncRow( 1 ); 238cdf0e10cSrcweir ScDocShell* pDocSh = rViewData.GetDocShell(); 239cdf0e10cSrcweir pDocSh->PostPaint( aDrawRange, PAINT_GRID| PAINT_EXTRAS); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir } 242cdf0e10cSrcweir } 243cdf0e10cSrcweir #endif 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246