office-gobmx/sd/source/ui/unoidl/SdUnoDrawView.cxx

609 lines
16 KiB
C++
Raw Normal View History

2002-01-30 04:40:42 -06:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2002-01-30 04:40:42 -06:00
*
* Copyright 2008 by Sun Microsystems, Inc.
2002-01-30 04:40:42 -06:00
*
* OpenOffice.org - a multi-platform office productivity suite
2002-01-30 04:40:42 -06:00
*
* $RCSfile: SdUnoDrawView.cxx,v $
* $Revision: 1.35 $
2002-01-30 04:40:42 -06:00
*
* This file is part of OpenOffice.org.
2002-01-30 04:40:42 -06: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.
2002-01-30 04:40:42 -06: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).
2002-01-30 04:40:42 -06: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.
2002-01-30 04:40:42 -06:00
*
************************************************************************/
2002-01-24 08:06:27 -06:00
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sd.hxx"
2002-01-24 08:06:27 -06:00
#include "SdUnoDrawView.hxx"
#include "DrawController.hxx"
#include "DrawDocShell.hxx"
#include "DrawViewShell.hxx"
#include "drawdoc.hxx"
#include "unolayer.hxx"
#include "unomodel.hxx"
#include "unopage.hxx"
#include "Window.hxx"
#include <cppuhelper/proptypehlp.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/viewfrm.hxx>
#include <svx/svdpagv.hxx>
2002-01-24 08:06:27 -06:00
#include <svx/unoshape.hxx>
#include <svx/unoshcol.hxx>
#include <svx/zoomitem.hxx>
#include <com/sun/star/drawing/XLayerManager.hpp>
#include <com/sun/star/view/DocumentZoomType.hpp>
2002-01-24 08:06:27 -06:00
#include <vector>
2002-01-24 08:06:27 -06:00
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
namespace sd {
2002-01-24 08:06:27 -06:00
SdUnoDrawView::SdUnoDrawView(
DrawController& rController,
DrawViewShell& rViewShell,
View& rView) throw()
: DrawSubControllerInterfaceBase(m_aMutex),
mrController(rController),
mrDrawViewShell(rViewShell),
mrView(rView)
2002-01-24 08:06:27 -06:00
{
}
2002-01-24 08:06:27 -06:00
SdUnoDrawView::~SdUnoDrawView() throw()
{
}
2002-01-24 08:06:27 -06:00
sal_Bool SdUnoDrawView::getMasterPageMode(void) const throw()
{
return (mrDrawViewShell.GetEditMode() == EM_MASTERPAGE);
2002-01-24 08:06:27 -06:00
}
void SdUnoDrawView::setMasterPageMode (sal_Bool bMasterPageMode) throw()
2002-01-24 08:06:27 -06:00
{
if ((mrDrawViewShell.GetEditMode() == EM_MASTERPAGE) != bMasterPageMode)
{
mrDrawViewShell.ChangeEditMode (
bMasterPageMode ? EM_MASTERPAGE : EM_PAGE,
mrDrawViewShell.IsLayerModeActive());
}
2002-01-24 08:06:27 -06:00
}
2002-01-24 08:06:27 -06:00
sal_Bool SdUnoDrawView::getLayerMode(void) const throw()
{
return mrDrawViewShell.IsLayerModeActive();
2002-01-24 08:06:27 -06:00
}
void SdUnoDrawView::setLayerMode (sal_Bool bLayerMode) throw()
2002-01-24 08:06:27 -06:00
{
if (mrDrawViewShell.IsLayerModeActive() != (bLayerMode==sal_True))
{
mrDrawViewShell.ChangeEditMode (
mrDrawViewShell.GetEditMode(),
bLayerMode);
}
2002-01-24 08:06:27 -06:00
}
Reference<drawing::XLayer> SdUnoDrawView::getActiveLayer (void) throw ()
{
Reference<drawing::XLayer> xCurrentLayer;
do
{
// Retrieve the layer manager from the model.
SdXImpressDocument* pModel = GetModel();
if (pModel == NULL)
break;
SdDrawDocument* pSdModel = pModel->GetDoc();
if (pSdModel == NULL)
break;
// From the model get the current SdrLayer object via the layer admin.
SdrLayerAdmin& rLayerAdmin = pSdModel->GetLayerAdmin ();
SdrLayer* pLayer = rLayerAdmin.GetLayer (mrView.GetActiveLayer(), TRUE);
if (pLayer == NULL)
break;
// Get the corresponding XLayer object from the implementation
// object of the layer manager.
Reference<drawing::XLayerManager> xManager (pModel->getLayerManager(), uno::UNO_QUERY);
SdLayerManager* pManager = SdLayerManager::getImplementation (xManager);
if (pManager != NULL)
xCurrentLayer = pManager->GetLayer (pLayer);
}
while (false);
return xCurrentLayer;
}
void SdUnoDrawView::setActiveLayer (const Reference<drawing::XLayer>& rxLayer) throw ()
{
do
{
// Get the SdrLayer object corresponding to the given reference.
if ( ! rxLayer.is())
break;
SdLayer* pLayer = SdLayer::getImplementation (rxLayer);
if (pLayer == NULL)
break;
SdrLayer* pSdrLayer = pLayer->GetSdrLayer();
if (pSdrLayer == NULL)
break;
// Set the new active layer and make the change visible.
mrView.SetActiveLayer (pSdrLayer->GetName());
mrDrawViewShell.ResetActualLayer ();
}
while (false);
}
2002-01-24 08:06:27 -06:00
// XSelectionSupplier
2002-01-24 08:06:27 -06:00
sal_Bool SAL_CALL SdUnoDrawView::select( const Any& aSelection )
throw(lang::IllegalArgumentException, RuntimeException)
{
bool bOk = true;
::std::vector<SdrObject*> aObjects;
2002-01-24 08:06:27 -06:00
SdrPage* pSdrPage = NULL;
2002-01-24 08:06:27 -06:00
Reference< drawing::XShape > xShape;
aSelection >>= xShape;
if(xShape.is())
{
SvxShape* pShape = SvxShape::getImplementation( xShape );
if( pShape && (pShape->GetSdrObject() != NULL) )
2002-01-24 08:06:27 -06:00
{
SdrObject* pObj = pShape->GetSdrObject();
pSdrPage = pObj->GetPage();
aObjects.push_back( pObj );
}
else
{
bOk = false;
}
}
else
{
Reference< drawing::XShapes > xShapes;
aSelection >>= xShapes;
if( xShapes.is() )
{
const sal_uInt32 nCount = xShapes->getCount();
for( sal_uInt32 i = 0; i < nCount; i++ )
2002-01-24 08:06:27 -06:00
{
xShapes->getByIndex(i) >>= xShape;
if( xShape.is() )
2002-01-24 08:06:27 -06:00
{
SvxShape* pShape = SvxShape::getImplementation(xShape);
if( (pShape == NULL) || (pShape->GetSdrObject() == NULL) )
{
bOk = false;
break;
}
SdrObject* pObj = pShape->GetSdrObject();
if( pSdrPage == NULL )
{
pSdrPage = pObj->GetPage();
}
else if( pSdrPage != pObj->GetPage() )
2002-01-24 08:06:27 -06:00
{
bOk = false;
break;
2002-01-24 08:06:27 -06:00
}
aObjects.push_back( pObj );
2002-01-24 08:06:27 -06:00
}
}
}
}
2002-05-08 03:52:47 -05:00
if( bOk )
{
if( pSdrPage )
{
setMasterPageMode( pSdrPage->IsMasterPage() );
mrDrawViewShell.SwitchPage( (pSdrPage->GetPageNum() - 1) >> 1 );
mrDrawViewShell.WriteFrameViewData();
}
SdrPageView *pPV = mrView.GetSdrPageView();
if(pPV)
{
// first deselect all
mrView.UnmarkAllObj( pPV );
::std::vector<SdrObject*>::iterator aIter( aObjects.begin() );
const ::std::vector<SdrObject*>::iterator aEnd( aObjects.end() );
while( aIter != aEnd )
{
SdrObject* pObj = (*aIter++);
mrView.MarkObj( pObj, pPV );
}
}
else
{
bOk = false;
}
2002-01-24 08:06:27 -06:00
}
return bOk;
2002-01-24 08:06:27 -06:00
}
//----------------------------------------------------------------------
Any SAL_CALL SdUnoDrawView::getSelection()
throw(RuntimeException)
{
Any aAny;
if( mrView.IsTextEdit() )
mrView.getTextSelection( aAny );
if( !aAny.hasValue() )
{
const SdrMarkList& rMarkList = mrView.GetMarkedObjectList();
sal_uInt32 nCount = rMarkList.GetMarkCount();
if( nCount )
{
Reference< drawing::XShapes > xShapes( SvxShapeCollection_NewInstance(), UNO_QUERY );
for( sal_uInt32 nNum = 0; nNum < nCount; nNum++)
{
SdrMark *pMark = rMarkList.GetMark(nNum);
if(pMark==NULL)
continue;
SdrObject *pObj = pMark->GetMarkedSdrObj();
if(pObj==NULL || pObj->GetPage() == NULL)
continue;
Reference< drawing::XDrawPage > xPage( pObj->GetPage()->getUnoPage(), UNO_QUERY);
if(!xPage.is())
continue;
SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xPage );
if(pDrawPage==NULL)
continue;
Reference< drawing::XShape > xShape( pObj->getUnoShape(), UNO_QUERY );
if(xShape.is())
xShapes->add(xShape);
}
aAny <<= xShapes;
}
}
return aAny;
2002-01-24 08:06:27 -06:00
}
void SAL_CALL SdUnoDrawView::addSelectionChangeListener (
const css::uno::Reference<css::view::XSelectionChangeListener>& rxListener)
throw(css::uno::RuntimeException)
2002-01-24 08:06:27 -06:00
{
(void)rxListener;
}
2002-01-24 08:06:27 -06:00
void SAL_CALL SdUnoDrawView::removeSelectionChangeListener (
const css::uno::Reference<css::view::XSelectionChangeListener>& rxListener)
throw(css::uno::RuntimeException)
{
(void)rxListener;
}
2002-01-24 08:06:27 -06:00
void SdUnoDrawView::setFastPropertyValue (
2002-01-24 08:06:27 -06:00
sal_Int32 nHandle,
const Any& rValue)
throw(css::beans::UnknownPropertyException,
css::beans::PropertyVetoException,
css::lang::IllegalArgumentException,
css::lang::WrappedTargetException,
css::uno::RuntimeException)
2002-01-24 08:06:27 -06:00
{
switch( nHandle )
{
case DrawController::PROPERTY_CURRENTPAGE:
2002-01-30 04:40:42 -06:00
{
Reference< drawing::XDrawPage > xPage;
rValue >>= xPage;
setCurrentPage( xPage );
}
break;
case DrawController::PROPERTY_MASTERPAGEMODE:
2002-01-24 08:06:27 -06:00
{
sal_Bool bValue = sal_False;
2002-01-24 08:06:27 -06:00
rValue >>= bValue;
setMasterPageMode( bValue );
}
break;
case DrawController::PROPERTY_LAYERMODE:
2002-01-24 08:06:27 -06:00
{
sal_Bool bValue = sal_False;
2002-01-24 08:06:27 -06:00
rValue >>= bValue;
setLayerMode( bValue );
}
case DrawController::PROPERTY_ACTIVE_LAYER:
{
Reference<drawing::XLayer> xLayer;
rValue >>= xLayer;
setActiveLayer (xLayer);
}
2002-01-24 08:06:27 -06:00
break;
case DrawController::PROPERTY_ZOOMVALUE:
{
sal_Int16 nZoom = 0;
rValue >>= nZoom;
SetZoom( nZoom );
}
break;
case DrawController::PROPERTY_ZOOMTYPE:
{
sal_Int16 nType = 0;
rValue >>= nType;
SetZoomType( nType );
}
break;
case DrawController::PROPERTY_VIEWOFFSET:
{
awt::Point aOffset;
rValue >>= aOffset;
SetViewOffset( aOffset );
}
break;
default:
throw beans::UnknownPropertyException();
2002-01-24 08:06:27 -06:00
}
}
Any SAL_CALL SdUnoDrawView::getFastPropertyValue (
sal_Int32 nHandle)
throw(css::beans::UnknownPropertyException,
css::lang::WrappedTargetException,
css::uno::RuntimeException)
2002-01-24 08:06:27 -06:00
{
Any aValue;
2002-01-24 08:06:27 -06:00
switch( nHandle )
{
case DrawController::PROPERTY_CURRENTPAGE:
aValue <<= (const_cast<SdUnoDrawView*>(this))->getCurrentPage();
2002-01-30 04:40:42 -06:00
break;
case DrawController::PROPERTY_MASTERPAGEMODE:
aValue <<= getMasterPageMode();
2002-01-30 04:40:42 -06:00
break;
2002-01-24 08:06:27 -06:00
case DrawController::PROPERTY_LAYERMODE:
aValue <<= getLayerMode();
2002-01-30 04:40:42 -06:00
break;
case DrawController::PROPERTY_ACTIVE_LAYER:
aValue <<= (const_cast<SdUnoDrawView*>(this))->getActiveLayer();
break;
case DrawController::PROPERTY_ZOOMVALUE:
aValue <<= GetZoom();
break;
case DrawController::PROPERTY_ZOOMTYPE:
aValue <<= (sal_Int16)com::sun::star::view::DocumentZoomType::BY_VALUE;
break;
case DrawController::PROPERTY_VIEWOFFSET:
aValue <<= GetViewOffset();
break;
default:
throw beans::UnknownPropertyException();
2002-01-24 08:06:27 -06:00
}
return aValue;
2002-01-24 08:06:27 -06:00
}
2002-01-30 04:40:42 -06:00
// XDrawView
2002-01-30 04:40:42 -06:00
2002-01-24 08:06:27 -06:00
void SAL_CALL SdUnoDrawView::setCurrentPage (
const Reference< drawing::XDrawPage >& xPage )
2002-01-24 08:06:27 -06:00
throw(RuntimeException)
{
SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xPage );
SdrPage *pSdrPage = pDrawPage ? pDrawPage->GetSdrPage() : NULL;
2002-01-24 08:06:27 -06:00
if(pSdrPage)
{
// End editing of text. Otherwise the edited text object would
// still be visible on the new page.
mrDrawViewShell.GetView()->SdrEndTextEdit();
setMasterPageMode( pSdrPage->IsMasterPage() );
mrDrawViewShell.SwitchPage( (pSdrPage->GetPageNum() - 1) >> 1 );
mrDrawViewShell.WriteFrameViewData();
2002-01-24 08:06:27 -06:00
}
}
//----------------------------------------------------------------------
Reference< drawing::XDrawPage > SAL_CALL SdUnoDrawView::getCurrentPage()
throw(RuntimeException)
{
Reference< drawing::XDrawPage > xPage;
SdrPageView *pPV = mrView.GetSdrPageView();
SdrPage* pPage = pPV ? pPV->GetPage() : NULL;
if(pPage)
xPage = Reference< drawing::XDrawPage >::query( pPage->getUnoPage() );
return xPage;
}
sal_Int16 SdUnoDrawView::GetZoom(void) const
{
if (mrDrawViewShell.GetActiveWindow() )
{
return (sal_Int16)mrDrawViewShell.GetActiveWindow()->GetZoom();
}
else
{
return 0;
}
}
void SdUnoDrawView::SetZoom( sal_Int16 nZoom )
{
SvxZoomItem aZoomItem( SVX_ZOOM_PERCENT, nZoom );
SfxViewFrame* pViewFrame = mrDrawViewShell.GetViewFrame();
if( pViewFrame )
{
SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
if( pDispatcher )
{
pDispatcher->Execute(SID_ATTR_ZOOM,SFX_CALLMODE_SYNCHRON,&aZoomItem, 0L);
}
}
}
void SdUnoDrawView::SetViewOffset(const awt::Point& rWinPos )
{
Point aWinPos( rWinPos.X, rWinPos.Y );
aWinPos += mrDrawViewShell.GetViewOrigin();
mrDrawViewShell.SetWinViewPos( aWinPos, true );
}
awt::Point SdUnoDrawView::GetViewOffset() const
{
Point aRet;
aRet = mrDrawViewShell.GetWinViewPos();
aRet -= mrDrawViewShell.GetViewOrigin();
return awt::Point( aRet.X(), aRet.Y() );
}
void SdUnoDrawView::SetZoomType ( sal_Int16 nType )
{
SfxViewFrame* pViewFrame = mrDrawViewShell.GetViewFrame();
if( pViewFrame )
{
SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
if( pDispatcher )
{
SvxZoomType eZoomType;
switch( nType )
{
case com::sun::star::view::DocumentZoomType::OPTIMAL:
eZoomType = SVX_ZOOM_OPTIMAL;
break;
case com::sun::star::view::DocumentZoomType::PAGE_WIDTH:
case com::sun::star::view::DocumentZoomType::PAGE_WIDTH_EXACT:
eZoomType = SVX_ZOOM_PAGEWIDTH;
break;
case com::sun::star::view::DocumentZoomType::ENTIRE_PAGE:
eZoomType = SVX_ZOOM_WHOLEPAGE;
break;
default:
return;
}
SvxZoomItem aZoomItem( eZoomType );
pDispatcher->Execute(SID_ATTR_ZOOM,SFX_CALLMODE_SYNCHRON,&aZoomItem, 0L);
}
}
}
SdXImpressDocument* SdUnoDrawView::GetModel (void) const throw()
{
if (mrView.GetDocSh()!=NULL)
{
Reference<frame::XModel> xModel (mrView.GetDocSh()->GetModel());
return SdXImpressDocument::getImplementation(xModel);
}
else
return NULL;
}
} // end of namespace sd