1cdf0e10cSrcweir /************************************************************************* 2cdf0e10cSrcweir * 3cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4cdf0e10cSrcweir * 5cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6cdf0e10cSrcweir * 7cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8cdf0e10cSrcweir * 9cdf0e10cSrcweir * This file is part of OpenOffice.org. 10cdf0e10cSrcweir * 11cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14cdf0e10cSrcweir * 15cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20cdf0e10cSrcweir * 21cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25cdf0e10cSrcweir * 26cdf0e10cSrcweir ************************************************************************/ 27cdf0e10cSrcweir 28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29cdf0e10cSrcweir #include "precompiled_sd.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include "Client.hxx" 32cdf0e10cSrcweir #include <com/sun/star/embed/NoVisualAreaSizeException.hpp> 33cdf0e10cSrcweir #include <svx/svdoole2.hxx> 34cdf0e10cSrcweir #include <svx/svdograf.hxx> 35cdf0e10cSrcweir #include <svx/svdpagv.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include "misc.hxx" 41cdf0e10cSrcweir 42cdf0e10cSrcweir #ifdef STARIMAGE_AVAILABLE 43cdf0e10cSrcweir #ifndef _SIMDLL_HXX 44cdf0e10cSrcweir #include <sim2/simdll.hxx> 45cdf0e10cSrcweir #endif 46cdf0e10cSrcweir #endif 47cdf0e10cSrcweir 48cdf0e10cSrcweir #include "strings.hrc" 49cdf0e10cSrcweir #include "ViewShell.hxx" 50cdf0e10cSrcweir #include "DrawViewShell.hxx" 51cdf0e10cSrcweir #include "View.hxx" 52cdf0e10cSrcweir #include "Window.hxx" 53cdf0e10cSrcweir #include "sdresid.hxx" 54cdf0e10cSrcweir #include <vcl/svapp.hxx> 55cdf0e10cSrcweir 56cdf0e10cSrcweir using namespace com::sun::star; 57cdf0e10cSrcweir 58cdf0e10cSrcweir namespace sd { 59cdf0e10cSrcweir 60cdf0e10cSrcweir /************************************************************************* 61cdf0e10cSrcweir |* 62cdf0e10cSrcweir |* Ctor 63cdf0e10cSrcweir |* 64cdf0e10cSrcweir \************************************************************************/ 65cdf0e10cSrcweir 66cdf0e10cSrcweir Client::Client(SdrOle2Obj* pObj, ViewShell* pViewShell, ::Window* pWindow) : 67cdf0e10cSrcweir SfxInPlaceClient(pViewShell->GetViewShell(), pWindow, pObj->GetAspect() ), 68cdf0e10cSrcweir mpViewShell(pViewShell), 69cdf0e10cSrcweir pSdrOle2Obj(pObj), 70cdf0e10cSrcweir pSdrGrafObj(NULL), 71cdf0e10cSrcweir pOutlinerParaObj (NULL) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir SetObject( pObj->GetObjRef() ); 74cdf0e10cSrcweir DBG_ASSERT( GetObject().is(), "No object connected!" ); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir /************************************************************************* 78cdf0e10cSrcweir |* 79cdf0e10cSrcweir |* Dtor 80cdf0e10cSrcweir |* 81cdf0e10cSrcweir \************************************************************************/ 82cdf0e10cSrcweir 83cdf0e10cSrcweir Client::~Client() 84cdf0e10cSrcweir { 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir 88cdf0e10cSrcweir /************************************************************************* 89cdf0e10cSrcweir |* 90cdf0e10cSrcweir |* Wenn IP-aktiv, dann kommt diese Anforderung um Vergroesserung des 91cdf0e10cSrcweir |* sichtbaren Ausschnitts des Objektes 92cdf0e10cSrcweir |* 93cdf0e10cSrcweir \************************************************************************/ 94cdf0e10cSrcweir 95cdf0e10cSrcweir void Client::RequestNewObjectArea( Rectangle& aObjRect ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir ::sd::View* pView = mpViewShell->GetView(); 98cdf0e10cSrcweir 99cdf0e10cSrcweir sal_Bool bSizeProtect = sal_False; 100cdf0e10cSrcweir sal_Bool bPosProtect = sal_False; 101cdf0e10cSrcweir 102cdf0e10cSrcweir const SdrMarkList& rMarkList = pView->GetMarkedObjectList(); 103cdf0e10cSrcweir if (rMarkList.GetMarkCount() == 1) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir SdrMark* pMark = rMarkList.GetMark(0); 106cdf0e10cSrcweir SdrObject* pObj = pMark->GetMarkedSdrObj(); 107cdf0e10cSrcweir 108cdf0e10cSrcweir // no need to check for changes, this method is called only if the area really changed 109cdf0e10cSrcweir bSizeProtect = pObj->IsResizeProtect(); 110cdf0e10cSrcweir bPosProtect = pObj->IsMoveProtect(); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir Rectangle aOldRect = GetObjArea(); 114cdf0e10cSrcweir if ( bPosProtect ) 115cdf0e10cSrcweir aObjRect.SetPos( aOldRect.TopLeft() ); 116cdf0e10cSrcweir 117cdf0e10cSrcweir if ( bSizeProtect ) 118cdf0e10cSrcweir aObjRect.SetSize( aOldRect.GetSize() ); 119cdf0e10cSrcweir 120cdf0e10cSrcweir Rectangle aWorkArea( pView->GetWorkArea() ); 121cdf0e10cSrcweir if ( !aWorkArea.IsInside(aObjRect) && !bPosProtect && aObjRect != aOldRect ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir // correct position 124cdf0e10cSrcweir Point aPos = aObjRect.TopLeft(); 125cdf0e10cSrcweir Size aSize = aObjRect.GetSize(); 126cdf0e10cSrcweir Point aWorkAreaTL = aWorkArea.TopLeft(); 127cdf0e10cSrcweir Point aWorkAreaBR = aWorkArea.BottomRight(); 128cdf0e10cSrcweir 129cdf0e10cSrcweir aPos.X() = Max(aPos.X(), aWorkAreaTL.X()); 130cdf0e10cSrcweir aPos.X() = Min(aPos.X(), aWorkAreaBR.X()-aSize.Width()); 131cdf0e10cSrcweir aPos.Y() = Max(aPos.Y(), aWorkAreaTL.Y()); 132cdf0e10cSrcweir aPos.Y() = Min(aPos.Y(), aWorkAreaBR.Y()-aSize.Height()); 133cdf0e10cSrcweir 134cdf0e10cSrcweir aObjRect.SetPos(aPos); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir void Client::ObjectAreaChanged() 139cdf0e10cSrcweir { 140cdf0e10cSrcweir ::sd::View* pView = mpViewShell->GetView(); 141cdf0e10cSrcweir const SdrMarkList& rMarkList = pView->GetMarkedObjectList(); 142cdf0e10cSrcweir if (rMarkList.GetMarkCount() == 1) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir SdrMark* pMark = rMarkList.GetMark(0); 145*079eb148SJürgen Schmidt SdrOle2Obj* pObj = dynamic_cast< SdrOle2Obj* >(pMark->GetMarkedSdrObj()); 146cdf0e10cSrcweir 147*079eb148SJürgen Schmidt if(pObj) 148*079eb148SJürgen Schmidt { 149*079eb148SJürgen Schmidt // no need to check for changes, this method is called only if the area really changed 150*079eb148SJürgen Schmidt Rectangle aNewRectangle(GetScaledObjArea()); 151*079eb148SJürgen Schmidt 152*079eb148SJürgen Schmidt // #i118524# if sheared/rotated, center to non-rotated LogicRect 153*079eb148SJürgen Schmidt pObj->setSuppressSetVisAreaSize(true); 154*079eb148SJürgen Schmidt 155*079eb148SJürgen Schmidt if(pObj->GetGeoStat().nDrehWink || pObj->GetGeoStat().nShearWink) 156*079eb148SJürgen Schmidt { 157*079eb148SJürgen Schmidt pObj->SetLogicRect( aNewRectangle ); 158*079eb148SJürgen Schmidt 159*079eb148SJürgen Schmidt const Rectangle& rBoundRect = pObj->GetCurrentBoundRect(); 160*079eb148SJürgen Schmidt const Point aDelta(aNewRectangle.Center() - rBoundRect.Center()); 161*079eb148SJürgen Schmidt 162*079eb148SJürgen Schmidt aNewRectangle.Move(aDelta.X(), aDelta.Y()); 163*079eb148SJürgen Schmidt } 164*079eb148SJürgen Schmidt 165*079eb148SJürgen Schmidt pObj->SetLogicRect( aNewRectangle ); 166*079eb148SJürgen Schmidt pObj->setSuppressSetVisAreaSize(false); 167*079eb148SJürgen Schmidt } 168cdf0e10cSrcweir } 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir /************************************************************************* 172cdf0e10cSrcweir |* 173cdf0e10cSrcweir |* 174cdf0e10cSrcweir |* 175cdf0e10cSrcweir \************************************************************************/ 176cdf0e10cSrcweir 177cdf0e10cSrcweir void Client::ViewChanged() 178cdf0e10cSrcweir { 179cdf0e10cSrcweir if ( GetAspect() == embed::Aspects::MSOLE_ICON ) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir // the iconified object seems not to need such a scaling handling 182cdf0e10cSrcweir // since the replacement image and the size a completely controlled by the container 183cdf0e10cSrcweir // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here 184cdf0e10cSrcweir 185cdf0e10cSrcweir pSdrOle2Obj->ActionChanged(); // draw needs it to remove lines in slide preview 186cdf0e10cSrcweir return; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir //TODO/LATER: should we try to avoid the recalculation of the visareasize 190cdf0e10cSrcweir //if we know that it didn't change? 191cdf0e10cSrcweir if (mpViewShell->GetActiveWindow()) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir ::sd::View* pView = mpViewShell->GetView(); 194cdf0e10cSrcweir if (pView) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir Rectangle aLogicRect( pSdrOle2Obj->GetLogicRect() ); 197cdf0e10cSrcweir Size aLogicSize( aLogicRect.GetWidth(), aLogicRect.GetHeight() ); 198cdf0e10cSrcweir 199cdf0e10cSrcweir if( pSdrOle2Obj->IsChart() ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir //charts never should be stretched see #i84323# for example 202cdf0e10cSrcweir pSdrOle2Obj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aLogicSize ) ); 203cdf0e10cSrcweir pSdrOle2Obj->BroadcastObjectChange(); 204cdf0e10cSrcweir return; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir // TODO/LEAN: maybe we can do this without requesting the VisualArea? 208cdf0e10cSrcweir // working with the visual area might need running state, so the object may switch itself to this state 209cdf0e10cSrcweir MapMode aMap100( MAP_100TH_MM ); 210cdf0e10cSrcweir Rectangle aVisArea; 211cdf0e10cSrcweir Size aSize = pSdrOle2Obj->GetOrigObjSize( &aMap100 ); 212cdf0e10cSrcweir 213cdf0e10cSrcweir aVisArea.SetSize( aSize ); 214cdf0e10cSrcweir Size aScaledSize( static_cast< long >( GetScaleWidth() * Fraction( aVisArea.GetWidth() ) ), 215cdf0e10cSrcweir static_cast< long >( GetScaleHeight() * Fraction( aVisArea.GetHeight() ) ) ); 216cdf0e10cSrcweir 217cdf0e10cSrcweir // react to the change if the difference is bigger than one pixel 218cdf0e10cSrcweir Size aPixelDiff = 219cdf0e10cSrcweir Application::GetDefaultDevice()->LogicToPixel( 220cdf0e10cSrcweir Size( aLogicRect.GetWidth() - aScaledSize.Width(), 221cdf0e10cSrcweir aLogicRect.GetHeight() - aScaledSize.Height() ), 222cdf0e10cSrcweir aMap100 ); 223cdf0e10cSrcweir if( aPixelDiff.Width() || aPixelDiff.Height() ) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir pSdrOle2Obj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aScaledSize ) ); 226cdf0e10cSrcweir pSdrOle2Obj->BroadcastObjectChange(); 227cdf0e10cSrcweir } 228cdf0e10cSrcweir else 229cdf0e10cSrcweir pSdrOle2Obj->ActionChanged(); 230cdf0e10cSrcweir } 231cdf0e10cSrcweir } 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir 235cdf0e10cSrcweir /************************************************************************* 236cdf0e10cSrcweir |* 237cdf0e10cSrcweir |* Objekt in den sichtbaren Breich scrollen 238cdf0e10cSrcweir |* 239cdf0e10cSrcweir \************************************************************************/ 240cdf0e10cSrcweir 241cdf0e10cSrcweir void Client::MakeVisible() 242cdf0e10cSrcweir { 243cdf0e10cSrcweir if (mpViewShell->ISA(DrawViewShell)) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir static_cast<DrawViewShell*>(mpViewShell)->MakeVisible( 246cdf0e10cSrcweir pSdrOle2Obj->GetLogicRect(), 247cdf0e10cSrcweir *mpViewShell->GetActiveWindow()); 248cdf0e10cSrcweir } 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir } // end of namespace sd 252cdf0e10cSrcweir 253