1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_embeddedobj.hxx"
26 #include <com/sun/star/embed/Aspects.hpp>
27 #include <com/sun/star/embed/EmbedStates.hpp>
28 #include <com/sun/star/datatransfer/XTransferable.hpp>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <com/sun/star/lang/DisposedException.hpp>
31 
32 #include <rtl/logfile.hxx>
33 
34 
35 #include <commonembobj.hxx>
36 
37 
38 using namespace ::com::sun::star;
39 
setVisualAreaSize(sal_Int64 nAspect,const awt::Size & aSize)40 void SAL_CALL OCommonEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
41 		throw ( lang::IllegalArgumentException,
42 				embed::WrongStateException,
43 				uno::Exception,
44 				uno::RuntimeException )
45 {
46 	RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::setVisualAreaSize" );
47 
48 	::osl::MutexGuard aGuard( m_aMutex );
49 	if ( m_bDisposed )
50 		throw lang::DisposedException(); // TODO
51 
52 	OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
53 	if ( nAspect == embed::Aspects::MSOLE_ICON )
54 		// no representation can be retrieved
55 		throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
56 									uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
57 
58 	if ( m_nObjectState == -1 )
59 		throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
60 									uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
61 
62     m_bHasClonedSize = sal_False;
63 
64     sal_Bool bBackToLoaded = sal_False;
65 	if ( m_nObjectState == embed::EmbedStates::LOADED )
66     {
67 		changeState( embed::EmbedStates::RUNNING );
68 
69         // the links should be switched back to loaded state for now to avoid locking problems
70         bBackToLoaded = m_bIsLink;
71     }
72 
73 	sal_Bool bSuccess = m_pDocHolder->SetExtent( nAspect, aSize );
74 
75     if ( bBackToLoaded )
76 		changeState( embed::EmbedStates::LOADED );
77 
78     if ( !bSuccess )
79 		throw uno::Exception(); // TODO:
80 }
81 
getVisualAreaSize(sal_Int64 nAspect)82 awt::Size SAL_CALL OCommonEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
83 		throw ( lang::IllegalArgumentException,
84 				embed::WrongStateException,
85 				uno::Exception,
86 				uno::RuntimeException )
87 {
88 	RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::getVisualAreaSize" );
89 
90 	::osl::MutexGuard aGuard( m_aMutex );
91 	if ( m_bDisposed )
92 		throw lang::DisposedException(); // TODO
93 
94 	if ( m_nObjectState == -1 )
95 		throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
96 									uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
97 
98 	OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
99 
100     if ( m_bHasClonedSize )
101         return m_aClonedSize;
102 
103     sal_Bool bBackToLoaded = sal_False;
104 	if ( m_nObjectState == embed::EmbedStates::LOADED )
105     {
106 		changeState( embed::EmbedStates::RUNNING );
107 
108         // the links should be switched back to loaded state for now to avoid locking problems
109         bBackToLoaded = m_bIsLink;
110     }
111 
112 	awt::Size aResult;
113 	sal_Bool bSuccess = m_pDocHolder->GetExtent( nAspect, &aResult );
114 
115     if ( bBackToLoaded )
116 		changeState( embed::EmbedStates::LOADED );
117 
118     if ( !bSuccess )
119 		throw uno::Exception(); // TODO:
120 
121 	return aResult;
122 }
123 
getMapUnit(sal_Int64 nAspect)124 sal_Int32 SAL_CALL OCommonEmbeddedObject::getMapUnit( sal_Int64 nAspect )
125 		throw ( uno::Exception,
126 				uno::RuntimeException)
127 {
128 	::osl::MutexGuard aGuard( m_aMutex );
129 	if ( m_bDisposed )
130 		throw lang::DisposedException(); // TODO
131 
132 	OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
133 	if ( nAspect == embed::Aspects::MSOLE_ICON )
134 		// no representation can be retrieved
135 		throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
136 									uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
137 
138 	if ( m_nObjectState == -1 )
139 		throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
140 									uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
141 
142     if ( m_bHasClonedSize )
143         return m_nClonedMapUnit;
144 
145     sal_Bool bBackToLoaded = sal_False;
146 	if ( m_nObjectState == embed::EmbedStates::LOADED )
147     {
148 		changeState( embed::EmbedStates::RUNNING );
149 
150         // the links should be switched back to loaded state for now to avoid locking problems
151         bBackToLoaded = m_bIsLink;
152     }
153 
154     sal_Int32 nResult = m_pDocHolder->GetMapUnit( nAspect );
155 
156     if ( bBackToLoaded )
157 		changeState( embed::EmbedStates::LOADED );
158 
159     if ( nResult < 0  )
160 		throw uno::Exception(); // TODO:
161 
162 	return nResult;
163 }
164 
getPreferredVisualRepresentation(sal_Int64 nAspect)165 embed::VisualRepresentation SAL_CALL OCommonEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
166 		throw ( lang::IllegalArgumentException,
167 				embed::WrongStateException,
168 				uno::Exception,
169 				uno::RuntimeException )
170 {
171 	RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::getPrefferedVisualRepresentation" );
172 
173 	::osl::MutexGuard aGuard( m_aMutex );
174 	if ( m_bDisposed )
175 		throw lang::DisposedException(); // TODO
176 
177 	if ( m_nObjectState == -1 )
178 		throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
179 									uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
180 
181 
182 	OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
183 	if ( nAspect == embed::Aspects::MSOLE_ICON )
184 		// no representation can be retrieved
185 		throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
186 									uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
187 
188     sal_Bool bBackToLoaded = sal_False;
189 	if ( m_nObjectState == embed::EmbedStates::LOADED )
190     {
191 		changeState( embed::EmbedStates::RUNNING );
192 
193         // the links should be switched back to loaded state for now to avoid locking problems
194         bBackToLoaded = m_bIsLink;
195     }
196 
197     OSL_ENSURE( m_pDocHolder->GetComponent().is(), "Running or Active object has no component!\n" );
198 
199 	// TODO: return for the aspect of the document
200 	embed::VisualRepresentation aVisualRepresentation;
201 
202     uno::Reference< embed::XVisualObject > xVisualObject( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
203     if( xVisualObject.is())
204     {
205         aVisualRepresentation = xVisualObject->getPreferredVisualRepresentation( nAspect );
206     }
207     else
208     {
209         uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
210         if (!xTransferable.is() )
211             throw uno::RuntimeException();
212 
213 	    datatransfer::DataFlavor aDataFlavor(
214                 ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
215 			    ::rtl::OUString::createFromAscii( "GDIMetaFile" ),
216 			    ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
217 
218         if( xTransferable->isDataFlavorSupported( aDataFlavor ))
219         {
220             aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor );
221             aVisualRepresentation.Flavor = aDataFlavor;
222         }
223         else
224             throw uno::RuntimeException();
225     }
226 
227     if ( bBackToLoaded )
228 		changeState( embed::EmbedStates::LOADED );
229 
230 	return aVisualRepresentation;
231 }
232 
233