1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testframecontrol.cxx,v $
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>
54 //==================================================================================================
57 , public XMouseListener
58 , public XMouseMotionListener
60 , public XWindowListener
61 , public XFocusListener
62 , public XPaintListener
65 SMART_UNO_DECLARATION( Listener_Impl
, UsrObject
);
67 virtual BOOL
queryInterface( Uik aUik
, XInterfaceRef
& rOut
);
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
);
80 virtual void keyPressed( const VclKeyEvent
& evt
);
81 virtual void keyReleased( const VclKeyEvent
& evt
);
84 virtual void focusGained( const FocusEvent
& evt
);
85 virtual void focusLost( const FocusEvent
& evt
);
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
);
94 virtual void windowPaint( const PaintEvent
& evt
);
97 virtual void disposing( const EventObject
& evt
);
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;
155 return UsrObject::queryInterface( aUik
, rOut
);
160 //--------------------------------------------------------------------------------------------------
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
) {}
172 void Listener_Impl::keyPressed( const VclKeyEvent
& evt
) {}
173 void Listener_Impl::keyReleased( const VclKeyEvent
& evt
) {}
176 void Listener_Impl::focusGained( const FocusEvent
& evt
) {}
177 void Listener_Impl::focusLost( const FocusEvent
& evt
) {}
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
) {}
186 void Listener_Impl::windowPaint( const PaintEvent
& evt
)
190 XControlRef
xControl( evt
.Source
, USR_QUERY
);
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 );
202 void Listener_Impl::disposing( const EventObject
& evt
) {}
205 //==================================================================================================
206 class FrameControlApplication
211 virtual void ShowStatusText( const XubString
& rText
);
214 FrameControlApplication() {}
221 Listener_Impl
* _pListener
;
222 XControlRef _xControl
;
224 WorkWindow
* _pWorkWin
;
227 FrameControlApplication g_App
;
230 Application
* pApp
= &g_App
;
234 //--------------------------------------------------------------------------------------------------
235 void FrameControlApplication::init()
237 XMultiServiceFactoryRef xMgr
= createRegistryServiceManager( L
"test.rdb" );
238 registerUsrServices( xMgr
);
239 setProcessServiceManager( xMgr
);
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
)
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
);
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()
289 _pListener
->removeAllListeners( _xControl
);
290 _xControl
->dispose(); // disposing event should occur
291 _pListener
->release();
294 _xControl
= XControlRef();
302 //--------------------------------------------------------------------------------------------------
303 void FrameControlApplication::Main()
305 // void TestErrcodes();
309 SetAppName( "RadioActiveControl-Demo" );
319 //--------------------------------------------------------------------------------------------------
320 void FrameControlApplication::ShowStatusText( const XubString
& rStatus
)
322 Application::GetAppWindow()->SetText( rStatus
);