1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: plctrl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include <com/sun/star/awt/XAdjustmentListener.hpp>
34 #include <com/sun/star/awt/XActionListener.hpp>
35 #include <com/sun/star/awt/XTextListener.hpp>
36 #include <com/sun/star/awt/XSpinListener.hpp>
37 #include <com/sun/star/awt/XItemListener.hpp>
38 #include <com/sun/star/awt/XVclContainerListener.hpp>
40 #include <plugin/plctrl.hxx>
41 #include <vcl/syschild.hxx>
42 #include <toolkit/helper/vclunohelper.hxx>
45 //--------------------------------------------------------------------------------------------------
46 PluginControl_Impl::PluginControl_Impl() :
52 , _nFlags( WINDOW_POSSIZE_ALL
)
53 , _bVisible( sal_False
)
54 , _bInDesignMode( sal_False
)
55 , _bEnable( sal_True
)
59 //--------------------------------------------------------------------------------------------------
60 PluginControl_Impl::~PluginControl_Impl()
64 MRCListenerMultiplexerHelper
* PluginControl_Impl::getMultiplexer()
67 _pMultiplexer
= new MRCListenerMultiplexerHelper( this, _xPeerWindow
);
70 //==================================================================================================
72 void PluginControl_Impl::addEventListener( const Reference
< ::com::sun::star::lang::XEventListener
> & l
)
73 throw( RuntimeException
)
75 _aDisposeListeners
.push_back( l
);
78 //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
79 void PluginControl_Impl::removeEventListener( const Reference
< ::com::sun::star::lang::XEventListener
> & l
)
80 throw( RuntimeException
)
82 _aDisposeListeners
.remove( l
);
85 //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
86 void PluginControl_Impl::dispose(void)
87 throw( RuntimeException
)
89 // send disposing events
90 ::com::sun::star::lang::EventObject aEvt
;
91 if( getMultiplexer() )
92 getMultiplexer()->disposeAndClear();
95 _xContext
= Reference
< XInterface
> ();
100 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
101 void PluginControl_Impl::setPosSize( sal_Int32 nX_
, sal_Int32 nY_
, sal_Int32 nWidth_
, sal_Int32 nHeight_
, sal_Int16 nFlags
)
102 throw( RuntimeException
)
104 _nX
= nX_
>=0 ? nX_
: 0;
105 _nY
= nY_
>=0 ? nY_
: 0;
106 _nWidth
= nWidth_
>=0 ? nWidth_
: 0;
107 _nHeight
= nHeight_
>=0 ? nHeight_
: 0;
110 if (_xPeerWindow
.is())
111 _xPeerWindow
->setPosSize( _nX
, _nY
, _nWidth
, _nHeight
, nFlags
);
114 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
115 ::com::sun::star::awt::Rectangle
PluginControl_Impl::getPosSize(void)
116 throw( RuntimeException
)
118 return _xPeerWindow
->getPosSize();
121 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
122 void PluginControl_Impl::setVisible( sal_Bool bVisible
)
123 throw( RuntimeException
)
125 _bVisible
= bVisible
;
126 if (_xPeerWindow
.is())
127 _xPeerWindow
->setVisible( _bVisible
&& !_bInDesignMode
);
130 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
131 void PluginControl_Impl::setEnable( sal_Bool bEnable
)
132 throw( RuntimeException
)
135 if (_xPeerWindow
.is())
136 _xPeerWindow
->setEnable( _bEnable
);
139 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
140 void PluginControl_Impl::setFocus(void) throw( RuntimeException
)
142 if (_xPeerWindow
.is())
143 _xPeerWindow
->setFocus();
147 //--------------------------------------------------------------------------------------------------
148 void PluginControl_Impl::releasePeer()
152 _xParentWindow
->removeFocusListener( this );
153 _xPeerWindow
->dispose();
155 _xPeerWindow
= Reference
< ::com::sun::star::awt::XWindow
> ();
156 _xPeer
= Reference
< ::com::sun::star::awt::XWindowPeer
> ();
157 getMultiplexer()->setPeer( Reference
< ::com::sun::star::awt::XWindow
> () );
161 //---- ::com::sun::star::awt::XControl ------------------------------------------------------------------------------------
162 void PluginControl_Impl::createPeer( const Reference
< ::com::sun::star::awt::XToolkit
> & /*xToolkit*/, const Reference
< ::com::sun::star::awt::XWindowPeer
> & xParentPeer
)
163 throw( RuntimeException
)
167 DBG_ERROR( "### Peer is already set!" );
171 _xParentPeer
= xParentPeer
;
172 _xParentWindow
= Reference
< ::com::sun::star::awt::XWindow
> ( xParentPeer
, UNO_QUERY
);
173 DBG_ASSERT( _xParentWindow
.is(), "### no parent peer window!" );
175 Window
* pImpl
= VCLUnoHelper::GetWindow( xParentPeer
);
178 _pSysChild
= new SystemChildWindow( pImpl
, WB_CLIPCHILDREN
);
179 if (pImpl
->HasFocus())
180 _pSysChild
->GrabFocus();
183 _xPeer
= Reference
< ::com::sun::star::awt::XWindowPeer
> ( _pSysChild
->GetComponentInterface() );
184 _xPeerWindow
= Reference
< ::com::sun::star::awt::XWindow
> ( _xPeer
, UNO_QUERY
);
185 // !_BOTH_ MUST BE VALID!
186 DBG_ASSERT( (_xPeer
.is() && _xPeerWindow
.is()), "### no peer!" );
188 _xParentWindow
->addFocusListener( this );
189 _xPeerWindow
->setPosSize( _nX
, _nY
, _nWidth
, _nHeight
, _nFlags
);
190 _xPeerWindow
->setEnable( _bEnable
);
191 _xPeerWindow
->setVisible( _bVisible
&& !_bInDesignMode
);
195 DBG_ERROR( "### cannot get implementation of parent peer!" );
198 getMultiplexer()->setPeer( _xPeerWindow
);
201 //---- ::com::sun::star::awt::XControl ------------------------------------------------------------------------------------
202 void PluginControl_Impl::setDesignMode( sal_Bool bOn
)
203 throw( RuntimeException
)
205 _bInDesignMode
= bOn
;
206 if (_xPeerWindow
.is())
207 _xPeerWindow
->setVisible( _bVisible
&& !_bInDesignMode
);
210 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
211 void PluginControl_Impl::addPaintListener( const Reference
< ::com::sun::star::awt::XPaintListener
> & l
)
212 throw( RuntimeException
)
214 getMultiplexer()->advise( ::getCppuType((const Reference
< ::com::sun::star::awt::XPaintListener
>*)0), l
);
217 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
218 void PluginControl_Impl::removePaintListener( const Reference
< ::com::sun::star::awt::XPaintListener
> & l
)
219 throw( RuntimeException
)
221 getMultiplexer()->unadvise( ::getCppuType((const Reference
< ::com::sun::star::awt::XPaintListener
>*)0), l
);
224 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
225 void PluginControl_Impl::addWindowListener( const Reference
< ::com::sun::star::awt::XWindowListener
> & l
)
226 throw( RuntimeException
)
228 getMultiplexer()->advise( ::getCppuType((const Reference
< ::com::sun::star::awt::XWindowListener
>*)0), l
);
231 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
232 void PluginControl_Impl::removeWindowListener( const Reference
< ::com::sun::star::awt::XWindowListener
> & l
)
233 throw( RuntimeException
)
235 getMultiplexer()->unadvise( ::getCppuType((const Reference
< ::com::sun::star::awt::XWindowListener
>*)0), l
);
238 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
239 void PluginControl_Impl::addFocusListener( const Reference
< ::com::sun::star::awt::XFocusListener
> & l
)
240 throw( RuntimeException
)
242 getMultiplexer()->advise( ::getCppuType((const Reference
< ::com::sun::star::awt::XFocusListener
>*)0), l
);
245 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
246 void PluginControl_Impl::removeFocusListener( const Reference
< ::com::sun::star::awt::XFocusListener
> & l
)
247 throw( RuntimeException
)
249 getMultiplexer()->unadvise( ::getCppuType((const Reference
< ::com::sun::star::awt::XFocusListener
>*)0), l
);
252 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
253 void PluginControl_Impl::addKeyListener( const Reference
< ::com::sun::star::awt::XKeyListener
> & l
)
254 throw( RuntimeException
)
256 getMultiplexer()->advise( ::getCppuType((const Reference
< ::com::sun::star::awt::XKeyListener
>*)0), l
);
259 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
260 void PluginControl_Impl::removeKeyListener( const Reference
< ::com::sun::star::awt::XKeyListener
> & l
)
261 throw( RuntimeException
)
263 getMultiplexer()->unadvise( ::getCppuType((const Reference
< ::com::sun::star::awt::XKeyListener
>*)0), l
);
266 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
267 void PluginControl_Impl::addMouseListener( const Reference
< ::com::sun::star::awt::XMouseListener
> & l
)
268 throw( RuntimeException
)
270 getMultiplexer()->advise( ::getCppuType((const Reference
< ::com::sun::star::awt::XMouseListener
>*)0), l
);
273 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
274 void PluginControl_Impl::removeMouseListener( const Reference
< ::com::sun::star::awt::XMouseListener
> & l
)
275 throw( RuntimeException
)
277 getMultiplexer()->unadvise( ::getCppuType((const Reference
< ::com::sun::star::awt::XMouseListener
>*)0), l
);
280 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
281 void PluginControl_Impl::addMouseMotionListener( const Reference
< ::com::sun::star::awt::XMouseMotionListener
> & l
)
282 throw( RuntimeException
)
284 getMultiplexer()->advise( ::getCppuType((const Reference
< ::com::sun::star::awt::XMouseMotionListener
>*)0), l
);
287 //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
288 void PluginControl_Impl::removeMouseMotionListener( const Reference
< ::com::sun::star::awt::XMouseMotionListener
> & l
)
289 throw( RuntimeException
)
291 getMultiplexer()->unadvise( ::getCppuType((const Reference
< ::com::sun::star::awt::XMouseMotionListener
>*)0), l
);
295 //---- ::com::sun::star::awt::XView ---------------------------------------------------------------------------------------
296 void PluginControl_Impl::draw( sal_Int32
/*x*/, sal_Int32
/*y*/ )
297 throw( RuntimeException
)
299 // has to be done by further implementation of control
302 //---- ::com::sun::star::awt::XView ---------------------------------------------------------------------------------------
303 void PluginControl_Impl::setZoom( float /*ZoomX*/, float /*ZoomY*/ )
304 throw( RuntimeException
)
306 // has to be done by further implementation of control
309 //---- ::com::sun::star::lang::XEventListener ------------------------------------------------------------------------------
310 void PluginControl_Impl::disposing( const ::com::sun::star::lang::EventObject
& /*rSource*/ )
311 throw( RuntimeException
)
314 //---- ::com::sun::star::awt::XFocusListener ------------------------------------------------------------------------------
315 void PluginControl_Impl::focusGained( const ::com::sun::star::awt::FocusEvent
& /*rEvt*/ )
316 throw( RuntimeException
)
318 if (_xPeerWindow
.is())
319 _xPeerWindow
->setFocus();
321 //---- ::com::sun::star::awt::XFocusListener ------------------------------------------------------------------------------
322 void PluginControl_Impl::focusLost( const ::com::sun::star::awt::FocusEvent
& /*rEvt*/ )
323 throw( RuntimeException
)