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