1 /*****************************************************************************
2 * wxwindows.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: wxwindows.cpp,v 1.18 2003/07/17 17:30:40 gbazin Exp $
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() */
34 #ifdef WIN32 /* mingw32 hack */
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
42 #include <wx/wxprec.h>
47 #include "wxwindows.h"
51 int wxEntry( int argc, char *argv[] , bool enterLoop = TRUE );
54 /*****************************************************************************
56 *****************************************************************************/
57 static int Open ( vlc_object_t * );
58 static void Close ( vlc_object_t * );
59 static int OpenDialogs ( vlc_object_t * );
61 static void Run ( intf_thread_t * );
62 static void Init ( intf_thread_t * );
64 static void ShowDialog ( intf_thread_t *, int, int );
66 /*****************************************************************************
67 * Local classes declarations.
68 *****************************************************************************/
69 class Instance: public wxApp
73 Instance( intf_thread_t *_p_intf );
78 intf_thread_t *p_intf;
79 wxLocale locale; /* locale we'll be using */
82 /*****************************************************************************
84 *****************************************************************************/
86 set_description( (char *) _("wxWindows interface module") );
87 set_capability( "interface", 50 );
88 set_callbacks( Open, Close );
89 add_shortcut( "wxwindows" );
90 add_shortcut( "wxwin" );
92 set_program( "wxvlc" );
95 set_description( _("wxWindows dialogs provider") );
96 set_capability( "dialogs provider", 50 );
97 set_callbacks( OpenDialogs, Close );
100 linked_with_a_crap_library_which_uses_atexit();
104 /*****************************************************************************
105 * Open: initialize and create window
106 *****************************************************************************/
107 static int Open( vlc_object_t *p_this )
109 intf_thread_t *p_intf = (intf_thread_t *)p_this;
111 /* Allocate instance and initialize some members */
112 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
113 if( p_intf->p_sys == NULL )
115 msg_Err( p_intf, "out of memory" );
119 p_intf->pf_run = Run;
121 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
123 /* Initialize wxWindows thread */
124 p_intf->p_sys->b_playing = 0;
126 p_intf->p_sys->p_input = NULL;
127 p_intf->p_sys->i_playing = -1;
128 p_intf->p_sys->b_slider_free = 1;
129 p_intf->p_sys->i_slider_pos = p_intf->p_sys->i_slider_oldpos = 0;
131 p_intf->p_sys->p_popup_menu = NULL;
132 p_intf->p_sys->b_popup_change = VLC_FALSE;
134 p_intf->pf_show_dialog = NULL;
139 static int OpenDialogs( vlc_object_t *p_this )
141 intf_thread_t *p_intf = (intf_thread_t *)p_this;
142 int i_ret = Open( p_this );
144 p_intf->pf_show_dialog = ShowDialog;
149 /*****************************************************************************
150 * Close: destroy interface window
151 *****************************************************************************/
152 static void Close( vlc_object_t *p_this )
154 intf_thread_t *p_intf = (intf_thread_t *)p_this;
156 if( p_intf->p_sys->p_input )
158 vlc_object_release( p_intf->p_sys->p_input );
161 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
163 /* Destroy structure */
164 free( p_intf->p_sys );
167 /*****************************************************************************
168 * Run: wxWindows thread
169 *****************************************************************************/
170 #if !defined(__BUILTIN__) && defined( WIN32 )
171 HINSTANCE hInstance = 0;
172 extern "C" BOOL WINAPI
173 DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
175 hInstance = (HINSTANCE)hModule;
180 static void Run( intf_thread_t *p_intf )
182 if( p_intf->pf_show_dialog )
184 /* The module is used in dialog provider mode */
186 /* Create a new thread for wxWindows */
187 if( vlc_thread_create( p_intf, "Skins Dialogs Thread",
188 Init, 0, VLC_TRUE ) )
190 msg_Err( p_intf, "cannot create Skins Dialogs Thread" );
191 p_intf->pf_show_dialog = NULL;
196 /* The module is used in interface mode */
201 static void Init( intf_thread_t *p_intf )
203 #if !defined( WIN32 )
204 static char *p_args[] = { "" };
208 /* Hack to pass the p_intf pointer to the new wxWindow Instance object */
209 wxTheApp = new Instance( p_intf );
212 #if !defined(__BUILTIN__)
213 wxEntry( hInstance/*GetModuleHandle(NULL)*/, NULL, NULL, SW_SHOW );
215 wxEntry( GetModuleHandle(NULL), NULL, NULL, SW_SHOW );
218 wxEntry( i_args, p_args );
222 /* following functions are local */
224 /*****************************************************************************
226 *****************************************************************************/
227 Instance::Instance( )
231 Instance::Instance( intf_thread_t *_p_intf )
237 IMPLEMENT_APP_NO_MAIN(Instance)
239 /*****************************************************************************
240 * Instance::OnInit: the parent interface execution starts here
241 *****************************************************************************
242 * This is the "main program" equivalent, the program execution will
244 *****************************************************************************/
245 bool Instance::OnInit()
247 /* Initialization of i18n stuff.
248 * Usefull for things we don't have any control over, like wxWindows
249 * provided facilities (eg. open file dialog) */
250 locale.Init( wxLANGUAGE_DEFAULT );
252 /* Make an instance of your derived frame. Passing NULL (the default value
253 * of Frame's constructor is NULL) as the frame doesn't have a parent
254 * since it is the first window */
256 if( !p_intf->pf_show_dialog )
258 /* The module is used in interface mode */
259 Interface *MainInterface = new Interface( p_intf );
260 p_intf->p_sys->p_wxwindow = MainInterface;
262 /* Show the interface */
263 MainInterface->Show( TRUE );
265 SetTopWindow( MainInterface );
268 new Timer( p_intf, MainInterface );
271 /* Creates the dialogs provider */
272 p_intf->p_sys->p_wxwindow =
273 new DialogsProvider( p_intf, p_intf->pf_show_dialog ?
274 NULL : p_intf->p_sys->p_wxwindow );
276 p_intf->p_sys->pf_show_dialog = ShowDialog;
278 /* OK, initialization is over */
279 vlc_thread_ready( p_intf );
281 /* Return TRUE to tell program to continue (FALSE would terminate) */
285 static void ShowDialog( intf_thread_t *p_intf, int i_dialog_event, int i_arg )
287 wxCommandEvent event( wxEVT_DIALOG, i_dialog_event );
288 event.SetInt( i_arg );
289 p_intf->p_sys->p_wxwindow->AddPendingEvent( event );