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 <avmedia/mediaplayer.hxx>
21 #include <avmedia/mediawindow.hxx>
22 #include <avmedia/mediaitem.hxx>
23 #include <mediamisc.hxx>
24 #include <strings.hrc>
25 #include <helpids.h>
26
27 #include <svl/stritem.hxx>
28 #include <svl/itemset.hxx>
29 #include <sfx2/sfxsids.hrc>
30 #include <sfx2/bindings.hxx>
31 #include <sfx2/dispatch.hxx>
32
33 namespace avmedia
34 {
35
MediaPlayer(vcl::Window * _pParent,sal_uInt16 nId,SfxBindings * _pBindings,SfxChildWinInfo * pInfo)36 MediaPlayer::MediaPlayer( vcl::Window* _pParent, sal_uInt16 nId, SfxBindings* _pBindings, SfxChildWinInfo* pInfo ) :
37 SfxChildWindow( _pParent, nId )
38 {
39 SetWindow( VclPtr<MediaFloater>::Create( _pBindings, this, _pParent ) );
40 static_cast< MediaFloater* >( GetWindow() )->Initialize( pInfo );
41 };
42
43
~MediaPlayer()44 MediaPlayer::~MediaPlayer()
45 {
46 }
47
48
SFX_IMPL_DOCKINGWINDOW_WITHID(MediaPlayer,SID_AVMEDIA_PLAYER)49 SFX_IMPL_DOCKINGWINDOW_WITHID( MediaPlayer, SID_AVMEDIA_PLAYER )
50
51
52 MediaFloater::MediaFloater( SfxBindings* _pBindings, SfxChildWindow* pCW, vcl::Window* pParent ) :
53 SfxDockingWindow( _pBindings, pCW, pParent, WB_CLOSEABLE | WB_MOVEABLE | WB_SIZEABLE | WB_DOCKABLE ),
54 mpMediaWindow( new MediaWindow( this, true ) )
55 {
56 const Size aSize( mpMediaWindow->getPreferredSize() );
57
58 SetPosSizePixel( Point( 0, 0 ), aSize );
59 SetMinOutputSizePixel( aSize );
60 SetText( AvmResId( AVMEDIA_STR_MEDIAPLAYER ) );
61 mpMediaWindow->show();
62 }
63
64
~MediaFloater()65 MediaFloater::~MediaFloater()
66 {
67 disposeOnce();
68 }
69
dispose()70 void MediaFloater::dispose()
71 {
72 if (IsFloatingMode())
73 {
74 Show(false, ShowFlags::NoFocusChange);
75 SetFloatingMode(false);
76 }
77 mpMediaWindow.reset();
78 SfxDockingWindow::dispose();
79 }
80
Resize()81 void MediaFloater::Resize()
82 {
83 SfxDockingWindow::Resize();
84
85 if( mpMediaWindow )
86 mpMediaWindow->setPosSize( tools::Rectangle( Point(), GetOutputSizePixel() ) );
87 }
88
ToggleFloatingMode()89 void MediaFloater::ToggleFloatingMode()
90 {
91 ::avmedia::MediaItem aRestoreItem;
92
93 if (mpMediaWindow)
94 mpMediaWindow->updateMediaItem( aRestoreItem );
95 mpMediaWindow.reset();
96
97 SfxDockingWindow::ToggleFloatingMode();
98
99 if (isDisposed())
100 return;
101
102 mpMediaWindow.reset( new MediaWindow( this, true ) );
103
104 mpMediaWindow->setPosSize( tools::Rectangle( Point(), GetOutputSizePixel() ) );
105 mpMediaWindow->executeMediaItem( aRestoreItem );
106
107 vcl::Window* pWindow = mpMediaWindow->getWindow();
108
109 if( pWindow )
110 pWindow->SetHelpId( HID_AVMEDIA_PLAYERWINDOW );
111
112 mpMediaWindow->show();
113 }
114
115
setURL(const OUString & rURL,const OUString & rReferer,bool bPlayImmediately)116 void MediaFloater::setURL( const OUString& rURL, const OUString& rReferer, bool bPlayImmediately )
117 {
118 if( mpMediaWindow )
119 {
120 mpMediaWindow->setURL( rURL, rReferer );
121
122 if( mpMediaWindow->isValid() && bPlayImmediately )
123 mpMediaWindow->start();
124 }
125 }
126
127
dispatchCurrentURL()128 void MediaFloater::dispatchCurrentURL()
129 {
130 SfxDispatcher* pDispatcher = GetBindings().GetDispatcher();
131
132 if( pDispatcher )
133 {
134 OUString url;
135 if (mpMediaWindow != nullptr) {
136 url = mpMediaWindow->getURL();
137 }
138 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, url );
139 pDispatcher->ExecuteList(SID_INSERT_AVMEDIA, SfxCallMode::RECORD,
140 { &aMediaURLItem });
141 }
142 }
143
144 } // namespace avmedia
145
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
147