1 /*****************************************************************************
2 * wxwindows.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: wxwindows.cpp,v 1.17 2003/07/05 15:35:28 sam 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 * );
60 static void Run ( intf_thread_t * );
62 /*****************************************************************************
63 * Local classes declarations.
64 *****************************************************************************/
65 class Instance: public wxApp
69 Instance( intf_thread_t *_p_intf );
74 intf_thread_t *p_intf;
75 wxLocale locale; /* locale we'll be using */
78 /*****************************************************************************
80 *****************************************************************************/
82 set_description( (char *) _("wxWindows interface module") );
83 set_capability( "interface", 50 );
84 set_callbacks( Open, Close );
85 add_shortcut( "wxwindows" );
86 add_shortcut( "wxwin" );
88 set_program( "wxvlc" );
90 linked_with_a_crap_library_which_uses_atexit();
94 /*****************************************************************************
95 * Open: initialize and create window
96 *****************************************************************************/
97 static int Open( vlc_object_t *p_this )
99 intf_thread_t *p_intf = (intf_thread_t *)p_this;
101 /* Allocate instance and initialize some members */
102 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
103 if( p_intf->p_sys == NULL )
105 msg_Err( p_intf, "out of memory" );
109 p_intf->pf_run = Run;
111 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
113 /* Initialize wxWindows thread */
114 p_intf->p_sys->b_playing = 0;
116 p_intf->p_sys->p_input = NULL;
117 p_intf->p_sys->i_playing = -1;
118 p_intf->p_sys->b_slider_free = 1;
119 p_intf->p_sys->i_slider_pos = p_intf->p_sys->i_slider_oldpos = 0;
121 p_intf->p_sys->p_popup_menu = NULL;
122 p_intf->p_sys->b_popup_change = VLC_FALSE;
127 /*****************************************************************************
128 * Close: destroy interface window
129 *****************************************************************************/
130 static void Close( vlc_object_t *p_this )
132 intf_thread_t *p_intf = (intf_thread_t *)p_this;
134 if( p_intf->p_sys->p_input )
136 vlc_object_release( p_intf->p_sys->p_input );
139 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
141 /* Destroy structure */
142 free( p_intf->p_sys );
145 /*****************************************************************************
146 * Run: wxWindows thread
147 *****************************************************************************/
148 #if !defined(__BUILTIN__) && defined( WIN32 )
149 HINSTANCE hInstance = 0;
150 extern "C" BOOL WINAPI
151 DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
153 hInstance = (HINSTANCE)hModule;
158 static void Run( intf_thread_t *p_intf )
160 #if !defined( WIN32 )
161 static char *p_args[] = { "" };
164 /* Hack to pass the p_intf pointer to the new wxWindow Instance object */
165 wxTheApp = new Instance( p_intf );
168 #if !defined(__BUILTIN__)
169 wxEntry( hInstance/*GetModuleHandle(NULL)*/, NULL, NULL, SW_SHOW, TRUE );
171 wxEntry( GetModuleHandle(NULL), NULL, NULL, SW_SHOW, TRUE );
174 wxEntry( 1, p_args );
178 /* following functions are local */
180 /*****************************************************************************
182 *****************************************************************************/
183 Instance::Instance( )
187 Instance::Instance( intf_thread_t *_p_intf )
193 IMPLEMENT_APP_NO_MAIN(Instance)
195 /*****************************************************************************
196 * Instance::OnInit: the parent interface execution starts here
197 *****************************************************************************
198 * This is the "main program" equivalent, the program execution will
200 *****************************************************************************/
201 bool Instance::OnInit()
203 /* Initialization of i18n stuff.
204 * Usefull for things we don't have any control over, like wxWindows
205 * provided facilities (eg. open file dialog) */
206 locale.Init( wxLANGUAGE_DEFAULT );
208 /* Make an instance of your derived frame. Passing NULL (the default value
209 * of Frame's constructor is NULL) as the frame doesn't have a frame
210 * since it is the first window */
211 Interface *MainInterface = new Interface( p_intf );
213 /* Create the playlist window */
214 p_intf->p_sys->p_playlist_window = new Playlist( p_intf, MainInterface );
216 /* Create the log window */
217 p_intf->p_sys->p_messages_window = new Messages( p_intf, MainInterface );
219 /* Create the fileinfo window */
220 p_intf->p_sys->p_fileinfo_window = new FileInfo ( p_intf, MainInterface );
222 /* Show the interface */
223 MainInterface->Show( TRUE );
225 SetTopWindow( MainInterface );
228 new Timer( p_intf, MainInterface );
230 /* Return TRUE to tell program to continue (FALSE would terminate) */