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/XHatchWindowController.hpp>
22 #include "hatchwindow.hxx"
25 #include <toolkit/helper/convert.hxx>
26 #include <cppuhelper/queryinterface.hxx>
27 #include <osl/mutex.hxx>
28 #include <vcl/svapp.hxx>
30 using namespace ::com::sun::star
;
32 VCLXHatchWindow::VCLXHatchWindow()
38 VCLXHatchWindow::~VCLXHatchWindow()
42 void VCLXHatchWindow::initializeWindow( const uno::Reference
< awt::XWindowPeer
>& xParent
,
43 const awt::Rectangle
& aBounds
,
44 const awt::Size
& aSize
)
46 SolarMutexGuard aGuard
;
48 vcl::Window
* pParent
= NULL
;
49 VCLXWindow
* pParentComponent
= VCLXWindow::GetImplementation( xParent
);
51 if ( pParentComponent
)
52 pParent
= pParentComponent
->GetWindow();
54 OSL_ENSURE( pParent
, "No parent window is provided!\n" );
56 throw lang::IllegalArgumentException(); // TODO
58 pHatchWindow
= VclPtr
<SvResizeWindow
>::Create( pParent
, this );
59 pHatchWindow
->setPosSizePixel( aBounds
.X
, aBounds
.Y
, aBounds
.Width
, aBounds
.Height
);
60 aHatchBorderSize
= aSize
;
61 pHatchWindow
->SetHatchBorderPixel( Size( aSize
.Width
, aSize
.Height
) );
63 SetWindow( pHatchWindow
);
64 pHatchWindow
->SetComponentInterface( this );
66 //pHatchWindow->Show();
69 void VCLXHatchWindow::QueryObjAreaPixel( Rectangle
& aRect
)
71 if ( m_xController
.is() )
73 awt::Rectangle aUnoRequestRect
= AWTRectangle( aRect
);
76 awt::Rectangle aUnoResultRect
= m_xController
->calcAdjustedRectangle( aUnoRequestRect
);
77 aRect
= VCLRectangle( aUnoResultRect
);
79 catch( uno::Exception
& )
81 OSL_FAIL( "Can't adjust rectangle size!\n" );
86 void VCLXHatchWindow::RequestObjAreaPixel( const Rectangle
& aRect
)
88 if ( m_xController
.is() )
90 awt::Rectangle aUnoRequestRect
= AWTRectangle( aRect
);
93 m_xController
->requestPositioning( aUnoRequestRect
);
95 catch( uno::Exception
& )
97 OSL_FAIL( "Can't request resizing!\n" );
102 void VCLXHatchWindow::InplaceDeactivate()
104 if ( m_xController
.is() )
106 // TODO: communicate with controller
111 uno::Any SAL_CALL
VCLXHatchWindow::queryInterface( const uno::Type
& rType
)
112 throw( uno::RuntimeException
, std::exception
)
115 // Don't use mutex or guard in this method!!! Is a method of XInterface.
117 uno::Any
aReturn( ::cppu::queryInterface( rType
,
118 static_cast< embed::XHatchWindow
* >( this ) ) );
120 if ( aReturn
.hasValue() )
125 return VCLXWindow::queryInterface( rType
) ;
128 void SAL_CALL
VCLXHatchWindow::acquire()
131 VCLXWindow::acquire();
134 void SAL_CALL
VCLXHatchWindow::release()
137 VCLXWindow::release();
140 uno::Sequence
< uno::Type
> SAL_CALL
VCLXHatchWindow::getTypes()
141 throw( uno::RuntimeException
, std::exception
)
143 static ::cppu::OTypeCollection
* pTypeCollection
= NULL
;
145 if ( pTypeCollection
== NULL
)
147 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() ) ;
149 if ( pTypeCollection
== NULL
)
151 static ::cppu::OTypeCollection
aTypeCollection(
152 cppu::UnoType
<embed::XHatchWindow
>::get(),
153 VCLXHatchWindow::getTypes() );
155 pTypeCollection
= &aTypeCollection
;
159 return pTypeCollection
->getTypes() ;
162 uno::Sequence
< sal_Int8
> SAL_CALL
VCLXHatchWindow::getImplementationId()
163 throw( uno::RuntimeException
, std::exception
)
165 return css::uno::Sequence
<sal_Int8
>();
168 ::com::sun::star::awt::Size SAL_CALL
VCLXHatchWindow::getHatchBorderSize() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
170 return aHatchBorderSize
;
173 void SAL_CALL
VCLXHatchWindow::setHatchBorderSize( const ::com::sun::star::awt::Size
& _hatchbordersize
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
177 aHatchBorderSize
= _hatchbordersize
;
178 pHatchWindow
->SetHatchBorderPixel( Size( aHatchBorderSize
.Width
, aHatchBorderSize
.Height
) );
182 void SAL_CALL
VCLXHatchWindow::setController( const uno::Reference
< embed::XHatchWindowController
>& xController
)
183 throw (uno::RuntimeException
, std::exception
)
185 m_xController
= xController
;
188 void SAL_CALL
VCLXHatchWindow::dispose()
189 throw (uno::RuntimeException
, std::exception
)
191 pHatchWindow
.clear();
192 VCLXWindow::dispose();
195 void SAL_CALL
VCLXHatchWindow::addEventListener( const uno::Reference
< lang::XEventListener
>& xListener
)
196 throw (uno::RuntimeException
, std::exception
)
198 VCLXWindow::addEventListener( xListener
);
201 void SAL_CALL
VCLXHatchWindow::removeEventListener( const uno::Reference
< lang::XEventListener
>& xListener
)
202 throw (uno::RuntimeException
, std::exception
)
204 VCLXWindow::removeEventListener( xListener
);
207 void VCLXHatchWindow::Activated()
209 if ( m_xController
.is() )
210 m_xController
->activated();
213 void VCLXHatchWindow::Deactivated()
215 if ( m_xController
.is() )
216 m_xController
->deactivated();
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */