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/EmbedStates.hpp>
31 #include <com/sun/star/lang/DisposedException.hpp>
32 
33 #include "commonembobj.hxx"
34 
35 
36 using namespace ::com::sun::star;
37 
38 awt::Rectangle GetRectangleInterception( const awt::Rectangle& aRect1, const awt::Rectangle& aRect2 );
39 sal_Bool RectanglesEqual( const awt::Rectangle& aRect1, const awt::Rectangle& aRect2 )
40 {
41 	return ( aRect1.X == aRect2.X
42 			&& aRect1.Y == aRect2.Y
43 			&& aRect1.Width == aRect2.Width
44 			&& aRect1.Height == aRect2.Height );
45 }
46 
47 void SAL_CALL OCommonEmbeddedObject::setObjectRectangles( const awt::Rectangle& aPosRect,
48 										  			 	const awt::Rectangle& aClipRect )
49 		throw ( embed::WrongStateException,
50 				uno::Exception,
51 				uno::RuntimeException )
52 {
53 	::osl::MutexGuard aGuard( m_aMutex );
54 	if ( m_bDisposed )
55 		throw lang::DisposedException(); // TODO
56 
57 	if ( m_nObjectState != embed::EmbedStates::INPLACE_ACTIVE
58 	  && m_nObjectState != embed::EmbedStates::UI_ACTIVE )
59 		throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is not activated inplace!\n" ),
60 									uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
61 
62 	awt::Rectangle aNewRectToShow = GetRectangleInterception( aPosRect, aClipRect );
63 	awt::Rectangle aOldRectToShow = GetRectangleInterception( m_aOwnRectangle, m_aClipRectangle );
64 
65 	// the clip rectangle changes view only in case interception is also changed
66 	if ( !RectanglesEqual( m_aOwnRectangle, aPosRect )
67 	  || ( !RectanglesEqual( m_aClipRectangle, aPosRect ) && !RectanglesEqual( aOldRectToShow, aNewRectToShow ) ) )
68 		m_pDocHolder->PlaceFrame( aNewRectToShow );
69 
70 	m_aOwnRectangle = aPosRect;
71 	m_aClipRectangle = aClipRect;
72 }
73 
74 void SAL_CALL OCommonEmbeddedObject::enableModeless( sal_Bool /*bEnable*/ )
75 		throw ( embed::WrongStateException,
76 				uno::Exception,
77 				uno::RuntimeException )
78 {
79 	// TODO: notify model that it can not use modal dialogs
80 }
81 
82 void SAL_CALL OCommonEmbeddedObject::translateAccelerators(
83 					const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
84 		throw ( embed::WrongStateException,
85 				uno::RuntimeException )
86 {
87 	// TODO: UI activation related
88 }
89 
90