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 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 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 174 Window::~Window() 175 { 176 } 177 178 // ------------------------------------------------------------------------------ 179 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 269 bool Window::create( const uno::Sequence< uno::Any >& /*rArguments*/ ) 270 { 271 bool bRet = false; 272 273 return bRet; 274 } 275 276 // ------------------------------------------------------------------------------ 277 278 void SAL_CALL Window::update( ) 279 throw (uno::RuntimeException) 280 { 281 } 282 283 // ------------------------------------------------------------------------------ 284 285 sal_Bool SAL_CALL Window::setZoomLevel( media::ZoomLevel eZoomLevel ) 286 throw (uno::RuntimeException) 287 { 288 bool bRet = false; 289 290 if( media::ZoomLevel_NOT_AVAILABLE != meZoomLevel && 291 media::ZoomLevel_NOT_AVAILABLE != eZoomLevel ) 292 { 293 if( eZoomLevel != meZoomLevel ) 294 { 295 meZoomLevel = eZoomLevel; 296 implLayoutVideoWindow(); 297 } 298 299 bRet = true; 300 } 301 302 return bRet; 303 } 304 305 // ------------------------------------------------------------------------------ 306 307 media::ZoomLevel SAL_CALL Window::getZoomLevel( ) 308 throw (uno::RuntimeException) 309 { 310 return meZoomLevel; 311 } 312 313 // ------------------------------------------------------------------------------ 314 315 void SAL_CALL Window::setPointerType( sal_Int32 nPointerType ) 316 throw (uno::RuntimeException) 317 { 318 mnPointerType = nPointerType; 319 } 320 321 // ------------------------------------------------------------------------------ 322 323 void SAL_CALL Window::setPosSize( sal_Int32 /*X*/, sal_Int32 /*Y*/, sal_Int32 /*Width*/, sal_Int32 /*Height*/, sal_Int16 /*Flags*/ ) 324 throw (uno::RuntimeException) 325 { 326 implLayoutVideoWindow(); 327 } 328 329 // ------------------------------------------------------------------------------ 330 331 awt::Rectangle SAL_CALL Window::getPosSize() 332 throw (uno::RuntimeException) 333 { 334 awt::Rectangle aRet; 335 336 return aRet; 337 } 338 339 // ------------------------------------------------------------------------------ 340 341 void SAL_CALL Window::setVisible( sal_Bool /* bVisible */ ) 342 throw (uno::RuntimeException) 343 { 344 } 345 346 // ------------------------------------------------------------------------------ 347 348 void SAL_CALL Window::setEnable( sal_Bool /* bEnable */ ) 349 throw (uno::RuntimeException) 350 { 351 } 352 353 // ------------------------------------------------------------------------------ 354 355 void SAL_CALL Window::setFocus( ) 356 throw (uno::RuntimeException) 357 { 358 } 359 360 // ------------------------------------------------------------------------------ 361 362 void SAL_CALL Window::addWindowListener( const uno::Reference< awt::XWindowListener >& xListener ) 363 throw (uno::RuntimeException) 364 { 365 maListeners.addInterface( getCppuType( &xListener ), xListener ); 366 } 367 368 // ------------------------------------------------------------------------------ 369 370 void SAL_CALL Window::removeWindowListener( const uno::Reference< awt::XWindowListener >& xListener ) 371 throw (uno::RuntimeException) 372 { 373 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 374 } 375 376 // ------------------------------------------------------------------------------ 377 378 void SAL_CALL Window::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) 379 throw (uno::RuntimeException) 380 { 381 maListeners.addInterface( getCppuType( &xListener ), xListener ); 382 } 383 384 // ------------------------------------------------------------------------------ 385 386 void SAL_CALL Window::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) 387 throw (uno::RuntimeException) 388 { 389 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 390 } 391 392 // ------------------------------------------------------------------------------ 393 394 void SAL_CALL Window::addKeyListener( const uno::Reference< awt::XKeyListener >& xListener ) 395 throw (uno::RuntimeException) 396 { 397 maListeners.addInterface( getCppuType( &xListener ), xListener ); 398 } 399 400 // ------------------------------------------------------------------------------ 401 402 void SAL_CALL Window::removeKeyListener( const uno::Reference< awt::XKeyListener >& xListener ) 403 throw (uno::RuntimeException) 404 { 405 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 406 } 407 408 // ------------------------------------------------------------------------------ 409 410 void SAL_CALL Window::addMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) 411 throw (uno::RuntimeException) 412 { 413 maListeners.addInterface( getCppuType( &xListener ), xListener ); 414 } 415 416 // ------------------------------------------------------------------------------ 417 418 void SAL_CALL Window::removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) 419 throw (uno::RuntimeException) 420 { 421 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 422 } 423 424 // ------------------------------------------------------------------------------ 425 426 void SAL_CALL Window::addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) 427 throw (uno::RuntimeException) 428 { 429 maListeners.addInterface( getCppuType( &xListener ), xListener ); 430 } 431 432 // ------------------------------------------------------------------------------ 433 434 void SAL_CALL Window::removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) 435 throw (uno::RuntimeException) 436 { 437 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 438 } 439 440 // ------------------------------------------------------------------------------ 441 442 void SAL_CALL Window::addPaintListener( const uno::Reference< awt::XPaintListener >& xListener ) 443 throw (uno::RuntimeException) 444 { 445 maListeners.addInterface( getCppuType( &xListener ), xListener ); 446 } 447 448 // ------------------------------------------------------------------------------ 449 450 void SAL_CALL Window::removePaintListener( const uno::Reference< awt::XPaintListener >& xListener ) 451 throw (uno::RuntimeException) 452 { 453 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 454 } 455 456 // ------------------------------------------------------------------------------ 457 458 void SAL_CALL Window::dispose( ) 459 throw (uno::RuntimeException) 460 { 461 } 462 463 // ------------------------------------------------------------------------------ 464 465 void SAL_CALL Window::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) 466 throw (uno::RuntimeException) 467 { 468 maListeners.addInterface( getCppuType( &xListener ), xListener ); 469 } 470 471 // ------------------------------------------------------------------------------ 472 473 void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) 474 throw (uno::RuntimeException) 475 { 476 maListeners.removeInterface( getCppuType( &xListener ), xListener ); 477 } 478 479 // ------------------------------------------------------------------------------ 480 481 void Window::fireMousePressedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ) 482 { 483 ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseListener >*) 0 ) ); 484 485 if( pContainer ) 486 { 487 ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); 488 489 while( aIter.hasMoreElements() ) 490 uno::Reference< awt::XMouseListener >( aIter.next(), uno::UNO_QUERY )->mousePressed( rEvt ); 491 } 492 } 493 494 // ----------------------------------------------------------------------------- 495 496 void Window::fireMouseReleasedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ) 497 { 498 ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseListener >*) 0 ) ); 499 500 if( pContainer ) 501 { 502 ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); 503 504 while( aIter.hasMoreElements() ) 505 uno::Reference< awt::XMouseListener >( aIter.next(), uno::UNO_QUERY )->mouseReleased( rEvt ); 506 } 507 } 508 509 // ----------------------------------------------------------------------------- 510 511 void Window::fireMouseMovedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ) 512 { 513 ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseMotionListener >*) 0 ) ); 514 515 if( pContainer ) 516 { 517 ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); 518 519 while( aIter.hasMoreElements() ) 520 uno::Reference< awt::XMouseMotionListener >( aIter.next(), uno::UNO_QUERY )->mouseMoved( rEvt ); 521 } 522 } 523 524 // ----------------------------------------------------------------------------- 525 526 void Window::fireSetFocusEvent( const ::com::sun::star::awt::FocusEvent& rEvt ) 527 { 528 ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XFocusListener >*) 0 ) ); 529 530 if( pContainer ) 531 { 532 ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); 533 534 while( aIter.hasMoreElements() ) 535 uno::Reference< awt::XFocusListener >( aIter.next(), uno::UNO_QUERY )->focusGained( rEvt ); 536 } 537 } 538 539 // ------------------------------------------------------------------------------ 540 541 ::rtl::OUString SAL_CALL Window::getImplementationName( ) 542 throw (uno::RuntimeException) 543 { 544 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_XINE_WINDOW_IMPLEMENTATIONNAME ) ); 545 } 546 547 // ------------------------------------------------------------------------------ 548 549 sal_Bool SAL_CALL Window::supportsService( const ::rtl::OUString& ServiceName ) 550 throw (uno::RuntimeException) 551 { 552 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_XINE_WINDOW_SERVICENAME ) ); 553 } 554 555 // ------------------------------------------------------------------------------ 556 557 uno::Sequence< ::rtl::OUString > SAL_CALL Window::getSupportedServiceNames( ) 558 throw (uno::RuntimeException) 559 { 560 uno::Sequence< ::rtl::OUString > aRet(1); 561 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_XINE_WINDOW_SERVICENAME ) ); 562 563 return aRet; 564 } 565 566 } // namespace xine 567 } // namespace avmedia 568