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