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