1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/awt/XAdjustmentListener.hpp>
30 #include <com/sun/star/awt/XActionListener.hpp>
31 #include <com/sun/star/awt/XTextListener.hpp>
32 #include <com/sun/star/awt/XSpinListener.hpp>
33 #include <com/sun/star/awt/XItemListener.hpp>
34 #include <com/sun/star/awt/XVclContainerListener.hpp>
35 #include <com/sun/star/awt/PosSize.hpp>
37 #include <plugin/plctrl.hxx>
38 #include <vcl/syschild.hxx>
39 #include <toolkit/helper/vclunohelper.hxx>
41 PluginControl_Impl::PluginControl_Impl()
42 : _pMultiplexer( NULL
)
47 , _nFlags( css::awt::PosSize::POSSIZE
)
49 , _bInDesignMode(false)
55 PluginControl_Impl::~PluginControl_Impl()
59 MRCListenerMultiplexerHelper
* PluginControl_Impl::getMultiplexer()
62 _pMultiplexer
= new MRCListenerMultiplexerHelper( this, _xPeerWindow
);
67 void PluginControl_Impl::addEventListener( const Reference
< ::com::sun::star::lang::XEventListener
> & l
)
68 throw( RuntimeException
, std::exception
)
70 _aDisposeListeners
.push_back( l
);
73 //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
74 void PluginControl_Impl::removeEventListener( const Reference
< ::com::sun::star::lang::XEventListener
> & l
)
75 throw( RuntimeException
, std::exception
)
77 _aDisposeListeners
.remove( l
);
80 //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
81 void PluginControl_Impl::dispose()
82 throw( RuntimeException
, std::exception
)
84 // send disposing events
85 ::com::sun::star::lang::EventObject aEvt
;
86 if( getMultiplexer() )
87 getMultiplexer()->disposeAndClear();
90 _xContext
= Reference
< XInterface
> ();
95 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
96 void PluginControl_Impl::setPosSize( sal_Int32 nX_
, sal_Int32 nY_
, sal_Int32 nWidth_
, sal_Int32 nHeight_
, sal_Int16 nFlags
)
97 throw( RuntimeException
, std::exception
)
99 _nX
= nX_
>=0 ? nX_
: 0;
100 _nY
= nY_
>=0 ? nY_
: 0;
101 _nWidth
= nWidth_
>=0 ? nWidth_
: 0;
102 _nHeight
= nHeight_
>=0 ? nHeight_
: 0;
105 if (_xPeerWindow
.is())
106 _xPeerWindow
->setPosSize( _nX
, _nY
, _nWidth
, _nHeight
, nFlags
);
109 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
110 ::com::sun::star::awt::Rectangle
PluginControl_Impl::getPosSize()
111 throw( RuntimeException
, std::exception
)
113 return _xPeerWindow
->getPosSize();
116 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
117 void PluginControl_Impl::setVisible( sal_Bool bVisible
)
118 throw( RuntimeException
, std::exception
)
120 _bVisible
= bVisible
;
121 if (_xPeerWindow
.is())
122 _xPeerWindow
->setVisible( _bVisible
&& !_bInDesignMode
);
125 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
126 void PluginControl_Impl::setEnable( sal_Bool bEnable
)
127 throw( RuntimeException
, std::exception
)
130 if (_xPeerWindow
.is())
131 _xPeerWindow
->setEnable( _bEnable
);
134 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
135 void PluginControl_Impl::setFocus() throw( RuntimeException
, std::exception
)
137 if (_xPeerWindow
.is())
138 _xPeerWindow
->setFocus();
143 void PluginControl_Impl::releasePeer()
147 _xParentWindow
->removeFocusListener( this );
148 _xPeerWindow
->dispose();
150 _xPeerWindow
= Reference
< ::com::sun::star::awt::XWindow
> ();
151 _xPeer
= Reference
< ::com::sun::star::awt::XWindowPeer
> ();
152 getMultiplexer()->setPeer( Reference
< ::com::sun::star::awt::XWindow
> () );
156 //---- ::com::sun::star::awt::XControl ------------------------------------------------------------------------------------
157 void PluginControl_Impl::createPeer( const Reference
< ::com::sun::star::awt::XToolkit
> & /*xToolkit*/, const Reference
< ::com::sun::star::awt::XWindowPeer
> & xParentPeer
)
158 throw( RuntimeException
, std::exception
)
162 OSL_FAIL( "### Peer is already set!" );
166 _xParentPeer
= xParentPeer
;
167 _xParentWindow
= Reference
< ::com::sun::star::awt::XWindow
> ( xParentPeer
, UNO_QUERY
);
168 DBG_ASSERT( _xParentWindow
.is(), "### no parent peer window!" );
170 vcl::Window
* pImpl
= VCLUnoHelper::GetWindow( xParentPeer
);
173 _pSysChild
= VclPtr
<SystemChildWindow
>::Create( pImpl
, WB_CLIPCHILDREN
);
174 if (pImpl
->HasFocus())
175 _pSysChild
->GrabFocus();
178 _xPeer
= Reference
< ::com::sun::star::awt::XWindowPeer
> ( _pSysChild
->GetComponentInterface() );
179 _xPeerWindow
= Reference
< ::com::sun::star::awt::XWindow
> ( _xPeer
, UNO_QUERY
);
180 // !_BOTH_ MUST BE VALID!
181 DBG_ASSERT( (_xPeer
.is() && _xPeerWindow
.is()), "### no peer!" );
183 _xParentWindow
->addFocusListener( this );
184 _xPeerWindow
->setPosSize( _nX
, _nY
, _nWidth
, _nHeight
, _nFlags
);
185 _xPeerWindow
->setEnable( _bEnable
);
186 _xPeerWindow
->setVisible( _bVisible
&& !_bInDesignMode
);
190 OSL_FAIL( "### cannot get implementation of parent peer!" );
193 getMultiplexer()->setPeer( _xPeerWindow
);
196 //---- ::com::sun::star::awt::XControl ------------------------------------------------------------------------------------
197 void PluginControl_Impl::setDesignMode( sal_Bool bOn
)
198 throw( RuntimeException
, std::exception
)
200 _bInDesignMode
= bOn
;
201 if (_xPeerWindow
.is())
202 _xPeerWindow
->setVisible( _bVisible
&& !_bInDesignMode
);
205 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
206 void PluginControl_Impl::addPaintListener( const Reference
< ::com::sun::star::awt::XPaintListener
> & l
)
207 throw( RuntimeException
, std::exception
)
209 getMultiplexer()->advise( cppu::UnoType
<com::sun::star::awt::XPaintListener
>::get(), l
);
212 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
213 void PluginControl_Impl::removePaintListener( const Reference
< ::com::sun::star::awt::XPaintListener
> & l
)
214 throw( RuntimeException
, std::exception
)
216 getMultiplexer()->unadvise( cppu::UnoType
<com::sun::star::awt::XPaintListener
>::get(), l
);
219 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
220 void PluginControl_Impl::addWindowListener( const Reference
< ::com::sun::star::awt::XWindowListener
> & l
)
221 throw( RuntimeException
, std::exception
)
223 getMultiplexer()->advise( cppu::UnoType
<com::sun::star::awt::XWindowListener
>::get(), l
);
226 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
227 void PluginControl_Impl::removeWindowListener( const Reference
< ::com::sun::star::awt::XWindowListener
> & l
)
228 throw( RuntimeException
, std::exception
)
230 getMultiplexer()->unadvise( cppu::UnoType
<com::sun::star::awt::XWindowListener
>::get(), l
);
233 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
234 void PluginControl_Impl::addFocusListener( const Reference
< ::com::sun::star::awt::XFocusListener
> & l
)
235 throw( RuntimeException
, std::exception
)
237 getMultiplexer()->advise( cppu::UnoType
<com::sun::star::awt::XFocusListener
>::get(), l
);
240 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
241 void PluginControl_Impl::removeFocusListener( const Reference
< ::com::sun::star::awt::XFocusListener
> & l
)
242 throw( RuntimeException
, std::exception
)
244 getMultiplexer()->unadvise( cppu::UnoType
<com::sun::star::awt::XFocusListener
>::get(), l
);
247 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
248 void PluginControl_Impl::addKeyListener( const Reference
< ::com::sun::star::awt::XKeyListener
> & l
)
249 throw( RuntimeException
, std::exception
)
251 getMultiplexer()->advise( cppu::UnoType
<com::sun::star::awt::XKeyListener
>::get(), l
);
254 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
255 void PluginControl_Impl::removeKeyListener( const Reference
< ::com::sun::star::awt::XKeyListener
> & l
)
256 throw( RuntimeException
, std::exception
)
258 getMultiplexer()->unadvise( cppu::UnoType
<com::sun::star::awt::XKeyListener
>::get(), l
);
261 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
262 void PluginControl_Impl::addMouseListener( const Reference
< ::com::sun::star::awt::XMouseListener
> & l
)
263 throw( RuntimeException
, std::exception
)
265 getMultiplexer()->advise( cppu::UnoType
<com::sun::star::awt::XMouseListener
>::get(), l
);
268 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
269 void PluginControl_Impl::removeMouseListener( const Reference
< ::com::sun::star::awt::XMouseListener
> & l
)
270 throw( RuntimeException
, std::exception
)
272 getMultiplexer()->unadvise( cppu::UnoType
<com::sun::star::awt::XMouseListener
>::get(), l
);
275 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
276 void PluginControl_Impl::addMouseMotionListener( const Reference
< ::com::sun::star::awt::XMouseMotionListener
> & l
)
277 throw( RuntimeException
, std::exception
)
279 getMultiplexer()->advise( cppu::UnoType
<com::sun::star::awt::XMouseMotionListener
>::get(), l
);
282 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
283 void PluginControl_Impl::removeMouseMotionListener( const Reference
< ::com::sun::star::awt::XMouseMotionListener
> & l
)
284 throw( RuntimeException
, std::exception
)
286 getMultiplexer()->unadvise( cppu::UnoType
<com::sun::star::awt::XMouseMotionListener
>::get(), l
);
290 //---- ::com::sun::star::awt::XView ---------------------------------------------------------------------------------------
291 void PluginControl_Impl::draw( sal_Int32
/*x*/, sal_Int32
/*y*/ )
292 throw( RuntimeException
, std::exception
)
294 // has to be done by further implementation of control
297 //---- ::com::sun::star::awt::XView ---------------------------------------------------------------------------------------
298 void PluginControl_Impl::setZoom( float /*ZoomX*/, float /*ZoomY*/ )
299 throw( RuntimeException
, std::exception
)
301 // has to be done by further implementation of control
304 //---- ::com::sun::star::lang::XEventListener ------------------------------------------------------------------------------
305 void PluginControl_Impl::disposing( const ::com::sun::star::lang::EventObject
& /*rSource*/ )
306 throw( RuntimeException
, std::exception
)
309 //---- ::com::sun::star::awt::XFocusListener ------------------------------------------------------------------------------
310 void PluginControl_Impl::focusGained( const ::com::sun::star::awt::FocusEvent
& /*rEvt*/ )
311 throw( RuntimeException
, std::exception
)
313 if (_xPeerWindow
.is())
314 _xPeerWindow
->setFocus();
316 //---- ::com::sun::star::awt::XFocusListener ------------------------------------------------------------------------------
317 void PluginControl_Impl::focusLost( const ::com::sun::star::awt::FocusEvent
& /*rEvt*/ )
318 throw( RuntimeException
, std::exception
)
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */