1 /*****************************************************************************
2 * wxwindows.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: wxwindows.cpp,v 1.11 2003/01/28 20:02:03 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 add_category_hint( N_("wxWindows"), NULL );
83 set_description( (char *) _("wxWindows interface module") );
84 set_capability( "interface", 50 );
85 set_callbacks( Open, Close );
86 add_shortcut( "wxwindows" );
87 add_shortcut( "wxwin" );
89 set_program( "wxvlc" );
92 /*****************************************************************************
93 * Open: initialize and create window
94 *****************************************************************************/
95 static int Open( vlc_object_t *p_this )
97 intf_thread_t *p_intf = (intf_thread_t *)p_this;
99 /* Allocate instance and initialize some members */
100 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
101 if( p_intf->p_sys == NULL )
103 msg_Err( p_intf, "out of memory" );
107 p_intf->pf_run = Run;
109 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
111 /* Initialize wxWindows thread */
112 p_intf->p_sys->b_playing = 0;
113 p_intf->p_sys->b_popup_changed = 0;
114 p_intf->p_sys->b_window_changed = 0;
115 p_intf->p_sys->b_playlist_changed = 0;
117 p_intf->p_sys->p_input = NULL;
118 p_intf->p_sys->i_playing = -1;
119 p_intf->p_sys->b_slider_free = 1;
120 p_intf->p_sys->i_slider_pos = p_intf->p_sys->i_slider_oldpos = 0;
122 p_intf->p_sys->i_part = 0;
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 *****************************************************************************/
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 wxEntry( hInstance/*GetModuleHandle(NULL)*/, NULL, NULL, SW_SHOW, TRUE );
170 wxEntry( 1, p_args );
174 /* following functions are local */
176 /*****************************************************************************
178 *****************************************************************************/
179 Instance::Instance( )
183 Instance::Instance( intf_thread_t *_p_intf )
189 IMPLEMENT_APP_NO_MAIN(Instance)
191 /*****************************************************************************
192 * Instance::OnInit: the parent interface execution starts here
193 *****************************************************************************
194 * This is the "main program" equivalent, the program execution will
196 *****************************************************************************/
197 bool Instance::OnInit()
199 /* Initialization of i18n stuff.
200 * Usefull for things we don't have any control over, like wxWindows
201 * provided facilities (eg. open file dialog) */
202 locale.Init( wxLANGUAGE_DEFAULT );
204 /* Make an instance of your derived frame. Passing NULL (the default value
205 * of Frame's constructor is NULL) as the frame doesn't have a frame
206 * since it is the first window */
207 Interface *MainInterface = new Interface( p_intf );
209 /* Create the playlist window */
210 p_intf->p_sys->p_playlist_window = new Playlist( p_intf, MainInterface );
212 /* Create the log window */
213 p_intf->p_sys->p_messages_window = new Messages( p_intf, MainInterface );
215 /* Show the interface */
216 MainInterface->Show( TRUE );
218 SetTopWindow( MainInterface );
221 new Timer( p_intf, MainInterface );
223 /* Return TRUE to tell program to continue (FALSE would terminate) */