]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/wxwindows.cpp
* modules/gui/wxwindows/*: a few fixes for the win32 build.
[vlc] / modules / gui / wxwindows / wxwindows.cpp
1 /*****************************************************************************
2  * wxwindows.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: wxwindows.cpp,v 1.6 2002/11/23 16:17:12 gbazin Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33
34 #ifdef WIN32                                                 /* mingw32 hack */
35 #undef Yield
36 #undef CreateDialog
37 #endif
38
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
41
42 #include <wx/wxprec.h>
43 #include <wx/wx.h>
44
45 #include <vlc/intf.h>
46
47 #include "wxwindows.h"
48
49 /*****************************************************************************
50  * Local prototypes.
51  *****************************************************************************/
52 static int  Open         ( vlc_object_t * );
53 static void Close        ( vlc_object_t * );
54
55 static void Run          ( intf_thread_t * );
56
57 /*****************************************************************************
58  * Local classes declarations.
59  *****************************************************************************/
60 class Instance: public wxApp
61 {
62 public:
63     Instance();
64     Instance( intf_thread_t *_p_intf );
65
66     bool OnInit();
67
68 private:
69     intf_thread_t *p_intf;
70     wxLocale locale;                                /* locale we'll be using */
71 };
72
73 /*****************************************************************************
74  * Module descriptor
75  *****************************************************************************/
76 vlc_module_begin();
77     add_category_hint( N_("wxWindows"), NULL );
78     set_description( (char *) _("wxWindows interface module") );
79     set_capability( "interface", 50 );
80     set_callbacks( Open, Close );
81     add_shortcut( "wxwindows" );
82     add_shortcut( "wxwin" );
83     set_program( "wxvlc" );
84 vlc_module_end();
85
86 /*****************************************************************************
87  * Open: initialize and create window
88  *****************************************************************************/
89 static int Open( vlc_object_t *p_this )
90 {
91     intf_thread_t *p_intf = (intf_thread_t *)p_this;
92
93     /* Allocate instance and initialize some members */
94     p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
95     if( p_intf->p_sys == NULL )
96     {
97         msg_Err( p_intf, "out of memory" );
98         return VLC_ENOMEM;
99     }
100
101     p_intf->pf_run = Run;
102
103     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
104
105     /* Initialize wxWindows thread */
106     p_intf->p_sys->b_playing = 0;
107     p_intf->p_sys->b_popup_changed = 0;
108     p_intf->p_sys->b_window_changed = 0;
109     p_intf->p_sys->b_playlist_changed = 0;
110
111     p_intf->p_sys->p_input = NULL;
112     p_intf->p_sys->i_playing = -1;
113     p_intf->p_sys->b_slider_free = 1;
114     p_intf->p_sys->i_slider_pos = p_intf->p_sys->i_slider_oldpos = 0;
115
116     p_intf->p_sys->i_part = -1;
117
118     return VLC_SUCCESS;
119 }
120
121 /*****************************************************************************
122  * Close: destroy interface window
123  *****************************************************************************/
124 static void Close( vlc_object_t *p_this )
125 {
126     intf_thread_t *p_intf = (intf_thread_t *)p_this;
127
128     if( p_intf->p_sys->p_input )
129     {
130         vlc_object_release( p_intf->p_sys->p_input );
131     }
132
133     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
134
135     /* Destroy structure */
136     free( p_intf->p_sys );
137 }
138
139 /*****************************************************************************
140  * Run: wxWindows thread
141  *****************************************************************************/
142 static void Run( intf_thread_t *p_intf )
143 {
144 #if !defined( WIN32 )
145     static char  *p_args[] = { "" };
146 #endif
147
148     /* Hack to pass the p_intf pointer to the new wxWindow Instance object */
149     wxTheApp = new Instance( p_intf );
150
151 #if defined( WIN32 )
152     wxEntry( GetModuleHandle(NULL), NULL, NULL, SW_SHOW, TRUE );
153 #else
154     wxEntry( 1, p_args );
155 #endif
156 }
157
158 /* following functions are local */
159
160 /*****************************************************************************
161  * Constructors.
162  *****************************************************************************/
163 Instance::Instance( )
164 {
165 }
166
167 Instance::Instance( intf_thread_t *_p_intf )
168 {
169     /* Initialization */
170     p_intf = _p_intf;
171 }
172
173 IMPLEMENT_APP_NO_MAIN(Instance)
174
175 /*****************************************************************************
176  * Instance::OnInit: the parent interface execution starts here
177  *****************************************************************************
178  * This is the "main program" equivalent, the program execution will
179  * start here.
180  *****************************************************************************/
181 bool Instance::OnInit()
182 {
183     /* Initialization of i18n stuff.
184      * Usefull for things we don't have any control over, like wxWindows
185      * provided facilities (eg. open file dialog) */
186     locale.Init( wxLANGUAGE_DEFAULT );
187
188     /* Make an instance of your derived frame. Passing NULL (the default value
189      * of Frame's constructor is NULL) as the frame doesn't have a frame
190      * since it is the first window */
191     Interface *MainInterface = new Interface( p_intf );
192
193     /* Create the playlist window */
194     p_intf->p_sys->p_playlist_window = new Playlist( p_intf, MainInterface );
195
196     /* Show the interface */
197     MainInterface->Show(TRUE);
198
199     SetTopWindow(MainInterface);
200
201     /* Start timer */
202     new Timer( p_intf, MainInterface );
203
204     /* Return TRUE to tell program to continue (FALSE would terminate) */
205     return TRUE;
206 }