Files
libreoffice/svx/source/svdraw/svdoole2.cxx

1323 lines
38 KiB
C++
Raw Normal View History

2000-09-18 16:07:07 +00:00
/*************************************************************************
*
* $RCSfile: svdoole2.cxx,v $
*
* $Revision: 1.36 $
2000-09-18 16:07:07 +00:00
*
* last change: $Author: vg $ $Date: 2003-05-26 09:06:45 $
2000-09-18 16:07:07 +00:00
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library 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 for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (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.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef _COM_SUN_STAR_UTIL_XMODIFYBROADCASTER_HPP_
#include <com/sun/star/util/XModifyBroadcaster.hpp>
#endif
2000-10-23 11:22:53 +00:00
#include <comphelper/processfactory.hxx>
2000-09-18 16:07:07 +00:00
#ifndef _IPOBJ_HXX //autogen
#include <so3/ipobj.hxx>
#endif
2001-09-18 09:47:27 +00:00
#ifndef _PERSIST_HXX
#include <so3/persist.hxx>
#endif
2000-09-18 16:07:07 +00:00
#ifndef _SFX_INTERNO_HXX
#include <sfx2/interno.hxx>
#endif
#ifndef _SVDPAGV_HXX
#include <svdpagv.hxx>
#endif
#ifndef _GLOBNAME_HXX
#include <tools/globname.hxx>
#endif
#ifndef _IPCLIENT_HXX //autogen
#include <so3/ipclient.hxx>
#endif
#ifndef _SV_JOBSET_HXX
#include <vcl/jobset.hxx>
#endif
#ifndef _SO_CLSIDS_HXX
#include <so3/clsids.hxx>
#endif
#include <sot/formats.hxx>
2000-09-18 16:07:07 +00:00
#ifndef _IPENV_HXX //autogen
#include <so3/ipenv.hxx>
#endif
#ifndef _PSEUDO_HXX
#include <so3/pseudo.hxx>
#endif
#ifndef _SVXLINKMGR_HXX //autogen
#include <linkmgr.hxx>
#endif
2001-06-22 14:46:24 +00:00
#ifndef SVTOOLS_TRANSFER_HXX
#include <svtools/transfer.hxx>
#endif
2000-09-18 16:07:07 +00:00
#include "svdoole2.hxx"
#include <svtools/solar.hrc>
#include "svdxout.hxx"
#ifndef SVTOOLS_URIHELPER_HXX
#include <svtools/urihelper.hxx>
#endif
#include "svdpagv.hxx"
#include "svdmodel.hxx"
#include "svdio.hxx"
#include "svdglob.hxx" // Stringcache
#include "svdstr.hrc" // Objektname
#include "svdetc.hxx"
#include "svdview.hxx"
#include "unomlstr.hxx"
using namespace ::rtl;
using namespace ::com::sun::star;
////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef SO2_DECL_SVINPLACEOBJECT_DEFINED
#define SO2_DECL_SVINPLACEOBJECT_DEFINED
SO2_DECL_REF(SvInPlaceObject)
#endif
class SdrOle2ObjImpl
{
public:
GDIMetaFile* pMetaFile; // Metafile fuer GetMtf kopieren und merken
GraphicObject* pGraphicObject;
String aPersistName; // name of object in persist
// #107645#
// New local var to avoid repeated loading if load of OLE2 fails
sal_Bool mbLoadingOLEObjectFailed;
bool mbConnected;
};
2000-09-18 16:07:07 +00:00
////////////////////////////////////////////////////////////////////////////////////////////////////
// Predicate determining whether the given OLE is an internal math
// object
static bool ImplIsMathObj( const SvInPlaceObjectRef& rObjRef )
{
if( !rObjRef.Is() )
return false;
SvGlobalName aClassName( rObjRef->GetClassName() );
if( aClassName == SvGlobalName(SO3_SM_CLASSID_30) ||
aClassName == SvGlobalName(SO3_SM_CLASSID_40) ||
aClassName == SvGlobalName(SO3_SM_CLASSID_50) ||
aClassName == SvGlobalName(SO3_SM_CLASSID_60) ||
aClassName == SvGlobalName(SO3_SM_CLASSID) )
{
return true;
}
else
{
return false;
}
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
TYPEINIT1(SdrOle2Obj,SdrRectObj);
SdrOle2Obj::SdrOle2Obj(FASTBOOL bFrame_)
{
bInDestruction = FALSE;
2000-09-18 16:07:07 +00:00
Init();
ppObjRef=new SvInPlaceObjectRef;
bFrame=bFrame_;
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
SdrOle2Obj::SdrOle2Obj(const SvInPlaceObjectRef& rNewObjRef, FASTBOOL bFrame_)
{
bInDestruction = FALSE;
2000-09-18 16:07:07 +00:00
Init();
ppObjRef=new SvInPlaceObjectRef(rNewObjRef);
bFrame=bFrame_;
SvInPlaceObjectRef& rIPRef = *ppObjRef;
if (rIPRef.Is() &&
(rIPRef->GetMiscStatus() & SVOBJ_MISCSTATUS_NOTRESIZEABLE) )
{
SetResizeProtect(TRUE);
}
// #108759# For math objects, set closed state to transparent
if( ImplIsMathObj( *ppObjRef ) )
SetClosedObj( false );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
SdrOle2Obj::SdrOle2Obj(const SvInPlaceObjectRef& rNewObjRef, const XubString& rNewObjName, FASTBOOL bFrame_)
{
bInDestruction = FALSE;
2000-09-18 16:07:07 +00:00
Init();
ppObjRef=new SvInPlaceObjectRef(rNewObjRef);
mpImpl->aPersistName = rNewObjName;
2000-09-18 16:07:07 +00:00
bFrame=bFrame_;
SvInPlaceObjectRef& rIPRef = *ppObjRef;
if (rIPRef.Is() &&
(rIPRef->GetMiscStatus() & SVOBJ_MISCSTATUS_NOTRESIZEABLE) )
{
SetResizeProtect(TRUE);
}
// #108759# For math objects, set closed state to transparent
if( ImplIsMathObj( *ppObjRef ) )
SetClosedObj( false );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
SdrOle2Obj::SdrOle2Obj(const SvInPlaceObjectRef& rNewObjRef, const XubString& rNewObjName, const Rectangle& rNewRect, FASTBOOL bFrame_):
SdrRectObj(rNewRect)
{
bInDestruction = FALSE;
2000-09-18 16:07:07 +00:00
Init();
ppObjRef=new SvInPlaceObjectRef(rNewObjRef);
mpImpl->aPersistName = rNewObjName;
2000-09-18 16:07:07 +00:00
bFrame=bFrame_;
SvInPlaceObjectRef& rIPRef = *ppObjRef;
if (rIPRef.Is() &&
(rIPRef->GetMiscStatus() & SVOBJ_MISCSTATUS_NOTRESIZEABLE) )
{
SetResizeProtect(TRUE);
}
// #108759# For math objects, set closed state to transparent
if( ImplIsMathObj( *ppObjRef ) )
SetClosedObj( false );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::Init()
{
mpImpl = new SdrOle2ObjImpl;
2000-09-18 16:07:07 +00:00
pModifyListener = NULL;
pGraphic=NULL;
mpImpl->pMetaFile=NULL;
mpImpl->pGraphicObject=NULL;
// #107645#
// init to start situation, loading did not fail
mpImpl->mbLoadingOLEObjectFailed = sal_False;
mpImpl->mbConnected = false;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
SdrOle2Obj::~SdrOle2Obj()
{
bInDestruction = TRUE;
2000-09-18 16:07:07 +00:00
// Aus Cache entfernen
GetSdrGlobalData().GetOLEObjCache().RemoveObj(this);
SvInPlaceObjectRef aRef( *ppObjRef );
2000-09-18 16:07:07 +00:00
2001-04-12 09:06:03 +00:00
Disconnect();
2000-09-18 16:07:07 +00:00
if(pModel && aRef.Is())
{
2000-09-18 16:07:07 +00:00
SvPersist* pPers=pModel->GetPersist();
if(pPers!=NULL)
{
pPers->Remove(aRef);
2000-09-18 16:07:07 +00:00
}
}
aRef.Clear();
2000-09-18 16:07:07 +00:00
delete ppObjRef;
if(pGraphic!=NULL)
delete pGraphic;
if(mpImpl->pMetaFile!=NULL)
delete mpImpl->pMetaFile;
if(mpImpl->pGraphicObject!=NULL)
delete mpImpl->pGraphicObject;
2000-09-18 16:07:07 +00:00
if(pModifyListener)
{
pModifyListener->invalidate();
pModifyListener->release();
pModifyListener = NULL;
}
delete mpImpl;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::SetGraphic(const Graphic* pGrf)
{
if ( pGraphic )
{
delete pGraphic;
pGraphic = NULL;
delete mpImpl->pGraphicObject;
mpImpl->pGraphicObject = NULL;
2000-09-18 16:07:07 +00:00
}
if (pGrf!=NULL)
{
2000-09-18 16:07:07 +00:00
pGraphic = new Graphic(*pGrf);
mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
}
2000-09-18 16:07:07 +00:00
if ( ppObjRef->Is() && pGrf )
SendRepaintBroadcast();
SetChanged();
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
FASTBOOL SdrOle2Obj::IsEmpty() const
{
return !ppObjRef->Is();
}
// -----------------------------------------------------------------------------
2001-04-12 09:06:03 +00:00
void SdrOle2Obj::Connect()
2000-09-18 16:07:07 +00:00
{
if(pModel && mpImpl->aPersistName.Len())
2000-09-18 16:07:07 +00:00
{
SvPersist* pPers=pModel->GetPersist();
2001-04-12 09:06:03 +00:00
if (pPers!=NULL)
2000-09-18 16:07:07 +00:00
{
SvInfoObjectRef xIObj;
SvInfoObject* pInfo = pPers->Find(mpImpl->aPersistName);
2000-09-18 16:07:07 +00:00
if (!pInfo)
{
2001-04-12 09:06:03 +00:00
if ( !ppObjRef->Is() )
GetObjRef(); // try to load inplace object
xIObj = pInfo = new SvEmbeddedInfoObject(*ppObjRef,mpImpl->aPersistName);
2000-09-18 16:07:07 +00:00
}
if ( !pPers->HasObject(mpImpl->aPersistName) )
2000-09-18 16:07:07 +00:00
{
pPers->Move(pInfo, mpImpl->aPersistName);
2000-09-18 16:07:07 +00:00
}
else
{
pInfo->SetDeleted(FALSE);
}
}
// In Cache einfuegen
GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
}
if ( ppObjRef->Is() && (*ppObjRef)->GetMiscStatus() & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
{
if (pModel && pModel->GetRefDevice() &&
pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
{
// Kein RefDevice oder RefDevice kein Printer
BOOL bModified = (*ppObjRef)->IsModified();
Printer* pPrinter = (Printer*) pModel->GetRefDevice();
(*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
(*ppObjRef)->SetModified( bModified );
}
}
if( !IsEmpty() )
{
// register modify listener
if( pModifyListener == NULL )
{
((SdrOle2Obj*)this)->pModifyListener = new SvxUnoShapeModifyListener( (SdrOle2Obj*)this );
pModifyListener->acquire();
}
uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
if( xBC.is() && pModifyListener )
{
uno::Reference< util::XModifyListener > xListener( pModifyListener );
xBC->addModifyListener( xListener );
}
mpImpl->mbConnected = true;
2000-09-18 16:07:07 +00:00
}
}
// -----------------------------------------------------------------------------
2001-04-12 09:06:03 +00:00
void SdrOle2Obj::Disconnect()
2000-09-18 16:07:07 +00:00
{
if( !mpImpl->mbConnected )
return;
if( !IsEmpty() && mpImpl->aPersistName.Len() )
2000-09-18 16:07:07 +00:00
{
uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
if( xBC.is() && pModifyListener )
{
uno::Reference< util::XModifyListener > xListener( pModifyListener );
xBC->removeModifyListener( xListener );
}
}
if (pModel && mpImpl->aPersistName.Len() )
2000-09-18 16:07:07 +00:00
{
if( pModel->IsInDestruction() )
{
*ppObjRef = NULL;
}
else
{
SvPersist* pPers = pModel->GetPersist();
2000-09-18 16:07:07 +00:00
if (pPers)
{
SvInfoObject* pInfo = pPers->Find(mpImpl->aPersistName);
2000-09-18 16:07:07 +00:00
if (pInfo)
{
pInfo->SetDeleted(TRUE);
pInfo->SetObj(0);
}
}
2000-09-18 16:07:07 +00:00
if ( ppObjRef->Is() )
(*ppObjRef)->DoClose();
2000-09-18 16:07:07 +00:00
}
// Aus Cache entfernen
GetSdrGlobalData().GetOLEObjCache().RemoveObj(this);
if ( ppObjRef->Is() )
ppObjRef->Clear();
2000-09-18 16:07:07 +00:00
}
mpImpl->mbConnected = false;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::SetModel(SdrModel* pNewModel)
{
FASTBOOL bChg = pNewModel!=pModel;
2000-09-18 16:07:07 +00:00
if( bChg )
Disconnect(); // mit dem alten Namen
2000-09-18 16:07:07 +00:00
if( pModel && pNewModel )
2000-09-18 16:07:07 +00:00
{
SvPersist* pDestPers = pNewModel->GetPersist();
SvPersist* pSrcPers = pModel->GetPersist();
if( pDestPers && pSrcPers && ( pDestPers != pSrcPers ) )
{
ImpCopyObject( *pSrcPers, *pDestPers, mpImpl->aPersistName );
}
2000-09-18 16:07:07 +00:00
}
SdrRectObj::SetModel( pNewModel );
if( bChg )
Connect();
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::SetPage(SdrPage* pNewPage)
{
FASTBOOL bRemove=pNewPage==NULL && pPage!=NULL;
FASTBOOL bInsert=pNewPage!=NULL && pPage==NULL;
2001-04-12 09:06:03 +00:00
if (bRemove) Disconnect();
2000-09-18 16:07:07 +00:00
SdrRectObj::SetPage(pNewPage);
2001-04-12 09:06:03 +00:00
if (bInsert) Connect();
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::SetObjRef(const SvInPlaceObjectRef& rNewObjRef)
{
if( rNewObjRef == *ppObjRef )
return;
2001-04-12 09:06:03 +00:00
Disconnect();
2000-09-18 16:07:07 +00:00
*ppObjRef=rNewObjRef;
SvInPlaceObjectRef& rIPRef = *ppObjRef;
if (rIPRef.Is() &&
(rIPRef->GetMiscStatus() & SVOBJ_MISCSTATUS_NOTRESIZEABLE) )
{
SetResizeProtect(TRUE);
}
// #108759# For math objects, set closed state to transparent
if( ImplIsMathObj( *ppObjRef ) )
SetClosedObj( false );
2001-04-12 09:06:03 +00:00
Connect();
2000-09-18 16:07:07 +00:00
SetChanged();
SendRepaintBroadcast();
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::SetClosedObj( bool bIsClosed )
{
// #108759# Allow changes to the closed state of OLE objects
bClosedObj = bIsClosed;
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
FASTBOOL SdrOle2Obj::HasSetName() const
{
return TRUE;
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::SetName(const XubString& rStr)
{
aName = rStr;
2000-09-18 16:07:07 +00:00
SetChanged();
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
XubString SdrOle2Obj::GetName() const
{
return aName;
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::SetPersistName( const String& rPersistName )
{
mpImpl->aPersistName = rPersistName;
SetChanged();
}
// -----------------------------------------------------------------------------
String SdrOle2Obj::GetPersistName() const
{
return mpImpl->aPersistName;
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
{
rInfo.bRotateFreeAllowed=FALSE;
rInfo.bRotate90Allowed =FALSE;
rInfo.bMirrorFreeAllowed=FALSE;
rInfo.bMirror45Allowed =FALSE;
rInfo.bMirror90Allowed =FALSE;
rInfo.bTransparenceAllowed = FALSE;
rInfo.bGradientAllowed = FALSE;
rInfo.bShearAllowed =FALSE;
rInfo.bEdgeRadiusAllowed=FALSE;
2000-09-18 16:07:07 +00:00
rInfo.bNoOrthoDesired =FALSE;
rInfo.bCanConvToPath =FALSE;
rInfo.bCanConvToPoly =FALSE;
rInfo.bCanConvToPathLineToArea=FALSE;
rInfo.bCanConvToPolyLineToArea=FALSE;
rInfo.bCanConvToContour = FALSE;
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
UINT16 SdrOle2Obj::GetObjIdentifier() const
{
return bFrame ? UINT16(OBJ_FRAME) : UINT16(OBJ_OLE2);
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
FASTBOOL SdrOle2Obj::Paint(ExtOutputDevice& rOut, const SdrPaintInfoRec& rInfoRec) const
{
FASTBOOL bOk=TRUE;
if( !pGraphic )
GetObjRef(); // try to load inplace object
if (ppObjRef->Is())
{
if( !bSizProt && (*ppObjRef)->GetMiscStatus() & SVOBJ_MISCSTATUS_NOTRESIZEABLE )
( (SdrOle2Obj*) this)->bSizProt = TRUE;
const SvEditObjectProtocol& rProt=(*ppObjRef)->GetProtocol();
OutputDevice* pOut=rOut.GetOutDev();
if (!rProt.IsInPlaceActive() || (*ppObjRef)->GetIPClient()->GetEnv()->GetEditWin()!=pOut)
{
if ((rInfoRec.nPaintMode & SDRPAINTMODE_DRAFTGRAF) ==0)
{
if (((*ppObjRef)->GetMiscStatus() & SVOBJ_MISCSTATUS_ACTIVATEWHENVISIBLE))
{
// PlugIn-Objekt connecten
if (rInfoRec.pPV!=NULL)
{
SdrOle2Obj* pOle2Obj = (SdrOle2Obj*) this;
SdrView* pSdrView = (SdrView*) &rInfoRec.pPV->GetView();
pSdrView->DoConnect(pOle2Obj);
}
}
// don't call DoDraw if this <20>s a special object and SDRPAINTMODE_HIDEDRAFTGRAF is set
if( ( ( (*ppObjRef)->GetMiscStatus() & SVOBJ_MISCSTATUS_SPECIALOBJECT ) == 0 ) ||
( ( rInfoRec.nPaintMode & SDRPAINTMODE_HIDEDRAFTGRAF ) == 0 ) )
{
// #108759# Temporarily set the current background
// color, since OLEs rely on that during
// auto-colored text rendering
Wallpaper aOldBg( pOut->GetBackground() );
if( rInfoRec.pPV && GetPage() )
pOut->SetBackground( rInfoRec.pPV->GetView().CalcBackgroundColor( GetSnapRect(),
rInfoRec.pPV->GetVisibleLayers(),
*GetPage() ) );
pOut->Push( PUSH_CLIPREGION );
pOut->IntersectClipRegion( aRect );
(*ppObjRef)->DoDraw(pOut,aRect.TopLeft(),aRect.GetSize(),JobSetup());
pOut->Pop();
// #108759# Restore old background
pOut->SetBackground( aOldBg );
}
2000-09-18 16:07:07 +00:00
}
else if( ( rInfoRec.nPaintMode & SDRPAINTMODE_HIDEDRAFTGRAF ) == 0 )
2000-09-18 16:07:07 +00:00
{ // sonst SDRPAINTMODE_DRAFTGRAF
Polygon aPoly(Rect2Poly(aRect,aGeo));
pOut->SetLineColor(Color(COL_BLACK));
pOut->DrawPolyLine(aPoly);
pOut->DrawLine(aPoly[0],aPoly[2]);
pOut->DrawLine(aPoly[1],aPoly[3]);
}
}
}
else if ( pGraphic )
{
OutputDevice* pOutDev=rOut.GetOutDev();
if( IsEmptyPresObj() )
{
2001-03-30 14:50:46 +00:00
const MapMode aDstMapMode( pOutDev->GetMapMode().GetMapUnit() );
Point aPos(aRect.Center());
Size aDstSize;
if( pGraphic->GetPrefMapMode().GetMapUnit() == MAP_PIXEL )
aDstSize = pOutDev->PixelToLogic( pGraphic->GetPrefSize(), aDstMapMode );
else
aDstSize = pOutDev->LogicToLogic( pGraphic->GetPrefSize(), pGraphic->GetPrefMapMode(), aDstMapMode );
aPos.X()-=aDstSize.Width() /2;
aPos.Y()-=aDstSize.Height()/2;
2000-09-18 16:07:07 +00:00
if (aPos.X() >= aRect.Left() && aPos.Y() >= aRect.Top())
2001-03-30 14:50:46 +00:00
pGraphic->Draw(pOutDev,aPos, aDstSize);
2000-09-18 16:07:07 +00:00
svtools::ColorConfig aColorConfig;
svtools::ColorConfigValue aColor( aColorConfig.GetColorValue( svtools::OBJECTBOUNDARIES ) );
2002-04-29 13:32:45 +00:00
if( aColor.bIsVisible )
{
pOutDev->SetFillColor();
pOutDev->SetLineColor( aColor.nColor );
pOutDev->DrawRect(aRect);
}
2000-09-18 16:07:07 +00:00
}
else
pGraphic->Draw( pOutDev, aRect.TopLeft(), aRect.GetSize() );
2000-09-18 16:07:07 +00:00
}
// #100499# OLE without context and without bitmap, do the same as
// for empty groups, additionally draw empty OLE bitmap
else
{
if(!rInfoRec.bPrinter && rInfoRec.aPaintLayer.IsSet(nLayerId))
{
OutputDevice* pOutDev = rOut.GetOutDev();
pOutDev->SetFillInBrush(Brush(BRUSH_NULL));
pOutDev->SetPen(Color(COL_LIGHTGRAY));
pOutDev->DrawRect(aOutRect);
Bitmap aBitmap(ResId(BMP_OLEOBJ, ImpGetResMgr()));
Rectangle aSnapRect(GetSnapRect());
Size aBitmapSize(pOutDev->PixelToLogic(aBitmap.GetSizePixel()));
pOutDev->DrawBitmap(
aSnapRect.Center() - Point(aBitmapSize.Width() / 2, aBitmapSize.Height() / 2),
aBitmapSize,
aBitmap);
}
}
2000-09-18 16:07:07 +00:00
if (HasText())
{
bOk=SdrTextObj::Paint(rOut,rInfoRec);
}
return bOk;
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
SdrObject* SdrOle2Obj::CheckHit(const Point& rPnt, USHORT nTol, const SetOfByte* pVisiLayer) const
{
return ImpCheckHit(rPnt,nTol,pVisiLayer,TRUE,TRUE);
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::TakeObjNameSingul(XubString& rName) const
{
rName = ImpGetResStr(bFrame ? STR_ObjNameSingulFrame : STR_ObjNameSingulOLE2);
2000-09-18 16:07:07 +00:00
if( aName.Len() )
2000-09-18 16:07:07 +00:00
{
rName.AppendAscii(" '");
rName += aName;
rName += sal_Unicode('\'');
}
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::TakeObjNamePlural(XubString& rName) const
{
rName=ImpGetResStr(bFrame ? STR_ObjNamePluralFrame : STR_ObjNamePluralOLE2);
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::ImpAssign( const SdrObject& rObj, SdrPage* pNewPage, SdrModel* pNewModel )
2000-09-18 16:07:07 +00:00
{
const SdrOle2Obj& rOle2Obj = static_cast< const SdrOle2Obj& >( rObj );
if( pModel )
Disconnect();
SdrRectObj::operator=( rObj );
// #108867# Manually copying bClosedObj attribute
SetClosedObj( rObj.IsClosedObj() );
if( pNewPage )
pPage = pNewPage;
if( pNewModel )
pModel = pNewModel;
aName = rOle2Obj.aName;
mpImpl->aPersistName = rOle2Obj.mpImpl->aPersistName;
aProgName = rOle2Obj.aProgName;
bFrame = rOle2Obj.bFrame;
if( rOle2Obj.pGraphic )
2000-09-18 16:07:07 +00:00
{
if( pGraphic )
{
2000-09-18 16:07:07 +00:00
delete pGraphic;
delete mpImpl->pGraphicObject;
}
pGraphic = new Graphic( *rOle2Obj.pGraphic );
mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
2000-09-18 16:07:07 +00:00
}
if( pModel && rObj.GetModel() )
{
SvPersist* pDestPers = pModel->GetPersist();
SvPersist* pSrcPers = rObj.GetModel()->GetPersist();
if( pDestPers && pSrcPers )
{
ImpCopyObject( *pSrcPers, *pDestPers, mpImpl->aPersistName );
if( rOle2Obj.ppObjRef->Is() && ppObjRef->Is() &&
( (*rOle2Obj.ppObjRef)->GetMapUnit() == (*ppObjRef)->GetMapUnit() ) )
{
(*ppObjRef)->SetVisArea( (*rOle2Obj.ppObjRef)->GetVisArea() );
}
}
Connect();
}
}
2000-09-18 16:07:07 +00:00
// -----------------------------------------------------------------------------
void SdrOle2Obj::ImpCopyObject( SvPersist& rSrcPersist, SvPersist& rDstPersist, String& rPersistName )
{
SvInfoObject* pInfo = rSrcPersist.Find( rPersistName );
2000-09-18 16:07:07 +00:00
if( pInfo != NULL )
{
SvPersistRef xNewRef;
const String aOldPersistName( rPersistName );
// loop because of storage bug 46033
for( USHORT i = 1, n = 0; n < 100; i++, n++ )
{
String aStr( rPersistName = OUString::createFromAscii( "Object " ) );
aStr += String::CreateFromInt32( i );
while( rDstPersist.Find( aStr ) )
{
aStr = rPersistName;
aStr += String::CreateFromInt32( ++i );
2000-09-18 16:07:07 +00:00
}
xNewRef = rDstPersist.CopyObject( aOldPersistName, rPersistName = aStr, &rSrcPersist );
if( xNewRef.Is() )
break;
2000-09-18 16:07:07 +00:00
}
*ppObjRef = &rDstPersist.GetObject( rPersistName );
2000-09-18 16:07:07 +00:00
}
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::operator=(const SdrObject& rObj)
{
if( &rObj != this )
ImpAssign( rObj );
}
// -----------------------------------------------------------------------------
SdrObject* SdrOle2Obj::Clone( SdrPage* pNewPage, SdrModel* pNewModel ) const
{
SdrOle2Obj* pObj = static_cast< SdrOle2Obj* >( SdrObjFactory::MakeNewObject( GetObjInventor(), GetObjIdentifier(),NULL ) );
if( pObj )
{
pObj->ImpAssign( *this, pNewPage, pNewModel );
if( pNewModel )
pObj->SetModel( pNewModel );
}
return pObj;
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
FASTBOOL SdrOle2Obj::HasSpecialDrag() const
{
return FALSE;
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::ImpSetVisAreaSize()
{
GetObjRef(); // try to load inplace object
2000-09-18 16:07:07 +00:00
SvInPlaceObjectRef& rIPRef=*ppObjRef;
if (rIPRef.Is())
{
if (rIPRef->GetMiscStatus() & SVOBJ_MISCSTATUS_SERVERRESIZE)
{
// Server resized selbst (StarChart)
// Neue VisArea setzen
Rectangle aVisArea = OutputDevice::LogicToLogic( aRect,
pModel->GetScaleUnit(), rIPRef->GetMapUnit() );
rIPRef->SetVisArea(aVisArea);
// Wurde die VisArea akzeptiert?
Rectangle aAcceptedVisArea(rIPRef->GetVisArea());
if (aVisArea.GetSize() != aAcceptedVisArea.GetSize())
{
// VisArea wurde nicht akzeptiert -> korrigieren
aRect.SetSize(OutputDevice::LogicToLogic( aAcceptedVisArea.GetSize(),
rIPRef->GetMapUnit(), pModel->GetScaleUnit()));
}
}
else
{
/**********************************************************************
* Nun wird nicht mehr die VisArea gesetzt, sondern es erfolgt eine
* Skalierung
**********************************************************************/
SvEmbeddedClient* pClient = (*ppObjRef)->GetClient();
if (pClient)
{
SvClientData* pData = pClient->GetClientData();
Size aObjAreaSize = rIPRef->GetVisArea().GetSize();
aObjAreaSize = OutputDevice::LogicToLogic( aObjAreaSize,
rIPRef->GetMapUnit(),
pModel->GetScaleUnit() );
Size aSize = aRect.GetSize();
Fraction aScaleWidth (aSize.Width(), aObjAreaSize.Width() );
Fraction aScaleHeight(aSize.Height(), aObjAreaSize.Height() );
// Nun auf 10 Binaerstellen kuerzen
Kuerzen(aScaleHeight, 10);
Kuerzen(aScaleWidth, 10);
pData->SetSizeScale(aScaleWidth, aScaleHeight);
Rectangle aScaleRect(aRect.TopLeft(), aObjAreaSize);
pData->SetObjArea(aScaleRect);
}
}
}
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
{
SdrRectObj::NbcResize(rRef,xFact,yFact);
if (aGeo.nShearWink!=0 || aGeo.nDrehWink!=0) { // kleine Korrekturen
if (aGeo.nDrehWink>=9000 && aGeo.nDrehWink<27000) {
aRect.Move(aRect.Left()-aRect.Right(),aRect.Top()-aRect.Bottom());
}
aGeo.nDrehWink=0;
aGeo.nShearWink=0;
aGeo.nSin=0.0;
aGeo.nCos=1.0;
aGeo.nTan=0.0;
SetRectsDirty();
}
2001-07-24 07:51:46 +00:00
if( (NULL == pModel) || !pModel->isLocked() )
ImpSetVisAreaSize();
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::SetGeoData(const SdrObjGeoData& rGeo)
{
SdrRectObj::SetGeoData(rGeo);
2001-07-24 07:51:46 +00:00
if( (NULL == pModel) || !pModel->isLocked() )
ImpSetVisAreaSize();
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::NbcSetSnapRect(const Rectangle& rRect)
{
SdrRectObj::NbcSetSnapRect(rRect);
2001-07-24 07:51:46 +00:00
if( (NULL == pModel) || !pModel->isLocked() )
ImpSetVisAreaSize();
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::NbcSetLogicRect(const Rectangle& rRect)
{
SdrRectObj::NbcSetLogicRect(rRect);
2001-07-24 07:51:46 +00:00
if( (NULL == pModel) || !pModel->isLocked() )
ImpSetVisAreaSize();
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
FASTBOOL SdrOle2Obj::HasGDIMetaFile() const
{
GetObjRef(); // try to load inplace object
SvInPlaceObjectRef& rIPRef=*ppObjRef;
BOOL bOK = FALSE;
if ( rIPRef.Is() )
bOK = TRUE;
return bOK;
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
const GDIMetaFile* SdrOle2Obj::GetGDIMetaFile() const
{
if( mpImpl->pMetaFile )
2000-09-18 16:07:07 +00:00
{
delete ((SdrOle2Obj*)this)->mpImpl->pMetaFile;
((SdrOle2Obj*)this)->mpImpl->pMetaFile = NULL;
2000-09-18 16:07:07 +00:00
}
GetObjRef(); // try to load inplace object
SvInPlaceObjectRef& rIPRef=*ppObjRef;
if (rIPRef.Is())
{
2001-06-22 14:46:24 +00:00
GDIMetaFile* pMtf=NULL;
TransferableDataHelper aData(rIPRef->CreateTransferableSnapshot() );
if( aData.HasFormat( FORMAT_GDIMETAFILE ) )
2000-09-18 16:07:07 +00:00
{
2001-06-22 14:46:24 +00:00
GDIMetaFile* pNewMtf = new GDIMetaFile;
if( aData.GetGDIMetaFile( FORMAT_GDIMETAFILE, *pNewMtf ) )
2001-07-02 09:12:59 +00:00
((SdrOle2Obj*)this)->mpImpl->pMetaFile = pNewMtf;
2001-06-22 14:46:24 +00:00
else
delete pNewMtf;
2000-09-18 16:07:07 +00:00
}
}
return mpImpl->pMetaFile;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::WriteData(SvStream& rOut) const
{
SdrRectObj::WriteData(rOut);
SdrDownCompat aCompat(rOut,STREAM_WRITE); // Fuer Abwaertskompatibilitaet (Lesen neuer Daten mit altem Code)
#ifdef DBG_UTIL
aCompat.SetID("SdrOle2Obj");
#endif
// UNICODE: rOut<<mpImpl->aPersistName;
rOut.WriteByteString(mpImpl->aPersistName);
2000-09-18 16:07:07 +00:00
// UNICODE: rOut<<aProgName;
rOut.WriteByteString(aProgName);
GetObjRef();
BOOL bObjRefValid=ppObjRef->Is();
rOut<<bObjRefValid;
BOOL bPreview = FALSE;
if( !IsEmptyPresObj() && pModel && pModel->IsSaveOLEPreview() )
bPreview = TRUE;
if( bPreview )
{
// set preview graphic (not for empty presentation objects)
GetGDIMetaFile();
if( mpImpl->pMetaFile )
2000-09-18 16:07:07 +00:00
{
Graphic aNewGraphic( *mpImpl->pMetaFile );
( (SdrOle2Obj*) this )->SetGraphic( &aNewGraphic );
2000-09-18 16:07:07 +00:00
}
}
BOOL bHasGraphic=pGraphic!=NULL;
rOut<<bHasGraphic;
if (bHasGraphic)
{
SdrDownCompat aGrafCompat(rOut,STREAM_WRITE); // ab V11 eingepackt
#ifdef DBG_UTIL
aGrafCompat.SetID("SdrOle2Obj(Graphic)");
#endif
rOut<<*pGraphic;
}
if( bPreview )
( (SdrOle2Obj*) this )->SetGraphic( NULL ); // remove preview graphic
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::ReadData(const SdrObjIOHeader& rHead, SvStream& rIn)
{
rIn.SetError( 0 );
if (rIn.GetError()!=0) return;
SdrRectObj::ReadData(rHead,rIn);
SdrDownCompat aCompat(rIn,STREAM_READ); // Fuer Abwaertskompatibilitaet (Lesen neuer Daten mit altem Code)
#ifdef DBG_UTIL
aCompat.SetID("SdrOle2Obj");
#endif
// UNICODE: rIn >> mpImpl->aPersistName;
rIn.ReadByteString(mpImpl->aPersistName);
2000-09-18 16:07:07 +00:00
// UNICODE: rIn >> aProgName;
rIn.ReadByteString(aProgName);
BOOL bObjRefValid;
rIn>>bObjRefValid;
BOOL bHasGraphic;
rIn>>bHasGraphic;
if (bHasGraphic)
{
if(pGraphic==NULL)
pGraphic=new Graphic;
if(rHead.GetVersion()>=11)
2000-09-18 16:07:07 +00:00
{ // ab V11 eingepackt
SdrDownCompat aGrafCompat(rIn,STREAM_READ);
#ifdef DBG_UTIL
aGrafCompat.SetID("SdrOle2Obj(Graphic)");
#endif
rIn>>*pGraphic;
}
else
rIn>>*pGraphic;
if( mpImpl->pGraphicObject )
delete mpImpl->pGraphicObject;
mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
2000-09-18 16:07:07 +00:00
}
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void SdrOle2Obj::NbcMove(const Size& rSize)
{
SdrRectObj::NbcMove(rSize);
2001-07-24 07:51:46 +00:00
if( (NULL == pModel) || !pModel->isLocked() )
ImpSetVisAreaSize();
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
BOOL SdrOle2Obj::Unload()
{
BOOL bUnloaded = FALSE;
if( ppObjRef && ppObjRef->Is() )
{
//Nicht notwendig im Doc DTor (MM)
ULONG nRefCount = (*ppObjRef)->GetRefCount();
// prevent Unload if there are external references
if( nRefCount > 2 )
return FALSE;
DBG_ASSERT( nRefCount == 2, "Wrong RefCount for unload" );
}
2001-04-12 09:06:03 +00:00
else
bUnloaded = TRUE;
2000-09-18 16:07:07 +00:00
if (pModel && ppObjRef && ppObjRef->Is() &&
SVOBJ_MISCSTATUS_ALWAYSACTIVATE != (*ppObjRef)->GetMiscStatus() &&
1 < (*ppObjRef)->GetRefCount() &&
!(*ppObjRef)->IsModified() &&
!(*ppObjRef)->GetProtocol().IsInPlaceActive() )
{
SvPersist* pPersist = pModel->GetPersist();
if (pPersist)
{
SvPersist* pO = *ppObjRef;
if( pO->IsModified() )
{
pO->DoSave();
pO->DoSaveCompleted();
}
ppObjRef->Clear();
if (pPersist->Unload(pO))
bUnloaded = TRUE;
else
*ppObjRef = pO;
}
}
return bUnloaded;
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::CreatePersistName( SvPersist* pPers )
{
mpImpl->aPersistName = OUString::createFromAscii( "Object " );
String aStr( mpImpl->aPersistName );
USHORT i = 1;
aStr+=String::CreateFromInt32( i );
while( pPers->Find( aStr ) )
{
aStr = mpImpl->aPersistName;
aStr += String::CreateFromInt32(++i);
}
mpImpl->aPersistName = aStr;
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
const SvInPlaceObjectRef& SdrOle2Obj::GetObjRef() const
{
if ( !ppObjRef->Is() && pModel && pModel->GetPersist() && !pModel->GetPersist()->IsHandsOff() )
{
// #107645#
// Only try loading if it did not wrent wrong up to now
if(!mpImpl->mbLoadingOLEObjectFailed)
{
// Objekt laden
(*ppObjRef) = &( pModel->GetPersist()->GetObject( mpImpl->aPersistName ) );
// #107645#
// If loading of OLE object failed, remember that to not invoke a endless
// loop trying to load it again and again.
if(!ppObjRef->Is())
{
mpImpl->mbLoadingOLEObjectFailed = sal_True;
}
// #108759# For math objects, set closed state to transparent
if( ImplIsMathObj( *ppObjRef ) )
const_cast<SdrOle2Obj*>(this)->SetClosedObj( false );
}
2000-09-18 16:07:07 +00:00
if ( ppObjRef->Is() )
{
if( !IsEmptyPresObj() )
{
// #75637# remember modified status of model
BOOL bWasChanged(pModel ? pModel->IsChanged() : FALSE);
// perhaps preview not valid anymore
// #75637# This line changes the modified state of the model
( (SdrOle2Obj*) this )->SetGraphic( NULL );
// #75637# if status was not set before, force it back
// to not set, so that SetGraphic(0L) above does not
// set the modified state of the model.
if(!bWasChanged && pModel && pModel->IsChanged())
pModel->SetChanged(FALSE);
}
if ( (*ppObjRef)->GetMiscStatus() & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
{
if (pModel && pModel->GetRefDevice() &&
pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
{
if(!bInDestruction)
{
// prevent SetModified (don't want no update here)
sal_Bool bWasEnabled = (*ppObjRef)->IsEnableSetModified();
if ( bWasEnabled )
(*ppObjRef)->EnableSetModified( sal_False );
// Kein RefDevice oder RefDevice kein Printer
Printer* pPrinter = (Printer*) pModel->GetRefDevice();
(*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
// reset state
(*ppObjRef)->EnableSetModified( bWasEnabled );
}
2000-09-18 16:07:07 +00:00
}
}
// register modify listener on initial load
if( pModifyListener == NULL )
{
((SdrOle2Obj*)this)->pModifyListener = new SvxUnoShapeModifyListener( (SdrOle2Obj*)this );
pModifyListener->acquire();
uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
if( xBC.is() && pModifyListener )
{
uno::Reference< util::XModifyListener > xListener( pModifyListener );
xBC->addModifyListener( xListener );
}
}
}
}
if (ppObjRef->Is())
{
// In Cache einfuegen
GetSdrGlobalData().GetOLEObjCache().InsertObj((SdrOle2Obj*) this);
}
return *ppObjRef;
}
// -----------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
uno::Reference< frame::XModel > SdrOle2Obj::getXModel() const
{
uno::Reference< frame::XModel > xModel;
if( pModel )
{
SvInPlaceObjectRef xSvIPO( GetObjRef() );
SfxInPlaceObjectRef xIPO( xSvIPO );
if( xIPO.Is() )
{
SfxObjectShell* pShell = xIPO->GetObjectShell();
if( pShell )
xModel = pShell->GetModel();
}
}
return xModel;
}
// -----------------------------------------------------------------------------