xref: /trunk/main/avmedia/source/xine/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 <com/sun/star/awt/SystemPointer.hdl>
25 
26 #include "window.hxx"
27 #include "player.hxx"
28 
29 using namespace ::com::sun::star;
30 
31 namespace avmedia { namespace xine {
32 
33 // -----------
34 // - statics -
35 // -----------
36 
ImplGetOwnStaticMutex()37 static ::osl::Mutex& ImplGetOwnStaticMutex()
38 {
39     static ::osl::Mutex* pMutex = NULL;
40 
41     if( pMutex == NULL )
42     {
43         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
44 
45         if( pMutex == NULL )
46         {
47             static ::osl::Mutex aMutex;
48             pMutex = &aMutex;
49         }
50     }
51 
52     return *pMutex;
53 }
54 
55 // -----------
56 // - WndProc -
57 // -----------
58 
59 /*
60 LRESULT CALLBACK MediaPlayerWndProc( HWND hWnd,UINT nMsg, WPARAM nPar1, LPARAM nPar2 )
61 {
62     Window* pWindow = (Window*) ::GetWindowLong( hWnd, 0 );
63     bool    bProcessed = true;
64 
65     if( pWindow )
66     {
67         switch( nMsg )
68         {
69             case( WM_SETCURSOR ):
70                 pWindow->updatePointer();
71             break;
72 
73             case( WM_GRAPHNOTIFY ):
74                 pWindow->processGraphEvent();
75             break;
76 
77             case( WM_MOUSEMOVE ):
78             case( WM_LBUTTONDOWN ):
79             case( WM_MBUTTONDOWN ):
80             case( WM_RBUTTONDOWN ):
81             case( WM_LBUTTONUP ):
82             case( WM_MBUTTONUP ):
83             case( WM_RBUTTONUP ):
84             {
85                 awt::MouseEvent aUNOEvt;
86                 POINT           aWinPoint;
87 
88                 if( !::GetCursorPos( &aWinPoint ) || !::ScreenToClient( hWnd, &aWinPoint ) )
89                 {
90                     aWinPoint.x = GET_X_LPARAM( nPar2 );
91                     aWinPoint.y = GET_Y_LPARAM( nPar2 );
92                 }
93                 aUNOEvt.Modifiers = 0;
94                 aUNOEvt.Buttons = 0;
95                 aUNOEvt.X = aWinPoint.x;
96                 aUNOEvt.Y = aWinPoint.y;
97                 aUNOEvt.PopupTrigger = false;
98 
99                 // Modifiers
100                 if( nPar1 & MK_SHIFT )
101                     aUNOEvt.Modifiers |= awt::KeyModifier::SHIFT;
102 
103                 if( nPar1 & MK_CONTROL )
104                     aUNOEvt.Modifiers |= awt::KeyModifier::MOD1;
105 
106                 // Buttons
107                 if( WM_LBUTTONDOWN == nMsg || WM_LBUTTONUP == nMsg )
108                     aUNOEvt.Buttons |= awt::MouseButton::LEFT;
109 
110                 if( WM_MBUTTONDOWN == nMsg || WM_MBUTTONUP == nMsg )
111                     aUNOEvt.Buttons |= awt::MouseButton::MIDDLE;
112 
113                 if( WM_RBUTTONDOWN == nMsg || WM_RBUTTONUP == nMsg )
114                     aUNOEvt.Buttons |= awt::MouseButton::RIGHT;
115 
116                 // event type
117                 if( WM_LBUTTONDOWN == nMsg ||
118                     WM_MBUTTONDOWN == nMsg ||
119                     WM_RBUTTONDOWN == nMsg )
120                 {
121                     aUNOEvt.ClickCount = 1;
122                     pWindow->fireMousePressedEvent( aUNOEvt );
123                 }
124                 else if( WM_LBUTTONUP == nMsg ||
125                          WM_MBUTTONUP == nMsg ||
126                          WM_RBUTTONUP == nMsg )
127                 {
128                     aUNOEvt.ClickCount = 1;
129                     pWindow->fireMouseReleasedEvent( aUNOEvt );
130                 }
131                 else if( WM_MOUSEMOVE == nMsg )
132                 {
133                     aUNOEvt.ClickCount = 0;
134                     pWindow->fireMouseMovedEvent( aUNOEvt );
135                     pWindow->updatePointer();
136                 }
137             }
138             break;
139 
140             case( WM_SETFOCUS ):
141             {
142                 const awt::FocusEvent aUNOEvt;
143                 pWindow->fireSetFocusEvent( aUNOEvt );
144             }
145             break;
146 
147             default:
148                 bProcessed = false;
149             break;
150         }
151     }
152     else
153         bProcessed = false;
154 
155     return( bProcessed ? 0 : DefWindowProc( hWnd, nMsg, nPar1, nPar2 ) );
156 }
157 */
158 
159 // ---------------
160 // - Window -
161 // ---------------
162 
Window(Player & rPlayer)163 Window::Window( Player& rPlayer ) :
164     mrPlayer( rPlayer ),
165     maListeners( maMutex ),
166     meZoomLevel( media::ZoomLevel_NOT_AVAILABLE ),
167     mnPointerType( awt::SystemPointer::ARROW )
168 {
169     ::osl::MutexGuard aGuard( ImplGetOwnStaticMutex() );
170 }
171 
172 // ------------------------------------------------------------------------------
173 
~Window()174 Window::~Window()
175 {
176 }
177 
178 // ------------------------------------------------------------------------------
179 
implLayoutVideoWindow()180 void Window::implLayoutVideoWindow()
181 {
182     if( media::ZoomLevel_NOT_AVAILABLE != meZoomLevel )
183     {
184         awt::Size           aPrefSize( mrPlayer.getPreferredPlayerWindowSize() );
185         awt::Rectangle      aRect = getPosSize();
186         int                 nW = aRect.Width, nH = aRect.Height;
187         int                 nVideoW = nW, nVideoH = nH;
188         int                 nX = 0, nY = 0, nWidth = 0, nHeight = 0;
189         bool                bDone = false, bZoom = false;
190 
191         if( media::ZoomLevel_ORIGINAL == meZoomLevel )
192         {
193             bZoom = true;
194         }
195         else if( media::ZoomLevel_ZOOM_1_TO_4 == meZoomLevel )
196         {
197             aPrefSize.Width >>= 2;
198             aPrefSize.Height >>= 2;
199             bZoom = true;
200         }
201         else if( media::ZoomLevel_ZOOM_1_TO_2 == meZoomLevel )
202         {
203             aPrefSize.Width >>= 1;
204             aPrefSize.Height >>= 1;
205             bZoom = true;
206         }
207         else if( media::ZoomLevel_ZOOM_2_TO_1 == meZoomLevel )
208         {
209             aPrefSize.Width <<= 1;
210             aPrefSize.Height <<= 1;
211             bZoom = true;
212         }
213         else if( media::ZoomLevel_ZOOM_4_TO_1 == meZoomLevel )
214         {
215             aPrefSize.Width <<= 2;
216             aPrefSize.Height <<= 2;
217             bZoom = true;
218         }
219         else if( media::ZoomLevel_FIT_TO_WINDOW == meZoomLevel )
220         {
221             nWidth = nVideoW;
222             nHeight = nVideoH;
223             bDone = true;
224         }
225 
226         if( bZoom )
227         {
228             if( ( aPrefSize.Width <= nVideoW ) && ( aPrefSize.Height <= nVideoH ) )
229             {
230                 nX = ( nVideoW - aPrefSize.Width ) >> 1;
231                 nY = ( nVideoH - aPrefSize.Height ) >> 1;
232                 nWidth = aPrefSize.Width;
233                 nHeight = aPrefSize.Height;
234                 bDone = true;
235             }
236         }
237 
238         if( !bDone )
239         {
240             if( aPrefSize.Width > 0 && aPrefSize.Height > 0 && nVideoW > 0 && nVideoH > 0 )
241             {
242                 double fPrefWH = (double) aPrefSize.Width / aPrefSize.Height;
243 
244                 if( fPrefWH < ( (double) nVideoW / nVideoH ) )
245                     nVideoW = (int)( nVideoH * fPrefWH );
246                 else
247                     nVideoH = (int)( nVideoW / fPrefWH );
248 
249                 nX = ( nW - nVideoW ) >> 1;
250                 nY = ( nH - nVideoH ) >> 1;
251                 nWidth = nVideoW;
252                 nHeight = nVideoH;
253             }
254             else
255                 nX = nY = nWidth = nHeight = 0;
256         }
257 
258         /*
259         IVideoWindow* pVideoWindow = const_cast< IVideoWindow* >( mrPlayer.getVideoWindow() );
260 
261         if( pVideoWindow )
262             pVideoWindow->SetWindowPosition( nX, nY, nWidth, nHeight );
263         */
264     }
265 }
266 
267 // ------------------------------------------------------------------------------
268 
create(const uno::Sequence<uno::Any> &)269 bool Window::create( const uno::Sequence< uno::Any >& /*rArguments*/ )
270 {
271     bool bRet = false;
272 
273     return bRet;
274 }
275 
276 // ------------------------------------------------------------------------------
277 
update()278 void SAL_CALL Window::update(  )
279 {
280 }
281 
282 // ------------------------------------------------------------------------------
283 
setZoomLevel(media::ZoomLevel eZoomLevel)284 sal_Bool SAL_CALL Window::setZoomLevel( media::ZoomLevel eZoomLevel )
285 {
286     bool bRet = false;
287 
288     if( media::ZoomLevel_NOT_AVAILABLE != meZoomLevel &&
289         media::ZoomLevel_NOT_AVAILABLE != eZoomLevel )
290     {
291         if( eZoomLevel != meZoomLevel )
292         {
293             meZoomLevel = eZoomLevel;
294             implLayoutVideoWindow();
295         }
296 
297         bRet = true;
298     }
299 
300     return bRet;
301 }
302 
303 // ------------------------------------------------------------------------------
304 
getZoomLevel()305 media::ZoomLevel SAL_CALL Window::getZoomLevel(  )
306 {
307     return meZoomLevel;
308 }
309 
310 // ------------------------------------------------------------------------------
311 
setPointerType(sal_Int32 nPointerType)312 void SAL_CALL Window::setPointerType( sal_Int32 nPointerType )
313 {
314     mnPointerType = nPointerType;
315 }
316 
317 // ------------------------------------------------------------------------------
318 
setPosSize(sal_Int32,sal_Int32,sal_Int32,sal_Int32,sal_Int16)319 void SAL_CALL Window::setPosSize( sal_Int32 /*X*/, sal_Int32 /*Y*/, sal_Int32 /*Width*/, sal_Int32 /*Height*/, sal_Int16 /*Flags*/ )
320 {
321     implLayoutVideoWindow();
322 }
323 
324 // ------------------------------------------------------------------------------
325 
getPosSize()326 awt::Rectangle SAL_CALL Window::getPosSize()
327 {
328     awt::Rectangle aRet;
329 
330     return aRet;
331 }
332 
333 // ------------------------------------------------------------------------------
334 
setVisible(sal_Bool)335 void SAL_CALL Window::setVisible( sal_Bool /* bVisible */ )
336 {
337 }
338 
339 // ------------------------------------------------------------------------------
340 
setEnable(sal_Bool)341 void SAL_CALL Window::setEnable( sal_Bool /* bEnable */ )
342 {
343 }
344 
345 // ------------------------------------------------------------------------------
346 
setFocus()347 void SAL_CALL Window::setFocus(  )
348 {
349 }
350 
351 // ------------------------------------------------------------------------------
352 
addWindowListener(const uno::Reference<awt::XWindowListener> & xListener)353 void SAL_CALL Window::addWindowListener( const uno::Reference< awt::XWindowListener >& xListener )
354 {
355     maListeners.addInterface( getCppuType( &xListener ), xListener );
356 }
357 
358 // ------------------------------------------------------------------------------
359 
removeWindowListener(const uno::Reference<awt::XWindowListener> & xListener)360 void SAL_CALL Window::removeWindowListener( const uno::Reference< awt::XWindowListener >& xListener )
361 {
362     maListeners.removeInterface( getCppuType( &xListener ), xListener );
363 }
364 
365 // ------------------------------------------------------------------------------
366 
addFocusListener(const uno::Reference<awt::XFocusListener> & xListener)367 void SAL_CALL Window::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
368 {
369     maListeners.addInterface( getCppuType( &xListener ), xListener );
370 }
371 
372 // ------------------------------------------------------------------------------
373 
removeFocusListener(const uno::Reference<awt::XFocusListener> & xListener)374 void SAL_CALL Window::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
375 {
376     maListeners.removeInterface( getCppuType( &xListener ), xListener );
377 }
378 
379 // ------------------------------------------------------------------------------
380 
addKeyListener(const uno::Reference<awt::XKeyListener> & xListener)381 void SAL_CALL Window::addKeyListener( const uno::Reference< awt::XKeyListener >& xListener )
382 {
383     maListeners.addInterface( getCppuType( &xListener ), xListener );
384 }
385 
386 // ------------------------------------------------------------------------------
387 
removeKeyListener(const uno::Reference<awt::XKeyListener> & xListener)388 void SAL_CALL Window::removeKeyListener( const uno::Reference< awt::XKeyListener >& xListener )
389 {
390     maListeners.removeInterface( getCppuType( &xListener ), xListener );
391 }
392 
393 // ------------------------------------------------------------------------------
394 
addMouseListener(const uno::Reference<awt::XMouseListener> & xListener)395 void SAL_CALL Window::addMouseListener( const uno::Reference< awt::XMouseListener >& xListener )
396 {
397     maListeners.addInterface( getCppuType( &xListener ), xListener );
398 }
399 
400 // ------------------------------------------------------------------------------
401 
removeMouseListener(const uno::Reference<awt::XMouseListener> & xListener)402 void SAL_CALL Window::removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener )
403 {
404     maListeners.removeInterface( getCppuType( &xListener ), xListener );
405 }
406 
407 // ------------------------------------------------------------------------------
408 
addMouseMotionListener(const uno::Reference<awt::XMouseMotionListener> & xListener)409 void SAL_CALL Window::addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener )
410 {
411     maListeners.addInterface( getCppuType( &xListener ), xListener );
412 }
413 
414 // ------------------------------------------------------------------------------
415 
removeMouseMotionListener(const uno::Reference<awt::XMouseMotionListener> & xListener)416 void SAL_CALL Window::removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener )
417 {
418     maListeners.removeInterface( getCppuType( &xListener ), xListener );
419 }
420 
421 // ------------------------------------------------------------------------------
422 
addPaintListener(const uno::Reference<awt::XPaintListener> & xListener)423 void SAL_CALL Window::addPaintListener( const uno::Reference< awt::XPaintListener >& xListener )
424 {
425     maListeners.addInterface( getCppuType( &xListener ), xListener );
426 }
427 
428 // ------------------------------------------------------------------------------
429 
removePaintListener(const uno::Reference<awt::XPaintListener> & xListener)430 void SAL_CALL Window::removePaintListener( const uno::Reference< awt::XPaintListener >& xListener )
431 {
432     maListeners.removeInterface( getCppuType( &xListener ), xListener );
433 }
434 
435 // ------------------------------------------------------------------------------
436 
dispose()437 void SAL_CALL Window::dispose(  )
438 {
439 }
440 
441 // ------------------------------------------------------------------------------
442 
addEventListener(const uno::Reference<lang::XEventListener> & xListener)443 void SAL_CALL Window::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
444 {
445     maListeners.addInterface( getCppuType( &xListener ), xListener );
446 }
447 
448 // ------------------------------------------------------------------------------
449 
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)450 void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
451 {
452     maListeners.removeInterface( getCppuType( &xListener ), xListener );
453 }
454 
455 // ------------------------------------------------------------------------------
456 
fireMousePressedEvent(const::com::sun::star::awt::MouseEvent & rEvt)457 void Window::fireMousePressedEvent( const ::com::sun::star::awt::MouseEvent& rEvt )
458 {
459     ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseListener >*) 0 ) );
460 
461     if( pContainer )
462     {
463         ::cppu::OInterfaceIteratorHelper aIter( *pContainer );
464 
465         while( aIter.hasMoreElements() )
466             uno::Reference< awt::XMouseListener >( aIter.next(), uno::UNO_QUERY )->mousePressed( rEvt );
467     }
468 }
469 
470 // -----------------------------------------------------------------------------
471 
fireMouseReleasedEvent(const::com::sun::star::awt::MouseEvent & rEvt)472 void Window::fireMouseReleasedEvent( const ::com::sun::star::awt::MouseEvent& rEvt )
473 {
474     ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseListener >*) 0 ) );
475 
476     if( pContainer )
477     {
478         ::cppu::OInterfaceIteratorHelper aIter( *pContainer );
479 
480         while( aIter.hasMoreElements() )
481             uno::Reference< awt::XMouseListener >( aIter.next(), uno::UNO_QUERY )->mouseReleased( rEvt );
482     }
483 }
484 
485 // -----------------------------------------------------------------------------
486 
fireMouseMovedEvent(const::com::sun::star::awt::MouseEvent & rEvt)487 void Window::fireMouseMovedEvent( const ::com::sun::star::awt::MouseEvent& rEvt )
488 {
489     ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseMotionListener >*) 0 ) );
490 
491     if( pContainer )
492     {
493         ::cppu::OInterfaceIteratorHelper aIter( *pContainer );
494 
495         while( aIter.hasMoreElements() )
496             uno::Reference< awt::XMouseMotionListener >( aIter.next(), uno::UNO_QUERY )->mouseMoved( rEvt );
497     }
498 }
499 
500 // -----------------------------------------------------------------------------
501 
fireSetFocusEvent(const::com::sun::star::awt::FocusEvent & rEvt)502 void Window::fireSetFocusEvent( const ::com::sun::star::awt::FocusEvent& rEvt )
503 {
504     ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XFocusListener >*) 0 ) );
505 
506     if( pContainer )
507     {
508         ::cppu::OInterfaceIteratorHelper aIter( *pContainer );
509 
510         while( aIter.hasMoreElements() )
511             uno::Reference< awt::XFocusListener >( aIter.next(), uno::UNO_QUERY )->focusGained( rEvt );
512     }
513 }
514 
515 // ------------------------------------------------------------------------------
516 
getImplementationName()517 ::rtl::OUString SAL_CALL Window::getImplementationName(  )
518 {
519     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_XINE_WINDOW_IMPLEMENTATIONNAME ) );
520 }
521 
522 // ------------------------------------------------------------------------------
523 
supportsService(const::rtl::OUString & ServiceName)524 sal_Bool SAL_CALL Window::supportsService( const ::rtl::OUString& ServiceName )
525 {
526     return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_XINE_WINDOW_SERVICENAME ) );
527 }
528 
529 // ------------------------------------------------------------------------------
530 
getSupportedServiceNames()531 uno::Sequence< ::rtl::OUString > SAL_CALL Window::getSupportedServiceNames(  )
532 {
533     uno::Sequence< ::rtl::OUString > aRet(1);
534     aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_XINE_WINDOW_SERVICENAME ) );
535 
536     return aRet;
537 }
538 
539 } // namespace xine
540 } // namespace avmedia
541