]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/wxwindows.cpp
950d8e9297e01dc146433b24da0362f891b5afca
[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.9 2002/12/15 18:37:39 ipkiss 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     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" );
89 vlc_module_end();
90
91 /*****************************************************************************
92  * Open: initialize and create window
93  *****************************************************************************/
94 static int Open( vlc_object_t *p_this )
95 {
96     intf_thread_t *p_intf = (intf_thread_t *)p_this;
97
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 )
101     {
102         msg_Err( p_intf, "out of memory" );
103         return VLC_ENOMEM;
104     }
105
106     p_intf->pf_run = Run;
107
108     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
109
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;
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->i_part = 0;
122
123     return VLC_SUCCESS;
124 }
125
126 /*****************************************************************************
127  * Close: destroy interface window
128  *****************************************************************************/
129 static void Close( vlc_object_t *p_this )
130 {
131     intf_thread_t *p_intf = (intf_thread_t *)p_this;
132
133     if( p_intf->p_sys->p_input )
134     {
135         vlc_object_release( p_intf->p_sys->p_input );
136     }
137
138     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
139
140     /* Destroy structure */
141     free( p_intf->p_sys );
142 }
143
144 /*****************************************************************************
145  * Run: wxWindows thread
146  *****************************************************************************/
147 static void Run( intf_thread_t *p_intf )
148 {
149 #if !defined( WIN32 )
150     static char  *p_args[] = { "" };
151 #endif
152
153     /* Hack to pass the p_intf pointer to the new wxWindow Instance object */
154     wxTheApp = new Instance( p_intf );
155
156 #if defined( WIN32 )
157     wxEntry( GetModuleHandle(NULL), NULL, NULL, SW_SHOW, TRUE );
158 #else
159     wxEntry( 1, p_args );
160 #endif
161 }
162
163 /* following functions are local */
164
165 /*****************************************************************************
166  * Constructors.
167  *****************************************************************************/
168 Instance::Instance( )
169 {
170 }
171
172 Instance::Instance( intf_thread_t *_p_intf )
173 {
174     /* Initialization */
175     p_intf = _p_intf;
176 }
177
178 IMPLEMENT_APP_NO_MAIN(Instance)
179
180 /*****************************************************************************
181  * Instance::OnInit: the parent interface execution starts here
182  *****************************************************************************
183  * This is the "main program" equivalent, the program execution will
184  * start here.
185  *****************************************************************************/
186 bool Instance::OnInit()
187 {
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 );
192
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 );
197
198     /* Create the playlist window */
199     p_intf->p_sys->p_playlist_window = new Playlist( p_intf, MainInterface );
200
201     /* Create the log window */
202     p_intf->p_sys->p_messages_window = new Messages( p_intf, MainInterface );
203
204     /* Show the interface */
205     MainInterface->Show( TRUE );
206
207     SetTopWindow( MainInterface );
208
209     /* Start timer */
210     new Timer( p_intf, MainInterface );
211
212     /* Return TRUE to tell program to continue (FALSE would terminate) */
213     return TRUE;
214 }