1 /*****************************************************************************
2 * wxwindows.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: wxwindows.cpp,v 1.9 2002/12/15 18:37:39 ipkiss 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" );
88 set_program( "wxvlc" );
91 /*****************************************************************************
92 * Open: initialize and create window
93 *****************************************************************************/
94 static int Open( vlc_object_t *p_this )
96 intf_thread_t *p_intf = (intf_thread_t *)p_this;
98 /* Allocate instance and initialize some members */
99 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
100 if( p_intf->p_sys == NULL )
102 msg_Err( p_intf, "out of memory" );
106 p_intf->pf_run = Run;
108 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
110 /* Initialize wxWindows thread */
111 p_intf->p_sys->b_playing = 0;
112 p_intf->p_sys->b_popup_changed = 0;
113 p_intf->p_sys->b_window_changed = 0;
114 p_intf->p_sys->b_playlist_changed = 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->i_part = 0;
126 /*****************************************************************************
127 * Close: destroy interface window
128 *****************************************************************************/
129 static void Close( vlc_object_t *p_this )
131 intf_thread_t *p_intf = (intf_thread_t *)p_this;
133 if( p_intf->p_sys->p_input )
135 vlc_object_release( p_intf->p_sys->p_input );
138 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
140 /* Destroy structure */
141 free( p_intf->p_sys );
144 /*****************************************************************************
145 * Run: wxWindows thread
146 *****************************************************************************/
147 static void Run( intf_thread_t *p_intf )
149 #if !defined( WIN32 )
150 static char *p_args[] = { "" };
153 /* Hack to pass the p_intf pointer to the new wxWindow Instance object */
154 wxTheApp = new Instance( p_intf );
157 wxEntry( GetModuleHandle(NULL), NULL, NULL, SW_SHOW, TRUE );
159 wxEntry( 1, p_args );
163 /* following functions are local */
165 /*****************************************************************************
167 *****************************************************************************/
168 Instance::Instance( )
172 Instance::Instance( intf_thread_t *_p_intf )
178 IMPLEMENT_APP_NO_MAIN(Instance)
180 /*****************************************************************************
181 * Instance::OnInit: the parent interface execution starts here
182 *****************************************************************************
183 * This is the "main program" equivalent, the program execution will
185 *****************************************************************************/
186 bool Instance::OnInit()
188 /* Initialization of i18n stuff.
189 * Usefull for things we don't have any control over, like wxWindows
190 * provided facilities (eg. open file dialog) */
191 locale.Init( wxLANGUAGE_DEFAULT );
193 /* Make an instance of your derived frame. Passing NULL (the default value
194 * of Frame's constructor is NULL) as the frame doesn't have a frame
195 * since it is the first window */
196 Interface *MainInterface = new Interface( p_intf );
198 /* Create the playlist window */
199 p_intf->p_sys->p_playlist_window = new Playlist( p_intf, MainInterface );
201 /* Create the log window */
202 p_intf->p_sys->p_messages_window = new Messages( p_intf, MainInterface );
204 /* Show the interface */
205 MainInterface->Show( TRUE );
207 SetTopWindow( MainInterface );
210 new Timer( p_intf, MainInterface );
212 /* Return TRUE to tell program to continue (FALSE would terminate) */