1 /*****************************************************************************
\r
2 * win32.cpp : Win32 interface plugin for vlc
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2002-2003 VideoLAN
\r
5 * $Id: win32.cpp,v 1.18 2003/03/30 18:14:38 gbazin Exp $
\r
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
\r
9 * This program is free software; you can redistribute it and/or modify
\r
10 * it under the terms of the GNU General Public License as published by
\r
11 * the Free Software Foundation; either version 2 of the License, or
\r
12 * (at your option) any later version.
\r
14 * This program is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU General Public License for more details.
\r
19 * You should have received a copy of the GNU General Public License
\r
20 * along with this program; if not, write to the Free Software
\r
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
\r
22 *****************************************************************************/
\r
24 /*****************************************************************************
\r
26 *****************************************************************************/
\r
28 #include <stdlib.h> /* malloc(), free() */
\r
29 #include <errno.h> /* ENOMEM */
\r
32 #include <vlc/vlc.h>
\r
33 #include <vlc/intf.h>
\r
35 #include "mainframe.h"
\r
37 #include "win32_common.h"
\r
39 /*****************************************************************************
\r
40 * Exported interface functions.
\r
41 *****************************************************************************/
\r
42 extern "C" __declspec(dllexport)
\r
43 int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
\r
45 /*****************************************************************************
\r
47 *****************************************************************************/
\r
48 static int Open ( vlc_object_t * );
\r
49 static void Close ( vlc_object_t * );
\r
50 static void Run ( intf_thread_t * );
\r
52 int Win32Manage( void *p_data );
\r
54 /*****************************************************************************
\r
55 * Open: initialize interface
\r
56 *****************************************************************************/
\r
57 static int Open ( vlc_object_t *p_this )
\r
59 intf_thread_t *p_intf = (intf_thread_t *)p_this;
\r
61 /* Allocate instance and initialize some members */
\r
62 p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
\r
63 if( p_intf->p_sys == NULL )
\r
65 msg_Err( p_intf, "out of memory" );
\r
69 p_intf->pf_run = Run;
\r
71 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
\r
73 /* Initialize Win32 thread */
\r
74 p_intf->p_sys->b_playing = 0;
\r
75 p_intf->p_sys->b_popup_changed = 0;
\r
77 p_intf->p_sys->p_input = NULL;
\r
78 p_intf->p_sys->i_playing = -1;
\r
79 p_intf->p_sys->b_play_when_adding = VLC_TRUE;
\r
81 p_intf->p_sys->b_slider_free = 1;
\r
83 p_intf->p_sys->b_aout_update = VLC_FALSE;
\r
84 p_intf->p_sys->b_vout_update = VLC_FALSE;
\r
85 p_intf->p_sys->b_program_update = VLC_FALSE;
\r
86 p_intf->p_sys->b_title_update = VLC_FALSE;
\r
87 p_intf->p_sys->b_chapter_update = VLC_FALSE;
\r
88 p_intf->p_sys->b_audio_update = VLC_FALSE;
\r
89 p_intf->p_sys->b_spu_update = VLC_FALSE;
\r
94 /*****************************************************************************
\r
95 * Close: destroy interface
\r
96 *****************************************************************************/
\r
97 static void Close ( vlc_object_t *p_this )
\r
99 intf_thread_t *p_intf = (intf_thread_t *)p_this;
\r
101 if( p_intf->p_sys->p_input )
\r
103 vlc_object_release( p_intf->p_sys->p_input );
\r
106 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
\r
108 /* Destroy structure */
\r
109 free( p_intf->p_sys );
\r
112 /*****************************************************************************
\r
114 *****************************************************************************/
\r
115 static void Run( intf_thread_t *p_intf )
\r
117 p_intf->p_sys->p_window = new TMainFrameDlg( NULL, p_intf );
\r
118 p_intf->p_sys->p_playwin = new TPlaylistDlg( NULL, p_intf );
\r
119 p_intf->p_sys->p_messages = new TMessagesDlg( NULL, p_intf );
\r
120 p_intf->p_sys->p_menus = new TMenusGen( p_intf );
\r
122 /* show main window and wait until it is closed */
\r
123 p_intf->p_sys->p_window->ShowModal();
\r
125 if( p_intf->p_sys->p_disc ) delete p_intf->p_sys->p_disc;
\r
126 if( p_intf->p_sys->p_network ) delete p_intf->p_sys->p_network;
\r
127 if( p_intf->p_sys->p_preferences ) delete p_intf->p_sys->p_preferences;
\r
128 delete p_intf->p_sys->p_menus;
\r
129 delete p_intf->p_sys->p_messages;
\r
130 delete p_intf->p_sys->p_playwin;
\r
131 delete p_intf->p_sys->p_window;
\r
134 /*****************************************************************************
\r
135 * Win32Manage: manage main thread messages
\r
136 *****************************************************************************
\r
137 * In this function, called approx. 10 times a second, we check what the
\r
138 * main program wanted to tell us.
\r
139 *****************************************************************************/
\r
140 int Win32Manage( intf_thread_t *p_intf )
\r
142 vlc_mutex_lock( &p_intf->change_lock );
\r
144 /* If the "display popup" flag has changed */
\r
145 if( p_intf->b_menu_change )
\r
147 /* FIXME: It would be nice to close the popup when the user left-clicks
\r
148 elsewhere, or to actualize the position when he right-clicks again,
\r
149 but i couldn't find a way to close it :-( */
\r
150 TPoint MousePos = Mouse->CursorPos;
\r
151 p_intf->p_sys->p_window->PopupMenuMain->Popup( MousePos.x, MousePos.y );
\r
152 p_intf->b_menu_change = 0;
\r
155 /* Update the log window */
\r
156 p_intf->p_sys->p_messages->UpdateLog();
\r
158 /* Update the playlist */
\r
159 p_intf->p_sys->p_playwin->Manage();
\r
161 /* Update the input */
\r
162 if( p_intf->p_sys->p_input == NULL )
\r
164 p_intf->p_sys->p_input = (input_thread_t *)
\r
165 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
\r
167 else if( p_intf->p_sys->p_input->b_dead )
\r
169 vlc_object_release( p_intf->p_sys->p_input );
\r
170 p_intf->p_sys->p_input = NULL;
\r
173 if( p_intf->p_sys->p_input != NULL && !p_intf->p_sys->p_input->b_die )
\r
175 vlc_bool_t b_need_menus = VLC_FALSE;
\r
176 input_thread_t * p_input = p_intf->p_sys->p_input;
\r
177 vlc_object_t * p_aout = NULL;
\r
178 vlc_object_t * p_vout = NULL;
\r
180 vlc_mutex_lock( &p_input->stream.stream_lock );
\r
182 /* New input or stream map change */
\r
183 if( p_input->stream.b_changed )
\r
185 p_intf->p_sys->p_window->ModeManage();
\r
186 b_need_menus = VLC_TRUE;
\r
187 p_intf->p_sys->b_playing = 1;
\r
190 /* Manage the slider */
\r
191 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
\r
193 TTrackBar * TrackBar = p_intf->p_sys->p_window->TrackBar;
\r
194 off_t NewValue = TrackBar->Position;
\r
196 #define p_area p_input->stream.p_selected_area
\r
197 /* If the user hasn't touched the slider since the last time,
\r
198 * then the input can safely change it */
\r
199 if( NewValue == p_intf->p_sys->OldValue )
\r
201 /* Update the value */
\r
202 TrackBar->Position = p_intf->p_sys->OldValue =
\r
203 ( (off_t)SLIDER_MAX_VALUE * p_area->i_tell ) /
\r
206 /* Otherwise, send message to the input if the user has
\r
207 * finished dragging the slider */
\r
208 else if( p_intf->p_sys->b_slider_free )
\r
210 off_t i_seek = ( NewValue * p_area->i_size ) /
\r
211 (off_t)SLIDER_MAX_VALUE;
\r
213 /* release the lock to be able to seek */
\r
214 vlc_mutex_unlock( &p_input->stream.stream_lock );
\r
215 input_Seek( p_input, i_seek, INPUT_SEEK_SET );
\r
216 vlc_mutex_lock( &p_input->stream.stream_lock );
\r
218 /* Update the old value */
\r
219 p_intf->p_sys->OldValue = NewValue;
\r
225 if( p_intf->p_sys->i_part != p_input->stream.p_selected_area->i_part )
\r
227 p_intf->p_sys->b_chapter_update = 1;
\r
228 b_need_menus = VLC_TRUE;
\r
231 /* Does the audio output require to update the menus ? */
\r
232 p_aout = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
\r
234 if( p_aout != NULL )
\r
237 if( var_Get( p_aout, "intf-change", &val ) >= 0
\r
240 p_intf->p_sys->b_aout_update = 1;
\r
241 b_need_menus = VLC_TRUE;
\r
244 vlc_object_release( p_aout );
\r
247 /* Does the video output require to update the menus ? */
\r
248 p_vout = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
\r
250 if( p_vout != NULL )
\r
253 if( var_Get( p_vout, "intf-change", &val ) >= 0
\r
256 p_intf->p_sys->b_vout_update = 1;
\r
257 b_need_menus = VLC_TRUE;
\r
260 if( var_Get( p_vout, "directx-on-top", &val ) >= 0 )
\r
262 p_intf->p_sys->p_window->MenuOnTop->Checked = val.b_bool;
\r
263 p_intf->p_sys->p_window->PopupOnTop->Checked = val.b_bool;
\r
266 vlc_object_release( p_vout );
\r
271 p_intf->p_sys->p_menus->SetupMenus();
\r
274 vlc_mutex_unlock( &p_input->stream.stream_lock );
\r
276 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
\r
278 p_intf->p_sys->p_window->ModeManage();
\r
279 p_intf->p_sys->b_playing = 0;
\r
282 if( p_intf->b_die )
\r
284 vlc_mutex_unlock( &p_intf->change_lock );
\r
286 /* Prepare to die, young Skywalker */
\r
287 p_intf->p_sys->p_window->ModalResult = mrOk;
\r
293 vlc_mutex_unlock( &p_intf->change_lock );
\r
298 /*****************************************************************************
\r
299 * Module descriptor
\r
300 *****************************************************************************/
\r
302 #define MAX_LINES_TEXT N_( "maximum number of lines in the log window" )
\r
303 #define MAX_LINES_LONGTEXT N_( \
\r
304 "You can set the maximum number of lines that the log window will display."\
\r
305 " Enter -1 if you want to keep all messages." )
\r
306 #define SHOW_CAPTIONS_TEXT N_( "display text under images in the toolbar" )
\r
307 #define SHOW_CAPTIONS_LONGTEXT N_( \
\r
308 "Check this option if you want to display the caption of the buttons in " \
\r
309 "the toolbar. Beware, the display may be messed up" )
\r
311 vlc_module_begin();
\r
312 add_category_hint( N_("Miscellaneous"), NULL, VLC_TRUE );
\r
313 add_integer( "intfwin-max-lines", 500, NULL, MAX_LINES_TEXT,
\r
314 MAX_LINES_LONGTEXT, VLC_TRUE );
\r
315 add_bool( "intfwin-show-captions", 0, NULL, SHOW_CAPTIONS_TEXT,
\r
316 SHOW_CAPTIONS_LONGTEXT, VLC_FALSE );
\r
317 set_description( _("Native Windows interface") );
\r
318 set_capability( "interface", 100 );
\r
319 set_callbacks( E_(Open), E_(Close) );
\r
320 add_shortcut( "win" );
\r
321 add_shortcut( "win32" );
\r