interface.cpp 25.9 KB
Newer Older
1
2
3
/*****************************************************************************
 * interface.cpp: WinCE gui plugin for VLC
 *****************************************************************************
4
 * Copyright (C) 2003 the VideoLAN team
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * $Id$
 *
 * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
 *          Gildas Bazin <gbazin@videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111,
 * USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
29
30
31
32
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

33
#include <vlc/vlc.h>
zorglub's avatar
zorglub committed
34
35
36
#include <vlc_aout.h>
#include <vlc_vout.h>
#include <vlc_interface.h>
37

38
#include "wince.h"
39
40
41

#include <windowsx.h>
#include <commctrl.h>
42
#include <commdlg.h>
43

44
45
46
#define NUMIMAGES     9   // Number of buttons in the toolbar
#define IMAGEWIDTH    17   // Width of the buttons in the toolbar
#define IMAGEHEIGHT   16   // Height of the buttons in the toolbar
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#define BUTTONWIDTH   0    // Width of the button images in the toolbar
#define BUTTONHEIGHT  0    // Height of the button images in the toolbar
#define ID_TOOLBAR    2000 // Identifier of the main tool bar

// Help strings
#define HELP_SIMPLE _T("Quick file open")
#define HELP_ADV    _T("Advanced open")
#define HELP_FILE   _T("Open a file")
#define HELP_DISC   _T("Open Disc Media")
#define HELP_NET    _T("Open a network stream")
#define HELP_SAT    _T("Open a satellite stream")
#define HELP_EJECT  _T("Eject the DVD/CD")
#define HELP_EXIT   _T("Exit this program")

#define HELP_OTHER _T("Open other types of inputs")

#define HELP_PLAYLIST   _T("Open the playlist")
#define HELP_LOGS       _T("Show the program logs")
#define HELP_FILEINFO   _T("Show information about the file being played")

#define HELP_PREFS _T("Go to the preferences menu")

#define HELP_ABOUT _T("About this program")

#define HELP_STOP _T("Stop")

#define HELP_PLAY _T("Play")
#define HELP_PAUSE _T("Pause")
#define HELP_PLO _T("Playlist")
#define HELP_PLP _T("Previous playlist item")
#define HELP_PLN _T("Next playlist item")
#define HELP_SLOW _T("Play slower")
#define HELP_FAST _T("Play faster")

// The TBBUTTON structure contains information the toolbar buttons.
82
static TBBUTTON tbButton[] =
83
{
84
85
86
87
88
89
90
91
92
93
94
95
96
  {0, ID_FILE_QUICKOPEN,        TBSTATE_ENABLED, TBSTYLE_BUTTON},
  {1, ID_FILE_OPENNET,       TBSTATE_ENABLED, TBSTYLE_BUTTON},
  {0, 0,              TBSTATE_ENABLED, TBSTYLE_SEP},
  {2, StopStream_Event,       TBSTATE_ENABLED, TBSTYLE_BUTTON},
  {3, PlayStream_Event,        TBSTATE_ENABLED, TBSTYLE_BUTTON},
  {0, 0,              TBSTATE_ENABLED, TBSTYLE_SEP},
  {4, ID_VIEW_PLAYLIST,       TBSTATE_ENABLED, TBSTYLE_BUTTON},
  {0, 0,              TBSTATE_ENABLED, TBSTYLE_SEP},
  {5, PrevStream_Event,      TBSTATE_ENABLED, TBSTYLE_BUTTON},
  {6, NextStream_Event,      TBSTATE_ENABLED, TBSTYLE_BUTTON},
  {0, 0,              TBSTATE_ENABLED, TBSTYLE_SEP},
  {7, SlowStream_Event,      TBSTATE_ENABLED, TBSTYLE_BUTTON},
  {8, FastStream_Event,       TBSTATE_ENABLED, TBSTYLE_BUTTON},
97
98
99
};

// Toolbar ToolTips
100
TCHAR * szToolTips[] =
101
102
103
104
105
106
107
108
{
    HELP_SIMPLE, HELP_NET, HELP_STOP, HELP_PLAY, HELP_PLO, HELP_PLP,
    HELP_PLN, HELP_SLOW, HELP_FAST
};

/*****************************************************************************
 * Constructor.
 *****************************************************************************/
gbazin's avatar
gbazin committed
109
110
111
112
Interface::Interface( intf_thread_t *p_intf, CBaseWindow *p_parent,
                      HINSTANCE h_inst )
  : CBaseWindow( p_intf, p_parent, h_inst ),
    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
118
{
}

Interface::~Interface()
{
ivoire's avatar
ivoire committed
119
120
    delete timer;
    delete video;
121
122
}

gbazin's avatar
gbazin committed
123
BOOL Interface::InitInstance()
124
125
126
127
{
    /* Initializations */
    i_old_playing_status = PAUSE_S;

128
129
130
131
    int i_style = WS_VISIBLE;

#ifndef UNDER_CE
    i_style |= WS_OVERLAPPEDWINDOW | WS_SIZEBOX;
132
133
#endif

134
135
    // Create main window
    hwndMain =
136
        CreateWindow( _T("VLC WinCE"), _T("VLC media player"), i_style,
137
                      0, MENU_HEIGHT, CW_USEDEFAULT, CW_USEDEFAULT,
gbazin's avatar
gbazin committed
138
                      NULL, NULL, GetInstance(), (void *)this );
139
140
141
142
143
144
145
146
147
148

    if( !hwndMain ) return FALSE;

    ShowWindow( hwndMain, TRUE );
    UpdateWindow( hwndMain );

    return TRUE;
}

/***********************************************************************
149
FUNCTION:
150
  CreateMenuBar
151

152
PURPOSE:
153
154
  Creates a menu bar.
***********************************************************************/
155
HWND Interface::CreateMenuBar( HWND hwnd, HINSTANCE hInst )
156
{
157
158
    HMENU menu_file, menu_view;

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#ifdef UNDER_CE
    SHMENUBARINFO mbi;
    memset( &mbi, 0, sizeof(SHMENUBARINFO) );
    mbi.cbSize     = sizeof(SHMENUBARINFO);
    mbi.hwndParent = hwnd;
    mbi.hInstRes   = hInst;
    mbi.nToolBarId = IDR_MENUBAR;

    if( !SHCreateMenuBar( &mbi ) )
    {
        MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
        return 0;
    }

    TBBUTTONINFO tbbi;
    tbbi.cbSize = sizeof(tbbi);
    tbbi.dwMask = TBIF_LPARAM;

    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
185
186
187
188
189
190
    menu_settings = (HMENU)tbbi.lParam;
    SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_VIDEO, (LPARAM)&tbbi );
    menu_video = (HMENU)tbbi.lParam;
    SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_AUDIO, (LPARAM)&tbbi );
    menu_audio = (HMENU)tbbi.lParam;
    SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_NAVIGATION, (LPARAM)&tbbi );
    menu_navigation = (HMENU)tbbi.lParam;
191
192

#else
193
194
195
196
197
198
    menu_file = CreatePopupMenu();
    menu_view = CreatePopupMenu();
    menu_settings = CreatePopupMenu();
    menu_audio = CreatePopupMenu();
    menu_video = CreatePopupMenu();
    menu_navigation = CreatePopupMenu();
199
200
#endif

201
    AppendMenu( menu_file, MF_STRING, ID_FILE_QUICKOPEN,
202
                _T("Quick &Open File...") );
203
204
    AppendMenu( menu_file, MF_SEPARATOR, 0, 0 );
    AppendMenu( menu_file, MF_STRING, ID_FILE_OPENFILE,
205
                _T("Open &File...") );
206
207
    AppendMenu( menu_file, MF_STRING, ID_FILE_OPENDIR,
                _T("Open &Directory...") );
208
    AppendMenu( menu_file, MF_STRING, ID_FILE_OPENNET,
209
                _T("Open &Network Stream...") );
210
211
    AppendMenu( menu_file, MF_SEPARATOR, 0, 0 );
    AppendMenu( menu_file, MF_STRING, ID_FILE_ABOUT,
212
                _T("About VLC") );
213
    AppendMenu( menu_file, MF_STRING, ID_FILE_EXIT,
214
215
                _T("E&xit") );

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
225
226
227
228
229
230
231
232
                _T("&Preferences...") );


#ifdef UNDER_CE
    return mbi.hwndMB;

#else
    HMENU hmenu = CreateMenu();

233
234
235
    AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_file, _T("File") );
    AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_view, _T("View") );
    AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_settings,
236
                _T("Settings") );
237
238
239
    AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_audio, _T("Audio") );
    AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_video, _T("Video") );
    AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_navigation, _T("Nav") );
240
241

    SetMenu( hwnd, hmenu );
242
    return 0;
243
244
245
246
247

#endif
}

/***********************************************************************
248
FUNCTION:
249
  CreateToolBar
250

251
PURPOSE:
252
253
  Registers the TOOLBAR control class and creates a toolbar.
***********************************************************************/
254
HWND CreateToolBar( HWND hwnd, HINSTANCE hInst )
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
{
    DWORD dwStyle;
    HWND hwndTB;
    RECT rect, rectTB;

    INITCOMMONCONTROLSEX iccex;
    iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    iccex.dwICC = ICC_BAR_CLASSES;

    // Registers TOOLBAR control classes from the common control dll
    InitCommonControlsEx (&iccex);

    //  Create the toolbar control
    dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS |
        WS_EX_OVERLAPPEDWINDOW | CCS_NOPARENTALIGN;

271
    hwndTB = CreateToolbarEx( hwnd, dwStyle, 0, NUMIMAGES,
272
273
274
275
        hInst, IDB_BITMAP1, tbButton, sizeof(tbButton) / sizeof(TBBUTTON),
        BUTTONWIDTH, BUTTONHEIGHT, IMAGEWIDTH, IMAGEHEIGHT, sizeof(TBBUTTON) );

    if( !hwndTB ) return NULL;
276
 
277
    // Add ToolTips to the toolbar.
278
    SendMessage( hwndTB, TB_SETTOOLTIPS, (WPARAM)NUMIMAGES,
279
280
281
282
283
                 (LPARAM)szToolTips );

    // Reposition the toolbar.
    GetClientRect( hwnd, &rect );
    GetWindowRect( hwndTB, &rectTB );
284
    MoveWindow( hwndTB, rect.left, rect.bottom - rect.top - 2*MENU_HEIGHT,
285
286
287
288
289
290
291
                rect.right - rect.left, MENU_HEIGHT, TRUE );

    return hwndTB;
}

/***********************************************************************

292
FUNCTION:
293
  CreateSliderBar
294

295
PURPOSE:
296
297
298
  Registers the TRACKBAR_CLASS control class and creates a trackbar.

***********************************************************************/
299
HWND CreateSliderBar( HWND hwnd, HINSTANCE hInst )
300
301
302
303
304
305
306
307
308
309
310
{
    HWND hwndSlider;
    RECT rect;

    INITCOMMONCONTROLSEX iccex;
    iccex.dwSize = sizeof( INITCOMMONCONTROLSEX );
    iccex.dwICC = ICC_BAR_CLASSES;

    // Registers TRACKBAR_CLASS control classes from the common control dll
    InitCommonControlsEx( &iccex );

311
    hwndSlider = CreateWindowEx( 0, TRACKBAR_CLASS, NULL,
312
313
314
315
316
317
318
319
320
321
322
323
                WS_CHILD | WS_VISIBLE | TBS_HORZ | WS_EX_OVERLAPPEDWINDOW |
                TBS_BOTTOM,  //|WS_CLIPSIBLINGS,
                0, 0, 0, 0, hwnd, NULL, hInst, NULL );

    if( !hwndSlider ) return NULL;

    SendMessage( hwndSlider, TBM_SETRANGEMIN, 1, 0 );
    SendMessage( hwndSlider, TBM_SETRANGEMAX, 1, SLIDER_MAX_POS );
    SendMessage( hwndSlider, TBM_SETPOS, 1, 0 );

    // Reposition the trackbar
    GetClientRect( hwnd, &rect );
324
325
    MoveWindow( hwndSlider, rect.left,
                rect.bottom - rect.top - 2*(MENU_HEIGHT-1) - SLIDER_HEIGHT,
326
327
328
329
330
331
332
                rect.right - rect.left - 40, 30, TRUE );

    ShowWindow( hwndSlider, SW_HIDE );

    return hwndSlider;
}

333
HWND CreateStaticText( HWND hwnd, HINSTANCE hInst )
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
{
    HWND hwndLabel;
    RECT rect;

    hwndLabel = CreateWindowEx( 0, _T("STATIC"), _T("label"),
                                WS_CHILD | WS_VISIBLE | SS_CENTER ,
                                0, 0, 0, 0, hwnd, (HMENU)1980, hInst, NULL );

    // Reposition the trackbar
    GetClientRect( hwnd, &rect );

    MoveWindow( hwndLabel, rect.left,
                rect.bottom - rect.top - 2*(MENU_HEIGHT-1) - SLIDER_HEIGHT +30,
                rect.right - rect.left - 40,
                SLIDER_HEIGHT - 30, TRUE );

    ShowWindow( hwndLabel, SW_HIDE );

    return hwndLabel;
}

/***********************************************************************

357
FUNCTION:
358
  CreateVolTrackBar
359

360
PURPOSE:
361
362
363
  Registers the TRACKBAR_CLASS control class and creates a trackbar.

***********************************************************************/
364
HWND CreateVolTrackBar( HWND hwnd, HINSTANCE hInst )
365
366
367
368
369
370
371
372
373
374
375
{
    HWND hwndVol;
    RECT rect;

    INITCOMMONCONTROLSEX iccex;
    iccex.dwSize = sizeof( INITCOMMONCONTROLSEX );
    iccex.dwICC = ICC_BAR_CLASSES;

    // Registers TRACKBAR_CLASS control classes from the common control dll
    InitCommonControlsEx( &iccex );

376
    hwndVol = CreateWindowEx( 0, TRACKBAR_CLASS, NULL,
377
378
379
380
381
382
383
384
385
                WS_CHILD | WS_VISIBLE | TBS_VERT | TBS_RIGHT | TBS_AUTOTICKS |
                WS_EX_OVERLAPPEDWINDOW, //|WS_CLIPSIBLINGS,
                0, 0, 0, 0, hwnd, NULL, hInst, NULL );

    if( !hwndVol ) return NULL;

    SendMessage( hwndVol, TBM_SETRANGEMIN, 1, 0 );
    SendMessage( hwndVol, TBM_SETRANGEMAX, 1, 200 );
    SendMessage( hwndVol, TBM_SETPOS, 1, 100 );
386
    SendMessage( hwndVol, TBM_SETTICFREQ, 50, 0 );
387
388
389

    // Reposition the trackbar
    GetClientRect( hwnd, &rect );
390
391
    MoveWindow( hwndVol, rect.right - rect.left - 40,
                rect.bottom - rect.top - 2*(MENU_HEIGHT-1) - SLIDER_HEIGHT,
392
393
394
395
396
397
398
399
400
                40, SLIDER_HEIGHT, TRUE );

    ShowWindow( hwndVol, SW_HIDE );

    return hwndVol;
}

/***********************************************************************

401
FUNCTION:
402
  CreateStatusBar
403

404
PURPOSE:
405
406
407
  Registers the StatusBar control class and creates a Statusbar.

***********************************************************************/
408
HWND CreateStatusBar( HWND hwnd, HINSTANCE hInst )
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
{
    DWORD dwStyle;
    HWND hwndSB;
    RECT rect;

    INITCOMMONCONTROLSEX iccex;
    iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
    iccex.dwICC = ICC_BAR_CLASSES;

    // Registers Statusbar control classes from the common control dll
    InitCommonControlsEx( &iccex );

    // Create the statusbar control
    dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS | CCS_NOPARENTALIGN;

424
    hwndSB = CreateWindowEx( 0, STATUSCLASSNAME, NULL,
425
426
427
428
429
430
                             WS_CHILD | WS_VISIBLE | TBS_VERT | TBS_BOTTOM |
                             TBS_RIGHT  |WS_CLIPSIBLINGS,
                             0, 0, CW_USEDEFAULT, 50, hwnd, NULL, hInst, 0 );

    if (!hwndSB ) return NULL;

431
    // Get the coordinates of the parent window's client area.
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
    GetClientRect( hwnd, &rect );

    // allocate memory for the panes of status bar
    int nopanes = 2;
    int *indicators = new int[nopanes];

    // set width for the panes
    indicators[0] = 3 * ( rect.right - rect.left ) / 4;
    indicators[1] = rect.right - rect.left;

    // call functions to set style
    SendMessage( hwndSB, SB_SETPARTS, (WPARAM)nopanes, (LPARAM)indicators );

    return hwndSB;
}

/***********************************************************************
449
FUNCTION:
450
451
  WndProc

452
PURPOSE:
453
454
  Processes messages sent to the main window.
***********************************************************************/
455
LRESULT Interface::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
456
457
458
459
{
    switch( msg )
    {
    case WM_CREATE:
460
461
462
463
464
465
466
467
        hwndCB = CreateMenuBar( hwnd, hInst );
        hwndTB = CreateToolBar( hwnd, hInst );
        hwndSlider = CreateSliderBar( hwnd, hInst );
        hwndLabel = CreateStaticText( hwnd, hInst );
        hwndVol = CreateVolTrackBar( hwnd, hInst );
#ifdef UNDER_CE
        hwndSB = CreateStatusBar( hwnd, hInst );
#endif
468
469

        /* Video window */
470
471
        if( config_GetInt( p_intf, "wince-embed" ) )
            video = CreateVideoWindow( p_intf, hwnd );
472

473
        timer = new Timer( p_intf, hwnd, this );
474
        break;
475
476
477
478

    case WM_COMMAND:
        switch( GET_WM_COMMAND_ID(wp,lp) )
        {
479
480
        case ID_FILE_QUICKOPEN:
        case ID_FILE_OPENFILE:
481
        case ID_FILE_OPENDIR:
482
        case ID_FILE_OPENNET:
483
484
485
486
487
        case ID_VIEW_STREAMINFO:
        case ID_VIEW_MESSAGES:
        case ID_VIEW_PLAYLIST:
        case ID_PREFERENCES:
            OnShowDialog( GET_WM_COMMAND_ID(wp,lp) );
488
            break;
489

490
491
492
493
494
495
        case PlayStream_Event: OnPlayStream(); break;
        case StopStream_Event: OnStopStream(); break;
        case PrevStream_Event: OnPrevStream(); break;
        case NextStream_Event: OnNextStream(); break;
        case SlowStream_Event: OnSlowStream(); break;
        case FastStream_Event: OnFastStream(); break;
496

497
        case ID_FILE_ABOUT:
498
499
500
        {
            string about = (string)"VLC media player " PACKAGE_VERSION +
                _("\n(WinCE interface)\n\n") +
501
                _("(c) 1996-2006 - the VideoLAN Team\n\n") +
502
503
504
                _("Compiled by ") + VLC_CompileBy() + "@" +
                VLC_CompileHost() + "." + VLC_CompileDomain() + ".\n" +
                _("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
510

            MessageBox( hwnd, _FROMMB(about.c_str()),
                        _T("About VLC media player"), MB_OK );
511
            break;
512
513
514
515
        }

        case ID_FILE_EXIT:
            SendMessage( hwnd, WM_CLOSE, 0, 0 );
516
            break;
517
518

        default:
519
            OnMenuEvent( p_intf, GET_WM_COMMAND_ID(wp,lp) );
520
521
522
            // we should test if it is a menu command
        }
        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
534
        }
        if( (HWND)lp == hwndLabel )
        {
535
536
            SetBkColor( (HDC)wp, RGB (192, 192, 192) );
            return( (LRESULT)::GetSysColorBrush(COLOR_3DFACE) );
537
538
539
540
        }
        break;

    case WM_HSCROLL:
541
        if( (HWND)lp == hwndSlider ) OnSliderUpdate( wp );
542
543
544
        break;

    case WM_VSCROLL:
545
        if( (HWND)lp == hwndVol ) OnChange( wp );
546
547
548
        break;

    case WM_INITMENUPOPUP:
549
550
551
552
553
554
555
556
        if( (HMENU)wp == menu_settings )
            RefreshSettingsMenu( p_intf, menu_settings );
        if( (HMENU)wp == menu_audio )
            RefreshAudioMenu( p_intf, menu_audio );
        if( (HMENU)wp == menu_video )
            RefreshVideoMenu( p_intf, menu_video );
        if( (HMENU)wp == menu_navigation )
            RefreshNavigMenu( p_intf, menu_navigation );
557
558
559
        /* Fall through */

    case WM_KILLFOCUS:
560
561
        SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
    case WM_ENTERMENULOOP:
562
563
564
565
566
        if( video && video->hWnd )
            SendMessage( video->hWnd, WM_KILLFOCUS, 0, 0 );
        break;

    case WM_SETFOCUS:
567
        SHSipPreference( hwnd, SIP_DOWN );
568
569
        SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
    case WM_EXITMENULOOP:
570
571
        if( video && video->hWnd )
            SendMessage( video->hWnd, WM_SETFOCUS, 0, 0 );
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
        break;

    case WM_LBUTTONDOWN:
        {
            SHRGINFO shrg;
            shrg.cbSize = sizeof( shrg );
            shrg.hwndClient = hwnd;
            shrg.ptDown.x = LOWORD(lp);
            shrg.ptDown.y = HIWORD(lp);
            shrg.dwFlags = SHRG_RETURNCMD ;

            if( SHRecognizeGesture( &shrg ) == GN_CONTEXTMENU )
                PopupMenu( p_intf, hwnd, shrg.ptDown );
        }
        break;
587

588
589
590
591
592
593
594
595
596
   case WM_RBUTTONUP:
        {
            POINT point;
            point.x = LOWORD(lp);
            point.y = HIWORD(lp);
            PopupMenu( p_intf, hwnd, point );
        }
        break;

597
598
    case WM_HELP:
        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
612
613
    }

    return DefWindowProc( hwnd, msg, wp, lp );
}

614
void Interface::OnShowDialog( int i_dialog_event )
615
{
616
    int i_id;
617

618
    switch( i_dialog_event )
619
    {
620
621
622
623
624
625
626
627
628
    case ID_FILE_QUICKOPEN: i_id = INTF_DIALOG_FILE_SIMPLE; break;
    case ID_FILE_OPENFILE: i_id = INTF_DIALOG_FILE; break;
    case ID_FILE_OPENDIR: i_id = INTF_DIALOG_DIRECTORY; break;
    case ID_FILE_OPENNET: i_id = INTF_DIALOG_NET; break;
    case ID_VIEW_PLAYLIST: i_id = INTF_DIALOG_PLAYLIST; break;
    case ID_VIEW_MESSAGES: i_id = INTF_DIALOG_MESSAGES; break;
    case ID_VIEW_STREAMINFO: i_id = INTF_DIALOG_FILEINFO; break;
    case ID_PREFERENCES: i_id = INTF_DIALOG_PREFS; break;
    default: i_id = INTF_DIALOG_FILE; break;
629
630
    }

631
632
    if( p_intf->p_sys->pf_show_dialog )
        p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
633
634
}

635
636
637
void Interface::OnPlayStream( void )
{
    playlist_t *p_playlist = (playlist_t *)
638
        vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
639
640
    if( p_playlist == NULL ) return;

641
    if( p_playlist->i_size )
642
643
644
645
    {
        vlc_value_t state;

        input_thread_t *p_input = (input_thread_t *)
646
            vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678

        if( p_input == NULL )
        {
            /* No stream was playing, start one */
            playlist_Play( p_playlist );
            TogglePlayButton( PLAYING_S );
            vlc_object_release( p_playlist );
            return;
        }

        var_Get( p_input, "state", &state );

        if( state.i_int != PAUSE_S )
        {
            /* A stream is being played, pause it */
            state.i_int = PAUSE_S;
        }
        else
        {
            /* Stream is paused, resume it */
            state.i_int = PLAYING_S;
        }
        var_Set( p_input, "state", state );

        TogglePlayButton( state.i_int );
        vlc_object_release( p_input );
        vlc_object_release( p_playlist );
    }
    else
    {
        /* If the playlist is empty, open a file requester instead */
        vlc_object_release( p_playlist );
679
        OnShowDialog( ID_FILE_QUICKOPEN );
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
    }
}

void Interface::TogglePlayButton( int i_playing_status )
{
    TBREPLACEBITMAP tbrb;
    tbrb.hInstOld = tbrb.hInstNew = (HINSTANCE) hInst;
    tbrb.nButtons = NUMIMAGES;

    if( i_playing_status == i_old_playing_status ) return;

    if( i_playing_status == PLAYING_S )
    {
        tbrb.nIDOld = IDB_BITMAP2;
        tbrb.nIDNew = IDB_BITMAP1;

        SendMessage( hwndTB, TB_REPLACEBITMAP, (WPARAM)0,
                     (LPARAM)(LPTBREPLACEBITMAP)&tbrb );
    }
    else
    {
        tbrb.nIDOld = IDB_BITMAP1;
        tbrb.nIDNew = IDB_BITMAP2;

        SendMessage( hwndTB, TB_REPLACEBITMAP, (WPARAM)0,
                     (LPARAM)(LPTBREPLACEBITMAP)&tbrb );
    }

    UpdateWindow( hwndTB );

    i_old_playing_status = i_playing_status;
}

void Interface::OnVideoOnTop( void )
{
    vlc_value_t val;

    vout_thread_t *p_vout = (vout_thread_t *)
718
        vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
719
720
721
722
723
724
725
726
727
728
729
730
731
732

    if( p_vout == NULL ) return;

    if( var_Get( (vlc_object_t *)p_vout, "video-on-top", &val ) < 0 )
        return;

    val.b_bool = !val.b_bool;
    var_Set( (vlc_object_t *)p_vout, "video-on-top", val );

    vlc_object_release( (vlc_object_t *)p_vout );
}

void Interface::OnSliderUpdate( int wp )
{
733
734
    vlc_mutex_lock( &p_intf->change_lock );
    input_thread_t *p_input = p_intf->p_sys->p_input;
735

736
    int dwPos = SendMessage( hwndSlider, TBM_GETPOS, 0, 0 );
737
738
739
740

    if( (int)LOWORD(wp) == SB_THUMBPOSITION ||
        (int)LOWORD(wp) == SB_ENDSCROLL )
    {
741
        if( p_intf->p_sys->i_slider_pos != dwPos && p_input )
742
743
744
745
746
747
        {
            vlc_value_t pos;
            pos.f_float = (float)dwPos / (float)SLIDER_MAX_POS;
            var_Set( p_input, "position", pos );
        }

748
        p_intf->p_sys->b_slider_free = true;
749
750
751
    }
    else
    {
752
        p_intf->p_sys->b_slider_free = false;
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770

        if( p_input )
        {
            /* Update stream date */
            char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
            mtime_t i_seconds;

            i_seconds = var_GetTime( p_input, "length" ) / I64C(1000000 );
            secstotimestr( psz_total, i_seconds );

            i_seconds = var_GetTime( p_input, "time" ) / I64C(1000000 );
            secstotimestr( psz_time, i_seconds );

            SendMessage( hwndLabel, WM_SETTEXT, (WPARAM)1,
                         (LPARAM)_FROMMB(psz_time) );
        }
    }

771
    vlc_mutex_unlock( &p_intf->change_lock );
772
773
774
775
776
777
778
779
}

void Interface::OnChange( int wp )
{
    DWORD dwPos = SendMessage( hwndVol, TBM_GETPOS, 0, 0 );

    if( LOWORD(wp) == SB_THUMBPOSITION || LOWORD(wp) == SB_ENDSCROLL )
    {
780
        VolumeChange( 200 - (int)dwPos );
781
        b_volume_hold = false;
782
783
784
    }
    else
    {
785
        b_volume_hold = 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
795
796
797
798
799
800
801
802
803
804
805
806
807
}

void Interface::VolumeUpdate()
{
    audio_volume_t i_volume;

    if( b_volume_hold ) return;

    aout_VolumeGet( p_intf, &i_volume );

    int i_volume_ctrl = 200 - i_volume * 200 * 2 / AOUT_VOLUME_MAX;

    DWORD dwPos = SendMessage( hwndVol, TBM_GETPOS, 0, 0 );
    if( i_volume_ctrl == (int)dwPos ) return;

    SendMessage( hwndVol, TBM_SETPOS, 1, i_volume_ctrl );
808
809
810
811
812
}

void Interface::OnStopStream( void )
{
    playlist_t * p_playlist = (playlist_t *)
813
        vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
814
815
816
817
818
819
820
821
822
823
    if( p_playlist == NULL ) return;

    playlist_Stop( p_playlist );
    TogglePlayButton( PAUSE_S );
    vlc_object_release( p_playlist );
}

void Interface::OnPrevStream( void )
{
    playlist_t * p_playlist = (playlist_t *)
824
        vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
825
826
827
828
829
830
831
832
833
    if( p_playlist == NULL ) return;

    playlist_Prev( p_playlist );
    vlc_object_release( p_playlist );
}

void Interface::OnNextStream( void )
{
    playlist_t * p_playlist = (playlist_t *)
834
        vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
835
836
837
838
839
840
841
842
843
    if( p_playlist == NULL ) return;

    playlist_Next( p_playlist );
    vlc_object_release( p_playlist );
}

void Interface::OnSlowStream( void )
{
    input_thread_t *p_input = (input_thread_t *)
844
        vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
845
846
847

    if( p_input == NULL ) return;

848
    vlc_value_t val; val.b_bool = true;
849
850
851
852
853
854
855
    var_Set( p_input, "rate-slower", val );
    vlc_object_release( p_input );
}

void Interface::OnFastStream( void )
{
    input_thread_t *p_input = (input_thread_t *)
856
        vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
857
858
859

    if( p_input == NULL ) return;

860
    vlc_value_t val; val.b_bool = true;
861
862
863
    var_Set( p_input, "rate-faster", val );
    vlc_object_release( p_input );
}
864
865
866
867
868
869

void Interface::Update()
{
    /* Misc updates */
    VolumeUpdate();
}