Files
libreoffice/sd/source/ui/docshell/docshell.cxx

561 lines
16 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-09-18 16:07:07 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 16:07:07 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 16:07:07 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 16:07:07 +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
*
* 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
*
* 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
*
************************************************************************/
#include "DrawDocShell.hxx"
2000-09-18 16:07:07 +00:00
#include <vcl/svapp.hxx>
#include <sfx2/docfac.hxx>
#include <sfx2/objface.hxx>
2000-09-18 16:07:07 +00:00
#include <svx/svxids.hrc>
2009-12-10 23:06:35 +01:00
#include <svl/srchitem.hxx>
2000-09-18 16:07:07 +00:00
#include <svx/srchdlg.hxx>
#include <editeng/flstitem.hxx>
#include <svl/eitem.hxx>
#include <svl/intitem.hxx>
2000-09-18 16:07:07 +00:00
#include <sfx2/printer.hxx>
#include <sfx2/docfile.hxx>
2000-09-18 16:07:07 +00:00
#include <svx/drawitem.hxx>
#include <sfx2/dispatch.hxx>
#include <svl/whiter.hxx>
#include <svl/itempool.hxx>
2000-09-18 16:07:07 +00:00
#include <svtools/ctrltool.hxx>
#include <svtools/filter.hxx>
#include <sot/clsids.hxx>
#include <svl/cjkoptions.hxx>
#include <svl/visitem.hxx>
2000-09-18 16:07:07 +00:00
#include <svx/svdoutl.hxx>
#include <sfx2/fcontnr.hxx>
2000-09-18 16:07:07 +00:00
#include "app.hrc"
#include "app.hxx"
#include "strmname.h"
#include "stlpool.hxx"
#include "strings.hrc"
#include "View.hxx"
2000-09-18 16:07:07 +00:00
#include "drawdoc.hxx"
#include "sdpage.hxx"
#include "glob.hrc"
#include "res_bmp.hrc"
#include "fupoor.hxx"
#include "fusearch.hxx"
#include "ViewShell.hxx"
2000-09-18 16:07:07 +00:00
#include "sdresid.hxx"
#include "slideshow.hxx"
2000-09-18 16:07:07 +00:00
#include "drawview.hxx"
#include "FrameView.hxx"
#include "unomodel.hxx"
#include "undo/undomanager.hxx"
#include "undo/undofactory.hxx"
#include "OutlineView.hxx"
#include "ViewShellBase.hxx"
using namespace sd;
#define DrawDocShell
#include "sdslots.hxx"
SFX_IMPL_INTERFACE(DrawDocShell, SfxObjectShell, SdResId(0))
{
2004-02-09 13:49:22 +00:00
SFX_CHILDWINDOW_REGISTRATION(SvxSearchDialogWrapper::GetChildWindowId());
}
namespace sd {
2000-09-18 16:07:07 +00:00
GraphicFilter* GetGrfFilter();
/*************************************************************************
|*
|* SFX-Slotmaps und -Definitionen
|*
\************************************************************************/
TYPEINIT1( DrawDocShell, SfxObjectShell );
2000-09-18 16:07:07 +00:00
SFX_IMPL_OBJECTFACTORY(
DrawDocShell,
SvGlobalName(SO3_SIMPRESS_CLASSID),
SFXOBJECTSHELL_STD_NORMAL,
"simpress" )
2000-09-18 16:07:07 +00:00
/*************************************************************************
|*
|* Construct
|*
\************************************************************************/
void DrawDocShell::Construct( bool bClipboard )
2000-09-18 16:07:07 +00:00
{
mbInDestruction = sal_False;
2000-09-18 16:07:07 +00:00
SetSlotFilter(); // setzt Filter zurueck
mbOwnDocument = mpDoc == 0;
if( mbOwnDocument )
mpDoc = new SdDrawDocument(meDocType, this);
// The document has been created so we can call UpdateRefDevice() to set
// the document's ref device.
UpdateRefDevice();
SetBaseModel( new SdXImpressDocument( this, bClipboard ) );
SetPool( &mpDoc->GetItemPool() );
mpUndoManager = new sd::UndoManager;
mpDoc->SetSdrUndoManager( mpUndoManager );
mpDoc->SetSdrUndoFactory( new sd::UndoFactory );
UpdateTablePointers();
SetStyleFamily(5); //CL: eigentlich SFX_STYLE_FAMILY_PSEUDO
2000-09-18 16:07:07 +00:00
}
/*************************************************************************
|*
|* Konstruktor 1
|*
\************************************************************************/
DrawDocShell::DrawDocShell(SfxObjectCreateMode eMode,
sal_Bool bDataObject,
DocumentType eDocumentType) :
SfxObjectShell( eMode == SFX_CREATE_MODE_INTERNAL ? SFX_CREATE_MODE_EMBEDDED : eMode),
mpDoc(NULL),
mpUndoManager(NULL),
mpPrinter(NULL),
mpViewShell(NULL),
mpFontList(NULL),
meDocType(eDocumentType),
mpFilterSIDs(0),
mbSdDataObj(bDataObject),
mbOwnPrinter(sal_False),
2002-08-01 10:30:12 +00:00
mbNewDocument( sal_True )
2000-09-18 16:07:07 +00:00
{
Construct( eMode == SFX_CREATE_MODE_INTERNAL );
2000-09-18 16:07:07 +00:00
}
/*************************************************************************
|*
|* Konstruktor 2
|*
\************************************************************************/
DrawDocShell::DrawDocShell( const sal_uInt64 nModelCreationFlags, sal_Bool bDataObject, DocumentType eDocumentType ) :
SfxObjectShell( nModelCreationFlags ),
mpDoc(NULL),
mpUndoManager(NULL),
mpPrinter(NULL),
mpViewShell(NULL),
mpFontList(NULL),
meDocType(eDocumentType),
mpFilterSIDs(0),
mbSdDataObj(bDataObject),
mbOwnPrinter(sal_False),
mbNewDocument( sal_True )
{
Construct( sal_False );
}
/*************************************************************************
|*
|* Konstruktor 3
|*
\************************************************************************/
2000-09-18 16:07:07 +00:00
DrawDocShell::DrawDocShell(SdDrawDocument* pDoc, SfxObjectCreateMode eMode,
sal_Bool bDataObject,
2000-09-18 16:07:07 +00:00
DocumentType eDocumentType) :
SfxObjectShell(eMode == SFX_CREATE_MODE_INTERNAL ? SFX_CREATE_MODE_EMBEDDED : eMode),
mpDoc(pDoc),
mpUndoManager(NULL),
mpPrinter(NULL),
mpViewShell(NULL),
mpFontList(NULL),
meDocType(eDocumentType),
mpFilterSIDs(0),
mbSdDataObj(bDataObject),
mbOwnPrinter(sal_False),
2002-08-01 10:30:12 +00:00
mbNewDocument( sal_True )
2000-09-18 16:07:07 +00:00
{
Construct( eMode == SFX_CREATE_MODE_INTERNAL );
2000-09-18 16:07:07 +00:00
}
/*************************************************************************
|*
|* Destruktor
|*
\************************************************************************/
DrawDocShell::~DrawDocShell()
2000-09-18 16:07:07 +00:00
{
// Tell all listeners that the doc shell is about to be
// destroyed. This has been introduced for the PreviewRenderer to
// free its view (that uses the item poll of the doc shell) but
// may be usefull in other places as well.
Broadcast(SfxSimpleHint(SFX_HINT_DYING));
mbInDestruction = sal_True;
SetDocShellFunction(0);
2000-09-18 16:07:07 +00:00
delete mpFontList;
if( mpDoc )
mpDoc->SetSdrUndoManager( 0 );
delete mpUndoManager;
if (mbOwnPrinter)
delete mpPrinter;
2000-09-18 16:07:07 +00:00
if( mbOwnDocument )
delete mpDoc;
2000-09-18 16:07:07 +00:00
// damit der Navigator das Verschwinden des Dokuments mitbekommt
SfxBoolItem aItem(SID_NAVIGATOR_INIT, sal_True);
SfxViewFrame* pFrame = mpViewShell ? mpViewShell->GetFrame() : GetFrame();
if( !pFrame )
pFrame = SfxViewFrame::GetFirst( this );
if( pFrame )
pFrame->GetDispatcher()->Execute(
SID_NAVIGATOR_INIT, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aItem, 0L);
2000-09-18 16:07:07 +00:00
}
/*************************************************************************
|*
|* Slot-Stati setzen
|*
\************************************************************************/
void DrawDocShell::GetState(SfxItemSet &rSet)
2000-09-18 16:07:07 +00:00
{
SfxWhichIter aIter( rSet );
sal_uInt16 nWhich = aIter.FirstWhich();
2000-09-18 16:07:07 +00:00
while ( nWhich )
{
sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich)
2000-09-18 16:07:07 +00:00
? GetPool().GetSlotId(nWhich)
: nWhich;
switch ( nSlotId )
{
case SID_SEARCH_ITEM:
{
rSet.Put( *SD_MOD()->GetSearchItem() );
}
break;
case SID_CLOSEDOC:
{
sal_Bool bDisabled = sal_False;
2000-09-18 16:07:07 +00:00
if (bDisabled)
{
rSet.DisableItem(SID_CLOSEDOC);
}
else
{
GetSlotState(SID_CLOSEDOC, SfxObjectShell::GetInterface(), &rSet);
}
}
break;
case SID_SEARCH_OPTIONS:
{
sal_uInt16 nOpt = SEARCH_OPTIONS_SEARCH |
2000-09-18 16:07:07 +00:00
SEARCH_OPTIONS_WHOLE_WORDS |
SEARCH_OPTIONS_BACKWARDS |
SEARCH_OPTIONS_REG_EXP |
SEARCH_OPTIONS_EXACT |
SEARCH_OPTIONS_SIMILARITY |
SEARCH_OPTIONS_SELECTION;
if (!IsReadOnly())
{
nOpt |= SEARCH_OPTIONS_REPLACE;
nOpt |= SEARCH_OPTIONS_REPLACE_ALL;
}
rSet.Put(SfxUInt16Item(nWhich, nOpt));
}
break;
case SID_VERSION:
{
GetSlotState( SID_VERSION, SfxObjectShell::GetInterface(), &rSet );
}
break;
case SID_CHINESE_CONVERSION:
case SID_HANGUL_HANJA_CONVERSION:
{
rSet.Put(SfxVisibilityItem(nWhich, SvtCJKOptions().IsAnyEnabled()));
}
break;
2000-09-18 16:07:07 +00:00
default:
break;
}
nWhich = aIter.NextWhich();
}
SfxViewFrame* pFrame = SfxViewFrame::Current();
2000-09-18 16:07:07 +00:00
if (pFrame)
{
if (rSet.GetItemState(SID_RELOAD) != SFX_ITEM_UNKNOWN)
{
pFrame->GetSlotState(SID_RELOAD,
pFrame->GetInterface(), &rSet);
}
}
}
void DrawDocShell::InPlaceActivate( sal_Bool bActive )
{
ViewShell* pViewSh = NULL;
SfxViewShell* pSfxViewSh = NULL;
SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
std::vector<FrameView*> &rViews = mpDoc->GetFrameViewList();
if( !bActive )
{
std::vector<FrameView*>::iterator pIter;
for ( pIter = rViews.begin(); pIter != rViews.end(); ++pIter )
delete *pIter;
rViews.clear();
while (pSfxViewFrame)
{
// Anzahl FrameViews ermitteln
pSfxViewSh = pSfxViewFrame->GetViewShell();
pViewSh = PTR_CAST( ViewShell, pSfxViewSh );
if ( pViewSh && pViewSh->GetFrameView() )
{
pViewSh->WriteFrameViewData();
rViews.push_back( new FrameView( mpDoc, pViewSh->GetFrameView() ) );
}
pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
}
}
SfxObjectShell::InPlaceActivate( bActive );
if( bActive )
{
for( sal_uInt32 i = 0; pSfxViewFrame && (i < rViews.size()); i++ )
{
// Anzahl FrameViews ermitteln
pSfxViewSh = pSfxViewFrame->GetViewShell();
pViewSh = PTR_CAST( ViewShell, pSfxViewSh );
if ( pViewSh )
{
pViewSh->ReadFrameViewData( rViews[ i ] );
}
pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
}
}
}
2000-09-18 16:07:07 +00:00
/*************************************************************************
|*
|* SFX-Aktivierung
|*
\************************************************************************/
void DrawDocShell::Activate( sal_Bool bMDI)
2000-09-18 16:07:07 +00:00
{
if (bMDI)
{
ApplySlotFilter();
mpDoc->StartOnlineSpelling();
2000-09-18 16:07:07 +00:00
}
}
/*************************************************************************
|*
|* SFX-Deaktivierung
|*
\************************************************************************/
void DrawDocShell::Deactivate( sal_Bool )
2000-09-18 16:07:07 +00:00
{
}
/*************************************************************************
|*
|* SFX-Undomanager zurueckgeben
|*
\************************************************************************/
::svl::IUndoManager* DrawDocShell::GetUndoManager()
2000-09-18 16:07:07 +00:00
{
return mpUndoManager;
2000-09-18 16:07:07 +00:00
}
/*************************************************************************
|*
|* Tabellenzeiger auffrischen
|*
\************************************************************************/
void DrawDocShell::UpdateTablePointers()
2000-09-18 16:07:07 +00:00
{
PutItem( SvxColorListItem( mpDoc->GetColorList(), SID_COLOR_TABLE ) );
PutItem( SvxGradientListItem( mpDoc->GetGradientList(), SID_GRADIENT_LIST ) );
PutItem( SvxHatchListItem( mpDoc->GetHatchList(), SID_HATCH_LIST ) );
PutItem( SvxBitmapListItem( mpDoc->GetBitmapList(), SID_BITMAP_LIST ) );
PutItem( SvxDashListItem( mpDoc->GetDashList(), SID_DASH_LIST ) );
PutItem( SvxLineEndListItem( mpDoc->GetLineEndList(), SID_LINEEND_LIST ) );
2000-09-18 16:07:07 +00:00
UpdateFontList();
2000-09-18 16:07:07 +00:00
}
void DrawDocShell::CancelSearching()
2000-09-18 16:07:07 +00:00
{
if( dynamic_cast<FuSearch*>( mxDocShellFunction.get() ) )
2000-09-18 16:07:07 +00:00
{
SetDocShellFunction(0);
2000-09-18 16:07:07 +00:00
}
}
/*************************************************************************
|*
|* den eingestellten SlotFilter anwenden
|*
\************************************************************************/
void DrawDocShell::ApplySlotFilter() const
2000-09-18 16:07:07 +00:00
{
SfxViewShell* pTestViewShell = SfxViewShell::GetFirst();
2000-09-18 16:07:07 +00:00
while( pTestViewShell )
{
if( pTestViewShell->GetObjectShell()
== const_cast<DrawDocShell*>( this )
&& pTestViewShell->GetViewFrame()
&& pTestViewShell->GetViewFrame()->GetDispatcher() )
{
SfxDispatcher* pDispatcher = pTestViewShell->GetViewFrame()->GetDispatcher();
2000-09-18 16:07:07 +00:00
if( mpFilterSIDs )
pDispatcher->SetSlotFilter( mbFilterEnable, mnFilterCount, mpFilterSIDs );
else
pDispatcher->SetSlotFilter();
2000-09-18 16:07:07 +00:00
if( pDispatcher->GetBindings() )
pDispatcher->GetBindings()->InvalidateAll( sal_True );
}
2000-09-18 16:07:07 +00:00
pTestViewShell = SfxViewShell::GetNext( *pTestViewShell );
}
2000-09-18 16:07:07 +00:00
}
void DrawDocShell::SetModified( sal_Bool bSet /* = sal_True */ )
2000-09-18 16:07:07 +00:00
{
SfxObjectShell::SetModified( bSet );
2000-09-18 16:07:07 +00:00
2011-02-07 22:11:09 +01:00
// change model state, too
// only set the changed state if modification is enabled
if( IsEnableSetModified() )
{
if ( mpDoc )
mpDoc->NbcSetChanged( bSet );
Broadcast( SfxSimpleHint( SFX_HINT_DOCCHANGED ) );
}
2000-09-18 16:07:07 +00:00
}
/*************************************************************************
|*
|* Callback fuer ExecuteSpellPopup()
|*
\************************************************************************/
2011-02-07 22:11:09 +01:00
// ExecuteSpellPopup now handled by DrawDocShell. This is necessary
// to get hands on the outliner and the text object.
IMPL_LINK(DrawDocShell, OnlineSpellCallback, SpellCallbackInfo*, pInfo)
{
SdrObject* pObj = NULL;
SdrOutliner* pOutl = NULL;
if(GetViewShell())
{
pOutl = GetViewShell()->GetView()->GetTextEditOutliner();
pObj = GetViewShell()->GetView()->GetTextEditObject();
}
mpDoc->ImpOnlineSpellCallback(pInfo, pObj, pOutl);
return(0);
}
void DrawDocShell::ClearUndoBuffer()
{
// clear possible undo buffers of outliners
SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
while(pSfxViewFrame)
{
ViewShellBase* pViewShellBase = dynamic_cast< ViewShellBase* >( pSfxViewFrame->GetViewShell() );
if( pViewShellBase )
{
::boost::shared_ptr<ViewShell> pViewSh( pViewShellBase->GetMainViewShell() );
if( pViewSh.get() )
{
::sd::View* pView = pViewSh->GetView();
if( pView )
{
pView->SdrEndTextEdit();
sd::OutlineView* pOutlView = dynamic_cast< sd::OutlineView* >( pView );
if( pOutlView )
{
SdrOutliner* pOutliner = pOutlView->GetOutliner();
if( pOutliner )
pOutliner->GetUndoManager().Clear();
}
}
}
}
pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
}
::svl::IUndoManager* pUndoManager = GetUndoManager();
if(pUndoManager && pUndoManager->GetUndoActionCount())
pUndoManager->Clear();
}
2000-09-18 16:07:07 +00:00
} // end of namespace sd
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */