]> git.sesse.net Git - vlc/blob - modules/gui/wince/interface.cpp
beos/*: update the playlist properly
[vlc] / modules / gui / wince / interface.cpp
1 /*****************************************************************************
2  * interface.cpp: WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 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., 59 Temple Place - Suite 330, Boston, MA  02111,
23  * USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <vlc/vlc.h>
30 #include <vlc/aout.h>
31 #include <vlc/vout.h>
32 #include <vlc/intf.h>
33
34 #include "wince.h"
35
36 #include <windowsx.h>
37 #include <commctrl.h>
38 #include <commdlg.h>
39
40 #define NUMIMAGES     9   // Number of buttons in the toolbar           
41 #define IMAGEWIDTH    17   // Width of the buttons in the toolbar  
42 #define IMAGEHEIGHT   16   // Height of the buttons in the toolbar  
43 #define BUTTONWIDTH   0    // Width of the button images in the toolbar
44 #define BUTTONHEIGHT  0    // Height of the button images in the toolbar
45 #define ID_TOOLBAR    2000 // Identifier of the main tool bar
46
47 // Help strings
48 #define HELP_SIMPLE _T("Quick file open")
49 #define HELP_ADV    _T("Advanced open")
50 #define HELP_FILE   _T("Open a file")
51 #define HELP_DISC   _T("Open Disc Media")
52 #define HELP_NET    _T("Open a network stream")
53 #define HELP_SAT    _T("Open a satellite stream")
54 #define HELP_EJECT  _T("Eject the DVD/CD")
55 #define HELP_EXIT   _T("Exit this program")
56
57 #define HELP_OTHER _T("Open other types of inputs")
58
59 #define HELP_PLAYLIST   _T("Open the playlist")
60 #define HELP_LOGS       _T("Show the program logs")
61 #define HELP_FILEINFO   _T("Show information about the file being played")
62
63 #define HELP_PREFS _T("Go to the preferences menu")
64
65 #define HELP_ABOUT _T("About this program")
66
67 #define HELP_STOP _T("Stop")
68
69 #define HELP_PLAY _T("Play")
70 #define HELP_PAUSE _T("Pause")
71 #define HELP_PLO _T("Playlist")
72 #define HELP_PLP _T("Previous playlist item")
73 #define HELP_PLN _T("Next playlist item")
74 #define HELP_SLOW _T("Play slower")
75 #define HELP_FAST _T("Play faster")
76
77 // The TBBUTTON structure contains information the toolbar buttons.
78 static TBBUTTON tbButton[] =      
79 {
80   {0, ID_FILE_QUICKOPEN,        TBSTATE_ENABLED, TBSTYLE_BUTTON},
81   {1, ID_FILE_OPENNET,       TBSTATE_ENABLED, TBSTYLE_BUTTON},
82   {0, 0,              TBSTATE_ENABLED, TBSTYLE_SEP},
83   {2, StopStream_Event,       TBSTATE_ENABLED, TBSTYLE_BUTTON},
84   {3, PlayStream_Event,        TBSTATE_ENABLED, TBSTYLE_BUTTON},
85   {0, 0,              TBSTATE_ENABLED, TBSTYLE_SEP},
86   {4, ID_VIEW_PLAYLIST,       TBSTATE_ENABLED, TBSTYLE_BUTTON},
87   {0, 0,              TBSTATE_ENABLED, TBSTYLE_SEP},
88   {5, PrevStream_Event,      TBSTATE_ENABLED, TBSTYLE_BUTTON},
89   {6, NextStream_Event,      TBSTATE_ENABLED, TBSTYLE_BUTTON},
90   {0, 0,              TBSTATE_ENABLED, TBSTYLE_SEP},
91   {7, SlowStream_Event,      TBSTATE_ENABLED, TBSTYLE_BUTTON},
92   {8, FastStream_Event,       TBSTATE_ENABLED, TBSTYLE_BUTTON},
93 };
94
95 // Toolbar ToolTips
96 TCHAR * szToolTips[] = 
97 {
98     HELP_SIMPLE, HELP_NET, HELP_STOP, HELP_PLAY, HELP_PLO, HELP_PLP,
99     HELP_PLN, HELP_SLOW, HELP_FAST
100 };
101
102 /*****************************************************************************
103  * Constructor.
104  *****************************************************************************/
105 Interface::Interface( intf_thread_t *p_intf, CBaseWindow *p_parent,
106                       HINSTANCE h_inst )
107   : CBaseWindow( p_intf, p_parent, h_inst ),
108     hwndMain(0), hwndCB(0), hwndTB(0), hwndSlider(0), hwndLabel(0),
109     hwndVol(0), hwndSB(0), timer(0), video(0), b_volume_hold(0)
110 {
111 }
112
113 Interface::~Interface()
114 {
115     if( timer ) delete timer;
116     if( video ) delete video;
117 }
118
119 BOOL Interface::InitInstance()
120 {
121     /* Initializations */
122     i_old_playing_status = PAUSE_S;
123
124     int i_style = WS_VISIBLE;
125
126 #ifndef UNDER_CE
127     i_style |= WS_OVERLAPPEDWINDOW | WS_SIZEBOX;
128 #endif
129
130     // Create main window
131     hwndMain =
132         CreateWindow( _T("VLC WinCE"), _T("VLC media player"), i_style,
133                       0, MENU_HEIGHT, CW_USEDEFAULT, CW_USEDEFAULT,
134                       NULL, NULL, GetInstance(), (void *)this );
135
136     if( !hwndMain ) return FALSE;
137
138     ShowWindow( hwndMain, TRUE );
139     UpdateWindow( hwndMain );
140
141     return TRUE;
142 }
143
144 /***********************************************************************
145 FUNCTION: 
146   CreateMenuBar
147
148 PURPOSE: 
149   Creates a menu bar.
150 ***********************************************************************/
151 HWND Interface::CreateMenuBar( HWND hwnd, HINSTANCE hInst )
152 {
153     HMENU menu_file, menu_view;
154
155 #ifdef UNDER_CE
156     SHMENUBARINFO mbi;
157     memset( &mbi, 0, sizeof(SHMENUBARINFO) );
158     mbi.cbSize     = sizeof(SHMENUBARINFO);
159     mbi.hwndParent = hwnd;
160     mbi.hInstRes   = hInst;
161     mbi.nToolBarId = IDR_MENUBAR;
162
163     if( !SHCreateMenuBar( &mbi ) )
164     {
165         MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
166         return 0;
167     }
168
169     TBBUTTONINFO tbbi;
170     tbbi.cbSize = sizeof(tbbi);
171     tbbi.dwMask = TBIF_LPARAM;
172
173     SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_FILE, (LPARAM)&tbbi );
174     menu_file = (HMENU)tbbi.lParam;
175     RemoveMenu( menu_file, 0, MF_BYPOSITION );
176     SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_VIEW, (LPARAM)&tbbi );
177     menu_view = (HMENU)tbbi.lParam;
178     RemoveMenu( menu_view, 0, MF_BYPOSITION );
179     SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_SETTINGS, (LPARAM)&tbbi );
180     menu_settings = (HMENU)tbbi.lParam;
181     SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_VIDEO, (LPARAM)&tbbi );
182     menu_video = (HMENU)tbbi.lParam;
183     SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_AUDIO, (LPARAM)&tbbi );
184     menu_audio = (HMENU)tbbi.lParam;
185     SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_NAVIGATION, (LPARAM)&tbbi );
186     menu_navigation = (HMENU)tbbi.lParam;
187
188 #else
189     menu_file = CreatePopupMenu();
190     menu_view = CreatePopupMenu();
191     menu_settings = CreatePopupMenu();
192     menu_audio = CreatePopupMenu();
193     menu_video = CreatePopupMenu();
194     menu_navigation = CreatePopupMenu();
195 #endif
196
197     AppendMenu( menu_file, MF_STRING, ID_FILE_QUICKOPEN,
198                 _T("Quick &Open File...") );
199     AppendMenu( menu_file, MF_SEPARATOR, 0, 0 );
200     AppendMenu( menu_file, MF_STRING, ID_FILE_OPENFILE,
201                 _T("Open &File...") );
202     AppendMenu( menu_file, MF_STRING, ID_FILE_OPENDIR,
203                 _T("Open &Directory...") );
204     AppendMenu( menu_file, MF_STRING, ID_FILE_OPENNET,
205                 _T("Open &Network Stream...") );
206     AppendMenu( menu_file, MF_SEPARATOR, 0, 0 );
207     AppendMenu( menu_file, MF_STRING, ID_FILE_ABOUT,
208                 _T("About VLC") );
209     AppendMenu( menu_file, MF_STRING, ID_FILE_EXIT,
210                 _T("E&xit") );
211
212     AppendMenu( menu_view, MF_STRING, ID_VIEW_PLAYLIST,
213                 _T("&Playlist...") );
214     AppendMenu( menu_view, MF_STRING, ID_VIEW_MESSAGES,
215                 _T("&Messages...") );
216     AppendMenu( menu_view, MF_STRING, ID_VIEW_STREAMINFO,
217                 _T("Stream and Media &info...") );
218
219     AppendMenu( menu_settings, MF_STRING, ID_PREFERENCES,
220                 _T("&Preferences...") );
221
222
223 #ifdef UNDER_CE
224     return mbi.hwndMB;
225
226 #else
227     HMENU hmenu = CreateMenu();
228
229     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_file, _T("File") );
230     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_view, _T("View") );
231     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_settings,
232                 _T("Settings") );
233     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_audio, _T("Audio") );
234     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_video, _T("Video") );
235     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_navigation, _T("Nav") );
236
237     SetMenu( hwnd, hmenu );
238     return 0;
239
240 #endif
241 }
242
243 /***********************************************************************
244 FUNCTION: 
245   CreateToolBar
246
247 PURPOSE: 
248   Registers the TOOLBAR control class and creates a toolbar.
249 ***********************************************************************/
250 HWND CreateToolBar( HWND hwnd, HINSTANCE hInst )
251 {
252     DWORD dwStyle;
253     HWND hwndTB;
254     RECT rect, rectTB;
255
256     INITCOMMONCONTROLSEX iccex;
257     iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
258     iccex.dwICC = ICC_BAR_CLASSES;
259
260     // Registers TOOLBAR control classes from the common control dll
261     InitCommonControlsEx (&iccex);
262
263     //  Create the toolbar control
264     dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS |
265         WS_EX_OVERLAPPEDWINDOW | CCS_NOPARENTALIGN;
266
267     hwndTB = CreateToolbarEx( hwnd, dwStyle, 0, NUMIMAGES,
268         hInst, IDB_BITMAP1, tbButton, sizeof(tbButton) / sizeof(TBBUTTON),
269         BUTTONWIDTH, BUTTONHEIGHT, IMAGEWIDTH, IMAGEHEIGHT, sizeof(TBBUTTON) );
270
271     if( !hwndTB ) return NULL;
272   
273     // Add ToolTips to the toolbar.
274     SendMessage( hwndTB, TB_SETTOOLTIPS, (WPARAM)NUMIMAGES, 
275                  (LPARAM)szToolTips );
276
277     // Reposition the toolbar.
278     GetClientRect( hwnd, &rect );
279     GetWindowRect( hwndTB, &rectTB );
280     MoveWindow( hwndTB, rect.left, rect.bottom - rect.top - 2*MENU_HEIGHT, 
281                 rect.right - rect.left, MENU_HEIGHT, TRUE );
282
283     return hwndTB;
284 }
285
286 /***********************************************************************
287
288 FUNCTION: 
289   CreateSliderBar
290
291 PURPOSE: 
292   Registers the TRACKBAR_CLASS control class and creates a trackbar.
293
294 ***********************************************************************/
295 HWND CreateSliderBar( HWND hwnd, HINSTANCE hInst )
296 {
297     HWND hwndSlider;
298     RECT rect;
299
300     INITCOMMONCONTROLSEX iccex;
301     iccex.dwSize = sizeof( INITCOMMONCONTROLSEX );
302     iccex.dwICC = ICC_BAR_CLASSES;
303
304     // Registers TRACKBAR_CLASS control classes from the common control dll
305     InitCommonControlsEx( &iccex );
306
307     hwndSlider = CreateWindowEx( 0, TRACKBAR_CLASS, NULL,
308                 WS_CHILD | WS_VISIBLE | TBS_HORZ | WS_EX_OVERLAPPEDWINDOW |
309                 TBS_BOTTOM,  //|WS_CLIPSIBLINGS,
310                 0, 0, 0, 0, hwnd, NULL, hInst, NULL );
311
312     if( !hwndSlider ) return NULL;
313
314     SendMessage( hwndSlider, TBM_SETRANGEMIN, 1, 0 );
315     SendMessage( hwndSlider, TBM_SETRANGEMAX, 1, SLIDER_MAX_POS );
316     SendMessage( hwndSlider, TBM_SETPOS, 1, 0 );
317
318     // Reposition the trackbar
319     GetClientRect( hwnd, &rect );
320     MoveWindow( hwndSlider, rect.left, 
321                 rect.bottom - rect.top - 2*(MENU_HEIGHT-1) - SLIDER_HEIGHT, 
322                 rect.right - rect.left - 40, 30, TRUE );
323
324     ShowWindow( hwndSlider, SW_HIDE );
325
326     return hwndSlider;
327 }
328
329 HWND CreateStaticText( HWND hwnd, HINSTANCE hInst )
330 {
331     HWND hwndLabel;
332     RECT rect;
333
334     hwndLabel = CreateWindowEx( 0, _T("STATIC"), _T("label"),
335                                 WS_CHILD | WS_VISIBLE | SS_CENTER ,
336                                 0, 0, 0, 0, hwnd, (HMENU)1980, hInst, NULL );
337
338     // Reposition the trackbar
339     GetClientRect( hwnd, &rect );
340
341     MoveWindow( hwndLabel, rect.left,
342                 rect.bottom - rect.top - 2*(MENU_HEIGHT-1) - SLIDER_HEIGHT +30,
343                 rect.right - rect.left - 40,
344                 SLIDER_HEIGHT - 30, TRUE );
345
346     ShowWindow( hwndLabel, SW_HIDE );
347
348     return hwndLabel;
349 }
350
351 /***********************************************************************
352
353 FUNCTION: 
354   CreateVolTrackBar
355
356 PURPOSE: 
357   Registers the TRACKBAR_CLASS control class and creates a trackbar.
358
359 ***********************************************************************/
360 HWND CreateVolTrackBar( HWND hwnd, HINSTANCE hInst )
361 {
362     HWND hwndVol;
363     RECT rect;
364
365     INITCOMMONCONTROLSEX iccex;
366     iccex.dwSize = sizeof( INITCOMMONCONTROLSEX );
367     iccex.dwICC = ICC_BAR_CLASSES;
368
369     // Registers TRACKBAR_CLASS control classes from the common control dll
370     InitCommonControlsEx( &iccex );
371
372     hwndVol = CreateWindowEx( 0, TRACKBAR_CLASS, NULL,
373                 WS_CHILD | WS_VISIBLE | TBS_VERT | TBS_RIGHT | TBS_AUTOTICKS |
374                 WS_EX_OVERLAPPEDWINDOW, //|WS_CLIPSIBLINGS,
375                 0, 0, 0, 0, hwnd, NULL, hInst, NULL );
376
377     if( !hwndVol ) return NULL;
378
379     SendMessage( hwndVol, TBM_SETRANGEMIN, 1, 0 );
380     SendMessage( hwndVol, TBM_SETRANGEMAX, 1, 200 );
381     SendMessage( hwndVol, TBM_SETPOS, 1, 100 );
382     SendMessage( hwndVol, TBM_SETTICFREQ, 50, 0 );  
383
384     // Reposition the trackbar
385     GetClientRect( hwnd, &rect );
386     MoveWindow( hwndVol, rect.right - rect.left - 40, 
387                 rect.bottom - rect.top - 2*(MENU_HEIGHT-1) - SLIDER_HEIGHT, 
388                 40, SLIDER_HEIGHT, TRUE );
389
390     ShowWindow( hwndVol, SW_HIDE );
391
392     return hwndVol;
393 }
394
395 /***********************************************************************
396
397 FUNCTION: 
398   CreateStatusBar
399
400 PURPOSE: 
401   Registers the StatusBar control class and creates a Statusbar.
402
403 ***********************************************************************/
404 HWND CreateStatusBar( HWND hwnd, HINSTANCE hInst )
405 {
406     DWORD dwStyle;
407     HWND hwndSB;
408     RECT rect;
409
410     INITCOMMONCONTROLSEX iccex;
411     iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
412     iccex.dwICC = ICC_BAR_CLASSES;
413
414     // Registers Statusbar control classes from the common control dll
415     InitCommonControlsEx( &iccex );
416
417     // Create the statusbar control
418     dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS | CCS_NOPARENTALIGN;
419
420     hwndSB = CreateWindowEx( 0, STATUSCLASSNAME, NULL,
421                              WS_CHILD | WS_VISIBLE | TBS_VERT | TBS_BOTTOM |
422                              TBS_RIGHT  |WS_CLIPSIBLINGS,
423                              0, 0, CW_USEDEFAULT, 50, hwnd, NULL, hInst, 0 );
424
425     if (!hwndSB ) return NULL;
426
427     // Get the coordinates of the parent window's client area. 
428     GetClientRect( hwnd, &rect );
429
430     // allocate memory for the panes of status bar
431     int nopanes = 2;
432     int *indicators = new int[nopanes];
433
434     // set width for the panes
435     indicators[0] = 3 * ( rect.right - rect.left ) / 4;
436     indicators[1] = rect.right - rect.left;
437
438     // call functions to set style
439     SendMessage( hwndSB, SB_SETPARTS, (WPARAM)nopanes, (LPARAM)indicators );
440
441     return hwndSB;
442 }
443
444 /***********************************************************************
445 FUNCTION: 
446   WndProc
447
448 PURPOSE: 
449   Processes messages sent to the main window.
450 ***********************************************************************/
451 LRESULT Interface::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
452 {
453     switch( msg )
454     {
455     case WM_CREATE:
456         hwndCB = CreateMenuBar( hwnd, hInst );
457         hwndTB = CreateToolBar( hwnd, hInst );
458         hwndSlider = CreateSliderBar( hwnd, hInst );
459         hwndLabel = CreateStaticText( hwnd, hInst );
460         hwndVol = CreateVolTrackBar( hwnd, hInst );
461 #ifdef UNDER_CE
462         hwndSB = CreateStatusBar( hwnd, hInst );
463 #endif
464
465         /* Video window */
466         if( config_GetInt( p_intf, "wince-embed" ) )
467             video = CreateVideoWindow( p_intf, hwnd );
468
469         timer = new Timer( p_intf, hwnd, this );
470         break;
471
472     case WM_COMMAND:
473         switch( GET_WM_COMMAND_ID(wp,lp) )
474         {
475         case ID_FILE_QUICKOPEN: 
476         case ID_FILE_OPENFILE: 
477         case ID_FILE_OPENDIR:
478         case ID_FILE_OPENNET:
479         case ID_VIEW_STREAMINFO:
480         case ID_VIEW_MESSAGES:
481         case ID_VIEW_PLAYLIST:
482         case ID_PREFERENCES:
483             OnShowDialog( GET_WM_COMMAND_ID(wp,lp) );
484             break;
485
486         case PlayStream_Event: OnPlayStream(); break;
487         case StopStream_Event: OnStopStream(); break;
488         case PrevStream_Event: OnPrevStream(); break;
489         case NextStream_Event: OnNextStream(); break;
490         case SlowStream_Event: OnSlowStream(); break;
491         case FastStream_Event: OnFastStream(); break;
492
493         case ID_FILE_ABOUT: 
494         {
495             string about = (string)"VLC media player " PACKAGE_VERSION +
496                 _("\n(WinCE interface)\n\n") +
497                 _("(c) 1996-2005 - the VideoLAN Team\n\n") +
498                 _("The VideoLAN team <videolan@videolan.org>\n"
499                   "http://www.videolan.org/\n\n");
500
501             MessageBox( hwnd, _FROMMB(about.c_str()),
502                         _T("About VLC media player"), MB_OK );
503             break;
504         }
505
506         case ID_FILE_EXIT:
507             SendMessage( hwnd, WM_CLOSE, 0, 0 );
508             break;
509
510         default:
511             OnMenuEvent( p_intf, GET_WM_COMMAND_ID(wp,lp) );
512             // we should test if it is a menu command
513         }
514         break;
515   
516     case WM_TIMER:
517         timer->Notify();
518         break;
519
520     case WM_CTLCOLORSTATIC: 
521         if( ( (HWND)lp == hwndSlider ) || ( (HWND)lp == hwndVol ) )
522         { 
523             return( (LRESULT)::GetSysColorBrush(COLOR_3DFACE) ); 
524         }
525         if( (HWND)lp == hwndLabel )
526         {
527             SetBkColor( (HDC)wp, RGB (192, 192, 192) ); 
528             return( (LRESULT)::GetSysColorBrush(COLOR_3DFACE) ); 
529         }
530         break;
531
532     case WM_HSCROLL:
533         if( (HWND)lp == hwndSlider ) OnSliderUpdate( wp );
534         break;
535
536     case WM_VSCROLL:
537         if( (HWND)lp == hwndVol ) OnChange( wp );
538         break;
539
540     case WM_INITMENUPOPUP:
541         if( (HMENU)wp == menu_settings )
542             RefreshSettingsMenu( p_intf, menu_settings );
543         if( (HMENU)wp == menu_audio )
544             RefreshAudioMenu( p_intf, menu_audio );
545         if( (HMENU)wp == menu_video )
546             RefreshVideoMenu( p_intf, menu_video );
547         if( (HMENU)wp == menu_navigation )
548             RefreshNavigMenu( p_intf, menu_navigation );
549         /* Fall through */
550
551     case WM_KILLFOCUS:
552         SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
553     case WM_ENTERMENULOOP:
554         if( video && video->hWnd )
555             SendMessage( video->hWnd, WM_KILLFOCUS, 0, 0 );
556         break;
557
558     case WM_SETFOCUS:
559         SHSipPreference( hwnd, SIP_DOWN ); 
560         SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
561     case WM_EXITMENULOOP:
562         if( video && video->hWnd )
563             SendMessage( video->hWnd, WM_SETFOCUS, 0, 0 );
564         break;
565
566     case WM_LBUTTONDOWN:
567         {
568             SHRGINFO shrg;
569             shrg.cbSize = sizeof( shrg );
570             shrg.hwndClient = hwnd;
571             shrg.ptDown.x = LOWORD(lp);
572             shrg.ptDown.y = HIWORD(lp);
573             shrg.dwFlags = SHRG_RETURNCMD ;
574
575             if( SHRecognizeGesture( &shrg ) == GN_CONTEXTMENU )
576                 PopupMenu( p_intf, hwnd, shrg.ptDown );
577         }
578         break;
579
580    case WM_RBUTTONUP:
581         {
582             POINT point;
583             point.x = LOWORD(lp);
584             point.y = HIWORD(lp);
585             PopupMenu( p_intf, hwnd, point );
586         }
587         break;
588
589     case WM_HELP:
590         MessageBox (hwnd, _T("Help"), _T("Help"), MB_OK);
591         break;
592
593     case WM_CLOSE:
594         if( hwndCB ) DestroyWindow( hwndCB );
595         DestroyWindow( hwnd );
596         break;
597
598     case WM_DESTROY:
599         PostQuitMessage( 0 );
600         break;
601     }
602
603     return DefWindowProc( hwnd, msg, wp, lp );
604 }
605
606 void Interface::OnShowDialog( int i_dialog_event )
607 {
608     int i_id;
609
610     switch( i_dialog_event )
611     {
612     case ID_FILE_QUICKOPEN: i_id = INTF_DIALOG_FILE_SIMPLE; break;
613     case ID_FILE_OPENFILE: i_id = INTF_DIALOG_FILE; break;
614     case ID_FILE_OPENDIR: i_id = INTF_DIALOG_DIRECTORY; break;
615     case ID_FILE_OPENNET: i_id = INTF_DIALOG_NET; break;
616     case ID_VIEW_PLAYLIST: i_id = INTF_DIALOG_PLAYLIST; break;
617     case ID_VIEW_MESSAGES: i_id = INTF_DIALOG_MESSAGES; break;
618     case ID_VIEW_STREAMINFO: i_id = INTF_DIALOG_FILEINFO; break;
619     case ID_PREFERENCES: i_id = INTF_DIALOG_PREFS; break;
620     default: i_id = INTF_DIALOG_FILE; break;
621     }
622
623     if( p_intf->p_sys->pf_show_dialog )
624         p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
625 }
626
627 void Interface::OnPlayStream( void )
628 {
629     playlist_t *p_playlist = (playlist_t *)
630         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
631     if( p_playlist == NULL ) return;
632
633     if( p_playlist->i_size && p_playlist->i_enabled )
634     {
635         vlc_value_t state;
636
637         input_thread_t *p_input = (input_thread_t *)
638             vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
639
640         if( p_input == NULL )
641         {
642             /* No stream was playing, start one */
643             playlist_Play( p_playlist );
644             TogglePlayButton( PLAYING_S );
645             vlc_object_release( p_playlist );
646             return;
647         }
648
649         var_Get( p_input, "state", &state );
650
651         if( state.i_int != PAUSE_S )
652         {
653             /* A stream is being played, pause it */
654             state.i_int = PAUSE_S;
655         }
656         else
657         {
658             /* Stream is paused, resume it */
659             state.i_int = PLAYING_S;
660         }
661         var_Set( p_input, "state", state );
662
663         TogglePlayButton( state.i_int );
664         vlc_object_release( p_input );
665         vlc_object_release( p_playlist );
666     }
667     else
668     {
669         /* If the playlist is empty, open a file requester instead */
670         vlc_object_release( p_playlist );
671         OnShowDialog( ID_FILE_QUICKOPEN );
672     }
673 }
674
675 void Interface::TogglePlayButton( int i_playing_status )
676 {
677     TBREPLACEBITMAP tbrb;
678     tbrb.hInstOld = tbrb.hInstNew = (HINSTANCE) hInst;
679     tbrb.nButtons = NUMIMAGES;
680
681     if( i_playing_status == i_old_playing_status ) return;
682
683     if( i_playing_status == PLAYING_S )
684     {
685         tbrb.nIDOld = IDB_BITMAP2;
686         tbrb.nIDNew = IDB_BITMAP1;
687
688         SendMessage( hwndTB, TB_REPLACEBITMAP, (WPARAM)0,
689                      (LPARAM)(LPTBREPLACEBITMAP)&tbrb );
690     }
691     else
692     {
693         tbrb.nIDOld = IDB_BITMAP1;
694         tbrb.nIDNew = IDB_BITMAP2;
695
696         SendMessage( hwndTB, TB_REPLACEBITMAP, (WPARAM)0,
697                      (LPARAM)(LPTBREPLACEBITMAP)&tbrb );
698     }
699
700     UpdateWindow( hwndTB );
701
702     i_old_playing_status = i_playing_status;
703 }
704
705 void Interface::OnVideoOnTop( void )
706 {
707     vlc_value_t val;
708
709     vout_thread_t *p_vout = (vout_thread_t *)
710         vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
711
712     if( p_vout == NULL ) return;
713
714     if( var_Get( (vlc_object_t *)p_vout, "video-on-top", &val ) < 0 )
715         return;
716
717     val.b_bool = !val.b_bool;
718     var_Set( (vlc_object_t *)p_vout, "video-on-top", val );
719
720     vlc_object_release( (vlc_object_t *)p_vout );
721 }
722
723 void Interface::OnSliderUpdate( int wp )
724 {
725     vlc_mutex_lock( &p_intf->change_lock );
726     input_thread_t *p_input = p_intf->p_sys->p_input;
727
728     int dwPos = SendMessage( hwndSlider, TBM_GETPOS, 0, 0 ); 
729
730     if( (int)LOWORD(wp) == SB_THUMBPOSITION ||
731         (int)LOWORD(wp) == SB_ENDSCROLL )
732     {
733         if( p_intf->p_sys->i_slider_pos != dwPos && p_input )
734         {
735             vlc_value_t pos;
736             pos.f_float = (float)dwPos / (float)SLIDER_MAX_POS;
737             var_Set( p_input, "position", pos );
738         }
739
740         p_intf->p_sys->b_slider_free = VLC_TRUE;
741     }
742     else
743     {
744         p_intf->p_sys->b_slider_free = VLC_FALSE;
745
746         if( p_input )
747         {
748             /* Update stream date */
749             char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
750             mtime_t i_seconds;
751
752             i_seconds = var_GetTime( p_input, "length" ) / I64C(1000000 );
753             secstotimestr( psz_total, i_seconds );
754
755             i_seconds = var_GetTime( p_input, "time" ) / I64C(1000000 );
756             secstotimestr( psz_time, i_seconds );
757
758             SendMessage( hwndLabel, WM_SETTEXT, (WPARAM)1,
759                          (LPARAM)_FROMMB(psz_time) );
760         }
761     }
762
763     vlc_mutex_unlock( &p_intf->change_lock );
764 }
765
766 void Interface::OnChange( int wp )
767 {
768     DWORD dwPos = SendMessage( hwndVol, TBM_GETPOS, 0, 0 );
769
770     if( LOWORD(wp) == SB_THUMBPOSITION || LOWORD(wp) == SB_ENDSCROLL )
771     {
772         VolumeChange( 200 - (int)dwPos );
773         b_volume_hold = VLC_FALSE;
774     }
775     else
776     {
777         b_volume_hold = VLC_TRUE;
778     }
779 }
780
781 void Interface::VolumeChange( int i_volume )
782 {
783     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
784 }
785
786 void Interface::VolumeUpdate()
787 {
788     audio_volume_t i_volume;
789
790     if( b_volume_hold ) return;
791
792     aout_VolumeGet( p_intf, &i_volume );
793
794     int i_volume_ctrl = 200 - i_volume * 200 * 2 / AOUT_VOLUME_MAX;
795
796     DWORD dwPos = SendMessage( hwndVol, TBM_GETPOS, 0, 0 );
797     if( i_volume_ctrl == (int)dwPos ) return;
798
799     SendMessage( hwndVol, TBM_SETPOS, 1, i_volume_ctrl );
800 }
801
802 void Interface::OnStopStream( void )
803 {
804     playlist_t * p_playlist = (playlist_t *)
805         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
806     if( p_playlist == NULL ) return;
807
808     playlist_Stop( p_playlist );
809     TogglePlayButton( PAUSE_S );
810     vlc_object_release( p_playlist );
811 }
812
813 void Interface::OnPrevStream( void )
814 {
815     playlist_t * p_playlist = (playlist_t *)
816         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
817     if( p_playlist == NULL ) return;
818
819     playlist_Prev( p_playlist );
820     vlc_object_release( p_playlist );
821 }
822
823 void Interface::OnNextStream( void )
824 {
825     playlist_t * p_playlist = (playlist_t *)
826         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
827     if( p_playlist == NULL ) return;
828
829     playlist_Next( p_playlist );
830     vlc_object_release( p_playlist );
831 }
832
833 void Interface::OnSlowStream( void )
834 {
835     input_thread_t *p_input = (input_thread_t *)
836         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
837
838     if( p_input == NULL ) return;
839
840     vlc_value_t val; val.b_bool = VLC_TRUE;
841     var_Set( p_input, "rate-slower", val );
842     vlc_object_release( p_input );
843 }
844
845 void Interface::OnFastStream( void )
846 {
847     input_thread_t *p_input = (input_thread_t *)
848         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
849
850     if( p_input == NULL ) return;
851
852     vlc_value_t val; val.b_bool = VLC_TRUE;
853     var_Set( p_input, "rate-faster", val );
854     vlc_object_release( p_input );
855 }
856
857 void Interface::Update()
858 {
859     /* Misc updates */
860     VolumeUpdate();
861 }