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