| 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/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> |
| 28 |
|
| 29 |
#include <cppuhelper/queryinterface.hxx> |
| 30 |
#include <osl/diagnose.h> |
| 31 |
#include <cppuhelper/supportsservice.hxx> |
| 32 |
#include <officecfg/Office/Common.hxx> |
| 33 |
|
| 34 |
#include <specialobject.hxx> |
| 35 |
|
| 36 |
using namespace ::com::sun::star; |
| 37 |
|
| 38 |
|
| 39 |
OSpecialEmbeddedObject::OSpecialEmbeddedObject( const uno::Reference< uno::XComponentContext >& rxContext, const uno::Sequence< beans::NamedValue >& aObjectProps ) |
| 40 |
: OCommonEmbeddedObject( rxContext, aObjectProps ) |
| 41 |
{ |
| 42 |
maSize.Width = maSize.Height = 10000; |
| 43 |
m_nObjectState = embed::EmbedStates::LOADED; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
uno::Any SAL_CALL OSpecialEmbeddedObject::queryInterface( const uno::Type& rType ) |
| 48 |
{ |
| 49 |
uno::Any aReturn = ::cppu::queryInterface( rType, |
| 50 |
static_cast< embed::XEmbeddedObject* >( this ), |
| 51 |
static_cast< embed::XInplaceObject* >( this ), |
| 52 |
static_cast< embed::XCommonEmbedPersist* >( static_cast< embed::XEmbedPersist* >( this ) ), |
| 53 |
static_cast< embed::XVisualObject* >( this ), |
| 54 |
static_cast< embed::XClassifiedObject* >( this ), |
| 55 |
static_cast< embed::XComponentSupplier* >( this ), |
| 56 |
static_cast< util::XCloseable* >( this ), |
| 57 |
static_cast< lang::XServiceInfo* >( this ), |
| 58 |
static_cast< lang::XTypeProvider* >( this ), |
| 59 |
static_cast< document::XEventBroadcaster* >( this ) ); |
| 60 |
if ( aReturn.hasValue() ) |
| 61 |
return aReturn; |
| 62 |
else |
| 63 |
return ::cppu::OWeakObject::queryInterface( rType ) ; |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
embed::VisualRepresentation SAL_CALL OSpecialEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect ) |
| 69 |
{ |
| 70 |
::osl::MutexGuard aGuard( m_aMutex ); |
| 71 |
if ( m_bDisposed ) |
| 72 |
throw lang::DisposedException(); // TODO |
| 73 |
|
| 74 |
// TODO: if object is in loaded state it should switch itself to the running state |
| 75 |
if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::LOADED ) |
| 76 |
throw embed::WrongStateException( u"The own object has no model!"_ustr, |
| 77 |
static_cast< ::cppu::OWeakObject* >(this) ); |
| 78 |
|
| 79 |
OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" ); |
| 80 |
if ( nAspect == embed::Aspects::MSOLE_ICON ) |
| 81 |
// no representation can be retrieved |
| 82 |
throw embed::WrongStateException( u"Illegal call!"_ustr, |
| 83 |
static_cast< ::cppu::OWeakObject* >(this) ); |
| 84 |
|
| 85 |
// TODO: return for the aspect of the document |
| 86 |
embed::VisualRepresentation aVisualRepresentation; |
| 87 |
return aVisualRepresentation; |
| 88 |
} |
| 89 |
|
| 90 |
void SAL_CALL OSpecialEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize ) |
| 91 |
{ |
| 92 |
::osl::MutexGuard aGuard( m_aMutex ); |
| 93 |
if ( m_bDisposed ) |
| 94 |
throw lang::DisposedException(); // TODO |
| 95 |
|
| 96 |
OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" ); |
| 97 |
if ( nAspect == embed::Aspects::MSOLE_ICON ) |
| 98 |
// no representation can be retrieved |
| 99 |
throw embed::WrongStateException( u"Illegal call!"_ustr, |
| 100 |
static_cast< ::cppu::OWeakObject* >(this) ); |
| 101 |
|
| 102 |
maSize = aSize; |
| 103 |
} |
| 104 |
|
| 105 |
awt::Size SAL_CALL OSpecialEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect ) |
| 106 |
{ |
| 107 |
::osl::MutexGuard aGuard( m_aMutex ); |
| 108 |
if ( m_bDisposed ) |
| 109 |
throw lang::DisposedException(); // TODO |
| 110 |
|
| 111 |
OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" ); |
| 112 |
if ( nAspect == embed::Aspects::MSOLE_ICON ) |
| 113 |
// no representation can be retrieved |
| 114 |
throw embed::WrongStateException( u"Illegal call!"_ustr, |
| 115 |
static_cast< ::cppu::OWeakObject* >(this) ); |
| 116 |
|
| 117 |
if ( m_nObjectState == -1 ) |
| 118 |
throw embed::WrongStateException( u"The own object has no model!"_ustr, |
| 119 |
static_cast< ::cppu::OWeakObject* >(this) ); |
| 120 |
|
| 121 |
return maSize; |
| 122 |
} |
| 123 |
|
| 124 |
sal_Int32 SAL_CALL OSpecialEmbeddedObject::getMapUnit( sal_Int64 nAspect ) |
| 125 |
{ |
| 126 |
::osl::MutexGuard aGuard( m_aMutex ); |
| 127 |
if ( m_bDisposed ) |
| 128 |
throw lang::DisposedException(); // TODO |
| 129 |
|
| 130 |
OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" ); |
| 131 |
if ( nAspect == embed::Aspects::MSOLE_ICON ) |
| 132 |
// no representation can be retrieved |
| 133 |
throw embed::WrongStateException( u"Illegal call!"_ustr, |
| 134 |
static_cast< ::cppu::OWeakObject* >(this) ); |
| 135 |
|
| 136 |
return embed::EmbedMapUnits::ONE_100TH_MM; |
| 137 |
} |
| 138 |
|
| 139 |
void SAL_CALL OSpecialEmbeddedObject::changeState( sal_Int32 nNewState ) |
| 140 |
{ |
| 141 |
if ( officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() |
| 142 |
&& nNewState != embed::EmbedStates::LOADED ) |
| 143 |
throw embed::UnreachableStateException(); |
| 144 |
|
| 145 |
if ( nNewState == embed::EmbedStates::UI_ACTIVE ) |
| 146 |
nNewState = embed::EmbedStates::INPLACE_ACTIVE; |
| 147 |
OCommonEmbeddedObject::changeState( nNewState ); |
| 148 |
} |
| 149 |
|
| 150 |
void SAL_CALL OSpecialEmbeddedObject::doVerb( sal_Int32 nVerbID ) |
| 151 |
{ |
| 152 |
::osl::MutexGuard aGuard( m_aMutex ); |
| 153 |
if ( m_bDisposed ) |
| 154 |
throw lang::DisposedException(); // TODO |
| 155 |
|
| 156 |
if ( m_nObjectState == -1 ) |
| 157 |
throw embed::WrongStateException( u"The object has no persistence!"_ustr, |
| 158 |
static_cast< ::cppu::OWeakObject* >(this) ); |
| 159 |
|
| 160 |
if ( nVerbID == -7 ) |
| 161 |
{ |
| 162 |
|
| 163 |
uno::Reference < ui::dialogs::XExecutableDialog > xDlg( m_xDocHolder->GetComponent(), uno::UNO_QUERY ); |
| 164 |
if ( !xDlg.is() ) |
| 165 |
throw embed::UnreachableStateException(); |
| 166 |
xDlg->execute(); |
| 167 |
} |
| 168 |
else |
| 169 |
OCommonEmbeddedObject::doVerb( nVerbID ); |
| 170 |
} |
| 171 |
|
| 172 |
void SAL_CALL OSpecialEmbeddedObject::reload( |
| 173 |
const uno::Sequence< beans::PropertyValue >&, |
| 174 |
const uno::Sequence< beans::PropertyValue >&) |
| 175 |
{ |
| 176 |
// Allow IFrames to reload their content |
| 177 |
SetInplaceActiveState(); |
| 178 |
} |
| 179 |
|
| 180 |
OUString SAL_CALL OSpecialEmbeddedObject::getImplementationName() |
| 181 |
{ |
| 182 |
return u"com.sun.star.comp.embed.OSpecialEmbeddedObject"_ustr; |
| 183 |
} |
| 184 |
|
| 185 |
sal_Bool SAL_CALL OSpecialEmbeddedObject::supportsService(const OUString& ServiceName) |
| 186 |
{ |
| 187 |
return cppu::supportsService(this, ServiceName); |
| 188 |
} |
| 189 |
|
| 190 |
uno::Sequence<OUString> SAL_CALL OSpecialEmbeddedObject::getSupportedServiceNames() |
| 191 |
{ |
| 192 |
return { u"com.sun.star.comp.embed.OSpecialEmbeddedObject"_ustr }; |
| 193 |
} |
| 194 |
|
| 195 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |