Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / embeddedobj / source / commonembedding / specialobject.cxx
blob7aca13b50b651d33389b1f5ce3ae5f9df129a618
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
21 #include <com/sun/star/embed/EmbedStates.hpp>
22 #include <com/sun/star/embed/EmbedVerbs.hpp>
23 #include <com/sun/star/embed/EmbedUpdateModes.hpp>
24 #include <com/sun/star/embed/XEmbeddedClient.hpp>
25 #include <com/sun/star/embed/XInplaceClient.hpp>
26 #include <com/sun/star/embed/XWindowSupplier.hpp>
27 #include <com/sun/star/embed/Aspects.hpp>
28 #include <com/sun/star/awt/XWindowPeer.hpp>
29 #include <com/sun/star/util/XCloseBroadcaster.hpp>
30 #include <com/sun/star/util/XCloseable.hpp>
31 #include <com/sun/star/util/XModifiable.hpp>
32 #include <com/sun/star/frame/XFrame.hpp>
33 #include <com/sun/star/frame/XComponentLoader.hpp>
34 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include <com/sun/star/embed/EmbedMapUnits.hpp>
38 #include <cppuhelper/typeprovider.hxx>
40 #include "specialobject.hxx"
41 #include "intercept.hxx"
43 using namespace ::com::sun::star;
46 OSpecialEmbeddedObject::OSpecialEmbeddedObject( const uno::Reference< uno::XComponentContext >& rxContext, const uno::Sequence< beans::NamedValue >& aObjectProps )
47 : OCommonEmbeddedObject( rxContext, aObjectProps )
49 maSize.Width = maSize.Height = 10000;
50 m_nObjectState = embed::EmbedStates::LOADED;
53 //------------------------------------------------------
54 uno::Any SAL_CALL OSpecialEmbeddedObject::queryInterface( const uno::Type& rType )
55 throw( uno::RuntimeException )
57 uno::Any aReturn;
59 aReturn <<= ::cppu::queryInterface( rType,
60 static_cast< embed::XEmbeddedObject* >( this ),
61 static_cast< embed::XInplaceObject* >( this ),
62 static_cast< embed::XVisualObject* >( this ),
63 static_cast< embed::XClassifiedObject* >( this ),
64 static_cast< embed::XComponentSupplier* >( this ),
65 static_cast< util::XCloseable* >( this ),
66 static_cast< document::XEventBroadcaster* >( this ) );
67 if ( aReturn.hasValue() )
68 return aReturn;
69 else
70 return ::cppu::OWeakObject::queryInterface( rType ) ;
74 //------------------------------------------------------
75 uno::Sequence< uno::Type > SAL_CALL OSpecialEmbeddedObject::getTypes()
76 throw( uno::RuntimeException )
78 static ::cppu::OTypeCollection* pTypeCollection = NULL;
80 if ( !pTypeCollection )
82 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
83 if ( !pTypeCollection )
85 static ::cppu::OTypeCollection aTypeCollection(
86 ::getCppuType( (const uno::Reference< lang::XTypeProvider >*)NULL ),
87 ::getCppuType( (const uno::Reference< embed::XEmbeddedObject >*)NULL ),
88 ::getCppuType( (const uno::Reference< embed::XInplaceObject >*)NULL ) );
90 pTypeCollection = &aTypeCollection ;
94 return pTypeCollection->getTypes() ;
98 embed::VisualRepresentation SAL_CALL OSpecialEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
99 throw ( lang::IllegalArgumentException,
100 embed::WrongStateException,
101 uno::Exception,
102 uno::RuntimeException )
104 ::osl::MutexGuard aGuard( m_aMutex );
105 if ( m_bDisposed )
106 throw lang::DisposedException(); // TODO
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( OUString( "The own object has no model!\n" ),
111 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
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( OUString( "Illegal call!\n" ),
117 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
119 // TODO: return for the aspect of the document
120 embed::VisualRepresentation aVisualRepresentation;
121 return aVisualRepresentation;
124 void SAL_CALL OSpecialEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
125 throw ( lang::IllegalArgumentException,
126 embed::WrongStateException,
127 uno::Exception,
128 uno::RuntimeException )
130 ::osl::MutexGuard aGuard( m_aMutex );
131 if ( m_bDisposed )
132 throw lang::DisposedException(); // TODO
134 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
135 if ( nAspect == embed::Aspects::MSOLE_ICON )
136 // no representation can be retrieved
137 throw embed::WrongStateException( OUString( "Illegal call!\n" ),
138 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
140 maSize = aSize;
143 awt::Size SAL_CALL OSpecialEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
144 throw ( lang::IllegalArgumentException,
145 embed::WrongStateException,
146 uno::Exception,
147 uno::RuntimeException )
149 ::osl::MutexGuard aGuard( m_aMutex );
150 if ( m_bDisposed )
151 throw lang::DisposedException(); // TODO
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( OUString( "Illegal call!\n" ),
157 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
159 if ( m_nObjectState == -1 )
160 throw embed::WrongStateException( OUString( "The own object has no model!\n" ),
161 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
163 awt::Size aResult;
164 return maSize;
167 sal_Int32 SAL_CALL OSpecialEmbeddedObject::getMapUnit( sal_Int64 nAspect )
168 throw ( uno::Exception,
169 uno::RuntimeException)
171 ::osl::MutexGuard aGuard( m_aMutex );
172 if ( m_bDisposed )
173 throw lang::DisposedException(); // TODO
175 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
176 if ( nAspect == embed::Aspects::MSOLE_ICON )
177 // no representation can be retrieved
178 throw embed::WrongStateException( OUString( "Illegal call!\n" ),
179 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
181 return embed::EmbedMapUnits::ONE_100TH_MM;
184 void SAL_CALL OSpecialEmbeddedObject::changeState( sal_Int32 nNewState )
185 throw ( ::com::sun::star::embed::UnreachableStateException,
186 ::com::sun::star::embed::WrongStateException,
187 ::com::sun::star::uno::Exception,
188 ::com::sun::star::uno::RuntimeException )
190 if ( nNewState == embed::EmbedStates::UI_ACTIVE )
191 nNewState = embed::EmbedStates::INPLACE_ACTIVE;
192 OCommonEmbeddedObject::changeState( nNewState );
195 void SAL_CALL OSpecialEmbeddedObject::doVerb( sal_Int32 nVerbID )
196 throw ( lang::IllegalArgumentException,
197 embed::WrongStateException,
198 embed::UnreachableStateException,
199 uno::Exception,
200 uno::RuntimeException )
202 ::osl::MutexGuard aGuard( m_aMutex );
203 if ( m_bDisposed )
204 throw lang::DisposedException(); // TODO
206 if ( m_nObjectState == -1 )
207 throw embed::WrongStateException( OUString( "The object has no persistence!\n" ),
208 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
210 if ( nVerbID == -7 )
213 uno::Reference < ui::dialogs::XExecutableDialog > xDlg( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
214 if ( xDlg.is() )
215 xDlg->execute();
216 else
217 throw embed::UnreachableStateException();
219 else
220 OCommonEmbeddedObject::doVerb( nVerbID );
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */