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