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