]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/interface.cpp
revert previous commit
[vlc] / modules / gui / wxwidgets / interface.cpp
1 /*****************************************************************************
2  * interface.cpp : wxWidgets plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
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 "interface.hpp"
28 #include "extrapanel.hpp"
29 #include "timer.hpp"
30 #include "video.hpp"
31 #include <vlc_keys.h>
32
33 #include "charset.h"
34
35 #include <vlc/aout.h>
36 #include "charset.h"
37
38 /* include the toolbar graphics */
39 #include "bitmaps/play.xpm"
40 #include "bitmaps/pause.xpm"
41 #include "bitmaps/stop.xpm"
42 #include "bitmaps/prev.xpm"
43 #include "bitmaps/next.xpm"
44 #include "bitmaps/eject.xpm"
45 #include "bitmaps/slow.xpm"
46 #include "bitmaps/fast.xpm"
47 #include "bitmaps/playlist.xpm"
48 #include "bitmaps/speaker.xpm"
49 #include "bitmaps/speaker_mute.xpm"
50
51 #define TOOLBAR_BMP_WIDTH 16
52 #define TOOLBAR_BMP_HEIGHT 16
53
54 /* include the icon graphic */
55 #include "../../../share/vlc32x32.xpm"
56 /* include a small icon graphic for the systray icon */
57 #ifdef wxHAS_TASK_BAR_ICON
58 #include "../../../share/vlc16x16.xpm"
59 #endif
60
61 /*****************************************************************************
62  * Local class declarations.
63  *****************************************************************************/
64 class wxMenuExt: public wxMenu
65 {
66 public:
67     /* Constructor */
68     wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
69                    const wxString& helpString, wxItemKind kind,
70                    char *_psz_var, int _i_object_id, vlc_value_t _val,
71                    int _i_val_type );
72
73     virtual ~wxMenuExt() {};
74
75     char *psz_var;
76     int  i_val_type;
77     int  i_object_id;
78     vlc_value_t val;
79
80 private:
81
82 };
83
84 class wxVolCtrl;
85 class VLCVolCtrl : public wxControl
86 {
87 public:
88     VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
89     virtual ~VLCVolCtrl() {};
90
91     virtual void OnPaint( wxPaintEvent &event );
92     void OnChange( wxMouseEvent& event );
93     void UpdateVolume();
94
95   private:
96     DECLARE_EVENT_TABLE()
97
98     wxVolCtrl *gauge;
99     int i_y_offset;
100     vlc_bool_t b_mute;
101     intf_thread_t *p_intf;
102 };
103
104 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
105    EVT_PAINT(VLCVolCtrl::OnPaint)
106
107     /* Mouse events */
108     EVT_LEFT_UP(VLCVolCtrl::OnChange)
109 END_EVENT_TABLE()
110
111 /*****************************************************************************
112  * Event Table.
113  *****************************************************************************/
114
115 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
116
117 /* IDs for the controls and the menu commands */
118 enum
119 {
120     /* menu items */
121     MenuDummy_Event = wxID_HIGHEST + 1000,
122     Exit_Event = wxID_HIGHEST,
123     OpenFileSimple_Event,
124     OpenAdv_Event,
125     OpenFile_Event,
126     OpenDir_Event,
127     OpenDisc_Event,
128     OpenNet_Event,
129     OpenCapture_Event,
130     OpenSat_Event,
131     OpenOther_Event,
132     EjectDisc_Event,
133
134     Wizard_Event,
135
136     Playlist_Event,
137     Logs_Event,
138     FileInfo_Event,
139
140     Prefs_Event,
141     Extended_Event,
142 //    Undock_Event,
143     Bookmarks_Event,
144     Skins_Event,
145
146     SliderScroll_Event,
147     StopStream_Event,
148     PlayStream_Event,
149     PrevStream_Event,
150     NextStream_Event,
151     SlowStream_Event,
152     FastStream_Event,
153
154     DiscMenu_Event,
155     DiscPrev_Event,
156     DiscNext_Event,
157
158     /* it is important for the id corresponding to the "About" command to have
159      * this standard value as otherwise it won't be handled properly under Mac
160      * (where it is special and put into the "Apple" menu) */
161     About_Event = wxID_ABOUT,
162     UpdateVLC_Event,
163     VLM_Event,
164
165     Iconize_Event
166 };
167
168 BEGIN_EVENT_TABLE(Interface, wxFrame)
169     /* Menu events */
170     EVT_MENU(Exit_Event, Interface::OnExit)
171     EVT_MENU(About_Event, Interface::OnAbout)
172     EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
173     EVT_MENU(VLM_Event, Interface::OnShowDialog)
174
175     EVT_MENU(Playlist_Event, Interface::OnShowDialog)
176     EVT_MENU(Logs_Event, Interface::OnShowDialog)
177     EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
178     EVT_MENU(Prefs_Event, Interface::OnShowDialog)
179
180     EVT_MENU_OPEN(Interface::OnMenuOpen)
181
182     EVT_MENU( Extended_Event, Interface::OnExtended )
183 //    EVT_MENU( Undock_Event, Interface::OnUndock )
184
185     EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
186
187 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
188     EVT_CONTEXT_MENU(Interface::OnContextMenu2)
189 #endif
190     EVT_RIGHT_UP(Interface::OnContextMenu)
191
192     /* Toolbar events */
193     EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
194     EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
195     EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
196     EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
197     EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
198     EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
199     EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
200     EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
201     EVT_MENU(Wizard_Event, Interface::OnShowDialog)
202     EVT_MENU(StopStream_Event, Interface::OnStopStream)
203     EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
204     EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
205     EVT_MENU(NextStream_Event, Interface::OnNextStream)
206     EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
207     EVT_MENU(FastStream_Event, Interface::OnFastStream)
208
209     /* Disc Buttons events */
210     EVT_BUTTON(DiscMenu_Event, Interface::OnDiscMenu)
211     EVT_BUTTON(DiscPrev_Event, Interface::OnDiscPrev)
212     EVT_BUTTON(DiscNext_Event, Interface::OnDiscNext)
213
214     /* Slider events */
215     EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
216
217     /* Custom events */
218     EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
219     EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
220
221     EVT_TIMER(ID_CONTROLS_TIMER, Interface::OnControlsTimer)
222     EVT_TIMER(ID_SLIDER_TIMER, Interface::OnSliderTimer)
223 END_EVENT_TABLE()
224
225 /*****************************************************************************
226  * Constructor.
227  *****************************************************************************/
228 Interface::Interface( intf_thread_t *_p_intf, long style ):
229     wxFrame( NULL, -1, wxT("VLC media player"),
230              wxDefaultPosition, wxSize(700,100), style )
231 {
232     /* Initializations */
233     p_intf = _p_intf;
234     i_old_playing_status = PAUSE_S;
235     b_extra = VLC_FALSE;
236 //    b_undock = VLC_FALSE;
237
238
239     extra_window = NULL;
240
241     /* Give our interface a nice little icon */
242     SetIcon( wxIcon( vlc_xpm ) );
243
244     /* Create a sizer for the main frame */
245     frame_sizer = new wxBoxSizer( wxVERTICAL );
246     SetSizer( frame_sizer );
247
248     /* Create a dummy widget that can get the keyboard focus */
249     wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
250                                       wxSize(0,0) );
251 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
252     /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
253      * Accelerators bug. */
254     p_dummy->m_imData = 0;
255     m_imData = 0;
256 #endif
257     p_dummy->SetFocus();
258     frame_sizer->Add( p_dummy, 0, 0 );
259
260 #ifdef wxHAS_TASK_BAR_ICON
261     /* Systray integration */
262     p_systray = NULL;
263     if ( config_GetInt( p_intf, "wx-systray" ) )
264     {
265         p_systray = new Systray(this, p_intf);
266         p_systray->SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
267         if ( (! p_systray->IsOk()) || (! p_systray->IsIconInstalled()) )
268         {
269             msg_Warn(p_intf, "Cannot set systray icon, weird things may happen");
270         }
271     }
272 #endif
273
274     /* Creation of the menu bar */
275     CreateOurMenuBar();
276
277     /* Creation of the tool bar */
278     CreateOurToolBar();
279
280     /* Create the extra panel */
281     extra_frame = new ExtraPanel( p_intf, this );
282     frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
283     frame_sizer->Hide( extra_frame );
284
285     /* Creation of the status bar
286      * Helptext for menu items and toolbar tools will automatically get
287      * displayed here. */
288     int i_status_width[3] = {-6, -2, -9};
289     statusbar = CreateStatusBar( 3 );                            /* 2 fields */
290     statusbar->SetStatusWidths( 3, i_status_width );
291     statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
292
293     /* Video window */
294     video_window = 0;
295     if( config_GetInt( p_intf, "wx-embed" ) )
296     {
297         video_window = CreateVideoWindow( p_intf, this );
298         frame_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
299     }
300
301     /* Creation of the slider sub-window */
302     CreateOurSlider();
303     frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
304     frame_sizer->Hide( slider_frame );
305
306     /* Make sure we've got the right background colour */
307     SetBackgroundColour( slider_frame->GetBackgroundColour() );
308
309     /* Layout everything */
310     frame_sizer->Layout();
311     frame_sizer->Fit(this);
312
313 #if wxUSE_DRAG_AND_DROP
314     /* Associate drop targets with the main interface */
315     SetDropTarget( new DragAndDrop( p_intf ) );
316 #endif
317
318     SetupHotkeys();
319
320     m_controls_timer.SetOwner(this, ID_CONTROLS_TIMER);
321     m_slider_timer.SetOwner(this, ID_SLIDER_TIMER);
322
323     /* Start timer */
324     timer = new Timer( p_intf, this );
325
326     /* */
327     WindowSettings *ws = p_intf->p_sys->p_window_settings;
328     wxPoint p;
329     wxSize  s;
330     bool    b_shown;
331
332     ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
333                    wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
334
335     if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) )
336         Move( p );
337
338     /* Set minimum window size to prevent user from glitching it */
339     wxSize  s2;
340     s = GetSize();
341
342     /* save smallest possible default minimum size */
343     default_size = GetSize();
344
345     /* save slider size for height only for MinSizing */
346     slider_size = slider_sizer->GetSize();
347
348     /* and save extended gui size for MinSize scheme */
349     s2 = extra_frame->GetSize();
350     s2.SetWidth( s2.GetWidth() +
351                 2 * wxSystemSettings::GetMetric( wxSYS_FRAMESIZE_X ) );
352     extended_size = s2;
353
354     /* Set initial minimum window size */
355     if( config_GetInt( p_intf, "wx-embed" ) )
356     {
357         s2 = video_window->GetSize();
358         s.SetHeight( s.GetHeight() - s2.GetHeight() );
359     }
360     if( config_GetInt( p_intf, "wx-extended" ) )
361     {
362         s.SetWidth( extended_size.GetWidth() );
363         s.SetHeight( s.GetHeight() + extended_size.GetHeight() );
364     }
365 #if (wxCHECK_VERSION(2,5,4))
366     SetMinSize( s );
367 #else
368     frame_sizer->SetMinSize( s );
369 #endif
370
371     /* Show extended GUI if requested */
372     if( ( b_extra = config_GetInt( p_intf, "wx-extended" ) ) )
373         frame_sizer->Show( extra_frame );
374 }
375
376 Interface::~Interface()
377 {
378     WindowSettings *ws = p_intf->p_sys->p_window_settings;
379
380     if( !IsIconized() )
381     {
382         ws->SetSettings( WindowSettings::ID_MAIN, true,
383                          GetPosition(), GetSize() );
384     }
385
386     PopEventHandler(true);
387
388     if( video_window ) delete video_window;
389
390 #ifdef wxHAS_TASK_BAR_ICON
391     if( p_systray ) delete p_systray;
392 #endif
393
394     if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
395
396     /* Clean up */
397     delete timer;
398 }
399
400 void Interface::Init()
401 {
402     /* Misc init */
403     SetupHotkeys();
404 }
405
406 void Interface::Update()
407 {
408     /* Misc updates */
409     ((VLCVolCtrl *)volctrl)->UpdateVolume();
410 }
411
412 void Interface::OnControlEvent( wxCommandEvent& event )
413 {
414     switch( event.GetId() )
415     {
416     case 0:
417         {
418           if( p_intf->p_sys->b_video_autosize )
419           {
420         frame_sizer->Layout();
421         frame_sizer->Fit(this);
422           }
423         }
424         break;
425
426     case 1:
427         long i_style = GetWindowStyle();
428         if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
429         else i_style &= ~wxSTAY_ON_TOP;
430         SetWindowStyle( i_style );
431         break;
432     }
433 }
434
435 /*****************************************************************************
436  * Private methods.
437  *****************************************************************************/
438 void Interface::CreateOurMenuBar()
439 {
440     int minimal = config_GetInt( p_intf, "wx-minimal" );
441
442     /* Create the "File" menu */
443     wxMenu *file_menu = new wxMenu;
444
445     if (!minimal)
446     {
447     file_menu->Append( OpenFileSimple_Event,
448                        wxU(_("Quick &Open File...\tCtrl-O")) );
449
450     file_menu->AppendSeparator();
451     file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
452     file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
453     file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
454     file_menu->Append( OpenNet_Event,
455                        wxU(_("Open &Network Stream...\tCtrl-N")) );
456     file_menu->Append( OpenCapture_Event,
457                        wxU(_("Open C&apture Device...\tCtrl-A")) );
458
459     file_menu->AppendSeparator();
460     file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
461     file_menu->AppendSeparator();
462     }
463     file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
464
465     /* Create the "View" menu */
466     wxMenu *view_menu = new wxMenu;
467     if (!minimal)
468     {
469     view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
470     }
471     view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
472     view_menu->Append( FileInfo_Event,
473                        wxU(_("Stream and Media &info...\tCtrl-I")) );
474     view_menu->Append( VLM_Event,
475                        wxU(_("VLM Control...\tCtrl-I")) );
476
477     /* Create the "Auto-generated" menus */
478     p_settings_menu = SettingsMenu( p_intf, this );
479     p_audio_menu = AudioMenu( p_intf, this );
480     p_video_menu = VideoMenu( p_intf, this );
481     p_navig_menu = NavigMenu( p_intf, this );
482
483     /* Create the "Help" menu */
484     wxMenu *help_menu = new wxMenu;
485     help_menu->Append( About_Event, wxU(_("About VLC media player")) );
486     help_menu->AppendSeparator();
487     help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
488
489     /* Append the freshly created menus to the menu bar... */
490     wxMenuBar *menubar = new wxMenuBar();
491     menubar->Append( file_menu, wxU(_("&File")) );
492     menubar->Append( view_menu, wxU(_("&View")) );
493     menubar->Append( p_settings_menu, wxU(_("&Settings")) );
494     menubar->Append( p_audio_menu, wxU(_("&Audio")) );
495     menubar->Append( p_video_menu, wxU(_("&Video")) );
496     menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
497     menubar->Append( help_menu, wxU(_("&Help")) );
498
499     /* Attach the menu bar to the frame */
500     SetMenuBar( menubar );
501
502     /* Find out size of menu bar */
503     int i_size = 0;
504     for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
505     {
506         int i_width, i_height;
507         menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
508         i_size += i_width +
509 #if defined(__WXGTK__)
510             22 /* approximate margin */;
511 #else
512 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
513             4 /* approximate margin */;
514 #else
515             18 /* approximate margin */;
516 #endif
517 #endif
518     }
519
520 /* Patch by zcot for menu wrapping */
521 #if defined(WIN32)
522     /* Find out size of msw menu bar */
523     i_size = 0;
524     SIZE sizing;
525     HDC hdc = GetDC( NULL );
526     for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
527     {
528         GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
529                                 menubar->GetLabelTop(i).Length(), &sizing );
530
531         // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
532         i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
533     }
534     ReleaseDC( NULL, hdc );
535     i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
536 #endif
537 /* End patch by zcot */
538
539     frame_sizer->SetMinSize( i_size, -1 );
540
541     /* Intercept all menu events in our custom event handler */
542     PushEventHandler( new MenuEvtHandler( p_intf, this ) );
543
544 #if wxUSE_DRAG_AND_DROP
545     /* Associate drop targets with the menubar */
546     menubar->SetDropTarget( new DragAndDrop( p_intf ) );
547 #endif
548 }
549
550 void Interface::CreateOurToolBar()
551 {
552 #define HELP_OPEN N_("Open")
553 #define HELP_STOP N_("Stop")
554 #define HELP_PLAY N_("Play")
555 #define HELP_PAUSE N_("Pause")
556 #define HELP_PLO N_("Playlist")
557 #define HELP_PLP N_("Previous playlist item")
558 #define HELP_PLN N_("Next playlist item")
559 #define HELP_SLOW N_("Play slower")
560 #define HELP_FAST N_("Play faster")
561
562     int minimal = config_GetInt( p_intf, "wx-minimal" );
563
564     wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
565                          * version because we don't include wx.rc */
566
567     wxToolBar *toolbar =
568         CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
569
570     toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
571
572     if (!minimal)
573     {
574     toolbar->AddTool( OpenFile_Event, wxT(""),
575                       wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
576     toolbar->AddSeparator();
577     }
578
579     wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
580                       wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
581     p_tool->SetClientData( p_tool );
582
583     if (!minimal)
584     {
585     toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
586                       wxU(_(HELP_STOP)) );
587     toolbar->AddSeparator();
588
589     toolbar->AddTool( PrevStream_Event, wxT(""),
590                       wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
591     toolbar->AddTool( SlowStream_Event, wxT(""),
592                       wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
593     toolbar->AddTool( FastStream_Event, wxT(""),
594                       wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
595     toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
596                       wxU(_(HELP_PLN)) );
597     toolbar->AddSeparator();
598     toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
599                       wxU(_(HELP_PLO)) );
600     }
601
602 #if !( (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 6) && (wxRELEASE_NUMBER < 2) )
603     wxControl *p_dummy_ctrl =
604         new wxControl( toolbar, -1, wxDefaultPosition,
605                        wxSize(35, 16 ), wxBORDER_NONE );
606
607     toolbar->AddControl( p_dummy_ctrl );
608 #endif
609
610     volctrl = new VLCVolCtrl( p_intf, toolbar );
611     toolbar->AddControl( volctrl );
612
613     toolbar->Realize();
614
615 #if wxUSE_DRAG_AND_DROP
616     /* Associate drop targets with the toolbar */
617     toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
618 #endif
619 }
620
621 void Interface::CreateOurSlider()
622 {
623     /* Create a new frame and sizer containing the slider */
624     slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
625     slider_frame->SetAutoLayout( TRUE );
626     slider_sizer = new wxBoxSizer( wxHORIZONTAL );
627     //slider_sizer->SetMinSize( -1, 50 );
628
629     /* Create slider */
630     slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
631                            SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
632
633     /* Add Disc Buttons */
634     disc_frame = new wxPanel( slider_frame, -1, wxDefaultPosition,
635                               wxDefaultSize );
636     disc_frame->SetAutoLayout( TRUE );
637     disc_sizer = new wxBoxSizer( wxHORIZONTAL );
638
639     disc_menu_button = new wxBitmapButton( disc_frame, DiscMenu_Event,
640                                            wxBitmap( playlist_xpm ) );
641     disc_prev_button = new wxBitmapButton( disc_frame, DiscPrev_Event,
642                                            wxBitmap( prev_xpm ) );
643     disc_next_button = new wxBitmapButton( disc_frame, DiscNext_Event,
644                                            wxBitmap( next_xpm ) );
645
646     disc_sizer->Add( disc_menu_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
647     disc_sizer->Add( disc_prev_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
648     disc_sizer->Add( disc_next_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
649
650     disc_frame->SetSizer( disc_sizer );
651     disc_sizer->Layout();
652
653     /* Add everything to the frame */
654     slider_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
655     slider_sizer->Add( disc_frame, 0, wxALL, 2 );
656     slider_frame->SetSizer( slider_sizer );
657
658     disc_frame->Hide();
659     slider_sizer->Hide( disc_frame );
660
661     slider_sizer->Layout();
662     slider_sizer->Fit( slider_frame );
663
664     /* Hide the slider by default */
665     slider_frame->Hide();
666 }
667
668 static int ConvertHotkeyModifiers( int i_hotkey )
669 {
670     int i_accel_flags = 0;
671     if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
672     if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
673     if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
674     if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
675     return i_accel_flags;
676 }
677
678 static int ConvertHotkey( int i_hotkey )
679 {
680     int i_key = i_hotkey & ~KEY_MODIFIER;
681     if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
682     else if( i_key & KEY_SPECIAL )
683     {
684         switch ( i_key )
685         {
686         case KEY_LEFT: return WXK_LEFT;
687         case KEY_RIGHT: return WXK_RIGHT;
688         case KEY_UP: return WXK_UP;
689         case KEY_DOWN: return WXK_DOWN;
690         case KEY_SPACE: return WXK_SPACE;
691         case KEY_ENTER: return WXK_RETURN;
692         case KEY_F1: return WXK_F1;
693         case KEY_F2: return WXK_F2;
694         case KEY_F3: return WXK_F3;
695         case KEY_F4: return WXK_F4;
696         case KEY_F5: return WXK_F5;
697         case KEY_F6: return WXK_F6;
698         case KEY_F7: return WXK_F7;
699         case KEY_F8: return WXK_F8;
700         case KEY_F9: return WXK_F9;
701         case KEY_F10: return WXK_F10;
702         case KEY_F11: return WXK_F11;
703         case KEY_F12: return WXK_F12;
704         case KEY_HOME: return WXK_HOME;
705         case KEY_END: return WXK_END;
706         case KEY_INSERT: return WXK_INSERT;
707         case KEY_DELETE: return WXK_DELETE;
708         case KEY_MENU: return WXK_MENU;
709         case KEY_ESC: return WXK_ESCAPE;
710         case KEY_PAGEUP: return WXK_PRIOR;
711         case KEY_PAGEDOWN: return WXK_NEXT;
712         case KEY_TAB: return WXK_TAB;
713         case KEY_BACKSPACE: return WXK_BACK;
714         }
715     }
716     return WXK_F24;
717 }
718
719 void Interface::SetupHotkeys()
720 {
721     struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
722     int i_hotkeys;
723
724     /* Count number of hoteys */
725     for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
726
727     p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
728     p_intf->p_sys->i_hotkeys = i_hotkeys;
729
730     wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
731
732     /* Setup the hotkeys as accelerators */
733     for( int i = 0; i < i_hotkeys; i++ )
734     {
735         int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
736         int i_key = ConvertHotkey( p_hotkeys[i].i_key );
737
738 #ifdef WIN32
739         if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
740             i_key = toupper(i_key);
741 #endif
742
743         p_entries[i].Set( i_mod, i_key,
744                           p_intf->p_sys->i_first_hotkey_event + i );
745     }
746
747     wxAcceleratorTable accel( i_hotkeys, p_entries );
748
749     if( !accel.Ok() )
750     {
751         msg_Err( p_intf, "invalid accelerator table" );
752     }
753     else
754     {
755         SetAcceleratorTable( accel );
756     }
757
758     delete [] p_entries;
759 }
760
761 void Interface::HideSlider( bool layout )
762 {
763     ShowSlider( false, layout );
764 }
765
766 void Interface::ShowSlider( bool show, bool layout )
767 {
768     if( show )
769     {
770         //prevent the hide timers from hiding it now
771         m_slider_timer.Stop();
772         m_controls_timer.Stop();
773
774         //prevent continuous layout
775         if( slider_frame->IsShown() ) return;
776         
777         wxSize ms = GetMinSize();
778         ms.SetHeight( ms.GetHeight() + slider_size.GetHeight() );
779 #if ( wxCHECK_VERSION( 2,5,4 ) )
780         SetMinSize( ms );
781 #else
782         frame_sizer->SetMinSize( ms );
783 #endif
784     }
785     else
786     {
787         //prevent continuous layout
788         if( !slider_frame->IsShown() ) return;
789         
790         wxSize ms = GetMinSize();
791         ms.SetHeight( ms.GetHeight() - slider_size.GetHeight() );
792 #if ( wxCHECK_VERSION( 2,5,4 ) )
793         SetMinSize( ms );
794 #else
795         frame_sizer->SetMinSize( ms );
796 #endif
797     }
798
799     if( layout && p_intf->p_sys->b_video_autosize )
800         UpdateVideoWindow( p_intf, video_window );
801
802     slider_frame->Show( show );
803     frame_sizer->Show( slider_frame, show );
804
805     if( layout )
806     {
807         frame_sizer->Layout();
808         if( p_intf->p_sys->b_video_autosize ) frame_sizer->Fit( this );
809     }
810 }
811
812 void Interface::HideDiscFrame( bool layout )
813 {
814     ShowDiscFrame( false, layout );
815 }
816
817 void Interface::ShowDiscFrame( bool show, bool layout )
818 {
819     if( show )
820     {
821         //prevent the hide timer from hiding it now
822         m_controls_timer.Stop();
823
824         //prevent continuous layout
825         if( disc_frame->IsShown() ) return;
826     }
827     else
828     {
829         //prevent continuous layout
830         if( !disc_frame->IsShown() ) return;
831     }
832
833     if( layout && p_intf->p_sys->b_video_autosize )
834         UpdateVideoWindow( p_intf, video_window );
835
836     disc_frame->Show( show );
837     slider_sizer->Show( disc_frame, show );
838
839     if( layout )
840     {
841         slider_sizer->Layout();
842         if( p_intf->p_sys->b_video_autosize )
843             slider_sizer->Fit( slider_frame );
844     }
845 }
846
847 /*****************************************************************************
848  * Event Handlers.
849  *****************************************************************************/
850 void Interface::OnControlsTimer( wxTimerEvent& WXUNUSED(event) )
851 {
852     if( p_intf->p_sys->b_video_autosize )
853         UpdateVideoWindow( p_intf, video_window );
854
855     /* Hide slider and Disc Buttons */
856     //postpone layout, we'll do it ourselves
857     HideDiscFrame( false );
858     HideSlider( false );
859
860     slider_sizer->Layout();
861     if( p_intf->p_sys->b_video_autosize )
862     {
863         slider_sizer->Fit( slider_frame );
864         frame_sizer->Fit( this );
865     }
866 }
867
868 void Interface::OnSliderTimer( wxTimerEvent& WXUNUSED(event) )
869 {
870     HideSlider();
871 }
872
873 void Interface::OnMenuOpen( wxMenuEvent& event )
874 {
875 #if defined( __WXMSW__ )
876 #   define GetEventObject GetMenu
877 #endif
878
879     if( event.GetEventObject() == p_settings_menu )
880     {
881         p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
882
883         /* Add static items */
884         p_settings_menu->AppendCheckItem( Extended_Event,
885             wxU(_("Extended &GUI\tCtrl-G") ) );
886         if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
887 #if 0
888         p_settings_menu->AppendCheckItem( Undock_Event,
889             wxU(_("&Undock Ext. GUI") ) );
890         if( b_undock ) p_settings_menu->Check( Undock_Event, TRUE );
891 #endif
892         p_settings_menu->Append( Bookmarks_Event,
893                                  wxU(_("&Bookmarks...\tCtrl-B") ) );
894         p_settings_menu->Append( Prefs_Event,
895                                  wxU(_("Preference&s...\tCtrl-S")) );
896     }
897
898     else if( event.GetEventObject() == p_audio_menu )
899     {
900         p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
901     }
902
903     else if( event.GetEventObject() == p_video_menu )
904     {
905         p_video_menu = VideoMenu( p_intf, this, p_video_menu );
906     }
907
908     else if( event.GetEventObject() == p_navig_menu )
909     {
910         p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
911     }
912
913 #if defined( __WXMSW__ )
914 #   undef GetEventObject
915 #endif
916 }
917
918 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
919 void Interface::OnContextMenu2(wxContextMenuEvent& event)
920 {
921     /* Only show the context menu for the main interface */
922     if( GetId() != event.GetId() )
923     {
924         event.Skip();
925         return;
926     }
927
928     if( p_intf->p_sys->pf_show_dialog )
929         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
930 }
931 #endif
932 void Interface::OnContextMenu(wxMouseEvent& event)
933 {
934     if( p_intf->p_sys->pf_show_dialog )
935         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
936 }
937
938 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
939 {
940     /* TRUE is to force the frame to close. */
941     Close(TRUE);
942 }
943
944 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
945 {
946     wxString msg;
947     msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
948         wxU(_(" (wxWidgets interface)\n\n")) +
949         wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
950        wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
951        wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
952        wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
953        wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
954 #ifdef __WXMSW__
955         wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
956 #else
957         wxU( LICENSE_MSG ) + wxT("\n\n") +
958 #endif
959         wxU(_("The VideoLAN team <videolan@videolan.org>\n"
960               "http://www.videolan.org/\n\n")) );
961
962     wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
963                   wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
964 }
965
966 void Interface::OnShowDialog( wxCommandEvent& event )
967 {
968     if( p_intf->p_sys->pf_show_dialog )
969     {
970         int i_id;
971
972         switch( event.GetId() )
973         {
974         case OpenFileSimple_Event:
975             i_id = INTF_DIALOG_FILE_SIMPLE;
976             break;
977         case OpenAdv_Event:
978             i_id = INTF_DIALOG_FILE;
979             break;
980         case OpenFile_Event:
981             i_id = INTF_DIALOG_FILE;
982             break;
983         case OpenDir_Event:
984             i_id = INTF_DIALOG_DIRECTORY;
985             break;
986         case OpenDisc_Event:
987             i_id = INTF_DIALOG_DISC;
988             break;
989         case OpenNet_Event:
990             i_id = INTF_DIALOG_NET;
991             break;
992         case OpenCapture_Event:
993             i_id = INTF_DIALOG_CAPTURE;
994             break;
995         case OpenSat_Event:
996             i_id = INTF_DIALOG_SAT;
997             break;
998         case Playlist_Event:
999             i_id = INTF_DIALOG_PLAYLIST;
1000             break;
1001         case Logs_Event:
1002             i_id = INTF_DIALOG_MESSAGES;
1003             break;
1004         case FileInfo_Event:
1005             i_id = INTF_DIALOG_FILEINFO;
1006             break;
1007         case Prefs_Event:
1008             i_id = INTF_DIALOG_PREFS;
1009             break;
1010         case Wizard_Event:
1011             i_id = INTF_DIALOG_WIZARD;
1012             break;
1013         case Bookmarks_Event:
1014             i_id = INTF_DIALOG_BOOKMARKS;
1015             break;
1016         case UpdateVLC_Event:
1017             i_id = INTF_DIALOG_UPDATEVLC;
1018             break;
1019         case VLM_Event:
1020             i_id = INTF_DIALOG_VLM;
1021             break;
1022         default:
1023             i_id = INTF_DIALOG_FILE;
1024             break;
1025         }
1026
1027         p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
1028     }
1029 }
1030
1031 void Interface::OnExtended(wxCommandEvent& event)
1032 {
1033     b_extra = (b_extra == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
1034
1035     if( b_extra == VLC_FALSE )
1036     {
1037         extra_frame->Hide();
1038         frame_sizer->Hide( extra_frame );
1039         wxSize ms = GetMinSize();
1040         ms.SetHeight( ms.GetHeight() - extended_size.GetHeight() );
1041         ms.SetWidth( default_size.GetWidth() );
1042 #if ( wxCHECK_VERSION( 2,5,4 ) )
1043         SetMinSize( ms );
1044 #else
1045         frame_sizer->SetMinSize( ms );
1046 #endif
1047     }
1048     else
1049     {
1050         extra_frame->Show();
1051         frame_sizer->Show( extra_frame );
1052         wxSize ms = GetMinSize();
1053         ms.SetHeight( ms.GetHeight() + extended_size.GetHeight() );
1054         ms.SetWidth( extended_size.GetWidth() );
1055 #if ( wxCHECK_VERSION( 2,5,4 ) )
1056         SetMinSize( ms );
1057 #else
1058         frame_sizer->SetMinSize( ms );
1059 #endif
1060     }
1061     frame_sizer->Layout();
1062     frame_sizer->Fit(this);
1063 }
1064
1065 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1066 {
1067     PlayStream();
1068 }
1069
1070 void Interface::PlayStream()
1071 {
1072     wxCommandEvent dummy;
1073     playlist_t *p_playlist =
1074         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1075                                        FIND_ANYWHERE );
1076     if( p_playlist == NULL ) return;
1077
1078     if( p_playlist->i_size && p_playlist->i_enabled )
1079     {
1080         vlc_value_t state;
1081
1082         input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1083                                                        VLC_OBJECT_INPUT,
1084                                                        FIND_ANYWHERE );
1085         if( p_input == NULL )
1086         {
1087             /* No stream was playing, start one */
1088             playlist_Play( p_playlist );
1089             TogglePlayButton( PLAYING_S );
1090             vlc_object_release( p_playlist );
1091             return;
1092         }
1093
1094         var_Get( p_input, "state", &state );
1095
1096         if( state.i_int != PAUSE_S )
1097         {
1098             /* A stream is being played, pause it */
1099             state.i_int = PAUSE_S;
1100         }
1101         else
1102         {
1103             /* Stream is paused, resume it */
1104             state.i_int = PLAYING_S;
1105         }
1106         var_Set( p_input, "state", state );
1107
1108         TogglePlayButton( state.i_int );
1109         vlc_object_release( p_input );
1110         vlc_object_release( p_playlist );
1111     }
1112     else
1113     {
1114         /* If the playlist is empty, open a file requester instead */
1115         vlc_object_release( p_playlist );
1116         OnShowDialog( dummy );
1117     }
1118 }
1119
1120 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1121 {
1122     StopStream();
1123 }
1124 void Interface::StopStream()
1125 {
1126     playlist_t * p_playlist =
1127         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1128                                        FIND_ANYWHERE );
1129     if( p_playlist == NULL )
1130     {
1131         return;
1132     }
1133
1134     playlist_Stop( p_playlist );
1135     TogglePlayButton( PAUSE_S );
1136     vlc_object_release( p_playlist );
1137 }
1138
1139 void Interface::OnSliderUpdate( wxScrollEvent& event )
1140 {
1141     vlc_mutex_lock( &p_intf->change_lock );
1142
1143 #ifdef WIN32
1144     if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
1145         || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
1146     {
1147 #endif
1148         if( p_intf->p_sys->i_slider_pos != event.GetPosition()
1149             && p_intf->p_sys->p_input )
1150         {
1151             vlc_value_t pos;
1152             pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
1153
1154             var_Set( p_intf->p_sys->p_input, "position", pos );
1155         }
1156
1157 #ifdef WIN32
1158         p_intf->p_sys->b_slider_free = VLC_TRUE;
1159     }
1160     else
1161     {
1162         p_intf->p_sys->b_slider_free = VLC_FALSE;
1163
1164         if( p_intf->p_sys->p_input )
1165         {
1166             /* Update stream date */
1167             char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
1168             mtime_t i_seconds;
1169
1170             i_seconds = var_GetTime( p_intf->p_sys->p_input, "length" ) /
1171                         I64C(1000000 );
1172             secstotimestr( psz_total, i_seconds );
1173
1174             i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) /
1175                         I64C(1000000 );
1176             secstotimestr( psz_time, i_seconds );
1177
1178             statusbar->SetStatusText( wxU(psz_time) + wxString(wxT(" / ") ) +
1179                                       wxU(psz_total), 0 );
1180         }
1181     }
1182 #endif
1183
1184 #undef WIN32
1185     vlc_mutex_unlock( &p_intf->change_lock );
1186 }
1187
1188 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1189 {
1190     PrevStream();
1191 }
1192
1193 void Interface::PrevStream()
1194 {
1195     playlist_t * p_playlist =
1196         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1197                                        FIND_ANYWHERE );
1198     if( p_playlist == NULL )
1199     {
1200         return;
1201     }
1202
1203     playlist_Prev( p_playlist );
1204     vlc_object_release( p_playlist );
1205 }
1206
1207 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1208 {
1209     NextStream();
1210 }
1211
1212 void Interface::NextStream()
1213 {
1214     playlist_t * p_playlist =
1215         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1216                                        FIND_ANYWHERE );
1217     if( p_playlist == NULL )
1218     {
1219         return;
1220     }
1221     playlist_Next( p_playlist );
1222     vlc_object_release( p_playlist );
1223 }
1224
1225 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1226 {
1227     input_thread_t *p_input =
1228         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1229                                            FIND_ANYWHERE );
1230     if( p_input )
1231     {
1232         vlc_value_t val; val.b_bool = VLC_TRUE;
1233
1234         var_Set( p_input, "rate-slower", val );
1235         vlc_object_release( p_input );
1236     }
1237 }
1238
1239 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1240 {
1241     input_thread_t *p_input =
1242         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1243                                            FIND_ANYWHERE );
1244     if( p_input )
1245     {
1246         vlc_value_t val; val.b_bool = VLC_TRUE;
1247
1248         var_Set( p_input, "rate-faster", val );
1249         vlc_object_release( p_input );
1250     }
1251 }
1252
1253 void Interface::TogglePlayButton( int i_playing_status )
1254 {
1255     if( i_playing_status == i_old_playing_status )
1256         return;
1257
1258     wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1259         GetToolBar()->GetToolClientData( PlayStream_Event );
1260     if( !p_tool ) return;
1261
1262     if( i_playing_status == PLAYING_S )
1263     {
1264         p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1265         p_tool->SetLabel( wxU(_("Pause")) );
1266         p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1267     }
1268     else
1269     {
1270         p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1271         p_tool->SetLabel( wxU(_("Play")) );
1272         p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1273     }
1274
1275     GetToolBar()->Realize();
1276     GetToolBar()->ToggleTool( PlayStream_Event, true );
1277     GetToolBar()->ToggleTool( PlayStream_Event, false );
1278
1279     i_old_playing_status = i_playing_status;
1280 }
1281
1282 void Interface::OnDiscMenu( wxCommandEvent& WXUNUSED(event) )
1283 {
1284     input_thread_t *p_input =
1285         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1286                                            FIND_ANYWHERE );
1287     if( p_input )
1288     {
1289         vlc_value_t val; val.i_int = 2;
1290
1291         var_Set( p_input, "title  0", val);
1292         vlc_object_release( p_input );
1293     }
1294 }
1295
1296 void Interface::OnDiscPrev( wxCommandEvent& WXUNUSED(event) )
1297 {
1298     input_thread_t *p_input =
1299         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1300                                            FIND_ANYWHERE );
1301     if( p_input )
1302     {
1303         int i_type = var_Type( p_input, "prev-chapter" );
1304         vlc_value_t val; val.b_bool = VLC_TRUE;
1305
1306         var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1307                  "prev-chapter" : "prev-title", val );
1308
1309         vlc_object_release( p_input );
1310     }
1311 }
1312
1313 void Interface::OnDiscNext( wxCommandEvent& WXUNUSED(event) )
1314 {
1315     input_thread_t *p_input =
1316         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1317                                            FIND_ANYWHERE );
1318     if( p_input )
1319     {
1320         int i_type = var_Type( p_input, "next-chapter" );
1321         vlc_value_t val; val.b_bool = VLC_TRUE;
1322
1323         var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1324                  "next-chapter" : "next-title", val );
1325
1326         vlc_object_release( p_input );
1327     }
1328 }
1329
1330 #if wxUSE_DRAG_AND_DROP
1331 /*****************************************************************************
1332  * Definition of DragAndDrop class.
1333  *****************************************************************************/
1334 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1335 {
1336     p_intf = _p_intf;
1337     b_enqueue = _b_enqueue;
1338 }
1339
1340 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1341                                const wxArrayString& filenames )
1342 {
1343     /* Add dropped files to the playlist */
1344
1345     playlist_t *p_playlist =
1346         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1347                                        FIND_ANYWHERE );
1348     if( p_playlist == NULL )
1349     {
1350         return FALSE;
1351     }
1352
1353     for( size_t i = 0; i < filenames.GetCount(); i++ )
1354     {
1355         char *psz_utf8 = wxFromLocale( filenames[i] );
1356
1357         playlist_Add( p_playlist, psz_utf8, psz_utf8,
1358                       PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1359                       PLAYLIST_END );
1360         wxLocaleFree( psz_utf8 );
1361     }
1362
1363     vlc_object_release( p_playlist );
1364
1365     return TRUE;
1366 }
1367 #endif
1368
1369 /*****************************************************************************
1370  * Definition of VolCtrl class.
1371  *****************************************************************************/
1372 class wxVolCtrl: public wxGauge
1373 {
1374 public:
1375     /* Constructor */
1376     wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1377                wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1378     virtual ~wxVolCtrl() {};
1379
1380     void UpdateVolume();
1381     int GetVolume();
1382
1383     void OnChange( wxMouseEvent& event );
1384
1385 private:
1386     intf_thread_t *p_intf;
1387
1388     DECLARE_EVENT_TABLE();
1389 };
1390
1391 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1392     /* Mouse events */
1393     EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1394     EVT_MOTION(wxVolCtrl::OnChange)
1395 END_EVENT_TABLE()
1396
1397 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1398                       wxPoint point, wxSize size )
1399   : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1400 {
1401     p_intf = _p_intf;
1402     UpdateVolume();
1403 }
1404
1405 void wxVolCtrl::OnChange( wxMouseEvent& event )
1406 {
1407     if( !event.LeftDown() && !event.LeftIsDown() ) return;
1408
1409     int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1410     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1411     UpdateVolume();
1412 }
1413
1414 void wxVolCtrl::UpdateVolume()
1415 {
1416     audio_volume_t i_volume;
1417     aout_VolumeGet( p_intf, &i_volume );
1418
1419     int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1420     if( i_gauge_volume == GetValue() ) return;
1421
1422     SetValue( i_gauge_volume );
1423     SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1424                 i_gauge_volume / 2 ) );
1425 }
1426
1427 #if defined(__WXGTK__)
1428 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1429 #else
1430 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1431 #endif
1432 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1433   :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1434               wxBORDER_NONE ),
1435    i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1436    b_mute(0), p_intf(_p_intf)
1437 {
1438     gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1439                            wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1440 }
1441
1442 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1443 {
1444     wxPaintDC dc( this );
1445     wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1446     dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1447 }
1448
1449 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1450 {
1451     if( event.GetX() < TOOLBAR_BMP_WIDTH )
1452     {
1453         int i_volume;
1454         aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1455
1456         b_mute = !b_mute;
1457         Refresh();
1458     }
1459 }
1460
1461 void VLCVolCtrl::UpdateVolume()
1462 {
1463     gauge->UpdateVolume();
1464
1465     int i_volume = gauge->GetValue();
1466     if( !!i_volume == !b_mute ) return;
1467     b_mute = !b_mute;
1468     Refresh();
1469 }
1470
1471 /*****************************************************************************
1472  * Systray class.
1473  *****************************************************************************/
1474
1475 #ifdef wxHAS_TASK_BAR_ICON
1476
1477 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1478     /* Mouse events */
1479 #ifdef WIN32
1480     EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1481 #else
1482     EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1483 #endif
1484     /* Menu events */
1485     EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1486     EVT_MENU(Exit_Event, Systray::OnExit)
1487     EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1488     EVT_MENU(NextStream_Event, Systray::OnNextStream)
1489     EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1490     EVT_MENU(StopStream_Event, Systray::OnStopStream)
1491 END_EVENT_TABLE()
1492
1493 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1494 {
1495     p_main_interface = _p_main_interface;
1496     p_intf = _p_intf;
1497 }
1498
1499 /* Event handlers */
1500 void Systray::OnMenuIconize( wxCommandEvent& event )
1501 {
1502     p_main_interface->Show( ! p_main_interface->IsShown() );
1503     if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1504 }
1505
1506 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1507 {
1508     wxCommandEvent cevent;
1509     OnMenuIconize(cevent);
1510 }
1511
1512 void Systray::OnExit( wxCommandEvent& event )
1513 {
1514     p_main_interface->Close(TRUE);
1515 }
1516
1517 void Systray::OnPrevStream( wxCommandEvent& event )
1518 {
1519     p_main_interface->PrevStream();
1520 }
1521
1522 void Systray::OnNextStream( wxCommandEvent& event )
1523 {
1524     p_main_interface->NextStream();
1525 }
1526
1527 void Systray::OnPlayStream( wxCommandEvent& event )
1528 {
1529     p_main_interface->PlayStream();
1530 }
1531
1532 void Systray::OnStopStream( wxCommandEvent& event )
1533 {
1534     p_main_interface->StopStream();
1535 }
1536
1537 /* Systray popup menu */
1538 wxMenu* Systray::CreatePopupMenu()
1539 {
1540     int minimal = config_GetInt( p_intf, "wx-minimal" );
1541
1542     wxMenu* systray_menu = new wxMenu;
1543     systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1544     systray_menu->AppendSeparator();
1545     systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1546
1547     if (!minimal)
1548     {
1549     systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1550     systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1551     systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1552     }
1553     systray_menu->AppendSeparator();
1554     systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1555     return systray_menu;
1556 }
1557
1558 void Systray::UpdateTooltip( const wxChar* tooltip )
1559 {
1560     SetIcon( wxIcon( vlc16x16_xpm ), tooltip );
1561 }
1562 #endif