Update ooo320-m1
[ooovba.git] / extensions / workben / testframecontrol.cxx
blobc16f626a1dbfb657bd17c5754027032362d76c93
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testframecontrol.cxx,v $
10 * $Revision: 1.6 $
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"
34 //#include <vos/mutex.hxx>
35 #include <vos/dynload.hxx>
37 #include <vcl/wrkwin.hxx>
38 #include <vcl/svapp.hxx>
40 #include <stardiv/uno/repos/implementationregistration.hxx>
41 #include <stardiv/uno/repos/serinfo.hxx>
42 #include <stardiv/uno/awt/vcllstnr.hxx>
43 #include <stardiv/uno/awt/device.hxx>
44 #include <stardiv/uno/awt/graphics.hxx>
45 #include <stardiv/uno/awt/vclwin.hxx>
47 #include <usr/services.hxx>
49 #include <svtools/unoiface.hxx>
51 using namespace vos;
52 using namespace usr;
54 //==================================================================================================
55 class Listener_Impl
56 : public UsrObject
57 , public XMouseListener
58 , public XMouseMotionListener
59 , public XKeyListener
60 , public XWindowListener
61 , public XFocusListener
62 , public XPaintListener
64 public:
65 SMART_UNO_DECLARATION( Listener_Impl, UsrObject );
67 virtual BOOL queryInterface( Uik aUik, XInterfaceRef& rOut );
69 // XMouseListener
70 virtual void mousePressed( const VclMouseEvent& evt );
71 virtual void mouseReleased( const VclMouseEvent& evt );
72 virtual void mouseEntered( const VclMouseEvent& evt );
73 virtual void mouseExited( const VclMouseEvent& evt );
75 // XMouseMotionListener
76 virtual void mouseDragged( const VclMouseEvent& evt );
77 virtual void mouseMoved( const VclMouseEvent& evt );
79 // XKeyListener
80 virtual void keyPressed( const VclKeyEvent& evt );
81 virtual void keyReleased( const VclKeyEvent& evt );
83 // XFocusListener
84 virtual void focusGained( const FocusEvent& evt );
85 virtual void focusLost( const FocusEvent& evt );
87 // XWindowListener
88 virtual void windowResized( const WindowEvent& evt );
89 virtual void windowMoved( const WindowEvent& evt );
90 virtual void windowShown( const EventObject& evt );
91 virtual void windowHidden( const EventObject& evt );
93 // XPaintListener
94 virtual void windowPaint( const PaintEvent& evt );
96 // XEventListener
97 virtual void disposing( const EventObject& evt );
99 public:
100 void addAllListeners( const XControlRef& xControl );
101 void removeAllListeners( const XControlRef& xControl );
104 //--------------------------------------------------------------------------------------------------
105 void Listener_Impl::addAllListeners( const XControlRef& xControl )
107 XWindowRef xWindow( xControl, USR_QUERY );
109 xWindow->addMouseListener( (XMouseListener*)this );
110 xWindow->addMouseMotionListener( (XMouseMotionListener*)this );
111 xWindow->addKeyListener( (XKeyListener*)this );
112 xWindow->addFocusListener( (XFocusListener*)this );
113 xWindow->addWindowListener( (XWindowListener*)this );
114 xWindow->addPaintListener( (XPaintListener*)this );
115 // cast due to ambiguities
116 xControl->addEventListener( (XEventListener*)(XPaintListener*)this );
119 //--------------------------------------------------------------------------------------------------
120 void Listener_Impl::removeAllListeners( const XControlRef& xControl )
122 XWindowRef xWindow( xControl, USR_QUERY );
124 xWindow->removeMouseListener( (XMouseListener*)this );
125 xWindow->removeMouseMotionListener( (XMouseMotionListener*)this );
126 xWindow->removeKeyListener( (XKeyListener*)this );
127 xWindow->removeFocusListener( (XFocusListener*)this );
128 xWindow->removeWindowListener( (XWindowListener*)this );
129 xWindow->removePaintListener( (XPaintListener*)this );
130 // cast due to ambiguities
131 xControl->removeEventListener( (XEventListener*)(XPaintListener*)this );
134 //--------------------------------------------------------------------------------------------------
135 SMART_UNO_IMPLEMENTATION( Listener_Impl, UsrObject );
137 //--------------------------------------------------------------------------------------------------
138 BOOL Listener_Impl::queryInterface( Uik aUik, XInterfaceRef& rOut )
140 if (aUik == XMouseListener::getSmartUik())
141 rOut = (XMouseListener*)this;
142 else if (aUik == XMouseMotionListener::getSmartUik())
143 rOut = (XMouseMotionListener*)this;
144 else if (aUik == XWindowListener::getSmartUik())
145 rOut = (XWindowListener*)this;
146 else if (aUik == XFocusListener::getSmartUik())
147 rOut = (XFocusListener*)this;
148 else if (aUik == XKeyListener::getSmartUik())
149 rOut = (XKeyListener*)this;
150 else if (aUik == XPaintListener::getSmartUik())
151 rOut = (XPaintListener*)this;
152 else if (aUik == ((XEventListener*)NULL)->getSmartUik())
153 rOut = (XEventListener*)(XMouseListener*)this;
154 else
155 return UsrObject::queryInterface( aUik, rOut );
157 return TRUE;
160 //--------------------------------------------------------------------------------------------------
161 // XMouseListener
162 void Listener_Impl::mousePressed( const VclMouseEvent& evt ) {}
163 void Listener_Impl::mouseReleased( const VclMouseEvent& evt ) {}
164 void Listener_Impl::mouseEntered( const VclMouseEvent& evt ) {}
165 void Listener_Impl::mouseExited( const VclMouseEvent& evt ) {}
167 // XMouseMotionListener
168 void Listener_Impl::mouseDragged( const VclMouseEvent& evt ) {}
169 void Listener_Impl::mouseMoved( const VclMouseEvent& evt ) {}
171 // XKeyListener
172 void Listener_Impl::keyPressed( const VclKeyEvent& evt ) {}
173 void Listener_Impl::keyReleased( const VclKeyEvent& evt ) {}
175 // XFocusListener
176 void Listener_Impl::focusGained( const FocusEvent& evt ) {}
177 void Listener_Impl::focusLost( const FocusEvent& evt ) {}
179 // XWindowListener
180 void Listener_Impl::windowResized( const WindowEvent& evt ) {}
181 void Listener_Impl::windowMoved( const WindowEvent& evt ) {}
182 void Listener_Impl::windowShown( const EventObject& evt ) {}
183 void Listener_Impl::windowHidden( const EventObject& evt ) {}
185 // XPaintListener
186 void Listener_Impl::windowPaint( const PaintEvent& evt )
188 if (evt.Source.is())
190 XControlRef xControl( evt.Source, USR_QUERY );
191 if (xControl.is())
193 XDeviceRef xDev( xControl->getPeer(), USR_QUERY );
194 XGraphicsRef xGraphics = xDev->createGraphics();
195 xGraphics->drawLine( 0, 0, 200, 200 );
196 xGraphics->drawLine( 200, 0, 0, 200 );
201 // XEventListener
202 void Listener_Impl::disposing( const EventObject& evt ) {}
205 //==================================================================================================
206 class FrameControlApplication
207 : public Application
209 public:
210 virtual void Main();
211 virtual void ShowStatusText( const XubString& rText );
213 public:
214 FrameControlApplication() {}
216 private:
217 void init();
218 void deinit();
220 private:
221 Listener_Impl* _pListener;
222 XControlRef _xControl;
224 WorkWindow* _pWorkWin;
227 FrameControlApplication g_App;
229 #ifdef __MWERKS__
230 Application* pApp = &g_App;
231 #endif
234 //--------------------------------------------------------------------------------------------------
235 void FrameControlApplication::init()
237 XMultiServiceFactoryRef xMgr = createRegistryServiceManager( L"test.rdb" );
238 registerUsrServices( xMgr );
239 setProcessServiceManager( xMgr );
240 InitExtVclToolkit();
241 Application::RegisterUnoServices();
243 XServiceRegistryRef xRegMgr(xMgr, USR_QUERY);
245 XImplementationRegistrationRef xIR( xMgr->createInstance(L"stardiv.uno.repos.ImplementationRegistration"), USR_QUERY );
248 char szDllName[_MAX_PATH]="";
250 ORealDynamicLoader::computeModuleName("fc", szDllName, _MAX_PATH);
251 UString aFCDllName = StringToOUString(szDllName, CHARSET_SYSTEM);
252 xIR->registerImplementation(L"stardiv.loader.SharedLibrary", aFCDllName, XSimpleRegistryRef() );
254 catch( CannotRegisterImplementationException& e )
260 // ...
262 XInterfaceRef xInst = xMgr->createInstance( L"stardiv.one.frame.FrameControl" );
263 if (xInst->queryInterface( XControl::getSmartUik(), _xControl ))
265 _pWorkWin = new WorkWindow( NULL, WB_APP | WB_STDWORK );
266 _pWorkWin->Show();
267 XWindowPeerRef xParent( _pWorkWin->GetComponentInterface() );
269 XToolkitRef xToolkit( xMgr->createInstance( L"stardiv.vcl.VclToolkit" ), USR_QUERY );
270 //xToolkit = XToolkitRef( xMgr->createInstance( L"stardiv.uno.awt.Toolkit" ), USR_QUERY );
271 _xControl->createPeer( xToolkit, xParent );
272 XWindowRef xWin( _xControl, USR_QUERY );
273 xWin->setPosSize( 50, 50, 400, 400, PosSize_POSSIZE );
274 xWin->setVisible( TRUE );
276 _pListener = new Listener_Impl();
277 _pListener->acquire();
278 _pListener->addAllListeners( _xControl );
279 // ... on paint a cross should be drawn
283 //--------------------------------------------------------------------------------------------------
284 void FrameControlApplication::deinit()
286 if (_pListener)
289 _pListener->removeAllListeners( _xControl );
290 _xControl->dispose(); // disposing event should occur
291 _pListener->release();
292 _pListener = NULL;
294 _xControl = XControlRef();
297 _pWorkWin->Hide();
298 delete _pWorkWin;
302 //--------------------------------------------------------------------------------------------------
303 void FrameControlApplication::Main()
305 // void TestErrcodes();
306 // TestErrcodes();
308 EnterMultiThread();
309 SetAppName( "RadioActiveControl-Demo" );
310 EnableSVLook();
312 init();
314 Execute();
316 deinit();
319 //--------------------------------------------------------------------------------------------------
320 void FrameControlApplication::ShowStatusText( const XubString& rStatus )
322 Application::GetAppWindow()->SetText( rStatus );