Branch libreoffice-5-0-4
[LibreOffice.git] / extensions / workben / testframecontrol.cxx
blob5cfa08c2c2a5fea4b9517a29a713a99faddfbe40
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <vcl/wrkwin.hxx>
22 #include <vcl/svapp.hxx>
24 #include <stardiv/uno/repos/implementationregistration.hxx>
25 #include <stardiv/uno/repos/serinfo.hxx>
26 #include <stardiv/uno/awt/vcllstnr.hxx>
27 #include <stardiv/uno/awt/device.hxx>
28 #include <stardiv/uno/awt/graphics.hxx>
29 #include <stardiv/uno/awt/vclwin.hxx>
31 #include <usr/services.hxx>
33 #include <svtools/unoiface.hxx>
35 using namespace usr;
38 class Listener_Impl
39 : public UsrObject
40 , public XMouseListener
41 , public XMouseMotionListener
42 , public XKeyListener
43 , public XWindowListener
44 , public XFocusListener
45 , public XPaintListener
47 public:
48 SMART_UNO_DECLARATION( Listener_Impl, UsrObject );
50 virtual BOOL queryInterface( Uik aUik, XInterfaceRef& rOut );
52 // XMouseListener
53 virtual void mousePressed( const VclMouseEvent& evt );
54 virtual void mouseReleased( const VclMouseEvent& evt );
55 virtual void mouseEntered( const VclMouseEvent& evt );
56 virtual void mouseExited( const VclMouseEvent& evt );
58 // XMouseMotionListener
59 virtual void mouseDragged( const VclMouseEvent& evt );
60 virtual void mouseMoved( const VclMouseEvent& evt );
62 // XKeyListener
63 virtual void keyPressed( const VclKeyEvent& evt );
64 virtual void keyReleased( const VclKeyEvent& evt );
66 // XFocusListener
67 virtual void focusGained( const FocusEvent& evt );
68 virtual void focusLost( const FocusEvent& evt );
70 // XWindowListener
71 virtual void windowResized( const WindowEvent& evt );
72 virtual void windowMoved( const WindowEvent& evt );
73 virtual void windowShown( const EventObject& evt );
74 virtual void windowHidden( const EventObject& evt );
76 // XPaintListener
77 virtual void windowPaint( const PaintEvent& evt );
79 // XEventListener
80 virtual void disposing( const EventObject& evt );
82 public:
83 void addAllListeners( const XControlRef& xControl );
84 void removeAllListeners( const XControlRef& xControl );
88 void Listener_Impl::addAllListeners( const XControlRef& xControl )
90 XWindowRef xWindow( xControl, USR_QUERY );
92 xWindow->addMouseListener( (XMouseListener*)this );
93 xWindow->addMouseMotionListener( (XMouseMotionListener*)this );
94 xWindow->addKeyListener( (XKeyListener*)this );
95 xWindow->addFocusListener( (XFocusListener*)this );
96 xWindow->addWindowListener( (XWindowListener*)this );
97 xWindow->addPaintListener( (XPaintListener*)this );
98 // cast due to ambiguities
99 xControl->addEventListener( (XEventListener*)(XPaintListener*)this );
103 void Listener_Impl::removeAllListeners( const XControlRef& xControl )
105 XWindowRef xWindow( xControl, USR_QUERY );
107 xWindow->removeMouseListener( (XMouseListener*)this );
108 xWindow->removeMouseMotionListener( (XMouseMotionListener*)this );
109 xWindow->removeKeyListener( (XKeyListener*)this );
110 xWindow->removeFocusListener( (XFocusListener*)this );
111 xWindow->removeWindowListener( (XWindowListener*)this );
112 xWindow->removePaintListener( (XPaintListener*)this );
113 // cast due to ambiguities
114 xControl->removeEventListener( (XEventListener*)(XPaintListener*)this );
118 SMART_UNO_IMPLEMENTATION( Listener_Impl, UsrObject );
121 BOOL Listener_Impl::queryInterface( Uik aUik, XInterfaceRef& rOut )
123 if (aUik == XMouseListener::getSmartUik())
124 rOut = (XMouseListener*)this;
125 else if (aUik == XMouseMotionListener::getSmartUik())
126 rOut = (XMouseMotionListener*)this;
127 else if (aUik == XWindowListener::getSmartUik())
128 rOut = (XWindowListener*)this;
129 else if (aUik == XFocusListener::getSmartUik())
130 rOut = (XFocusListener*)this;
131 else if (aUik == XKeyListener::getSmartUik())
132 rOut = (XKeyListener*)this;
133 else if (aUik == XPaintListener::getSmartUik())
134 rOut = (XPaintListener*)this;
135 else if (aUik == ((XEventListener*)NULL)->getSmartUik())
136 rOut = (XEventListener*)(XMouseListener*)this;
137 else
138 return UsrObject::queryInterface( aUik, rOut );
140 return TRUE;
144 // XMouseListener
145 void Listener_Impl::mousePressed( const VclMouseEvent& evt ) {}
146 void Listener_Impl::mouseReleased( const VclMouseEvent& evt ) {}
147 void Listener_Impl::mouseEntered( const VclMouseEvent& evt ) {}
148 void Listener_Impl::mouseExited( const VclMouseEvent& evt ) {}
150 // XMouseMotionListener
151 void Listener_Impl::mouseDragged( const VclMouseEvent& evt ) {}
152 void Listener_Impl::mouseMoved( const VclMouseEvent& evt ) {}
154 // XKeyListener
155 void Listener_Impl::keyPressed( const VclKeyEvent& evt ) {}
156 void Listener_Impl::keyReleased( const VclKeyEvent& evt ) {}
158 // XFocusListener
159 void Listener_Impl::focusGained( const FocusEvent& evt ) {}
160 void Listener_Impl::focusLost( const FocusEvent& evt ) {}
162 // XWindowListener
163 void Listener_Impl::windowResized( const WindowEvent& evt ) {}
164 void Listener_Impl::windowMoved( const WindowEvent& evt ) {}
165 void Listener_Impl::windowShown( const EventObject& evt ) {}
166 void Listener_Impl::windowHidden( const EventObject& evt ) {}
168 // XPaintListener
169 void Listener_Impl::windowPaint( const PaintEvent& evt )
171 if (evt.Source.is())
173 XControlRef xControl( evt.Source, USR_QUERY );
174 if (xControl.is())
176 XDeviceRef xDev( xControl->getPeer(), USR_QUERY );
177 XGraphicsRef xGraphics = xDev->createGraphics();
178 xGraphics->drawLine( 0, 0, 200, 200 );
179 xGraphics->drawLine( 200, 0, 0, 200 );
184 // XEventListener
185 void Listener_Impl::disposing( const EventObject& evt ) {}
189 class FrameControlApplication
190 : public Application
192 public:
193 virtual void Main();
195 public:
196 FrameControlApplication() {}
198 private:
199 void init();
200 void deinit();
202 private:
203 Listener_Impl* _pListener;
204 XControlRef _xControl;
206 WorkWindow* _pWorkWin;
209 FrameControlApplication g_App;
212 void FrameControlApplication::init()
214 XMultiServiceFactoryRef xMgr = createRegistryServiceManager( L"test.rdb" );
215 registerUsrServices( xMgr );
216 setProcessServiceManager( xMgr );
217 InitExtVclToolkit();
218 Application::RegisterUnoServices();
220 XServiceRegistryRef xRegMgr(xMgr, USR_QUERY);
222 XImplementationRegistrationRef xIR( xMgr->createInstance(L"stardiv.uno.repos.ImplementationRegistration"), USR_QUERY );
225 char szDllName[_MAX_PATH]="";
227 ORealDynamicLoader::computeModuleName("fc", szDllName, _MAX_PATH);
228 UString aFCDllName = StringToOUString(szDllName, CHARSET_SYSTEM);
229 xIR->registerImplementation(L"stardiv.loader.SharedLibrary", aFCDllName, XSimpleRegistryRef() );
231 catch( CannotRegisterImplementationException& e )
239 XInterfaceRef xInst = xMgr->createInstance( L"stardiv.one.frame.FrameControl" );
240 if (xInst->queryInterface( XControl::getSmartUik(), _xControl ))
242 _pWorkWin = VclPtr<WorkWindow>::Create( nullptr, WB_APP | WB_STDWORK );
243 _pWorkWin->Show();
244 XWindowPeerRef xParent( _pWorkWin->GetComponentInterface() );
246 XToolkitRef xToolkit( xMgr->createInstance( L"stardiv.vcl.VclToolkit" ), USR_QUERY );
247 //xToolkit = XToolkitRef( xMgr->createInstance( L"stardiv.uno.awt.Toolkit" ), USR_QUERY );
248 _xControl->createPeer( xToolkit, xParent );
249 XWindowRef xWin( _xControl, USR_QUERY );
250 xWin->setPosSize( 50, 50, 400, 400, PosSize_POSSIZE );
251 xWin->setVisible( TRUE );
253 _pListener = new Listener_Impl();
254 _pListener->acquire();
255 _pListener->addAllListeners( _xControl );
256 // ... on paint a cross should be drawn
261 void FrameControlApplication::deinit()
263 if (_pListener)
266 _pListener->removeAllListeners( _xControl );
267 _xControl->dispose(); // disposing event should occur
268 _pListener->release();
269 _pListener = NULL;
271 _xControl = XControlRef();
274 _pWorkWin->Hide();
275 delete _pWorkWin;
280 void FrameControlApplication::Main()
282 // void TestErrcodes();
283 // TestErrcodes();
285 EnterMultiThread();
286 SetAppName( "RadioActiveControl-Demo" );
287 EnableSVLook();
289 init();
291 Execute();
293 deinit();
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */