2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 21:25:25 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:25:25 +00:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:25:25 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:25:25 +00:00
|
|
|
* $RCSfile: futext3.cxx,v $
|
2009-03-02 14:19:13 +00:00
|
|
|
* $Revision: 1.15.128.8 $
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:25:25 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:25:25 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:25:25 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:25:25 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-07-21 12:53:42 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_sc.hxx"
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <svx/editeng.hxx>
|
|
|
|
#include <svx/outlobj.hxx>
|
|
|
|
#include <svx/svdocapt.hxx>
|
|
|
|
#include <svx/svdpage.hxx>
|
|
|
|
#include <svx/svdundo.hxx>
|
|
|
|
#include <svx/svdview.hxx>
|
2009-03-02 14:19:13 +00:00
|
|
|
#include <svx/editobj.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <vcl/cursor.hxx>
|
|
|
|
#include <sfx2/objsh.hxx>
|
2004-11-09 17:00:26 +00:00
|
|
|
#include <svx/writingmodeitem.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
#include "global.hxx"
|
|
|
|
#include "drwlayer.hxx"
|
|
|
|
#include "userdat.hxx"
|
|
|
|
#include "tabvwsh.hxx" // oder GetDocument irgendwo
|
|
|
|
#include "document.hxx"
|
|
|
|
#include "editutil.hxx"
|
|
|
|
#include "futext.hxx"
|
2005-02-21 15:01:43 +00:00
|
|
|
#include "docsh.hxx"
|
2008-01-29 14:42:44 +00:00
|
|
|
#include "postit.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "globstr.hrc"
|
2007-12-12 12:20:49 +00:00
|
|
|
#include "attrib.hxx"
|
|
|
|
#include "scitems.hxx"
|
|
|
|
#include "drawview.hxx"
|
2009-03-02 14:19:13 +00:00
|
|
|
#include "undocell.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------
|
|
|
|
// Editieren von Notiz-Legendenobjekten muss immer ueber StopEditMode beendet werden,
|
|
|
|
// damit die Aenderungen ins Dokument uebernommen werden!
|
|
|
|
// (Fontwork-Execute in drawsh und drtxtob passiert nicht fuer Legendenobjekte)
|
2004-11-09 17:00:26 +00:00
|
|
|
// bTextDirection=TRUE means that this function is called from SID_TEXTDIRECTION_XXX(drtxtob.cxx).
|
2000-09-18 16:07:07 +00:00
|
|
|
// ------------------------------------------------------------------------------------
|
|
|
|
|
2009-03-02 14:19:13 +00:00
|
|
|
void FuText::StopEditMode(BOOL /*bTextDirection*/)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
SdrObject* pObject = pView->GetTextEditObject();
|
2009-03-02 14:19:13 +00:00
|
|
|
if( !pObject ) return;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2009-03-02 14:19:13 +00:00
|
|
|
// relock the internal layer that has been unlocked in FuText::SetInEditMode()
|
|
|
|
if ( pObject->GetLayer() == SC_LAYER_INTERN )
|
|
|
|
pView->LockInternalLayer();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2009-03-02 14:19:13 +00:00
|
|
|
ScViewData& rViewData = *pViewShell->GetViewData();
|
|
|
|
ScDocument& rDoc = *rViewData.GetDocument();
|
|
|
|
ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
|
|
|
|
DBG_ASSERT( pDrawLayer && (pDrawLayer == pDrDoc), "FuText::StopEditMode - missing or different drawing layers" );
|
|
|
|
|
|
|
|
ScAddress aNotePos;
|
|
|
|
ScPostIt* pNote = 0;
|
|
|
|
if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObject, rViewData.GetTabNo() ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2009-03-02 14:19:13 +00:00
|
|
|
aNotePos = pCaptData->maStart;
|
|
|
|
pNote = rDoc.GetNote( aNotePos );
|
|
|
|
DBG_ASSERT( pNote && (pNote->GetCaption() == pObject), "FuText::StopEditMode - missing or invalid cell note" );
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2009-03-02 14:19:13 +00:00
|
|
|
ScDocShell* pDocShell = rViewData.GetDocShell();
|
|
|
|
SfxUndoManager* pUndoMgr = rDoc.IsUndoEnabled() ? pDocShell->GetUndoManager() : 0;
|
|
|
|
bool bNewNote = false;
|
|
|
|
if( pNote && pUndoMgr )
|
|
|
|
{
|
|
|
|
/* Put all undo actions already collected (e.g. create caption object)
|
|
|
|
and all following undo actions (text changed) together into a ListAction. */
|
2000-09-18 16:07:07 +00:00
|
|
|
String aUndoStr = ScGlobal::GetRscString( STR_UNDO_EDITNOTE );
|
2009-03-02 14:19:13 +00:00
|
|
|
pUndoMgr->EnterListAction( aUndoStr, aUndoStr );
|
|
|
|
if( SdrUndoGroup* pCalcUndo = pDrawLayer->GetCalcUndo() )
|
|
|
|
{
|
|
|
|
/* Note has been created before editing, if first undo action is
|
|
|
|
an insert action. Needed below to decide whether to drop the
|
|
|
|
undo if editing a new note has been cancelled. */
|
|
|
|
bNewNote = (pCalcUndo->GetActionCount() > 0) && pCalcUndo->GetAction( 0 )->ISA( SdrUndoNewObj );
|
|
|
|
// create a "insert note" undo action if needed
|
|
|
|
if( bNewNote )
|
|
|
|
pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, aNotePos, pNote->GetNoteData(), true, pCalcUndo ) );
|
|
|
|
else
|
|
|
|
pUndoMgr->AddUndoAction( pCalcUndo );
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2009-03-02 14:19:13 +00:00
|
|
|
/* SdrObjEditView::SdrEndTextEdit() may try to delete the entire drawing
|
|
|
|
object, if it does not contain text and has invisible border and fill.
|
|
|
|
This must not happen for note caption objects. They will be removed
|
|
|
|
below together with the cell note if the text is empty (independent of
|
|
|
|
border and area formatting). It is possible to prevent automatic
|
|
|
|
deletion by passing sal_True to this function. The return value changes
|
|
|
|
from SDRENDTEXTEDIT_DELETED to SDRENDTEXTEDIT_SHOULDBEDELETED in this
|
|
|
|
case. */
|
|
|
|
/*SdrEndTextEditKind eResult =*/ pView->SdrEndTextEdit( pNote != 0 );
|
|
|
|
|
|
|
|
// or ScEndTextEdit (with drawview.hxx)
|
|
|
|
pViewShell->SetDrawTextUndo( 0 );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
Cursor* pCur = pWindow->GetCursor();
|
2009-03-02 14:19:13 +00:00
|
|
|
if( pCur && pCur->IsVisible() )
|
2000-09-18 16:07:07 +00:00
|
|
|
pCur->Hide();
|
|
|
|
|
2009-03-02 14:19:13 +00:00
|
|
|
if( pNote )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2009-03-02 14:19:13 +00:00
|
|
|
// hide the caption object if it is in hidden state
|
2009-07-03 12:42:53 +00:00
|
|
|
pNote->ShowCaptionTemp( aNotePos, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2009-03-02 14:19:13 +00:00
|
|
|
// update author and date
|
|
|
|
pNote->AutoStamp();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2009-03-02 14:19:13 +00:00
|
|
|
/* If the entire text has been cleared, the cell note and its caption
|
|
|
|
object have to be removed. */
|
|
|
|
SdrTextObj* pTextObject = dynamic_cast< SdrTextObj* >( pObject );
|
|
|
|
bool bDeleteNote = !pTextObject || !pTextObject->HasText();
|
|
|
|
if( bDeleteNote )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2009-03-02 14:19:13 +00:00
|
|
|
if( pUndoMgr )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2009-03-02 14:19:13 +00:00
|
|
|
// collect the "remove object" drawing undo action created by DeleteNote()
|
|
|
|
pDrawLayer->BeginCalcUndo();
|
|
|
|
// rescue note data before deletion
|
|
|
|
ScNoteData aNoteData( pNote->GetNoteData() );
|
|
|
|
// delete note from document (removes caption, but does not delete it)
|
|
|
|
rDoc.DeleteNote( aNotePos );
|
|
|
|
// create undo action for removed note
|
|
|
|
pUndoMgr->AddUndoAction( new ScUndoReplaceNote( *pDocShell, aNotePos, aNoteData, false, pDrawLayer->GetCalcUndo() ) );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2009-03-02 14:19:13 +00:00
|
|
|
else
|
2004-09-08 12:54:53 +00:00
|
|
|
{
|
2009-03-02 14:19:13 +00:00
|
|
|
rDoc.DeleteNote( aNotePos );
|
2004-09-08 12:54:53 +00:00
|
|
|
}
|
2009-03-02 14:19:13 +00:00
|
|
|
// ScDocument::DeleteNote has deleted the note that pNote points to
|
|
|
|
pNote = 0;
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2009-03-02 14:19:13 +00:00
|
|
|
// finalize the undo list action
|
|
|
|
if( pUndoMgr )
|
|
|
|
{
|
|
|
|
pUndoMgr->LeaveListAction();
|
|
|
|
|
|
|
|
/* #i94039# Update the default name "Edit Note" of the undo action
|
|
|
|
if the note has been created before editing or is deleted due
|
|
|
|
to deleted text. If the note has been created *and* is deleted,
|
|
|
|
the last undo action can be removed completely. Note: The
|
|
|
|
function LeaveListAction() removes the last action by itself,
|
|
|
|
if it is empty (when result is SDRENDTEXTEDIT_UNCHANGED). */
|
|
|
|
if( bNewNote && bDeleteNote )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2009-03-02 14:19:13 +00:00
|
|
|
pUndoMgr->RemoveLastUndoAction();
|
|
|
|
}
|
|
|
|
else if( bNewNote || bDeleteNote )
|
|
|
|
{
|
|
|
|
SfxListUndoAction* pAction = dynamic_cast< SfxListUndoAction* >( pUndoMgr->GetUndoAction() );
|
|
|
|
DBG_ASSERT( pAction, "FuText::StopEditMode - list undo action expected" );
|
|
|
|
if( pAction )
|
|
|
|
pAction->SetComment( ScGlobal::GetRscString( bNewNote ? STR_UNDO_INSERTNOTE : STR_UNDO_DELETENOTE ) );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-08 12:54:53 +00:00
|
|
|
// Called following an EndDragObj() to update the new note rectangle position
|
2009-03-02 14:19:13 +00:00
|
|
|
void FuText::StopDragMode(SdrObject* /*pObject*/)
|
2004-09-08 12:54:53 +00:00
|
|
|
{
|
2009-03-02 14:19:13 +00:00
|
|
|
#if 0 // DR
|
|
|
|
ScViewData& rViewData = *pViewShell->GetViewData();
|
|
|
|
if( ScDrawObjData* pData = ScDrawLayer::GetNoteCaptionData( pObject, rViewData.GetTabNo() ) )
|
2004-09-08 12:54:53 +00:00
|
|
|
{
|
2009-03-02 14:19:13 +00:00
|
|
|
ScDocument& rDoc = *rViewData.GetDocument();
|
|
|
|
const ScAddress& rPos = pData->maStart;
|
|
|
|
ScPostIt* pNote = rDoc.GetNote( rPos );
|
|
|
|
DBG_ASSERT( pNote && (pNote->GetCaption() == pObject), "FuText::StopDragMode - missing or invalid cell note" );
|
|
|
|
if( pNote )
|
2004-09-08 12:54:53 +00:00
|
|
|
{
|
2009-03-02 14:19:13 +00:00
|
|
|
Rectangle aOldRect = pNote->CalcRectangle( rDoc, rPos );
|
|
|
|
Rectangle aNewRect = pObject->GetLogicRect();
|
|
|
|
if( aOldRect != aNewRect )
|
2004-09-08 12:54:53 +00:00
|
|
|
{
|
2009-03-02 14:19:13 +00:00
|
|
|
pNote->UpdateFromRectangle( rDoc, rPos, aNewRect );
|
|
|
|
OutlinerParaObject* pPObj = pCaption->GetOutlinerParaObject();
|
|
|
|
bool bVertical = (pPObj && pPObj->IsVertical());
|
|
|
|
// The new height/width is honoured if property item is reset.
|
|
|
|
if(!bVertical && aNewRect.Bottom() - aNewRect.Top() > aOldRect.Bottom() - aOldRect.Top())
|
2004-09-08 12:54:53 +00:00
|
|
|
{
|
2009-03-02 14:19:13 +00:00
|
|
|
if(pCaption->IsAutoGrowHeight() && !bVertical)
|
2004-09-08 12:54:53 +00:00
|
|
|
{
|
2009-03-02 14:19:13 +00:00
|
|
|
pCaption->SetMergedItem( SdrTextAutoGrowHeightItem( false ) );
|
|
|
|
aNote.SetItemSet( *pDoc, pCaption->GetMergedItemSet() );
|
2004-09-08 12:54:53 +00:00
|
|
|
}
|
2009-03-02 14:19:13 +00:00
|
|
|
}
|
|
|
|
else if(bVertical && aNewRect.Right() - aNewRect.Left() > aOldRect.Right() - aOldRect.Left())
|
|
|
|
{
|
|
|
|
if(pCaption->IsAutoGrowWidth() && bVertical)
|
2004-11-09 17:00:26 +00:00
|
|
|
{
|
2009-03-02 14:19:13 +00:00
|
|
|
pCaption->SetMergedItem( SdrTextAutoGrowWidthItem( false ) );
|
|
|
|
aNote.SetItemSet( *pDoc, pCaption->GetMergedItemSet() );
|
2004-11-09 17:00:26 +00:00
|
|
|
}
|
2004-09-08 12:54:53 +00:00
|
|
|
}
|
2009-03-02 14:19:13 +00:00
|
|
|
pViewShell->SetNote( aTabPos.Col(), aTabPos.Row(), aTabPos.Tab(), aNote );
|
|
|
|
|
|
|
|
// This repaint should not be necessary but it cleans
|
|
|
|
// up the 'marks' left behind by the note handles
|
|
|
|
// now that notes can simultaineously have handles and edit active.
|
|
|
|
ScRange aDrawRange = rDoc.GetRange( rPos.Tab(), aOldRect );
|
|
|
|
// Set Start/End Row to previous/next row to allow for handles.
|
|
|
|
if( aDrawRange.aStart.Row() > 0 )
|
|
|
|
aDrawRange.aStart.IncRow( -1 );
|
|
|
|
if( aDrawRange.aEnd.Row() < MAXROW )
|
|
|
|
aDrawRange.aEnd.IncRow( 1 );
|
|
|
|
ScDocShell* pDocSh = rViewData.GetDocShell();
|
|
|
|
pDocSh->PostPaint( aDrawRange, PAINT_GRID| PAINT_EXTRAS);
|
2004-09-08 12:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-02 14:19:13 +00:00
|
|
|
#endif
|
2004-09-08 12:54:53 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|