]> git.sesse.net Git - vlc/blob - modules/gui/wince/timer.cpp
Remove stdlib.h
[vlc] / modules / gui / wince / timer.cpp
1 /*****************************************************************************
2  * timer.cpp : WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 2000-2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <string.h>                                            /* strerror() */
29 #include <stdio.h>
30 #include <vlc/vlc.h>
31 #include <vlc_aout.h>
32 #include <vlc_interface.h>
33
34 #include "wince.h"
35
36 #include <commctrl.h>
37
38 /* Callback prototype */
39 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
40                         vlc_value_t old_val, vlc_value_t new_val, void * );
41
42 /*****************************************************************************
43  * Constructor.
44  *****************************************************************************/
45 Timer::Timer( intf_thread_t *_p_intf, HWND hwnd, Interface *_p_main_interface)
46 {
47     p_intf = _p_intf;
48     p_main_interface = _p_main_interface;
49     i_old_playing_status = PAUSE_S;
50     i_old_rate = INPUT_RATE_DEFAULT;
51
52     /* Register callback for the intf-popupmenu variable */
53     playlist_t *p_playlist =
54         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
55                                        FIND_ANYWHERE );
56     if( p_playlist != NULL )
57     {
58         var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
59         vlc_object_release( p_playlist );
60     }
61
62     SetTimer( hwnd, 1, 200 /*milliseconds*/, NULL );
63 }
64
65 Timer::~Timer()
66 {
67     /* Unregister callback */
68     playlist_t *p_playlist =
69         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
70                                        FIND_ANYWHERE );
71     if( p_playlist != NULL )
72     {
73         var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
74         vlc_object_release( p_playlist );
75     }
76 }
77
78 /*****************************************************************************
79  * Private methods.
80  *****************************************************************************/
81
82 /*****************************************************************************
83  * Manage: manage main thread messages
84  *****************************************************************************
85  * In this function, called approx. 10 times a second, we check what the
86  * main program wanted to tell us.
87  *****************************************************************************/
88 void Timer::Notify( void )
89 {
90     vlc_value_t val;
91     char *shortname;
92
93     vlc_mutex_lock( &p_intf->change_lock );
94
95     /* Update the input */
96     if( p_intf->p_sys->p_input == NULL )
97     {
98         p_intf->p_sys->p_input =
99             (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
100                                                FIND_ANYWHERE );
101
102         /* Show slider */
103         if( p_intf->p_sys->p_input )
104         {
105             ShowWindow( p_main_interface->hwndSlider, SW_SHOW );
106             ShowWindow( p_main_interface->hwndLabel, SW_SHOW );
107             ShowWindow( p_main_interface->hwndVol, SW_SHOW );
108
109             // only for local file, check if works well with net url
110             shortname = strrchr( p_intf->p_sys->p_input->input.p_item->psz_name, '\\' );
111             if (! shortname)
112                 shortname = p_intf->p_sys->p_input->input.p_item->psz_name;
113             else shortname++;
114                         
115             SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
116                          (WPARAM) 0, (LPARAM)_FROMMB(shortname) );
117
118             p_main_interface->TogglePlayButton( PLAYING_S );
119             i_old_playing_status = PLAYING_S;
120         }
121     }
122     else if( p_intf->p_sys->p_input->b_dead )
123     {
124         /* Hide slider */
125         ShowWindow( p_main_interface->hwndSlider, SW_HIDE);
126         ShowWindow( p_main_interface->hwndLabel, SW_HIDE);
127         ShowWindow( p_main_interface->hwndVol, SW_HIDE);
128
129         p_main_interface->TogglePlayButton( PAUSE_S );
130         i_old_playing_status = PAUSE_S;
131
132         SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
133                      (WPARAM) 0, (LPARAM)(LPCTSTR) TEXT(""));
134
135         vlc_object_release( p_intf->p_sys->p_input );
136         p_intf->p_sys->p_input = NULL;
137     }
138
139     if( p_intf->p_sys->p_input )
140     {
141         input_thread_t *p_input = p_intf->p_sys->p_input;
142
143         if( !p_input->b_die )
144         {
145             /* New input or stream map change */
146             p_intf->p_sys->b_playing = 1;
147
148             /* Manage the slider */
149             if( /*p_input->stream.b_seekable &&*/ p_intf->p_sys->b_playing )
150             {
151                 /* Update the slider if the user isn't dragging it. */
152                 if( p_intf->p_sys->b_slider_free )
153                 {
154                     vlc_value_t pos;
155                     char psz_time[ MSTRTIME_MAX_SIZE ];
156                     vlc_value_t time;
157                     mtime_t i_seconds;
158
159                     /* Update the value */
160                     var_Get( p_input, "position", &pos );
161                     if( pos.f_float >= 0.0 )
162                     {
163                         p_intf->p_sys->i_slider_pos =
164                             (int)(SLIDER_MAX_POS * pos.f_float);
165
166                         SendMessage( p_main_interface->hwndSlider, TBM_SETPOS, 
167                                      1, p_intf->p_sys->i_slider_pos );
168
169                         var_Get( p_intf->p_sys->p_input, "time", &time );
170                         i_seconds = time.i_time / 1000000;
171                         secstotimestr ( psz_time, i_seconds );
172
173                         SendMessage( p_main_interface->hwndLabel, WM_SETTEXT, 
174                                      (WPARAM)1, (LPARAM)_FROMMB(psz_time) );
175                     }
176                 }
177             }
178
179             /* Take care of the volume, etc... */
180             p_main_interface->Update();
181
182             /* Manage Playing status */
183             var_Get( p_input, "state", &val );
184             if( i_old_playing_status != val.i_int )
185             {
186                 if( val.i_int == PAUSE_S )
187                 {
188                     p_main_interface->TogglePlayButton( PAUSE_S );
189                 }
190                 else
191                 {
192                     p_main_interface->TogglePlayButton( PLAYING_S );
193                 }
194                 i_old_playing_status = val.i_int;
195             }
196
197             /* Manage Speed status */
198             var_Get( p_input, "rate", &val );
199             if( i_old_rate != val.i_int )
200             {
201                 TCHAR psz_text[15];
202                 _stprintf( psz_text + 2, _T("x%.2f"), 1000.0 / val.i_int );
203                 psz_text[0] = psz_text[1] = _T('\t');
204
205                 SendMessage( p_main_interface->hwndSB, SB_SETTEXT, 
206                              (WPARAM) 1, (LPARAM)(LPCTSTR) psz_text );
207
208                 i_old_rate = val.i_int;
209             }
210         }
211     }
212     else if( p_intf->p_sys->b_playing && !intf_ShouldDie( p_intf ) )
213     {
214         p_intf->p_sys->b_playing = 0;
215         p_main_interface->TogglePlayButton( PAUSE_S );
216         i_old_playing_status = PAUSE_S;
217     }
218
219     if( intf_ShouldDie( p_intf ) )
220     {
221         vlc_mutex_unlock( &p_intf->change_lock );
222
223         /* Prepare to die, young Skywalker */
224 /*        p_main_interface->Close(TRUE);*/
225         return;
226     }
227
228     vlc_mutex_unlock( &p_intf->change_lock );
229 }
230
231 /*****************************************************************************
232  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
233  *  We don't show the menu directly here because we don't want the
234  *  caller to block for a too long time.
235  *****************************************************************************/
236 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
237                         vlc_value_t old_val, vlc_value_t new_val, void *param )
238 {
239     intf_thread_t *p_intf = (intf_thread_t *)param;
240
241     if( p_intf->p_sys->pf_show_dialog )
242     {
243         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
244                                        new_val.b_bool, 0 );
245     }
246
247     return VLC_SUCCESS;
248 }