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