1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/queryinterface.hxx>
39 #include <cppuhelper/typeprovider.hxx>
41 #include "specialobject.hxx"
42 #include "intercept.hxx"
44 using namespace ::com::sun::star
;
47 OSpecialEmbeddedObject::OSpecialEmbeddedObject( const uno::Reference
< uno::XComponentContext
>& rxContext
, const uno::Sequence
< beans::NamedValue
>& aObjectProps
)
48 : OCommonEmbeddedObject( rxContext
, aObjectProps
)
50 maSize
.Width
= maSize
.Height
= 10000;
51 m_nObjectState
= embed::EmbedStates::LOADED
;
55 uno::Any SAL_CALL
OSpecialEmbeddedObject::queryInterface( const uno::Type
& rType
)
56 throw( uno::RuntimeException
, std::exception
)
60 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 static_cast< document::XEventBroadcaster
* >( this ) );
68 if ( aReturn
.hasValue() )
71 return ::cppu::OWeakObject::queryInterface( rType
) ;
76 uno::Sequence
< uno::Type
> SAL_CALL
OSpecialEmbeddedObject::getTypes()
77 throw( uno::RuntimeException
)
79 static ::cppu::OTypeCollection
* pTypeCollection
= NULL
;
81 if ( !pTypeCollection
)
83 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
84 if ( !pTypeCollection
)
86 static ::cppu::OTypeCollection
aTypeCollection(
87 cppu::UnoType
<lang::XTypeProvider
>::get(),
88 cppu::UnoType
<embed::XEmbeddedObject
>::get(),
89 cppu::UnoType
<embed::XInplaceObject
>::get());
91 pTypeCollection
= &aTypeCollection
;
95 return pTypeCollection
->getTypes() ;
99 embed::VisualRepresentation SAL_CALL
OSpecialEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect
)
100 throw ( lang::IllegalArgumentException
,
101 embed::WrongStateException
,
103 uno::RuntimeException
, std::exception
)
105 ::osl::MutexGuard
aGuard( m_aMutex
);
107 throw lang::DisposedException(); // TODO
109 // TODO: if object is in loaded state it should switch itself to the running state
110 if ( m_nObjectState
== -1 || m_nObjectState
== embed::EmbedStates::LOADED
)
111 throw embed::WrongStateException( "The own object has no model!",
112 static_cast< ::cppu::OWeakObject
* >(this) );
114 OSL_ENSURE( nAspect
!= embed::Aspects::MSOLE_ICON
, "For iconified objects no graphical replacement is required!\n" );
115 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
116 // no representation can be retrieved
117 throw embed::WrongStateException( "Illegal call!",
118 static_cast< ::cppu::OWeakObject
* >(this) );
120 // TODO: return for the aspect of the document
121 embed::VisualRepresentation aVisualRepresentation
;
122 return aVisualRepresentation
;
125 void SAL_CALL
OSpecialEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect
, const awt::Size
& aSize
)
126 throw ( lang::IllegalArgumentException
,
127 embed::WrongStateException
,
129 uno::RuntimeException
, std::exception
)
131 ::osl::MutexGuard
aGuard( m_aMutex
);
133 throw lang::DisposedException(); // TODO
135 OSL_ENSURE( nAspect
!= embed::Aspects::MSOLE_ICON
, "For iconified objects no graphical replacement is required!\n" );
136 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
137 // no representation can be retrieved
138 throw embed::WrongStateException( "Illegal call!",
139 static_cast< ::cppu::OWeakObject
* >(this) );
144 awt::Size SAL_CALL
OSpecialEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect
)
145 throw ( lang::IllegalArgumentException
,
146 embed::WrongStateException
,
148 uno::RuntimeException
, std::exception
)
150 ::osl::MutexGuard
aGuard( m_aMutex
);
152 throw lang::DisposedException(); // TODO
154 OSL_ENSURE( nAspect
!= embed::Aspects::MSOLE_ICON
, "For iconified objects no graphical replacement is required!\n" );
155 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
156 // no representation can be retrieved
157 throw embed::WrongStateException( "Illegal call!",
158 static_cast< ::cppu::OWeakObject
* >(this) );
160 if ( m_nObjectState
== -1 )
161 throw embed::WrongStateException( "The own object has no model!",
162 static_cast< ::cppu::OWeakObject
* >(this) );
168 sal_Int32 SAL_CALL
OSpecialEmbeddedObject::getMapUnit( sal_Int64 nAspect
)
169 throw ( uno::Exception
,
170 uno::RuntimeException
, std::exception
)
172 ::osl::MutexGuard
aGuard( m_aMutex
);
174 throw lang::DisposedException(); // TODO
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( "Illegal call!",
180 static_cast< ::cppu::OWeakObject
* >(this) );
182 return embed::EmbedMapUnits::ONE_100TH_MM
;
185 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
)
191 if ( nNewState
== embed::EmbedStates::UI_ACTIVE
)
192 nNewState
= embed::EmbedStates::INPLACE_ACTIVE
;
193 OCommonEmbeddedObject::changeState( nNewState
);
196 void SAL_CALL
OSpecialEmbeddedObject::doVerb( sal_Int32 nVerbID
)
197 throw ( lang::IllegalArgumentException
,
198 embed::WrongStateException
,
199 embed::UnreachableStateException
,
201 uno::RuntimeException
, std::exception
)
203 ::osl::MutexGuard
aGuard( m_aMutex
);
205 throw lang::DisposedException(); // TODO
207 if ( m_nObjectState
== -1 )
208 throw embed::WrongStateException( "The object has no persistence!",
209 static_cast< ::cppu::OWeakObject
* >(this) );
214 uno::Reference
< ui::dialogs::XExecutableDialog
> xDlg( m_pDocHolder
->GetComponent(), uno::UNO_QUERY
);
218 throw embed::UnreachableStateException();
221 OCommonEmbeddedObject::doVerb( nVerbID
);
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */