Files
libreoffice/sw/source/core/edit/edundo.cxx

258 lines
8.0 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
2011-03-31 10:05:04 +02:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 23:08:29 +00:00
#include <svx/svdview.hxx>
2000-09-18 23:08:29 +00:00
#include <editsh.hxx>
#include <fesh.hxx>
#include <doc.hxx>
#include <IDocumentUndoRedo.hxx>
2000-09-18 23:08:29 +00:00
#include <pam.hxx>
#include <UndoCore.hxx>
2000-09-18 23:08:29 +00:00
#include <swundo.hxx>
#include <dcontact.hxx>
#include <flyfrm.hxx>
#include <frmfmt.hxx>
#include <viewimp.hxx>
#include <docsh.hxx>
#include <pagefrm.hxx>
2000-09-18 23:08:29 +00:00
/** helper function to select all objects in an SdrMarkList;
* implementation: see below */
static void lcl_SelectSdrMarkList( SwEditShell* pShell,
const SdrMarkList* pSdrMarkList );
bool SwEditShell::CursorsLocked() const
{
return GetDoc()->GetDocShell()->GetModel()->hasControllersLocked();
}
void SwEditShell::HandleUndoRedoContext(::sw::UndoRedoContext & rContext)
{
// do nothing if somebody has locked controllers!
if (CursorsLocked())
{
return;
}
SwFrmFmt * pSelFmt(0);
SdrMarkList * pMarkList(0);
rContext.GetSelections(pSelFmt, pMarkList);
if (pSelFmt) // select frame
{
if (RES_DRAWFRMFMT == pSelFmt->Which())
{
SdrObject* pSObj = pSelFmt->FindSdrObject();
static_cast<SwFEShell*>(this)->SelectObj(
pSObj->GetCurrentBoundRect().Center() );
}
else
{
Point aPt;
SwFlyFrm *const pFly =
static_cast<SwFlyFrmFmt*>(pSelFmt)->GetFrm(& aPt, false);
if (pFly)
{
// fdo#36681: Invalidate the content and layout to refresh
// the picture anchoring properly
SwPageFrm* pPageFrm = pFly->FindPageFrmOfAnchor();
pPageFrm->InvalidateFlyLayout();
pPageFrm->InvalidateCntnt();
static_cast<SwFEShell*>(this)->SelectFlyFrm(*pFly, true);
}
}
}
else if (pMarkList)
{
lcl_SelectSdrMarkList( this, pMarkList );
}
else if (GetCrsr()->GetNext() != GetCrsr())
{
// current cursor is the last one:
// go around the ring, to the first cursor
GoNextCrsr();
}
}
bool SwEditShell::Undo(sal_uInt16 const nCount)
2000-09-18 23:08:29 +00:00
{
SET_CURR_SHELL( this );
2011-02-08 08:51:51 +01:00
// current undo state was not saved
::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
bool bRet = false;
2000-09-18 23:08:29 +00:00
StartAllAction();
{
// Actually it should be enough to just work on the current Cursor, i.e. if there is a cycle
// cancel the latter temporarily, so that an insert during Undo is not done in all areas.
2000-09-18 23:08:29 +00:00
KillPams();
SetMark(); // Bound1 and Bound2 in the same Node
2000-09-18 23:08:29 +00:00
ClearMark();
// Keep Cursor - so that we're able to set it at
// the same position for autoformat or autocorrection
SwUndoId nLastUndoId(UNDO_EMPTY);
GetLastUndoInfo(0, & nLastUndoId);
const bool bRestoreCrsr = nCount == 1
&& ( UNDO_AUTOFORMAT == nLastUndoId
|| UNDO_AUTOCORRECT == nLastUndoId
|| UNDO_SETDEFTATTR == nLastUndoId );
2000-09-18 23:08:29 +00:00
Push();
// Destroy stored TableBoxPtr. A dection is only permitted for the new "Box"!
2000-09-18 23:08:29 +00:00
ClearTblBoxCntnt();
RedlineMode_t eOld = GetDoc()->GetRedlineMode();
2000-09-18 23:08:29 +00:00
try {
for (sal_uInt16 i = 0; i < nCount; ++i)
2000-09-18 23:08:29 +00:00
{
bRet = GetDoc()->GetIDocumentUndoRedo().Undo()
|| bRet;
2000-09-18 23:08:29 +00:00
}
2012-01-07 15:50:41 +09:00
} catch (const ::com::sun::star::uno::Exception & e) {
OSL_TRACE("SwEditShell::Undo(): exception caught:\n %s",
OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8)
.getStr());
2000-09-18 23:08:29 +00:00
}
if (bRestoreCrsr)
{ // fdo#39003 Pop does not touch the rest of the cursor ring
KillPams(); // so call this first to get rid of unwanted cursors
}
2000-09-18 23:08:29 +00:00
Pop( !bRestoreCrsr );
GetDoc()->SetRedlineMode( eOld );
GetDoc()->CompressRedlines();
// automatic detection of the new "Box"
2000-09-18 23:08:29 +00:00
SaveTblBoxCntnt();
}
EndAllAction();
2000-09-18 23:08:29 +00:00
return bRet;
}
bool SwEditShell::Redo(sal_uInt16 const nCount)
2000-09-18 23:08:29 +00:00
{
SET_CURR_SHELL( this );
bool bRet = false;
2011-02-08 08:51:51 +01:00
// undo state was not saved
::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
2000-09-18 23:08:29 +00:00
StartAllAction();
{
// Actually it should be enough to just work on the current Cursor, i.e. if there is a cycle
// cancel the latter temporarily, so that an insert during Undo is not done in all areas.
2000-09-18 23:08:29 +00:00
KillPams();
SetMark(); // Bound1 and Bound2 in the same Node
2000-09-18 23:08:29 +00:00
ClearMark();
SwUndoId nFirstRedoId(UNDO_EMPTY);
GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(0, & nFirstRedoId);
const bool bRestoreCrsr = nCount == 1 && UNDO_SETDEFTATTR == nFirstRedoId;
Push();
// Destroy stored TableBoxPtr. A dection is only permitted for the new "Box"!
2000-09-18 23:08:29 +00:00
ClearTblBoxCntnt();
RedlineMode_t eOld = GetDoc()->GetRedlineMode();
2000-09-18 23:08:29 +00:00
try {
for (sal_uInt16 i = 0; i < nCount; ++i)
2000-09-18 23:08:29 +00:00
{
bRet = GetDoc()->GetIDocumentUndoRedo().Redo()
|| bRet;
2000-09-18 23:08:29 +00:00
}
2012-01-07 15:50:41 +09:00
} catch (const ::com::sun::star::uno::Exception & e) {
OSL_TRACE("SwEditShell::Redo(): exception caught:\n %s",
OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8)
.getStr());
2000-09-18 23:08:29 +00:00
}
Pop( !bRestoreCrsr );
2000-09-18 23:08:29 +00:00
GetDoc()->SetRedlineMode( eOld );
GetDoc()->CompressRedlines();
// automatic detection of the new "Box"
2000-09-18 23:08:29 +00:00
SaveTblBoxCntnt();
}
EndAllAction();
2000-09-18 23:08:29 +00:00
return bRet;
}
bool SwEditShell::Repeat(sal_uInt16 const nCount)
2000-09-18 23:08:29 +00:00
{
SET_CURR_SHELL( this );
bool bRet = false;
2000-09-18 23:08:29 +00:00
StartAllAction();
try {
::sw::RepeatContext context(*GetDoc(), *GetCrsr());
bRet = GetDoc()->GetIDocumentUndoRedo().Repeat( context, nCount )
|| bRet;
2012-01-07 15:50:41 +09:00
} catch (const ::com::sun::star::uno::Exception & e) {
OSL_TRACE("SwEditShell::Repeat(): exception caught:\n %s",
OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8)
.getStr());
}
2000-09-18 23:08:29 +00:00
EndAllAction();
return bRet;
}
static void lcl_SelectSdrMarkList( SwEditShell* pShell,
const SdrMarkList* pSdrMarkList )
{
OSL_ENSURE( pShell != NULL, "need shell!" );
OSL_ENSURE( pSdrMarkList != NULL, "need mark list" );
if( pShell->ISA( SwFEShell ) )
{
SwFEShell* pFEShell = static_cast<SwFEShell*>( pShell );
bool bFirst = true;
for( sal_uInt16 i = 0; i < pSdrMarkList->GetMarkCount(); ++i )
{
SdrObject *pObj = pSdrMarkList->GetMark( i )->GetMarkedSdrObj();
if( pObj )
{
pFEShell->SelectObj( Point(), bFirst ? 0 : SW_ADD_SELECT, pObj );
bFirst = false;
}
}
// the old implementation would always unselect
// objects, even if no new ones were selected. If this
// is a problem, we need to re-work this a little.
OSL_ENSURE( pSdrMarkList->GetMarkCount() != 0, "empty mark list" );
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */