1 /*****************************************************************************
\r
2 * intf_win32.cpp: Win32 interface plugin for vlc
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2002 VideoLAN
\r
6 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
\r
8 * This program is free software; you can redistribute it and/or modify
\r
9 * it under the terms of the GNU General Public License as published by
\r
10 * the Free Software Foundation; either version 2 of the License, or
\r
11 * (at your option) any later version.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 * GNU General Public License for more details.
\r
18 * You should have received a copy of the GNU General Public License
\r
19 * along with this program; if not, write to the Free Software
\r
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
\r
21 *****************************************************************************/
\r
23 /*****************************************************************************
\r
25 *****************************************************************************/
\r
27 #include <stdlib.h> /* malloc(), free() */
\r
28 #include <errno.h> /* ENOMEM */
\r
29 #include <string.h> /* strerror() */
\r
31 #include <vlc/vlc.h>
\r
32 #include <vlc/intf.h>
\r
34 #include "mainframe.h"
\r
36 #include "win32_common.h"
\r
38 intf_thread_t *p_intfGlobal;
\r
40 /*****************************************************************************
\r
42 *****************************************************************************/
\r
43 static int intf_Open ( intf_thread_t *p_intf );
\r
44 static void intf_Close ( intf_thread_t *p_intf );
\r
45 static void intf_Run ( intf_thread_t *p_intf );
\r
47 int Win32Manage( void *p_data );
\r
49 /*****************************************************************************
\r
50 * Functions exported as capabilities. They are declared as static so that
\r
51 * we don't pollute the namespace too much.
\r
52 *****************************************************************************/
\r
53 void _M( intf_getfunctions )( function_list_t * p_function_list )
\r
55 p_function_list->functions.intf.pf_open = intf_Open;
\r
56 p_function_list->functions.intf.pf_close = intf_Close;
\r
57 p_function_list->functions.intf.pf_run = intf_Run;
\r
60 /*****************************************************************************
\r
61 * intf_Open: initialize interface
\r
62 *****************************************************************************/
\r
63 static int intf_Open( intf_thread_t *p_intf )
\r
65 /* Allocate instance and initialize some members */
\r
66 p_intf->p_sys = (intf_sys_s *) malloc( sizeof( intf_sys_t ) );
\r
67 if( p_intf->p_sys == NULL )
\r
69 msg_Err( p_intf, "out of memory" );
\r
73 p_intfGlobal = p_intf;
\r
75 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
\r
77 /* Initialize Win32 thread */
\r
78 p_intf->p_sys->b_playing = 0;
\r
79 p_intf->p_sys->b_popup_changed = 0;
\r
81 p_intf->p_sys->p_input = NULL;
\r
82 p_intf->p_sys->i_playing = -1;
\r
83 p_intf->p_sys->b_slider_free = 1;
\r
88 /*****************************************************************************
\r
89 * intf_Close: destroy interface
\r
90 *****************************************************************************/
\r
91 static void intf_Close( intf_thread_t *p_intf )
\r
93 if( p_intf->p_sys->p_input )
\r
95 vlc_object_release( p_intf->p_sys->p_input );
\r
98 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
\r
100 /* Destroy structure */
\r
101 free( p_intf->p_sys );
\r
104 /*****************************************************************************
\r
105 * intf_Run: main loop
\r
106 *****************************************************************************/
\r
107 static void intf_Run( intf_thread_t *p_intf )
\r
109 p_intf->p_sys->p_window = new TMainFrameDlg( NULL );
\r
110 p_intf->p_sys->p_playwin = new TPlaylistDlg( NULL );
\r
111 p_intf->p_sys->p_messages = new TMessagesDlg( NULL );
\r
113 /* show main window and wait until it is closed */
\r
114 p_intf->p_sys->p_window->ShowModal();
\r
116 if( p_intf->p_sys->p_disc ) delete p_intf->p_sys->p_disc;
\r
117 if( p_intf->p_sys->p_network ) delete p_intf->p_sys->p_network;
\r
118 if( p_intf->p_sys->p_preferences ) delete p_intf->p_sys->p_preferences;
\r
119 delete p_intf->p_sys->p_messages;
\r
120 delete p_intf->p_sys->p_playwin;
\r
123 /*****************************************************************************
\r
124 * Win32Manage: manage main thread messages
\r
125 *****************************************************************************
\r
126 * In this function, called approx. 10 times a second, we check what the
\r
127 * main program wanted to tell us.
\r
128 *****************************************************************************/
\r
129 int Win32Manage( intf_thread_t *p_intf )
\r
131 vlc_mutex_lock( &p_intf->change_lock );
\r
133 /* If the "display popup" flag has changed */
\r
134 if( p_intf->b_menu_change )
\r
136 /* FIXME: It would be nice to close the popup when the user left-clicks
\r
137 elsewhere, or to actualize the position when he right-clicks again,
\r
138 but i couldn't find a way to close it :-( */
\r
139 TPoint MousePos = Mouse->CursorPos;
\r
140 p_intf->p_sys->p_window->PopupMenuMain->Popup( MousePos.x, MousePos.y );
\r
141 p_intf->b_menu_change = 0;
\r
144 /* Update the log window */
\r
145 p_intf->p_sys->p_messages->UpdateLog();
\r
147 /* Update the playlist */
\r
148 p_intf->p_sys->p_playwin->Manage( p_intf );
\r
150 /* Update the input */
\r
151 if( p_intf->p_sys->p_input == NULL )
\r
153 p_intf->p_sys->p_input = (input_thread_t *)
\r
154 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
\r
156 else if( p_intf->p_sys->p_input->b_dead )
\r
158 vlc_object_release( p_intf->p_sys->p_input );
\r
159 p_intf->p_sys->p_input = NULL;
\r
162 if( p_intf->p_sys->p_input )
\r
164 input_thread_t *p_input = p_intf->p_sys->p_input;
\r
166 vlc_mutex_lock( &p_input->stream.stream_lock );
\r
168 if( !p_input->b_die )
\r
170 /* New input or stream map change */
\r
171 if( p_input->stream.b_changed )
\r
173 p_intf->p_sys->p_window->ModeManage();
\r
174 SetupMenus( p_intf );
\r
175 p_intf->p_sys->b_playing = 1;
\r
178 /* Manage the slider */
\r
179 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
\r
181 TTrackBar * TrackBar = p_intf->p_sys->p_window->TrackBar;
\r
182 off_t NewValue = TrackBar->Position;
\r
184 #define p_area p_input->stream.p_selected_area
\r
185 /* If the user hasn't touched the slider since the last time,
\r
186 * then the input can safely change it */
\r
187 if( NewValue == p_intf->p_sys->OldValue )
\r
189 /* Update the value */
\r
190 TrackBar->Position = p_intf->p_sys->OldValue =
\r
191 ( (off_t)SLIDER_MAX_VALUE * p_area->i_tell ) /
\r
194 /* Otherwise, send message to the input if the user has
\r
195 * finished dragging the slider */
\r
196 else if( p_intf->p_sys->b_slider_free )
\r
198 off_t i_seek = ( NewValue * p_area->i_size ) /
\r
199 (off_t)SLIDER_MAX_VALUE;
\r
201 /* release the lock to be able to seek */
\r
202 vlc_mutex_unlock( &p_input->stream.stream_lock );
\r
203 input_Seek( p_input, i_seek, INPUT_SEEK_SET );
\r
204 vlc_mutex_lock( &p_input->stream.stream_lock );
\r
206 /* Update the old value */
\r
207 p_intf->p_sys->OldValue = NewValue;
\r
210 /* Update the display */
\r
211 // TrackBar->Invalidate();
\r
216 if( p_intf->p_sys->i_part !=
\r
217 p_input->stream.p_selected_area->i_part )
\r
219 // p_intf->p_sys->b_chapter_update = 1;
\r
220 SetupMenus( p_intf );
\r
224 vlc_mutex_unlock( &p_input->stream.stream_lock );
\r
226 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
\r
228 p_intf->p_sys->p_window->ModeManage();
\r
229 p_intf->p_sys->b_playing = 0;
\r
232 if( p_intf->b_die )
\r
234 vlc_mutex_unlock( &p_intf->change_lock );
\r
236 /* Prepare to die, young Skywalker */
\r
237 p_intf->p_sys->p_window->ModalResult = mrOk;
\r
243 vlc_mutex_unlock( &p_intf->change_lock );
\r