1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <mediacontrol.hxx>
21 #include <strings.hrc>
22 #include <mediamisc.hxx>
23 #include <avmedia/mediawindow.hxx>
25 #include <vcl/weld.hxx>
26 #include <avmedia/MediaControlBase.hxx>
31 MediaControl::MediaControl( vcl::Window
* pParent
, MediaControlStyle eControlStyle
) :
32 // MediaControlStyle::MultiLine is the normal docking windows of tools->media player
33 // MediaControlStyle::SingleLine is the toolbar of view->toolbar->media playback
34 InterimItemWindow(pParent
, eControlStyle
== MediaControlStyle::MultiLine
?
35 u
"svx/ui/mediawindow.ui"_ustr
:
36 u
"svx/ui/medialine.ui"_ustr
,
38 maIdle( "avmedia MediaControl Idle" ),
39 maChangeTimeIdle( "avmedia MediaControl Change Time Idle" ),
40 maItem( 0, AVMediaSetMask::ALL
),
42 meControlStyle( eControlStyle
)
44 mxPlayToolBox
= m_xBuilder
->weld_toolbar(u
"playtoolbox"_ustr
);
45 mxTimeSlider
= m_xBuilder
->weld_scale(u
"timeslider"_ustr
);
46 mxMuteToolBox
= m_xBuilder
->weld_toolbar(u
"mutetoolbox"_ustr
);
47 mxVolumeSlider
= m_xBuilder
->weld_scale(u
"volumeslider"_ustr
);
48 mxZoomListBox
= m_xBuilder
->weld_combo_box(u
"zoombox"_ustr
);
49 mxTimeEdit
= m_xBuilder
->weld_entry(u
"timeedit"_ustr
);
50 mxMediaPath
= m_xBuilder
->weld_label(u
"url"_ustr
);
54 mxPlayToolBox
->connect_clicked( LINK( this, MediaControl
, implSelectHdl
) );
56 mxTimeSlider
->connect_value_changed( LINK( this, MediaControl
, implTimeHdl
) );
57 // when changing the time, use this to do the time change after active scrolling
58 // has stopped for a little which
59 maChangeTimeIdle
.SetPriority( TaskPriority::LOWEST
);
60 maChangeTimeIdle
.SetInvokeHandler( LINK( this, MediaControl
, implTimeEndHdl
) );
62 mxTimeEdit
->set_text(u
" 00:00:00/00:00:00 "_ustr
);
63 Size aTextSize
= mxTimeEdit
->get_preferred_size();
64 mxTimeEdit
->set_size_request(aTextSize
.Width(), aTextSize
.Height());
65 mxTimeEdit
->set_text(OUString());
67 mxMuteToolBox
->connect_clicked( LINK( this, MediaControl
, implSelectHdl
) );
68 mxVolumeSlider
->connect_value_changed( LINK( this, MediaControl
, implVolumeHdl
) );
70 mxZoomListBox
->connect_changed( LINK( this, MediaControl
, implZoomSelectHdl
) );
71 mxZoomListBox
->set_help_id(HID_AVMEDIA_ZOOMLISTBOX
);
73 const OUString
aMediaPath( AvmResId( AVMEDIA_MEDIA_PATH_DEFAULT
) );
74 mxMediaPath
->set_label(aMediaPath
);
75 if (meControlStyle
== MediaControlStyle::SingleLine
)
76 mxMediaPath
->set_size_request(mxMediaPath
->get_preferred_size().Width() + 400, -1); // maybe extend the no. 400 to span the screen width
78 // we want time field + progress slider to update as the media plays
79 // give this task a lower prio than REPAINT so that UI updates are not starved
80 maIdle
.SetPriority( TaskPriority::POST_PAINT
);
81 maIdle
.SetInvokeHandler( LINK( this, MediaControl
, implTimeoutHdl
) );
84 void MediaControl::InitializeWidgets()
86 if( meControlStyle
!= MediaControlStyle::SingleLine
)
88 mxPlayToolBox
->set_item_help_id(u
"open"_ustr
, HID_AVMEDIA_TOOLBOXITEM_OPEN
);
89 mxPlayToolBox
->set_item_help_id(u
"apply"_ustr
, HID_AVMEDIA_TOOLBOXITEM_INSERT
);
91 avmedia::MediaControlBase::InitializeWidgets();
94 MediaControl::~MediaControl()
99 void MediaControl::dispose()
103 InterimItemWindow::dispose();
106 void MediaControl::UpdateURLField(MediaItem
const & tempItem
)
108 const OUString
aURL( AvmResId(AVMEDIA_MEDIA_PATH
) + ": " + tempItem
.getURL() ) ;
109 mxMediaPath
->set_label(aURL
);
112 void MediaControl::setState( const MediaItem
& rItem
)
116 bool bChanged
= maItem
.merge(rItem
);
119 if( rItem
.getURL().isEmpty() && meControlStyle
== MediaControlStyle::SingleLine
)
120 mxPlayToolBox
->set_sensitive(false);
121 UpdateToolBoxes( maItem
);
122 UpdateTimeSlider( maItem
);
123 UpdateVolumeSlider( maItem
);
124 UpdateTimeField( maItem
, maItem
.getTime() );
125 UpdateURLField(maItem
);
129 IMPL_LINK( MediaControl
, implTimeHdl
, weld::Scale
&, rSlider
, void )
133 UpdateTimeField(maItem
, rSlider
.get_value() * maItem
.getDuration() / AVMEDIA_TIME_RANGE
);
134 maChangeTimeIdle
.Start();
137 IMPL_LINK_NOARG(MediaControl
, implTimeEndHdl
, Timer
*, void)
141 aExecItem
.setTime( mxTimeSlider
->get_value() * maItem
.getDuration() / AVMEDIA_TIME_RANGE
);
142 // keep state (if the media was playing, keep it playing)
143 aExecItem
.setState(maItem
.getState());
144 execute( aExecItem
);
150 IMPL_LINK( MediaControl
, implVolumeHdl
, weld::Scale
&, rSlider
, void )
154 aExecItem
.setVolumeDB(rSlider
.get_value());
155 execute( aExecItem
);
159 IMPL_LINK( MediaControl
, implSelectHdl
, const OUString
&, rIdent
, void )
162 if (rIdent
== "open")
165 if (MediaWindow::executeMediaURLDialog(GetFrameWeld(), aURL
, nullptr))
167 if( !MediaWindow::isMediaURL( aURL
, u
""_ustr
/*TODO?*/, true ) )
168 MediaWindow::executeFormatErrorBox(GetFrameWeld());
171 aExecItem
.setURL( aURL
, u
""_ustr
, u
""_ustr
/*TODO?*/ );
172 aExecItem
.setState( MediaState::Play
);
177 SelectPlayToolBoxItem( aExecItem
, maItem
, rIdent
);
179 if (aExecItem
.getState() == MediaState::Play
)
181 else if (aExecItem
.getState() == MediaState::Pause
||
182 aExecItem
.getState() == MediaState::Stop
)
185 if( aExecItem
.getMaskSet() != AVMediaSetMask::NONE
)
186 execute( aExecItem
);
191 IMPL_LINK( MediaControl
, implZoomSelectHdl
, weld::ComboBox
&, rBox
, void )
193 bool bCurrentlySettingZoom
= mbCurrentlySettingZoom
;
194 mbCurrentlySettingZoom
= true;
197 css::media::ZoomLevel eLevel
;
199 switch (rBox
.get_active())
201 case AVMEDIA_ZOOMLEVEL_50
: eLevel
= css::media::ZoomLevel_ZOOM_1_TO_2
; break;
202 case AVMEDIA_ZOOMLEVEL_100
: eLevel
= css::media::ZoomLevel_ORIGINAL
; break;
203 case AVMEDIA_ZOOMLEVEL_200
: eLevel
= css::media::ZoomLevel_ZOOM_2_TO_1
; break;
204 case AVMEDIA_ZOOMLEVEL_FIT
: eLevel
= css::media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT
; break;
205 case AVMEDIA_ZOOMLEVEL_SCALED
: eLevel
= css::media::ZoomLevel_FIT_TO_WINDOW
; break;
207 default: eLevel
= css::media::ZoomLevel_NOT_AVAILABLE
; break;
210 aExecItem
.setZoom( eLevel
);
211 execute( aExecItem
);
214 mbCurrentlySettingZoom
= bCurrentlySettingZoom
;
217 IMPL_LINK_NOARG(MediaControl
, implTimeoutHdl
, Timer
*, void)
223 } // namespace avmedia
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */