Update ooo320-m1
[ooovba.git] / embeddedobj / source / commonembedding / specialobject.cxx
blobc1622aa29615d00781d3b830c4332fc923c5ffa7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: specialobject.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_embeddedobj.hxx"
33 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
34 #include <com/sun/star/embed/EmbedStates.hpp>
35 #include <com/sun/star/embed/EmbedVerbs.hpp>
36 #include <com/sun/star/embed/EmbedUpdateModes.hpp>
37 #include <com/sun/star/embed/XEmbeddedClient.hpp>
38 #include <com/sun/star/embed/XInplaceClient.hpp>
39 #include <com/sun/star/embed/XWindowSupplier.hpp>
40 #include <com/sun/star/embed/Aspects.hpp>
41 #include <com/sun/star/awt/XWindowPeer.hpp>
42 #include <com/sun/star/util/XCloseBroadcaster.hpp>
43 #include <com/sun/star/util/XCloseable.hpp>
44 #include <com/sun/star/util/XModifiable.hpp>
45 #include <com/sun/star/frame/XFrame.hpp>
46 #include <com/sun/star/frame/XComponentLoader.hpp>
47 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
48 #include <com/sun/star/lang/DisposedException.hpp>
49 #include <com/sun/star/embed/EmbedMapUnits.hpp>
51 #include <cppuhelper/typeprovider.hxx>
53 #include "specialobject.hxx"
54 #include "intercept.hxx"
56 using namespace ::com::sun::star;
59 OSpecialEmbeddedObject::OSpecialEmbeddedObject( const uno::Reference< lang::XMultiServiceFactory >& xFactory, const uno::Sequence< beans::NamedValue >& aObjectProps )
60 : OCommonEmbeddedObject( xFactory, aObjectProps )
62 maSize.Width = maSize.Height = 10000;
63 m_nObjectState = embed::EmbedStates::LOADED;
66 //------------------------------------------------------
67 uno::Any SAL_CALL OSpecialEmbeddedObject::queryInterface( const uno::Type& rType )
68 throw( uno::RuntimeException )
70 uno::Any aReturn;
72 aReturn <<= ::cppu::queryInterface( rType,
73 static_cast< embed::XEmbeddedObject* >( this ),
74 static_cast< embed::XInplaceObject* >( this ),
75 static_cast< embed::XVisualObject* >( this ),
76 static_cast< embed::XClassifiedObject* >( this ),
77 static_cast< embed::XComponentSupplier* >( this ),
78 static_cast< util::XCloseable* >( this ),
79 static_cast< document::XEventBroadcaster* >( this ) );
80 if ( aReturn.hasValue() )
81 return aReturn;
82 else
83 return ::cppu::OWeakObject::queryInterface( rType ) ;
87 //------------------------------------------------------
88 uno::Sequence< uno::Type > SAL_CALL OSpecialEmbeddedObject::getTypes()
89 throw( uno::RuntimeException )
91 static ::cppu::OTypeCollection* pTypeCollection = NULL;
93 if ( !pTypeCollection )
95 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
96 if ( !pTypeCollection )
98 static ::cppu::OTypeCollection aTypeCollection(
99 ::getCppuType( (const uno::Reference< lang::XTypeProvider >*)NULL ),
100 ::getCppuType( (const uno::Reference< embed::XEmbeddedObject >*)NULL ),
101 ::getCppuType( (const uno::Reference< embed::XInplaceObject >*)NULL ) );
103 pTypeCollection = &aTypeCollection ;
107 return pTypeCollection->getTypes() ;
111 embed::VisualRepresentation SAL_CALL OSpecialEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
112 throw ( lang::IllegalArgumentException,
113 embed::WrongStateException,
114 uno::Exception,
115 uno::RuntimeException )
117 ::osl::MutexGuard aGuard( m_aMutex );
118 if ( m_bDisposed )
119 throw lang::DisposedException(); // TODO
121 // TODO: if object is in loaded state it should switch itself to the running state
122 if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::LOADED )
123 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ),
124 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
126 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
127 if ( nAspect == embed::Aspects::MSOLE_ICON )
128 // no representation can be retrieved
129 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
130 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
132 // TODO: return for the aspect of the document
133 embed::VisualRepresentation aVisualRepresentation;
135 OSL_ENSURE( m_pDocHolder->GetComponent().is(), "Running or Active object has no component!\n" );
136 uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
137 if ( !xTransferable.is() )
138 throw uno::RuntimeException();
140 datatransfer::DataFlavor aDataFlavor(
141 ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
142 ::rtl::OUString::createFromAscii( "GDIMetaFile" ),
143 ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
145 aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor );
146 aVisualRepresentation.Flavor = aDataFlavor;*/
147 return aVisualRepresentation;
150 void SAL_CALL OSpecialEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
151 throw ( lang::IllegalArgumentException,
152 embed::WrongStateException,
153 uno::Exception,
154 uno::RuntimeException )
156 ::osl::MutexGuard aGuard( m_aMutex );
157 if ( m_bDisposed )
158 throw lang::DisposedException(); // TODO
160 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
161 if ( nAspect == embed::Aspects::MSOLE_ICON )
162 // no representation can be retrieved
163 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
164 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
166 maSize = aSize;
169 awt::Size SAL_CALL OSpecialEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
170 throw ( lang::IllegalArgumentException,
171 embed::WrongStateException,
172 uno::Exception,
173 uno::RuntimeException )
175 ::osl::MutexGuard aGuard( m_aMutex );
176 if ( m_bDisposed )
177 throw lang::DisposedException(); // TODO
179 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
180 if ( nAspect == embed::Aspects::MSOLE_ICON )
181 // no representation can be retrieved
182 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
183 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
185 if ( m_nObjectState == -1 )
186 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ),
187 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
189 awt::Size aResult;
190 return maSize;
193 sal_Int32 SAL_CALL OSpecialEmbeddedObject::getMapUnit( sal_Int64 nAspect )
194 throw ( uno::Exception,
195 uno::RuntimeException)
197 ::osl::MutexGuard aGuard( m_aMutex );
198 if ( m_bDisposed )
199 throw lang::DisposedException(); // TODO
201 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
202 if ( nAspect == embed::Aspects::MSOLE_ICON )
203 // no representation can be retrieved
204 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
205 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
207 return embed::EmbedMapUnits::ONE_100TH_MM;
210 void SAL_CALL OSpecialEmbeddedObject::changeState( sal_Int32 nNewState )
211 throw ( ::com::sun::star::embed::UnreachableStateException,
212 ::com::sun::star::embed::WrongStateException,
213 ::com::sun::star::uno::Exception,
214 ::com::sun::star::uno::RuntimeException )
216 if ( nNewState == embed::EmbedStates::UI_ACTIVE )
217 nNewState = embed::EmbedStates::INPLACE_ACTIVE;
218 OCommonEmbeddedObject::changeState( nNewState );
221 void SAL_CALL OSpecialEmbeddedObject::doVerb( sal_Int32 nVerbID )
222 throw ( lang::IllegalArgumentException,
223 embed::WrongStateException,
224 embed::UnreachableStateException,
225 uno::Exception,
226 uno::RuntimeException )
228 ::osl::MutexGuard aGuard( m_aMutex );
229 if ( m_bDisposed )
230 throw lang::DisposedException(); // TODO
232 if ( m_nObjectState == -1 )
233 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
234 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
236 if ( nVerbID == -7 )
239 uno::Reference < ui::dialogs::XExecutableDialog > xDlg( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
240 if ( xDlg.is() )
241 xDlg->execute();
242 else
243 throw embed::UnreachableStateException();
245 else
246 OCommonEmbeddedObject::doVerb( nVerbID );