1 /*****************************************************************************
2 * wxwindows.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
39 #include "wxwindows.h"
42 #if defined(WIN32) && defined(_WX_INIT_H_)
43 /* Hack to detect wxWindows 2.5 which has a different wxEntry() prototype */
44 extern int wxEntry( HINSTANCE hInstance, HINSTANCE hPrevInstance = NULL,
45 char *pCmdLine = NULL, int nCmdShow = SW_NORMAL );
48 int wxEntry( int argc, char *argv[] , bool enterLoop = TRUE );
51 /*****************************************************************************
53 *****************************************************************************/
54 static int Open ( vlc_object_t * );
55 static void Close ( vlc_object_t * );
56 static int OpenDialogs ( vlc_object_t * );
58 static void Run ( intf_thread_t * );
59 static void Init ( intf_thread_t * );
61 static void ShowDialog ( intf_thread_t *, int, int, intf_dialog_args_t * );
63 /*****************************************************************************
64 * Local classes declarations.
65 *****************************************************************************/
66 class Instance: public wxApp
70 Instance( intf_thread_t *_p_intf );
76 intf_thread_t *p_intf;
77 wxLocale locale; /* locale we'll be using */
80 /*****************************************************************************
82 *****************************************************************************/
83 #define EMBED_TEXT N_("Embed video in interface")
84 #define EMBED_LONGTEXT N_("Embed the video inside the interface instead " \
85 "of having it in a separate window.")
86 #define BOOKMARKS_TEXT N_("Show bookmarks dialog")
87 #define BOOKMARKS_LONGTEXT N_("Show bookmarks dialog when the interface " \
94 int i_score = getenv( "DISPLAY" ) == NULL ? 15 : 150;
96 set_description( (char *) _("wxWindows interface module") );
97 set_capability( "interface", i_score );
98 set_callbacks( Open, Close );
99 add_shortcut( "wxwindows" );
100 add_shortcut( "wxwin" );
101 add_shortcut( "wx" );
102 set_program( "wxvlc" );
104 add_bool( "wxwin-embed", 1, NULL,
105 EMBED_TEXT, EMBED_LONGTEXT, VLC_FALSE );
106 add_bool( "wxwin-bookmarks", 0, NULL,
107 BOOKMARKS_TEXT, BOOKMARKS_LONGTEXT, VLC_FALSE );
110 set_description( _("wxWindows dialogs provider") );
111 set_capability( "dialogs provider", 50 );
112 set_callbacks( OpenDialogs, Close );
115 linked_with_a_crap_library_which_uses_atexit();
119 /*****************************************************************************
120 * Open: initialize and create window
121 *****************************************************************************/
122 static int Open( vlc_object_t *p_this )
124 intf_thread_t *p_intf = (intf_thread_t *)p_this;
126 /* Allocate instance and initialize some members */
127 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
128 if( p_intf->p_sys == NULL )
130 msg_Err( p_intf, "out of memory" );
133 memset( p_intf->p_sys, 0, sizeof( intf_sys_t ) );
135 p_intf->pf_run = Run;
137 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
139 /* Initialize wxWindows thread */
140 p_intf->p_sys->b_playing = 0;
142 p_intf->p_sys->p_input = NULL;
143 p_intf->p_sys->i_playing = -1;
144 p_intf->p_sys->b_slider_free = 1;
145 p_intf->p_sys->i_slider_pos = p_intf->p_sys->i_slider_oldpos = 0;
147 p_intf->p_sys->p_popup_menu = NULL;
148 p_intf->p_sys->p_video_window = NULL;
150 p_intf->pf_show_dialog = NULL;
152 /* We support play on start */
153 p_intf->b_play = VLC_TRUE;
158 static int OpenDialogs( vlc_object_t *p_this )
160 intf_thread_t *p_intf = (intf_thread_t *)p_this;
161 int i_ret = Open( p_this );
163 p_intf->pf_show_dialog = ShowDialog;
168 /*****************************************************************************
169 * Close: destroy interface window
170 *****************************************************************************/
171 static void Close( vlc_object_t *p_this )
173 intf_thread_t *p_intf = (intf_thread_t *)p_this;
175 if( p_intf->p_sys->p_input )
177 vlc_object_release( p_intf->p_sys->p_input );
180 if( p_intf->pf_show_dialog )
182 /* We must destroy the dialogs thread */
183 wxCommandEvent event( wxEVT_DIALOG, INTF_DIALOG_EXIT );
184 p_intf->p_sys->p_wxwindow->AddPendingEvent( event );
185 vlc_thread_join( p_intf );
188 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
190 /* Destroy structure */
191 free( p_intf->p_sys );
194 /*****************************************************************************
195 * Run: wxWindows thread
196 *****************************************************************************/
197 #if !defined(__BUILTIN__) && defined( WIN32 )
198 HINSTANCE hInstance = 0;
199 extern "C" BOOL WINAPI
200 DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
202 hInstance = (HINSTANCE)hModule;
207 static void Run( intf_thread_t *p_intf )
209 if( p_intf->pf_show_dialog )
211 /* The module is used in dialog provider mode */
213 /* Create a new thread for wxWindows */
214 if( vlc_thread_create( p_intf, "Skins Dialogs Thread",
215 Init, 0, VLC_TRUE ) )
217 msg_Err( p_intf, "cannot create Skins Dialogs Thread" );
218 p_intf->pf_show_dialog = NULL;
223 /* The module is used in interface mode */
228 static void Init( intf_thread_t *p_intf )
230 #if !defined( WIN32 )
231 static char *p_args[] = { "" };
235 /* Hack to pass the p_intf pointer to the new wxWindow Instance object */
237 wxApp::SetInstance( new Instance( p_intf ) );
239 wxTheApp = new Instance( p_intf );
243 #if !defined(__BUILTIN__)
244 wxEntry( hInstance/*GetModuleHandle(NULL)*/, NULL, NULL, SW_SHOW );
246 wxEntry( GetModuleHandle(NULL), NULL, NULL, SW_SHOW );
249 wxEntry( i_args, p_args );
253 /* following functions are local */
255 /*****************************************************************************
257 *****************************************************************************/
258 Instance::Instance( )
262 Instance::Instance( intf_thread_t *_p_intf )
268 IMPLEMENT_APP_NO_MAIN(Instance)
270 /*****************************************************************************
271 * Instance::OnInit: the parent interface execution starts here
272 *****************************************************************************
273 * This is the "main program" equivalent, the program execution will
275 *****************************************************************************/
276 bool Instance::OnInit()
278 /* Initialization of i18n stuff.
279 * Usefull for things we don't have any control over, like wxWindows
280 * provided facilities (eg. open file dialog) */
281 locale.Init( wxLANGUAGE_DEFAULT );
283 /* FIXME: The stream output mrl parsing uses ',' already so we want to
284 * keep the default '.' for floating point numbers. */
285 setlocale( LC_NUMERIC, "C" );
287 /* Make an instance of your derived frame. Passing NULL (the default value
288 * of Frame's constructor is NULL) as the frame doesn't have a parent
289 * since it is the first window */
291 if( !p_intf->pf_show_dialog )
293 /* The module is used in interface mode */
294 Interface *MainInterface = new Interface( p_intf );
295 p_intf->p_sys->p_wxwindow = MainInterface;
297 /* Show the interface */
298 MainInterface->Show( TRUE );
299 SetTopWindow( MainInterface );
300 MainInterface->Raise();
303 /* Creates the dialogs provider */
304 p_intf->p_sys->p_wxwindow =
305 CreateDialogsProvider( p_intf, p_intf->pf_show_dialog ?
306 NULL : p_intf->p_sys->p_wxwindow );
308 p_intf->p_sys->pf_show_dialog = ShowDialog;
310 /* OK, initialization is over */
311 vlc_thread_ready( p_intf );
313 /* Check if we need to start playing */
314 if( !p_intf->pf_show_dialog && p_intf->b_play )
316 playlist_t *p_playlist =
317 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
321 playlist_Play( p_playlist );
322 vlc_object_release( p_playlist );
326 /* Return TRUE to tell program to continue (FALSE would terminate) */
330 /*****************************************************************************
331 * Instance::OnExit: called when the interface execution stops
332 *****************************************************************************/
333 int Instance::OnExit()
335 if( p_intf->pf_show_dialog )
337 /* We need to manually clean up the dialogs class */
338 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
343 static void ShowDialog( intf_thread_t *p_intf, int i_dialog_event, int i_arg,
344 intf_dialog_args_t *p_arg )
346 wxCommandEvent event( wxEVT_DIALOG, i_dialog_event );
347 event.SetInt( i_arg );
348 event.SetClientData( p_arg );
351 SendMessage( (HWND)p_intf->p_sys->p_wxwindow->GetHandle(),
352 WM_CANCELMODE, 0, 0 );
354 if( i_dialog_event == INTF_DIALOG_POPUPMENU && i_arg == 0 ) return;
356 /* Hack to prevent popup events to be enqueued when
357 * one is already active */
358 if( i_dialog_event != INTF_DIALOG_POPUPMENU ||
359 !p_intf->p_sys->p_popup_menu )
361 p_intf->p_sys->p_wxwindow->AddPendingEvent( event );