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