]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/interface.cpp
first shot at a file info dialog for the wxwindows interface. It still
[vlc] / 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.12 2002/12/21 11:20:30 sigmunau 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 /* include the toolbar graphics */
50 #include "bitmaps/file.xpm"
51 #include "bitmaps/disc.xpm"
52 #include "bitmaps/net.xpm"
53 #if 0
54 #include "bitmaps/sat.xpm"
55 #endif
56 #include "bitmaps/play.xpm"
57 #include "bitmaps/pause.xpm"
58 #include "bitmaps/stop.xpm"
59 #include "bitmaps/previous.xpm"
60 #include "bitmaps/next.xpm"
61 #include "bitmaps/playlist.xpm"
62 #define TOOLBAR_BMP_WIDTH 24
63 #define TOOLBAR_BMP_HEIGHT 24
64
65 /* include the icon graphic */
66 #include "share/vlc32x32.xpm"
67
68 /*****************************************************************************
69  * Local class declarations.
70  *****************************************************************************/
71
72 /*****************************************************************************
73  * Event Table.
74  *****************************************************************************/
75
76 /* IDs for the controls and the menu commands */
77 enum
78 {
79     /* menu items */
80     Exit_Event = 1,
81     OpenFile_Event,
82     OpenDisc_Event,
83     OpenNet_Event,
84     OpenSat_Event,
85     EjectDisc_Event,
86
87     Playlist_Event,
88     Logs_Event,
89     FileInfo_Event,
90
91     Audio_Event,
92     Subtitles_Event,
93     Prefs_Event,
94
95     SliderScroll_Event,
96     StopStream_Event,
97     PlayStream_Event,
98     PauseStream_Event,
99     PrevStream_Event,
100     NextStream_Event,
101
102     /* it is important for the id corresponding to the "About" command to have
103      * this standard value as otherwise it won't be handled properly under Mac
104      * (where it is special and put into the "Apple" menu) */
105     About_Event = wxID_ABOUT
106 };
107
108 BEGIN_EVENT_TABLE(Interface, wxFrame)
109     /* Menu events */
110     EVT_MENU(Exit_Event, Interface::OnExit)
111     EVT_MENU(About_Event, Interface::OnAbout)
112     EVT_MENU(Playlist_Event, Interface::OnPlaylist)
113     EVT_MENU(Logs_Event, Interface::OnLogs)
114     EVT_MENU(FileInfo_Event, Interface::OnFileInfo)
115     EVT_MENU(OpenFile_Event, Interface::OnOpenFile)
116     /* Toolbar events */
117     EVT_MENU(OpenFile_Event, Interface::OnOpenFile)
118     EVT_MENU(StopStream_Event, Interface::OnStopStream)
119     EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
120     EVT_MENU(PauseStream_Event, Interface::OnPauseStream)
121     EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
122     EVT_MENU(NextStream_Event, Interface::OnNextStream)
123     /* Slider events */
124     EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
125 END_EVENT_TABLE()
126
127 /*****************************************************************************
128  * Constructor.
129  *****************************************************************************/
130 Interface::Interface( intf_thread_t *_p_intf ):
131     wxFrame( NULL, -1, "title", wxDefaultPosition, wxDefaultSize,
132              wxDEFAULT_FRAME_STYLE )
133 {
134     /* Initializations */
135     p_intf = _p_intf;
136
137     /* Give our interface a nice little icon */
138     SetIcon( *new wxIcon( vlc_xpm ) );
139
140     /* Create a sizer for the main frame */
141     frame_sizer = new wxBoxSizer( wxHORIZONTAL );
142     SetSizer( frame_sizer );
143
144     /* Creation of the menu bar */
145     CreateOurMenuBar();
146
147     /* Creation of the tool bar */
148     CreateOurToolBar();
149
150     /* Creation of the slider sub-window */
151     CreateOurSlider();
152
153     /* Creation of the status bar
154      * Helptext for menu items and toolbar tools will automatically get
155      * displayed here. */
156     int i_status_width[2] = {-2,-3};
157     statusbar = CreateStatusBar( 2 );                            /* 2 fields */
158     statusbar->SetStatusWidths( 2, i_status_width );
159
160     SetTitle( COPYRIGHT_MESSAGE );
161
162     /* Make sure we've got the right background colour */
163     SetBackgroundColour( slider_frame->GetBackgroundColour() );
164
165     /* Layout everything */
166     SetAutoLayout( TRUE );
167     frame_sizer->Layout();
168     frame_sizer->Fit(this);
169
170 #if !defined(__WXX11__)
171     /* Associate drop targets with the main interface */
172     SetDropTarget( new DragAndDrop( p_intf ) );
173 #endif
174 }
175
176 Interface::~Interface()
177 {
178 }
179
180 /*****************************************************************************
181  * Private methods.
182  *****************************************************************************/
183 void Interface::CreateOurMenuBar()
184 {
185 #define HELP_FILE  N_("Open a file")
186 #define HELP_DISC  N_("Open a DVD or (S)VCD")
187 #define HELP_NET   N_("Open a network stream")
188 #define HELP_SAT   N_("Open a satellite stream")
189 #define HELP_EJECT N_("Eject the DVD/CD")
190 #define HELP_EXIT  N_("Exit this program")
191
192 #define HELP_PLAYLIST   N_("Open the playlist")
193 #define HELP_LOGS       N_("Show the program logs")
194 #define HELP_FILEINFO       N_("Show information about the file being played")
195
196 #define HELP_AUDIO N_("Change the current audio track")
197 #define HELP_SUBS  N_("Change the current subtitles stream")
198 #define HELP_PREFS N_("Go to the preferences menu")
199
200 #define HELP_ABOUT N_("About this program")
201
202     /* Create the "File" menu */
203     wxMenu *file_menu = new wxMenu;
204     file_menu->Append( OpenFile_Event, _("&Open File..."), HELP_FILE );
205     file_menu->Append( OpenDisc_Event, _("Open &Disc..."), HELP_DISC );
206     file_menu->Append( OpenNet_Event, _("&Network Stream..."), HELP_NET );
207 #if 0
208     file_menu->Append( OpenSat_Event, _("&Satellite Stream..."), HELP_NET );
209 #endif
210     file_menu->AppendSeparator();
211     file_menu->Append( EjectDisc_Event, _("&Eject Disc"), HELP_EJECT );
212     file_menu->AppendSeparator();
213     file_menu->Append( Exit_Event, _("E&xit"), HELP_EXIT );
214
215     /* Create the "View" menu */
216     wxMenu *view_menu = new wxMenu;
217     view_menu->Append( Playlist_Event, _("&Playlist..."), HELP_PLAYLIST );
218     view_menu->Append( Logs_Event, _("&Logs..."), HELP_LOGS );
219     view_menu->Append( FileInfo_Event, _("&File info..."), HELP_FILEINFO );
220
221     /* Create the "Settings" menu */
222     wxMenu *settings_menu = new wxMenu;
223     settings_menu->Append( Audio_Event, _("&Audio"), HELP_AUDIO );
224     settings_menu->Append( Subtitles_Event, _("&Subtitles"), HELP_SUBS );
225     settings_menu->AppendSeparator();
226     settings_menu->Append( Prefs_Event, _("&Preferences..."), HELP_PREFS );
227
228     /* Create the "Help" menu */
229     wxMenu *help_menu = new wxMenu;
230     help_menu->Append( About_Event, _("&About..."), HELP_ABOUT );
231
232     /* Append the freshly created menus to the menu bar... */
233     wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
234     menubar->Append( file_menu, _("&File") );
235     menubar->Append( view_menu, _("&View") );
236     menubar->Append( settings_menu, _("&Settings") );
237     menubar->Append( help_menu, _("&Help") );
238
239     /* Attach the menu bar to the frame */
240     SetMenuBar( menubar );
241
242 #if !defined(__WXX11__)
243     /* Associate drop targets with the menubar */
244     menubar->SetDropTarget( new DragAndDrop( p_intf ) );
245 #endif
246 }
247
248 void Interface::CreateOurToolBar()
249 {
250 #define HELP_STOP N_("Stop current playlist item")
251 #define HELP_PLAY N_("Play current playlist item")
252 #define HELP_PAUSE N_("Pause current playlist item")
253 #define HELP_PLO N_("Open playlist")
254 #define HELP_PLP N_("Previous playlist item")
255 #define HELP_PLN N_("Next playlist item")
256
257     wxBitmap *p_bmp_file     = new wxBitmap( file_xpm );
258     wxBitmap *p_bmp_disc     = new wxBitmap( disc_xpm );
259     wxBitmap *p_bmp_net      = new wxBitmap( net_xpm );
260     wxBitmap *p_bmp_play     = new wxBitmap( play_xpm );
261     wxBitmap *p_bmp_stop     = new wxBitmap( stop_xpm );
262     wxBitmap *p_bmp_pause    = new wxBitmap( pause_xpm );
263     wxBitmap *p_bmp_prev     = new wxBitmap( previous_xpm );
264     wxBitmap *p_bmp_next     = new wxBitmap( next_xpm );
265     wxBitmap *p_bmp_playlist = new wxBitmap( playlist_xpm );
266
267     wxToolBar *toolbar = CreateToolBar(
268         wxTB_HORIZONTAL | wxTB_TEXT | wxTB_FLAT | wxTB_DOCKABLE );
269
270     toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
271
272     toolbar->AddTool( OpenFile_Event, _("File"), *p_bmp_file, HELP_FILE );
273     toolbar->AddTool( OpenFile_Event, _("Disc"), *p_bmp_disc, HELP_DISC );
274     toolbar->AddTool( OpenFile_Event, _("Net"), *p_bmp_net, HELP_NET );
275 #if 0
276     toolbar->AddTool( OpenFile_Event, _("Sat"), *p_bmp_net, HELP_SAT );
277 #endif
278     toolbar->AddSeparator();
279     toolbar->AddTool( StopStream_Event, _("Stop"), *p_bmp_stop, HELP_STOP );
280     toolbar->AddTool( PlayStream_Event, _("Play"), *p_bmp_play, HELP_PLAY );
281     toolbar->AddTool( PauseStream_Event, _("Pause"), *p_bmp_pause, HELP_PAUSE);
282     toolbar->AddSeparator();
283     toolbar->AddTool( Playlist_Event, _("Playlist"), *p_bmp_playlist,
284                       HELP_PLO );
285     toolbar->AddTool( PrevStream_Event, _("Prev"), *p_bmp_prev, HELP_PLP );
286     toolbar->AddTool( NextStream_Event, _("Next"), *p_bmp_next, HELP_PLN );
287
288     toolbar->Realize();
289
290     /* Place the toolbar in a sizer, so we can calculate the width of the
291      * toolbar and set this as the minimum for the main frame size. */
292     wxBoxSizer *toolbar_sizer = new wxBoxSizer( wxHORIZONTAL );
293     toolbar_sizer->Add( toolbar, 0, 0, 0 );
294     toolbar_sizer->Layout();
295     frame_sizer->SetMinSize( toolbar_sizer->GetMinSize().GetWidth(), -1 );
296
297 #if !defined(__WXX11__)
298     /* Associate drop targets with the toolbar */
299     toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
300 #endif
301 }
302
303 void Interface::CreateOurSlider()
304 {
305     /* Create a new frame containing the slider */
306     slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
307     slider_frame->SetAutoLayout( TRUE );
308     slider_frame->Hide();
309
310     /* Create static box to surround the slider */
311     slider_box = new wxStaticBox( slider_frame, -1, "" );
312
313     /* Create sizer for slider frame */
314     wxStaticBoxSizer *slider_sizer =
315         new wxStaticBoxSizer( slider_box, wxHORIZONTAL );
316     slider_frame->SetSizer( slider_sizer );
317     slider_sizer->SetMinSize( -1, 50 );
318
319     /* Create slider */
320     slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
321                            SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
322     slider_sizer->Add( slider, 1, wxGROW | wxALL, 5 );
323     slider_sizer->Layout();
324     slider_sizer->SetSizeHints(slider_frame);
325 }
326
327 /*****************************************************************************
328  * Event Handlers.
329  *****************************************************************************/
330 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
331 {
332     /* TRUE is to force the frame to close. */
333     Close(TRUE);
334 }
335
336 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
337 {
338     wxString msg;
339     msg.Printf( _("This is the about dialog of the VideoLAN Client.\n") );
340
341     wxMessageBox( msg, _("About VideoLAN Client"),
342                   wxOK | wxICON_INFORMATION, this );
343 }
344
345 void Interface::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
346 {
347     /* Show/hide the playlist window */
348     wxFrame *p_playlist_window = p_intf->p_sys->p_playlist_window;
349     if( p_playlist_window )
350     {
351         p_playlist_window->Show( ! p_playlist_window->IsShown() );
352     }
353 }
354
355 void Interface::OnLogs( wxCommandEvent& WXUNUSED(event) )
356 {
357     /* Show/hide the log window */
358     wxFrame *p_messages_window = p_intf->p_sys->p_messages_window;
359     if( p_messages_window )
360     {
361         p_messages_window->Show( ! p_messages_window->IsShown() );
362     }
363 }
364
365 void Interface::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
366 {
367     /* Show/hide the fileinfo window */
368     wxFrame *p_fileinfo_window = new FileInfo( p_intf, this );
369     if( p_fileinfo_window )
370     {
371         p_fileinfo_window->Show( true );//! p_messages_window->IsShown() );
372     }
373 }
374
375 void Interface::OnOpenFile( wxCommandEvent& WXUNUSED(event) )
376 {
377     wxFileDialog dialog( this, _("Open file"), _(""), _(""), _("*.*") );
378
379     if( dialog.ShowModal() == wxID_OK )
380     {
381         /* Update the playlist */
382         playlist_t *p_playlist =
383             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
384                                            FIND_ANYWHERE );
385         if( p_playlist == NULL )
386         {
387             return;
388         }
389
390         playlist_Add( p_playlist, (char *)dialog.GetPath().c_str(),
391                       PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
392
393         /* Rebuild the playlist */
394         p_intf->p_sys->p_playlist_window->Rebuild();
395
396         vlc_object_release( p_playlist );
397     }
398 }
399
400 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
401 {
402     wxCommandEvent dummy;
403     playlist_t *p_playlist =
404         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
405                                        FIND_ANYWHERE );
406     if( p_playlist == NULL )
407     {
408         OnOpenFile( dummy );
409         return;
410     }
411
412     /* If the playlist is empty, open a file requester instead */
413     vlc_mutex_lock( &p_playlist->object_lock );
414     if( p_playlist->i_size )
415     {
416         vlc_mutex_unlock( &p_playlist->object_lock );
417         playlist_Play( p_playlist );
418         vlc_object_release( p_playlist );
419     }
420     else
421     {
422         vlc_mutex_unlock( &p_playlist->object_lock );
423         vlc_object_release( p_playlist );
424         OnOpenFile( dummy );
425     }
426 }
427
428 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
429 {
430     playlist_t * p_playlist =
431         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
432                                        FIND_ANYWHERE );
433     if( p_playlist == NULL )
434     {
435         return;
436     }
437
438     playlist_Stop( p_playlist );
439     vlc_object_release( p_playlist );
440 }
441
442 void Interface::OnPauseStream( wxCommandEvent& WXUNUSED(event) )
443 {
444     if( p_intf->p_sys->p_input == NULL )
445     {
446         return;
447     }
448
449     input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
450 }
451
452 void Interface::OnSliderUpdate( wxScrollEvent& event )
453 {
454     p_intf->p_sys->i_slider_pos = event.GetPosition();
455 }
456
457 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
458 {
459     playlist_t * p_playlist =
460         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
461                                        FIND_ANYWHERE );
462     if( p_playlist == NULL )
463     {
464         return;
465     }
466
467     playlist_Prev( p_playlist );
468     vlc_object_release( p_playlist );
469 }
470
471 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
472 {
473     playlist_t * p_playlist =
474         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
475                                        FIND_ANYWHERE );
476     if( p_playlist == NULL )
477     {
478         return;
479     }
480
481     playlist_Next( p_playlist );
482     vlc_object_release( p_playlist );
483 }
484
485 #if !defined(__WXX11__)
486 /*****************************************************************************
487  * Definition of DragAndDrop class.
488  *****************************************************************************/
489 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
490 {
491     p_intf = _p_intf;
492 }
493
494 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
495                                const wxArrayString& filenames )
496 {
497     unsigned int i;
498
499     /* Add dropped files to the playlist */
500
501     playlist_t *p_playlist =
502         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
503                                        FIND_ANYWHERE );
504     if( p_playlist == NULL )
505     {
506         return FALSE;
507     }
508
509     for( i = 0; i < filenames.GetCount(); i++ )
510         playlist_Add( p_playlist, (char *)filenames[i].c_str(),
511                       PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
512
513     /* Rebuild the playlist */
514     p_intf->p_sys->p_playlist_window->Rebuild();
515
516     vlc_object_release( p_playlist );
517
518     return TRUE;
519 }
520 #endif