1 /*****************************************************************************
2 * wxwindows.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: wxwindows.cpp,v 1.5 2002/11/23 14:28:51 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() */
32 #include <wx/wxprec.h>
35 /* Let vlc take care of the i18n stuff */
38 #ifdef WIN32 /* mingw32 hack */
46 #include "wxwindows.h"
48 /*****************************************************************************
50 *****************************************************************************/
51 static int Open ( vlc_object_t * );
52 static void Close ( vlc_object_t * );
54 static void Run ( intf_thread_t * );
56 /*****************************************************************************
57 * Local classes declarations.
58 *****************************************************************************/
59 class Instance: public wxApp
63 Instance( intf_thread_t *_p_intf );
68 intf_thread_t *p_intf;
69 wxLocale locale; /* locale we'll be using */
72 /*****************************************************************************
74 *****************************************************************************/
76 add_category_hint( N_("wxWindows"), NULL );
77 set_description( (char *) _("wxWindows interface module") );
78 set_capability( "interface", 50 );
79 set_callbacks( Open, Close );
80 set_program( "wxvlc" );
83 /*****************************************************************************
84 * Open: initialize and create window
85 *****************************************************************************/
86 static int Open( vlc_object_t *p_this )
88 intf_thread_t *p_intf = (intf_thread_t *)p_this;
90 /* Allocate instance and initialize some members */
91 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
92 if( p_intf->p_sys == NULL )
94 msg_Err( p_intf, "out of memory" );
100 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
102 /* Initialize wxWindows thread */
103 p_intf->p_sys->b_playing = 0;
104 p_intf->p_sys->b_popup_changed = 0;
105 p_intf->p_sys->b_window_changed = 0;
106 p_intf->p_sys->b_playlist_changed = 0;
108 p_intf->p_sys->p_input = NULL;
109 p_intf->p_sys->i_playing = -1;
110 p_intf->p_sys->b_slider_free = 1;
111 p_intf->p_sys->i_slider_pos = p_intf->p_sys->i_slider_oldpos = 0;
113 p_intf->p_sys->i_part = -1;
118 /*****************************************************************************
119 * Close: destroy interface window
120 *****************************************************************************/
121 static void Close( vlc_object_t *p_this )
123 intf_thread_t *p_intf = (intf_thread_t *)p_this;
125 if( p_intf->p_sys->p_input )
127 vlc_object_release( p_intf->p_sys->p_input );
130 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
132 /* Destroy structure */
133 free( p_intf->p_sys );
136 /*****************************************************************************
137 * Run: wxWindows thread
138 *****************************************************************************/
139 static void Run( intf_thread_t *p_intf )
141 static char *p_args[] = { "" };
143 /* Hack to pass the p_intf pointer to the new wxWindow Instance object */
144 wxTheApp = new Instance( p_intf );
147 wxEntry( GetModuleHandle(NULL), NULL, NULL, SW_SHOW, TRUE );
149 wxEntry( 1, p_args );
153 /* following functions are local */
155 /*****************************************************************************
157 *****************************************************************************/
158 Instance::Instance( )
162 Instance::Instance( intf_thread_t *_p_intf )
168 IMPLEMENT_APP_NO_MAIN(Instance)
170 /*****************************************************************************
171 * Instance::OnInit: the parent interface execution starts here
172 *****************************************************************************
173 * This is the "main program" equivalent, the program execution will
175 *****************************************************************************/
176 bool Instance::OnInit()
178 /* Initialization of i18n stuff.
179 * Usefull for things we don't have any control over, like wxWindows
180 * provided facilities (eg. open file dialog) */
181 locale.Init( wxLANGUAGE_DEFAULT );
183 /* Make an instance of your derived frame. Passing NULL (the default value
184 * of Frame's constructor is NULL) as the frame doesn't have a frame
185 * since it is the first window */
186 Interface *MainInterface = new Interface( p_intf );
188 /* Create the playlist window */
189 p_intf->p_sys->p_playlist_window = new Playlist( p_intf, MainInterface );
191 /* Show the interface */
192 MainInterface->Show(TRUE);
194 SetTopWindow(MainInterface);
197 new Timer( p_intf, MainInterface );
199 /* Return TRUE to tell program to continue (FALSE would terminate) */