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