Files
libreoffice/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx

412 lines
13 KiB
C++
Raw Normal View History

2003-10-06 08:58:36 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2003-10-06 08:58:36 +00:00
*
* Copyright 2008 by Sun Microsystems, Inc.
2003-10-06 08:58:36 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2003-10-06 08:58:36 +00:00
*
* $RCSfile: DrawViewWrapper.cxx,v $
* $Revision: 1.20 $
2003-10-06 08:58:36 +00:00
*
* This file is part of OpenOffice.org.
2003-10-06 08:58:36 +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.
2003-10-06 08:58:36 +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).
2003-10-06 08:58:36 +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.
2003-10-06 08:58:36 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_chart2.hxx"
2003-10-06 08:58:36 +00:00
#include "DrawViewWrapper.hxx"
#include "chartview/DrawModelWrapper.hxx"
#include "ConfigurationAccess.hxx"
2003-10-06 08:58:36 +00:00
// header for class SdrPage
#include <svx/svdpage.hxx>
//header for class SdrPageView
#include <svx/svdpagv.hxx>
// header for class SdrModel
#include <svx/svdmodel.hxx>
// header for class E3dScene
#include <svx/scene3d.hxx>
2003-10-28 15:10:57 +00:00
#include <svx/svdetc.hxx>
#include <svx/svdoutl.hxx>
// header for class SvxForbiddenCharactersTable
#include <svx/forbiddencharacterstable.hxx>
#ifndef _SVX_SVXIDS_HRC
#include <svx/svxids.hrc>
#endif
// header for class SvxShape
#include <svx/unoshape.hxx>
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <sfx2/objsh.hxx>
using namespace ::com::sun::star;
2003-10-06 08:58:36 +00:00
//.............................................................................
namespace chart
{
//.............................................................................
namespace
{
short lcl_getHitTolerance( OutputDevice* pOutDev )
{
const short HITPIX=2; //hit-tolerance in pixel
short nHitTolerance = 50;
if(pOutDev)
nHitTolerance = static_cast<short>(pOutDev->PixelToLogic(Size(HITPIX,0)).Width());
return nHitTolerance;
}
// this code is copied from sfx2/source/doc/objembed.cxx
SfxObjectShell * lcl_GetParentObjectShell( const uno::Reference< frame::XModel > & xModel )
{
SfxObjectShell* pResult = NULL;
try
{
uno::Reference< container::XChild > xChildModel( xModel, uno::UNO_QUERY );
if ( xChildModel.is() )
{
uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
if ( xParentTunnel.is() )
{
SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
pResult = reinterpret_cast< SfxObjectShell * >(
xParentTunnel->getSomething( uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
}
}
}
catch( uno::Exception& )
{
// TODO: error handling
}
return pResult;
}
// this code is copied from sfx2/source/doc/objembed.cxx. It is a workaround to
// get the reference device (e.g. printer) fromthe parent document
OutputDevice * lcl_GetParentRefDevice( const uno::Reference< frame::XModel > & xModel )
{
SfxObjectShell * pParent = lcl_GetParentObjectShell( xModel );
if ( pParent )
return pParent->GetDocumentRefDev();
return NULL;
}
}
2003-10-28 15:10:57 +00:00
/*
void lcl_initOutliner( SdrOutliner* pTargetOutliner, SdrOutliner* pSourceOutliner )
{
//just an unsuccessful try to initialize the text edit outliner correctly
//if( bInit )
{
pTargetOutliner->EraseVirtualDevice();
pTargetOutliner->SetUpdateMode(FALSE);
pTargetOutliner->SetEditTextObjectPool( pSourceOutliner->GetEditTextObjectPool() );
pTargetOutliner->SetDefTab( pSourceOutliner->GetDefTab() );
}
pTargetOutliner->SetRefDevice( pSourceOutliner->GetRefDevice() );
pTargetOutliner->SetForbiddenCharsTable( pSourceOutliner->GetForbiddenCharsTable() );
pTargetOutliner->SetAsianCompressionMode( pSourceOutliner->GetAsianCompressionMode() );
pTargetOutliner->SetKernAsianPunctuation( pSourceOutliner->IsKernAsianPunctuation() );
pTargetOutliner->SetStyleSheetPool( pSourceOutliner->GetStyleSheetPool() );
pTargetOutliner->SetRefMapMode( pSourceOutliner->GetRefMapMode() );
pTargetOutliner->SetDefaultLanguage( pSourceOutliner->GetDefaultLanguage() );
pTargetOutliner->SetHyphenator( pSourceOutliner->GetHyphenator() );
USHORT nX, nY;
pSourceOutliner->GetGlobalCharStretching( nX, nY );
pTargetOutliner->SetGlobalCharStretching( nX, nY );
2003-10-06 08:58:36 +00:00
2003-10-28 15:10:57 +00:00
*//*
if ( !GetRefDevice() )
{
MapMode aMapMode(eObjUnit, Point(0,0), aObjUnit, aObjUnit);
pTargetOutliner->SetRefMapMode(aMapMode);
}
*//*
}
*/
DrawViewWrapper::DrawViewWrapper( SdrModel* pSdrModel, OutputDevice* pOut, bool bPaintPageForEditMode)
2003-10-28 15:10:57 +00:00
: E3dView(pSdrModel, pOut)
2003-10-06 08:58:36 +00:00
, m_pMarkHandleProvider(NULL)
2003-10-28 15:10:57 +00:00
, m_apOutliner( SdrMakeOutliner( OUTLINERMODE_TEXTOBJECT, pSdrModel ) )
, m_bRestoreMapMode( false )
2003-10-06 08:58:36 +00:00
{
// #114898#
SetBufferedOutputAllowed(true);
SetBufferedOverlayAllowed(true);
SetPagePaintingAllowed(bPaintPageForEditMode);
ReInit();
2003-10-06 08:58:36 +00:00
}
void DrawViewWrapper::ReInit()
{
OutputDevice* pOutDev = this->GetFirstOutputDevice();
Size aOutputSize(100,100);
if(pOutDev)
aOutputSize = pOutDev->GetOutputSize();
bPageVisible = false;
bPageBorderVisible = false;
bBordVisible = false;
bGridVisible = false;
bHlplVisible = false;
this->SetNoDragXorPolys(true);//for interactive 3D resize-dragging: paint only a single rectangle (not a simulated 3D object)
//this->SetResizeAtCenter(true);//for interactive resize-dragging: keep the object center fix
//a correct work area is at least necessary for correct values in the position and size dialog
Rectangle aRect(Point(0,0), aOutputSize);
this->SetWorkArea(aRect);
this->ShowSdrPage(this->GetModel()->GetPage(0));
}
2003-10-06 08:58:36 +00:00
DrawViewWrapper::~DrawViewWrapper()
{
aComeBackTimer.Stop();//@todo this should be done in destructor of base class
UnmarkAllObj();//necessary to aavoid a paint call during the destructor hierarchy
2003-10-06 08:58:36 +00:00
}
SdrPageView* DrawViewWrapper::GetPageView() const
{
SdrPageView* pSdrPageView = this->GetSdrPageView();
return pSdrPageView;
};
2003-10-06 08:58:36 +00:00
//virtual
void DrawViewWrapper::SetMarkHandles()
{
if( m_pMarkHandleProvider && m_pMarkHandleProvider->getMarkHandles( aHdl ) )
return;
else
SdrView::SetMarkHandles();
}
SdrObject* DrawViewWrapper::getHitObject( const Point& rPnt ) const
{
SdrObject* pRet = NULL;
//ULONG nOptions =SDRSEARCH_DEEP|SDRSEARCH_PASS2BOUND|SDRSEARCH_PASS3NEAREST;
ULONG nOptions = SDRSEARCH_DEEP | SDRSEARCH_TESTMARKABLE;
SdrPageView* pSdrPageView = this->GetPageView();
this->SdrView::PickObj(rPnt, lcl_getHitTolerance( this->GetFirstOutputDevice() ), pRet, pSdrPageView, nOptions);
if( pRet )
2003-10-06 08:58:36 +00:00
{
//3d objects need a special treatment
//because the simple PickObj method is not accurate in this case for performance reasons
E3dObject* pE3d = dynamic_cast< E3dObject* >(pRet);
if( pE3d )
{
E3dScene* pScene = pE3d->GetScene();
if( pScene )
{
::std::vector< SdrObject* > aHitList;
sal_uInt32 nHitCount = pScene->HitTest( rPnt, aHitList );
if( nHitCount )
pRet = aHitList[0];
}
}
2003-10-06 08:58:36 +00:00
}
return pRet;
}
void DrawViewWrapper::MarkObject( SdrObject* pObj )
{
bool bFrameDragSingles = true;//true == green == surrounding handles
if(pObj)
pObj->SetMarkProtect(false);
2003-10-06 08:58:36 +00:00
if( m_pMarkHandleProvider )
bFrameDragSingles = m_pMarkHandleProvider->getFrameDragSingles();
2003-10-06 08:58:36 +00:00
this->SetFrameDragSingles(bFrameDragSingles);//decide wether each single object should get handles
this->SdrView::MarkObj( pObj, this->GetPageView() );
this->showMarkHandles();
2003-10-06 08:58:36 +00:00
}
void DrawViewWrapper::setMarkHandleProvider( MarkHandleProvider* pMarkHandleProvider )
{
m_pMarkHandleProvider = pMarkHandleProvider;
}
void DrawViewWrapper::CompleteRedraw(OutputDevice* pOut, const Region& rReg, sdr::contact::ViewObjectContactRedirector* /* pRedirector */)
2003-10-06 08:58:36 +00:00
{
svtools::ColorConfig aColorConfig;
Color aFillColor = Color( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
this->SetApplicationBackgroundColor(aFillColor);
this->E3dView::CompleteRedraw( pOut, rReg );
2003-10-06 08:58:36 +00:00
}
SdrObject* DrawViewWrapper::getSelectedObject() const
2003-10-28 15:10:57 +00:00
{
SdrObject* pObj(NULL);
const SdrMarkList& rMarkList = this->GetMarkedObjectList();
2003-10-28 15:10:57 +00:00
if(rMarkList.GetMarkCount() == 1)
{
SdrMark* pMark = rMarkList.GetMark(0);
pObj = pMark->GetMarkedSdrObj();
2003-10-28 15:10:57 +00:00
}
return pObj;
}
SdrObject* DrawViewWrapper::getTextEditObject() const
{
SdrObject* pObj = this->getSelectedObject();
SdrObject* pTextObj = NULL;
if( pObj && pObj->HasTextEdit())
pTextObj = (SdrTextObj*)pObj;
2003-10-28 15:10:57 +00:00
return pTextObj;
}
void DrawViewWrapper::attachParentReferenceDevice( const uno::Reference< frame::XModel > & xChartModel )
{
OutputDevice * pParentRefDev( lcl_GetParentRefDevice( xChartModel ));
SdrOutliner * pOutliner( getOutliner());
if( pParentRefDev && pOutliner )
{
pOutliner->SetRefDevice( pParentRefDev );
}
}
2003-10-28 15:10:57 +00:00
SdrOutliner* DrawViewWrapper::getOutliner() const
{
// lcl_initOutliner( m_apOutliner.get(), &GetModel()->GetDrawOutliner() );
return m_apOutliner.get();
}
SfxItemSet DrawViewWrapper::getPositionAndSizeItemSetFromMarkedObject() const
{
SfxItemSet aFullSet( GetModel()->GetItemPool(),
SID_ATTR_TRANSFORM_POS_X,SID_ATTR_TRANSFORM_ANGLE,
SID_ATTR_TRANSFORM_PROTECT_POS,SID_ATTR_TRANSFORM_AUTOHEIGHT,
SDRATTR_ECKENRADIUS,SDRATTR_ECKENRADIUS,
SID_ATTR_METRIC,SID_ATTR_METRIC,
0);
SfxItemSet aGeoSet( E3dView::GetGeoAttrFromMarked() );
aFullSet.Put( aGeoSet );
aFullSet.Put( SfxUInt16Item(SID_ATTR_METRIC,static_cast< sal_uInt16 >( ConfigurationAccess::getConfigurationAccess()->getFieldUnit())));
return aFullSet;
}
SdrObject* DrawViewWrapper::getNamedSdrObject( const rtl::OUString& rName ) const
{
if(rName.getLength()==0)
return 0;
SdrPageView* pSdrPageView = this->GetPageView();
if( pSdrPageView )
{
return DrawModelWrapper::getNamedSdrObject( rName, pSdrPageView->GetObjList() );
}
return 0;
}
bool DrawViewWrapper::IsObjectHit( SdrObject* pObj, const Point& rPnt ) const
{
if(pObj)
{
Rectangle aRect(pObj->GetCurrentBoundRect());
return aRect.IsInside(rPnt);
}
return false;
}
void DrawViewWrapper::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
{
//prevent wrong reselection of objects
SdrModel* pSdrModel( this->GetModel() );
if( pSdrModel && pSdrModel->isLocked() )
return;
const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
//#i76053# do nothing when only changes on the hidden draw page were made ( e.g. when the symbols for the dialogs are created )
SdrPageView* pSdrPageView = this->GetPageView();
if( pSdrHint && pSdrPageView )
{
if( pSdrPageView->GetPage() != pSdrHint->GetPage() )
return;
}
E3dView::Notify(rBC, rHint);
if( pSdrHint != 0 )
{
SdrHintKind eKind = pSdrHint->GetKind();
if( eKind == HINT_BEGEDIT )
{
// #i79965# remember map mode
OSL_ASSERT( ! m_bRestoreMapMode );
OutputDevice* pOutDev = this->GetFirstOutputDevice();
if( pOutDev )
{
m_aMapModeToRestore = pOutDev->GetMapMode();
m_bRestoreMapMode = true;
}
}
else if( eKind == HINT_ENDEDIT )
{
// #i79965# scroll back view when ending text edit
OSL_ASSERT( m_bRestoreMapMode );
if( m_bRestoreMapMode )
{
OutputDevice* pOutDev = this->GetFirstOutputDevice();
if( pOutDev )
{
pOutDev->SetMapMode( m_aMapModeToRestore );
m_bRestoreMapMode = false;
}
}
}
}
}
//static
SdrObject* DrawViewWrapper::getSdrObject( const uno::Reference<
drawing::XShape >& xShape )
{
SdrObject* pRet = 0;
uno::Reference< lang::XUnoTunnel > xUnoTunnel( xShape, uno::UNO_QUERY );
uno::Reference< lang::XTypeProvider > xTypeProvider( xShape, uno::UNO_QUERY );
if(xUnoTunnel.is()&&xTypeProvider.is())
{
SvxShape* pSvxShape = reinterpret_cast<SvxShape*>(xUnoTunnel->getSomething( SvxShape::getUnoTunnelId() ));
if(pSvxShape)
pRet = pSvxShape->GetSdrObject();
}
return pRet;
}
2003-10-06 08:58:36 +00:00
//.............................................................................
} //namespace chart
//.............................................................................