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/embed/Aspects.hpp>
21 : #include <com/sun/star/embed/EmbedStates.hpp>
22 : #include <com/sun/star/datatransfer/XTransferable.hpp>
23 : #include <com/sun/star/uno/Sequence.hxx>
24 : #include <com/sun/star/lang/DisposedException.hpp>
25 :
26 :
27 : #include <commonembobj.hxx>
28 :
29 :
30 : using namespace ::com::sun::star;
31 :
32 298 : void SAL_CALL OCommonEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
33 : throw ( lang::IllegalArgumentException,
34 : embed::WrongStateException,
35 : uno::Exception,
36 : uno::RuntimeException, std::exception )
37 : {
38 298 : ::osl::MutexGuard aGuard( m_aMutex );
39 298 : if ( m_bDisposed )
40 0 : throw lang::DisposedException(); // TODO
41 :
42 : SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
43 298 : if ( nAspect == embed::Aspects::MSOLE_ICON )
44 : // no representation can be retrieved
45 : throw embed::WrongStateException( "Illegal call!",
46 0 : static_cast< ::cppu::OWeakObject* >(this) );
47 :
48 298 : if ( m_nObjectState == -1 )
49 : throw embed::WrongStateException( "The own object has no persistence!",
50 0 : static_cast< ::cppu::OWeakObject* >(this) );
51 :
52 298 : m_bHasClonedSize = false;
53 :
54 298 : bool bBackToLoaded = false;
55 298 : if ( m_nObjectState == embed::EmbedStates::LOADED )
56 : {
57 : //attempt an optimization for chart components
58 153 : if (!IsChartComponent())
59 : {
60 0 : changeState( embed::EmbedStates::RUNNING );
61 :
62 : // the links should be switched back to loaded state for now to avoid locking problems
63 0 : bBackToLoaded = m_bIsLink;
64 : }
65 : }
66 :
67 298 : bool bSuccess = m_pDocHolder->SetExtent( nAspect, aSize );
68 :
69 298 : if ( bBackToLoaded )
70 0 : changeState( embed::EmbedStates::LOADED );
71 :
72 298 : if ( !bSuccess )
73 153 : throw uno::Exception(); // TODO:
74 145 : }
75 :
76 873 : awt::Size SAL_CALL OCommonEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
77 : throw ( lang::IllegalArgumentException,
78 : embed::WrongStateException,
79 : uno::Exception,
80 : uno::RuntimeException, std::exception )
81 : {
82 873 : ::osl::MutexGuard aGuard( m_aMutex );
83 873 : if ( m_bDisposed )
84 0 : throw lang::DisposedException(); // TODO
85 :
86 873 : if ( m_nObjectState == -1 )
87 : throw embed::WrongStateException( "The own object has no persistence!",
88 0 : static_cast< ::cppu::OWeakObject* >(this) );
89 :
90 : SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
91 :
92 873 : if ( m_bHasClonedSize )
93 3 : return m_aClonedSize;
94 :
95 870 : bool bBackToLoaded = false;
96 870 : if ( m_nObjectState == embed::EmbedStates::LOADED )
97 : {
98 24 : changeState( embed::EmbedStates::RUNNING );
99 :
100 : // the links should be switched back to loaded state for now to avoid locking problems
101 23 : bBackToLoaded = m_bIsLink;
102 : }
103 :
104 869 : awt::Size aResult;
105 869 : bool bSuccess = m_pDocHolder->GetExtent( nAspect, &aResult );
106 :
107 869 : if ( bBackToLoaded )
108 0 : changeState( embed::EmbedStates::LOADED );
109 :
110 869 : if ( !bSuccess )
111 0 : throw uno::Exception(); // TODO:
112 :
113 870 : return aResult;
114 : }
115 :
116 1090 : sal_Int32 SAL_CALL OCommonEmbeddedObject::getMapUnit( sal_Int64 nAspect )
117 : throw ( uno::Exception,
118 : uno::RuntimeException, std::exception)
119 : {
120 1090 : ::osl::MutexGuard aGuard( m_aMutex );
121 1090 : if ( m_bDisposed )
122 0 : throw lang::DisposedException(); // TODO
123 :
124 : SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
125 1090 : if ( nAspect == embed::Aspects::MSOLE_ICON )
126 : // no representation can be retrieved
127 : throw embed::WrongStateException( "Illegal call!",
128 0 : static_cast< ::cppu::OWeakObject* >(this) );
129 :
130 1090 : if ( m_nObjectState == -1 )
131 : throw embed::WrongStateException( "The own object has no persistence!",
132 0 : static_cast< ::cppu::OWeakObject* >(this) );
133 :
134 1090 : if ( m_bHasClonedSize )
135 81 : return m_nClonedMapUnit;
136 :
137 1009 : bool bBackToLoaded = false;
138 1009 : if ( m_nObjectState == embed::EmbedStates::LOADED )
139 : {
140 : //attempt an optimization for chart components
141 76 : if (!IsChartComponent())
142 : {
143 1 : changeState( embed::EmbedStates::RUNNING );
144 :
145 : // the links should be switched back to loaded state for now to avoid locking problems
146 0 : bBackToLoaded = m_bIsLink;
147 : }
148 : }
149 :
150 1008 : sal_Int32 nResult = m_pDocHolder->GetMapUnit( nAspect );
151 :
152 1008 : if ( bBackToLoaded )
153 0 : changeState( embed::EmbedStates::LOADED );
154 :
155 1008 : if ( nResult < 0 )
156 0 : throw uno::Exception(); // TODO:
157 :
158 1009 : return nResult;
159 : }
160 :
161 4909 : embed::VisualRepresentation SAL_CALL OCommonEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
162 : throw ( lang::IllegalArgumentException,
163 : embed::WrongStateException,
164 : uno::Exception,
165 : uno::RuntimeException, std::exception )
166 : {
167 4909 : ::osl::MutexGuard aGuard( m_aMutex );
168 4909 : if ( m_bDisposed )
169 0 : throw lang::DisposedException(); // TODO
170 :
171 4909 : if ( m_nObjectState == -1 )
172 : throw embed::WrongStateException( "The own object has no persistence!",
173 0 : static_cast< ::cppu::OWeakObject* >(this) );
174 :
175 :
176 : SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
177 4909 : 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 4909 : bool bBackToLoaded = false;
183 4909 : if ( m_nObjectState == embed::EmbedStates::LOADED )
184 : {
185 2 : changeState( embed::EmbedStates::RUNNING );
186 :
187 : // the links should be switched back to loaded state for now to avoid locking problems
188 2 : bBackToLoaded = m_bIsLink;
189 : }
190 :
191 : SAL_WARN_IF( !m_pDocHolder->GetComponent().is(), "embeddedobj.common", "Running or Active object has no component!" );
192 :
193 : // TODO: return for the aspect of the document
194 4909 : embed::VisualRepresentation aVisualRepresentation;
195 :
196 9818 : uno::Reference< embed::XVisualObject > xVisualObject( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
197 4909 : if( xVisualObject.is())
198 : {
199 4909 : aVisualRepresentation = xVisualObject->getPreferredVisualRepresentation( nAspect );
200 : }
201 : else
202 : {
203 0 : uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
204 0 : if (!xTransferable.is() )
205 0 : throw uno::RuntimeException();
206 :
207 : datatransfer::DataFlavor aDataFlavor(
208 : OUString( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
209 : OUString( "GDIMetaFile" ),
210 0 : cppu::UnoType<uno::Sequence< sal_Int8 >>::get() );
211 :
212 0 : if( xTransferable->isDataFlavorSupported( aDataFlavor ))
213 : {
214 0 : aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor );
215 0 : aVisualRepresentation.Flavor = aDataFlavor;
216 : }
217 : else
218 0 : throw uno::RuntimeException();
219 : }
220 :
221 4909 : if ( bBackToLoaded )
222 0 : changeState( embed::EmbedStates::LOADED );
223 :
224 9818 : return aVisualRepresentation;
225 : }
226 :
227 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|