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

437 lines
14 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 2000, 2010 Oracle and/or its affiliates.
2003-10-06 08:58:36 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
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
#include <svtools/lingucfg.hxx>
#include <svx/langitem.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 <editeng/forbiddencharacterstable.hxx>
2003-10-28 15:10:57 +00:00
#ifndef _SVX_SVXIDS_HRC
#include <svx/svxids.hrc>
#endif
// header for class SvxShape
#include <svx/unoshape.hxx>
#include <svx/fhgtitem.hxx>
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <sfx2/objsh.hxx>
2008-10-17 08:40:10 +00:00
#include <svx/helperhittest3d.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);
// #i12587# support for shapes in chart
SdrOutliner* pOutliner = getOutliner();
SfxItemPool* pOutlinerPool = ( pOutliner ? pOutliner->GetEditTextObjectPool() : NULL );
if ( pOutlinerPool )
{
SvtLinguConfig aLinguConfig;
SvtLinguOptions aLinguOptions;
if ( aLinguConfig.GetOptions( aLinguOptions ) )
{
pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage, EE_CHAR_LANGUAGE ) );
pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) );
pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) );
}
// set font height without changing SdrEngineDefaults
pOutlinerPool->SetPoolDefaultItem( SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT ) ); // 12pt
}
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 )
{
2008-10-17 08:40:10 +00:00
// prepare result vector and call helper
::std::vector< const E3dCompoundObject* > aHitList;
const basegfx::B2DPoint aHitPoint(rPnt.X(), rPnt.Y());
getAllHit3DObjectsSortedFrontToBack(aHitPoint, *pScene, aHitList);
if(aHitList.size())
{
// choose the frontmost hit 3D object of the scene
pRet = const_cast< E3dCompoundObject* >(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 );
CWS-TOOLING: integrate CWS chart37 2009-05-22 09:10:36 +0200 iha r272170 : #i102130# color of pies is not loaded correctly 2009-04-27 17:16:20 +0200 iha r271294 : #i24203# compiler problem 2009-04-27 16:43:21 +0200 iha r271292 : #i101281# missing API documentation for secondary axis title properties 2009-04-27 15:26:05 +0200 hde r271276 : #i100987 2009-04-27 15:24:42 +0200 hde r271273 : #i100987 2009-04-24 15:08:33 +0200 iha r271214 : #i100995# crash with some logarithmic scalings 2009-04-22 18:50:56 +0200 dr r271134 : #i82177# write out deleted point labels 2009-04-22 18:40:48 +0200 iha r271133 : #i101281# missing API documentation for secondary axis title properties 2009-04-22 16:39:42 +0200 dr r271128 : #i82177# extensions for bubble charts 2009-04-22 14:37:00 +0200 dr r271114 : #i82177# import/export data label type and separator 2009-04-22 14:36:24 +0200 dr r271113 : #i82177# import/export data label type and separator 2009-04-21 15:25:26 +0200 dr r271038 : #i82177# import data label type and separator from BIFF8 CHFR records 2009-04-21 14:37:16 +0200 dr r271037 : #i82177# dump BIFF8 chart future records 2009-04-20 17:44:27 +0200 iha r271002 : #i96898# reduce library exports 2009-04-20 13:01:13 +0200 iha r270975 : #i24203# rotate data labels - help ids 2009-04-20 11:40:33 +0200 dr r270969 : #i96600# export of axis scaling/positioning properties 2009-04-16 16:02:31 +0200 dr r270892 : #i69599# keep Y axis left in 3d charts 2009-04-15 18:16:46 +0200 dr r270859 : #i69599# import of axis position settings 2009-04-15 18:16:01 +0200 dr r270858 : #i69599# correct handling of logarithmic crossing axes 2009-04-14 16:27:48 +0200 dr r270794 : #i96599# handle auto axis position on logarithmic axes 2009-04-09 19:59:51 +0200 dr r270722 : #i96599# import axis crossing settings, fix import of logarithmic scaling settings 2009-04-09 18:26:00 +0200 iha r270720 : #i96898# reduce library exports 2009-04-09 15:17:04 +0200 iha r270710 : #i96898# reduce library exports 2009-04-09 10:50:14 +0200 dr r270682 : #i24203# import/export of data label rotation, fixed some other broken stuff too 2009-04-08 16:54:54 +0200 dr r270657 : #i24203# import rotation for data point labels 2009-04-06 18:19:17 +0200 iha r270571 : #i100876# Axis scaling settings dialog wrong after API usage (anys different from double type) 2009-04-06 15:57:05 +0200 iha r270567 : #i100105# #i58585# leftover -> 2009-04-06 15:55:48 +0200 iha r270564 : #i58585# leftover -> 2009-04-02 16:41:07 +0200 iha r270422 : #i99721# remove unused code 2009-04-02 14:29:03 +0200 iha r270407 : #i99721# remove unused code 2009-03-26 10:58:23 +0100 iha r270059 : #i96898# reduce library exports 2009-03-26 10:13:49 +0100 iha r270055 : #i96898# reduce library exports 2009-03-25 09:39:13 +0100 iha r269998 : CWS-TOOLING: rebase CWS chart37 to trunk@269781 (milestone: DEV300:m44) 2009-03-24 17:56:56 +0100 iha r269986 : #i96898# reduce library exports 2009-03-24 16:56:44 +0100 iha r269974 : #i99721# remove unused code 2009-03-24 16:48:48 +0100 iha r269970 : #i89731# remove unused string 2009-03-24 15:44:04 +0100 iha r269961 : remove unused code 2009-03-24 15:22:45 +0100 iha r269959 : remove unused code 2009-03-24 15:17:17 +0100 iha r269957 : remove unused code 2009-03-24 11:14:53 +0100 iha r269923 : #i24203# rotate data labels 2009-03-09 12:10:25 +0100 hde r269076 : #i99300# 2009-03-06 15:56:26 +0100 iha r269011 : #i93953# Source Format for secondary axis without data 2009-02-17 15:59:05 +0100 iha r268177 : avoid warning during build 2009-02-17 15:01:59 +0100 iha r268173 : avoid warning during build 2009-02-13 09:39:03 +0100 ufi r267693 : i96999 2009-02-11 15:12:35 +0100 iha r267604 : removed unused string 2009-02-11 14:00:29 +0100 iha r267600 : #i96999# Corrected wording from 'correlation coefficient' to 'coefficient of determination' 2009-02-11 10:56:45 +0100 iha r267584 : #i89731# typo in resource string 2009-02-11 10:01:29 +0100 iha r267582 : #i89031# compile error on asian windows systems 2009-02-10 16:15:16 +0100 iha r267552 : #i24203# rotate data labels 2009-02-04 18:00:33 +0100 iha r267395 : #i98893# don't export defaults to file 2009-02-04 15:48:15 +0100 iha r267390 : #i92128# asian typography for chart elements 2009-02-04 15:17:41 +0100 iha r267386 : #i92128# asian typography for chart elements 2009-01-30 14:41:10 +0100 iha r267197 : CWS-TOOLING: rebase CWS chart37 to trunk@267171 (milestone: DEV300:m41)
2009-06-04 09:41:18 +00:00
aFullSet.Put( SfxUInt16Item(SID_ATTR_METRIC,static_cast< sal_uInt16 >( ConfigurationAccess::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
//.............................................................................