xref: /aoo42x/main/sw/source/core/frmedt/feflyole.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_sw.hxx"
30 #include <com/sun/star/embed/EmbedStates.hpp>
31 
32 #ifndef _SFX_CLIENTSH_HXX
33 #include <sfx2/ipclient.hxx>
34 #endif
35 #include <sfx2/viewsh.hxx>
36 #include <sfx2/app.hxx>
37 #include <unotools/moduleoptions.hxx>
38 #include <sfx2/viewfrm.hxx>
39 
40 #include <sot/exchange.hxx>
41 #include <fmtcntnt.hxx>
42 #include <fmtanchr.hxx>
43 #include <fesh.hxx>
44 #include <cntfrm.hxx>
45 #include <frmfmt.hxx>
46 #include <flyfrm.hxx>
47 #include <pam.hxx>
48 #include <doc.hxx>
49 #include <ndtxt.hxx>
50 #include <notxtfrm.hxx>
51 #include <ndole.hxx>
52 #include <swcli.hxx>
53 
54 using namespace com::sun::star;
55 
56 SwFlyFrm *SwFEShell::FindFlyFrm( const uno::Reference < embed::XEmbeddedObject >& xObj ) const
57 {
58 	SwFlyFrm *pFly = FindFlyFrm();
59 	if ( pFly && pFly->Lower() && pFly->Lower()->IsNoTxtFrm() )
60 	{
61 		SwOLENode *pNd = ((SwNoTxtFrm*)pFly->Lower())->GetNode()->GetOLENode();
62         if ( !pNd || pNd->GetOLEObj().GetOleRef() != xObj )
63 			pFly = 0;
64 	}
65 	else
66 		pFly = 0;
67 
68 	if ( !pFly )
69 	{
70 		//Kein Fly oder der falsche selektiert. Ergo muessen wir leider suchen.
71 		sal_Bool bExist = sal_False;
72 		SwStartNode *pStNd;
73 		sal_uLong nSttIdx = GetNodes().GetEndOfAutotext().StartOfSectionIndex() + 1,
74 			  nEndIdx = GetNodes().GetEndOfAutotext().GetIndex();
75 		while( nSttIdx < nEndIdx &&
76 				0 != (pStNd = GetNodes()[ nSttIdx ]->GetStartNode()) )
77 		{
78 			SwNode *pNd = GetNodes()[ nSttIdx+1 ];
79 			if ( pNd->IsOLENode() &&
80                  ((SwOLENode*)pNd)->GetOLEObj().GetOleRef() == xObj )
81 			{
82 				bExist = sal_True;
83 				SwFrm *pFrm = ((SwOLENode*)pNd)->getLayoutFrm( GetLayout() );
84 				if ( pFrm )
85 					pFly = pFrm->FindFlyFrm();
86 				break;
87 			}
88 			nSttIdx = pStNd->EndOfSectionIndex() + 1;
89 		}
90 
91 		ASSERT( bExist, "OLE-Object unknown and FlyFrm not found." );
92 	}
93 	return pFly;
94 }
95 
96 
97 String SwFEShell::GetUniqueOLEName() const
98 {
99 	return GetDoc()->GetUniqueOLEName();
100 }
101 
102 
103 String SwFEShell::GetUniqueFrameName() const
104 {
105 	return GetDoc()->GetUniqueFrameName();
106 }
107 
108 
109 void SwFEShell::MakeObjVisible( const uno::Reference < embed::XEmbeddedObject >& xObj ) const
110 {
111     SwFlyFrm *pFly = FindFlyFrm( xObj );
112 	if ( pFly )
113 	{
114 		SwRect aTmp( pFly->Prt() );
115 		aTmp += pFly->Frm().Pos();
116 		if ( !aTmp.IsOver( VisArea() ) )
117 		{
118 			((SwFEShell*)this)->StartAction();
119 			((SwFEShell*)this)->MakeVisible( aTmp );
120 			((SwFEShell*)this)->EndAction();
121 		}
122 	}
123 }
124 
125 sal_Bool SwFEShell::FinishOLEObj()						// Server wird beendet
126 {
127 	SfxInPlaceClient* pIPClient = GetSfxViewShell()->GetIPClient();
128     if ( !pIPClient )
129         return sal_False;
130 
131     sal_Bool bRet = pIPClient->IsObjectInPlaceActive();
132 	if( bRet )
133 	{
134         uno::Reference < embed::XEmbeddedObject > xObj = pIPClient->GetObject();
135 		if( CNT_OLE == GetCntType() )
136 	        ClearAutomaticContour();
137 
138 		if( ((SwOleClient*)pIPClient)->IsCheckForOLEInCaption() !=
139 			IsCheckForOLEInCaption() )
140 			SetCheckForOLEInCaption( !IsCheckForOLEInCaption() );
141 
142         // leave UIActive state
143         pIPClient->DeactivateObject();
144 	}
145 	return bRet;
146 }
147 
148 
149 
150 
151