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