* modules/gui/wxwindows/*: fixes for the win32 build. Removed a few
[vlc.git] / modules / gui / wxwindows / interface.cpp
1 /*****************************************************************************
2  * interface.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: interface.cpp,v 1.5 2002/11/20 14:24:00 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 #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
46 #include "wxwindows.h"
47
48 /* include the toolbar graphics */
49 #include "bitmaps/file.xpm"
50 #include "bitmaps/disc.xpm"
51 #include "bitmaps/net.xpm"
52 #if 0
53 #include "bitmaps/sat.xpm"
54 #endif
55 #include "bitmaps/play.xpm"
56 #include "bitmaps/pause.xpm"
57 #include "bitmaps/stop.xpm"
58 #include "bitmaps/previous.xpm"
59 #include "bitmaps/next.xpm"
60 #include "bitmaps/playlist.xpm"
61
62 /*****************************************************************************
63  * Event Table.
64  *****************************************************************************/
65
66 /* IDs for the controls and the menu commands */
67 enum
68 {
69     /* menu items */
70     Exit_Event = 1,
71     OpenFile_Event,
72     OpenDisc_Event,
73     OpenNet_Event,
74     OpenSat_Event,
75     EjectDisc_Event,
76
77     Logs_Event,
78
79     Audio_Event,
80     Subtitles_Event,
81     Prefs_Event,
82
83     SliderScroll_Event,
84     StopStream_Event,
85     PlayStream_Event,
86     PauseStream_Event,
87     PrevStream_Event,
88     NextStream_Event,
89
90     /* it is important for the id corresponding to the "About" command to have
91      * this standard value as otherwise it won't be handled properly under Mac
92      * (where it is special and put into the "Apple" menu) */
93     About_Event = wxID_ABOUT
94 };
95
96 BEGIN_EVENT_TABLE(Interface, wxFrame)
97     /* Menu events */
98     EVT_MENU(Exit_Event, Interface::OnExit)
99     EVT_MENU(About_Event, Interface::OnAbout)
100     EVT_MENU(OpenFile_Event, Interface::OnOpenFile)
101     /* Toolbar events */
102     EVT_MENU(OpenFile_Event, Interface::OnOpenFile)
103     EVT_MENU(StopStream_Event, Interface::OnStopStream)
104     EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
105     EVT_MENU(PauseStream_Event, Interface::OnPauseStream)
106     EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
107     EVT_MENU(NextStream_Event, Interface::OnNextStream)
108     /* Slider events */
109     EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
110 END_EVENT_TABLE()
111
112 /*****************************************************************************
113  * Constructor.
114  *****************************************************************************/
115 Interface::Interface( intf_thread_t *_p_intf ):
116     wxFrame( NULL, -1, "title", wxDefaultPosition, wxDefaultSize,
117              wxDEFAULT_FRAME_STYLE )
118 {
119
120     /* Initializations */
121     p_intf = _p_intf;
122
123     /* Give our interface a nice icon */
124     //SetIcon( wxICON(vlcicon) );
125
126     /* Create our "File" menu */
127 #define HELP_FILE  N_("Open a file")
128 #define HELP_DISC  N_("Open a DVD or (S)VCD")
129 #define HELP_NET   N_("Open a network stream")
130 #define HELP_SAT   N_("Open a satellite stream")
131 #define HELP_EJECT N_("Eject the DVD/CD")
132 #define HELP_EXIT  N_("Exit this program")
133     wxMenu *file_menu = new wxMenu;
134     file_menu->Append( OpenFile_Event, _("&Open File..."), HELP_FILE );
135     file_menu->Append( OpenDisc_Event, _("Open &Disc..."), HELP_DISC );
136     file_menu->Append( OpenNet_Event, _("&Network Stream..."), HELP_NET );
137 #if 0
138     file_menu->Append( OpenSat_Event, _("&Satellite Stream..."), HELP_NET );
139 #endif
140     file_menu->AppendSeparator();
141     file_menu->Append( EjectDisc_Event, _("&Eject Disc"), HELP_EJECT );
142     file_menu->AppendSeparator();
143     file_menu->Append( Exit_Event, _("E&xit"), HELP_EXIT );
144
145     /* Create our "View" menu */
146 #define HELP_LOGS  N_("Show the program logs")
147     wxMenu *view_menu = new wxMenu;
148     view_menu->Append( Logs_Event, _("&Logs..."), HELP_LOGS );
149
150     /* Create our "Settings" menu */
151 #define HELP_AUDIO N_("Change the current audio track")
152 #define HELP_SUBS  N_("Change the current subtitles stream")
153 #define HELP_PREFS N_("Go to the preferences menu")
154     wxMenu *settings_menu = new wxMenu;
155     settings_menu->Append( Audio_Event, _("&Audio"), HELP_AUDIO );
156     settings_menu->Append( Subtitles_Event, _("&Subtitles"), HELP_SUBS );
157     settings_menu->AppendSeparator();
158     settings_menu->Append( Prefs_Event, _("&Preferences..."), HELP_PREFS );
159
160     /* Create our "Help" menu */
161 #define HELP_ABOUT N_("About this program")
162     wxMenu *help_menu = new wxMenu;
163     help_menu->Append( About_Event, _("&About..."), HELP_ABOUT );
164
165     /* Append the freshly created menus to the menu bar... */
166     wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
167     menubar->Append( file_menu, _("&File") );
168     menubar->Append( view_menu, _("&View") );
169     menubar->Append( settings_menu, _("&Settings") );
170     menubar->Append( help_menu, _("&Help") );
171
172     /* Attach the menu bar to the frame */
173     SetMenuBar( menubar );
174
175     /* Create toolbar */
176 #define HELP_STOP N_("Stop current playlist item")
177 #define HELP_PLAY N_("Play current playlist item")
178 #define HELP_PAUSE N_("Pause current playlist item")
179 #define HELP_PLO N_("Open playlist")
180 #define HELP_PLP N_("Previous playlist item")
181 #define HELP_PLN N_("Next playlist item")
182     wxBitmap *p_bmp_file     = new wxBitmap( file_xpm );
183     wxBitmap *p_bmp_disc     = new wxBitmap( disc_xpm );
184     wxBitmap *p_bmp_net      = new wxBitmap( net_xpm );
185     wxBitmap *p_bmp_play     = new wxBitmap( play_xpm );
186     wxBitmap *p_bmp_stop     = new wxBitmap( stop_xpm );
187     wxBitmap *p_bmp_pause    = new wxBitmap( pause_xpm );
188     wxBitmap *p_bmp_prev     = new wxBitmap( previous_xpm );
189     wxBitmap *p_bmp_next     = new wxBitmap( next_xpm );
190     wxBitmap *p_bmp_playlist = new wxBitmap( playlist_xpm );
191
192     wxToolBar *toolbar = CreateToolBar(
193         wxTB_HORIZONTAL | wxTB_TEXT | wxTB_FLAT | wxTB_DOCKABLE );
194
195     toolbar->AddTool( OpenFile_Event, _("File"), *p_bmp_file, HELP_FILE );
196     toolbar->AddTool( OpenFile_Event, _("Disc"), *p_bmp_disc, HELP_DISC );
197     toolbar->AddTool( OpenFile_Event, _("Net"), *p_bmp_net, HELP_NET );
198 #if 0
199     toolbar->AddTool( OpenFile_Event, _("Sat"), *p_bmp_net, HELP_SAT );
200 #endif
201     toolbar->AddSeparator();
202     toolbar->AddTool( StopStream_Event, _("Stop"), *p_bmp_stop, HELP_STOP );
203     toolbar->AddTool( PlayStream_Event, _("Play"), *p_bmp_play, HELP_PLAY );
204     toolbar->AddTool( PauseStream_Event, _("Pause"), *p_bmp_pause, HELP_PAUSE);
205     toolbar->AddSeparator();
206     toolbar->AddTool( wxID_OPEN, _("Playlist"), *p_bmp_playlist, HELP_PLO );
207     toolbar->AddTool( PrevStream_Event, _("Prev"), *p_bmp_prev, HELP_PLP );
208     toolbar->AddTool( NextStream_Event, _("Next"), *p_bmp_next, HELP_PLN );
209
210     toolbar->Realize();
211
212     /* Create slider */
213     wxBoxSizer *slider_sizer = new wxBoxSizer( wxVERTICAL );
214     slider = new wxSlider( this, SliderScroll_Event, 0, 0, 100,
215                            wxDefaultPosition, wxSize( 450, 50 ),
216                            wxSL_HORIZONTAL | wxSL_TOP );
217     slider_sizer->Add( slider, 0, wxGROW | wxALL | wxALIGN_CENTER, 5 );
218
219     /* use the sizer for layout */
220     slider->Hide();
221     slider_sizer->Layout();
222     SetSizerAndFit( slider_sizer );
223
224     /* Give the frame an optional statusbar. The '1' just means one field.
225      * A gripsizer will automatically get put on into the corner, if that
226      * is the normal OS behaviour for frames on that platform. Helptext
227      * for menu items and toolbar tools will automatically get displayed
228      * here. */
229     statusbar = CreateStatusBar(2);
230     int i_status_width[2] = {-2,-3};
231     statusbar->SetStatusWidths( 2, i_status_width );
232
233     SetTitle( COPYRIGHT_MESSAGE );
234     SetAutoLayout( TRUE );
235     Layout();
236 }
237
238 Interface::~Interface()
239 {
240 }
241
242 /*****************************************************************************
243  * Private methods.
244  *****************************************************************************/
245 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
246 {
247     /* TRUE is to force the frame to close. */
248     Close(TRUE);
249 }
250
251 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
252 {
253     wxString msg;
254     msg.Printf( _("This is the about dialog of the VideoLAN Client.\n") );
255
256     wxMessageBox( msg, "About VideoLAN Client",
257                   wxOK | wxICON_INFORMATION, this );
258 }
259
260 void Interface::OnOpenFile( wxCommandEvent& WXUNUSED(event) )
261 {
262     wxFileDialog dialog( this, _("Open file"), _(""), _(""),
263                          _("*.*") );
264
265     if( dialog.ShowModal() == wxID_OK )
266     {
267         /* Update the playlist */
268         playlist_t *p_playlist =
269             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
270                                            FIND_ANYWHERE );
271         if( p_playlist == NULL )
272         {
273             return;
274         }
275
276         playlist_Add( p_playlist, (char *)dialog.GetPath().c_str(),
277                       PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
278
279         vlc_object_release( p_playlist );
280     }
281 }
282
283 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
284 {
285     wxCommandEvent dummy;
286     playlist_t *p_playlist =
287         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
288                                        FIND_ANYWHERE );
289     if( p_playlist == NULL )
290     {
291         OnOpenFile( dummy );
292         return;
293     }
294
295     /* If the playlist is empty, open a file requester instead */
296     vlc_mutex_lock( &p_playlist->object_lock );
297     if( p_playlist->i_size )
298     {
299         vlc_mutex_unlock( &p_playlist->object_lock );
300         playlist_Play( p_playlist );
301         vlc_object_release( p_playlist );
302     }
303     else
304     {
305         vlc_mutex_unlock( &p_playlist->object_lock );
306         vlc_object_release( p_playlist );
307         OnOpenFile( dummy );
308     }
309 }
310
311 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
312 {
313     playlist_t * p_playlist =
314         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
315                                        FIND_ANYWHERE );
316     if( p_playlist == NULL )
317     {
318         return;
319     }
320
321     playlist_Stop( p_playlist );
322     vlc_object_release( p_playlist );
323 }
324
325 void Interface::OnPauseStream( wxCommandEvent& WXUNUSED(event) )
326 {
327     if( p_intf->p_sys->p_input == NULL )
328     {
329         return;
330     }
331
332     input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
333 }
334
335 void Interface::OnSliderUpdate( wxScrollEvent& event )
336 {
337     p_intf->p_sys->i_slider_pos = event.GetPosition();
338 }
339
340 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
341 {
342     playlist_t * p_playlist =
343         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
344                                        FIND_ANYWHERE );
345     if( p_playlist == NULL )
346     {
347         return;
348     }
349
350     playlist_Prev( p_playlist );
351     vlc_object_release( p_playlist );
352 }
353
354 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
355 {
356     playlist_t * p_playlist =
357         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
358                                        FIND_ANYWHERE );
359     if( p_playlist == NULL )
360     {
361         return;
362     }
363
364     playlist_Next( p_playlist );
365     vlc_object_release( p_playlist );
366 }