Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / embeddedobj / source / commonembedding / specialobject.cxx
blob683fe0aab3f259b5798cb53984f938370c3e32c7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/ui/dialogs/XExecutableDialog.hpp>
21 #include <com/sun/star/embed/EmbedStates.hpp>
22 #include <com/sun/star/embed/UnreachableStateException.hpp>
23 #include <com/sun/star/embed/WrongStateException.hpp>
24 #include <com/sun/star/embed/Aspects.hpp>
25 #include <com/sun/star/util/XCloseable.hpp>
26 #include <com/sun/star/lang/DisposedException.hpp>
27 #include <com/sun/star/embed/EmbedMapUnits.hpp>
29 #include <cppuhelper/queryinterface.hxx>
30 #include <osl/diagnose.h>
32 #include <specialobject.hxx>
34 using namespace ::com::sun::star;
37 OSpecialEmbeddedObject::OSpecialEmbeddedObject( const uno::Reference< uno::XComponentContext >& rxContext, const uno::Sequence< beans::NamedValue >& aObjectProps )
38 : OCommonEmbeddedObject( rxContext, aObjectProps )
40 maSize.Width = maSize.Height = 10000;
41 m_nObjectState = embed::EmbedStates::LOADED;
45 uno::Any SAL_CALL OSpecialEmbeddedObject::queryInterface( const uno::Type& rType )
47 uno::Any aReturn = ::cppu::queryInterface( rType,
48 static_cast< embed::XEmbeddedObject* >( this ),
49 static_cast< embed::XInplaceObject* >( this ),
50 static_cast< embed::XVisualObject* >( this ),
51 static_cast< embed::XClassifiedObject* >( this ),
52 static_cast< embed::XComponentSupplier* >( this ),
53 static_cast< util::XCloseable* >( this ),
54 static_cast< document::XEventBroadcaster* >( this ) );
55 if ( aReturn.hasValue() )
56 return aReturn;
57 else
58 return ::cppu::OWeakObject::queryInterface( rType ) ;
63 embed::VisualRepresentation SAL_CALL OSpecialEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
65 ::osl::MutexGuard aGuard( m_aMutex );
66 if ( m_bDisposed )
67 throw lang::DisposedException(); // TODO
69 // TODO: if object is in loaded state it should switch itself to the running state
70 if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::LOADED )
71 throw embed::WrongStateException( "The own object has no model!",
72 static_cast< ::cppu::OWeakObject* >(this) );
74 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" );
75 if ( nAspect == embed::Aspects::MSOLE_ICON )
76 // no representation can be retrieved
77 throw embed::WrongStateException( "Illegal call!",
78 static_cast< ::cppu::OWeakObject* >(this) );
80 // TODO: return for the aspect of the document
81 embed::VisualRepresentation aVisualRepresentation;
82 return aVisualRepresentation;
85 void SAL_CALL OSpecialEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
87 ::osl::MutexGuard aGuard( m_aMutex );
88 if ( m_bDisposed )
89 throw lang::DisposedException(); // TODO
91 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" );
92 if ( nAspect == embed::Aspects::MSOLE_ICON )
93 // no representation can be retrieved
94 throw embed::WrongStateException( "Illegal call!",
95 static_cast< ::cppu::OWeakObject* >(this) );
97 maSize = aSize;
100 awt::Size SAL_CALL OSpecialEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
102 ::osl::MutexGuard aGuard( m_aMutex );
103 if ( m_bDisposed )
104 throw lang::DisposedException(); // TODO
106 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" );
107 if ( nAspect == embed::Aspects::MSOLE_ICON )
108 // no representation can be retrieved
109 throw embed::WrongStateException( "Illegal call!",
110 static_cast< ::cppu::OWeakObject* >(this) );
112 if ( m_nObjectState == -1 )
113 throw embed::WrongStateException( "The own object has no model!",
114 static_cast< ::cppu::OWeakObject* >(this) );
116 return maSize;
119 sal_Int32 SAL_CALL OSpecialEmbeddedObject::getMapUnit( sal_Int64 nAspect )
121 ::osl::MutexGuard aGuard( m_aMutex );
122 if ( m_bDisposed )
123 throw lang::DisposedException(); // TODO
125 OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!" );
126 if ( nAspect == embed::Aspects::MSOLE_ICON )
127 // no representation can be retrieved
128 throw embed::WrongStateException( "Illegal call!",
129 static_cast< ::cppu::OWeakObject* >(this) );
131 return embed::EmbedMapUnits::ONE_100TH_MM;
134 void SAL_CALL OSpecialEmbeddedObject::changeState( sal_Int32 nNewState )
136 if ( nNewState == embed::EmbedStates::UI_ACTIVE )
137 nNewState = embed::EmbedStates::INPLACE_ACTIVE;
138 OCommonEmbeddedObject::changeState( nNewState );
141 void SAL_CALL OSpecialEmbeddedObject::doVerb( sal_Int32 nVerbID )
143 ::osl::MutexGuard aGuard( m_aMutex );
144 if ( m_bDisposed )
145 throw lang::DisposedException(); // TODO
147 if ( m_nObjectState == -1 )
148 throw embed::WrongStateException( "The object has no persistence!",
149 static_cast< ::cppu::OWeakObject* >(this) );
151 if ( nVerbID == -7 )
154 uno::Reference < ui::dialogs::XExecutableDialog > xDlg( m_xDocHolder->GetComponent(), uno::UNO_QUERY );
155 if ( !xDlg.is() )
156 throw embed::UnreachableStateException();
157 xDlg->execute();
159 else
160 OCommonEmbeddedObject::doVerb( nVerbID );
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */