Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : *
6 : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : *
8 : * OpenOffice.org - a multi-platform office productivity suite
9 : *
10 : * This file is part of OpenOffice.org.
11 : *
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.
15 : *
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).
21 : *
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.
26 : *
27 : ************************************************************************/
28 :
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>
36 :
37 : #include <plugin/plctrl.hxx>
38 : #include <vcl/syschild.hxx>
39 : #include <toolkit/helper/vclunohelper.hxx>
40 :
41 0 : PluginControl_Impl::PluginControl_Impl()
42 : : _pMultiplexer( NULL )
43 : , _nX( 0 )
44 : , _nY( 0 )
45 : , _nWidth( 100 )
46 : , _nHeight( 100 )
47 : , _nFlags( css::awt::PosSize::POSSIZE )
48 : , _bVisible(false)
49 : , _bInDesignMode(false)
50 : , _bEnable(true)
51 0 : , _pSysChild(NULL)
52 : {
53 0 : }
54 :
55 0 : PluginControl_Impl::~PluginControl_Impl()
56 : {
57 0 : }
58 :
59 0 : MRCListenerMultiplexerHelper* PluginControl_Impl::getMultiplexer()
60 : {
61 0 : if( ! _pMultiplexer )
62 0 : _pMultiplexer = new MRCListenerMultiplexerHelper( this, _xPeerWindow );
63 0 : return _pMultiplexer;
64 : }
65 :
66 :
67 0 : void PluginControl_Impl::addEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l )
68 : throw( RuntimeException, std::exception )
69 : {
70 0 : _aDisposeListeners.push_back( l );
71 0 : }
72 :
73 : //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
74 0 : void PluginControl_Impl::removeEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l )
75 : throw( RuntimeException, std::exception )
76 : {
77 0 : _aDisposeListeners.remove( l );
78 0 : }
79 :
80 : //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
81 0 : void PluginControl_Impl::dispose()
82 : throw( RuntimeException, std::exception )
83 : {
84 : // send disposing events
85 0 : ::com::sun::star::lang::EventObject aEvt;
86 0 : if( getMultiplexer() )
87 0 : getMultiplexer()->disposeAndClear();
88 :
89 : // release context
90 0 : _xContext = Reference< XInterface > ();
91 0 : releasePeer();
92 0 : }
93 :
94 :
95 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
96 0 : void PluginControl_Impl::setPosSize( sal_Int32 nX_, sal_Int32 nY_, sal_Int32 nWidth_, sal_Int32 nHeight_, sal_Int16 nFlags )
97 : throw( RuntimeException, std::exception )
98 : {
99 0 : _nX = nX_ >=0 ? nX_ : 0;
100 0 : _nY = nY_ >=0 ? nY_ : 0;
101 0 : _nWidth = nWidth_ >=0 ? nWidth_ : 0;
102 0 : _nHeight = nHeight_ >=0 ? nHeight_ : 0;
103 0 : _nFlags = nFlags;
104 :
105 0 : if (_xPeerWindow.is())
106 0 : _xPeerWindow->setPosSize( _nX, _nY, _nWidth, _nHeight, nFlags );
107 0 : }
108 :
109 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
110 0 : ::com::sun::star::awt::Rectangle PluginControl_Impl::getPosSize()
111 : throw( RuntimeException, std::exception )
112 : {
113 0 : return _xPeerWindow->getPosSize();
114 : }
115 :
116 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
117 0 : void PluginControl_Impl::setVisible( sal_Bool bVisible )
118 : throw( RuntimeException, std::exception )
119 : {
120 0 : _bVisible = bVisible;
121 0 : if (_xPeerWindow.is())
122 0 : _xPeerWindow->setVisible( _bVisible && !_bInDesignMode );
123 0 : }
124 :
125 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
126 0 : void PluginControl_Impl::setEnable( sal_Bool bEnable )
127 : throw( RuntimeException, std::exception )
128 : {
129 0 : _bEnable = bEnable;
130 0 : if (_xPeerWindow.is())
131 0 : _xPeerWindow->setEnable( _bEnable );
132 0 : }
133 :
134 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
135 0 : void PluginControl_Impl::setFocus() throw( RuntimeException, std::exception )
136 : {
137 0 : if (_xPeerWindow.is())
138 0 : _xPeerWindow->setFocus();
139 0 : }
140 :
141 :
142 :
143 0 : void PluginControl_Impl::releasePeer()
144 : {
145 0 : if (_xPeer.is())
146 : {
147 0 : _xParentWindow->removeFocusListener( this );
148 0 : _xPeerWindow->dispose();
149 0 : _pSysChild = NULL;
150 0 : _xPeerWindow = Reference< ::com::sun::star::awt::XWindow > ();
151 0 : _xPeer = Reference< ::com::sun::star::awt::XWindowPeer > ();
152 0 : getMultiplexer()->setPeer( Reference< ::com::sun::star::awt::XWindow > () );
153 : }
154 0 : }
155 :
156 : //---- ::com::sun::star::awt::XControl ------------------------------------------------------------------------------------
157 0 : 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 )
159 : {
160 0 : if (_xPeer.is())
161 : {
162 : OSL_FAIL( "### Peer is already set!" );
163 0 : return;
164 : }
165 :
166 0 : _xParentPeer = xParentPeer;
167 0 : _xParentWindow = Reference< ::com::sun::star::awt::XWindow > ( xParentPeer, UNO_QUERY );
168 : DBG_ASSERT( _xParentWindow.is(), "### no parent peer window!" );
169 :
170 0 : vcl::Window* pImpl = VCLUnoHelper::GetWindow( xParentPeer );
171 0 : if (pImpl)
172 : {
173 0 : _pSysChild = VclPtr<SystemChildWindow>::Create( pImpl, WB_CLIPCHILDREN );
174 0 : if (pImpl->HasFocus())
175 0 : _pSysChild->GrabFocus();
176 :
177 : // get peer
178 0 : _xPeer = Reference< ::com::sun::star::awt::XWindowPeer > ( _pSysChild->GetComponentInterface() );
179 0 : _xPeerWindow = Reference< ::com::sun::star::awt::XWindow > ( _xPeer, UNO_QUERY );
180 : // !_BOTH_ MUST BE VALID!
181 : DBG_ASSERT( (_xPeer.is() && _xPeerWindow.is()), "### no peer!" );
182 :
183 0 : _xParentWindow->addFocusListener( this );
184 0 : _xPeerWindow->setPosSize( _nX, _nY, _nWidth, _nHeight, _nFlags );
185 0 : _xPeerWindow->setEnable( _bEnable );
186 0 : _xPeerWindow->setVisible( _bVisible && !_bInDesignMode );
187 : }
188 : else
189 : {
190 : OSL_FAIL( "### cannot get implementation of parent peer!" );
191 : }
192 :
193 0 : getMultiplexer()->setPeer( _xPeerWindow );
194 : }
195 :
196 : //---- ::com::sun::star::awt::XControl ------------------------------------------------------------------------------------
197 0 : void PluginControl_Impl::setDesignMode( sal_Bool bOn )
198 : throw( RuntimeException, std::exception )
199 : {
200 0 : _bInDesignMode = bOn;
201 0 : if (_xPeerWindow.is())
202 0 : _xPeerWindow->setVisible( _bVisible && !_bInDesignMode );
203 0 : }
204 :
205 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
206 0 : void PluginControl_Impl::addPaintListener( const Reference< ::com::sun::star::awt::XPaintListener > & l )
207 : throw( RuntimeException, std::exception )
208 : {
209 0 : getMultiplexer()->advise( cppu::UnoType<com::sun::star::awt::XPaintListener>::get(), l );
210 0 : }
211 :
212 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
213 0 : void PluginControl_Impl::removePaintListener( const Reference< ::com::sun::star::awt::XPaintListener > & l )
214 : throw( RuntimeException, std::exception )
215 : {
216 0 : getMultiplexer()->unadvise( cppu::UnoType<com::sun::star::awt::XPaintListener>::get(), l );
217 0 : }
218 :
219 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
220 0 : void PluginControl_Impl::addWindowListener( const Reference< ::com::sun::star::awt::XWindowListener > & l )
221 : throw( RuntimeException, std::exception )
222 : {
223 0 : getMultiplexer()->advise( cppu::UnoType<com::sun::star::awt::XWindowListener>::get(), l );
224 0 : }
225 :
226 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
227 0 : void PluginControl_Impl::removeWindowListener( const Reference< ::com::sun::star::awt::XWindowListener > & l )
228 : throw( RuntimeException, std::exception )
229 : {
230 0 : getMultiplexer()->unadvise( cppu::UnoType<com::sun::star::awt::XWindowListener>::get(), l );
231 0 : }
232 :
233 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
234 0 : void PluginControl_Impl::addFocusListener( const Reference< ::com::sun::star::awt::XFocusListener > & l )
235 : throw( RuntimeException, std::exception )
236 : {
237 0 : getMultiplexer()->advise( cppu::UnoType<com::sun::star::awt::XFocusListener>::get(), l );
238 0 : }
239 :
240 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
241 0 : void PluginControl_Impl::removeFocusListener( const Reference< ::com::sun::star::awt::XFocusListener > & l )
242 : throw( RuntimeException, std::exception )
243 : {
244 0 : getMultiplexer()->unadvise( cppu::UnoType<com::sun::star::awt::XFocusListener>::get(), l );
245 0 : }
246 :
247 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
248 0 : void PluginControl_Impl::addKeyListener( const Reference< ::com::sun::star::awt::XKeyListener > & l )
249 : throw( RuntimeException, std::exception )
250 : {
251 0 : getMultiplexer()->advise( cppu::UnoType<com::sun::star::awt::XKeyListener>::get(), l );
252 0 : }
253 :
254 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
255 0 : void PluginControl_Impl::removeKeyListener( const Reference< ::com::sun::star::awt::XKeyListener > & l )
256 : throw( RuntimeException, std::exception )
257 : {
258 0 : getMultiplexer()->unadvise( cppu::UnoType<com::sun::star::awt::XKeyListener>::get(), l );
259 0 : }
260 :
261 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
262 0 : void PluginControl_Impl::addMouseListener( const Reference< ::com::sun::star::awt::XMouseListener > & l )
263 : throw( RuntimeException, std::exception )
264 : {
265 0 : getMultiplexer()->advise( cppu::UnoType<com::sun::star::awt::XMouseListener>::get(), l );
266 0 : }
267 :
268 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
269 0 : void PluginControl_Impl::removeMouseListener( const Reference< ::com::sun::star::awt::XMouseListener > & l )
270 : throw( RuntimeException, std::exception )
271 : {
272 0 : getMultiplexer()->unadvise( cppu::UnoType<com::sun::star::awt::XMouseListener>::get(), l );
273 0 : }
274 :
275 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
276 0 : void PluginControl_Impl::addMouseMotionListener( const Reference< ::com::sun::star::awt::XMouseMotionListener > & l )
277 : throw( RuntimeException, std::exception )
278 : {
279 0 : getMultiplexer()->advise( cppu::UnoType<com::sun::star::awt::XMouseMotionListener>::get(), l );
280 0 : }
281 :
282 : //---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
283 0 : void PluginControl_Impl::removeMouseMotionListener( const Reference< ::com::sun::star::awt::XMouseMotionListener > & l )
284 : throw( RuntimeException, std::exception )
285 : {
286 0 : getMultiplexer()->unadvise( cppu::UnoType<com::sun::star::awt::XMouseMotionListener>::get(), l );
287 0 : }
288 :
289 :
290 : //---- ::com::sun::star::awt::XView ---------------------------------------------------------------------------------------
291 0 : void PluginControl_Impl::draw( sal_Int32 /*x*/, sal_Int32 /*y*/ )
292 : throw( RuntimeException, std::exception )
293 : {
294 : // has to be done by further implementation of control
295 0 : }
296 :
297 : //---- ::com::sun::star::awt::XView ---------------------------------------------------------------------------------------
298 0 : void PluginControl_Impl::setZoom( float /*ZoomX*/, float /*ZoomY*/ )
299 : throw( RuntimeException, std::exception )
300 : {
301 : // has to be done by further implementation of control
302 0 : }
303 :
304 : //---- ::com::sun::star::lang::XEventListener ------------------------------------------------------------------------------
305 0 : void PluginControl_Impl::disposing( const ::com::sun::star::lang::EventObject & /*rSource*/ )
306 : throw( RuntimeException, std::exception )
307 : {
308 0 : }
309 : //---- ::com::sun::star::awt::XFocusListener ------------------------------------------------------------------------------
310 0 : void PluginControl_Impl::focusGained( const ::com::sun::star::awt::FocusEvent & /*rEvt*/ )
311 : throw( RuntimeException, std::exception )
312 : {
313 0 : if (_xPeerWindow.is())
314 0 : _xPeerWindow->setFocus();
315 0 : }
316 : //---- ::com::sun::star::awt::XFocusListener ------------------------------------------------------------------------------
317 0 : void PluginControl_Impl::focusLost( const ::com::sun::star::awt::FocusEvent & /*rEvt*/ )
318 : throw( RuntimeException, std::exception )
319 : {
320 0 : }
321 :
322 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|