Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / embeddedobj / source / commonembedding / specialobject.cxx
blob3dc1eb7e47efed5ad34ed74f14cc527f5103e53f
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/UnreachableStateException.hpp>
23 #include <com/sun/star/embed/WrongStateException.hpp>
24 #include <com/sun/star/embed/Aspects.hpp>
25 #include <com/sun/star/util/XCloseable.hpp>
26 #include <com/sun/star/lang/DisposedException.hpp>
27 #include <com/sun/star/embed/EmbedMapUnits.hpp>
29 #include <cppuhelper/queryinterface.hxx>
30 #include <osl/diagnose.h>
31 #include <cppuhelper/supportsservice.hxx>
33 #include <specialobject.hxx>
35 using namespace ::com::sun::star;
38 OSpecialEmbeddedObject::OSpecialEmbeddedObject( const uno::Reference< uno::XComponentContext >& rxContext, const uno::Sequence< beans::NamedValue >& aObjectProps )
39 : OCommonEmbeddedObject( rxContext, aObjectProps )
41 maSize.Width = maSize.Height = 10000;
42 m_nObjectState = embed::EmbedStates::LOADED;
46 uno::Any SAL_CALL OSpecialEmbeddedObject::queryInterface( const uno::Type& rType )
48 uno::Any aReturn = ::cppu::queryInterface( rType,
49 static_cast< embed::XEmbeddedObject* >( this ),
50 static_cast< embed::XInplaceObject* >( this ),
51 static_cast< embed::XCommonEmbedPersist* >( static_cast< embed::XEmbedPersist* >( this ) ),
52 static_cast< embed::XVisualObject* >( this ),
53 static_cast< embed::XClassifiedObject* >( this ),
54 static_cast< embed::XComponentSupplier* >( this ),
55 static_cast< util::XCloseable* >( this ),
56 static_cast< lang::XServiceInfo* >( this ),
57 static_cast< lang::XTypeProvider* >( this ),
58 static_cast< document::XEventBroadcaster* >( this ) );
59 if ( aReturn.hasValue() )
60 return aReturn;
61 else
62 return ::cppu::OWeakObject::queryInterface( rType ) ;
67 embed::VisualRepresentation SAL_CALL OSpecialEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
69 ::osl::MutexGuard aGuard( m_aMutex );
70 if ( m_bDisposed )
71 throw lang::DisposedException(); // TODO
73 // TODO: if object is in loaded state it should switch itself to the running state
74 if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::LOADED )
75 throw embed::WrongStateException( "The own object has no model!",
76 static_cast< ::cppu::OWeakObject* >(this) );
78 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" );
79 if ( nAspect == embed::Aspects::MSOLE_ICON )
80 // no representation can be retrieved
81 throw embed::WrongStateException( "Illegal call!",
82 static_cast< ::cppu::OWeakObject* >(this) );
84 // TODO: return for the aspect of the document
85 embed::VisualRepresentation aVisualRepresentation;
86 return aVisualRepresentation;
89 void SAL_CALL OSpecialEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
91 ::osl::MutexGuard aGuard( m_aMutex );
92 if ( m_bDisposed )
93 throw lang::DisposedException(); // TODO
95 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" );
96 if ( nAspect == embed::Aspects::MSOLE_ICON )
97 // no representation can be retrieved
98 throw embed::WrongStateException( "Illegal call!",
99 static_cast< ::cppu::OWeakObject* >(this) );
101 maSize = aSize;
104 awt::Size SAL_CALL OSpecialEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
106 ::osl::MutexGuard aGuard( m_aMutex );
107 if ( m_bDisposed )
108 throw lang::DisposedException(); // TODO
110 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" );
111 if ( nAspect == embed::Aspects::MSOLE_ICON )
112 // no representation can be retrieved
113 throw embed::WrongStateException( "Illegal call!",
114 static_cast< ::cppu::OWeakObject* >(this) );
116 if ( m_nObjectState == -1 )
117 throw embed::WrongStateException( "The own object has no model!",
118 static_cast< ::cppu::OWeakObject* >(this) );
120 return maSize;
123 sal_Int32 SAL_CALL OSpecialEmbeddedObject::getMapUnit( sal_Int64 nAspect )
125 ::osl::MutexGuard aGuard( m_aMutex );
126 if ( m_bDisposed )
127 throw lang::DisposedException(); // TODO
129 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" );
130 if ( nAspect == embed::Aspects::MSOLE_ICON )
131 // no representation can be retrieved
132 throw embed::WrongStateException( "Illegal call!",
133 static_cast< ::cppu::OWeakObject* >(this) );
135 return embed::EmbedMapUnits::ONE_100TH_MM;
138 void SAL_CALL OSpecialEmbeddedObject::changeState( sal_Int32 nNewState )
140 if ( nNewState == embed::EmbedStates::UI_ACTIVE )
141 nNewState = embed::EmbedStates::INPLACE_ACTIVE;
142 OCommonEmbeddedObject::changeState( nNewState );
145 void SAL_CALL OSpecialEmbeddedObject::doVerb( sal_Int32 nVerbID )
147 ::osl::MutexGuard aGuard( m_aMutex );
148 if ( m_bDisposed )
149 throw lang::DisposedException(); // TODO
151 if ( m_nObjectState == -1 )
152 throw embed::WrongStateException( "The object has no persistence!",
153 static_cast< ::cppu::OWeakObject* >(this) );
155 if ( nVerbID == -7 )
158 uno::Reference < ui::dialogs::XExecutableDialog > xDlg( m_xDocHolder->GetComponent(), uno::UNO_QUERY );
159 if ( !xDlg.is() )
160 throw embed::UnreachableStateException();
161 xDlg->execute();
163 else
164 OCommonEmbeddedObject::doVerb( nVerbID );
167 void SAL_CALL OSpecialEmbeddedObject::reload(
168 const uno::Sequence< beans::PropertyValue >&,
169 const uno::Sequence< beans::PropertyValue >&)
171 // Allow IFrames to reload their content
172 SetInplaceActiveState();
175 OUString SAL_CALL OSpecialEmbeddedObject::getImplementationName()
177 return "com.sun.star.comp.embed.OSpecialEmbeddedObject";
180 sal_Bool SAL_CALL OSpecialEmbeddedObject::supportsService(const OUString& ServiceName)
182 return cppu::supportsService(this, ServiceName);
185 uno::Sequence<OUString> SAL_CALL OSpecialEmbeddedObject::getSupportedServiceNames()
187 return { "com.sun.star.comp.embed.OSpecialEmbeddedObject" };
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */