]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/wxwindows.cpp
38b51895a9a391745dabf545d5e08bd733f7d583
[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.17 2003/07/05 15:35:28 sam 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 /* Temporary hack */
50 #ifdef __DARWIN__
51 int wxEntry( int argc, char *argv[] , bool enterLoop = TRUE );
52 #endif
53
54 /*****************************************************************************
55  * Local prototypes.
56  *****************************************************************************/
57 static int  Open         ( vlc_object_t * );
58 static void Close        ( vlc_object_t * );
59
60 static void Run          ( intf_thread_t * );
61
62 /*****************************************************************************
63  * Local classes declarations.
64  *****************************************************************************/
65 class Instance: public wxApp
66 {
67 public:
68     Instance();
69     Instance( intf_thread_t *_p_intf );
70
71     bool OnInit();
72
73 private:
74     intf_thread_t *p_intf;
75     wxLocale locale;                                /* locale we'll be using */
76 };
77
78 /*****************************************************************************
79  * Module descriptor
80  *****************************************************************************/
81 vlc_module_begin();
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" );
87     add_shortcut( "wx" );
88     set_program( "wxvlc" );
89 #if !defined(WIN32)
90     linked_with_a_crap_library_which_uses_atexit();
91 #endif
92 vlc_module_end();
93
94 /*****************************************************************************
95  * Open: initialize and create window
96  *****************************************************************************/
97 static int Open( vlc_object_t *p_this )
98 {
99     intf_thread_t *p_intf = (intf_thread_t *)p_this;
100
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 )
104     {
105         msg_Err( p_intf, "out of memory" );
106         return VLC_ENOMEM;
107     }
108
109     p_intf->pf_run = Run;
110
111     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
112
113     /* Initialize wxWindows thread */
114     p_intf->p_sys->b_playing = 0;
115
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;
120
121     p_intf->p_sys->p_popup_menu = NULL;
122     p_intf->p_sys->b_popup_change = VLC_FALSE;
123
124     return VLC_SUCCESS;
125 }
126
127 /*****************************************************************************
128  * Close: destroy interface window
129  *****************************************************************************/
130 static void Close( vlc_object_t *p_this )
131 {
132     intf_thread_t *p_intf = (intf_thread_t *)p_this;
133
134     if( p_intf->p_sys->p_input )
135     {
136         vlc_object_release( p_intf->p_sys->p_input );
137     }
138
139     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
140
141     /* Destroy structure */
142     free( p_intf->p_sys );
143 }
144
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)
152 {
153     hInstance = (HINSTANCE)hModule;
154     return TRUE;
155 }
156 #endif
157
158 static void Run( intf_thread_t *p_intf )
159 {
160 #if !defined( WIN32 )
161     static char  *p_args[] = { "" };
162 #endif
163
164     /* Hack to pass the p_intf pointer to the new wxWindow Instance object */
165     wxTheApp = new Instance( p_intf );
166
167 #if defined( WIN32 )
168 #if !defined(__BUILTIN__)
169     wxEntry( hInstance/*GetModuleHandle(NULL)*/, NULL, NULL, SW_SHOW, TRUE );
170 #else
171     wxEntry( GetModuleHandle(NULL), NULL, NULL, SW_SHOW, TRUE );
172 #endif
173 #else
174     wxEntry( 1, p_args );
175 #endif
176 }
177
178 /* following functions are local */
179
180 /*****************************************************************************
181  * Constructors.
182  *****************************************************************************/
183 Instance::Instance( )
184 {
185 }
186
187 Instance::Instance( intf_thread_t *_p_intf )
188 {
189     /* Initialization */
190     p_intf = _p_intf;
191 }
192
193 IMPLEMENT_APP_NO_MAIN(Instance)
194
195 /*****************************************************************************
196  * Instance::OnInit: the parent interface execution starts here
197  *****************************************************************************
198  * This is the "main program" equivalent, the program execution will
199  * start here.
200  *****************************************************************************/
201 bool Instance::OnInit()
202 {
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 );
207
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 );
212
213     /* Create the playlist window */
214     p_intf->p_sys->p_playlist_window = new Playlist( p_intf, MainInterface );
215
216     /* Create the log window */
217     p_intf->p_sys->p_messages_window = new Messages( p_intf, MainInterface );
218
219     /* Create the fileinfo window */
220     p_intf->p_sys->p_fileinfo_window = new FileInfo ( p_intf, MainInterface );
221
222     /* Show the interface */
223     MainInterface->Show( TRUE );
224
225     SetTopWindow( MainInterface );
226
227     /* Start timer */
228     new Timer( p_intf, MainInterface );
229
230     /* Return TRUE to tell program to continue (FALSE would terminate) */
231     return TRUE;
232 }