1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: visobj.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_embeddedobj.hxx"
33 #include <com/sun/star/embed/Aspects.hpp>
34 #include <com/sun/star/embed/EmbedStates.hpp>
35 #include <com/sun/star/datatransfer/XTransferable.hpp>
36 #include <com/sun/star/uno/Sequence.hxx>
37 #include <com/sun/star/lang/DisposedException.hpp>
39 #include <rtl/logfile.hxx>
42 #include <commonembobj.hxx>
45 using namespace ::com::sun::star
;
47 void SAL_CALL
OCommonEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect
, const awt::Size
& aSize
)
48 throw ( lang::IllegalArgumentException
,
49 embed::WrongStateException
,
51 uno::RuntimeException
)
53 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OCommonEmbeddedObject::setVisualAreaSize" );
55 ::osl::MutexGuard
aGuard( m_aMutex
);
57 throw lang::DisposedException(); // TODO
59 OSL_ENSURE( nAspect
!= embed::Aspects::MSOLE_ICON
, "For iconified objects no graphical replacement is required!\n" );
60 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
61 // no representation can be retrieved
62 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
63 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
65 if ( m_nObjectState
== -1 )
66 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
67 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
69 m_bHasClonedSize
= sal_False
;
71 sal_Bool bBackToLoaded
= sal_False
;
72 if ( m_nObjectState
== embed::EmbedStates::LOADED
)
74 changeState( embed::EmbedStates::RUNNING
);
76 // the links should be switched back to loaded state for now to avoid locking problems
77 bBackToLoaded
= m_bIsLink
;
80 sal_Bool bSuccess
= m_pDocHolder
->SetExtent( nAspect
, aSize
);
83 changeState( embed::EmbedStates::LOADED
);
86 throw uno::Exception(); // TODO:
89 awt::Size SAL_CALL
OCommonEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect
)
90 throw ( lang::IllegalArgumentException
,
91 embed::WrongStateException
,
93 uno::RuntimeException
)
95 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OCommonEmbeddedObject::getVisualAreaSize" );
97 ::osl::MutexGuard
aGuard( m_aMutex
);
99 throw lang::DisposedException(); // TODO
101 if ( m_nObjectState
== -1 )
102 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
103 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
105 OSL_ENSURE( nAspect
!= embed::Aspects::MSOLE_ICON
, "For iconified objects no graphical replacement is required!\n" );
107 if ( m_bHasClonedSize
)
108 return m_aClonedSize
;
110 sal_Bool bBackToLoaded
= sal_False
;
111 if ( m_nObjectState
== embed::EmbedStates::LOADED
)
113 changeState( embed::EmbedStates::RUNNING
);
115 // the links should be switched back to loaded state for now to avoid locking problems
116 bBackToLoaded
= m_bIsLink
;
120 sal_Bool bSuccess
= m_pDocHolder
->GetExtent( nAspect
, &aResult
);
123 changeState( embed::EmbedStates::LOADED
);
126 throw uno::Exception(); // TODO:
131 sal_Int32 SAL_CALL
OCommonEmbeddedObject::getMapUnit( sal_Int64 nAspect
)
132 throw ( uno::Exception
,
133 uno::RuntimeException
)
135 ::osl::MutexGuard
aGuard( m_aMutex
);
137 throw lang::DisposedException(); // TODO
139 OSL_ENSURE( nAspect
!= embed::Aspects::MSOLE_ICON
, "For iconified objects no graphical replacement is required!\n" );
140 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
141 // no representation can be retrieved
142 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
143 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
145 if ( m_nObjectState
== -1 )
146 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
147 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
149 if ( m_bHasClonedSize
)
150 return m_nClonedMapUnit
;
152 sal_Bool bBackToLoaded
= sal_False
;
153 if ( m_nObjectState
== embed::EmbedStates::LOADED
)
155 changeState( embed::EmbedStates::RUNNING
);
157 // the links should be switched back to loaded state for now to avoid locking problems
158 bBackToLoaded
= m_bIsLink
;
161 sal_Int32 nResult
= m_pDocHolder
->GetMapUnit( nAspect
);
164 changeState( embed::EmbedStates::LOADED
);
167 throw uno::Exception(); // TODO:
172 embed::VisualRepresentation SAL_CALL
OCommonEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect
)
173 throw ( lang::IllegalArgumentException
,
174 embed::WrongStateException
,
176 uno::RuntimeException
)
178 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OCommonEmbeddedObject::getPrefferedVisualRepresentation" );
180 ::osl::MutexGuard
aGuard( m_aMutex
);
182 throw lang::DisposedException(); // TODO
184 if ( m_nObjectState
== -1 )
185 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ),
186 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
189 OSL_ENSURE( nAspect
!= embed::Aspects::MSOLE_ICON
, "For iconified objects no graphical replacement is required!\n" );
190 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
191 // no representation can be retrieved
192 throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
193 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
195 sal_Bool bBackToLoaded
= sal_False
;
196 if ( m_nObjectState
== embed::EmbedStates::LOADED
)
198 changeState( embed::EmbedStates::RUNNING
);
200 // the links should be switched back to loaded state for now to avoid locking problems
201 bBackToLoaded
= m_bIsLink
;
204 OSL_ENSURE( m_pDocHolder
->GetComponent().is(), "Running or Active object has no component!\n" );
206 // TODO: return for the aspect of the document
207 embed::VisualRepresentation aVisualRepresentation
;
209 uno::Reference
< embed::XVisualObject
> xVisualObject( m_pDocHolder
->GetComponent(), uno::UNO_QUERY
);
210 if( xVisualObject
.is())
212 aVisualRepresentation
= xVisualObject
->getPreferredVisualRepresentation( nAspect
);
216 uno::Reference
< datatransfer::XTransferable
> xTransferable( m_pDocHolder
->GetComponent(), uno::UNO_QUERY
);
217 if (!xTransferable
.is() )
218 throw uno::RuntimeException();
220 datatransfer::DataFlavor
aDataFlavor(
221 ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
222 ::rtl::OUString::createFromAscii( "GDIMetaFile" ),
223 ::getCppuType( (const uno::Sequence
< sal_Int8
>*) NULL
) );
225 if( xTransferable
->isDataFlavorSupported( aDataFlavor
))
227 aVisualRepresentation
.Data
= xTransferable
->getTransferData( aDataFlavor
);
228 aVisualRepresentation
.Flavor
= aDataFlavor
;
231 throw uno::RuntimeException();
235 changeState( embed::EmbedStates::LOADED
);
237 return aVisualRepresentation
;