1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_extensions.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir //#include <vos/mutex.hxx>
32*cdf0e10cSrcweir #include <vos/dynload.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
35*cdf0e10cSrcweir #include <vcl/svapp.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <stardiv/uno/repos/implementationregistration.hxx>
38*cdf0e10cSrcweir #include <stardiv/uno/repos/serinfo.hxx>
39*cdf0e10cSrcweir #include <stardiv/uno/awt/vcllstnr.hxx>
40*cdf0e10cSrcweir #include <stardiv/uno/awt/device.hxx>
41*cdf0e10cSrcweir #include <stardiv/uno/awt/graphics.hxx>
42*cdf0e10cSrcweir #include <stardiv/uno/awt/vclwin.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include <usr/services.hxx>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include <svtools/unoiface.hxx>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir using namespace vos;
49*cdf0e10cSrcweir using namespace usr;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir //==================================================================================================
52*cdf0e10cSrcweir class Listener_Impl
53*cdf0e10cSrcweir 	: public UsrObject
54*cdf0e10cSrcweir 	, public XMouseListener
55*cdf0e10cSrcweir 	, public XMouseMotionListener
56*cdf0e10cSrcweir 	, public XKeyListener
57*cdf0e10cSrcweir 	, public XWindowListener
58*cdf0e10cSrcweir 	, public XFocusListener
59*cdf0e10cSrcweir 	, public XPaintListener
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir public:
62*cdf0e10cSrcweir 	SMART_UNO_DECLARATION( Listener_Impl, UsrObject );
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 	virtual BOOL		queryInterface( Uik aUik, XInterfaceRef& rOut );
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 	// XMouseListener
67*cdf0e10cSrcweir 	virtual void		mousePressed( const VclMouseEvent& evt );
68*cdf0e10cSrcweir 	virtual void		mouseReleased( const VclMouseEvent& evt );
69*cdf0e10cSrcweir 	virtual void		mouseEntered( const VclMouseEvent& evt );
70*cdf0e10cSrcweir 	virtual void		mouseExited( const VclMouseEvent& evt );
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 	// XMouseMotionListener
73*cdf0e10cSrcweir 	virtual void		mouseDragged( const VclMouseEvent& evt );
74*cdf0e10cSrcweir 	virtual void		mouseMoved( const VclMouseEvent& evt );
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	// XKeyListener
77*cdf0e10cSrcweir 	virtual void		keyPressed( const VclKeyEvent& evt );
78*cdf0e10cSrcweir 	virtual void		keyReleased( const VclKeyEvent& evt );
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	// XFocusListener
81*cdf0e10cSrcweir 	virtual void		focusGained( const FocusEvent& evt );
82*cdf0e10cSrcweir 	virtual void		focusLost( const FocusEvent& evt );
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	// XWindowListener
85*cdf0e10cSrcweir 	virtual void		windowResized( const WindowEvent& evt );
86*cdf0e10cSrcweir 	virtual void		windowMoved( const WindowEvent& evt );
87*cdf0e10cSrcweir 	virtual void		windowShown( const EventObject& evt );
88*cdf0e10cSrcweir 	virtual void		windowHidden( const EventObject& evt );
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	// XPaintListener
91*cdf0e10cSrcweir 	virtual void		windowPaint( const PaintEvent& evt );
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	// XEventListener
94*cdf0e10cSrcweir 	virtual void		disposing( const EventObject& evt );
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir public:
97*cdf0e10cSrcweir 	void				addAllListeners( const XControlRef& xControl );
98*cdf0e10cSrcweir 	void				removeAllListeners( const XControlRef& xControl );
99*cdf0e10cSrcweir };
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
102*cdf0e10cSrcweir void Listener_Impl::addAllListeners( const XControlRef& xControl )
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir 	XWindowRef xWindow( xControl, USR_QUERY );
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 	xWindow->addMouseListener( (XMouseListener*)this );
107*cdf0e10cSrcweir 	xWindow->addMouseMotionListener( (XMouseMotionListener*)this );
108*cdf0e10cSrcweir 	xWindow->addKeyListener( (XKeyListener*)this );
109*cdf0e10cSrcweir 	xWindow->addFocusListener( (XFocusListener*)this );
110*cdf0e10cSrcweir 	xWindow->addWindowListener( (XWindowListener*)this );
111*cdf0e10cSrcweir 	xWindow->addPaintListener( (XPaintListener*)this );
112*cdf0e10cSrcweir 	// cast due to ambiguities
113*cdf0e10cSrcweir 	xControl->addEventListener( (XEventListener*)(XPaintListener*)this );
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
117*cdf0e10cSrcweir void Listener_Impl::removeAllListeners( const XControlRef& xControl )
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir 	XWindowRef xWindow( xControl, USR_QUERY );
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 	xWindow->removeMouseListener( (XMouseListener*)this );
122*cdf0e10cSrcweir 	xWindow->removeMouseMotionListener( (XMouseMotionListener*)this );
123*cdf0e10cSrcweir 	xWindow->removeKeyListener( (XKeyListener*)this );
124*cdf0e10cSrcweir 	xWindow->removeFocusListener( (XFocusListener*)this );
125*cdf0e10cSrcweir 	xWindow->removeWindowListener( (XWindowListener*)this );
126*cdf0e10cSrcweir 	xWindow->removePaintListener( (XPaintListener*)this );
127*cdf0e10cSrcweir 	// cast due to ambiguities
128*cdf0e10cSrcweir 	xControl->removeEventListener( (XEventListener*)(XPaintListener*)this );
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
132*cdf0e10cSrcweir SMART_UNO_IMPLEMENTATION( Listener_Impl, UsrObject );
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
135*cdf0e10cSrcweir BOOL Listener_Impl::queryInterface( Uik aUik, XInterfaceRef& rOut )
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir 	if (aUik == XMouseListener::getSmartUik())
138*cdf0e10cSrcweir 		rOut = (XMouseListener*)this;
139*cdf0e10cSrcweir 	else if (aUik == XMouseMotionListener::getSmartUik())
140*cdf0e10cSrcweir 		rOut = (XMouseMotionListener*)this;
141*cdf0e10cSrcweir 	else if (aUik == XWindowListener::getSmartUik())
142*cdf0e10cSrcweir 		rOut = (XWindowListener*)this;
143*cdf0e10cSrcweir 	else if (aUik == XFocusListener::getSmartUik())
144*cdf0e10cSrcweir 		rOut = (XFocusListener*)this;
145*cdf0e10cSrcweir 	else if (aUik == XKeyListener::getSmartUik())
146*cdf0e10cSrcweir 		rOut = (XKeyListener*)this;
147*cdf0e10cSrcweir 	else if (aUik == XPaintListener::getSmartUik())
148*cdf0e10cSrcweir 		rOut = (XPaintListener*)this;
149*cdf0e10cSrcweir 	else if (aUik == ((XEventListener*)NULL)->getSmartUik())
150*cdf0e10cSrcweir 		rOut = (XEventListener*)(XMouseListener*)this;
151*cdf0e10cSrcweir 	else
152*cdf0e10cSrcweir 		return UsrObject::queryInterface( aUik, rOut );
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 	return TRUE;
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
158*cdf0e10cSrcweir // XMouseListener
159*cdf0e10cSrcweir void Listener_Impl::mousePressed( const VclMouseEvent& evt )	{}
160*cdf0e10cSrcweir void Listener_Impl::mouseReleased( const VclMouseEvent& evt )	{}
161*cdf0e10cSrcweir void Listener_Impl::mouseEntered( const VclMouseEvent& evt )	{}
162*cdf0e10cSrcweir void Listener_Impl::mouseExited( const VclMouseEvent& evt )		{}
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir // XMouseMotionListener
165*cdf0e10cSrcweir void Listener_Impl::mouseDragged( const VclMouseEvent& evt )	{}
166*cdf0e10cSrcweir void Listener_Impl::mouseMoved( const VclMouseEvent& evt )		{}
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir // XKeyListener
169*cdf0e10cSrcweir void Listener_Impl::keyPressed( const VclKeyEvent& evt )		{}
170*cdf0e10cSrcweir void Listener_Impl::keyReleased( const VclKeyEvent& evt )		{}
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir // XFocusListener
173*cdf0e10cSrcweir void Listener_Impl::focusGained( const FocusEvent& evt )		{}
174*cdf0e10cSrcweir void Listener_Impl::focusLost( const FocusEvent& evt )			{}
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir // XWindowListener
177*cdf0e10cSrcweir void Listener_Impl::windowResized( const WindowEvent& evt )		{}
178*cdf0e10cSrcweir void Listener_Impl::windowMoved( const WindowEvent& evt )		{}
179*cdf0e10cSrcweir void Listener_Impl::windowShown( const EventObject& evt )		{}
180*cdf0e10cSrcweir void Listener_Impl::windowHidden( const EventObject& evt )		{}
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir // XPaintListener
183*cdf0e10cSrcweir void Listener_Impl::windowPaint( const PaintEvent& evt )
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir 	if (evt.Source.is())
186*cdf0e10cSrcweir 	{
187*cdf0e10cSrcweir 		XControlRef xControl( evt.Source, USR_QUERY );
188*cdf0e10cSrcweir 		if (xControl.is())
189*cdf0e10cSrcweir 		{
190*cdf0e10cSrcweir 			XDeviceRef xDev( xControl->getPeer(), USR_QUERY );
191*cdf0e10cSrcweir 			XGraphicsRef xGraphics = xDev->createGraphics();
192*cdf0e10cSrcweir 			xGraphics->drawLine( 0, 0, 200, 200 );
193*cdf0e10cSrcweir 			xGraphics->drawLine( 200, 0, 0, 200 );
194*cdf0e10cSrcweir 		}
195*cdf0e10cSrcweir 	}
196*cdf0e10cSrcweir }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir // XEventListener
199*cdf0e10cSrcweir void Listener_Impl::disposing( const EventObject& evt )		{}
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir //==================================================================================================
203*cdf0e10cSrcweir class FrameControlApplication
204*cdf0e10cSrcweir 	: public Application
205*cdf0e10cSrcweir {
206*cdf0e10cSrcweir public:
207*cdf0e10cSrcweir     virtual void        Main();
208*cdf0e10cSrcweir     virtual void        ShowStatusText( const XubString& rText );
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir public:
211*cdf0e10cSrcweir 						FrameControlApplication()		{}
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir private:
214*cdf0e10cSrcweir 	void				init();
215*cdf0e10cSrcweir 	void				deinit();
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir private:
218*cdf0e10cSrcweir 	Listener_Impl*		_pListener;
219*cdf0e10cSrcweir 	XControlRef			_xControl;
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 	WorkWindow*			_pWorkWin;
222*cdf0e10cSrcweir };
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir FrameControlApplication g_App;
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir #ifdef __MWERKS__
227*cdf0e10cSrcweir Application* pApp = &g_App;
228*cdf0e10cSrcweir #endif
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
232*cdf0e10cSrcweir void FrameControlApplication::init()
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir 	XMultiServiceFactoryRef xMgr = createRegistryServiceManager( L"test.rdb" );
235*cdf0e10cSrcweir 	registerUsrServices( xMgr );
236*cdf0e10cSrcweir 	setProcessServiceManager( xMgr );
237*cdf0e10cSrcweir 	InitExtVclToolkit();
238*cdf0e10cSrcweir 	Application::RegisterUnoServices();
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 	XServiceRegistryRef xRegMgr(xMgr, USR_QUERY);
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 	XImplementationRegistrationRef xIR( xMgr->createInstance(L"stardiv.uno.repos.ImplementationRegistration"), USR_QUERY );
243*cdf0e10cSrcweir 	try
244*cdf0e10cSrcweir 	{
245*cdf0e10cSrcweir 		char szDllName[_MAX_PATH]="";
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 		ORealDynamicLoader::computeModuleName("fc", szDllName, _MAX_PATH);
248*cdf0e10cSrcweir 		UString aFCDllName = StringToOUString(szDllName, CHARSET_SYSTEM);
249*cdf0e10cSrcweir 		xIR->registerImplementation(L"stardiv.loader.SharedLibrary", aFCDllName, XSimpleRegistryRef() );
250*cdf0e10cSrcweir 	}
251*cdf0e10cSrcweir 	catch( CannotRegisterImplementationException& e )
252*cdf0e10cSrcweir 	{
253*cdf0e10cSrcweir 	}
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 	// ...
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 	XInterfaceRef xInst = xMgr->createInstance( L"stardiv.one.frame.FrameControl" );
260*cdf0e10cSrcweir 	if (xInst->queryInterface( XControl::getSmartUik(), _xControl ))
261*cdf0e10cSrcweir 	{
262*cdf0e10cSrcweir 		_pWorkWin = new WorkWindow( NULL, WB_APP | WB_STDWORK );
263*cdf0e10cSrcweir 		_pWorkWin->Show();
264*cdf0e10cSrcweir 		XWindowPeerRef xParent( _pWorkWin->GetComponentInterface() );
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 		XToolkitRef xToolkit( xMgr->createInstance( L"stardiv.vcl.VclToolkit" ), USR_QUERY );
267*cdf0e10cSrcweir 		//xToolkit = XToolkitRef( xMgr->createInstance( L"stardiv.uno.awt.Toolkit" ), USR_QUERY );
268*cdf0e10cSrcweir 		_xControl->createPeer( xToolkit, xParent );
269*cdf0e10cSrcweir 		XWindowRef xWin( _xControl, USR_QUERY );
270*cdf0e10cSrcweir 		xWin->setPosSize( 50, 50, 400, 400, PosSize_POSSIZE );
271*cdf0e10cSrcweir 		xWin->setVisible( TRUE );
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 		_pListener = new Listener_Impl();
274*cdf0e10cSrcweir 		_pListener->acquire();
275*cdf0e10cSrcweir 		_pListener->addAllListeners( _xControl );
276*cdf0e10cSrcweir 		// ... on paint a cross should be drawn
277*cdf0e10cSrcweir 	}
278*cdf0e10cSrcweir }
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
281*cdf0e10cSrcweir void FrameControlApplication::deinit()
282*cdf0e10cSrcweir {
283*cdf0e10cSrcweir 	if (_pListener)
284*cdf0e10cSrcweir 	{
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir 		_pListener->removeAllListeners( _xControl );
287*cdf0e10cSrcweir 		_xControl->dispose();	// disposing event should occur
288*cdf0e10cSrcweir 		_pListener->release();
289*cdf0e10cSrcweir 		_pListener = NULL;
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 		_xControl = XControlRef();
292*cdf0e10cSrcweir 	}
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 	_pWorkWin->Hide();
295*cdf0e10cSrcweir 	delete _pWorkWin;
296*cdf0e10cSrcweir }
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
300*cdf0e10cSrcweir void FrameControlApplication::Main()
301*cdf0e10cSrcweir {
302*cdf0e10cSrcweir //  	void TestErrcodes();
303*cdf0e10cSrcweir //  	TestErrcodes();
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 	EnterMultiThread();
306*cdf0e10cSrcweir 	SetAppName( "RadioActiveControl-Demo" );
307*cdf0e10cSrcweir 	EnableSVLook();
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 	init();
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 	Execute();
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir 	deinit();
314*cdf0e10cSrcweir }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
317*cdf0e10cSrcweir void FrameControlApplication::ShowStatusText( const XubString& rStatus )
318*cdf0e10cSrcweir {
319*cdf0e10cSrcweir 	Application::GetAppWindow()->SetText( rStatus );
320*cdf0e10cSrcweir }
321