1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
27 #include <commonembobj.hxx>
30 using namespace ::com::sun::star
;
32 void SAL_CALL
OCommonEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect
, const awt::Size
& aSize
)
33 throw ( lang::IllegalArgumentException
,
34 embed::WrongStateException
,
36 uno::RuntimeException
)
38 ::osl::MutexGuard
aGuard( m_aMutex
);
40 throw lang::DisposedException(); // TODO
42 SAL_WARN_IF( nAspect
== embed::Aspects::MSOLE_ICON
, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
43 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
44 // no representation can be retrieved
45 throw embed::WrongStateException( OUString( "Illegal call!\n" ),
46 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
48 if ( m_nObjectState
== -1 )
49 throw embed::WrongStateException( OUString( "The own object has no persistence!\n" ),
50 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
52 m_bHasClonedSize
= sal_False
;
54 sal_Bool bBackToLoaded
= sal_False
;
55 if ( m_nObjectState
== embed::EmbedStates::LOADED
)
57 changeState( embed::EmbedStates::RUNNING
);
59 // the links should be switched back to loaded state for now to avoid locking problems
60 bBackToLoaded
= m_bIsLink
;
63 sal_Bool bSuccess
= m_pDocHolder
->SetExtent( nAspect
, aSize
);
66 changeState( embed::EmbedStates::LOADED
);
69 throw uno::Exception(); // TODO:
72 awt::Size SAL_CALL
OCommonEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect
)
73 throw ( lang::IllegalArgumentException
,
74 embed::WrongStateException
,
76 uno::RuntimeException
)
78 ::osl::MutexGuard
aGuard( m_aMutex
);
80 throw lang::DisposedException(); // TODO
82 if ( m_nObjectState
== -1 )
83 throw embed::WrongStateException( OUString( "The own object has no persistence!\n" ),
84 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
86 SAL_WARN_IF( nAspect
== embed::Aspects::MSOLE_ICON
, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
88 if ( m_bHasClonedSize
)
91 sal_Bool bBackToLoaded
= sal_False
;
92 if ( m_nObjectState
== embed::EmbedStates::LOADED
)
94 changeState( embed::EmbedStates::RUNNING
);
96 // the links should be switched back to loaded state for now to avoid locking problems
97 bBackToLoaded
= m_bIsLink
;
101 sal_Bool bSuccess
= m_pDocHolder
->GetExtent( nAspect
, &aResult
);
104 changeState( embed::EmbedStates::LOADED
);
107 throw uno::Exception(); // TODO:
112 sal_Int32 SAL_CALL
OCommonEmbeddedObject::getMapUnit( sal_Int64 nAspect
)
113 throw ( uno::Exception
,
114 uno::RuntimeException
)
116 ::osl::MutexGuard
aGuard( m_aMutex
);
118 throw lang::DisposedException(); // TODO
120 SAL_WARN_IF( nAspect
== embed::Aspects::MSOLE_ICON
, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
121 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
122 // no representation can be retrieved
123 throw embed::WrongStateException( OUString( "Illegal call!\n" ),
124 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
126 if ( m_nObjectState
== -1 )
127 throw embed::WrongStateException( OUString( "The own object has no persistence!\n" ),
128 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
130 if ( m_bHasClonedSize
)
131 return m_nClonedMapUnit
;
133 sal_Bool bBackToLoaded
= sal_False
;
134 if ( m_nObjectState
== embed::EmbedStates::LOADED
)
136 changeState( embed::EmbedStates::RUNNING
);
138 // the links should be switched back to loaded state for now to avoid locking problems
139 bBackToLoaded
= m_bIsLink
;
142 sal_Int32 nResult
= m_pDocHolder
->GetMapUnit( nAspect
);
145 changeState( embed::EmbedStates::LOADED
);
148 throw uno::Exception(); // TODO:
153 embed::VisualRepresentation SAL_CALL
OCommonEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect
)
154 throw ( lang::IllegalArgumentException
,
155 embed::WrongStateException
,
157 uno::RuntimeException
)
159 ::osl::MutexGuard
aGuard( m_aMutex
);
161 throw lang::DisposedException(); // TODO
163 if ( m_nObjectState
== -1 )
164 throw embed::WrongStateException( OUString( "The own object has no persistence!\n" ),
165 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
168 SAL_WARN_IF( nAspect
== embed::Aspects::MSOLE_ICON
, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
169 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
170 // no representation can be retrieved
171 throw embed::WrongStateException( OUString( "Illegal call!\n" ),
172 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
174 sal_Bool bBackToLoaded
= sal_False
;
175 if ( m_nObjectState
== embed::EmbedStates::LOADED
)
177 changeState( embed::EmbedStates::RUNNING
);
179 // the links should be switched back to loaded state for now to avoid locking problems
180 bBackToLoaded
= m_bIsLink
;
183 SAL_WARN_IF( !m_pDocHolder
->GetComponent().is(), "embeddedobj.common", "Running or Active object has no component!" );
185 // TODO: return for the aspect of the document
186 embed::VisualRepresentation aVisualRepresentation
;
188 uno::Reference
< embed::XVisualObject
> xVisualObject( m_pDocHolder
->GetComponent(), uno::UNO_QUERY
);
189 if( xVisualObject
.is())
191 aVisualRepresentation
= xVisualObject
->getPreferredVisualRepresentation( nAspect
);
195 uno::Reference
< datatransfer::XTransferable
> xTransferable( m_pDocHolder
->GetComponent(), uno::UNO_QUERY
);
196 if (!xTransferable
.is() )
197 throw uno::RuntimeException();
199 datatransfer::DataFlavor
aDataFlavor(
200 OUString( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
201 OUString( "GDIMetaFile" ),
202 ::getCppuType( (const uno::Sequence
< sal_Int8
>*) NULL
) );
204 if( xTransferable
->isDataFlavorSupported( aDataFlavor
))
206 aVisualRepresentation
.Data
= xTransferable
->getTransferData( aDataFlavor
);
207 aVisualRepresentation
.Flavor
= aDataFlavor
;
210 throw uno::RuntimeException();
214 changeState( embed::EmbedStates::LOADED
);
216 return aVisualRepresentation
;
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */