]> git.sesse.net Git - vlc/blob - modules/gui/wince/interface.cpp
* modules/gui/wince: usual bunch of cleanup + updates.
[vlc] / modules / gui / wince / interface.cpp
1 /*****************************************************************************
2  * interface.cpp: WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
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 <winuser.h>
37 #include <windows.h>
38 #include <windowsx.h>
39 #include <commctrl.h>
40 #include <commdlg.h>
41
42 #define NUMIMAGES     9   // Number of buttons in the toolbar           
43 #define IMAGEWIDTH    17   // Width of the buttons in the toolbar  
44 #define IMAGEHEIGHT   16   // Height of the buttons in the toolbar  
45 #define BUTTONWIDTH   0    // Width of the button images in the toolbar
46 #define BUTTONHEIGHT  0    // Height of the button images in the toolbar
47 #define ID_TOOLBAR    2000 // Identifier of the main tool bar
48
49 // Help strings
50 #define HELP_SIMPLE _T("Quick file open")
51 #define HELP_ADV    _T("Advanced open")
52 #define HELP_FILE   _T("Open a file")
53 #define HELP_DISC   _T("Open Disc Media")
54 #define HELP_NET    _T("Open a network stream")
55 #define HELP_SAT    _T("Open a satellite stream")
56 #define HELP_EJECT  _T("Eject the DVD/CD")
57 #define HELP_EXIT   _T("Exit this program")
58
59 #define HELP_OTHER _T("Open other types of inputs")
60
61 #define HELP_PLAYLIST   _T("Open the playlist")
62 #define HELP_LOGS       _T("Show the program logs")
63 #define HELP_FILEINFO   _T("Show information about the file being played")
64
65 #define HELP_PREFS _T("Go to the preferences menu")
66 #define EXTRA_PREFS _T("Shows the extended GUI")
67
68 #define HELP_ABOUT _T("About this program")
69
70 #define HELP_STOP _T("Stop")
71
72 #define HELP_PLAY _T("Play")
73 #define HELP_PAUSE _T("Pause")
74 #define HELP_PLO _T("Playlist")
75 #define HELP_PLP _T("Previous playlist item")
76 #define HELP_PLN _T("Next playlist item")
77 #define HELP_SLOW _T("Play slower")
78 #define HELP_FAST _T("Play faster")
79
80 // The TBBUTTON structure contains information the toolbar buttons.
81 static TBBUTTON tbButton[] =      
82 {
83   {0, ID_FILE_QUICKOPEN,        TBSTATE_ENABLED, TBSTYLE_BUTTON},
84   {1, ID_FILE_OPENNET,       TBSTATE_ENABLED, TBSTYLE_BUTTON},
85   {0, 0,              TBSTATE_ENABLED, TBSTYLE_SEP},
86   {2, StopStream_Event,       TBSTATE_ENABLED, TBSTYLE_BUTTON},
87   {3, PlayStream_Event,        TBSTATE_ENABLED, TBSTYLE_BUTTON},
88   {0, 0,              TBSTATE_ENABLED, TBSTYLE_SEP},
89   {4, ID_VIEW_PLAYLIST,       TBSTATE_ENABLED, TBSTYLE_BUTTON},
90   {0, 0,              TBSTATE_ENABLED, TBSTYLE_SEP},
91   {5, PrevStream_Event,      TBSTATE_ENABLED, TBSTYLE_BUTTON},
92   {6, NextStream_Event,      TBSTATE_ENABLED, TBSTYLE_BUTTON},
93   {0, 0,              TBSTATE_ENABLED, TBSTYLE_SEP},
94   {7, SlowStream_Event,      TBSTATE_ENABLED, TBSTYLE_BUTTON},
95   {8, FastStream_Event,       TBSTATE_ENABLED, TBSTYLE_BUTTON},
96 };
97
98 // Toolbar ToolTips
99 TCHAR * szToolTips[] = 
100 {
101     HELP_SIMPLE, HELP_NET, HELP_STOP, HELP_PLAY, HELP_PLO, HELP_PLP,
102     HELP_PLN, HELP_SLOW, HELP_FAST
103 };
104
105 /*****************************************************************************
106  * Constructor.
107  *****************************************************************************/
108 BOOL Interface::InitInstance( HINSTANCE hInstance, intf_thread_t *_p_intf )
109 {
110     /* Initializations */
111     p_intf = _p_intf;
112     hwndMain = hwndCB = hwndTB = hwndSlider = hwndLabel = hwndVol = hwndSB = 0;
113     i_old_playing_status = PAUSE_S;
114
115     hInst = hInstance; // Store instance handle in our global variable
116
117     // Register window class
118     WNDCLASS wc;
119     wc.style = CS_HREDRAW | CS_VREDRAW ;
120     wc.lpfnWndProc = (WNDPROC)BaseWndProc;
121     wc.cbClsExtra = 0;
122     wc.cbWndExtra = 0;
123     wc.hIcon = NULL;
124     wc.hInstance = hInstance;
125     wc.hCursor = NULL;
126     wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
127     wc.lpszMenuName = NULL;
128     wc.lpszClassName = _T("VLC WinCE");
129     if( !RegisterClass( &wc ) ) return FALSE;
130
131     int i_style = WS_VISIBLE;
132
133 #ifndef UNDER_CE
134     i_style |= WS_OVERLAPPEDWINDOW | WS_SIZEBOX;
135 #endif
136
137     // Create main window
138     hwndMain =
139         CreateWindow( _T("VLC WinCE"), _T("VLC media player"), i_style,
140                       0, MENU_HEIGHT, CW_USEDEFAULT, CW_USEDEFAULT,
141                       NULL, NULL, hInstance, (void *)this );
142
143     if( !hwndMain ) return FALSE;
144
145     ShowWindow( hwndMain, TRUE );
146     UpdateWindow( hwndMain );
147
148     return TRUE;
149 }
150
151 /***********************************************************************
152 FUNCTION: 
153   CreateMenuBar
154
155 PURPOSE: 
156   Creates a menu bar.
157 ***********************************************************************/
158 static HWND CreateMenuBar( HWND hwnd, HINSTANCE hInst )
159 {
160 #ifdef UNDER_CE
161     SHMENUBARINFO mbi;
162     memset( &mbi, 0, sizeof(SHMENUBARINFO) );
163     mbi.cbSize     = sizeof(SHMENUBARINFO);
164     mbi.hwndParent = hwnd;
165     mbi.hInstRes   = hInst;
166     mbi.nToolBarId = IDR_MENUBAR;
167
168     if( !SHCreateMenuBar( &mbi ) )
169     {
170         MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
171         return 0;
172     }
173
174     TBBUTTONINFO tbbi;
175     tbbi.cbSize = sizeof(tbbi);
176     tbbi.dwMask = TBIF_LPARAM;
177
178     SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_FILE, (LPARAM)&tbbi );
179     HMENU hmenu_file = (HMENU)tbbi.lParam;
180     RemoveMenu( hmenu_file, 0, MF_BYPOSITION );
181     SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_VIEW, (LPARAM)&tbbi );
182     HMENU hmenu_view = (HMENU)tbbi.lParam;
183     RemoveMenu( hmenu_view, 0, MF_BYPOSITION );
184     SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_SETTINGS, (LPARAM)&tbbi );
185     HMENU hmenu_settings = (HMENU)tbbi.lParam;
186
187 #else
188     HMENU hmenu_file = CreatePopupMenu();
189     HMENU hmenu_view = CreatePopupMenu();
190     HMENU hmenu_settings = CreatePopupMenu();
191     HMENU hmenu_audio = CreatePopupMenu();
192     HMENU hmenu_video = CreatePopupMenu();
193     HMENU hmenu_navigation = CreatePopupMenu();
194 #endif
195
196     AppendMenu( hmenu_file, MF_STRING, ID_FILE_QUICKOPEN,
197                 _T("Quick &Open File") );
198     AppendMenu( hmenu_file, MF_SEPARATOR, 0, 0 );
199     AppendMenu( hmenu_file, MF_STRING, ID_FILE_OPENFILE,
200                 _T("Open &File") );
201     AppendMenu( hmenu_file, MF_STRING, ID_FILE_OPENNET,
202                 _T("Open Network Stream") );
203     AppendMenu( hmenu_file, MF_SEPARATOR, 0, 0 );
204     AppendMenu( hmenu_file, MF_STRING, ID_FILE_ABOUT,
205                 _T("About VLC") );
206     AppendMenu( hmenu_file, MF_STRING, ID_FILE_EXIT,
207                 _T("E&xit") );
208
209     AppendMenu( hmenu_view, MF_STRING, ID_VIEW_PLAYLIST,
210                 _T("&Playlist") );
211     AppendMenu( hmenu_view, MF_STRING, ID_VIEW_MESSAGES,
212                 _T("&Messages") );
213     AppendMenu( hmenu_view, MF_STRING, ID_VIEW_STREAMINFO,
214                 _T("&Stream and Media info") );
215
216     AppendMenu( hmenu_settings, MF_STRING, ID_SETTINGS_EXTEND,
217                 _T("&Extended GUI") );
218     AppendMenu( hmenu_settings, MF_STRING, ID_SETTINGS_PREF,
219                 _T("&Preferences...") );
220
221
222 #ifdef UNDER_CE
223     return mbi.hwndMB;
224
225 #else
226     HMENU hmenu = CreateMenu();
227
228     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_file, _T("File") );
229     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_view, _T("View") );
230     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_settings,
231                 _T("Settings") );
232     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_audio, _T("Audio") );
233     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_video, _T("Video") );
234     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_navigation,
235                 _T("Nav.") );
236
237     SetMenu( hwnd, hmenu );
238     return hwnd;
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   CreateDialogBox
447
448 PURPOSE:
449   Creates a Dialog Box.
450 ***********************************************************************/
451 int CBaseWindow::CreateDialogBox( HWND hwnd, CBaseWindow *p_obj )
452 {
453     uint8_t p_buffer[sizeof(DLGTEMPLATE) + sizeof(WORD) * 4];
454     DLGTEMPLATE *p_dlg_template = (DLGTEMPLATE *)p_buffer;
455     memset( p_dlg_template, 0, sizeof(DLGTEMPLATE) + sizeof(WORD) * 4 );
456
457     // these values are arbitrary, they won't be used normally anyhow
458     p_dlg_template->x  = 0; p_dlg_template->y  = 0;
459     p_dlg_template->cx = 300; p_dlg_template->cy = 300;
460     p_dlg_template->style =
461         DS_MODALFRAME|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX;
462
463     return DialogBoxIndirectParam( GetModuleHandle(0), p_dlg_template, hwnd,
464                                    (DLGPROC)p_obj->BaseWndProc, (LPARAM)p_obj );
465 }
466
467 /***********************************************************************
468 FUNCTION: 
469   BaseWndProc
470
471 PURPOSE: 
472   Processes messages sent to the main window.
473 ***********************************************************************/
474 LRESULT CALLBACK CBaseWindow::BaseWndProc( HWND hwnd, UINT msg, WPARAM wParam,
475                                            LPARAM lParam )
476 {
477     CBaseWindow *p_obj;
478
479     // check to see if a copy of the 'this' pointer needs to be saved
480     if( msg == WM_CREATE )
481     {
482         p_obj = (CBaseWindow *)(((LPCREATESTRUCT)lParam)->lpCreateParams);
483         SetWindowLong( hwnd, GWL_USERDATA,
484                        (LONG)((LPCREATESTRUCT)lParam)->lpCreateParams );
485
486         p_obj->hWnd = hwnd;
487     }
488
489     if( msg == WM_INITDIALOG )
490     {
491         p_obj = (CBaseWindow *)lParam;
492         SetWindowLong( hwnd, GWL_USERDATA, lParam );
493         p_obj->hWnd = hwnd;
494     }
495
496     // Retrieve the pointer
497     p_obj = (CBaseWindow *)GetWindowLong( hwnd, GWL_USERDATA );
498
499     if( !p_obj ) return DefWindowProc( hwnd, msg, wParam, lParam );
500
501     // Filter message through child classes
502     return p_obj->WndProc( hwnd, msg, wParam, lParam );
503 }
504
505 /***********************************************************************
506 FUNCTION: 
507   WndProc
508
509 PURPOSE: 
510   Processes messages sent to the main window.
511 ***********************************************************************/
512 LRESULT CALLBACK Interface::WndProc( HWND hwnd, UINT msg, WPARAM wp,
513                                      LPARAM lp )
514 {
515     switch( msg )
516     {
517     case WM_CREATE:
518         hwndCB = CreateMenuBar( hwnd, hInst );
519         hwndTB = CreateToolBar( hwnd, hInst );
520         hwndSlider = CreateSliderBar( hwnd, hInst );
521         hwndLabel = CreateStaticText( hwnd, hInst );
522         hwndVol = CreateVolTrackBar( hwnd, hInst );
523 #ifdef UNDER_CE
524         hwndSB = CreateStatusBar( hwnd, hInst );
525 #endif
526
527         /* Video window */
528         if( config_GetInt( p_intf, "wince-embed" ) )
529             video = CreateVideoWindow( p_intf, hwnd );
530
531         ti = new Timer(p_intf, hwnd, this);
532
533         // Hide the SIP button (WINCE only)
534         SetForegroundWindow( hwnd );
535         SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
536         break;
537
538     case WM_COMMAND:
539         switch( GET_WM_COMMAND_ID(wp,lp) )
540         {
541         case ID_FILE_QUICKOPEN: 
542             OnOpenFileSimple();
543             break;
544
545         case ID_FILE_OPENFILE: 
546             open = new OpenDialog( p_intf, hInst, FILE_ACCESS,
547                                    ID_FILE_OPENFILE, OPEN_NORMAL );
548             CreateDialogBox( hwnd, open );
549             delete open;
550             break;
551
552         case ID_FILE_OPENNET:
553             open = new OpenDialog( p_intf, hInst, NET_ACCESS, ID_FILE_OPENNET,
554                                    OPEN_NORMAL );
555             CreateDialogBox( hwnd, open );
556             delete open;
557             break;
558
559         case PlayStream_Event: 
560             OnPlayStream();
561             break;
562
563         case StopStream_Event: 
564             OnStopStream();
565             break;
566
567         case PrevStream_Event: 
568             OnPrevStream();
569             break;
570
571         case NextStream_Event: 
572             OnNextStream();
573             break;
574
575         case SlowStream_Event: 
576             OnSlowStream();
577             break;
578
579         case FastStream_Event: 
580             OnFastStream();
581             break;
582
583         case ID_FILE_ABOUT: 
584         {
585             string about = (string)"VLC media player " PACKAGE_VERSION +
586                 _("\n(WinCE interface)\n\n") +
587                 _("(c) 1996-2005 - the VideoLAN Team\n\n") +
588                 _("The VideoLAN team <videolan@videolan.org>\n"
589                   "http://www.videolan.org/\n\n");
590
591             MessageBox( hwnd, _FROMMB(about.c_str()),
592                         _T("About VLC media player"), MB_OK );
593             break;
594         }
595
596         case ID_FILE_EXIT:
597             SendMessage( hwnd, WM_CLOSE, 0, 0 );
598             break;
599
600         case ID_VIEW_STREAMINFO:
601             fi = new FileInfo( p_intf, hInst );
602             CreateDialogBox( hwnd, fi );
603             delete fi;
604             break;
605
606         case ID_VIEW_MESSAGES:
607             hmsg = new Messages( p_intf, hInst );
608             CreateDialogBox( hwnd, hmsg );
609             delete hmsg;
610             break;
611
612         case ID_VIEW_PLAYLIST:
613             pl = new Playlist( p_intf, hInst );
614             CreateDialogBox( hwnd, pl );
615             delete pl;
616             break;
617
618         case ID_SETTINGS_PREF:
619             pref = new PrefsDialog( p_intf, hInst );
620             CreateDialogBox( hwnd, pref );
621             delete pref;
622             break;
623                   
624         default:
625             OnMenuEvent( p_intf, GET_WM_COMMAND_ID(wp,lp) );
626             // we should test if it is a menu command
627         }
628         break;
629   
630     case WM_TIMER:
631         ti->Notify();
632         break;
633
634     case WM_CTLCOLORSTATIC: 
635         if( ( (HWND)lp == hwndSlider ) || ( (HWND)lp == hwndVol ) )
636         { 
637             return( (LRESULT)::GetSysColorBrush(COLOR_3DFACE) ); 
638         }
639         if( (HWND)lp == hwndLabel )
640         {
641             SetBkColor( (HDC)wp, RGB (192, 192, 192) ); 
642             return( (LRESULT)::GetSysColorBrush(COLOR_3DFACE) ); 
643         }
644         break;
645
646     case WM_HSCROLL:
647         if( (HWND)lp == hwndSlider ) OnSliderUpdate( wp );
648         break;
649
650     case WM_VSCROLL:
651         if( (HWND)lp == hwndVol ) OnChange( wp );
652         break;
653
654     case WM_INITMENUPOPUP:
655         RefreshSettingsMenu( p_intf,
656             (HMENU)SendMessage( hwndCB, SHCMBM_GETSUBMENU, (WPARAM)0,
657                                 (LPARAM)IDM_SETTINGS ) );
658         RefreshAudioMenu( p_intf,
659             (HMENU)SendMessage( hwndCB, SHCMBM_GETSUBMENU, (WPARAM)0,
660                                 (LPARAM)IDM_AUDIO ) );
661         RefreshVideoMenu( p_intf,
662             (HMENU)SendMessage( hwndCB, SHCMBM_GETSUBMENU, (WPARAM)0,
663                                 (LPARAM)IDM_VIDEO ) );
664         RefreshNavigMenu( p_intf,
665             (HMENU)SendMessage( hwndCB, SHCMBM_GETSUBMENU, (WPARAM)0,
666                                 (LPARAM)IDM_NAVIGATION ) );
667
668 #if 0
669         // Undo the video display because menu is opened
670         // due to GAPI, menu top display is not assumed
671         // FIXME verify if p_child_window exits
672         SendMessage( p_intf->p_sys->p_video_window->p_child_window,
673                      WM_INITMENUPOPUP, wp, lp );
674 #endif
675
676         //refresh screen
677         /* InvalidateRect(hwnd, NULL, TRUE);
678            /UpdateWindow(hwndCB); //  NULL*/
679         break;
680
681 #if 0
682     case WM_NOTIFY:
683         // Redo the video display because menu can be closed
684         // FIXME verify if p_child_window exits
685         if( (((NMHDR *)lp)->code) == NM_CUSTOMDRAW )
686             SendMessage( p_intf->p_sys->p_video_window->p_child_window,
687                          WM_NOTIFY, wp, lp );
688         return lResult;
689 #endif
690         break;
691
692     case WM_HELP:
693         MessageBox (hwnd, _T("Help"), _T("Help"), MB_OK);
694         break;
695
696     case WM_CLOSE:
697         DestroyWindow( hwndCB );
698         DestroyWindow( hwnd );
699         break;
700
701     case WM_DESTROY:
702         PostQuitMessage( 0 );
703         break;
704     }
705
706     return DefWindowProc( hwnd, msg, wp, lp );
707 }
708
709 void Interface::OnOpenFileSimple( void )
710 {
711     OPENFILENAME ofn;
712     TCHAR DateiName[80+1] = _T("\0");
713     static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
714
715     playlist_t *p_playlist = (playlist_t *)
716         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
717     if( p_playlist == NULL ) return;
718
719     memset( &ofn, 0, sizeof(OPENFILENAME) );
720     ofn.lStructSize = sizeof(OPENFILENAME);
721     ofn.hwndOwner = NULL;
722     ofn.hInstance = hInst;
723     ofn.lpstrFilter = szFilter;
724     ofn.lpstrCustomFilter = NULL;
725     ofn.nMaxCustFilter = 0;
726     ofn.nFilterIndex = 1;     
727     ofn.lpstrFile = (LPTSTR)DateiName; 
728     ofn.nMaxFile = 80;
729     ofn.lpstrFileTitle = NULL; 
730     ofn.nMaxFileTitle = 40;
731     ofn.lpstrInitialDir = NULL;
732     ofn.lpstrTitle = _T("Quick Open File");
733     ofn.Flags = 0; 
734     ofn.nFileOffset = 0;
735     ofn.nFileExtension = 0;
736     ofn.lpstrDefExt = NULL;
737     ofn.lCustData = 0L;
738     ofn.lpfnHook = NULL;
739     ofn.lpTemplateName = NULL;
740
741     SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
742
743     if( GetOpenFile( &ofn ) )
744     {
745         char *psz_filename = _TOMB(ofn.lpstrFile);
746         playlist_Add( p_playlist, psz_filename, psz_filename,
747                       PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
748     }
749
750     vlc_object_release( p_playlist );
751 }
752
753 void Interface::OnPlayStream( void )
754 {
755     playlist_t *p_playlist = (playlist_t *)
756         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
757     if( p_playlist == NULL ) return;
758
759     if( p_playlist->i_size && p_playlist->i_enabled )
760     {
761         vlc_value_t state;
762
763         input_thread_t *p_input = (input_thread_t *)
764             vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
765
766         if( p_input == NULL )
767         {
768             /* No stream was playing, start one */
769             playlist_Play( p_playlist );
770             TogglePlayButton( PLAYING_S );
771             vlc_object_release( p_playlist );
772             return;
773         }
774
775         var_Get( p_input, "state", &state );
776
777         if( state.i_int != PAUSE_S )
778         {
779             /* A stream is being played, pause it */
780             state.i_int = PAUSE_S;
781         }
782         else
783         {
784             /* Stream is paused, resume it */
785             state.i_int = PLAYING_S;
786         }
787         var_Set( p_input, "state", state );
788
789         TogglePlayButton( state.i_int );
790         vlc_object_release( p_input );
791         vlc_object_release( p_playlist );
792     }
793     else
794     {
795         /* If the playlist is empty, open a file requester instead */
796         vlc_object_release( p_playlist );
797         OnOpenFileSimple();
798     }
799 }
800
801 void Interface::TogglePlayButton( int i_playing_status )
802 {
803     TBREPLACEBITMAP tbrb;
804     tbrb.hInstOld = tbrb.hInstNew = (HINSTANCE) hInst;
805     tbrb.nButtons = NUMIMAGES;
806
807     if( i_playing_status == i_old_playing_status ) return;
808
809     if( i_playing_status == PLAYING_S )
810     {
811         tbrb.nIDOld = IDB_BITMAP2;
812         tbrb.nIDNew = IDB_BITMAP1;
813
814         SendMessage( hwndTB, TB_REPLACEBITMAP, (WPARAM)0,
815                      (LPARAM)(LPTBREPLACEBITMAP)&tbrb );
816     }
817     else
818     {
819         tbrb.nIDOld = IDB_BITMAP1;
820         tbrb.nIDNew = IDB_BITMAP2;
821
822         SendMessage( hwndTB, TB_REPLACEBITMAP, (WPARAM)0,
823                      (LPARAM)(LPTBREPLACEBITMAP)&tbrb );
824     }
825
826     UpdateWindow( hwndTB );
827
828     i_old_playing_status = i_playing_status;
829 }
830
831 void Interface::OnVideoOnTop( void )
832 {
833     vlc_value_t val;
834
835     vout_thread_t *p_vout = (vout_thread_t *)
836         vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
837
838     if( p_vout == NULL ) return;
839
840     if( var_Get( (vlc_object_t *)p_vout, "video-on-top", &val ) < 0 )
841         return;
842
843     val.b_bool = !val.b_bool;
844     var_Set( (vlc_object_t *)p_vout, "video-on-top", val );
845
846     vlc_object_release( (vlc_object_t *)p_vout );
847 }
848
849 void Interface::OnSliderUpdate( int wp )
850 {
851     vlc_mutex_lock( &p_intf->change_lock );
852     input_thread_t *p_input = p_intf->p_sys->p_input;
853
854     int dwPos = SendMessage( hwndSlider, TBM_GETPOS, 0, 0 ); 
855
856     if( (int)LOWORD(wp) == SB_THUMBPOSITION ||
857         (int)LOWORD(wp) == SB_ENDSCROLL )
858     {
859         if( p_intf->p_sys->i_slider_pos != dwPos && p_input )
860         {
861             vlc_value_t pos;
862             pos.f_float = (float)dwPos / (float)SLIDER_MAX_POS;
863             var_Set( p_input, "position", pos );
864         }
865
866         p_intf->p_sys->b_slider_free = VLC_TRUE;
867     }
868     else
869     {
870         p_intf->p_sys->b_slider_free = VLC_FALSE;
871
872         if( p_input )
873         {
874             /* Update stream date */
875             char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
876             mtime_t i_seconds;
877
878             i_seconds = var_GetTime( p_input, "length" ) / I64C(1000000 );
879             secstotimestr( psz_total, i_seconds );
880
881             i_seconds = var_GetTime( p_input, "time" ) / I64C(1000000 );
882             secstotimestr( psz_time, i_seconds );
883
884             SendMessage( hwndLabel, WM_SETTEXT, (WPARAM)1,
885                          (LPARAM)_FROMMB(psz_time) );
886         }
887     }
888
889     vlc_mutex_unlock( &p_intf->change_lock );
890 }
891
892 void Interface::OnChange( int wp )
893 {
894     DWORD dwPos = SendMessage( hwndVol, TBM_GETPOS, 0, 0 );
895
896     if( LOWORD(wp) == SB_THUMBPOSITION || LOWORD(wp) == SB_ENDSCROLL )
897     {
898         Change( 200 - (int)dwPos );
899     }
900 }
901
902 void Interface::Change( int i_volume )
903 {
904     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
905 #if 0
906     SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
907                 i_volume ) );
908 #endif
909 }
910
911 void Interface::OnStopStream( void )
912 {
913     playlist_t * p_playlist = (playlist_t *)
914         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
915     if( p_playlist == NULL ) return;
916
917     playlist_Stop( p_playlist );
918     TogglePlayButton( PAUSE_S );
919     vlc_object_release( p_playlist );
920 }
921
922 void Interface::OnPrevStream( void )
923 {
924     playlist_t * p_playlist = (playlist_t *)
925         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
926     if( p_playlist == NULL ) return;
927
928     playlist_Prev( p_playlist );
929     vlc_object_release( p_playlist );
930 }
931
932 void Interface::OnNextStream( void )
933 {
934     playlist_t * p_playlist = (playlist_t *)
935         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
936     if( p_playlist == NULL ) return;
937
938     playlist_Next( p_playlist );
939     vlc_object_release( p_playlist );
940 }
941
942 void Interface::OnSlowStream( void )
943 {
944     input_thread_t *p_input = (input_thread_t *)
945         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
946
947     if( p_input == NULL ) return;
948
949     vlc_value_t val; val.b_bool = VLC_TRUE;
950     var_Set( p_input, "rate-slower", val );
951     vlc_object_release( p_input );
952 }
953
954 void Interface::OnFastStream( void )
955 {
956     input_thread_t *p_input = (input_thread_t *)
957         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
958
959     if( p_input == NULL ) return;
960
961     vlc_value_t val; val.b_bool = VLC_TRUE;
962     var_Set( p_input, "rate-faster", val );
963     vlc_object_release( p_input );
964 }