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