WinCE intf: remove VLC_Changeset
[vlc/solaris.git] / modules / gui / wince / interface.cpp
blobb97e766b1679ad9799a21246b86f0e5e6dff2158
1 /*****************************************************************************
2 * interface.cpp: WinCE gui plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
5 * $Id$
7 * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8 * Gildas Bazin <gbazin@videolan.org>
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.
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.
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 *****************************************************************************/
26 /*****************************************************************************
27 * Preamble
28 *****************************************************************************/
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
33 #define __STDC_CONSTANT_MACROS 1
34 #include <inttypes.h>
36 #include <vlc_common.h>
37 #include <vlc_aout.h>
38 #include <vlc_vout.h>
39 #include <vlc_interface.h>
40 #include <vlc_input.h>
41 #include <vlc_playlist.h>
43 #include "wince.h"
44 #define INT64_C(val) val##LL
46 #include <windowsx.h>
47 #include <commctrl.h>
48 #include <commdlg.h>
50 #define NUMIMAGES 9 // Number of buttons in the toolbar
51 #define IMAGEWIDTH 17 // Width of the buttons in the toolbar
52 #define IMAGEHEIGHT 16 // Height of the buttons in the toolbar
53 #define BUTTONWIDTH 0 // Width of the button images in the toolbar
54 #define BUTTONHEIGHT 0 // Height of the button images in the toolbar
55 #define ID_TOOLBAR 2000 // Identifier of the main tool bar
57 // Help strings
58 #define HELP_SIMPLE _T("Quick file open")
59 #define HELP_ADV _T("Advanced open")
60 #define HELP_FILE _T("Open a file")
61 #define HELP_DISC _T("Open Disc Media")
62 #define HELP_NET _T("Open a network stream")
63 #define HELP_SAT _T("Open a satellite stream")
64 #define HELP_EJECT _T("Eject the DVD/CD")
65 #define HELP_EXIT _T("Exit this program")
67 #define HELP_OTHER _T("Open other types of inputs")
69 #define HELP_PLAYLIST _T("Open the playlist")
70 #define HELP_LOGS _T("Show the program logs")
71 #define HELP_FILEINFO _T("Show information about the file being played")
73 #define HELP_PREFS _T("Go to the preferences menu")
75 #define HELP_ABOUT _T("About this program")
77 #define HELP_STOP _T("Stop")
79 #define HELP_PLAY _T("Play")
80 #define HELP_PAUSE _T("Pause")
81 #define HELP_PLO _T("Playlist")
82 #define HELP_PLP _T("Previous playlist item")
83 #define HELP_PLN _T("Next playlist item")
84 #define HELP_SLOW _T("Play slower")
85 #define HELP_FAST _T("Play faster")
87 // The TBBUTTON structure contains information the toolbar buttons.
88 static TBBUTTON tbButton[] =
90 {0, ID_FILE_QUICKOPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON},
91 {1, ID_FILE_OPENNET, TBSTATE_ENABLED, TBSTYLE_BUTTON},
92 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
93 {2, StopStream_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
94 {3, PlayStream_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
95 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
96 {4, ID_VIEW_PLAYLIST, TBSTATE_ENABLED, TBSTYLE_BUTTON},
97 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
98 {5, PrevStream_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
99 {6, NextStream_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
100 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
101 {7, SlowStream_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
102 {8, FastStream_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
105 // Toolbar ToolTips
106 TCHAR * szToolTips[] =
108 HELP_SIMPLE, HELP_NET, HELP_STOP, HELP_PLAY, HELP_PLO, HELP_PLP,
109 HELP_PLN, HELP_SLOW, HELP_FAST
112 /*****************************************************************************
113 * Constructor.
114 *****************************************************************************/
115 Interface::Interface( intf_thread_t *p_intf, CBaseWindow *p_parent,
116 HINSTANCE h_inst )
117 : CBaseWindow( p_intf, p_parent, h_inst ),
118 hwndMain(0), hwndCB(0), hwndTB(0), hwndSlider(0), hwndLabel(0),
119 hwndVol(0), hwndSB(0), timer(0), video(0), b_volume_hold(0)
123 Interface::~Interface()
125 delete timer;
126 delete video;
129 BOOL Interface::InitInstance()
131 /* Initializations */
132 i_old_playing_status = PAUSE_S;
134 int i_style = WS_VISIBLE;
136 #ifndef UNDER_CE
137 i_style |= WS_OVERLAPPEDWINDOW | WS_SIZEBOX;
138 #endif
140 // Create main window
141 hwndMain =
142 CreateWindow( _T("VLC WinCE"), _T("VLC media player"), i_style,
143 0, MENU_HEIGHT, CW_USEDEFAULT, CW_USEDEFAULT,
144 NULL, NULL, GetInstance(), (void *)this );
146 if( !hwndMain ) return FALSE;
148 ShowWindow( hwndMain, TRUE );
149 UpdateWindow( hwndMain );
151 return TRUE;
154 /***********************************************************************
155 FUNCTION:
156 CreateMenuBar
158 PURPOSE:
159 Creates a menu bar.
160 ***********************************************************************/
161 HWND Interface::CreateMenuBar( HWND hwnd, HINSTANCE hInst )
163 HMENU menu_file, menu_view;
165 #ifdef UNDER_CE
166 SHMENUBARINFO mbi;
167 memset( &mbi, 0, sizeof(SHMENUBARINFO) );
168 mbi.cbSize = sizeof(SHMENUBARINFO);
169 mbi.hwndParent = hwnd;
170 mbi.hInstRes = hInst;
171 mbi.nToolBarId = IDR_MENUBAR;
173 if( !SHCreateMenuBar( &mbi ) )
175 MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
176 return 0;
179 TBBUTTONINFO tbbi;
180 tbbi.cbSize = sizeof(tbbi);
181 tbbi.dwMask = TBIF_LPARAM;
183 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_FILE, (LPARAM)&tbbi );
184 menu_file = (HMENU)tbbi.lParam;
185 RemoveMenu( menu_file, 0, MF_BYPOSITION );
186 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_VIEW, (LPARAM)&tbbi );
187 menu_view = (HMENU)tbbi.lParam;
188 RemoveMenu( menu_view, 0, MF_BYPOSITION );
189 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_SETTINGS, (LPARAM)&tbbi );
190 menu_settings = (HMENU)tbbi.lParam;
191 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_VIDEO, (LPARAM)&tbbi );
192 menu_video = (HMENU)tbbi.lParam;
193 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_AUDIO, (LPARAM)&tbbi );
194 menu_audio = (HMENU)tbbi.lParam;
195 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_NAVIGATION, (LPARAM)&tbbi );
196 menu_navigation = (HMENU)tbbi.lParam;
198 #else
199 menu_file = CreatePopupMenu();
200 menu_view = CreatePopupMenu();
201 menu_settings = CreatePopupMenu();
202 menu_audio = CreatePopupMenu();
203 menu_video = CreatePopupMenu();
204 menu_navigation = CreatePopupMenu();
205 #endif
207 AppendMenu( menu_file, MF_STRING, ID_FILE_QUICKOPEN,
208 _T("Quick &Open File...") );
209 AppendMenu( menu_file, MF_SEPARATOR, 0, 0 );
210 AppendMenu( menu_file, MF_STRING, ID_FILE_OPENFILE,
211 _T("Open &File...") );
212 AppendMenu( menu_file, MF_STRING, ID_FILE_OPENDIR,
213 _T("Open &Directory...") );
214 AppendMenu( menu_file, MF_STRING, ID_FILE_OPENNET,
215 _T("Open &Network Stream...") );
216 AppendMenu( menu_file, MF_SEPARATOR, 0, 0 );
217 AppendMenu( menu_file, MF_STRING, ID_FILE_ABOUT,
218 _T("About VLC") );
219 AppendMenu( menu_file, MF_STRING, ID_FILE_EXIT,
220 _T("E&xit") );
222 AppendMenu( menu_view, MF_STRING, ID_VIEW_PLAYLIST,
223 _T("&Playlist...") );
224 AppendMenu( menu_view, MF_STRING, ID_VIEW_MESSAGES,
225 _T("&Messages...") );
226 AppendMenu( menu_view, MF_STRING, ID_VIEW_STREAMINFO,
227 _T("Stream and Media &info...") );
229 AppendMenu( menu_settings, MF_STRING, ID_PREFERENCES,
230 _T("&Preferences...") );
233 #ifdef UNDER_CE
234 return mbi.hwndMB;
236 #else
237 HMENU hmenu = CreateMenu();
239 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_file, _T("File") );
240 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_view, _T("View") );
241 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_settings,
242 _T("Settings") );
243 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_audio, _T("Audio") );
244 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_video, _T("Video") );
245 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)menu_navigation, _T("Nav") );
247 SetMenu( hwnd, hmenu );
248 return 0;
250 #endif
253 /***********************************************************************
254 FUNCTION:
255 CreateToolBar
257 PURPOSE:
258 Registers the TOOLBAR control class and creates a toolbar.
259 ***********************************************************************/
260 HWND CreateToolBar( HWND hwnd, HINSTANCE hInst )
262 DWORD dwStyle;
263 HWND hwndTB;
264 RECT rect, rectTB;
266 INITCOMMONCONTROLSEX iccex;
267 iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
268 iccex.dwICC = ICC_BAR_CLASSES;
270 // Registers TOOLBAR control classes from the common control dll
271 InitCommonControlsEx (&iccex);
273 // Create the toolbar control
274 dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS |
275 WS_EX_OVERLAPPEDWINDOW | CCS_NOPARENTALIGN;
277 hwndTB = CreateToolbarEx( hwnd, dwStyle, 0, NUMIMAGES,
278 hInst, IDB_BITMAP1, tbButton, sizeof(tbButton) / sizeof(TBBUTTON),
279 BUTTONWIDTH, BUTTONHEIGHT, IMAGEWIDTH, IMAGEHEIGHT, sizeof(TBBUTTON) );
281 if( !hwndTB ) return NULL;
283 // Add ToolTips to the toolbar.
284 SendMessage( hwndTB, TB_SETTOOLTIPS, (WPARAM)NUMIMAGES,
285 (LPARAM)szToolTips );
287 // Reposition the toolbar.
288 GetClientRect( hwnd, &rect );
289 GetWindowRect( hwndTB, &rectTB );
290 MoveWindow( hwndTB, rect.left, rect.bottom - rect.top - 2*MENU_HEIGHT,
291 rect.right - rect.left, MENU_HEIGHT, TRUE );
293 return hwndTB;
296 /***********************************************************************
298 FUNCTION:
299 CreateSliderBar
301 PURPOSE:
302 Registers the TRACKBAR_CLASS control class and creates a trackbar.
304 ***********************************************************************/
305 HWND CreateSliderBar( HWND hwnd, HINSTANCE hInst )
307 HWND hwndSlider;
308 RECT rect;
310 INITCOMMONCONTROLSEX iccex;
311 iccex.dwSize = sizeof( INITCOMMONCONTROLSEX );
312 iccex.dwICC = ICC_BAR_CLASSES;
314 // Registers TRACKBAR_CLASS control classes from the common control dll
315 InitCommonControlsEx( &iccex );
317 hwndSlider = CreateWindowEx( 0, TRACKBAR_CLASS, NULL,
318 WS_CHILD | WS_VISIBLE | TBS_HORZ | WS_EX_OVERLAPPEDWINDOW |
319 TBS_BOTTOM, //|WS_CLIPSIBLINGS,
320 0, 0, 0, 0, hwnd, NULL, hInst, NULL );
322 if( !hwndSlider ) return NULL;
324 SendMessage( hwndSlider, TBM_SETRANGEMIN, 1, 0 );
325 SendMessage( hwndSlider, TBM_SETRANGEMAX, 1, SLIDER_MAX_POS );
326 SendMessage( hwndSlider, TBM_SETPOS, 1, 0 );
328 // Reposition the trackbar
329 GetClientRect( hwnd, &rect );
330 MoveWindow( hwndSlider, rect.left,
331 rect.bottom - rect.top - 2*(MENU_HEIGHT-1) - SLIDER_HEIGHT,
332 rect.right - rect.left - 40, 30, TRUE );
334 ShowWindow( hwndSlider, SW_HIDE );
336 return hwndSlider;
339 HWND CreateStaticText( HWND hwnd, HINSTANCE hInst )
341 HWND hwndLabel;
342 RECT rect;
344 hwndLabel = CreateWindowEx( 0, _T("STATIC"), _T("label"),
345 WS_CHILD | WS_VISIBLE | SS_CENTER ,
346 0, 0, 0, 0, hwnd, (HMENU)1980, hInst, NULL );
348 // Reposition the trackbar
349 GetClientRect( hwnd, &rect );
351 MoveWindow( hwndLabel, rect.left,
352 rect.bottom - rect.top - 2*(MENU_HEIGHT-1) - SLIDER_HEIGHT +30,
353 rect.right - rect.left - 40,
354 SLIDER_HEIGHT - 30, TRUE );
356 ShowWindow( hwndLabel, SW_HIDE );
358 return hwndLabel;
361 /***********************************************************************
363 FUNCTION:
364 CreateVolTrackBar
366 PURPOSE:
367 Registers the TRACKBAR_CLASS control class and creates a trackbar.
369 ***********************************************************************/
370 HWND CreateVolTrackBar( HWND hwnd, HINSTANCE hInst )
372 HWND hwndVol;
373 RECT rect;
375 INITCOMMONCONTROLSEX iccex;
376 iccex.dwSize = sizeof( INITCOMMONCONTROLSEX );
377 iccex.dwICC = ICC_BAR_CLASSES;
379 // Registers TRACKBAR_CLASS control classes from the common control dll
380 InitCommonControlsEx( &iccex );
382 hwndVol = CreateWindowEx( 0, TRACKBAR_CLASS, NULL,
383 WS_CHILD | WS_VISIBLE | TBS_VERT | TBS_RIGHT | TBS_AUTOTICKS |
384 WS_EX_OVERLAPPEDWINDOW, //|WS_CLIPSIBLINGS,
385 0, 0, 0, 0, hwnd, NULL, hInst, NULL );
387 if( !hwndVol ) return NULL;
389 SendMessage( hwndVol, TBM_SETRANGEMIN, 1, 0 );
390 SendMessage( hwndVol, TBM_SETRANGEMAX, 1, 200 );
391 SendMessage( hwndVol, TBM_SETPOS, 1, 100 );
392 SendMessage( hwndVol, TBM_SETTICFREQ, 50, 0 );
394 // Reposition the trackbar
395 GetClientRect( hwnd, &rect );
396 MoveWindow( hwndVol, rect.right - rect.left - 40,
397 rect.bottom - rect.top - 2*(MENU_HEIGHT-1) - SLIDER_HEIGHT,
398 40, SLIDER_HEIGHT, TRUE );
400 ShowWindow( hwndVol, SW_HIDE );
402 return hwndVol;
405 /***********************************************************************
407 FUNCTION:
408 CreateStatusBar
410 PURPOSE:
411 Registers the StatusBar control class and creates a Statusbar.
413 ***********************************************************************/
414 HWND CreateStatusBar( HWND hwnd, HINSTANCE hInst )
416 DWORD dwStyle;
417 HWND hwndSB;
418 RECT rect;
420 INITCOMMONCONTROLSEX iccex;
421 iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
422 iccex.dwICC = ICC_BAR_CLASSES;
424 // Registers Statusbar control classes from the common control dll
425 InitCommonControlsEx( &iccex );
427 // Create the statusbar control
428 dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS | CCS_NOPARENTALIGN;
430 hwndSB = CreateWindowEx( 0, STATUSCLASSNAME, NULL,
431 WS_CHILD | WS_VISIBLE | TBS_VERT | TBS_BOTTOM |
432 TBS_RIGHT |WS_CLIPSIBLINGS,
433 0, 0, CW_USEDEFAULT, 50, hwnd, NULL, hInst, 0 );
435 if (!hwndSB ) return NULL;
437 // Get the coordinates of the parent window's client area.
438 GetClientRect( hwnd, &rect );
440 // allocate memory for the panes of status bar
441 int nopanes = 2;
442 int *indicators = new int[nopanes];
444 // set width for the panes
445 indicators[0] = 3 * ( rect.right - rect.left ) / 4;
446 indicators[1] = rect.right - rect.left;
448 // call functions to set style
449 SendMessage( hwndSB, SB_SETPARTS, (WPARAM)nopanes, (LPARAM)indicators );
451 return hwndSB;
454 /***********************************************************************
455 FUNCTION:
456 WndProc
458 PURPOSE:
459 Processes messages sent to the main window.
460 ***********************************************************************/
461 LRESULT Interface::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
463 switch( msg )
465 case WM_CREATE:
466 hwndCB = CreateMenuBar( hwnd, hInst );
467 hwndTB = CreateToolBar( hwnd, hInst );
468 hwndSlider = CreateSliderBar( hwnd, hInst );
469 hwndLabel = CreateStaticText( hwnd, hInst );
470 hwndVol = CreateVolTrackBar( hwnd, hInst );
471 #ifdef UNDER_CE
472 hwndSB = CreateStatusBar( hwnd, hInst );
473 #endif
475 /* Video window */
476 if( config_GetInt( p_intf, "wince-embed" ) )
477 video = CreateVideoWindow( p_intf, hwnd );
479 timer = new Timer( p_intf, hwnd, this );
480 break;
482 case WM_COMMAND:
483 switch( GET_WM_COMMAND_ID(wp,lp) )
485 case ID_FILE_QUICKOPEN:
486 case ID_FILE_OPENFILE:
487 case ID_FILE_OPENDIR:
488 case ID_FILE_OPENNET:
489 case ID_VIEW_STREAMINFO:
490 case ID_VIEW_MESSAGES:
491 case ID_VIEW_PLAYLIST:
492 case ID_PREFERENCES:
493 OnShowDialog( GET_WM_COMMAND_ID(wp,lp) );
494 break;
496 case PlayStream_Event: OnPlayStream(); break;
497 case StopStream_Event: OnStopStream(); break;
498 case PrevStream_Event: OnPrevStream(); break;
499 case NextStream_Event: OnNextStream(); break;
500 case SlowStream_Event: OnSlowStream(); break;
501 case FastStream_Event: OnFastStream(); break;
503 case ID_FILE_ABOUT:
505 string about = (string)"VLC media player " PACKAGE_VERSION +
506 _("\n(WinCE interface)\n\n") +
507 _("(c) 1996-2008 - the VideoLAN Team\n\n") +
508 _("Compiled by ") + VLC_CompileBy() + "@" +
509 VLC_CompileHost() + "." + VLC_CompileDomain() + ".\n" +
510 _("Compiler: ") + VLC_Compiler() + ".\n\n" +
511 _("The VideoLAN team <videolan@videolan.org>\n"
512 "http://www.videolan.org/");
514 MessageBox( hwnd, _FROMMB(about.c_str()),
515 _T("About VLC media player"), MB_OK );
516 break;
519 case ID_FILE_EXIT:
520 SendMessage( hwnd, WM_CLOSE, 0, 0 );
521 break;
523 default:
524 OnMenuEvent( p_intf, GET_WM_COMMAND_ID(wp,lp) );
525 // we should test if it is a menu command
527 break;
529 case WM_TIMER:
530 timer->Notify();
531 break;
533 case WM_CTLCOLORSTATIC:
534 if( ( (HWND)lp == hwndSlider ) || ( (HWND)lp == hwndVol ) )
536 return( (LRESULT)::GetSysColorBrush(COLOR_3DFACE) );
538 if( (HWND)lp == hwndLabel )
540 SetBkColor( (HDC)wp, RGB (192, 192, 192) );
541 return( (LRESULT)::GetSysColorBrush(COLOR_3DFACE) );
543 break;
545 case WM_HSCROLL:
546 if( (HWND)lp == hwndSlider ) OnSliderUpdate( wp );
547 break;
549 case WM_VSCROLL:
550 if( (HWND)lp == hwndVol ) OnChange( wp );
551 break;
553 case WM_INITMENUPOPUP:
554 if( (HMENU)wp == menu_settings )
555 RefreshSettingsMenu( p_intf, menu_settings );
556 if( (HMENU)wp == menu_audio )
557 RefreshAudioMenu( p_intf, menu_audio );
558 if( (HMENU)wp == menu_video )
559 RefreshVideoMenu( p_intf, menu_video );
560 if( (HMENU)wp == menu_navigation )
561 RefreshNavigMenu( p_intf, menu_navigation );
562 /* Fall through */
564 case WM_KILLFOCUS:
565 SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
566 case WM_ENTERMENULOOP:
567 if( video && video->hWnd )
568 SendMessage( video->hWnd, WM_KILLFOCUS, 0, 0 );
569 break;
571 case WM_SETFOCUS:
572 SHSipPreference( hwnd, SIP_DOWN );
573 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
574 case WM_EXITMENULOOP:
575 if( video && video->hWnd )
576 SendMessage( video->hWnd, WM_SETFOCUS, 0, 0 );
577 break;
579 case WM_LBUTTONDOWN:
581 SHRGINFO shrg;
582 shrg.cbSize = sizeof( shrg );
583 shrg.hwndClient = hwnd;
584 shrg.ptDown.x = LOWORD(lp);
585 shrg.ptDown.y = HIWORD(lp);
586 shrg.dwFlags = SHRG_RETURNCMD ;
588 if( SHRecognizeGesture( &shrg ) == GN_CONTEXTMENU )
589 PopupMenu( p_intf, hwnd, shrg.ptDown );
591 break;
593 case WM_RBUTTONUP:
595 POINT point;
596 point.x = LOWORD(lp);
597 point.y = HIWORD(lp);
598 PopupMenu( p_intf, hwnd, point );
600 break;
602 case WM_HELP:
603 MessageBox (hwnd, _T("Help"), _T("Help"), MB_OK);
604 break;
606 case WM_CLOSE:
607 if( hwndCB ) DestroyWindow( hwndCB );
608 DestroyWindow( hwnd );
609 break;
611 case WM_DESTROY:
612 PostQuitMessage( 0 );
613 break;
616 return DefWindowProc( hwnd, msg, wp, lp );
619 void Interface::OnShowDialog( int i_dialog_event )
621 int i_id;
623 switch( i_dialog_event )
625 case ID_FILE_QUICKOPEN: i_id = INTF_DIALOG_FILE_SIMPLE; break;
626 case ID_FILE_OPENFILE: i_id = INTF_DIALOG_FILE; break;
627 case ID_FILE_OPENDIR: i_id = INTF_DIALOG_DIRECTORY; break;
628 case ID_FILE_OPENNET: i_id = INTF_DIALOG_NET; break;
629 case ID_VIEW_PLAYLIST: i_id = INTF_DIALOG_PLAYLIST; break;
630 case ID_VIEW_MESSAGES: i_id = INTF_DIALOG_MESSAGES; break;
631 case ID_VIEW_STREAMINFO: i_id = INTF_DIALOG_FILEINFO; break;
632 case ID_PREFERENCES: i_id = INTF_DIALOG_PREFS; break;
633 default: i_id = INTF_DIALOG_FILE; break;
636 if( p_intf->p_sys->pf_show_dialog )
637 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
640 void Interface::OnPlayStream( void )
642 playlist_t *p_playlist = pl_Hold( p_intf );
643 if( p_playlist == NULL ) return;
645 if( !playlist_IsEmpty(p_playlist) )
647 vlc_value_t state;
649 input_thread_t *p_input = (input_thread_t *)
650 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
652 if( p_input == NULL )
654 /* No stream was playing, start one */
655 playlist_Play( p_playlist );
656 TogglePlayButton( PLAYING_S );
657 pl_Release( p_intf );
658 return;
661 var_Get( p_input, "state", &state );
663 if( state.i_int != PAUSE_S )
665 /* A stream is being played, pause it */
666 state.i_int = PAUSE_S;
668 else
670 /* Stream is paused, resume it */
671 state.i_int = PLAYING_S;
673 var_Set( p_input, "state", state );
675 TogglePlayButton( state.i_int );
676 vlc_object_release( p_input );
678 else
680 /* If the playlist is empty, open a file requester instead */
681 OnShowDialog( ID_FILE_QUICKOPEN );
683 pl_Release( p_intf );
686 void Interface::TogglePlayButton( int i_playing_status )
688 TBREPLACEBITMAP tbrb;
689 tbrb.hInstOld = tbrb.hInstNew = (HINSTANCE) hInst;
690 tbrb.nButtons = NUMIMAGES;
692 if( i_playing_status == i_old_playing_status ) return;
694 if( i_playing_status == PLAYING_S )
696 tbrb.nIDOld = IDB_BITMAP2;
697 tbrb.nIDNew = IDB_BITMAP1;
699 SendMessage( hwndTB, TB_REPLACEBITMAP, (WPARAM)0,
700 (LPARAM)(LPTBREPLACEBITMAP)&tbrb );
702 else
704 tbrb.nIDOld = IDB_BITMAP1;
705 tbrb.nIDNew = IDB_BITMAP2;
707 SendMessage( hwndTB, TB_REPLACEBITMAP, (WPARAM)0,
708 (LPARAM)(LPTBREPLACEBITMAP)&tbrb );
711 UpdateWindow( hwndTB );
713 i_old_playing_status = i_playing_status;
716 void Interface::OnVideoOnTop( void )
718 vlc_value_t val;
720 vout_thread_t *p_vout = (vout_thread_t *)
721 vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
723 if( p_vout == NULL ) return;
725 if( var_Get( (vlc_object_t *)p_vout, "video-on-top", &val ) < 0 )
726 return;
728 val.b_bool = !val.b_bool;
729 var_Set( (vlc_object_t *)p_vout, "video-on-top", val );
731 vlc_object_release( (vlc_object_t *)p_vout );
734 void Interface::OnSliderUpdate( int wp )
736 vlc_mutex_lock( &p_intf->change_lock );
737 input_thread_t *p_input = p_intf->p_sys->p_input;
739 int dwPos = SendMessage( hwndSlider, TBM_GETPOS, 0, 0 );
741 if( (int)LOWORD(wp) == SB_THUMBPOSITION ||
742 (int)LOWORD(wp) == SB_ENDSCROLL )
744 if( p_intf->p_sys->i_slider_pos != dwPos && p_input )
746 vlc_value_t pos;
747 pos.f_float = (float)dwPos / (float)SLIDER_MAX_POS;
748 var_Set( p_input, "position", pos );
751 p_intf->p_sys->b_slider_free = true;
753 else
755 p_intf->p_sys->b_slider_free = false;
757 if( p_input )
759 /* Update stream date */
760 char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
761 mtime_t i_seconds;
763 i_seconds = var_GetTime( p_input, "length" ) / INT64_C(1000000 );
764 secstotimestr( psz_total, i_seconds );
766 i_seconds = var_GetTime( p_input, "time" ) / INT64_C(1000000 );
767 secstotimestr( psz_time, i_seconds );
769 SendMessage( hwndLabel, WM_SETTEXT, (WPARAM)1,
770 (LPARAM)_FROMMB(psz_time) );
774 vlc_mutex_unlock( &p_intf->change_lock );
777 void Interface::OnChange( int wp )
779 DWORD dwPos = SendMessage( hwndVol, TBM_GETPOS, 0, 0 );
781 if( LOWORD(wp) == SB_THUMBPOSITION || LOWORD(wp) == SB_ENDSCROLL )
783 VolumeChange( 200 - (int)dwPos );
784 b_volume_hold = false;
786 else
788 b_volume_hold = true;
792 void Interface::VolumeChange( int i_volume )
794 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
797 void Interface::VolumeUpdate()
799 audio_volume_t i_volume;
801 if( b_volume_hold ) return;
803 aout_VolumeGet( p_intf, &i_volume );
805 int i_volume_ctrl = 200 - i_volume * 200 * 2 / AOUT_VOLUME_MAX;
807 DWORD dwPos = SendMessage( hwndVol, TBM_GETPOS, 0, 0 );
808 if( i_volume_ctrl == (int)dwPos ) return;
810 SendMessage( hwndVol, TBM_SETPOS, 1, i_volume_ctrl );
813 void Interface::OnStopStream( void )
815 playlist_t * p_playlist = pl_Hold( p_intf );
816 if( p_playlist == NULL ) return;
818 playlist_Stop( p_playlist );
819 TogglePlayButton( PAUSE_S );
820 pl_Release( p_intf );
823 void Interface::OnPrevStream( void )
825 playlist_t * p_playlist = pl_Hold( p_intf );
826 if( p_playlist == NULL ) return;
828 playlist_Prev( p_playlist );
829 pl_Release( p_intf );
832 void Interface::OnNextStream( void )
834 playlist_t * p_playlist = pl_Hold( p_intf );
835 if( p_playlist == NULL ) return;
837 playlist_Next( p_playlist );
838 pl_Release( p_intf );
841 void Interface::OnSlowStream( void )
843 input_thread_t *p_input = (input_thread_t *)
844 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
846 if( p_input == NULL ) return;
848 vlc_value_t val; val.b_bool = true;
849 var_Set( p_input, "rate-slower", val );
850 vlc_object_release( p_input );
853 void Interface::OnFastStream( void )
855 input_thread_t *p_input = (input_thread_t *)
856 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
858 if( p_input == NULL ) return;
860 vlc_value_t val; val.b_bool = true;
861 var_Set( p_input, "rate-faster", val );
862 vlc_object_release( p_input );
865 void Interface::Update()
867 /* Misc updates */
868 VolumeUpdate();