xref: /trunk/main/embeddedobj/source/commonembedding/specialobject.cxx (revision 9d37da743abb7db0a497688391f6e55a19f27c44)
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 
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 //------------------------------------------------------
60 uno::Any SAL_CALL OSpecialEmbeddedObject::queryInterface( const uno::Type& rType )
61 {
62     uno::Any aReturn;
63 
64     aReturn <<= ::cppu::queryInterface( rType,
65                                         static_cast< embed::XEmbeddedObject* >( this ),
66                                         static_cast< embed::XInplaceObject* >( this ),
67                                         static_cast< embed::XVisualObject* >( this ),
68                                         static_cast< embed::XClassifiedObject* >( this ),
69                                         static_cast< embed::XComponentSupplier* >( this ),
70                                         static_cast< util::XCloseable* >( this ),
71                                         static_cast< document::XEventBroadcaster* >( this ) );
72     if ( aReturn.hasValue() )
73         return aReturn;
74     else
75         return ::cppu::OWeakObject::queryInterface( rType ) ;
76 
77 }
78 
79 //------------------------------------------------------
80 uno::Sequence< uno::Type > SAL_CALL OSpecialEmbeddedObject::getTypes()
81 {
82     static ::cppu::OTypeCollection* pTypeCollection = NULL;
83 
84     if ( !pTypeCollection )
85     {
86         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
87         if ( !pTypeCollection )
88         {
89             static ::cppu::OTypeCollection aTypeCollection(
90                                         ::getCppuType( (const uno::Reference< lang::XTypeProvider >*)NULL ),
91                                         ::getCppuType( (const uno::Reference< embed::XEmbeddedObject >*)NULL ),
92                                         ::getCppuType( (const uno::Reference< embed::XInplaceObject >*)NULL ) );
93 
94             pTypeCollection = &aTypeCollection ;
95         }
96     }
97 
98     return pTypeCollection->getTypes() ;
99 
100 }
101 
102 embed::VisualRepresentation SAL_CALL OSpecialEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
103 {
104     ::osl::MutexGuard aGuard( m_aMutex );
105     if ( m_bDisposed )
106         throw lang::DisposedException(); // TODO
107 
108     // TODO: if object is in loaded state it should switch itself to the running state
109     if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::LOADED )
110         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ),
111                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
112 
113     OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
114     if ( nAspect == embed::Aspects::MSOLE_ICON )
115         // no representation can be retrieved
116         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
117                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
118 
119     // TODO: return for the aspect of the document
120     embed::VisualRepresentation aVisualRepresentation;
121     /*
122     OSL_ENSURE( m_pDocHolder->GetComponent().is(), "Running or Active object has no component!\n" );
123     uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
124     if ( !xTransferable.is() )
125         throw uno::RuntimeException();
126 
127     datatransfer::DataFlavor aDataFlavor(
128             ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
129             ::rtl::OUString::createFromAscii( "GDIMetaFile" ),
130             ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
131 
132     aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor );
133     aVisualRepresentation.Flavor = aDataFlavor;*/
134     return aVisualRepresentation;
135 }
136 
137 void SAL_CALL OSpecialEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
138 {
139     ::osl::MutexGuard aGuard( m_aMutex );
140     if ( m_bDisposed )
141         throw lang::DisposedException(); // TODO
142 
143     OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
144     if ( nAspect == embed::Aspects::MSOLE_ICON )
145         // no representation can be retrieved
146         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
147                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
148 
149     maSize = aSize;
150 }
151 
152 awt::Size SAL_CALL OSpecialEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
153 {
154     ::osl::MutexGuard aGuard( m_aMutex );
155     if ( m_bDisposed )
156         throw lang::DisposedException(); // TODO
157 
158     OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
159     if ( nAspect == embed::Aspects::MSOLE_ICON )
160         // no representation can be retrieved
161         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
162                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
163 
164     if ( m_nObjectState == -1 )
165         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no model!\n" ),
166                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
167 
168     awt::Size aResult;
169     return maSize;
170 }
171 
172 sal_Int32 SAL_CALL OSpecialEmbeddedObject::getMapUnit( sal_Int64 nAspect )
173 {
174     ::osl::MutexGuard aGuard( m_aMutex );
175     if ( m_bDisposed )
176         throw lang::DisposedException(); // TODO
177 
178     OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
179     if ( nAspect == embed::Aspects::MSOLE_ICON )
180         // no representation can be retrieved
181         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
182                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
183 
184     return embed::EmbedMapUnits::ONE_100TH_MM;
185 }
186 
187 void SAL_CALL OSpecialEmbeddedObject::changeState( sal_Int32 nNewState )
188 {
189     if ( nNewState == embed::EmbedStates::UI_ACTIVE )
190         nNewState = embed::EmbedStates::INPLACE_ACTIVE;
191     OCommonEmbeddedObject::changeState( nNewState );
192 }
193 
194 void SAL_CALL OSpecialEmbeddedObject::doVerb( sal_Int32 nVerbID )
195 {
196     ::osl::MutexGuard aGuard( m_aMutex );
197     if ( m_bDisposed )
198         throw lang::DisposedException(); // TODO
199 
200     if ( m_nObjectState == -1 )
201         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
202                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
203 
204     if ( nVerbID == -7 )
205     {
206 
207         uno::Reference < ui::dialogs::XExecutableDialog > xDlg( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
208         if ( xDlg.is() )
209             xDlg->execute();
210         else
211             throw embed::UnreachableStateException();
212     }
213     else
214         OCommonEmbeddedObject::doVerb( nVerbID );
215 }
216