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_embeddedobj.hxx"
26 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
27 #include <com/sun/star/embed/EmbedStates.hpp>
28 #include <com/sun/star/embed/EmbedVerbs.hpp>
29 #include <com/sun/star/embed/EmbedUpdateModes.hpp>
30 #include <com/sun/star/embed/XEmbeddedClient.hpp>
31 #include <com/sun/star/embed/XInplaceClient.hpp>
32 #include <com/sun/star/embed/XWindowSupplier.hpp>
33 #include <com/sun/star/embed/Aspects.hpp>
34 #include <com/sun/star/awt/XWindowPeer.hpp>
35 #include <com/sun/star/util/XCloseBroadcaster.hpp>
36 #include <com/sun/star/util/XCloseable.hpp>
37 #include <com/sun/star/util/XModifiable.hpp>
38 #include <com/sun/star/frame/XFrame.hpp>
39 #include <com/sun/star/frame/XComponentLoader.hpp>
40 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
41 #include <com/sun/star/lang/DisposedException.hpp>
42 #include <com/sun/star/embed/EmbedMapUnits.hpp>
43
44 #include <cppuhelper/typeprovider.hxx>
45
46 #include "specialobject.hxx"
47 #include "intercept.hxx"
48
49 using namespace ::com::sun::star;
50
51
OSpecialEmbeddedObject(const uno::Reference<lang::XMultiServiceFactory> & xFactory,const uno::Sequence<beans::NamedValue> & aObjectProps)52 OSpecialEmbeddedObject::OSpecialEmbeddedObject( const uno::Reference< lang::XMultiServiceFactory >& xFactory, const uno::Sequence< beans::NamedValue >& aObjectProps )
53 : OCommonEmbeddedObject( xFactory, aObjectProps )
54 {
55 maSize.Width = maSize.Height = 10000;
56 m_nObjectState = embed::EmbedStates::LOADED;
57 }
58
59 //------------------------------------------------------
queryInterface(const uno::Type & rType)60 uno::Any SAL_CALL OSpecialEmbeddedObject::queryInterface( const uno::Type& rType )
61 throw( uno::RuntimeException )
62 {
63 uno::Any aReturn;
64
65 aReturn <<= ::cppu::queryInterface( rType,
66 static_cast< embed::XEmbeddedObject* >( this ),
67 static_cast< embed::XInplaceObject* >( this ),
68 static_cast< embed::XVisualObject* >( this ),
69 static_cast< embed::XClassifiedObject* >( this ),
70 static_cast< embed::XComponentSupplier* >( this ),
71 static_cast< util::XCloseable* >( this ),
72 static_cast< document::XEventBroadcaster* >( this ) );
73 if ( aReturn.hasValue() )
74 return aReturn;
75 else
76 return ::cppu::OWeakObject::queryInterface( rType ) ;
77
78 }
79
80 //------------------------------------------------------
getTypes()81 uno::Sequence< uno::Type > SAL_CALL OSpecialEmbeddedObject::getTypes()
82 throw( uno::RuntimeException )
83 {
84 static ::cppu::OTypeCollection* pTypeCollection = NULL;
85
86 if ( !pTypeCollection )
87 {
88 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
89 if ( !pTypeCollection )
90 {
91 static ::cppu::OTypeCollection aTypeCollection(
92 ::getCppuType( (const uno::Reference< lang::XTypeProvider >*)NULL ),
93 ::getCppuType( (const uno::Reference< embed::XEmbeddedObject >*)NULL ),
94 ::getCppuType( (const uno::Reference< embed::XInplaceObject >*)NULL ) );
95
96 pTypeCollection = &aTypeCollection ;
97 }
98 }
99
100 return pTypeCollection->getTypes() ;
101
102 }
103
getPreferredVisualRepresentation(sal_Int64 nAspect)104 embed::VisualRepresentation SAL_CALL OSpecialEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
105 throw ( lang::IllegalArgumentException,
106 embed::WrongStateException,
107 uno::Exception,
108 uno::RuntimeException )
109 {
110 ::osl::MutexGuard aGuard( m_aMutex );
111 if ( m_bDisposed )
112 throw lang::DisposedException(); // TODO
113
114 // TODO: if object is in loaded state it should switch itself to the running state
115 if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::LOADED )
116 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ),
117 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
118
119 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
120 if ( nAspect == embed::Aspects::MSOLE_ICON )
121 // no representation can be retrieved
122 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
123 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
124
125 // TODO: return for the aspect of the document
126 embed::VisualRepresentation aVisualRepresentation;
127 /*
128 OSL_ENSURE( m_pDocHolder->GetComponent().is(), "Running or Active object has no component!\n" );
129 uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
130 if ( !xTransferable.is() )
131 throw uno::RuntimeException();
132
133 datatransfer::DataFlavor aDataFlavor(
134 ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
135 ::rtl::OUString::createFromAscii( "GDIMetaFile" ),
136 ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
137
138 aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor );
139 aVisualRepresentation.Flavor = aDataFlavor;*/
140 return aVisualRepresentation;
141 }
142
setVisualAreaSize(sal_Int64 nAspect,const awt::Size & aSize)143 void SAL_CALL OSpecialEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
144 throw ( lang::IllegalArgumentException,
145 embed::WrongStateException,
146 uno::Exception,
147 uno::RuntimeException )
148 {
149 ::osl::MutexGuard aGuard( m_aMutex );
150 if ( m_bDisposed )
151 throw lang::DisposedException(); // TODO
152
153 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
154 if ( nAspect == embed::Aspects::MSOLE_ICON )
155 // no representation can be retrieved
156 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
157 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
158
159 maSize = aSize;
160 }
161
getVisualAreaSize(sal_Int64 nAspect)162 awt::Size SAL_CALL OSpecialEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
163 throw ( lang::IllegalArgumentException,
164 embed::WrongStateException,
165 uno::Exception,
166 uno::RuntimeException )
167 {
168 ::osl::MutexGuard aGuard( m_aMutex );
169 if ( m_bDisposed )
170 throw lang::DisposedException(); // TODO
171
172 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
173 if ( nAspect == embed::Aspects::MSOLE_ICON )
174 // no representation can be retrieved
175 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
176 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
177
178 if ( m_nObjectState == -1 )
179 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ),
180 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
181
182 awt::Size aResult;
183 return maSize;
184 }
185
getMapUnit(sal_Int64 nAspect)186 sal_Int32 SAL_CALL OSpecialEmbeddedObject::getMapUnit( sal_Int64 nAspect )
187 throw ( uno::Exception,
188 uno::RuntimeException)
189 {
190 ::osl::MutexGuard aGuard( m_aMutex );
191 if ( m_bDisposed )
192 throw lang::DisposedException(); // TODO
193
194 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
195 if ( nAspect == embed::Aspects::MSOLE_ICON )
196 // no representation can be retrieved
197 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
198 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
199
200 return embed::EmbedMapUnits::ONE_100TH_MM;
201 }
202
changeState(sal_Int32 nNewState)203 void SAL_CALL OSpecialEmbeddedObject::changeState( sal_Int32 nNewState )
204 throw ( ::com::sun::star::embed::UnreachableStateException,
205 ::com::sun::star::embed::WrongStateException,
206 ::com::sun::star::uno::Exception,
207 ::com::sun::star::uno::RuntimeException )
208 {
209 if ( nNewState == embed::EmbedStates::UI_ACTIVE )
210 nNewState = embed::EmbedStates::INPLACE_ACTIVE;
211 OCommonEmbeddedObject::changeState( nNewState );
212 }
213
doVerb(sal_Int32 nVerbID)214 void SAL_CALL OSpecialEmbeddedObject::doVerb( sal_Int32 nVerbID )
215 throw ( lang::IllegalArgumentException,
216 embed::WrongStateException,
217 embed::UnreachableStateException,
218 uno::Exception,
219 uno::RuntimeException )
220 {
221 ::osl::MutexGuard aGuard( m_aMutex );
222 if ( m_bDisposed )
223 throw lang::DisposedException(); // TODO
224
225 if ( m_nObjectState == -1 )
226 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
227 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
228
229 if ( nVerbID == -7 )
230 {
231
232 uno::Reference < ui::dialogs::XExecutableDialog > xDlg( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
233 if ( xDlg.is() )
234 xDlg->execute();
235 else
236 throw embed::UnreachableStateException();
237 }
238 else
239 OCommonEmbeddedObject::doVerb( nVerbID );
240 }
241
242