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