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