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