Update ooo320-m1
[ooovba.git] / sc / source / ui / drawfunc / futext3.cxx
blobf55e454e3aefc027e38121e7c6fa1acf0c71aed0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: futext3.cxx,v $
10 * $Revision: 1.15.128.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include <svx/editeng.hxx>
35 #include <svx/outlobj.hxx>
36 #include <svx/svdocapt.hxx>
37 #include <svx/svdpage.hxx>
38 #include <svx/svdundo.hxx>
39 #include <svx/svdview.hxx>
40 #include <svx/editobj.hxx>
41 #include <vcl/cursor.hxx>
42 #include <sfx2/objsh.hxx>
43 #include <svx/writingmodeitem.hxx>
45 #include "global.hxx"
46 #include "drwlayer.hxx"
47 #include "userdat.hxx"
48 #include "tabvwsh.hxx" // oder GetDocument irgendwo
49 #include "document.hxx"
50 #include "editutil.hxx"
51 #include "futext.hxx"
52 #include "docsh.hxx"
53 #include "postit.hxx"
54 #include "globstr.hrc"
55 #include "attrib.hxx"
56 #include "scitems.hxx"
57 #include "drawview.hxx"
58 #include "undocell.hxx"
60 // ------------------------------------------------------------------------------------
61 // Editieren von Notiz-Legendenobjekten muss immer ueber StopEditMode beendet werden,
62 // damit die Aenderungen ins Dokument uebernommen werden!
63 // (Fontwork-Execute in drawsh und drtxtob passiert nicht fuer Legendenobjekte)
64 // bTextDirection=TRUE means that this function is called from SID_TEXTDIRECTION_XXX(drtxtob.cxx).
65 // ------------------------------------------------------------------------------------
67 void FuText::StopEditMode(BOOL /*bTextDirection*/)
69 SdrObject* pObject = pView->GetTextEditObject();
70 if( !pObject ) return;
72 // relock the internal layer that has been unlocked in FuText::SetInEditMode()
73 if ( pObject->GetLayer() == SC_LAYER_INTERN )
74 pView->LockInternalLayer();
76 ScViewData& rViewData = *pViewShell->GetViewData();
77 ScDocument& rDoc = *rViewData.GetDocument();
78 ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
79 DBG_ASSERT( pDrawLayer && (pDrawLayer == pDrDoc), "FuText::StopEditMode - missing or different drawing layers" );
81 ScAddress aNotePos;
82 ScPostIt* pNote = 0;
83 if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObject, rViewData.GetTabNo() ) )
85 aNotePos = pCaptData->maStart;
86 pNote = rDoc.GetNote( aNotePos );
87 DBG_ASSERT( pNote && (pNote->GetCaption() == pObject), "FuText::StopEditMode - missing or invalid cell note" );
90 ScDocShell* pDocShell = rViewData.GetDocShell();
91 SfxUndoManager* pUndoMgr = rDoc.IsUndoEnabled() ? pDocShell->GetUndoManager() : 0;
92 bool bNewNote = false;
93 if( pNote && pUndoMgr )
95 /* Put all undo actions already collected (e.g. create caption object)
96 and all following undo actions (text changed) together into a ListAction. */
97 String aUndoStr = ScGlobal::GetRscString( STR_UNDO_EDITNOTE );
98 pUndoMgr->EnterListAction( aUndoStr, aUndoStr );
99 if( SdrUndoGroup* pCalcUndo = pDrawLayer->GetCalcUndo() )
101 /* Note has been created before editing, if first undo action is
102 an insert action. Needed below to decide whether to drop the
103 undo if editing a new note has been cancelled. */
104 bNewNote = (pCalcUndo->GetActionCount() > 0) && pCalcUndo->GetAction( 0 )->ISA( SdrUndoNewObj );
105 // create a "insert note" undo action if needed
106 if( bNewNote )
107 pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, aNotePos, pNote->GetNoteData(), true, pCalcUndo ) );
108 else
109 pUndoMgr->AddUndoAction( pCalcUndo );
113 if( pNote )
114 rDoc.LockStreamValid(true); // only the affected sheet is invalidated below
116 /* SdrObjEditView::SdrEndTextEdit() may try to delete the entire drawing
117 object, if it does not contain text and has invisible border and fill.
118 This must not happen for note caption objects. They will be removed
119 below together with the cell note if the text is empty (independent of
120 border and area formatting). It is possible to prevent automatic
121 deletion by passing sal_True to this function. The return value changes
122 from SDRENDTEXTEDIT_DELETED to SDRENDTEXTEDIT_SHOULDBEDELETED in this
123 case. */
124 /*SdrEndTextEditKind eResult =*/ pView->SdrEndTextEdit( pNote != 0 );
126 // or ScEndTextEdit (with drawview.hxx)
127 pViewShell->SetDrawTextUndo( 0 );
129 Cursor* pCur = pWindow->GetCursor();
130 if( pCur && pCur->IsVisible() )
131 pCur->Hide();
133 if( pNote )
135 // hide the caption object if it is in hidden state
136 pNote->ShowCaptionTemp( aNotePos, false );
138 // update author and date
139 pNote->AutoStamp();
141 /* If the entire text has been cleared, the cell note and its caption
142 object have to be removed. */
143 SdrTextObj* pTextObject = dynamic_cast< SdrTextObj* >( pObject );
144 bool bDeleteNote = !pTextObject || !pTextObject->HasText();
145 if( bDeleteNote )
147 if( pUndoMgr )
149 // collect the "remove object" drawing undo action created by DeleteNote()
150 pDrawLayer->BeginCalcUndo();
151 // rescue note data before deletion
152 ScNoteData aNoteData( pNote->GetNoteData() );
153 // delete note from document (removes caption, but does not delete it)
154 rDoc.DeleteNote( aNotePos );
155 // create undo action for removed note
156 pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, aNotePos, aNoteData, false, pDrawLayer->GetCalcUndo() ) );
158 else
160 rDoc.DeleteNote( aNotePos );
162 // ScDocument::DeleteNote has deleted the note that pNote points to
163 pNote = 0;
166 // finalize the undo list action
167 if( pUndoMgr )
169 pUndoMgr->LeaveListAction();
171 /* #i94039# Update the default name "Edit Note" of the undo action
172 if the note has been created before editing or is deleted due
173 to deleted text. If the note has been created *and* is deleted,
174 the last undo action can be removed completely. Note: The
175 function LeaveListAction() removes the last action by itself,
176 if it is empty (when result is SDRENDTEXTEDIT_UNCHANGED). */
177 if( bNewNote && bDeleteNote )
179 pUndoMgr->RemoveLastUndoAction();
181 else if( bNewNote || bDeleteNote )
183 SfxListUndoAction* pAction = dynamic_cast< SfxListUndoAction* >( pUndoMgr->GetUndoAction() );
184 DBG_ASSERT( pAction, "FuText::StopEditMode - list undo action expected" );
185 if( pAction )
186 pAction->SetComment( ScGlobal::GetRscString( bNewNote ? STR_UNDO_INSERTNOTE : STR_UNDO_DELETENOTE ) );
190 // invalidate stream positions only for the affected sheet
191 rDoc.LockStreamValid(false);
192 if (rDoc.IsStreamValid(aNotePos.Tab()))
193 rDoc.SetStreamValid(aNotePos.Tab(), FALSE);
197 // Called following an EndDragObj() to update the new note rectangle position
198 void FuText::StopDragMode(SdrObject* /*pObject*/)
200 #if 0 // DR
201 ScViewData& rViewData = *pViewShell->GetViewData();
202 if( ScDrawObjData* pData = ScDrawLayer::GetNoteCaptionData( pObject, rViewData.GetTabNo() ) )
204 ScDocument& rDoc = *rViewData.GetDocument();
205 const ScAddress& rPos = pData->maStart;
206 ScPostIt* pNote = rDoc.GetNote( rPos );
207 DBG_ASSERT( pNote && (pNote->GetCaption() == pObject), "FuText::StopDragMode - missing or invalid cell note" );
208 if( pNote )
210 Rectangle aOldRect = pNote->CalcRectangle( rDoc, rPos );
211 Rectangle aNewRect = pObject->GetLogicRect();
212 if( aOldRect != aNewRect )
214 pNote->UpdateFromRectangle( rDoc, rPos, aNewRect );
215 OutlinerParaObject* pPObj = pCaption->GetOutlinerParaObject();
216 bool bVertical = (pPObj && pPObj->IsVertical());
217 // The new height/width is honoured if property item is reset.
218 if(!bVertical && aNewRect.Bottom() - aNewRect.Top() > aOldRect.Bottom() - aOldRect.Top())
220 if(pCaption->IsAutoGrowHeight() && !bVertical)
222 pCaption->SetMergedItem( SdrTextAutoGrowHeightItem( false ) );
223 aNote.SetItemSet( *pDoc, pCaption->GetMergedItemSet() );
226 else if(bVertical && aNewRect.Right() - aNewRect.Left() > aOldRect.Right() - aOldRect.Left())
228 if(pCaption->IsAutoGrowWidth() && bVertical)
230 pCaption->SetMergedItem( SdrTextAutoGrowWidthItem( false ) );
231 aNote.SetItemSet( *pDoc, pCaption->GetMergedItemSet() );
234 pViewShell->SetNote( aTabPos.Col(), aTabPos.Row(), aTabPos.Tab(), aNote );
236 // This repaint should not be necessary but it cleans
237 // up the 'marks' left behind by the note handles
238 // now that notes can simultaineously have handles and edit active.
239 ScRange aDrawRange = rDoc.GetRange( rPos.Tab(), aOldRect );
240 // Set Start/End Row to previous/next row to allow for handles.
241 if( aDrawRange.aStart.Row() > 0 )
242 aDrawRange.aStart.IncRow( -1 );
243 if( aDrawRange.aEnd.Row() < MAXROW )
244 aDrawRange.aEnd.IncRow( 1 );
245 ScDocShell* pDocSh = rViewData.GetDocShell();
246 pDocSh->PostPaint( aDrawRange, PAINT_GRID| PAINT_EXTRAS);
250 #endif