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