LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/avmedia/source/viewer - mediawindow_impl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 226 0.4 %
Date: 2013-07-09 Functions: 2 36 5.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "mediawindow_impl.hxx"
      21             : #include "mediaevent_impl.hxx"
      22             : #include "mediamisc.hxx"
      23             : #include "mediawindow.hrc"
      24             : #include "helpids.hrc"
      25             : 
      26             : #include <algorithm>
      27             : #include <cmath>
      28             : #include <osl/mutex.hxx>
      29             : #include <vcl/svapp.hxx>
      30             : #ifdef UNX
      31             : #include <vcl/sysdata.hxx>
      32             : #endif
      33             : 
      34             : #include <com/sun/star/awt/SystemPointer.hpp>
      35             : #include <com/sun/star/lang/XComponent.hpp>
      36             : 
      37             : using namespace ::com::sun::star;
      38             : 
      39             : namespace avmedia { namespace priv {
      40             : 
      41             : // ----------------------
      42             : // - MediaWindowControl -
      43             : // ----------------------
      44             : 
      45           0 : MediaWindowControl::MediaWindowControl( Window* pParent ) :
      46           0 :     MediaControl( pParent, MEDIACONTROLSTYLE_MULTILINE )
      47             : {
      48           0 : }
      49             : 
      50             : // ---------------------------------------------------------------------
      51             : 
      52           0 : MediaWindowControl::~MediaWindowControl()
      53             : {
      54           0 : }
      55             : 
      56             : // ---------------------------------------------------------------------
      57             : 
      58           0 : void MediaWindowControl::update()
      59             : {
      60           0 :     MediaItem aItem;
      61             : 
      62           0 :     static_cast< MediaWindowImpl* >( GetParent() )->updateMediaItem( aItem );
      63           0 :     setState( aItem );
      64           0 : }
      65             : 
      66             : // ---------------------------------------------------------------------
      67             : 
      68           0 : void  MediaWindowControl::execute( const MediaItem& rItem )
      69             : {
      70           0 :     static_cast< MediaWindowImpl* >( GetParent() )->executeMediaItem( rItem );
      71           0 : }
      72             : 
      73             : // --------------------
      74             : // - MediaChildWindow -
      75             : // --------------------
      76             : 
      77           0 : MediaChildWindow::MediaChildWindow( Window* pParent ) :
      78           0 :     SystemChildWindow( pParent, WB_CLIPCHILDREN )
      79             : {
      80           0 : }
      81             : 
      82             : // ---------------------------------------------------------------------
      83             : 
      84           0 : MediaChildWindow::~MediaChildWindow()
      85             : {
      86           0 : }
      87             : 
      88             : // ---------------------------------------------------------------------
      89             : 
      90           0 : void MediaChildWindow::MouseMove( const MouseEvent& rMEvt )
      91             : {
      92           0 :     const MouseEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rMEvt.GetPosPixel() ) ),
      93           0 :                                           rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() );
      94             : 
      95           0 :     SystemChildWindow::MouseMove( rMEvt );
      96           0 :     GetParent()->MouseMove( aTransformedEvent );
      97           0 : }
      98             : 
      99             : // ---------------------------------------------------------------------
     100             : 
     101           0 : void MediaChildWindow::MouseButtonDown( const MouseEvent& rMEvt )
     102             : {
     103           0 :     const MouseEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rMEvt.GetPosPixel() ) ),
     104           0 :                                           rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() );
     105             : 
     106           0 :     SystemChildWindow::MouseButtonDown( rMEvt );
     107           0 :     GetParent()->MouseButtonDown( aTransformedEvent );
     108           0 : }
     109             : 
     110             : // ---------------------------------------------------------------------
     111             : 
     112           0 : void MediaChildWindow::MouseButtonUp( const MouseEvent& rMEvt )
     113             : {
     114           0 :     const MouseEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rMEvt.GetPosPixel() ) ),
     115           0 :                                           rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() );
     116             : 
     117           0 :     SystemChildWindow::MouseButtonUp( rMEvt );
     118           0 :     GetParent()->MouseButtonUp( aTransformedEvent );
     119           0 : }
     120             : 
     121             : // ---------------------------------------------------------------------
     122             : 
     123           0 : void MediaChildWindow::KeyInput( const KeyEvent& rKEvt )
     124             : {
     125           0 :     SystemChildWindow::KeyInput( rKEvt );
     126           0 :     GetParent()->KeyInput( rKEvt );
     127           0 : }
     128             : 
     129             : // ---------------------------------------------------------------------
     130             : 
     131           0 : void MediaChildWindow::KeyUp( const KeyEvent& rKEvt )
     132             : {
     133           0 :     SystemChildWindow::KeyUp( rKEvt );
     134           0 :     GetParent()->KeyUp( rKEvt );
     135           0 : }
     136             : 
     137             : // ---------------------------------------------------------------------
     138             : 
     139           0 : void MediaChildWindow::Command( const CommandEvent& rCEvt )
     140             : {
     141           0 :     const CommandEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rCEvt.GetMousePosPixel() ) ),
     142           0 :                                             rCEvt.GetCommand(), rCEvt.IsMouseEvent(), rCEvt.GetData() );
     143             : 
     144           0 :     SystemChildWindow::Command( rCEvt );
     145           0 :     GetParent()->Command( aTransformedEvent );
     146           0 : }
     147             : 
     148             : // ----------------------
     149             : // - MediaWindowImpl -
     150             : // ----------------------
     151             : 
     152           0 : MediaWindowImpl::MediaWindowImpl( Window* pParent, MediaWindow* pMediaWindow, bool bInternalMediaControl ) :
     153             :     Control( pParent ),
     154             :     MediaWindowBaseImpl( pMediaWindow ),
     155             :     DropTargetHelper( this ),
     156             :     DragSourceHelper( this ),
     157           0 :     mxEventsIf( static_cast< ::cppu::OWeakObject* >( mpEvents = new MediaEventListenersImpl( maChildWindow ) ) ),
     158             :     maChildWindow( this ),
     159           0 :     mpMediaWindowControl( bInternalMediaControl ? new MediaWindowControl( this ) : NULL ),
     160             :     mpEmptyBmpEx( NULL ),
     161           0 :     mpAudioBmpEx( NULL )
     162             : {
     163           0 :     maChildWindow.SetBackground( Color( COL_BLACK ) );
     164           0 :     maChildWindow.SetHelpId( HID_AVMEDIA_PLAYERWINDOW );
     165           0 :     maChildWindow.Hide();
     166             : 
     167           0 :     if( mpMediaWindowControl )
     168             :     {
     169           0 :         mpMediaWindowControl->SetSizePixel( mpMediaWindowControl->getMinSizePixel() );
     170           0 :         mpMediaWindowControl->Show();
     171             :     }
     172           0 : }
     173             : 
     174             : // ---------------------------------------------------------------------
     175             : 
     176           0 : MediaWindowImpl::~MediaWindowImpl()
     177             : {
     178           0 :     delete mpEmptyBmpEx;
     179           0 :     delete mpAudioBmpEx;
     180           0 :     delete mpMediaWindowControl;
     181           0 : }
     182             : 
     183             : // ---------------------------------------------------------------------
     184             : 
     185           0 : void MediaWindowImpl::cleanUp()
     186             : {
     187           0 :     uno::Reference< media::XPlayerWindow > xPlayerWindow( getPlayerWindow() );
     188             : 
     189           0 :     mpEvents->cleanUp();
     190             : 
     191           0 :     if( xPlayerWindow.is() )
     192             :     {
     193           0 :         xPlayerWindow->removeKeyListener( uno::Reference< awt::XKeyListener >( mxEventsIf, uno::UNO_QUERY ) );
     194           0 :         xPlayerWindow->removeMouseListener( uno::Reference< awt::XMouseListener >( mxEventsIf, uno::UNO_QUERY ) );
     195           0 :         xPlayerWindow->removeMouseMotionListener( uno::Reference< awt::XMouseMotionListener >( mxEventsIf, uno::UNO_QUERY ) );
     196             : 
     197           0 :         uno::Reference< lang::XComponent > xComponent( xPlayerWindow, uno::UNO_QUERY );
     198           0 :         if( xComponent.is() )
     199           0 :             xComponent->dispose();
     200             : 
     201           0 :         setPlayerWindow( NULL );
     202             :     }
     203             : 
     204           0 :     MediaWindowBaseImpl::cleanUp();
     205           0 : }
     206             : 
     207             : // ---------------------------------------------------------------------
     208             : 
     209           0 : void MediaWindowImpl::onURLChanged()
     210             : {
     211           0 :     if( getPlayer().is() )
     212             :     {
     213           0 :         uno::Sequence< uno::Any >              aArgs( 3 );
     214           0 :         uno::Reference< media::XPlayerWindow > xPlayerWindow;
     215           0 :         const Point                            aPoint;
     216           0 :         const Size                             aSize( maChildWindow.GetSizePixel() );
     217           0 :         const sal_Int32                        nWndHandle = 0;
     218             : 
     219           0 :         aArgs[ 0 ] = uno::makeAny( nWndHandle );
     220           0 :         aArgs[ 1 ] = uno::makeAny( awt::Rectangle( aPoint.X(), aPoint.Y(), aSize.Width(), aSize.Height() ) );
     221           0 :         aArgs[ 2 ] = uno::makeAny( reinterpret_cast< sal_IntPtr >( &maChildWindow ) );
     222             : 
     223             :         try
     224             :         {
     225           0 :             xPlayerWindow = getPlayer()->createPlayerWindow( aArgs );
     226             :         }
     227           0 :         catch( uno::RuntimeException )
     228             :         {
     229             :             // happens eg, on MacOSX where Java frames cannot be created from X11 window handles
     230             :         }
     231             : 
     232           0 :         setPlayerWindow( xPlayerWindow );
     233             : 
     234           0 :         if( xPlayerWindow.is() )
     235             :         {
     236           0 :             xPlayerWindow->addKeyListener( uno::Reference< awt::XKeyListener >( mxEventsIf, uno::UNO_QUERY ) );
     237           0 :             xPlayerWindow->addMouseListener( uno::Reference< awt::XMouseListener >( mxEventsIf, uno::UNO_QUERY ) );
     238           0 :             xPlayerWindow->addMouseMotionListener( uno::Reference< awt::XMouseMotionListener >( mxEventsIf, uno::UNO_QUERY ) );
     239           0 :             xPlayerWindow->addFocusListener( uno::Reference< awt::XFocusListener >( mxEventsIf, uno::UNO_QUERY ) );
     240           0 :         }
     241             :     }
     242             :     else
     243           0 :         setPlayerWindow( NULL );
     244             : 
     245           0 :     if( getPlayerWindow().is() )
     246           0 :         maChildWindow.Show();
     247             :     else
     248           0 :         maChildWindow.Hide();
     249             : 
     250           0 :     if( mpMediaWindowControl )
     251             :     {
     252           0 :         MediaItem aItem;
     253             : 
     254           0 :         updateMediaItem( aItem );
     255           0 :         mpMediaWindowControl->setState( aItem );
     256             :     }
     257           0 : }
     258             : 
     259             : // ---------------------------------------------------------------------
     260             : 
     261           0 : void MediaWindowImpl::setPosSize( const Rectangle& rRect )
     262             : {
     263           0 :     SetPosSizePixel( rRect.TopLeft(), rRect.GetSize() );
     264           0 : }
     265             : 
     266             : // ---------------------------------------------------------------------
     267             : 
     268           0 : void MediaWindowImpl::setPointer( const Pointer& rPointer )
     269             : {
     270           0 :     uno::Reference< media::XPlayerWindow >  xPlayerWindow( getPlayerWindow() );
     271             : 
     272           0 :     SetPointer( rPointer );
     273           0 :     maChildWindow.SetPointer( rPointer );
     274             : 
     275           0 :     if( xPlayerWindow.is() )
     276             :     {
     277             :         long nPointer;
     278             : 
     279           0 :         switch( rPointer.GetStyle() )
     280             :         {
     281           0 :             case( POINTER_CROSS ): nPointer = awt::SystemPointer::CROSS; break;
     282           0 :             case( POINTER_HAND ): nPointer = awt::SystemPointer::HAND; break;
     283           0 :             case( POINTER_MOVE ): nPointer = awt::SystemPointer::MOVE; break;
     284           0 :             case( POINTER_WAIT ): nPointer = awt::SystemPointer::WAIT; break;
     285             : 
     286           0 :             default: nPointer = awt::SystemPointer::ARROW; break;
     287             :         }
     288             : 
     289           0 :         xPlayerWindow->setPointerType( nPointer );
     290           0 :     }
     291           0 : }
     292             : 
     293             : // ---------------------------------------------------------------------
     294             : 
     295           0 : void MediaWindowImpl::Resize()
     296             : {
     297           0 :     uno::Reference< media::XPlayerWindow >  xPlayerWindow( getPlayerWindow() );
     298           0 :     const Size                              aCurSize( GetOutputSizePixel() );
     299           0 :     const sal_Int32                         nOffset( mpMediaWindowControl ? AVMEDIA_CONTROLOFFSET : 0 );
     300           0 :     Size                                    aPlayerWindowSize( aCurSize.Width() - ( nOffset << 1 ),
     301           0 :                                                                aCurSize.Height() - ( nOffset << 1 ) );
     302             : 
     303           0 :     if( mpMediaWindowControl )
     304             :     {
     305           0 :         const sal_Int32 nControlHeight = mpMediaWindowControl->GetSizePixel().Height();
     306           0 :         const sal_Int32 nControlY = ::std::max( aCurSize.Height() - nControlHeight - nOffset, 0L );
     307             : 
     308           0 :         aPlayerWindowSize.Height() = ( nControlY - ( nOffset << 1 ) );
     309           0 :         mpMediaWindowControl->SetPosSizePixel( Point( nOffset, nControlY ), Size( aCurSize.Width() - ( nOffset << 1 ), nControlHeight ) );
     310             :     }
     311             : 
     312           0 :     if( xPlayerWindow.is() )
     313           0 :         xPlayerWindow->setPosSize( 0, 0, aPlayerWindowSize.Width(), aPlayerWindowSize.Height(), 0 );
     314             : 
     315           0 :     maChildWindow.SetPosSizePixel( Point( nOffset, nOffset ), aPlayerWindowSize );
     316           0 : }
     317             : 
     318             : // ---------------------------------------------------------------------
     319             : 
     320           0 : void MediaWindowImpl::StateChanged( StateChangedType eType )
     321             : {
     322           0 :     uno::Reference< media::XPlayerWindow > xPlayerWindow( getPlayerWindow() );
     323             : 
     324           0 :     if( xPlayerWindow.is() )
     325             :     {
     326             :         // stop playing when going disabled or hidden
     327           0 :         switch( eType )
     328             :         {
     329             :             case STATE_CHANGE_VISIBLE:
     330             :             {
     331           0 :                 stopPlayingInternal( !IsVisible() );
     332           0 :                 xPlayerWindow->setVisible( IsVisible() );
     333             :             }
     334           0 :             break;
     335             : 
     336             :             case STATE_CHANGE_ENABLE:
     337             :             {
     338           0 :                 stopPlayingInternal( !IsEnabled() );
     339           0 :                 xPlayerWindow->setEnable( IsEnabled() );
     340             :             }
     341           0 :             break;
     342             : 
     343             :             default:
     344           0 :             break;
     345             :         }
     346           0 :     }
     347           0 : }
     348             : 
     349             : // ---------------------------------------------------------------------
     350             : 
     351           0 : void MediaWindowImpl::Paint( const Rectangle& )
     352             : {
     353           0 :     BitmapEx* pLogo = NULL;
     354             : 
     355           0 :     if( !getPlayer().is() )
     356             :     {
     357           0 :         if( !mpEmptyBmpEx )
     358           0 :             mpEmptyBmpEx = new BitmapEx( AVMEDIA_RESID( AVMEDIA_BMP_EMPTYLOGO ) );
     359             : 
     360           0 :         pLogo = mpEmptyBmpEx;
     361             :     }
     362           0 :     else if( !getPlayerWindow().is() )
     363             :     {
     364           0 :         if( !mpAudioBmpEx )
     365           0 :             mpAudioBmpEx = new BitmapEx( AVMEDIA_RESID( AVMEDIA_BMP_AUDIOLOGO ) );
     366             : 
     367           0 :         pLogo = mpAudioBmpEx;
     368             :     }
     369             : 
     370           0 :     const Point     aBasePos( maChildWindow.GetPosPixel() );
     371           0 :     const Rectangle aVideoRect( aBasePos, maChildWindow.GetSizePixel() );
     372             : 
     373           0 :     if( pLogo && !pLogo->IsEmpty() && ( aVideoRect.GetWidth() > 0 ) && ( aVideoRect.GetHeight() > 0 ) )
     374             :     {
     375           0 :         Size        aLogoSize( pLogo->GetSizePixel() );
     376           0 :         const Color aBackgroundColor( 67, 67, 67 );
     377             : 
     378           0 :         SetLineColor( aBackgroundColor );
     379           0 :         SetFillColor( aBackgroundColor );
     380           0 :         DrawRect( aVideoRect );
     381             : 
     382           0 :         if( ( aLogoSize.Width() > aVideoRect.GetWidth() || aLogoSize.Height() > aVideoRect.GetHeight() ) &&
     383           0 :             ( aLogoSize.Height() > 0 ) )
     384             :         {
     385           0 :             const double fLogoWH = (double) aLogoSize.Width() / aLogoSize.Height();
     386             : 
     387           0 :             if( fLogoWH < ( (double) aVideoRect.GetWidth() / aVideoRect.GetHeight() ) )
     388             :             {
     389           0 :                 aLogoSize.Width() = (long) ( aVideoRect.GetHeight() * fLogoWH );
     390           0 :                 aLogoSize.Height()= aVideoRect.GetHeight();
     391             :             }
     392             :             else
     393             :             {
     394           0 :                 aLogoSize.Width() = aVideoRect.GetWidth();
     395           0 :                 aLogoSize.Height()= (long) ( aVideoRect.GetWidth() / fLogoWH );
     396             :             }
     397             :         }
     398             : 
     399           0 :         DrawBitmapEx( Point( aBasePos.X() + ( ( aVideoRect.GetWidth() - aLogoSize.Width() ) >> 1 ),
     400           0 :                              aBasePos.Y() + ( ( aVideoRect.GetHeight() - aLogoSize.Height() ) >> 1 ) ),
     401           0 :                       aLogoSize, *pLogo );
     402             :     }
     403           0 : }
     404             : 
     405             : // ---------------------------------------------------------------------
     406             : 
     407           0 : void MediaWindowImpl::GetFocus()
     408             : {
     409           0 : }
     410             : 
     411             : // ---------------------------------------------------------------------
     412             : 
     413           0 : void MediaWindowImpl::MouseMove( const MouseEvent& rMEvt )
     414             : {
     415           0 :     MediaWindow* pMediaWindow = getMediaWindow();
     416             : 
     417           0 :     if( pMediaWindow )
     418           0 :         pMediaWindow->MouseMove( rMEvt );
     419           0 : }
     420             : 
     421             : // ---------------------------------------------------------------------
     422             : 
     423           0 : void MediaWindowImpl::MouseButtonDown( const MouseEvent& rMEvt )
     424             : {
     425           0 :     MediaWindow* pMediaWindow = getMediaWindow();
     426             : 
     427           0 :     if( pMediaWindow )
     428           0 :         pMediaWindow->MouseButtonDown( rMEvt );
     429           0 : }
     430             : 
     431             : // ---------------------------------------------------------------------
     432             : 
     433           0 : void MediaWindowImpl::MouseButtonUp( const MouseEvent& rMEvt )
     434             : {
     435           0 :     MediaWindow* pMediaWindow = getMediaWindow();
     436             : 
     437           0 :     if( pMediaWindow )
     438           0 :         pMediaWindow->MouseButtonUp( rMEvt );
     439           0 : }
     440             : 
     441             : // ---------------------------------------------------------------------
     442             : 
     443           0 : void MediaWindowImpl::KeyInput( const KeyEvent& rKEvt )
     444             : {
     445           0 :     MediaWindow* pMediaWindow = getMediaWindow();
     446             : 
     447           0 :     if( pMediaWindow )
     448           0 :         pMediaWindow->KeyInput( rKEvt );
     449           0 : }
     450             : 
     451             : // ---------------------------------------------------------------------
     452             : 
     453           0 : void MediaWindowImpl::KeyUp( const KeyEvent& rKEvt )
     454             : {
     455           0 :     MediaWindow* pMediaWindow = getMediaWindow();
     456             : 
     457           0 :     if( pMediaWindow )
     458           0 :         pMediaWindow->KeyUp( rKEvt );
     459           0 : }
     460             : 
     461             : // ---------------------------------------------------------------------
     462             : 
     463           0 : void MediaWindowImpl::Command( const CommandEvent& rCEvt )
     464             : {
     465           0 :     MediaWindow* pMediaWindow = getMediaWindow();
     466             : 
     467           0 :     if( pMediaWindow )
     468           0 :         pMediaWindow->Command( rCEvt );
     469           0 : }
     470             : 
     471             : // ---------------------------------------------------------------------
     472             : 
     473           0 : sal_Int8 MediaWindowImpl::AcceptDrop( const AcceptDropEvent& rEvt )
     474             : {
     475           0 :     MediaWindow* pMediaWindow = getMediaWindow();
     476           0 :     return( pMediaWindow ? pMediaWindow->AcceptDrop( rEvt ) : 0 );
     477             : }
     478             : 
     479             : // ---------------------------------------------------------------------
     480             : 
     481           0 : sal_Int8 MediaWindowImpl::ExecuteDrop( const ExecuteDropEvent& rEvt )
     482             : {
     483           0 :     MediaWindow* pMediaWindow = getMediaWindow();
     484           0 :     return( pMediaWindow ? pMediaWindow->ExecuteDrop( rEvt ) : 0 );
     485             : }
     486             : 
     487             : // ---------------------------------------------------------------------
     488             : 
     489           0 : void MediaWindowImpl::StartDrag( sal_Int8 nAction, const Point& rPosPixel )
     490             : {
     491           0 :     MediaWindow* pMediaWindow = getMediaWindow();
     492             : 
     493           0 :     if( pMediaWindow )
     494           0 :         pMediaWindow->StartDrag( nAction, rPosPixel );
     495           0 : }
     496             : 
     497             : } // namespace priv
     498         258 : } // namespace avmedia
     499             : 
     500             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10