xref: /trunk/main/avmedia/source/win/window.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 #include <tools/prewin.h>
25 #if defined _MSC_VER
26 #pragma warning(push, 1)
27 #pragma warning(disable: 4917)
28 #endif
29 #include <windows.h>
30 #include <objbase.h>
31 #include <strmif.h>
32 #include <control.h>
33 #include <dshow.h>
34 #if defined _MSC_VER
35 #pragma warning(pop)
36 #endif
37 #include <tools/postwin.h>
38 #include <com/sun/star/awt/SystemPointer.hdl>
39 
40 #include "window.hxx"
41 #include "player.hxx"
42 
43 #define AVMEDIA_WIN_WINDOW_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Window_DirectX"
44 #define AVMEDIA_WIN_WINDOW_SERVICENAME "com.sun.star.media.Window_DirectX"
45 
46 using namespace ::com::sun::star;
47 
48 namespace avmedia { namespace win {
49 
50 // -----------
51 // - statics -
52 // -----------
53 
ImplGetOwnStaticMutex()54 static ::osl::Mutex& ImplGetOwnStaticMutex()
55 {
56     static ::osl::Mutex* pMutex = NULL;
57 
58     if( pMutex == NULL )
59     {
60         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
61 
62         if( pMutex == NULL )
63         {
64             static ::osl::Mutex aMutex;
65             pMutex = &aMutex;
66         }
67     }
68 
69     return *pMutex;
70 }
71 
72 // -----------
73 // - WndProc -
74 // -----------
75 
MediaPlayerWndProc(HWND hWnd,UINT nMsg,WPARAM nPar1,LPARAM nPar2)76 LRESULT CALLBACK MediaPlayerWndProc( HWND hWnd,UINT nMsg, WPARAM nPar1, LPARAM nPar2 )
77 {
78     Window* pWindow = (Window*) ::GetWindowLong( hWnd, 0 );
79     bool    bProcessed = true;
80 
81     if( pWindow )
82     {
83         switch( nMsg )
84         {
85             case( WM_SETCURSOR ):
86                 pWindow->updatePointer();
87             break;
88 
89             case( WM_GRAPHNOTIFY ):
90                 pWindow->processGraphEvent();
91             break;
92 
93             case( WM_MOUSEMOVE ):
94             case( WM_LBUTTONDOWN ):
95             case( WM_MBUTTONDOWN ):
96             case( WM_RBUTTONDOWN ):
97             case( WM_LBUTTONUP ):
98             case( WM_MBUTTONUP ):
99             case( WM_RBUTTONUP ):
100             {
101                 awt::MouseEvent aUNOEvt;
102                 POINT           aWinPoint;
103 
104                 if( !::GetCursorPos( &aWinPoint ) || !::ScreenToClient( hWnd, &aWinPoint ) )
105                 {
106                     aWinPoint.x = GET_X_LPARAM( nPar2 );
107                     aWinPoint.y = GET_Y_LPARAM( nPar2 );
108                 }
109                 aUNOEvt.Modifiers = 0;
110                 aUNOEvt.Buttons = 0;
111                 aUNOEvt.X = aWinPoint.x;
112                 aUNOEvt.Y = aWinPoint.y;
113                 aUNOEvt.PopupTrigger = false;
114 
115                 // Modifiers
116                 if( nPar1 & MK_SHIFT )
117                     aUNOEvt.Modifiers |= awt::KeyModifier::SHIFT;
118 
119                 if( nPar1 & MK_CONTROL )
120                     aUNOEvt.Modifiers |= awt::KeyModifier::MOD1;
121 
122                 // Buttons
123                 if( WM_LBUTTONDOWN == nMsg || WM_LBUTTONUP == nMsg )
124                     aUNOEvt.Buttons |= awt::MouseButton::LEFT;
125 
126                 if( WM_MBUTTONDOWN == nMsg || WM_MBUTTONUP == nMsg )
127                     aUNOEvt.Buttons |= awt::MouseButton::MIDDLE;
128 
129                 if( WM_RBUTTONDOWN == nMsg || WM_RBUTTONUP == nMsg )
130                     aUNOEvt.Buttons |= awt::MouseButton::RIGHT;
131 
132                 // event type
133                 if( WM_LBUTTONDOWN == nMsg ||
134                     WM_MBUTTONDOWN == nMsg ||
135                     WM_RBUTTONDOWN == nMsg )
136                 {
137                     aUNOEvt.ClickCount = 1;
138                     pWindow->fireMousePressedEvent( aUNOEvt );
139                 }
140                 else if( WM_LBUTTONUP == nMsg ||
141                          WM_MBUTTONUP == nMsg ||
142                          WM_RBUTTONUP == nMsg )
143                 {
144                     aUNOEvt.ClickCount = 1;
145                     pWindow->fireMouseReleasedEvent( aUNOEvt );
146                 }
147                 else if( WM_MOUSEMOVE == nMsg )
148                 {
149                     aUNOEvt.ClickCount = 0;
150                     pWindow->fireMouseMovedEvent( aUNOEvt );
151                     pWindow->updatePointer();
152                 }
153             }
154             break;
155 
156             case( WM_SETFOCUS ):
157             {
158                 const awt::FocusEvent aUNOEvt;
159                 pWindow->fireSetFocusEvent( aUNOEvt );
160             }
161             break;
162 
163             default:
164                 bProcessed = false;
165             break;
166         }
167     }
168     else
169         bProcessed = false;
170 
171     return( bProcessed ? 0 : DefWindowProc( hWnd, nMsg, nPar1, nPar2 ) );
172 }
173 
174 // ---------------
175 // - Window -
176 // ---------------
177 
lcl_getWndClass()178 WNDCLASS* lcl_getWndClass()
179 {
180     static WNDCLASS* s_pWndClass = NULL;
181     if ( !s_pWndClass )
182     {
183         s_pWndClass = new WNDCLASS;
184 
185         memset( s_pWndClass, 0, sizeof( *s_pWndClass ) );
186         s_pWndClass->hInstance = GetModuleHandle( NULL );
187         s_pWndClass->cbWndExtra = sizeof( DWORD );
188         s_pWndClass->lpfnWndProc = MediaPlayerWndProc;
189         s_pWndClass->lpszClassName = "com_sun_star_media_PlayerWnd";
190         s_pWndClass->hbrBackground = (HBRUSH) ::GetStockObject( BLACK_BRUSH );
191         s_pWndClass->hCursor = ::LoadCursor( NULL, IDC_ARROW );
192 
193         ::RegisterClass( s_pWndClass );
194     }
195     return s_pWndClass;
196 }
197 
198 // ------------------------------------------------------------------------------
199 
Window(const uno::Reference<uno::XComponentContext> & rxContext,Player & rPlayer)200 Window::Window( const uno::Reference< uno::XComponentContext >& rxContext, Player& rPlayer ) :
201     mxContext( rxContext ),
202     mrPlayer( rPlayer ),
203     meZoomLevel( media::ZoomLevel_NOT_AVAILABLE ),
204     mnParentWnd( 0 ),
205     mnFrameWnd( 0 ),
206     maListeners( maMutex ),
207     mnPointerType( awt::SystemPointer::ARROW )
208 {
209     ::osl::MutexGuard aGuard( ImplGetOwnStaticMutex() );
210 
211     lcl_getWndClass();
212 }
213 
214 // ------------------------------------------------------------------------------
215 
~Window()216 Window::~Window()
217 {
218     if( mnFrameWnd )
219         ::DestroyWindow( (HWND) mnFrameWnd );
220 }
221 
222 // ------------------------------------------------------------------------------
223 
ImplLayoutVideoWindow()224 void Window::ImplLayoutVideoWindow()
225 {
226     if( media::ZoomLevel_NOT_AVAILABLE != meZoomLevel )
227     {
228         awt::Size           aPrefSize( mrPlayer.getPreferredPlayerWindowSize() );
229         awt::Rectangle      aRect = getPosSize();
230         int                 nW = aRect.Width, nH = aRect.Height;
231         int                 nVideoW = nW, nVideoH = nH;
232         int                 nX = 0, nY = 0, nWidth = 0, nHeight = 0;
233         bool                bDone = false, bZoom = false;
234 
235         if( media::ZoomLevel_ORIGINAL == meZoomLevel )
236         {
237             bZoom = true;
238         }
239         else if( media::ZoomLevel_ZOOM_1_TO_4 == meZoomLevel )
240         {
241             aPrefSize.Width >>= 2;
242             aPrefSize.Height >>= 2;
243             bZoom = true;
244         }
245         else if( media::ZoomLevel_ZOOM_1_TO_2 == meZoomLevel )
246         {
247             aPrefSize.Width >>= 1;
248             aPrefSize.Height >>= 1;
249             bZoom = true;
250         }
251         else if( media::ZoomLevel_ZOOM_2_TO_1 == meZoomLevel )
252         {
253             aPrefSize.Width <<= 1;
254             aPrefSize.Height <<= 1;
255             bZoom = true;
256         }
257         else if( media::ZoomLevel_ZOOM_4_TO_1 == meZoomLevel )
258         {
259             aPrefSize.Width <<= 2;
260             aPrefSize.Height <<= 2;
261             bZoom = true;
262         }
263         else if( media::ZoomLevel_FIT_TO_WINDOW == meZoomLevel )
264         {
265             nWidth = nVideoW;
266             nHeight = nVideoH;
267             bDone = true;
268         }
269 
270         if( bZoom )
271         {
272             if( ( aPrefSize.Width <= nVideoW ) && ( aPrefSize.Height <= nVideoH ) )
273             {
274                 nX = ( nVideoW - aPrefSize.Width ) >> 1;
275                 nY = ( nVideoH - aPrefSize.Height ) >> 1;
276                 nWidth = aPrefSize.Width;
277                 nHeight = aPrefSize.Height;
278                 bDone = true;
279             }
280         }
281 
282         if( !bDone )
283         {
284             if( aPrefSize.Width > 0 && aPrefSize.Height > 0 && nVideoW > 0 && nVideoH > 0 )
285             {
286                 double fPrefWH = (double) aPrefSize.Width / aPrefSize.Height;
287 
288                 if( fPrefWH < ( (double) nVideoW / nVideoH ) )
289                     nVideoW = (int)( nVideoH * fPrefWH );
290                 else
291                     nVideoH = (int)( nVideoW / fPrefWH );
292 
293                 nX = ( nW - nVideoW ) >> 1;
294                 nY = ( nH - nVideoH ) >> 1;
295                 nWidth = nVideoW;
296                 nHeight = nVideoH;
297             }
298             else
299                 nX = nY = nWidth = nHeight = 0;
300         }
301 
302         IVideoWindow* pVideoWindow = const_cast< IVideoWindow* >( mrPlayer.getVideoWindow() );
303 
304         if( pVideoWindow )
305             pVideoWindow->SetWindowPosition( nX, nY, nWidth, nHeight );
306     }
307 }
308 
309 // ------------------------------------------------------------------------------
310 
create(const uno::Sequence<uno::Any> & rArguments)311 bool Window::create( const uno::Sequence< uno::Any >& rArguments )
312 {
313     IVideoWindow* pVideoWindow = const_cast< IVideoWindow* >( mrPlayer.getVideoWindow() );
314     WNDCLASS* mpWndClass = lcl_getWndClass();
315 
316 
317     if( !mnFrameWnd && pVideoWindow && mpWndClass )
318     {
319         awt::Rectangle  aRect;
320         sal_IntPtr       nWnd;
321 
322         rArguments[ 0 ] >>= nWnd;
323         rArguments[ 1 ] >>= aRect;
324 
325         mnParentWnd = static_cast<int>(nWnd);
326 
327         mnFrameWnd = (int) ::CreateWindow( mpWndClass->lpszClassName, NULL,
328                                            WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
329                                            aRect.X, aRect.Y, aRect.Width, aRect.Height,
330                                            (HWND) mnParentWnd, NULL, mpWndClass->hInstance, 0 );
331 
332         // if the last CreateWindow failed...
333         if( mnFrameWnd == 0 )
334         {
335             // try again and this time assume that mnParent is indeed a dc
336             mnParentWnd = reinterpret_cast<int>(::WindowFromDC( (HDC)mnParentWnd ));
337             mnFrameWnd = (int) ::CreateWindow( mpWndClass->lpszClassName, NULL,
338                                            WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
339                                            aRect.X, aRect.Y, aRect.Width, aRect.Height,
340                                            (HWND)mnParentWnd , NULL, mpWndClass->hInstance, 0 );
341         }
342 
343         if( mnFrameWnd )
344         {
345             ::SetWindowLong( (HWND) mnFrameWnd, 0, (DWORD) this );
346 
347 #ifdef DDRAW_TEST_OUTPUT
348             IDirectDraw7*           pDDraw;
349             IDirectDrawSurface7*    pDDSurface;
350             IDirectDrawClipper*     pDDClipper;
351 
352             if( DD_OK == DirectDrawCreateEx( NULL, (void**) &pDDraw, IID_IDirectDraw7, NULL ) )
353             {
354                 if( DD_OK == pDDraw->SetCooperativeLevel( (HWND) mnParentWnd, DDSCL_NORMAL ) )
355                 {
356                     DDSURFACEDESC2 aDDDesc;
357 
358                     memset( &aDDDesc, 0, sizeof( aDDDesc ) );
359                     aDDDesc.dwSize = sizeof( aDDDesc );
360                     aDDDesc.dwFlags = DDSD_CAPS;
361                     aDDDesc.ddsCaps.dwCaps |= DDSCAPS_PRIMARYSURFACE;
362 
363                     if( DD_OK == pDDraw->CreateSurface( &aDDDesc, &pDDSurface, NULL ) )
364                     {
365                         if( DD_OK == pDDraw->CreateClipper( 0, &pDDClipper, NULL ) )
366                         {
367                             pDDClipper->SetHWnd( 0, (HWND) mnFrameWnd );
368                             pDDSurface->SetClipper( pDDClipper );
369                         }
370 
371                         mrPlayer.setDDrawParams( (IDirectDraw*) pDDraw, (IDirectDrawSurface*) pDDSurface );
372 #endif
373 
374                         pVideoWindow->put_Owner( (OAHWND) mnFrameWnd );
375                         pVideoWindow->put_MessageDrain( (OAHWND) mnFrameWnd );
376                         pVideoWindow->put_WindowStyle( WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN );
377 
378                         mrPlayer.setNotifyWnd( mnFrameWnd );
379 
380                         meZoomLevel = media::ZoomLevel_FIT_TO_WINDOW;
381                         ImplLayoutVideoWindow();
382 #ifdef DDRAW_TEST_OUTPUT
383                     }
384                 }
385             }
386 #endif
387         }
388     }
389 
390     return( mnFrameWnd != 0 );
391 }
392 
393 // ------------------------------------------------------------------------------
394 
processGraphEvent()395 void Window::processGraphEvent()
396 {
397     mrPlayer.processEvent();
398 }
399 
400 // ------------------------------------------------------------------------------
401 
updatePointer()402 void Window::updatePointer()
403 {
404     char* pCursorName;
405 
406     switch( mnPointerType )
407     {
408         case( awt::SystemPointer::CROSS ): pCursorName = IDC_CROSS; break;
409         //case( awt::SystemPointer::HAND ): pCursorName = IDC_HAND; break;
410         case( awt::SystemPointer::MOVE ): pCursorName = IDC_SIZEALL; break;
411         case( awt::SystemPointer::WAIT ): pCursorName = IDC_WAIT; break;
412 
413         default:
414             pCursorName = IDC_ARROW;
415         break;
416     }
417 
418     ::SetCursor( ::LoadCursor( NULL, pCursorName ) );
419 }
420 
421 // ------------------------------------------------------------------------------
422 
update()423 void SAL_CALL Window::update(  )
424 {
425     ::RedrawWindow( (HWND) mnFrameWnd, NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE  );
426 }
427 
428 // ------------------------------------------------------------------------------
429 
setZoomLevel(media::ZoomLevel eZoomLevel)430 sal_Bool SAL_CALL Window::setZoomLevel( media::ZoomLevel eZoomLevel )
431 {
432         boolean bRet = false;
433 
434         if( media::ZoomLevel_NOT_AVAILABLE != meZoomLevel &&
435             media::ZoomLevel_NOT_AVAILABLE != eZoomLevel )
436         {
437             if( eZoomLevel != meZoomLevel )
438             {
439                 meZoomLevel = eZoomLevel;
440                 ImplLayoutVideoWindow();
441             }
442 
443             bRet = true;
444         }
445 
446         return bRet;
447 }
448 
449 // ------------------------------------------------------------------------------
450 
getZoomLevel()451 media::ZoomLevel SAL_CALL Window::getZoomLevel(  )
452 {
453     return meZoomLevel;
454 }
455 
456 // ------------------------------------------------------------------------------
457 
setPointerType(sal_Int32 nPointerType)458 void SAL_CALL Window::setPointerType( sal_Int32 nPointerType )
459 {
460     mnPointerType = nPointerType;
461 }
462 
463 // ------------------------------------------------------------------------------
464 
setPosSize(sal_Int32 X,sal_Int32 Y,sal_Int32 Width,sal_Int32 Height,sal_Int16)465 void SAL_CALL Window::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 )
466 {
467     if( mnFrameWnd )
468     {
469         ::SetWindowPos( (HWND) mnFrameWnd, HWND_TOP, X, Y, Width, Height, 0 );
470         ImplLayoutVideoWindow();
471     }
472 }
473 
474 // ------------------------------------------------------------------------------
475 
getPosSize()476 awt::Rectangle SAL_CALL Window::getPosSize()
477 {
478     awt::Rectangle aRet;
479 
480     if( mnFrameWnd )
481     {
482         ::RECT  aWndRect;
483 
484         if( ::GetClientRect( (HWND) mnFrameWnd, &aWndRect ) )
485         {
486             aRet.X = aWndRect.left;
487             aRet.Y = aWndRect.top;
488             aRet.Width = aWndRect.right - aWndRect.left + 1;
489             aRet.Height = aWndRect.bottom - aWndRect.top + 1;
490         }
491     }
492 
493     return aRet;
494 }
495 
496 // ------------------------------------------------------------------------------
497 
setVisible(sal_Bool bVisible)498 void SAL_CALL Window::setVisible( sal_Bool bVisible )
499 {
500     if( mnFrameWnd )
501     {
502         IVideoWindow* pVideoWindow = const_cast< IVideoWindow* >( mrPlayer.getVideoWindow() );
503 
504         if( pVideoWindow )
505             pVideoWindow->put_Visible( bVisible ? OATRUE : OAFALSE );
506 
507         ::ShowWindow( (HWND) mnFrameWnd, bVisible ? SW_SHOW : SW_HIDE );
508     }
509 }
510 
511 // ------------------------------------------------------------------------------
512 
setEnable(sal_Bool bEnable)513 void SAL_CALL Window::setEnable( sal_Bool bEnable )
514 {
515     if( mnFrameWnd )
516         ::EnableWindow( (HWND) mnFrameWnd, bEnable );
517 }
518 
519 // ------------------------------------------------------------------------------
520 
setFocus()521 void SAL_CALL Window::setFocus(  )
522 {
523     if( mnFrameWnd )
524         ::SetFocus( (HWND) mnFrameWnd );
525 }
526 
527 // ------------------------------------------------------------------------------
528 
addWindowListener(const uno::Reference<awt::XWindowListener> & xListener)529 void SAL_CALL Window::addWindowListener( const uno::Reference< awt::XWindowListener >& xListener )
530 {
531     maListeners.addInterface( getCppuType( &xListener ), xListener );
532 }
533 
534 // ------------------------------------------------------------------------------
535 
removeWindowListener(const uno::Reference<awt::XWindowListener> & xListener)536 void SAL_CALL Window::removeWindowListener( const uno::Reference< awt::XWindowListener >& xListener )
537 {
538     maListeners.removeInterface( getCppuType( &xListener ), xListener );
539 }
540 
541 // ------------------------------------------------------------------------------
542 
addFocusListener(const uno::Reference<awt::XFocusListener> & xListener)543 void SAL_CALL Window::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
544 {
545     maListeners.addInterface( getCppuType( &xListener ), xListener );
546 }
547 
548 // ------------------------------------------------------------------------------
549 
removeFocusListener(const uno::Reference<awt::XFocusListener> & xListener)550 void SAL_CALL Window::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
551 {
552     maListeners.removeInterface( getCppuType( &xListener ), xListener );
553 }
554 
555 // ------------------------------------------------------------------------------
556 
addKeyListener(const uno::Reference<awt::XKeyListener> & xListener)557 void SAL_CALL Window::addKeyListener( const uno::Reference< awt::XKeyListener >& xListener )
558 {
559     maListeners.addInterface( getCppuType( &xListener ), xListener );
560 }
561 
562 // ------------------------------------------------------------------------------
563 
removeKeyListener(const uno::Reference<awt::XKeyListener> & xListener)564 void SAL_CALL Window::removeKeyListener( const uno::Reference< awt::XKeyListener >& xListener )
565 {
566     maListeners.removeInterface( getCppuType( &xListener ), xListener );
567 }
568 
569 // ------------------------------------------------------------------------------
570 
addMouseListener(const uno::Reference<awt::XMouseListener> & xListener)571 void SAL_CALL Window::addMouseListener( const uno::Reference< awt::XMouseListener >& xListener )
572 {
573     maListeners.addInterface( getCppuType( &xListener ), xListener );
574 }
575 
576 // ------------------------------------------------------------------------------
577 
removeMouseListener(const uno::Reference<awt::XMouseListener> & xListener)578 void SAL_CALL Window::removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener )
579 {
580     maListeners.removeInterface( getCppuType( &xListener ), xListener );
581 }
582 
583 // ------------------------------------------------------------------------------
584 
addMouseMotionListener(const uno::Reference<awt::XMouseMotionListener> & xListener)585 void SAL_CALL Window::addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener )
586 {
587     maListeners.addInterface( getCppuType( &xListener ), xListener );
588 }
589 
590 // ------------------------------------------------------------------------------
591 
removeMouseMotionListener(const uno::Reference<awt::XMouseMotionListener> & xListener)592 void SAL_CALL Window::removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener )
593 {
594     maListeners.removeInterface( getCppuType( &xListener ), xListener );
595 }
596 
597 // ------------------------------------------------------------------------------
598 
addPaintListener(const uno::Reference<awt::XPaintListener> & xListener)599 void SAL_CALL Window::addPaintListener( const uno::Reference< awt::XPaintListener >& xListener )
600 {
601     maListeners.addInterface( getCppuType( &xListener ), xListener );
602 }
603 
604 // ------------------------------------------------------------------------------
605 
removePaintListener(const uno::Reference<awt::XPaintListener> & xListener)606 void SAL_CALL Window::removePaintListener( const uno::Reference< awt::XPaintListener >& xListener )
607 {
608     maListeners.removeInterface( getCppuType( &xListener ), xListener );
609 }
610 
611 // ------------------------------------------------------------------------------
612 
dispose()613 void SAL_CALL Window::dispose(  )
614 {
615 }
616 
617 // ------------------------------------------------------------------------------
618 
addEventListener(const uno::Reference<lang::XEventListener> & xListener)619 void SAL_CALL Window::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
620 {
621     maListeners.addInterface( getCppuType( &xListener ), xListener );
622 }
623 
624 // ------------------------------------------------------------------------------
625 
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)626 void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
627 {
628     maListeners.removeInterface( getCppuType( &xListener ), xListener );
629 }
630 
631 // ------------------------------------------------------------------------------
632 
fireMousePressedEvent(const::com::sun::star::awt::MouseEvent & rEvt)633 void Window::fireMousePressedEvent( const ::com::sun::star::awt::MouseEvent& rEvt )
634 {
635     ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseListener >*) 0 ) );
636 
637     if( pContainer )
638     {
639         ::cppu::OInterfaceIteratorHelper aIter( *pContainer );
640 
641         while( aIter.hasMoreElements() )
642             uno::Reference< awt::XMouseListener >( aIter.next(), uno::UNO_QUERY )->mousePressed( rEvt );
643     }
644 }
645 
646 // -----------------------------------------------------------------------------
647 
fireMouseReleasedEvent(const::com::sun::star::awt::MouseEvent & rEvt)648 void Window::fireMouseReleasedEvent( const ::com::sun::star::awt::MouseEvent& rEvt )
649 {
650     ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseListener >*) 0 ) );
651 
652     if( pContainer )
653     {
654         ::cppu::OInterfaceIteratorHelper aIter( *pContainer );
655 
656         while( aIter.hasMoreElements() )
657             uno::Reference< awt::XMouseListener >( aIter.next(), uno::UNO_QUERY )->mouseReleased( rEvt );
658     }
659 }
660 
661 // -----------------------------------------------------------------------------
662 
fireMouseMovedEvent(const::com::sun::star::awt::MouseEvent & rEvt)663 void Window::fireMouseMovedEvent( const ::com::sun::star::awt::MouseEvent& rEvt )
664 {
665     ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseMotionListener >*) 0 ) );
666 
667     if( pContainer )
668     {
669         ::cppu::OInterfaceIteratorHelper aIter( *pContainer );
670 
671         while( aIter.hasMoreElements() )
672             uno::Reference< awt::XMouseMotionListener >( aIter.next(), uno::UNO_QUERY )->mouseMoved( rEvt );
673     }
674 }
675 
676 // -----------------------------------------------------------------------------
677 
fireSetFocusEvent(const::com::sun::star::awt::FocusEvent & rEvt)678 void Window::fireSetFocusEvent( const ::com::sun::star::awt::FocusEvent& rEvt )
679 {
680     ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XFocusListener >*) 0 ) );
681 
682     if( pContainer )
683     {
684         ::cppu::OInterfaceIteratorHelper aIter( *pContainer );
685 
686         while( aIter.hasMoreElements() )
687             uno::Reference< awt::XFocusListener >( aIter.next(), uno::UNO_QUERY )->focusGained( rEvt );
688     }
689 }
690 
691 // ------------------------------------------------------------------------------
692 
getImplementationName()693 ::rtl::OUString SAL_CALL Window::getImplementationName(  )
694 {
695     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_WIN_WINDOW_IMPLEMENTATIONNAME ) );
696 }
697 
698 // ------------------------------------------------------------------------------
699 
supportsService(const::rtl::OUString & ServiceName)700 sal_Bool SAL_CALL Window::supportsService( const ::rtl::OUString& ServiceName )
701 {
702     return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_WIN_WINDOW_SERVICENAME ) );
703 }
704 
705 // ------------------------------------------------------------------------------
706 
getSupportedServiceNames()707 uno::Sequence< ::rtl::OUString > SAL_CALL Window::getSupportedServiceNames(  )
708 {
709     uno::Sequence< ::rtl::OUString > aRet(1);
710     aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_WIN_WINDOW_SERVICENAME ) );
711 
712     return aRet;
713 }
714 
715 } // namespace win
716 } // namespace avmedia
717