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_sc.hxx" 26 27 // INCLUDE --------------------------------------------------------------- 28 29 30 #include <com/sun/star/embed/XEmbeddedObject.hpp> 31 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp> 32 33 #include <toolkit/helper/vclunohelper.hxx> 34 #include <sfx2/objsh.hxx> 35 #include <sfx2/viewfrm.hxx> 36 #include <sot/sotref.hxx> 37 #include <svx/svditer.hxx> 38 #include <svx/svdobj.hxx> 39 #include <svx/svdmodel.hxx> 40 #include <svx/svdpage.hxx> 41 #include <svx/svdoole2.hxx> 42 #include <svx/svdview.hxx> 43 #include <svx/svdograf.hxx> 44 #include <svtools/embedhlp.hxx> 45 46 #include "client.hxx" 47 #include "tabvwsh.hxx" 48 #include "docsh.hxx" 49 50 using namespace com::sun::star; 51 52 //------------------------------------------------------------------------ 53 54 ScClient::ScClient( ScTabViewShell* pViewShell, Window* pDraw, SdrModel* pSdrModel, SdrOle2Obj* pObj ) : 55 SfxInPlaceClient( pViewShell, pDraw, pObj->GetAspect() ), 56 pModel( pSdrModel ), 57 pGrafEdit( 0 ) 58 { 59 SetObject( pObj->GetObjRef() ); 60 } 61 62 __EXPORT ScClient::~ScClient() 63 { 64 } 65 66 SdrOle2Obj* ScClient::GetDrawObj() 67 { 68 uno::Reference < embed::XEmbeddedObject > xObj = GetObject(); 69 SdrOle2Obj* pOle2Obj = NULL; 70 String aName = GetViewShell()->GetObjectShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj ); 71 72 sal_uInt16 nPages = pModel->GetPageCount(); 73 for (sal_uInt16 nPNr=0; nPNr<nPages && !pOle2Obj; nPNr++) 74 { 75 SdrPage* pPage = pModel->GetPage(nPNr); 76 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS ); 77 SdrObject* pObject = aIter.Next(); 78 while (pObject && !pOle2Obj) 79 { 80 if ( pObject->GetObjIdentifier() == OBJ_OLE2 ) 81 { 82 // name from InfoObject is PersistName 83 if ( ((SdrOle2Obj*)pObject)->GetPersistName() == aName ) 84 pOle2Obj = (SdrOle2Obj*)pObject; 85 } 86 pObject = aIter.Next(); 87 } 88 } 89 return pOle2Obj; 90 } 91 92 void __EXPORT ScClient::RequestNewObjectArea( Rectangle& aLogicRect ) 93 { 94 SfxViewShell* pSfxViewSh = GetViewShell(); 95 ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh ); 96 if (!pViewSh) 97 { 98 DBG_ERROR("Wrong ViewShell"); 99 return; 100 } 101 102 Rectangle aOldRect = GetObjArea(); 103 SdrOle2Obj* pDrawObj = GetDrawObj(); 104 if ( pDrawObj ) 105 { 106 if ( pDrawObj->IsResizeProtect() ) 107 aLogicRect.SetSize( aOldRect.GetSize() ); 108 109 if ( pDrawObj->IsMoveProtect() ) 110 aLogicRect.SetPos( aOldRect.TopLeft() ); 111 } 112 113 sal_uInt16 nTab = pViewSh->GetViewData()->GetTabNo(); 114 SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(static_cast<sal_Int16>(nTab))); 115 if ( pPage && aLogicRect != aOldRect ) 116 { 117 Point aPos; 118 Size aSize = pPage->GetSize(); 119 if ( aSize.Width() < 0 ) 120 { 121 aPos.X() = aSize.Width() + 1; // negative 122 aSize.Width() = -aSize.Width(); // positive 123 } 124 Rectangle aPageRect( aPos, aSize ); 125 126 if (aLogicRect.Right() > aPageRect.Right()) 127 { 128 long nDiff = aLogicRect.Right() - aPageRect.Right(); 129 aLogicRect.Left() -= nDiff; 130 aLogicRect.Right() -= nDiff; 131 } 132 if (aLogicRect.Bottom() > aPageRect.Bottom()) 133 { 134 long nDiff = aLogicRect.Bottom() - aPageRect.Bottom(); 135 aLogicRect.Top() -= nDiff; 136 aLogicRect.Bottom() -= nDiff; 137 } 138 139 if (aLogicRect.Left() < aPageRect.Left()) 140 { 141 long nDiff = aLogicRect.Left() - aPageRect.Left(); 142 aLogicRect.Right() -= nDiff; 143 aLogicRect.Left() -= nDiff; 144 } 145 if (aLogicRect.Top() < aPageRect.Top()) 146 { 147 long nDiff = aLogicRect.Top() - aPageRect.Top(); 148 aLogicRect.Bottom() -= nDiff; 149 aLogicRect.Top() -= nDiff; 150 } 151 } 152 } 153 154 void __EXPORT ScClient::ObjectAreaChanged() 155 { 156 SfxViewShell* pSfxViewSh = GetViewShell(); 157 ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh ); 158 if (!pViewSh) 159 { 160 DBG_ERROR("Wrong ViewShell"); 161 return; 162 } 163 164 // Position und Groesse ins Dokument uebernehmen 165 SdrOle2Obj* pDrawObj = GetDrawObj(); 166 if (pDrawObj) 167 { 168 Rectangle aNewRectangle(GetScaledObjArea()); 169 170 // #i118524# if sheared/rotated, center to non-rotated LogicRect 171 pDrawObj->setSuppressSetVisAreaSize(true); 172 173 if(pDrawObj->GetGeoStat().nDrehWink || pDrawObj->GetGeoStat().nShearWink) 174 { 175 pDrawObj->SetLogicRect( aNewRectangle ); 176 177 const Rectangle& rBoundRect = pDrawObj->GetCurrentBoundRect(); 178 const Point aDelta(aNewRectangle.Center() - rBoundRect.Center()); 179 180 aNewRectangle.Move(aDelta.X(), aDelta.Y()); 181 } 182 183 pDrawObj->SetLogicRect( aNewRectangle ); 184 pDrawObj->setSuppressSetVisAreaSize(false); 185 186 // set document modified (SdrModel::SetChanged is not used) 187 // TODO/LATER: is there a reason that this code is not executed in Draw? 188 // SfxViewShell* pSfxViewSh = GetViewShell(); 189 // ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh ); 190 if (pViewSh) 191 pViewSh->GetViewData()->GetDocShell()->SetDrawModified(); 192 } 193 194 if (pDrawObj) 195 pViewSh->ScrollToObject( pDrawObj ); 196 } 197 198 void __EXPORT ScClient::ViewChanged() 199 { 200 if ( GetAspect() == embed::Aspects::MSOLE_ICON ) 201 { 202 // the iconified object seems not to need such a scaling handling 203 // since the replacement image and the size a completely controlled by the container 204 // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here 205 206 return; 207 } 208 209 uno::Reference < embed::XEmbeddedObject > xObj = GetObject(); 210 211 // TODO/LEAN: working with Visual Area can switch object to running state 212 awt::Size aSz; 213 try { 214 aSz = xObj->getVisualAreaSize( GetAspect() ); 215 } catch ( embed::NoVisualAreaSizeException& ) 216 { 217 DBG_ERROR("The visual area size must be available!\n"); 218 } 219 220 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( GetAspect() ) ); 221 Size aVisSize = OutputDevice::LogicToLogic( Size( aSz.Width, aSz.Height ), aMapUnit, MAP_100TH_MM ); 222 223 // Groesse ins Dokument uebernehmen 224 SdrOle2Obj* pDrawObj = GetDrawObj(); 225 if (pDrawObj) 226 { 227 Rectangle aLogicRect = pDrawObj->GetLogicRect(); 228 Fraction aFractX = GetScaleWidth(); 229 Fraction aFractY = GetScaleHeight(); 230 aFractX *= aVisSize.Width(); 231 aFractY *= aVisSize.Height(); 232 aVisSize = Size( (long) aFractX, (long) aFractY ); // skaliert fuer Draw-Model 233 234 // pClientData->SetObjArea vor pDrawObj->SetLogicRect, damit keine 235 // falschen Skalierungen ausgerechnet werden: 236 //Rectangle aObjArea = aLogicRect; 237 //aObjArea.SetSize( aVisSize ); // Dokument-Groesse vom Server 238 //SetObjArea( aObjArea ); 239 240 SfxViewShell* pSfxViewSh = GetViewShell(); 241 ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh ); 242 if ( pViewSh ) 243 { 244 Window* pWin = pViewSh->GetActiveWin(); 245 if ( pWin->LogicToPixel( aVisSize ) != pWin->LogicToPixel( aLogicRect.GetSize() ) ) 246 { 247 aLogicRect.SetSize( aVisSize ); 248 pDrawObj->SetLogicRect( aLogicRect ); 249 250 // set document modified (SdrModel::SetChanged is not used) 251 pViewSh->GetViewData()->GetDocShell()->SetDrawModified(); 252 } 253 } 254 } 255 } 256 257 void __EXPORT ScClient::MakeVisible() 258 { 259 SdrOle2Obj* pDrawObj = GetDrawObj(); 260 if (pDrawObj) 261 { 262 SfxViewShell* pSfxViewSh = GetViewShell(); 263 ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh ); 264 if (pViewSh) 265 pViewSh->ScrollToObject( pDrawObj ); 266 } 267 } 268 269