xref: /AOO41X/main/sfx2/source/doc/objembed.cxx (revision d119d52d53d0b2180f2ae51341d882123be2af2b)
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_sfx2.hxx"
26 #include <com/sun/star/container/XChild.hpp>
27 #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
28 #include <com/sun/star/embed/XComponentSupplier.hpp>
29 #include <com/sun/star/embed/XEmbedPersist.hpp>
30 #include <com/sun/star/util/XCloseable.hpp>
31 #include <com/sun/star/embed/EmbedStates.hpp>
32 
33 #include <sfx2/objsh.hxx>
34 #include <sfx2/app.hxx>
35 #include "objshimp.hxx"
36 #include <sfx2/sfx.hrc>
37 #include <sfx2/event.hxx>
38 
39 #include <comphelper/seqstream.hxx>
40 #include <comphelper/processfactory.hxx>
41 #include <comphelper/storagehelper.hxx>
42 #include <svtools/embedtransfer.hxx>
43 #include <vcl/outdev.hxx>
44 #include <vcl/gdimtf.hxx>
45 
46 using namespace ::com::sun::star;
47 
48 // -----------------------------------------------------------------------
49 // TODO/LATER: this workaround must be replaced by API in future if possible
GetParentShellByModel_Impl()50 SfxObjectShell* SfxObjectShell::GetParentShellByModel_Impl()
51 {
52     SfxObjectShell* pResult = NULL;
53 
54     try {
55         uno::Reference< container::XChild > xChildModel( GetModel(), uno::UNO_QUERY );
56         if ( xChildModel.is() )
57         {
58             uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
59             if ( xParentTunnel.is() )
60             {
61                 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
62                 pResult = reinterpret_cast<SfxObjectShell*>(xParentTunnel->getSomething(
63                                                 uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
64             }
65         }
66     }
67     catch( uno::Exception& )
68     {
69         // TODO: error handling
70     }
71 
72     return pResult;
73 }
74 
75 // -----------------------------------------------------------------------
GetDocumentPrinter()76 Printer* SfxObjectShell::GetDocumentPrinter()
77 {
78     SfxObjectShell* pParent = GetParentShellByModel_Impl();
79     if ( pParent )
80         return pParent->GetDocumentPrinter();
81     return NULL;
82 }
83 
84 // -----------------------------------------------------------------------
GetDocumentRefDev()85 OutputDevice* SfxObjectShell::GetDocumentRefDev()
86 {
87     SfxObjectShell* pParent = GetParentShellByModel_Impl();
88     if ( pParent )
89         return pParent->GetDocumentRefDev();
90     return NULL;
91 }
92 
93 // -----------------------------------------------------------------------
OnDocumentPrinterChanged(Printer *)94 void SfxObjectShell::OnDocumentPrinterChanged( Printer* /*pNewPrinter*/ )
95 {
96     // virtual method
97 }
98 
99 // -----------------------------------------------------------------------
GetVisArea(sal_uInt16 nAspect) const100 Rectangle SfxObjectShell::GetVisArea( sal_uInt16 nAspect ) const
101 {
102     if( nAspect == ASPECT_CONTENT )
103         return pImp->m_aVisArea;
104     else if( nAspect == ASPECT_THUMBNAIL )
105     {
106         Rectangle aRect;
107         aRect.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ),
108                                          MAP_100TH_MM, GetMapUnit() ) );
109         return aRect;
110     }
111     return Rectangle();
112 }
113 
114 // -----------------------------------------------------------------------
GetVisArea() const115 const Rectangle& SfxObjectShell::GetVisArea() const
116 {
117     pImp->m_aVisArea = GetVisArea( ASPECT_CONTENT );
118     return pImp->m_aVisArea;
119 }
120 
121 // -----------------------------------------------------------------------
SetVisArea(const Rectangle & rVisArea)122 void SfxObjectShell::SetVisArea( const Rectangle & rVisArea )
123 {
124     if( pImp->m_aVisArea != rVisArea )
125     {
126         pImp->m_aVisArea = rVisArea;
127         if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
128         {
129             if ( IsEnableSetModified() )
130                 SetModified( sal_True );
131 
132             SFX_APP()->NotifyEvent(SfxEventHint( SFX_EVENT_VISAREACHANGED, GlobalEventConfig::GetEventName(STR_EVENT_VISAREACHANGED), this));
133 
134             /*
135             Size aSize (GetVisArea().GetSize());
136             if ( GetIPEnv() && GetIPEnv()->GetEditWin() )
137                 ViewChanged( ASPECT_CONTENT );
138             */
139 
140 
141             // OutPlace die Gr"o\se des MDI-Fensters anpassen
142             // Unbedingt den Gr"o\senvergleich machen, spart nicht nur Zeit, sondern
143             // vermeidet auch Rundungsfehler !
144             /*
145                 // in case of ole outplace editing the frame should be found
146                 SfxViewFrame* pFrameToResize = pFrame ? pFrame : SfxViewFrame::GetFirst( GetObjectShell() );
147 
148                 if ( pFrameToResize && !pIPF && rRect.GetSize() != aSize &&
149                     !pFrameToResize->IsAdjustPosSizePixelLocked_Impl() )
150 
151                 {
152                     // Zuerst die logischen Koordinaten von IP-Objekt und EditWindow
153                     // ber"ucksichtigen
154                     SfxViewShell *pShell = pFrameToResize->GetViewShell();
155                     Window *pWindow = pShell->GetWindow();
156 
157                     // Da in den Applikationen bei der R"ucktransformation immer die
158                     // Eckpunkte tranformiert werden und nicht die Size (um die Ecken
159                     // alignen zu k"onnen), transformieren wir hier auch die Punkte, um
160                     // m"oglichst wenig Rundungsfehler zu erhalten.
161                     Rectangle aRect = pWindow->LogicToPixel( rRect );
162                     Size aSize = aRect.GetSize();
163                     pShell->GetWindow()->SetSizePixel( aSize );
164                     pFrameToResize->DoAdjustPosSizePixel( pShell, Point(), aSize );
165                 }
166 
167             // bei InPlace die View skalieren
168             if ( GetIPEnv() && GetIPEnv()->GetEditWin() && !bDisableViewScaling && pIPF )
169                 pIPF->GetEnv_Impl()->MakeScale( rRect.GetSize(), GetMapUnit(),
170                             pIPF->GetViewShell()->GetWindow()->GetOutputSizePixel() );
171            */
172         }
173     }
174 }
175 
176 // -----------------------------------------------------------------------
SetVisAreaSize(const Size & rVisSize)177 void SfxObjectShell::SetVisAreaSize( const Size & rVisSize )
178 {
179     SetVisArea( Rectangle( GetVisArea().TopLeft(), rVisSize ) );
180 }
181 
182 // -----------------------------------------------------------------------
GetMiscStatus() const183 sal_uIntPtr SfxObjectShell::GetMiscStatus() const
184 {
185     return 0;
186 }
187 
188 // -----------------------------------------------------------------------
GetMapUnit() const189 MapUnit SfxObjectShell::GetMapUnit() const
190 {
191     return pImp->m_nMapUnit;
192 }
193 
194 // -----------------------------------------------------------------------
SetMapUnit(MapUnit nMapUnit)195 void SfxObjectShell::SetMapUnit( MapUnit nMapUnit )
196 {
197     pImp->m_nMapUnit = nMapUnit;
198 }
199 
200 // -----------------------------------------------------------------------
FillTransferableObjectDescriptor(TransferableObjectDescriptor & rDesc) const201 void SfxObjectShell::FillTransferableObjectDescriptor( TransferableObjectDescriptor& rDesc ) const
202 {
203     sal_uInt32 nClipFormat;
204     String aAppName, aShortName;
205     FillClass( &rDesc.maClassName, &nClipFormat, &aAppName, &rDesc.maTypeName, &aShortName, SOFFICE_FILEFORMAT_CURRENT );
206 
207     rDesc.mnViewAspect = ASPECT_CONTENT;
208     rDesc.mnOle2Misc = GetMiscStatus();
209     rDesc.maSize = OutputDevice::LogicToLogic( GetVisArea().GetSize(), GetMapUnit(), MAP_100TH_MM );
210     rDesc.maDragStartPos = Point();
211     rDesc.maDisplayName = String();
212     rDesc.mbCanLink = sal_False;
213 }
214 
215 // -----------------------------------------------------------------------
DoDraw(OutputDevice * pDev,const Point & rObjPos,const Size & rSize,const JobSetup & rSetup,sal_uInt16 nAspect)216 void SfxObjectShell::DoDraw( OutputDevice* pDev,
217                             const Point & rObjPos,
218                             const Size & rSize,
219                             const JobSetup & rSetup,
220                             sal_uInt16 nAspect )
221 {
222     MapMode aMod = pDev->GetMapMode();
223     Size aSize = GetVisArea( nAspect ).GetSize();
224     MapMode aWilliMode( GetMapUnit() );
225     aSize = pDev->LogicToLogic( aSize, &aWilliMode, &aMod );
226     if( aSize.Width() && aSize.Height() )
227     {
228         Fraction aXF( rSize.Width(), aSize.Width() );
229         Fraction aYF( rSize.Height(), aSize.Height() );
230 
231 //REMOVE            Point aOrg = rObjPos;
232 //REMOVE            aMod.SetMapUnit( MAP_100TH_MM );
233 //REMOVE            aSize = pDev->LogicToLogic( GetVisArea( nAspect ).GetSize(), &aMod, &aWilliMode );
234         DoDraw_Impl( pDev, rObjPos, aXF, aYF, rSetup, nAspect );
235     }
236 }
237 
238 // -----------------------------------------------------------------------
DoDraw_Impl(OutputDevice * pDev,const Point & rViewPos,const Fraction & rScaleX,const Fraction & rScaleY,const JobSetup & rSetup,sal_uInt16 nAspect)239 void SfxObjectShell::DoDraw_Impl( OutputDevice* pDev,
240                                const Point & rViewPos,
241                                const Fraction & rScaleX,
242                                const Fraction & rScaleY,
243                                const JobSetup & rSetup,
244                                sal_uInt16 nAspect )
245 {
246     Rectangle aVisArea  = GetVisArea( nAspect );
247     // MapUnit des Ziels
248     MapMode aMapMode( GetMapUnit() );
249     aMapMode.SetScaleX( rScaleX );
250     aMapMode.SetScaleY( rScaleY );
251 
252     // Ziel in Pixel
253     Point aOrg   = pDev->LogicToLogic( rViewPos, NULL, &aMapMode );
254     Point aDelta = aOrg - aVisArea.TopLeft();
255 
256     // Origin entsprechend zum sichtbaren Bereich verschieben
257     // Origin mit Scale setzen
258     aMapMode.SetOrigin( aDelta );
259 
260     // Deviceeinstellungen sichern
261     pDev->Push();
262 
263     Region aRegion;
264     if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
265     {
266         aRegion = pDev->GetClipRegion();
267         aRegion = pDev->LogicToPixel( aRegion );
268     }
269     pDev->SetRelativeMapMode( aMapMode );
270 
271     GDIMetaFile * pMtf = pDev->GetConnectMetaFile();
272     if( pMtf )
273     {
274         if( pMtf->IsRecord() && pDev->GetOutDevType() != OUTDEV_PRINTER )
275             pMtf->Stop();
276         else
277             pMtf = NULL;
278     }
279 // #ifndef UNX
280     if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
281 // #endif
282     {
283         aRegion = pDev->PixelToLogic( aRegion );
284         pDev->SetClipRegion( aRegion );
285     }
286     if( pMtf )
287         pMtf->Record( pDev );
288 
289 //REMOVE        SvOutPlaceObjectRef xOutRef( this );
290 //REMOVE        if ( xOutRef.Is() )
291 //REMOVE            xOutRef->DrawObject( pDev, rSetup, rSize, nAspect );
292 //REMOVE        else
293         Draw( pDev, rSetup, nAspect );
294 //REMOVE        DrawHatch( pDev, aVisArea.TopLeft(), aVisArea.GetSize() );
295 
296     // Deviceeinstellungen wieder herstellen
297     pDev->Pop();
298 
299 }
300 
GetEmbeddedObjectContainer() const301 comphelper::EmbeddedObjectContainer& SfxObjectShell::GetEmbeddedObjectContainer() const
302 {
303     if ( !pImp->mpObjectContainer )
304         pImp->mpObjectContainer = new comphelper::EmbeddedObjectContainer( ((SfxObjectShell*)this)->GetStorage(), GetModel() );
305     return *pImp->mpObjectContainer;
306 }
307 
ClearEmbeddedObjects()308 void SfxObjectShell::ClearEmbeddedObjects()
309 {
310     // frees alle space taken by embedded objects
311     DELETEZ( pImp->mpObjectContainer );
312 }
313 
314