1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
31 //#include <vos/mutex.hxx>
32 #include <vos/dynload.hxx>
34 #include <vcl/wrkwin.hxx>
35 #include <vcl/svapp.hxx>
37 #include <stardiv/uno/repos/implementationregistration.hxx>
38 #include <stardiv/uno/repos/serinfo.hxx>
39 #include <stardiv/uno/awt/vcllstnr.hxx>
40 #include <stardiv/uno/awt/device.hxx>
41 #include <stardiv/uno/awt/graphics.hxx>
42 #include <stardiv/uno/awt/vclwin.hxx>
44 #include <usr/services.hxx>
46 #include <svtools/unoiface.hxx>
51 //==================================================================================================
54 , public XMouseListener
55 , public XMouseMotionListener
57 , public XWindowListener
58 , public XFocusListener
59 , public XPaintListener
62 SMART_UNO_DECLARATION( Listener_Impl
, UsrObject
);
64 virtual BOOL
queryInterface( Uik aUik
, XInterfaceRef
& rOut
);
67 virtual void mousePressed( const VclMouseEvent
& evt
);
68 virtual void mouseReleased( const VclMouseEvent
& evt
);
69 virtual void mouseEntered( const VclMouseEvent
& evt
);
70 virtual void mouseExited( const VclMouseEvent
& evt
);
72 // XMouseMotionListener
73 virtual void mouseDragged( const VclMouseEvent
& evt
);
74 virtual void mouseMoved( const VclMouseEvent
& evt
);
77 virtual void keyPressed( const VclKeyEvent
& evt
);
78 virtual void keyReleased( const VclKeyEvent
& evt
);
81 virtual void focusGained( const FocusEvent
& evt
);
82 virtual void focusLost( const FocusEvent
& evt
);
85 virtual void windowResized( const WindowEvent
& evt
);
86 virtual void windowMoved( const WindowEvent
& evt
);
87 virtual void windowShown( const EventObject
& evt
);
88 virtual void windowHidden( const EventObject
& evt
);
91 virtual void windowPaint( const PaintEvent
& evt
);
94 virtual void disposing( const EventObject
& evt
);
97 void addAllListeners( const XControlRef
& xControl
);
98 void removeAllListeners( const XControlRef
& xControl
);
101 //--------------------------------------------------------------------------------------------------
102 void Listener_Impl::addAllListeners( const XControlRef
& xControl
)
104 XWindowRef
xWindow( xControl
, USR_QUERY
);
106 xWindow
->addMouseListener( (XMouseListener
*)this );
107 xWindow
->addMouseMotionListener( (XMouseMotionListener
*)this );
108 xWindow
->addKeyListener( (XKeyListener
*)this );
109 xWindow
->addFocusListener( (XFocusListener
*)this );
110 xWindow
->addWindowListener( (XWindowListener
*)this );
111 xWindow
->addPaintListener( (XPaintListener
*)this );
112 // cast due to ambiguities
113 xControl
->addEventListener( (XEventListener
*)(XPaintListener
*)this );
116 //--------------------------------------------------------------------------------------------------
117 void Listener_Impl::removeAllListeners( const XControlRef
& xControl
)
119 XWindowRef
xWindow( xControl
, USR_QUERY
);
121 xWindow
->removeMouseListener( (XMouseListener
*)this );
122 xWindow
->removeMouseMotionListener( (XMouseMotionListener
*)this );
123 xWindow
->removeKeyListener( (XKeyListener
*)this );
124 xWindow
->removeFocusListener( (XFocusListener
*)this );
125 xWindow
->removeWindowListener( (XWindowListener
*)this );
126 xWindow
->removePaintListener( (XPaintListener
*)this );
127 // cast due to ambiguities
128 xControl
->removeEventListener( (XEventListener
*)(XPaintListener
*)this );
131 //--------------------------------------------------------------------------------------------------
132 SMART_UNO_IMPLEMENTATION( Listener_Impl
, UsrObject
);
134 //--------------------------------------------------------------------------------------------------
135 BOOL
Listener_Impl::queryInterface( Uik aUik
, XInterfaceRef
& rOut
)
137 if (aUik
== XMouseListener::getSmartUik())
138 rOut
= (XMouseListener
*)this;
139 else if (aUik
== XMouseMotionListener::getSmartUik())
140 rOut
= (XMouseMotionListener
*)this;
141 else if (aUik
== XWindowListener::getSmartUik())
142 rOut
= (XWindowListener
*)this;
143 else if (aUik
== XFocusListener::getSmartUik())
144 rOut
= (XFocusListener
*)this;
145 else if (aUik
== XKeyListener::getSmartUik())
146 rOut
= (XKeyListener
*)this;
147 else if (aUik
== XPaintListener::getSmartUik())
148 rOut
= (XPaintListener
*)this;
149 else if (aUik
== ((XEventListener
*)NULL
)->getSmartUik())
150 rOut
= (XEventListener
*)(XMouseListener
*)this;
152 return UsrObject::queryInterface( aUik
, rOut
);
157 //--------------------------------------------------------------------------------------------------
159 void Listener_Impl::mousePressed( const VclMouseEvent
& evt
) {}
160 void Listener_Impl::mouseReleased( const VclMouseEvent
& evt
) {}
161 void Listener_Impl::mouseEntered( const VclMouseEvent
& evt
) {}
162 void Listener_Impl::mouseExited( const VclMouseEvent
& evt
) {}
164 // XMouseMotionListener
165 void Listener_Impl::mouseDragged( const VclMouseEvent
& evt
) {}
166 void Listener_Impl::mouseMoved( const VclMouseEvent
& evt
) {}
169 void Listener_Impl::keyPressed( const VclKeyEvent
& evt
) {}
170 void Listener_Impl::keyReleased( const VclKeyEvent
& evt
) {}
173 void Listener_Impl::focusGained( const FocusEvent
& evt
) {}
174 void Listener_Impl::focusLost( const FocusEvent
& evt
) {}
177 void Listener_Impl::windowResized( const WindowEvent
& evt
) {}
178 void Listener_Impl::windowMoved( const WindowEvent
& evt
) {}
179 void Listener_Impl::windowShown( const EventObject
& evt
) {}
180 void Listener_Impl::windowHidden( const EventObject
& evt
) {}
183 void Listener_Impl::windowPaint( const PaintEvent
& evt
)
187 XControlRef
xControl( evt
.Source
, USR_QUERY
);
190 XDeviceRef
xDev( xControl
->getPeer(), USR_QUERY
);
191 XGraphicsRef xGraphics
= xDev
->createGraphics();
192 xGraphics
->drawLine( 0, 0, 200, 200 );
193 xGraphics
->drawLine( 200, 0, 0, 200 );
199 void Listener_Impl::disposing( const EventObject
& evt
) {}
202 //==================================================================================================
203 class FrameControlApplication
208 virtual void ShowStatusText( const XubString
& rText
);
211 FrameControlApplication() {}
218 Listener_Impl
* _pListener
;
219 XControlRef _xControl
;
221 WorkWindow
* _pWorkWin
;
224 FrameControlApplication g_App
;
227 Application
* pApp
= &g_App
;
231 //--------------------------------------------------------------------------------------------------
232 void FrameControlApplication::init()
234 XMultiServiceFactoryRef xMgr
= createRegistryServiceManager( L
"test.rdb" );
235 registerUsrServices( xMgr
);
236 setProcessServiceManager( xMgr
);
238 Application::RegisterUnoServices();
240 XServiceRegistryRef
xRegMgr(xMgr
, USR_QUERY
);
242 XImplementationRegistrationRef
xIR( xMgr
->createInstance(L
"stardiv.uno.repos.ImplementationRegistration"), USR_QUERY
);
245 char szDllName
[_MAX_PATH
]="";
247 ORealDynamicLoader::computeModuleName("fc", szDllName
, _MAX_PATH
);
248 UString aFCDllName
= StringToOUString(szDllName
, CHARSET_SYSTEM
);
249 xIR
->registerImplementation(L
"stardiv.loader.SharedLibrary", aFCDllName
, XSimpleRegistryRef() );
251 catch( CannotRegisterImplementationException
& e
)
259 XInterfaceRef xInst
= xMgr
->createInstance( L
"stardiv.one.frame.FrameControl" );
260 if (xInst
->queryInterface( XControl::getSmartUik(), _xControl
))
262 _pWorkWin
= new WorkWindow( NULL
, WB_APP
| WB_STDWORK
);
264 XWindowPeerRef
xParent( _pWorkWin
->GetComponentInterface() );
266 XToolkitRef
xToolkit( xMgr
->createInstance( L
"stardiv.vcl.VclToolkit" ), USR_QUERY
);
267 //xToolkit = XToolkitRef( xMgr->createInstance( L"stardiv.uno.awt.Toolkit" ), USR_QUERY );
268 _xControl
->createPeer( xToolkit
, xParent
);
269 XWindowRef
xWin( _xControl
, USR_QUERY
);
270 xWin
->setPosSize( 50, 50, 400, 400, PosSize_POSSIZE
);
271 xWin
->setVisible( TRUE
);
273 _pListener
= new Listener_Impl();
274 _pListener
->acquire();
275 _pListener
->addAllListeners( _xControl
);
276 // ... on paint a cross should be drawn
280 //--------------------------------------------------------------------------------------------------
281 void FrameControlApplication::deinit()
286 _pListener
->removeAllListeners( _xControl
);
287 _xControl
->dispose(); // disposing event should occur
288 _pListener
->release();
291 _xControl
= XControlRef();
299 //--------------------------------------------------------------------------------------------------
300 void FrameControlApplication::Main()
302 // void TestErrcodes();
306 SetAppName( "RadioActiveControl-Demo" );
316 //--------------------------------------------------------------------------------------------------
317 void FrameControlApplication::ShowStatusText( const XubString
& rStatus
)
319 Application::GetAppWindow()->SetText( rStatus
);