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 <avmedia/mediaplayer.hxx>
25 #include <avmedia/mediawindow.hxx>
26 #include <avmedia/mediaitem.hxx>
27 #include "mediamisc.hxx"
28 #include "mediacontrol.hrc"
29 #include "helpids.hrc"
30 
31 #include <svl/stritem.hxx>
32 #include <sfx2/app.hxx>
33 #include <sfx2/sfxsids.hrc>
34 #include <sfx2/bindings.hxx>
35 #include <sfx2/dispatch.hxx>
36 
37 namespace avmedia
38 {
39 
40 // ---------------
41 // - MediaPlayer -
42 // ---------------
43 
MediaPlayer(Window * _pParent,sal_uInt16 nId,SfxBindings * _pBindings,SfxChildWinInfo * pInfo)44 MediaPlayer::MediaPlayer( Window* _pParent, sal_uInt16 nId, SfxBindings* _pBindings, SfxChildWinInfo* pInfo ) :
45 	SfxChildWindow( _pParent, nId )
46 {
47 	pWindow = new MediaFloater( _pBindings, this, _pParent );
48 	eChildAlignment = SFX_ALIGN_NOALIGNMENT;
49 	static_cast< MediaFloater* >( pWindow )->Initialize( pInfo );
50 };
51 
52 // -----------------------------------------------------------------------------
53 
~MediaPlayer()54 MediaPlayer::~MediaPlayer()
55 {
56 }
57 
58 // -----------------------------------------------------------------------------
59 
SFX_IMPL_DOCKINGWINDOW(MediaPlayer,SID_AVMEDIA_PLAYER)60 SFX_IMPL_DOCKINGWINDOW( MediaPlayer, SID_AVMEDIA_PLAYER )
61 
62 // ----------------
63 // - MediaFloater -
64 // ----------------
65 
66 MediaFloater::MediaFloater( SfxBindings* _pBindings, SfxChildWindow* pCW, Window* pParent ) :
67 	SfxDockingWindow( _pBindings, pCW, pParent, WB_CLOSEABLE | WB_MOVEABLE | WB_SIZEABLE | WB_DOCKABLE ),
68 	mpMediaWindow( new MediaWindow( this, true ) )
69 {
70 	const Size aSize( 378, 256 );
71 
72 	SetPosSizePixel( Point( 0, 0 ), aSize );
73 	SetMinOutputSizePixel( aSize );
74 	SetText( String( AVMEDIA_RESID( AVMEDIA_STR_MEDIAPLAYER ) ) );
75     implInit();
76 	mpMediaWindow->show();
77 }
78 
79 // -----------------------------------------------------------------------------
80 
~MediaFloater()81 MediaFloater::~MediaFloater()
82 {
83 	delete mpMediaWindow;
84 	mpMediaWindow = NULL;
85 }
86 
87 // -----------------------------------------------------------------------------
88 
implInit()89 void MediaFloater::implInit()
90 {
91 }
92 
93 // -------------------------------------------------------------------------
94 
Resize()95 void MediaFloater::Resize()
96 {
97 	SfxDockingWindow::Resize();
98 
99 	if( mpMediaWindow )
100 	    mpMediaWindow->setPosSize( Rectangle( Point(), GetOutputSizePixel() ) );
101 }
102 
103 // -----------------------------------------------------------------------------
104 
ToggleFloatingMode()105 void MediaFloater::ToggleFloatingMode()
106 {
107 	::avmedia::MediaItem aRestoreItem;
108 
109 	mpMediaWindow->updateMediaItem( aRestoreItem );
110 	delete mpMediaWindow;
111 	mpMediaWindow = NULL;
112 
113 	SfxDockingWindow::ToggleFloatingMode();
114 
115 	mpMediaWindow = new MediaWindow( this, true );
116 
117 	mpMediaWindow->setPosSize( Rectangle( Point(), GetOutputSizePixel() ) );
118 	mpMediaWindow->executeMediaItem( aRestoreItem );
119 
120 	Window* pWindow = mpMediaWindow->getWindow();
121 
122 	if( pWindow )
123 	    pWindow->SetHelpId( HID_AVMEDIA_PLAYERWINDOW );
124 
125 	mpMediaWindow->show();
126 }
127 
128 // -----------------------------------------------------------------------------
129 
setURL(const::rtl::OUString & rURL,bool bPlayImmediately)130 void MediaFloater::setURL( const ::rtl::OUString& rURL, bool bPlayImmediately )
131 {
132 	if( mpMediaWindow )
133 	{
134 	    mpMediaWindow->setURL( rURL );
135 
136 	    if( mpMediaWindow->isValid() && bPlayImmediately )
137 		    mpMediaWindow->start();
138     }
139 }
140 
141 // -----------------------------------------------------------------------------
142 
getURL() const143 const ::rtl::OUString& MediaFloater::getURL() const
144 {
145     static const ::rtl::OUString aEmptyStr;
146 	return( mpMediaWindow ? mpMediaWindow->getURL() : aEmptyStr );
147 }
148 
149 // -----------------------------------------------------------------------------
150 
dispatchCurrentURL()151 void MediaFloater::dispatchCurrentURL()
152 {
153 	SfxDispatcher* pDispatcher = GetBindings().GetDispatcher();
154 
155 	if( pDispatcher )
156 	{
157 		const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, getURL() );
158 		pDispatcher->Execute( SID_INSERT_AVMEDIA, SFX_CALLMODE_RECORD, &aMediaURLItem, 0L );
159 	}
160 }
161 
162 }
163