Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
37 :
38 : #include <cppuhelper/queryinterface.hxx>
39 : #include <cppuhelper/typeprovider.hxx>
40 :
41 : #include "specialobject.hxx"
42 : #include "intercept.hxx"
43 :
44 : using namespace ::com::sun::star;
45 :
46 :
47 8 : OSpecialEmbeddedObject::OSpecialEmbeddedObject( const uno::Reference< uno::XComponentContext >& rxContext, const uno::Sequence< beans::NamedValue >& aObjectProps )
48 8 : : OCommonEmbeddedObject( rxContext, aObjectProps )
49 : {
50 8 : maSize.Width = maSize.Height = 10000;
51 8 : m_nObjectState = embed::EmbedStates::LOADED;
52 8 : }
53 :
54 :
55 135 : uno::Any SAL_CALL OSpecialEmbeddedObject::queryInterface( const uno::Type& rType )
56 : throw( uno::RuntimeException, std::exception )
57 : {
58 135 : uno::Any aReturn;
59 :
60 270 : aReturn <<= ::cppu::queryInterface( rType,
61 : static_cast< embed::XEmbeddedObject* >( this ),
62 : static_cast< embed::XInplaceObject* >( this ),
63 : static_cast< embed::XVisualObject* >( this ),
64 : static_cast< embed::XClassifiedObject* >( this ),
65 : static_cast< embed::XComponentSupplier* >( this ),
66 : static_cast< util::XCloseable* >( this ),
67 135 : static_cast< document::XEventBroadcaster* >( this ) );
68 135 : if ( aReturn.hasValue() )
69 52 : return aReturn;
70 : else
71 83 : return ::cppu::OWeakObject::queryInterface( rType ) ;
72 :
73 : }
74 :
75 :
76 0 : uno::Sequence< uno::Type > SAL_CALL OSpecialEmbeddedObject::getTypes()
77 : throw( uno::RuntimeException )
78 : {
79 : static ::cppu::OTypeCollection* pTypeCollection = NULL;
80 :
81 0 : if ( !pTypeCollection )
82 : {
83 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
84 0 : if ( !pTypeCollection )
85 : {
86 : static ::cppu::OTypeCollection aTypeCollection(
87 0 : cppu::UnoType<lang::XTypeProvider>::get(),
88 0 : cppu::UnoType<embed::XEmbeddedObject>::get(),
89 0 : cppu::UnoType<embed::XInplaceObject>::get());
90 :
91 0 : pTypeCollection = &aTypeCollection ;
92 0 : }
93 : }
94 :
95 0 : return pTypeCollection->getTypes() ;
96 :
97 : }
98 :
99 0 : embed::VisualRepresentation SAL_CALL OSpecialEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
100 : throw ( lang::IllegalArgumentException,
101 : embed::WrongStateException,
102 : uno::Exception,
103 : uno::RuntimeException, std::exception )
104 : {
105 0 : ::osl::MutexGuard aGuard( m_aMutex );
106 0 : if ( m_bDisposed )
107 0 : throw lang::DisposedException(); // TODO
108 :
109 : // TODO: if object is in loaded state it should switch itself to the running state
110 0 : if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::LOADED )
111 : throw embed::WrongStateException( "The own object has no model!",
112 0 : static_cast< ::cppu::OWeakObject* >(this) );
113 :
114 : OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
115 0 : if ( nAspect == embed::Aspects::MSOLE_ICON )
116 : // no representation can be retrieved
117 : throw embed::WrongStateException( "Illegal call!",
118 0 : static_cast< ::cppu::OWeakObject* >(this) );
119 :
120 : // TODO: return for the aspect of the document
121 0 : embed::VisualRepresentation aVisualRepresentation;
122 0 : return aVisualRepresentation;
123 : }
124 :
125 0 : void SAL_CALL OSpecialEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
126 : throw ( lang::IllegalArgumentException,
127 : embed::WrongStateException,
128 : uno::Exception,
129 : uno::RuntimeException, std::exception )
130 : {
131 0 : ::osl::MutexGuard aGuard( m_aMutex );
132 0 : if ( m_bDisposed )
133 0 : throw lang::DisposedException(); // TODO
134 :
135 : OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
136 0 : if ( nAspect == embed::Aspects::MSOLE_ICON )
137 : // no representation can be retrieved
138 : throw embed::WrongStateException( "Illegal call!",
139 0 : static_cast< ::cppu::OWeakObject* >(this) );
140 :
141 0 : maSize = aSize;
142 0 : }
143 :
144 0 : awt::Size SAL_CALL OSpecialEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
145 : throw ( lang::IllegalArgumentException,
146 : embed::WrongStateException,
147 : uno::Exception,
148 : uno::RuntimeException, std::exception )
149 : {
150 0 : ::osl::MutexGuard aGuard( m_aMutex );
151 0 : if ( m_bDisposed )
152 0 : throw lang::DisposedException(); // TODO
153 :
154 : OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
155 0 : if ( nAspect == embed::Aspects::MSOLE_ICON )
156 : // no representation can be retrieved
157 : throw embed::WrongStateException( "Illegal call!",
158 0 : static_cast< ::cppu::OWeakObject* >(this) );
159 :
160 0 : if ( m_nObjectState == -1 )
161 : throw embed::WrongStateException( "The own object has no model!",
162 0 : static_cast< ::cppu::OWeakObject* >(this) );
163 :
164 0 : awt::Size aResult;
165 0 : return maSize;
166 : }
167 :
168 0 : sal_Int32 SAL_CALL OSpecialEmbeddedObject::getMapUnit( sal_Int64 nAspect )
169 : throw ( uno::Exception,
170 : uno::RuntimeException, std::exception)
171 : {
172 0 : ::osl::MutexGuard aGuard( m_aMutex );
173 0 : if ( m_bDisposed )
174 0 : throw lang::DisposedException(); // TODO
175 :
176 : OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
177 0 : if ( nAspect == embed::Aspects::MSOLE_ICON )
178 : // no representation can be retrieved
179 : throw embed::WrongStateException( "Illegal call!",
180 0 : static_cast< ::cppu::OWeakObject* >(this) );
181 :
182 0 : return embed::EmbedMapUnits::ONE_100TH_MM;
183 : }
184 :
185 20 : void SAL_CALL OSpecialEmbeddedObject::changeState( sal_Int32 nNewState )
186 : throw ( ::com::sun::star::embed::UnreachableStateException,
187 : ::com::sun::star::embed::WrongStateException,
188 : ::com::sun::star::uno::Exception,
189 : ::com::sun::star::uno::RuntimeException, std::exception )
190 : {
191 20 : if ( nNewState == embed::EmbedStates::UI_ACTIVE )
192 0 : nNewState = embed::EmbedStates::INPLACE_ACTIVE;
193 20 : OCommonEmbeddedObject::changeState( nNewState );
194 9 : }
195 :
196 0 : void SAL_CALL OSpecialEmbeddedObject::doVerb( sal_Int32 nVerbID )
197 : throw ( lang::IllegalArgumentException,
198 : embed::WrongStateException,
199 : embed::UnreachableStateException,
200 : uno::Exception,
201 : uno::RuntimeException, std::exception )
202 : {
203 0 : ::osl::MutexGuard aGuard( m_aMutex );
204 0 : if ( m_bDisposed )
205 0 : throw lang::DisposedException(); // TODO
206 :
207 0 : if ( m_nObjectState == -1 )
208 : throw embed::WrongStateException( "The object has no persistence!",
209 0 : static_cast< ::cppu::OWeakObject* >(this) );
210 :
211 0 : if ( nVerbID == -7 )
212 : {
213 :
214 0 : uno::Reference < ui::dialogs::XExecutableDialog > xDlg( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
215 0 : if ( xDlg.is() )
216 0 : xDlg->execute();
217 : else
218 0 : throw embed::UnreachableStateException();
219 : }
220 : else
221 0 : OCommonEmbeddedObject::doVerb( nVerbID );
222 0 : }
223 :
224 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|