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