xref: /aoo42x/main/sd/source/ui/docshell/sdclient.cxx (revision cdf0e10c)
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 		SdrObject* pObj = pMark->GetMarkedSdrObj();
146 
147         // no need to check for changes, this method is called only if the area really changed
148         pObj->SetLogicRect( GetScaledObjArea() );
149 	}
150 }
151 
152 /*************************************************************************
153 |*
154 |*
155 |*
156 \************************************************************************/
157 
158 void Client::ViewChanged()
159 {
160 	if ( GetAspect() == embed::Aspects::MSOLE_ICON )
161 	{
162 		// the iconified object seems not to need such a scaling handling
163 		// since the replacement image and the size a completely controlled by the container
164 		// TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
165 
166 		pSdrOle2Obj->ActionChanged(); // draw needs it to remove lines in slide preview
167 		return;
168 	}
169 
170     //TODO/LATER: should we try to avoid the recalculation of the visareasize
171     //if we know that it didn't change?
172     if (mpViewShell->GetActiveWindow())
173 	{
174 		::sd::View* pView = mpViewShell->GetView();
175 		if (pView)
176 		{
177             Rectangle aLogicRect( pSdrOle2Obj->GetLogicRect() );
178             Size aLogicSize( aLogicRect.GetWidth(), aLogicRect.GetHeight() );
179 
180             if( pSdrOle2Obj->IsChart() )
181             {
182                 //charts never should be stretched see #i84323# for example
183                 pSdrOle2Obj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aLogicSize ) );
184                 pSdrOle2Obj->BroadcastObjectChange();
185                 return;
186             }
187 
188             // TODO/LEAN: maybe we can do this without requesting the VisualArea?
189             // working with the visual area might need running state, so the object may switch itself to this state
190             MapMode             aMap100( MAP_100TH_MM );
191             Rectangle           aVisArea;
192             Size aSize = pSdrOle2Obj->GetOrigObjSize( &aMap100 );
193 
194             aVisArea.SetSize( aSize );
195             Size                aScaledSize( static_cast< long >( GetScaleWidth() * Fraction( aVisArea.GetWidth() ) ),
196                                                 static_cast< long >( GetScaleHeight() * Fraction( aVisArea.GetHeight() ) ) );
197 
198             // react to the change if the difference is bigger than one pixel
199             Size aPixelDiff =
200                 Application::GetDefaultDevice()->LogicToPixel(
201                     Size( aLogicRect.GetWidth() - aScaledSize.Width(),
202                           aLogicRect.GetHeight() - aScaledSize.Height() ),
203                     aMap100 );
204             if( aPixelDiff.Width() || aPixelDiff.Height() )
205             {
206                 pSdrOle2Obj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aScaledSize ) );
207                 pSdrOle2Obj->BroadcastObjectChange();
208             }
209             else
210                 pSdrOle2Obj->ActionChanged();
211 		}
212 	}
213 }
214 
215 
216 /*************************************************************************
217 |*
218 |* Objekt in den sichtbaren Breich scrollen
219 |*
220 \************************************************************************/
221 
222 void Client::MakeVisible()
223 {
224 	if (mpViewShell->ISA(DrawViewShell))
225 	{
226 		static_cast<DrawViewShell*>(mpViewShell)->MakeVisible(
227             pSdrOle2Obj->GetLogicRect(),
228             *mpViewShell->GetActiveWindow());
229 	}
230 }
231 
232 } // end of namespace sd
233 
234