xref: /trunk/main/embeddedobj/source/commonembedding/visobj.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_embeddedobj.hxx"
30 #include <com/sun/star/embed/Aspects.hpp>
31 #include <com/sun/star/embed/EmbedStates.hpp>
32 #include <com/sun/star/datatransfer/XTransferable.hpp>
33 #include <com/sun/star/uno/Sequence.hxx>
34 #include <com/sun/star/lang/DisposedException.hpp>
35 
36 #include <rtl/logfile.hxx>
37 
38 
39 #include <commonembobj.hxx>
40 
41 
42 using namespace ::com::sun::star;
43 
44 void SAL_CALL OCommonEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
45         throw ( lang::IllegalArgumentException,
46                 embed::WrongStateException,
47                 uno::Exception,
48                 uno::RuntimeException )
49 {
50     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::setVisualAreaSize" );
51 
52     ::osl::MutexGuard aGuard( m_aMutex );
53     if ( m_bDisposed )
54         throw lang::DisposedException(); // TODO
55 
56     OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
57     if ( nAspect == embed::Aspects::MSOLE_ICON )
58         // no representation can be retrieved
59         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
60                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
61 
62     if ( m_nObjectState == -1 )
63         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
64                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
65 
66     m_bHasClonedSize = sal_False;
67 
68     sal_Bool bBackToLoaded = sal_False;
69     if ( m_nObjectState == embed::EmbedStates::LOADED )
70     {
71         changeState( embed::EmbedStates::RUNNING );
72 
73         // the links should be switched back to loaded state for now to avoid locking problems
74         bBackToLoaded = m_bIsLink;
75     }
76 
77     sal_Bool bSuccess = m_pDocHolder->SetExtent( nAspect, aSize );
78 
79     if ( bBackToLoaded )
80         changeState( embed::EmbedStates::LOADED );
81 
82     if ( !bSuccess )
83         throw uno::Exception(); // TODO:
84 }
85 
86 awt::Size SAL_CALL OCommonEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
87         throw ( lang::IllegalArgumentException,
88                 embed::WrongStateException,
89                 uno::Exception,
90                 uno::RuntimeException )
91 {
92     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::getVisualAreaSize" );
93 
94     ::osl::MutexGuard aGuard( m_aMutex );
95     if ( m_bDisposed )
96         throw lang::DisposedException(); // TODO
97 
98     if ( m_nObjectState == -1 )
99         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
100                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
101 
102     OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
103 
104     if ( m_bHasClonedSize )
105         return m_aClonedSize;
106 
107     sal_Bool bBackToLoaded = sal_False;
108     if ( m_nObjectState == embed::EmbedStates::LOADED )
109     {
110         changeState( embed::EmbedStates::RUNNING );
111 
112         // the links should be switched back to loaded state for now to avoid locking problems
113         bBackToLoaded = m_bIsLink;
114     }
115 
116     awt::Size aResult;
117     sal_Bool bSuccess = m_pDocHolder->GetExtent( nAspect, &aResult );
118 
119     if ( bBackToLoaded )
120         changeState( embed::EmbedStates::LOADED );
121 
122     if ( !bSuccess )
123         throw uno::Exception(); // TODO:
124 
125     return aResult;
126 }
127 
128 sal_Int32 SAL_CALL OCommonEmbeddedObject::getMapUnit( sal_Int64 nAspect )
129         throw ( uno::Exception,
130                 uno::RuntimeException)
131 {
132     ::osl::MutexGuard aGuard( m_aMutex );
133     if ( m_bDisposed )
134         throw lang::DisposedException(); // TODO
135 
136     OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
137     if ( nAspect == embed::Aspects::MSOLE_ICON )
138         // no representation can be retrieved
139         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
140                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
141 
142     if ( m_nObjectState == -1 )
143         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
144                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
145 
146     if ( m_bHasClonedSize )
147         return m_nClonedMapUnit;
148 
149     sal_Bool bBackToLoaded = sal_False;
150     if ( m_nObjectState == embed::EmbedStates::LOADED )
151     {
152         changeState( embed::EmbedStates::RUNNING );
153 
154         // the links should be switched back to loaded state for now to avoid locking problems
155         bBackToLoaded = m_bIsLink;
156     }
157 
158     sal_Int32 nResult = m_pDocHolder->GetMapUnit( nAspect );
159 
160     if ( bBackToLoaded )
161         changeState( embed::EmbedStates::LOADED );
162 
163     if ( nResult < 0  )
164         throw uno::Exception(); // TODO:
165 
166     return nResult;
167 }
168 
169 embed::VisualRepresentation SAL_CALL OCommonEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
170         throw ( lang::IllegalArgumentException,
171                 embed::WrongStateException,
172                 uno::Exception,
173                 uno::RuntimeException )
174 {
175     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::getPrefferedVisualRepresentation" );
176 
177     ::osl::MutexGuard aGuard( m_aMutex );
178     if ( m_bDisposed )
179         throw lang::DisposedException(); // TODO
180 
181     if ( m_nObjectState == -1 )
182         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
183                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
184 
185 
186     OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
187     if ( nAspect == embed::Aspects::MSOLE_ICON )
188         // no representation can be retrieved
189         throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
190                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
191 
192     sal_Bool bBackToLoaded = sal_False;
193     if ( m_nObjectState == embed::EmbedStates::LOADED )
194     {
195         changeState( embed::EmbedStates::RUNNING );
196 
197         // the links should be switched back to loaded state for now to avoid locking problems
198         bBackToLoaded = m_bIsLink;
199     }
200 
201     OSL_ENSURE( m_pDocHolder->GetComponent().is(), "Running or Active object has no component!\n" );
202 
203     // TODO: return for the aspect of the document
204     embed::VisualRepresentation aVisualRepresentation;
205 
206     uno::Reference< embed::XVisualObject > xVisualObject( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
207     if( xVisualObject.is())
208     {
209         aVisualRepresentation = xVisualObject->getPreferredVisualRepresentation( nAspect );
210     }
211     else
212     {
213         uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
214         if (!xTransferable.is() )
215             throw uno::RuntimeException();
216 
217         datatransfer::DataFlavor aDataFlavor(
218                 ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
219                 ::rtl::OUString::createFromAscii( "GDIMetaFile" ),
220                 ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
221 
222         if( xTransferable->isDataFlavorSupported( aDataFlavor ))
223         {
224             aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor );
225             aVisualRepresentation.Flavor = aDataFlavor;
226         }
227         else
228             throw uno::RuntimeException();
229     }
230 
231     if ( bBackToLoaded )
232         changeState( embed::EmbedStates::LOADED );
233 
234     return aVisualRepresentation;
235 }
236 
237