]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/wxwindows.cpp
* ./modules/gui/wxwindows/playlist.cpp: added a playlist to the wxwindows interface
[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.4 2002/11/23 01:32:40 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 #include <vlc/intf.h>
34
35 /* Let wxWindows take care of the i18n stuff */
36 #undef _
37
38 #ifdef WIN32                                                 /* mingw32 hack */
39 #undef Yield
40 #undef CreateDialog
41 #endif
42
43 #include <wx/wxprec.h>
44 #include <wx/wx.h>
45 #include <wx/imagpng.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 };
71
72 /*****************************************************************************
73  * Module descriptor
74  *****************************************************************************/
75 vlc_module_begin();
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" );
81 vlc_module_end();
82
83 /*****************************************************************************
84  * Open: initialize and create window
85  *****************************************************************************/
86 static int Open( vlc_object_t *p_this )
87 {
88     intf_thread_t *p_intf = (intf_thread_t *)p_this;
89
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 )
93     {
94         msg_Err( p_intf, "out of memory" );
95         return VLC_ENOMEM;
96     }
97
98     p_intf->pf_run = Run;
99
100     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
101
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;
107
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;
112
113     p_intf->p_sys->i_part = -1;
114
115     return VLC_SUCCESS;
116 }
117
118 /*****************************************************************************
119  * Close: destroy interface window
120  *****************************************************************************/
121 static void Close( vlc_object_t *p_this )
122 {
123     intf_thread_t *p_intf = (intf_thread_t *)p_this;
124
125     if( p_intf->p_sys->p_input )
126     {
127         vlc_object_release( p_intf->p_sys->p_input );
128     }
129
130     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
131
132     /* Destroy structure */
133     free( p_intf->p_sys );
134 }
135
136 /*****************************************************************************
137  * Run: wxWindows thread
138  *****************************************************************************/
139 static void Run( intf_thread_t *p_intf )
140 {
141     static char  *p_args[] = { "" };
142
143     /* Hack to pass the p_intf pointer to the new wxWindow Instance object */
144     wxTheApp = new Instance( p_intf );
145
146 #if defined( WIN32 )
147     wxEntry( GetModuleHandle(NULL), NULL, NULL, SW_SHOW, TRUE );
148 #else
149     wxEntry( 1, p_args );
150 #endif
151 }
152
153 /* following functions are local */
154
155 /*****************************************************************************
156  * Constructors.
157  *****************************************************************************/
158 Instance::Instance( )
159 {
160 }
161
162 Instance::Instance( intf_thread_t *_p_intf )
163 {
164     /* Initialization */
165     p_intf = _p_intf;
166 }
167
168 IMPLEMENT_APP_NO_MAIN(Instance)
169
170 /*****************************************************************************
171  * Instance::OnInit: the parent interface execution starts here
172  *****************************************************************************
173  * This is the "main program" equivalent, the program execution will
174  * start here.
175  *****************************************************************************/
176 bool Instance::OnInit()
177 {
178     /* Make an instance of your derived frame. Passing NULL (the default value
179      * of Frame's constructor is NULL) as the frame doesn't have a frame
180      * since it is the first window */
181     Interface *MainInterface = new Interface( p_intf );
182
183     /* Create the playlist window */
184     p_intf->p_sys->p_playlist_window = new Playlist( p_intf, MainInterface );
185
186     /* Show the interface */
187     MainInterface->Show(TRUE);
188
189     SetTopWindow(MainInterface);
190
191     /* Start timer */
192     new Timer( p_intf, MainInterface );
193
194     /* Return TRUE to tell program to continue (FALSE would terminate) */
195     return TRUE;
196 }