1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>

#include <iostream>
#include "mediawindow_impl.hxx"
#include "mediaevent_impl.hxx"
#include <mediamisc.hxx>
#include <bitmaps.hlst>
#include <helpids.h>

#include <algorithm>
#include <cmath>

#include <sal/log.hxx>
#include <comphelper/processfactory.hxx>
#include <tools/urlobj.hxx>
#include <unotools/securityoptions.hxx>
#include <vcl/svapp.hxx>

#include <com/sun/star/awt/SystemPointer.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/media/XManager.hpp>
#include <vcl/sysdata.hxx>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLContext.hxx>
#endif
using namespace ::com::sun::star;

namespace avmedia { namespace priv {

MediaWindowControl::MediaWindowControl(vcl::Window* pParent)
    : MediaControl(pParent, MEDIACONTROLSTYLE_MULTILINE)
{
}

void MediaWindowControl::update()
{
    MediaItem aItem;

    static_cast< MediaWindowImpl* >( GetParent() )->updateMediaItem( aItem );
    setState(aItem);
}

void MediaWindowControl::execute(const MediaItem& rItem)
{
    static_cast<MediaWindowImpl*>(GetParent())->executeMediaItem(rItem);
}

MediaChildWindow::MediaChildWindow(vcl::Window* pParent)
    : SystemChildWindow(pParent, WB_CLIPCHILDREN)
{
}

void MediaChildWindow::MouseMove( const MouseEvent& rMEvt )
{
    const MouseEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rMEvt.GetPosPixel() ) ),
                                          rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() );

    SystemChildWindow::MouseMove( rMEvt );
    GetParent()->MouseMove( aTransformedEvent );
}

void MediaChildWindow::MouseButtonDown( const MouseEvent& rMEvt )
{
    const MouseEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rMEvt.GetPosPixel() ) ),
                                          rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() );

    SystemChildWindow::MouseButtonDown( rMEvt );
    GetParent()->MouseButtonDown( aTransformedEvent );
}

void MediaChildWindow::MouseButtonUp( const MouseEvent& rMEvt )
{
    const MouseEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rMEvt.GetPosPixel() ) ),
                                          rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() );

    SystemChildWindow::MouseButtonUp( rMEvt );
    GetParent()->MouseButtonUp( aTransformedEvent );
}

void MediaChildWindow::KeyInput( const KeyEvent& rKEvt )
{
    SystemChildWindow::KeyInput( rKEvt );
    GetParent()->KeyInput( rKEvt );
}

void MediaChildWindow::KeyUp( const KeyEvent& rKEvt )
{
    SystemChildWindow::KeyUp( rKEvt );
    GetParent()->KeyUp( rKEvt );
}

void MediaChildWindow::Command( const CommandEvent& rCEvt )
{
    const CommandEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rCEvt.GetMousePosPixel() ) ),
                                          rCEvt.GetCommand(), rCEvt.IsMouseEvent(), rCEvt.GetEventData() );

    SystemChildWindow::Command( rCEvt );
    GetParent()->Command( aTransformedEvent );
}

MediaWindowImpl::MediaWindowImpl(vcl::Window* pParent, MediaWindow* pMediaWindow, bool bInternalMediaControl)
    : Control(pParent)
    , DropTargetHelper(this)
    , DragSourceHelper(this)
    , mpMediaWindow(pMediaWindow)
    , mpMediaWindowControl(bInternalMediaControl ? VclPtr<MediaWindowControl>::Create(this) : nullptr)
    , mpEmptyBmpEx(nullptr)
    , mpAudioBmpEx(nullptr)
{
    if (mpMediaWindowControl)
    {
        mpMediaWindowControl->SetSizePixel(mpMediaWindowControl->getMinSizePixel());
        mpMediaWindowControl->Show();
    }
}

MediaWindowImpl::~MediaWindowImpl()
{
    disposeOnce();
}

void MediaWindowImpl::dispose()
{
    if (mxEvents.is())
        mxEvents->cleanUp();

    if (mxPlayerWindow.is())
    {
        auto pEventsIf = static_cast<cppu::OWeakObject*>(mxEvents.get());
        mxPlayerWindow->removeKeyListener( uno::Reference< awt::XKeyListener >( pEventsIf, uno::UNO_QUERY ) );
        mxPlayerWindow->removeMouseListener( uno::Reference< awt::XMouseListener >( pEventsIf, uno::UNO_QUERY ) );
        mxPlayerWindow->removeMouseMotionListener( uno::Reference< awt::XMouseMotionListener >( pEventsIf, uno::UNO_QUERY ) );

        uno::Reference< lang::XComponent > xComponent( mxPlayerWindow, uno::UNO_QUERY );
        if (xComponent.is())
            xComponent->dispose();

        mxPlayerWindow.clear();
    }

    uno::Reference< lang::XComponent > xComponent( mxPlayer, uno::UNO_QUERY );
    if (xComponent.is()) // this stops the player
        xComponent->dispose();

    mxPlayer.clear();

    mpMediaWindow = nullptr;

    mpEmptyBmpEx.reset();
    mpAudioBmpEx.reset();
    mpMediaWindowControl.disposeAndClear();
    mpChildWindow.disposeAndClear();

    Control::dispose();
}

uno::Reference<media::XPlayer> MediaWindowImpl::createPlayer(const OUString& rURL, const OUString& rReferer, const OUString* pMimeType)
{
    uno::Reference<media::XPlayer> xPlayer;

    if( rURL.isEmpty() )
        return xPlayer;

    if (SvtSecurityOptions().isUntrustedReferer(rReferer))
    {
        return xPlayer;
    }
    uno::Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext());

    if (!pMimeType || *pMimeType == AVMEDIA_MIMETYPE_COMMON)
    {

        static const char * aServiceManagers[] =
        {
            AVMEDIA_MANAGER_SERVICE_PREFERRED,
            AVMEDIA_MANAGER_SERVICE_NAME,
// a fallback path just for gstreamer which has
// two significant versions deployed at once ...
#ifdef AVMEDIA_MANAGER_SERVICE_NAME_OLD
            AVMEDIA_MANAGER_SERVICE_NAME_OLD<--- Skipping configuration 'AVMEDIA_MANAGER_SERVICE_NAME_OLD' since the value of 'AVMEDIA_MANAGER_SERVICE_NAME_OLD' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
#endif
// fallback to AVMedia framework on OS X
#ifdef AVMEDIA_MANAGER_SERVICE_NAME_FALLBACK1
            AVMEDIA_MANAGER_SERVICE_NAME_FALLBACK1<--- Skipping configuration 'AVMEDIA_MANAGER_SERVICE_NAME_FALLBACK1' since the value of 'AVMEDIA_MANAGER_SERVICE_NAME_FALLBACK1' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
#endif
        };

        for (sal_uInt32 i = 0; !xPlayer.is() && i < SAL_N_ELEMENTS( aServiceManagers ); ++i)
        {
            const OUString aServiceName(aServiceManagers[i],
                                        strlen( aServiceManagers[i]),
                                        RTL_TEXTENCODING_ASCII_US);

            xPlayer = createPlayer(rURL, aServiceName, xContext);
        }
    }

    return xPlayer;
}

uno::Reference< media::XPlayer > MediaWindowImpl::createPlayer(
    const OUString& rURL, const OUString& rManagerServName,
    const uno::Reference< uno::XComponentContext >& xContext)
{
    uno::Reference< media::XPlayer > xPlayer;
    try
    {
        uno::Reference< media::XManager > xManager (
            xContext->getServiceManager()->createInstanceWithContext(rManagerServName, xContext),
            uno::UNO_QUERY );
        if( xManager.is() )
            xPlayer.set( xManager->createPlayer( rURL ), uno::UNO_QUERY );
        else
            SAL_INFO( "avmedia", "failed to create media player service " << rManagerServName );
    } catch ( const uno::Exception &e )
    {
        SAL_WARN( "avmedia", "couldn't create media player " << rManagerServName << ", " << e);
    }
    return xPlayer;
}

void MediaWindowImpl::setURL( const OUString& rURL,
        OUString const& rTempURL, OUString const& rReferer)
{
    maReferer = rReferer;
    if( rURL != getURL() )
    {
        if( mxPlayer.is() )
            mxPlayer->stop();

        if( mxPlayerWindow.is() )
        {
            mxPlayerWindow->setVisible( false );
            mxPlayerWindow.clear();
        }

        mxPlayer.clear();
        mTempFileURL.clear();

        if (!rTempURL.isEmpty())
        {
            maFileURL = rURL;
            mTempFileURL = rTempURL;
        }
        else
        {
            INetURLObject aURL( rURL );

            if (aURL.GetProtocol() != INetProtocol::NotValid)
                maFileURL = aURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous);
            else
                maFileURL = rURL;
        }

        mxPlayer = createPlayer((!mTempFileURL.isEmpty()) ? mTempFileURL : maFileURL, rReferer, &m_sMimeType );
        onURLChanged();
    }
}

const OUString& MediaWindowImpl::getURL() const
{
    return maFileURL;
}

bool MediaWindowImpl::isValid() const
{
    return mxPlayer.is();
}

Size MediaWindowImpl::getPreferredSize() const
{
    Size aRet(480, 360);

    if( mxPlayer.is() )
    {
        awt::Size aPrefSize( mxPlayer->getPreferredPlayerWindowSize() );

        aRet.setWidth( aPrefSize.Width );
        aRet.setHeight( aPrefSize.Height );
    }

    return aRet;
}

bool MediaWindowImpl::start()
{
    return mxPlayer.is() && ( mxPlayer->start(), true );
}

void MediaWindowImpl::updateMediaItem( MediaItem& rItem ) const
{
    if( isPlaying() )
        rItem.setState( MediaState::Play );
    else
        rItem.setState( ( getMediaTime() == 0.0 ) ? MediaState::Stop : MediaState::Pause );

    rItem.setDuration( getDuration() );
    rItem.setTime( getMediaTime() );
    rItem.setLoop( mxPlayer.is() && mxPlayer->isPlaybackLoop() );
    rItem.setMute( mxPlayer.is() && mxPlayer->isMute() );
    rItem.setVolumeDB( mxPlayer.is() ? mxPlayer->getVolumeDB() : 0 );
    rItem.setZoom( mxPlayerWindow.is() ? mxPlayerWindow->getZoomLevel() : media::ZoomLevel_NOT_AVAILABLE );
    rItem.setURL( getURL(), mTempFileURL, maReferer );
}

void MediaWindowImpl::executeMediaItem( const MediaItem& rItem )
{
    const AVMediaSetMask nMaskSet = rItem.getMaskSet();

    // set URL first
    if (nMaskSet & AVMediaSetMask::URL)
    {
        m_sMimeType = rItem.getMimeType();
        setURL(rItem.getURL(), rItem.getTempURL(), rItem.getReferer());
    }

    // set different states next
    if (nMaskSet & AVMediaSetMask::TIME)
        setMediaTime(std::min(rItem.getTime(), getDuration()));

    if (nMaskSet & AVMediaSetMask::LOOP && mxPlayer.is() )
        mxPlayer->setPlaybackLoop( rItem.isLoop() );

    if (nMaskSet & AVMediaSetMask::MUTE && mxPlayer.is() )
        mxPlayer->setMute( rItem.isMute() );

    if (nMaskSet & AVMediaSetMask::VOLUMEDB && mxPlayer.is() )
        mxPlayer->setVolumeDB( rItem.getVolumeDB() );

    if (nMaskSet & AVMediaSetMask::ZOOM && mxPlayerWindow.is() )
        mxPlayerWindow->setZoomLevel( rItem.getZoom() );

    // set play state at last
    if (nMaskSet & AVMediaSetMask::STATE)
    {
        switch (rItem.getState())
        {
            case MediaState::Play:
            {
                if (!isPlaying())
                    start();
            }
            break;

            case MediaState::Pause:
            {
                if (isPlaying())
                    stop();
            }
            break;

            case MediaState::Stop:
            {
                if (isPlaying())
                {
                    setMediaTime( 0.0 );
                    stop();
                    setMediaTime( 0.0 );
                }
            }
            break;
        }
    }
}

void MediaWindowImpl::stop()
{
    if( mxPlayer.is() )
        mxPlayer->stop();
}

bool MediaWindowImpl::isPlaying() const
{
    return( mxPlayer.is() && mxPlayer->isPlaying() );
}

double MediaWindowImpl::getDuration() const
{
    return( mxPlayer.is() ? mxPlayer->getDuration() : 0.0 );
}

void MediaWindowImpl::setMediaTime( double fTime )
{
    if( mxPlayer.is() )
        mxPlayer->setMediaTime( fTime );
}

double MediaWindowImpl::getMediaTime() const
{
    return( mxPlayer.is() ? mxPlayer->getMediaTime() : 0.0 );
}

void MediaWindowImpl::stopPlayingInternal(bool bStop)
{
    if (isPlaying())
    {
        bStop ? mxPlayer->stop() : mxPlayer->start();
    }
}

void MediaWindowImpl::onURLChanged()
{
    if (m_sMimeType == AVMEDIA_MIMETYPE_COMMON)
    {
        mpChildWindow.disposeAndClear();
        mpChildWindow.reset(VclPtr<MediaChildWindow>::Create(this));
    }
    if (!mpChildWindow)
        return;
    mpChildWindow->SetHelpId(HID_AVMEDIA_PLAYERWINDOW);
    mxEvents = new MediaEventListenersImpl(*mpChildWindow.get());

    if (mxPlayer.is())
    {
        Resize();
        uno::Sequence<uno::Any> aArgs( 3 );
        uno::Reference<media::XPlayerWindow> xPlayerWindow;
        const Point aPoint;
        const Size aSize(mpChildWindow->GetSizePixel());

        aArgs[0] <<= mpChildWindow->GetParentWindowHandle();
        aArgs[1] <<= awt::Rectangle(aPoint.X(), aPoint.Y(), aSize.Width(), aSize.Height());
        aArgs[2] <<= reinterpret_cast<sal_IntPtr>(mpChildWindow.get());

        try
        {
            xPlayerWindow = mxPlayer->createPlayerWindow( aArgs );
        }
        catch( const uno::RuntimeException& )
        {
            // happens eg, on MacOSX where Java frames cannot be created from X11 window handles
        }

        mxPlayerWindow = xPlayerWindow;

        if( xPlayerWindow.is() )
        {
            auto pEventsIf = static_cast<cppu::OWeakObject*>(mxEvents.get());
            xPlayerWindow->addKeyListener( uno::Reference< awt::XKeyListener >( pEventsIf, uno::UNO_QUERY ) );
            xPlayerWindow->addMouseListener( uno::Reference< awt::XMouseListener >( pEventsIf, uno::UNO_QUERY ) );
            xPlayerWindow->addMouseMotionListener( uno::Reference< awt::XMouseMotionListener >( pEventsIf, uno::UNO_QUERY ) );
            xPlayerWindow->addFocusListener( uno::Reference< awt::XFocusListener >( pEventsIf, uno::UNO_QUERY ) );
        }
    }
    else
        mxPlayerWindow.clear();

    if( mxPlayerWindow.is() )
        mpChildWindow->Show();
    else
        mpChildWindow->Hide();

    if( mpMediaWindowControl )
    {
        MediaItem aItem;

        updateMediaItem( aItem );
        mpMediaWindowControl->setState( aItem );
    }
}

void MediaWindowImpl::setPosSize(const tools::Rectangle& rRect)
{
    SetPosSizePixel(rRect.TopLeft(), rRect.GetSize());
}

void MediaWindowImpl::setPointer(const Pointer& rPointer)
{
    SetPointer(rPointer);

    if (mpChildWindow)
        mpChildWindow->SetPointer(rPointer);

    if (mxPlayerWindow.is())
    {
        long nPointer;

        switch (rPointer.GetStyle())
        {
            case PointerStyle::Cross:
                nPointer = awt::SystemPointer::CROSS;
                break;
            case PointerStyle::Hand:
                nPointer = awt::SystemPointer::HAND;
                break;
            case PointerStyle::Move:
                nPointer = awt::SystemPointer::MOVE;
                break;
            case PointerStyle::Wait:
                nPointer = awt::SystemPointer::WAIT;
                break;
            default:
                nPointer = awt::SystemPointer::ARROW;
                break;
        }

        mxPlayerWindow->setPointerType(nPointer);
    }
}

void MediaWindowImpl::Resize()
{
    const Size aCurSize(GetOutputSizePixel());
    const sal_Int32 nOffset(mpMediaWindowControl ? AVMEDIA_CONTROLOFFSET : 0);

    Size aPlayerWindowSize(aCurSize.Width() - (nOffset << 1),
                           aCurSize.Height() - (nOffset << 1));

    if (mpMediaWindowControl)
    {
        const sal_Int32 nControlHeight = mpMediaWindowControl->GetSizePixel().Height();
        const sal_Int32 nControlY = std::max(aCurSize.Height() - nControlHeight - nOffset, 0L);

        aPlayerWindowSize.setHeight( nControlY - (nOffset << 1) );
        mpMediaWindowControl->SetPosSizePixel(Point(nOffset, nControlY ), Size(aCurSize.Width() - (nOffset << 1), nControlHeight));
    }
    if (mpChildWindow)
        mpChildWindow->SetPosSizePixel(Point(0, 0), aPlayerWindowSize);

    if (mxPlayerWindow.is())
        mxPlayerWindow->setPosSize(0, 0, aPlayerWindowSize.Width(), aPlayerWindowSize.Height(), 0);
}

void MediaWindowImpl::StateChanged(StateChangedType eType)
{
    if (mxPlayerWindow.is())
    {
        // stop playing when going disabled or hidden
        switch (eType)
        {
            case StateChangedType::Visible:
            {
                stopPlayingInternal(!IsVisible());
                mxPlayerWindow->setVisible(IsVisible());
            }
            break;

            case StateChangedType::Enable:
            {
                stopPlayingInternal(!IsEnabled());
                mxPlayerWindow->setEnable(IsEnabled());
            }
            break;

            default:
            break;
        }
    }
}

void MediaWindowImpl::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
{
    if (mxPlayerWindow.is())
        mxPlayerWindow->update();

    BitmapEx* pLogo = nullptr;

    if (!mxPlayer.is())
    {
        if (!mpEmptyBmpEx)
            mpEmptyBmpEx.reset(new BitmapEx(AVMEDIA_BMP_EMPTYLOGO));

        pLogo = mpEmptyBmpEx.get();
    }
    else if (!mxPlayerWindow.is())
    {
        if (!mpAudioBmpEx)
            mpAudioBmpEx.reset(new BitmapEx(AVMEDIA_BMP_AUDIOLOGO));

        pLogo = mpAudioBmpEx.get();
    }

    if (!mpChildWindow)
        return;

    const Point aBasePos(mpChildWindow->GetPosPixel());
    const tools::Rectangle aVideoRect(aBasePos, mpChildWindow->GetSizePixel());

    if (pLogo && !pLogo->IsEmpty() && (aVideoRect.GetWidth() > 0) && (aVideoRect.GetHeight() > 0))
    {
        Size aLogoSize(pLogo->GetSizePixel());
        const Color aBackgroundColor(67, 67, 67);

        rRenderContext.SetLineColor(aBackgroundColor);
        rRenderContext.SetFillColor(aBackgroundColor);
        rRenderContext.DrawRect(aVideoRect);

        if ((aLogoSize.Width() > aVideoRect.GetWidth() || aLogoSize.Height() > aVideoRect.GetHeight() ) &&
            (aLogoSize.Height() > 0))
        {
            const double fLogoWH = double(aLogoSize.Width()) / aLogoSize.Height();

            if (fLogoWH < (double(aVideoRect.GetWidth()) / aVideoRect.GetHeight()))
            {
                aLogoSize.setWidth( long(aVideoRect.GetHeight() * fLogoWH) );
                aLogoSize.setHeight( aVideoRect.GetHeight() );
            }
            else
            {
                aLogoSize.setWidth( aVideoRect.GetWidth() );
                aLogoSize.setHeight( long(aVideoRect.GetWidth() / fLogoWH) );
            }
        }

        Point aPoint(aBasePos.X() + ((aVideoRect.GetWidth() - aLogoSize.Width()) >> 1),
                     aBasePos.Y() + ((aVideoRect.GetHeight() - aLogoSize.Height()) >> 1));

        rRenderContext.DrawBitmapEx(aPoint, aLogoSize, *pLogo);
    }
}

void MediaWindowImpl::GetFocus()
{
}

void MediaWindowImpl::MouseMove(const MouseEvent& rMEvt)
{
    if (mpMediaWindow)
        mpMediaWindow->MouseMove(rMEvt);
}

void MediaWindowImpl::MouseButtonDown(const MouseEvent& rMEvt)
{
    if (mpMediaWindow)
        mpMediaWindow->MouseButtonDown(rMEvt);
}

void MediaWindowImpl::MouseButtonUp(const MouseEvent& rMEvt)
{
    if (mpMediaWindow)
        mpMediaWindow->MouseButtonUp(rMEvt);
}

void MediaWindowImpl::KeyInput(const KeyEvent& rKEvt)
{
    if (mpMediaWindow)
        mpMediaWindow->KeyInput(rKEvt);
}

void MediaWindowImpl::KeyUp(const KeyEvent& rKEvt)
{
    if (mpMediaWindow)
        mpMediaWindow->KeyUp(rKEvt);
}

void MediaWindowImpl::Command(const CommandEvent& rCEvt)
{
    if (mpMediaWindow)
        mpMediaWindow->Command(rCEvt);
}

sal_Int8 MediaWindowImpl::AcceptDrop(const AcceptDropEvent& rEvt)
{
    return (mpMediaWindow ? mpMediaWindow->AcceptDrop(rEvt) : 0);
}

sal_Int8 MediaWindowImpl::ExecuteDrop(const ExecuteDropEvent& rEvt)
{
    return (mpMediaWindow ? mpMediaWindow->ExecuteDrop(rEvt) : 0);
}

void MediaWindowImpl::StartDrag(sal_Int8 nAction, const Point& rPosPixel)
{
    if (mpMediaWindow)
        mpMediaWindow->StartDrag(nAction, rPosPixel);
}

} // namespace priv
} // namespace avmedia

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */