]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/interface.cpp
Fixes from hobophobe on IRC
[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 libvlc_int_t::hotkey *p_hotkeys = p_intf->p_libvlc->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     wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
955                   wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
956 }
957
958 void Interface::OnShowDialog( wxCommandEvent& event )
959 {
960     if( p_intf->p_sys->pf_show_dialog )
961     {
962         int i_id;
963
964         switch( event.GetId() )
965         {
966         case OpenFileSimple_Event:
967             i_id = INTF_DIALOG_FILE_SIMPLE;
968             break;
969         case OpenAdv_Event:
970             i_id = INTF_DIALOG_FILE;
971             break;
972         case OpenFile_Event:
973             i_id = INTF_DIALOG_FILE;
974             break;
975         case OpenDir_Event:
976             i_id = INTF_DIALOG_DIRECTORY;
977             break;
978         case OpenDisc_Event:
979             i_id = INTF_DIALOG_DISC;
980             break;
981         case OpenNet_Event:
982             i_id = INTF_DIALOG_NET;
983             break;
984         case OpenCapture_Event:
985             i_id = INTF_DIALOG_CAPTURE;
986             break;
987         case OpenSat_Event:
988             i_id = INTF_DIALOG_SAT;
989             break;
990         case Playlist_Event:
991             i_id = INTF_DIALOG_PLAYLIST;
992             break;
993         case Logs_Event:
994             i_id = INTF_DIALOG_MESSAGES;
995             break;
996         case FileInfo_Event:
997             i_id = INTF_DIALOG_FILEINFO;
998             break;
999         case Prefs_Event:
1000             i_id = INTF_DIALOG_PREFS;
1001             break;
1002         case Wizard_Event:
1003             i_id = INTF_DIALOG_WIZARD;
1004             break;
1005         case Bookmarks_Event:
1006             i_id = INTF_DIALOG_BOOKMARKS;
1007             break;
1008         case UpdateVLC_Event:
1009             i_id = INTF_DIALOG_UPDATEVLC;
1010             break;
1011         case VLM_Event:
1012             i_id = INTF_DIALOG_VLM;
1013             break;
1014         default:
1015             i_id = INTF_DIALOG_FILE;
1016             break;
1017         }
1018
1019         p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
1020     }
1021 }
1022
1023 void Interface::OnExtended( wxCommandEvent& WXUNUSED(event) )
1024 {
1025     UpdateVideoWindow( p_intf, video_window );
1026
1027     if( !extra_frame )
1028     {
1029         /* Create the extra panel */
1030         extra_frame = new ExtraPanel( p_intf, main_panel );
1031         panel_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
1032         ext_min_size = extra_frame->GetBestSize();
1033     }
1034
1035     b_extra = !b_extra;
1036     panel_sizer->Show( extra_frame, b_extra );
1037
1038     SetIntfMinSize();
1039     main_sizer->Layout();
1040     main_sizer->Fit( this );
1041 }
1042
1043 void Interface::OnSmallPlaylist( wxCommandEvent& WXUNUSED(event) )
1044 {
1045     UpdateVideoWindow( p_intf, video_window );
1046
1047     if( !playlist_manager )
1048     {
1049         /* Create the extra panel */
1050         playlist_manager = new PlaylistManager( p_intf, splitter );
1051     }
1052
1053     if( !splitter->IsSplit() ) splitter->Split( main_panel, playlist_manager );
1054     else splitter->Unsplit( playlist_manager );
1055
1056     SetIntfMinSize();
1057     main_sizer->Layout();
1058     main_sizer->Fit( this );
1059 }
1060
1061 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1062 {
1063     PlayStream();
1064 }
1065
1066 void Interface::PlayStream()
1067 {
1068     wxCommandEvent dummy;
1069     playlist_t *p_playlist =
1070         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1071                                        FIND_ANYWHERE );
1072     if( p_playlist == NULL ) return;
1073
1074     if( !playlist_IsEmpty(p_playlist) && p_playlist->i_enabled )
1075     {
1076         vlc_value_t state;
1077
1078         input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1079                                                        VLC_OBJECT_INPUT,
1080                                                        FIND_ANYWHERE );
1081         if( p_input == NULL )
1082         {
1083             /* No stream was playing, start one */
1084             playlist_Play( p_playlist );
1085             vlc_object_release( p_playlist );
1086             input_manager->Update();
1087             return;
1088         }
1089
1090         var_Get( p_input, "state", &state );
1091         if( state.i_int != PAUSE_S )
1092         {
1093             /* A stream is being played, pause it */
1094             state.i_int = PAUSE_S;
1095         }
1096         else
1097         {
1098             /* Stream is paused, resume it */
1099             state.i_int = PLAYING_S;
1100         }
1101         var_Set( p_input, "state", state );
1102
1103         vlc_object_release( p_input );
1104         vlc_object_release( p_playlist );
1105         input_manager->Update();
1106     }
1107     else
1108     {
1109         /* If the playlist is empty, open a file requester instead */
1110         vlc_object_release( p_playlist );
1111         OnShowDialog( dummy );
1112         GetToolBar()->ToggleTool( PlayStream_Event, false );
1113     }
1114 }
1115
1116 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1117 {
1118     StopStream();
1119 }
1120 void Interface::StopStream()
1121 {
1122     playlist_t * p_playlist =
1123         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1124                                        FIND_ANYWHERE );
1125     if( p_playlist == NULL )
1126     {
1127         return;
1128     }
1129
1130     playlist_Stop( p_playlist );
1131     vlc_object_release( p_playlist );
1132     input_manager->Update();
1133 }
1134
1135 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1136 {
1137     PrevStream();
1138 }
1139
1140 void Interface::PrevStream()
1141 {
1142     playlist_t * p_playlist =
1143         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1144                                        FIND_ANYWHERE );
1145     if( p_playlist == NULL )
1146     {
1147         return;
1148     }
1149
1150     playlist_Prev( p_playlist );
1151     vlc_object_release( p_playlist );
1152 }
1153
1154 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1155 {
1156     NextStream();
1157 }
1158
1159 void Interface::NextStream()
1160 {
1161     playlist_t * p_playlist =
1162         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1163                                        FIND_ANYWHERE );
1164     if( p_playlist == NULL )
1165     {
1166         return;
1167     }
1168     playlist_Next( p_playlist );
1169     vlc_object_release( p_playlist );
1170 }
1171
1172 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1173 {
1174     input_thread_t *p_input =
1175         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1176                                            FIND_ANYWHERE );
1177     if( p_input )
1178     {
1179         vlc_value_t val; val.b_bool = VLC_TRUE;
1180
1181         var_Set( p_input, "rate-slower", val );
1182         vlc_object_release( p_input );
1183     }
1184 }
1185
1186 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1187 {
1188     input_thread_t *p_input =
1189         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1190                                            FIND_ANYWHERE );
1191     if( p_input )
1192     {
1193         vlc_value_t val; val.b_bool = VLC_TRUE;
1194
1195         var_Set( p_input, "rate-faster", val );
1196         vlc_object_release( p_input );
1197     }
1198 }
1199
1200 void Interface::TogglePlayButton( int i_playing_status )
1201 {
1202     wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1203         GetToolBar()->GetToolClientData( PlayStream_Event );
1204     if( !p_tool ) return;
1205
1206     if( i_playing_status == PLAYING_S )
1207     {
1208         p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1209         p_tool->SetLabel( wxU(_("Pause")) );
1210         p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1211     }
1212     else
1213     {
1214         p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1215         p_tool->SetLabel( wxU(_("Play")) );
1216         p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1217     }
1218
1219     GetToolBar()->Realize();
1220
1221 #if defined( __WXMSW__ )
1222     /* Needed to work around a bug in wxToolBar::Realize() */
1223     GetToolBar()->SetSize( GetSize().GetWidth(),
1224                            GetToolBar()->GetSize().GetHeight() );
1225     GetToolBar()->Update();
1226 #endif
1227
1228     GetToolBar()->ToggleTool( PlayStream_Event, true );
1229     GetToolBar()->ToggleTool( PlayStream_Event, false );
1230 }
1231
1232 void Interface::OnInteraction( wxCommandEvent& event )
1233 {
1234     interaction_dialog_t *p_dialog = (interaction_dialog_t *)
1235                                         event.GetClientData();
1236
1237     intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1238     p_arg->p_dialog = p_dialog;
1239     p_arg->p_intf = p_intf;
1240
1241     p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_INTERACTION,
1242                                        0, p_arg );
1243
1244 }
1245
1246 static int InteractCallback( vlc_object_t *p_this,
1247                              const char *psz_var, vlc_value_t old_val,
1248                              vlc_value_t new_val, void *param )
1249 {
1250     Interface *p_interface = (Interface*)param;
1251     /*interaction_dialog_t *p_dialog = (interaction_dialog_t*)(new_val.p_address);*/
1252
1253     wxCommandEvent event( wxEVT_INTERACTION, -1 );
1254     event.SetClientData( new_val.p_address );
1255     p_interface->AddPendingEvent( event );
1256     return VLC_SUCCESS;
1257 }
1258
1259 #if wxUSE_DRAG_AND_DROP
1260 /*****************************************************************************
1261  * Definition of DragAndDrop class.
1262  *****************************************************************************/
1263 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1264 {
1265     p_intf = _p_intf;
1266     b_enqueue = _b_enqueue;
1267 }
1268
1269 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1270                                const wxArrayString& filenames )
1271 {
1272     /* Add dropped files to the playlist */
1273
1274     playlist_t *p_playlist =
1275         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1276                                        FIND_ANYWHERE );
1277     if( p_playlist == NULL )
1278     {
1279         return FALSE;
1280     }
1281
1282     /* If we drag & drop a subtitle file, add it on the fly */
1283     if( filenames.GetCount() == 1 )
1284     {
1285         char *psz_utf8 = wxDnDFromLocale( filenames[0] );
1286         input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1287                                             VLC_OBJECT_INPUT, FIND_ANYWHERE );
1288         if( p_input )
1289         {
1290             if( input_AddSubtitles( p_input, psz_utf8, VLC_TRUE ) )
1291             {
1292                 vlc_object_release( p_input );
1293                 wxDnDLocaleFree( psz_utf8 );
1294                 vlc_object_release( p_playlist );
1295                 return TRUE;
1296             }
1297             vlc_object_release( p_input );
1298         }
1299         wxDnDLocaleFree( psz_utf8 );
1300     }
1301
1302     for( size_t i = 0; i < filenames.GetCount(); i++ )
1303     {
1304         char *psz_utf8 = wxDnDFromLocale( filenames[i] );
1305
1306         playlist_PlaylistAdd( p_playlist, psz_utf8, NULL,
1307                       PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1308                       PLAYLIST_END );
1309
1310         wxDnDLocaleFree( psz_utf8 );
1311     }
1312
1313     vlc_object_release( p_playlist );
1314
1315     return TRUE;
1316 }
1317 #endif
1318
1319 /*****************************************************************************
1320  * Definition of VolCtrl class.
1321  *****************************************************************************/
1322 class wxVolCtrl: public wxGauge
1323 {
1324 public:
1325     /* Constructor */
1326     wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1327                wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1328     virtual ~wxVolCtrl() {};
1329
1330     void UpdateVolume();
1331     int GetVolume();
1332
1333     void OnChange( wxMouseEvent& event );
1334
1335 private:
1336     intf_thread_t *p_intf;
1337
1338     DECLARE_EVENT_TABLE();
1339 };
1340
1341 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1342     /* Mouse events */
1343     EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1344     EVT_MOTION(wxVolCtrl::OnChange)
1345 END_EVENT_TABLE()
1346
1347 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1348                       wxPoint point, wxSize size )
1349   : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1350 {
1351     p_intf = _p_intf;
1352     UpdateVolume();
1353 }
1354
1355 void wxVolCtrl::OnChange( wxMouseEvent& event )
1356 {
1357     if( !event.LeftDown() && !event.LeftIsDown() ) return;
1358
1359     int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1360     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1361     UpdateVolume();
1362 }
1363
1364 void wxVolCtrl::UpdateVolume()
1365 {
1366     audio_volume_t i_volume;
1367     aout_VolumeGet( p_intf, &i_volume );
1368
1369     int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1370     if( i_gauge_volume == GetValue() ) return;
1371
1372     SetValue( i_gauge_volume );
1373     SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1374                 i_gauge_volume / 2 ) );
1375 }
1376
1377 #if defined(__WXGTK__)
1378 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1379 #else
1380 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1381 #endif
1382 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1383   :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1384               wxBORDER_NONE ),
1385    i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1386    b_mute(0), p_intf(_p_intf)
1387 {
1388     gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1389                            wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1390 }
1391
1392 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1393 {
1394     wxPaintDC dc( this );
1395     wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1396     dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1397 }
1398
1399 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1400 {
1401     if( event.GetX() < TOOLBAR_BMP_WIDTH )
1402     {
1403         int i_volume;
1404         aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1405
1406         b_mute = !b_mute;
1407         Refresh();
1408     }
1409 }
1410
1411 void VLCVolCtrl::UpdateVolume()
1412 {
1413     gauge->UpdateVolume();
1414
1415     int i_volume = gauge->GetValue();
1416     if( !!i_volume == !b_mute ) return;
1417     b_mute = !b_mute;
1418     Refresh();
1419 }
1420
1421 /*****************************************************************************
1422  * Systray class.
1423  *****************************************************************************/
1424
1425 /* wxCocoa pretends to support this, but at least 2.6.x doesn't */
1426 #ifndef __APPLE__
1427 #ifdef wxHAS_TASK_BAR_ICON
1428
1429 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1430     /* Mouse events */
1431 #ifdef WIN32
1432     EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1433 #else
1434     EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1435 #endif
1436     /* Menu events */
1437     EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1438     EVT_MENU(Exit_Event, Systray::OnExit)
1439     EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1440     EVT_MENU(NextStream_Event, Systray::OnNextStream)
1441     EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1442     EVT_MENU(StopStream_Event, Systray::OnStopStream)
1443 END_EVENT_TABLE()
1444
1445 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1446 {
1447     p_main_interface = _p_main_interface;
1448     p_intf = _p_intf;
1449
1450     SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
1451     if( !IsOk() || !IsIconInstalled() )
1452     {
1453         msg_Warn(p_intf, "cannot set systray icon, weird things may happen");
1454     }
1455 }
1456
1457 /* Event handlers */
1458 void Systray::OnMenuIconize( wxCommandEvent& event )
1459 {
1460     p_main_interface->Show( ! p_main_interface->IsShown() );
1461     if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1462 }
1463
1464 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1465 {
1466     wxCommandEvent cevent;
1467     OnMenuIconize(cevent);
1468 }
1469
1470 void Systray::OnExit( wxCommandEvent& event )
1471 {
1472     p_main_interface->Close(TRUE);
1473 }
1474
1475 void Systray::OnPrevStream( wxCommandEvent& event )
1476 {
1477     p_main_interface->PrevStream();
1478 }
1479
1480 void Systray::OnNextStream( wxCommandEvent& event )
1481 {
1482     p_main_interface->NextStream();
1483 }
1484
1485 void Systray::OnPlayStream( wxCommandEvent& event )
1486 {
1487     p_main_interface->PlayStream();
1488 }
1489
1490 void Systray::OnStopStream( wxCommandEvent& event )
1491 {
1492     p_main_interface->StopStream();
1493 }
1494
1495 /* Systray popup menu */
1496 wxMenu* Systray::CreatePopupMenu()
1497 {
1498     int minimal = config_GetInt( p_intf, "wx-minimal" );
1499
1500     wxMenu* systray_menu = new wxMenu;
1501     systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1502     systray_menu->AppendSeparator();
1503     systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1504
1505     if (!minimal)
1506     {
1507     systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1508     systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1509     systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1510     }
1511     systray_menu->AppendSeparator();
1512     systray_menu->Append( Iconize_Event, wxU(_("Show/Hide Interface")) );
1513     return systray_menu;
1514 }
1515
1516 void Systray::UpdateTooltip( const wxChar* tooltip )
1517 {
1518     SetIcon( wxIcon( vlc16x16_xpm ), tooltip );
1519 }
1520 #endif
1521 #endif