Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "mediacontrol.hxx"
30 : : #include "mediacontrol.hrc"
31 : : #include "mediamisc.hxx"
32 : : #include <avmedia/mediawindow.hxx>
33 : : #include <avmedia/mediaplayer.hxx>
34 : : #include "helpids.hrc"
35 : : #include <tools/time.hxx>
36 : : #include <vcl/svapp.hxx>
37 : : #include <vcl/lstbox.hxx>
38 : : #include <unotools/syslocale.hxx>
39 : : #include <sfx2/viewfrm.hxx>
40 : : #include <math.h>
41 : : #include <algorithm>
42 : :
43 : : #define AVMEDIA_TIMEOUT 100
44 : : #define AVMEDIA_TIME_RANGE 2048
45 : : #define AVMEDIA_DB_RANGE -40
46 : : #define AVMEDIA_LINEINCREMENT 1.0
47 : : #define AVMEDIA_PAGEINCREMENT 10.0
48 : :
49 : : #define AVMEDIA_TOOLBOXITEM_PLAY 0x0001
50 : : #define AVMEDIA_TOOLBOXITEM_PLAYFFW 0x0002
51 : : #define AVMEDIA_TOOLBOXITEM_PAUSE 0x0004
52 : : #define AVMEDIA_TOOLBOXITEM_STOP 0x0008
53 : : #define AVMEDIA_TOOLBOXITEM_MUTE 0x0010
54 : : #define AVMEDIA_TOOLBOXITEM_LOOP 0x0011
55 : : #define AVMEDIA_TOOLBOXITEM_ZOOM 0x0012
56 : : #define AVMEDIA_TOOLBOXITEM_OPEN 0x0014
57 : : #define AVMEDIA_TOOLBOXITEM_INSERT 0x0018
58 : :
59 : : #define AVMEDIA_ZOOMLEVEL_50 0
60 : : #define AVMEDIA_ZOOMLEVEL_100 1
61 : : #define AVMEDIA_ZOOMLEVEL_200 2
62 : : #define AVMEDIA_ZOOMLEVEL_FIT 3
63 : : #define AVMEDIA_ZOOMLEVEL_SCALED 4
64 : : #define AVMEDIA_ZOOMLEVEL_INVALID 65535
65 : :
66 : : namespace avmedia
67 : : {
68 : :
69 : : // ----------------
70 : : // - MediaControl -
71 : : // ---------------
72 : :
73 : 0 : MediaControl::MediaControl( Window* pParent, MediaControlStyle eControlStyle ) :
74 : : Control( pParent ),
75 [ # # ]: 0 : maImageList( AVMEDIA_RESID( AVMEDIA_IMGLST ) ),
76 : : maItem( 0, AVMEDIA_SETMASK_ALL ),
77 : : maPlayToolBox( this, WB_3DLOOK ),
78 : : maTimeSlider( this, WB_HORZ | WB_DRAG | WB_3DLOOK | WB_SLIDERSET ),
79 : : maMuteToolBox( this, WB_3DLOOK ),
80 : : maVolumeSlider( this, WB_HORZ | WB_DRAG | WB_SLIDERSET ),
81 : : maZoomToolBox( this, WB_3DLOOK ),
82 [ # # ]: 0 : mpZoomListBox( new ListBox( &maZoomToolBox, WB_BORDER | WB_DROPDOWN | WB_AUTOHSCROLL | WB_3DLOOK ) ),
83 : : maTimeEdit( this, WB_CENTER | WB_READONLY | WB_BORDER | WB_3DLOOK | WB_READONLY ),
84 : : meControlStyle( eControlStyle ),
85 [ # # ][ # # ]: 0 : mbLocked( false )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
86 : : {
87 [ # # ]: 0 : const String aTimeText( RTL_CONSTASCII_USTRINGPARAM( " 00:00:00/00:00:00 " ) );
88 : :
89 [ # # ]: 0 : SetBackground();
90 [ # # ]: 0 : SetPaintTransparent( sal_True );
91 [ # # ]: 0 : SetParentClipMode( PARENTCLIPMODE_NOCLIP );
92 : :
93 [ # # ]: 0 : if( MEDIACONTROLSTYLE_SINGLELINE != meControlStyle )
94 : : {
95 [ # # ][ # # ]: 0 : maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_OPEN, implGetImage( AVMEDIA_IMG_OPEN ), String( AVMEDIA_RESID( AVMEDIA_STR_OPEN ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
96 [ # # ]: 0 : maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_OPEN, HID_AVMEDIA_TOOLBOXITEM_OPEN );
97 : :
98 [ # # ][ # # ]: 0 : maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_INSERT, implGetImage( AVMEDIA_IMG_INSERT ), String( AVMEDIA_RESID( AVMEDIA_STR_INSERT ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
99 [ # # ]: 0 : maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_INSERT, HID_AVMEDIA_TOOLBOXITEM_INSERT );
100 : :
101 [ # # ]: 0 : maPlayToolBox.InsertSeparator();
102 : : }
103 : : else
104 : : {
105 [ # # ]: 0 : mpZoomListBox->SetBackground();
106 : :
107 [ # # ]: 0 : maZoomToolBox.SetBackground();
108 [ # # ]: 0 : maZoomToolBox.SetPaintTransparent( sal_True );
109 [ # # ]: 0 : maPlayToolBox.SetBackground();
110 [ # # ]: 0 : maPlayToolBox.SetPaintTransparent( sal_True );
111 [ # # ]: 0 : maMuteToolBox.SetBackground();
112 [ # # ]: 0 : maMuteToolBox.SetPaintTransparent( sal_True );
113 : :
114 : : }
115 : :
116 [ # # ][ # # ]: 0 : maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_PLAY, implGetImage( AVMEDIA_IMG_PLAY ), String( AVMEDIA_RESID( AVMEDIA_STR_PLAY ) ), TIB_CHECKABLE );
[ # # ][ # # ]
[ # # ][ # # ]
117 [ # # ]: 0 : maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_PLAY, HID_AVMEDIA_TOOLBOXITEM_PLAY );
118 : :
119 [ # # ][ # # ]: 0 : maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_PAUSE, implGetImage( AVMEDIA_IMG_PAUSE ), String( AVMEDIA_RESID( AVMEDIA_STR_PAUSE ) ), TIB_CHECKABLE );
[ # # ][ # # ]
[ # # ][ # # ]
120 [ # # ]: 0 : maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_PAUSE, HID_AVMEDIA_TOOLBOXITEM_PAUSE );
121 : :
122 [ # # ][ # # ]: 0 : maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_STOP, implGetImage( AVMEDIA_IMG_STOP ), String( AVMEDIA_RESID( AVMEDIA_STR_STOP ) ), TIB_CHECKABLE );
[ # # ][ # # ]
[ # # ][ # # ]
123 [ # # ]: 0 : maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_STOP, HID_AVMEDIA_TOOLBOXITEM_STOP );
124 : :
125 [ # # ]: 0 : maPlayToolBox.InsertSeparator();
126 : :
127 [ # # ][ # # ]: 0 : maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_LOOP, implGetImage( AVMEDIA_IMG_ENDLESS ), String( AVMEDIA_RESID( AVMEDIA_STR_ENDLESS ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
128 [ # # ]: 0 : maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_LOOP, HID_AVMEDIA_TOOLBOXITEM_LOOP );
129 : :
130 [ # # ]: 0 : if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
131 [ # # ]: 0 : maPlayToolBox.InsertSeparator();
132 : :
133 [ # # ]: 0 : maPlayToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) );
134 [ # # ][ # # ]: 0 : maPlayToolBox.SetSizePixel( maPlayToolBox.CalcWindowSizePixel() );
135 [ # # ]: 0 : maPlayToolBox.Show();
136 [ # # ]: 0 : maMinSize = maPlayToolBox.GetSizePixel();
137 : :
138 [ # # ]: 0 : maTimeSlider.SetSlideHdl( LINK( this, MediaControl, implTimeHdl ) );
139 [ # # ]: 0 : maTimeSlider.SetEndSlideHdl( LINK( this, MediaControl, implTimeEndHdl ) );
140 [ # # ]: 0 : maTimeSlider.SetRange( Range( 0, AVMEDIA_TIME_RANGE ) );
141 [ # # ]: 0 : maTimeSlider.SetHelpId( HID_AVMEDIA_TIMESLIDER );
142 [ # # ]: 0 : maTimeSlider.SetUpdateMode( true );
143 [ # # ][ # # ]: 0 : maTimeSlider.SetSizePixel( Size( 128, maPlayToolBox.GetSizePixel().Height() ) );
144 [ # # ]: 0 : maTimeSlider.Show();
145 [ # # ]: 0 : maMinSize.Width() += maTimeSlider.GetSizePixel().Width();
146 : :
147 [ # # ]: 0 : maTimeEdit.SetText( aTimeText );
148 [ # # ]: 0 : maTimeEdit.SetUpdateMode( true );
149 [ # # ][ # # ]: 0 : maTimeEdit.SetSizePixel( Size( maTimeEdit.GetTextWidth( aTimeText ) + 8, maPlayToolBox.GetSizePixel().Height() ) );
[ # # ]
150 [ # # ][ # # ]: 0 : maTimeEdit.SetControlBackground( Application::GetSettings().GetStyleSettings().GetWindowColor() );
151 [ # # ]: 0 : maTimeEdit.SetHelpId( HID_AVMEDIA_TIMEEDIT );
152 [ # # ]: 0 : maTimeEdit.Disable();
153 [ # # ]: 0 : maTimeEdit.Show();
154 [ # # ]: 0 : maMinSize.Width() += maTimeEdit.GetSizePixel().Width();
155 : :
156 [ # # ]: 0 : if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
157 [ # # ]: 0 : maMuteToolBox.InsertSeparator();
158 : :
159 [ # # ][ # # ]: 0 : maMuteToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_MUTE, implGetImage( AVMEDIA_IMG_MUTE ), String( AVMEDIA_RESID( AVMEDIA_STR_MUTE ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
160 [ # # ]: 0 : maMuteToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_MUTE, HID_AVMEDIA_TOOLBOXITEM_MUTE );
161 : :
162 [ # # ]: 0 : maMuteToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) );
163 [ # # ][ # # ]: 0 : maMuteToolBox.SetSizePixel( maMuteToolBox.CalcWindowSizePixel() );
164 [ # # ]: 0 : maMuteToolBox.Show();
165 [ # # ]: 0 : maMinSize.Width() += maMuteToolBox.GetSizePixel().Width();
166 : :
167 [ # # ]: 0 : maVolumeSlider.SetSlideHdl( LINK( this, MediaControl, implVolumeHdl ) );
168 [ # # ]: 0 : maVolumeSlider.SetEndSlideHdl( LINK( this, MediaControl, implVolumeEndHdl ) );
169 [ # # ]: 0 : maVolumeSlider.SetRange( Range( AVMEDIA_DB_RANGE, 0 ) );
170 [ # # ]: 0 : maVolumeSlider.SetUpdateMode( true );
171 [ # # ]: 0 : maVolumeSlider.SetHelpId( HID_AVMEDIA_VOLUMESLIDER );
172 [ # # ][ # # ]: 0 : maVolumeSlider.SetSizePixel( Size( 48, maPlayToolBox.GetSizePixel().Height() ) );
173 [ # # ]: 0 : maVolumeSlider.Show();
174 [ # # ]: 0 : maMinSize.Width() += maVolumeSlider.GetSizePixel().Width();
175 : :
176 [ # # ][ # # ]: 0 : mpZoomListBox->SetSizePixel( Size( maTimeEdit.GetSizePixel().Width(), 260 ) );
177 [ # # ][ # # ]: 0 : mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_50 ) ), AVMEDIA_ZOOMLEVEL_50 );
[ # # ][ # # ]
178 [ # # ][ # # ]: 0 : mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_100 ) ), AVMEDIA_ZOOMLEVEL_100 );
[ # # ][ # # ]
179 [ # # ][ # # ]: 0 : mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_200 ) ), AVMEDIA_ZOOMLEVEL_200 );
[ # # ][ # # ]
180 [ # # ][ # # ]: 0 : mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_FIT ) ), AVMEDIA_ZOOMLEVEL_FIT );
[ # # ][ # # ]
181 [ # # ]: 0 : mpZoomListBox->SetSelectHdl( LINK( this, MediaControl, implZoomSelectHdl ) );
182 [ # # ]: 0 : mpZoomListBox->SetHelpId( HID_AVMEDIA_ZOOMLISTBOX );
183 : :
184 [ # # ][ # # ]: 0 : maZoomToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_ZOOM, String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM ) ) );
[ # # ][ # # ]
185 [ # # ]: 0 : maZoomToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_ZOOM, HID_AVMEDIA_ZOOMLISTBOX );
186 : :
187 [ # # ]: 0 : maZoomToolBox.SetItemWindow( AVMEDIA_TOOLBOXITEM_ZOOM, mpZoomListBox );
188 [ # # ]: 0 : maZoomToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) );
189 [ # # ][ # # ]: 0 : maZoomToolBox.SetSizePixel( maZoomToolBox.CalcWindowSizePixel() );
190 [ # # ]: 0 : maZoomToolBox.Show();
191 [ # # ]: 0 : maMinSize.Width() += maZoomToolBox.GetSizePixel().Width();
192 : :
193 [ # # ]: 0 : if( MEDIACONTROLSTYLE_MULTILINE == meControlStyle )
194 : : {
195 : 0 : maMinSize.Width() = 256;
196 : 0 : maMinSize.Height() = ( maMinSize.Height() << 1 ) + AVMEDIA_CONTROLOFFSET;
197 : : }
198 : :
199 [ # # ]: 0 : maTimer.SetTimeout( AVMEDIA_TIMEOUT );
200 [ # # ]: 0 : maTimer.SetTimeoutHdl( LINK( this, MediaControl, implTimeoutHdl ) );
201 [ # # ][ # # ]: 0 : maTimer.Start();
202 : 0 : }
203 : :
204 : : // ------------------------------------------------------------------------------
205 : :
206 [ # # ][ # # ]: 0 : MediaControl::~MediaControl()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
207 : : {
208 [ # # ]: 0 : maZoomToolBox.SetItemWindow( AVMEDIA_TOOLBOXITEM_ZOOM, NULL );
209 [ # # ][ # # ]: 0 : delete mpZoomListBox;
210 [ # # ]: 0 : }
211 : :
212 : : // ------------------------------------------------------------------------------
213 : :
214 : 0 : const Size& MediaControl::getMinSizePixel() const
215 : : {
216 : 0 : return maMinSize;
217 : : }
218 : :
219 : : // ------------------------------------------------------------------------------
220 : :
221 : 0 : void MediaControl::Resize()
222 : : {
223 : 0 : Point aPos( 0, 0 );
224 [ # # ]: 0 : const sal_Int32 nPlayToolBoxWidth = maPlayToolBox.GetSizePixel().Width();
225 [ # # ]: 0 : const sal_Int32 nMuteToolBoxWidth = maMuteToolBox.GetSizePixel().Width();
226 [ # # ]: 0 : const sal_Int32 nVolumeSliderWidth = maVolumeSlider.GetSizePixel().Width();
227 [ # # ]: 0 : const sal_Int32 nZoomToolBoxWidth = maZoomToolBox.GetSizePixel().Width();
228 [ # # ]: 0 : const sal_Int32 nTimeEditWidth = maTimeEdit.GetSizePixel().Width();
229 [ # # ]: 0 : const sal_Int32 nTimeSliderHeight = maTimeSlider.GetSizePixel().Height();
230 : :
231 [ # # ]: 0 : if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
232 : : {
233 [ # # ]: 0 : const sal_Int32 nTimeSliderWidth = GetSizePixel().Width() - ( AVMEDIA_CONTROLOFFSET * 3 ) -
234 : 0 : nPlayToolBoxWidth - nMuteToolBoxWidth - nVolumeSliderWidth - nTimeEditWidth - nZoomToolBoxWidth;
235 : :
236 [ # # ][ # # ]: 0 : maPlayToolBox.SetPosSizePixel( aPos, maPlayToolBox.GetSizePixel() );
237 : :
238 : 0 : aPos.X() += nPlayToolBoxWidth;
239 [ # # ]: 0 : maTimeSlider.SetPosSizePixel( aPos, Size( nTimeSliderWidth, nTimeSliderHeight ) );
240 : :
241 : 0 : aPos.X() += nTimeSliderWidth + AVMEDIA_CONTROLOFFSET;
242 [ # # ][ # # ]: 0 : maTimeEdit.SetPosSizePixel( aPos, maTimeEdit.GetSizePixel() );
243 : :
244 : 0 : aPos.X() += nTimeEditWidth + AVMEDIA_CONTROLOFFSET;
245 [ # # ][ # # ]: 0 : maMuteToolBox.SetPosSizePixel( aPos, maMuteToolBox.GetSizePixel() );
246 : :
247 : 0 : aPos.X() += nMuteToolBoxWidth;
248 [ # # ][ # # ]: 0 : maVolumeSlider.SetPosSizePixel( aPos, maVolumeSlider.GetSizePixel() );
249 : :
250 : 0 : aPos.X() += nVolumeSliderWidth + AVMEDIA_CONTROLOFFSET;
251 [ # # ][ # # ]: 0 : maZoomToolBox.SetPosSizePixel( aPos, maZoomToolBox.GetSizePixel() );
252 : : }
253 : : else
254 : : {
255 [ # # ]: 0 : const sal_Int32 nTimeSliderWidth = GetSizePixel().Width() - AVMEDIA_CONTROLOFFSET - nTimeEditWidth;
256 : :
257 [ # # ]: 0 : maTimeSlider.SetPosSizePixel( aPos, Size( nTimeSliderWidth, nTimeSliderHeight ) );
258 : :
259 : 0 : aPos.X() += nTimeSliderWidth + AVMEDIA_CONTROLOFFSET;
260 [ # # ][ # # ]: 0 : maTimeEdit.SetPosSizePixel( aPos, maTimeEdit.GetSizePixel() );
261 : :
262 : 0 : aPos.X() = 0;
263 : 0 : aPos.Y() += nTimeSliderHeight + AVMEDIA_CONTROLOFFSET;
264 [ # # ][ # # ]: 0 : maPlayToolBox.SetPosSizePixel( aPos, maPlayToolBox.GetSizePixel() );
265 : :
266 [ # # ]: 0 : aPos.X() = GetSizePixel().Width() - nVolumeSliderWidth - nMuteToolBoxWidth - nZoomToolBoxWidth - AVMEDIA_CONTROLOFFSET;
267 [ # # ][ # # ]: 0 : maMuteToolBox.SetPosSizePixel( aPos, maMuteToolBox.GetSizePixel() );
268 : :
269 : 0 : aPos.X() += nMuteToolBoxWidth;
270 [ # # ][ # # ]: 0 : maVolumeSlider.SetPosSizePixel( aPos, maVolumeSlider.GetSizePixel() );
271 : :
272 [ # # ]: 0 : aPos.X() = GetSizePixel().Width() - nZoomToolBoxWidth;
273 [ # # ][ # # ]: 0 : maZoomToolBox.SetPosSizePixel( aPos, maZoomToolBox.GetSizePixel() );
274 : : }
275 : 0 : }
276 : :
277 : : // ------------------------------------------------------------------------------
278 : :
279 : 0 : void MediaControl::setState( const MediaItem& rItem )
280 : : {
281 [ # # ]: 0 : if( !mbLocked )
282 : : {
283 : 0 : maItem.merge( rItem );
284 : :
285 : 0 : implUpdateToolboxes();
286 : 0 : implUpdateTimeSlider();
287 : 0 : implUpdateVolumeSlider();
288 : 0 : implUpdateTimeField( maItem.getTime() );
289 : : }
290 : 0 : }
291 : :
292 : : // ------------------------------------------------------------------------------
293 : :
294 : 0 : void MediaControl::implUpdateToolboxes()
295 : : {
296 : 0 : const bool bValidURL = ( !maItem.getURL().isEmpty());
297 : :
298 : 0 : maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_INSERT, bValidURL );
299 : 0 : maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PLAY, bValidURL );
300 : 0 : maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, bValidURL );
301 : 0 : maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PAUSE, bValidURL );
302 : 0 : maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_STOP, bValidURL );
303 : 0 : maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_LOOP, bValidURL );
304 : 0 : maMuteToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_MUTE, bValidURL );
305 : :
306 [ # # ][ # # ]: 0 : if( !bValidURL || !IsEnabled() )
[ # # ]
307 : : {
308 : 0 : mpZoomListBox->Disable();
309 : :
310 [ # # ]: 0 : if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
311 : 0 : maPlayToolBox.Disable();
312 : :
313 : 0 : maMuteToolBox.Disable();
314 : : }
315 : : else
316 : : {
317 : 0 : maPlayToolBox.Enable();
318 : 0 : maMuteToolBox.Enable();
319 : :
320 [ # # ][ # # ]: 0 : if( MEDIASTATE_PLAY == maItem.getState() || MEDIASTATE_PLAYFFW == maItem.getState() )
[ # # ]
321 : : {
322 : 0 : maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, true );
323 : 0 : maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, MEDIASTATE_PLAYFFW == maItem.getState() );
324 : 0 : maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, false );
325 : 0 : maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, false );
326 : : }
327 [ # # ][ # # ]: 0 : else if( maItem.getTime() > 0.0 && ( maItem.getTime() < maItem.getDuration() ) )
[ # # ]
328 : : {
329 : 0 : maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, false );
330 : 0 : maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, false );
331 : 0 : maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, true );
332 : 0 : maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, false );
333 : : }
334 : : else
335 : : {
336 : 0 : maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, false );
337 : 0 : maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, false );
338 : 0 : maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, false );
339 : 0 : maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, true );
340 : : }
341 : :
342 : 0 : maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_LOOP, maItem.isLoop() );
343 : 0 : maMuteToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_MUTE, maItem.isMute() );
344 : :
345 [ # # ][ # # ]: 0 : if( !mpZoomListBox->IsTravelSelect() && !mpZoomListBox->IsInDropDown() )
[ # # ]
346 : : {
347 : : sal_uInt16 nSelectEntryPos ;
348 : :
349 [ # # # # : 0 : switch( maItem.getZoom() )
# # ]
350 : : {
351 : 0 : case( ::com::sun::star::media::ZoomLevel_ZOOM_1_TO_2 ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_50; break;
352 : 0 : case( ::com::sun::star::media::ZoomLevel_ORIGINAL ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_100; break;
353 : 0 : case( ::com::sun::star::media::ZoomLevel_ZOOM_2_TO_1 ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_200; break;
354 : 0 : case( ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_FIT; break;
355 : 0 : case( ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_SCALED; break;
356 : :
357 : 0 : default: nSelectEntryPos = AVMEDIA_ZOOMLEVEL_INVALID; break;
358 : : }
359 : :
360 [ # # ]: 0 : if( nSelectEntryPos != AVMEDIA_ZOOMLEVEL_INVALID )
361 : : {
362 : 0 : mpZoomListBox->Enable();
363 : 0 : mpZoomListBox->SelectEntryPos( nSelectEntryPos );
364 : : }
365 : : else
366 : 0 : mpZoomListBox->Disable();
367 : : }
368 : : }
369 : 0 : }
370 : :
371 : : // ------------------------------------------------------------------------------
372 : :
373 : 0 : void MediaControl::implUpdateTimeSlider()
374 : : {
375 [ # # ][ # # ]: 0 : if( maItem.getURL().isEmpty() || !IsEnabled() )
[ # # ]
376 : 0 : maTimeSlider.Disable();
377 : : else
378 : : {
379 [ # # ]: 0 : maTimeSlider.Enable();
380 : :
381 [ # # ]: 0 : const double fDuration = maItem.getDuration();
382 : :
383 [ # # ]: 0 : if( fDuration > 0.0 )
384 : : {
385 [ # # ][ # # ]: 0 : const double fTime = ::std::min( maItem.getTime(), fDuration );
386 : :
387 [ # # ]: 0 : if( !maTimeSlider.GetLineSize() )
388 : 0 : maTimeSlider.SetLineSize( static_cast< sal_uInt32 >( AVMEDIA_TIME_RANGE * AVMEDIA_LINEINCREMENT / fDuration ) );
389 : :
390 [ # # ]: 0 : if( !maTimeSlider.GetPageSize() )
391 : 0 : maTimeSlider.SetPageSize( static_cast< sal_uInt32 >( AVMEDIA_TIME_RANGE * AVMEDIA_PAGEINCREMENT / fDuration ) );
392 : :
393 [ # # ]: 0 : maTimeSlider.SetThumbPos( static_cast< sal_Int32 >( fTime / fDuration * AVMEDIA_TIME_RANGE ) );
394 : : }
395 : : }
396 : 0 : }
397 : :
398 : : // ------------------------------------------------------------------------------
399 : :
400 : 0 : void MediaControl::implUpdateVolumeSlider()
401 : : {
402 [ # # ][ # # ]: 0 : if( maItem.getURL().isEmpty() || !IsEnabled() )
[ # # ]
403 : 0 : maVolumeSlider.Disable();
404 : : else
405 : : {
406 [ # # ]: 0 : maVolumeSlider.Enable();
407 : :
408 [ # # ]: 0 : const sal_Int32 nVolumeDB = maItem.getVolumeDB();
409 : :
410 [ # # ]: 0 : maVolumeSlider.SetThumbPos( ::std::min( ::std::max( nVolumeDB, static_cast< sal_Int32 >( AVMEDIA_DB_RANGE ) ),
411 [ # # ][ # # ]: 0 : static_cast< sal_Int32 >( 0 ) ) );
412 : : }
413 : 0 : }
414 : :
415 : : // ------------------------------------------------------------------------------
416 : :
417 : 0 : void MediaControl::implUpdateTimeField( double fCurTime )
418 : : {
419 [ # # ]: 0 : if( !maItem.getURL().isEmpty() )
420 : : {
421 [ # # ]: 0 : String aTimeString;
422 : :
423 [ # # ]: 0 : SvtSysLocale aSysLocale;
424 [ # # ]: 0 : const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData();
425 : :
426 [ # # ][ # # ]: 0 : aTimeString += rLocaleData.getDuration( Time( 0, 0, static_cast< sal_uInt32 >( floor( fCurTime ) ) ) );
[ # # ]
427 [ # # ]: 0 : aTimeString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " / " ));
428 [ # # ][ # # ]: 0 : aTimeString += rLocaleData.getDuration( Time( 0, 0, static_cast< sal_uInt32 >( floor( maItem.getDuration() ) )) );
[ # # ][ # # ]
429 : :
430 [ # # ][ # # ]: 0 : if( maTimeEdit.GetText() != aTimeString )
[ # # ][ # # ]
431 [ # # ][ # # ]: 0 : maTimeEdit.SetText( aTimeString );
[ # # ]
432 : : }
433 : 0 : }
434 : :
435 : : // ------------------------------------------------------------------------------
436 : :
437 : 0 : Image MediaControl::implGetImage( sal_Int32 nImageId ) const
438 : : {
439 : 0 : return maImageList.GetImage( static_cast< sal_uInt16 >( nImageId ) );
440 : : }
441 : :
442 : : // ------------------------------------------------------------------------------
443 : :
444 : 0 : IMPL_LINK( MediaControl, implTimeHdl, Slider*, p )
445 : : {
446 : 0 : mbLocked = true;
447 : 0 : maTimer.Stop();
448 : 0 : implUpdateTimeField( p->GetThumbPos() * maItem.getDuration() / AVMEDIA_TIME_RANGE );
449 : :
450 : 0 : return 0;
451 : : }
452 : :
453 : : // ------------------------------------------------------------------------------
454 : :
455 : 0 : IMPL_LINK( MediaControl, implTimeEndHdl, Slider*, p )
456 : : {
457 [ # # ]: 0 : MediaItem aExecItem;
458 : :
459 [ # # ][ # # ]: 0 : aExecItem.setTime( p->GetThumbPos() * maItem.getDuration() / AVMEDIA_TIME_RANGE );
460 [ # # ]: 0 : execute( aExecItem );
461 [ # # ]: 0 : update();
462 [ # # ]: 0 : maTimer.Start();
463 : 0 : mbLocked = false;
464 : :
465 [ # # ]: 0 : return 0;
466 : : }
467 : :
468 : : // ------------------------------------------------------------------------------
469 : :
470 : 0 : IMPL_LINK( MediaControl, implVolumeHdl, Slider*, p )
471 : : {
472 [ # # ]: 0 : MediaItem aExecItem;
473 : :
474 [ # # ]: 0 : aExecItem.setVolumeDB( static_cast< sal_Int16 >( p->GetThumbPos() ) );
475 [ # # ]: 0 : execute( aExecItem );
476 [ # # ]: 0 : update();
477 : :
478 [ # # ]: 0 : return 0;
479 : : }
480 : :
481 : : // ------------------------------------------------------------------------------
482 : :
483 : 0 : IMPL_LINK_NOARG(MediaControl, implVolumeEndHdl)
484 : : {
485 : 0 : return 0;
486 : : }
487 : :
488 : : // ------------------------------------------------------------------------------
489 : :
490 : 0 : IMPL_LINK( MediaControl, implSelectHdl, ToolBox*, p )
491 : : {
492 [ # # ]: 0 : if( p )
493 : : {
494 [ # # ]: 0 : MediaItem aExecItem;
495 : :
496 [ # # # # : 0 : switch( p->GetCurItemId() )
# # # # ]
497 : : {
498 : : case( AVMEDIA_TOOLBOXITEM_OPEN ):
499 : : {
500 : 0 : ::rtl::OUString aURL;
501 : :
502 [ # # ][ # # ]: 0 : if (::avmedia::MediaWindow::executeMediaURLDialog(
503 [ # # ]: 0 : GetParent(), aURL, 0))
504 : : {
505 [ # # ][ # # ]: 0 : if( !::avmedia::MediaWindow::isMediaURL( aURL, true ) )
506 [ # # ]: 0 : ::avmedia::MediaWindow::executeFormatErrorBox( this );
507 : : else
508 : : {
509 [ # # ]: 0 : aExecItem.setURL( aURL, 0 );
510 [ # # ]: 0 : aExecItem.setState( MEDIASTATE_PLAY );
511 : : }
512 : 0 : }
513 : : }
514 : 0 : break;
515 : :
516 : : case( AVMEDIA_TOOLBOXITEM_INSERT ):
517 : : {
518 [ # # ][ # # ]: 0 : MediaFloater* pFloater = AVMEDIA_MEDIAWINDOW();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
519 : :
520 [ # # ]: 0 : if( pFloater )
521 [ # # ]: 0 : pFloater->dispatchCurrentURL();
522 : : }
523 : 0 : break;
524 : :
525 : : case( AVMEDIA_TOOLBOXITEM_PLAY ):
526 : : case( AVMEDIA_TOOLBOXITEM_PLAYFFW ):
527 : : {
528 [ # # ][ # # ]: 0 : aExecItem.setState( ( AVMEDIA_TOOLBOXITEM_PLAYFFW == p->GetCurItemId() ) ? MEDIASTATE_PLAYFFW : MEDIASTATE_PLAY );
529 : :
530 [ # # ][ # # ]: 0 : if( maItem.getTime() == maItem.getDuration() )
[ # # ]
531 [ # # ]: 0 : aExecItem.setTime( 0.0 );
532 : : else
533 [ # # ][ # # ]: 0 : aExecItem.setTime( maItem.getTime() );
534 : : }
535 : 0 : break;
536 : :
537 : : case( AVMEDIA_TOOLBOXITEM_PAUSE ):
538 : : {
539 [ # # ]: 0 : aExecItem.setState( MEDIASTATE_PAUSE );
540 : : }
541 : 0 : break;
542 : :
543 : : case( AVMEDIA_TOOLBOXITEM_STOP ):
544 : : {
545 [ # # ]: 0 : aExecItem.setState( MEDIASTATE_STOP );
546 [ # # ]: 0 : aExecItem.setTime( 0.0 );
547 : : }
548 : 0 : break;
549 : :
550 : : case( AVMEDIA_TOOLBOXITEM_MUTE ):
551 : : {
552 [ # # ][ # # ]: 0 : aExecItem.setMute( !maMuteToolBox.IsItemChecked( AVMEDIA_TOOLBOXITEM_MUTE ) );
553 : : }
554 : 0 : break;
555 : :
556 : : case( AVMEDIA_TOOLBOXITEM_LOOP ):
557 : : {
558 [ # # ][ # # ]: 0 : aExecItem.setLoop( !maPlayToolBox.IsItemChecked( AVMEDIA_TOOLBOXITEM_LOOP ) );
559 : : }
560 : 0 : break;
561 : :
562 : : default:
563 : 0 : break;
564 : : }
565 : :
566 [ # # ][ # # ]: 0 : if( aExecItem.getMaskSet() != AVMEDIA_SETMASK_NONE )
567 [ # # ][ # # ]: 0 : execute( aExecItem );
568 : : }
569 : :
570 : 0 : update();
571 : 0 : p->Invalidate( INVALIDATE_UPDATE );
572 : :
573 : 0 : return 0;
574 : : }
575 : :
576 : : // ------------------------------------------------------------------------------
577 : :
578 : 0 : IMPL_LINK( MediaControl, implZoomSelectHdl, ListBox*, p )
579 : : {
580 [ # # ]: 0 : if( p )
581 : : {
582 [ # # ]: 0 : MediaItem aExecItem;
583 : : ::com::sun::star::media::ZoomLevel eLevel;
584 : :
585 [ # # ][ # # : 0 : switch( p->GetSelectEntryPos() )
# # # # ]
586 : : {
587 : 0 : case( AVMEDIA_ZOOMLEVEL_50 ): eLevel = ::com::sun::star::media::ZoomLevel_ZOOM_1_TO_2; break;
588 : 0 : case( AVMEDIA_ZOOMLEVEL_100 ): eLevel = ::com::sun::star::media::ZoomLevel_ORIGINAL; break;
589 : 0 : case( AVMEDIA_ZOOMLEVEL_200 ): eLevel = ::com::sun::star::media::ZoomLevel_ZOOM_2_TO_1; break;
590 : 0 : case( AVMEDIA_ZOOMLEVEL_FIT ): eLevel = ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT; break;
591 : 0 : case( AVMEDIA_ZOOMLEVEL_SCALED ): eLevel = ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW; break;
592 : :
593 : 0 : default: eLevel = ::com::sun::star::media::ZoomLevel_NOT_AVAILABLE; break;
594 : : }
595 : :
596 [ # # ]: 0 : aExecItem.setZoom( eLevel );
597 [ # # ]: 0 : execute( aExecItem );
598 [ # # ][ # # ]: 0 : update();
599 : : }
600 : :
601 : 0 : return 0;
602 : : }
603 : :
604 : : // ------------------------------------------------------------------------------
605 : :
606 : 0 : IMPL_LINK_NOARG(MediaControl, implTimeoutHdl)
607 : : {
608 : 0 : update();
609 : 0 : maTimer.Start();
610 : :
611 : 0 : return 0;
612 : : }
613 : :
614 : : }
615 : :
616 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|