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