interface.cpp 44 KB
Newer Older
gbazin's avatar
 
gbazin committed
1
2
3
/*****************************************************************************
 * interface.cpp : wxWindows plugin for vlc
 *****************************************************************************
dionoea's avatar
dionoea committed
4
 * Copyright (C) 2000-2005 VideoLAN
gbazin's avatar
gbazin committed
5
 * $Id$
gbazin's avatar
 
gbazin committed
6
 *
7
 * Authors: Gildas Bazin <gbazin@videolan.org>
gbazin's avatar
 
gbazin committed
8
9
10
11
12
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
13
 *
gbazin's avatar
 
gbazin committed
14
15
16
17
18
19
20
21
22
23
24
25
26
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
27
#include <vlc/vlc.h>
gbazin's avatar
   
gbazin committed
28
#include <vlc/aout.h>
29
#include <vlc/vout.h>
30
#include <vlc/input.h>
gbazin's avatar
   
gbazin committed
31
#include <vlc/intf.h>
gbazin's avatar
 
gbazin committed
32
33
34
35
36
37
38

#include "wxwindows.h"

/* include the toolbar graphics */
#include "bitmaps/play.xpm"
#include "bitmaps/pause.xpm"
#include "bitmaps/stop.xpm"
39
#include "bitmaps/prev.xpm"
gbazin's avatar
 
gbazin committed
40
#include "bitmaps/next.xpm"
41
#include "bitmaps/eject.xpm"
gbazin's avatar
   
gbazin committed
42
#include "bitmaps/slow.xpm"
43
#include "bitmaps/fast.xpm"
44
#include "bitmaps/playlist.xpm"
45
#include "bitmaps/speaker.xpm"
46
#include "bitmaps/speaker_mute.xpm"
gbazin's avatar
   
gbazin committed
47

48
49
#define TOOLBAR_BMP_WIDTH 16
#define TOOLBAR_BMP_HEIGHT 16
gbazin's avatar
   
gbazin committed
50

gbazin's avatar
   
gbazin committed
51
/* include the icon graphic */
Sam Hocevar's avatar
Sam Hocevar committed
52
#include "../../../share/vlc32x32.xpm"
53
/* include a small icon graphic for the systray icon */
54
#ifdef wxHAS_TASK_BAR_ICON
55
#include "../../../share/vlc16x16.xpm"
56
#endif
gbazin's avatar
   
gbazin committed
57
58
59
60

/*****************************************************************************
 * Local class declarations.
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class wxMenuExt: public wxMenu
{
public:
    /* Constructor */
    wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
                   const wxString& helpString, wxItemKind kind,
                   char *_psz_var, int _i_object_id, vlc_value_t _val,
                   int _i_val_type );

    virtual ~wxMenuExt() {};

    char *psz_var;
    int  i_val_type;
    int  i_object_id;
    vlc_value_t val;

private:

};
gbazin's avatar
   
gbazin committed
80

81
82
class wxVolCtrl;
class VLCVolCtrl : public wxControl
gbazin's avatar
   
gbazin committed
83
84
{
public:
85
86
    VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
    virtual ~VLCVolCtrl() {};
gbazin's avatar
   
gbazin committed
87

88
89
    virtual void OnPaint( wxPaintEvent &event );
    void OnChange( wxMouseEvent& event );
90
    void UpdateVolume();
gbazin's avatar
   
gbazin committed
91

92
93
  private:
    DECLARE_EVENT_TABLE()
gbazin's avatar
   
gbazin committed
94

95
96
    wxVolCtrl *gauge;
    int i_y_offset;
gbazin's avatar
   
gbazin committed
97
98
99
    intf_thread_t *p_intf;
};

100
101
102
BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
   EVT_PAINT(VLCVolCtrl::OnPaint)

gbazin's avatar
   
gbazin committed
103
    /* Mouse events */
104
    EVT_LEFT_UP(VLCVolCtrl::OnChange)
gbazin's avatar
   
gbazin committed
105
106
END_EVENT_TABLE()

gbazin's avatar
 
gbazin committed
107
108
109
110
/*****************************************************************************
 * Event Table.
 *****************************************************************************/

gbazin's avatar
gbazin committed
111
112
DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );

gbazin's avatar
 
gbazin committed
113
114
115
116
/* IDs for the controls and the menu commands */
enum
{
    /* menu items */
zorglub's avatar
zorglub committed
117
    MenuDummy_Event = wxID_HIGHEST + 1000,
gbazin's avatar
   
gbazin committed
118
    Exit_Event = wxID_HIGHEST,
gbazin's avatar
   
gbazin committed
119
    OpenFileSimple_Event,
zorglub's avatar
zorglub committed
120
    OpenAdv_Event,
gbazin's avatar
 
gbazin committed
121
    OpenFile_Event,
122
    OpenDir_Event,
gbazin's avatar
 
gbazin committed
123
124
    OpenDisc_Event,
    OpenNet_Event,
gbazin's avatar
gbazin committed
125
    OpenCapture_Event,
gbazin's avatar
 
gbazin committed
126
    OpenSat_Event,
zorglub's avatar
zorglub committed
127
    OpenOther_Event,
gbazin's avatar
 
gbazin committed
128
129
    EjectDisc_Event,

130
    Wizard_Event,
zorglub's avatar
zorglub committed
131

132
    Playlist_Event,
gbazin's avatar
 
gbazin committed
133
    Logs_Event,
134
    FileInfo_Event,
gbazin's avatar
 
gbazin committed
135
136

    Prefs_Event,
gbazin's avatar
gbazin committed
137
    Extended_Event,
138
//    Undock_Event,
gbazin's avatar
gbazin committed
139
    Bookmarks_Event,
gbazin's avatar
   
gbazin committed
140
    Skins_Event,
gbazin's avatar
 
gbazin committed
141
142
143
144
145

    SliderScroll_Event,
    StopStream_Event,
    PlayStream_Event,
    PrevStream_Event,
gbazin's avatar
   
gbazin committed
146
    NextStream_Event,
gbazin's avatar
   
gbazin committed
147
148
    SlowStream_Event,
    FastStream_Event,
gbazin's avatar
 
gbazin committed
149

150
151
152
153
    DiscMenu_Event,
    DiscPrev_Event,
    DiscNext_Event,

gbazin's avatar
 
gbazin committed
154
155
156
    /* it is important for the id corresponding to the "About" command to have
     * this standard value as otherwise it won't be handled properly under Mac
     * (where it is special and put into the "Apple" menu) */
157
158
159
    About_Event = wxID_ABOUT,

    Iconize_Event
gbazin's avatar
 
gbazin committed
160
161
162
163
164
165
};

BEGIN_EVENT_TABLE(Interface, wxFrame)
    /* Menu events */
    EVT_MENU(Exit_Event, Interface::OnExit)
    EVT_MENU(About_Event, Interface::OnAbout)
gbazin's avatar
   
gbazin committed
166
167
168
169
170

    EVT_MENU(Playlist_Event, Interface::OnShowDialog)
    EVT_MENU(Logs_Event, Interface::OnShowDialog)
    EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
    EVT_MENU(Prefs_Event, Interface::OnShowDialog)
gbazin's avatar
   
gbazin committed
171

gbazin's avatar
   
gbazin committed
172
173
    EVT_MENU_OPEN(Interface::OnMenuOpen)

174
175
    EVT_MENU( Extended_Event, Interface::OnExtended )
//    EVT_MENU( Undock_Event, Interface::OnUndock )
zorglub's avatar
zorglub committed
176

177
    EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
zorglub's avatar
zorglub committed
178

gbazin's avatar
   
gbazin committed
179
#if defined( __WXMSW__ ) || defined( __WXMAC__ )
gbazin's avatar
   
gbazin committed
180
    EVT_CONTEXT_MENU(Interface::OnContextMenu2)
gbazin's avatar
   
gbazin committed
181
#endif
gbazin's avatar
   
gbazin committed
182
    EVT_RIGHT_UP(Interface::OnContextMenu)
gbazin's avatar
   
gbazin committed
183

gbazin's avatar
 
gbazin committed
184
    /* Toolbar events */
gbazin's avatar
   
gbazin committed
185
    EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
zorglub's avatar
zorglub committed
186
    EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
gbazin's avatar
   
gbazin committed
187
    EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
188
    EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
gbazin's avatar
   
gbazin committed
189
190
    EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
    EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
gbazin's avatar
gbazin committed
191
    EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
gbazin's avatar
   
gbazin committed
192
    EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
193
    EVT_MENU(Wizard_Event, Interface::OnShowDialog)
gbazin's avatar
 
gbazin committed
194
195
196
197
    EVT_MENU(StopStream_Event, Interface::OnStopStream)
    EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
    EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
    EVT_MENU(NextStream_Event, Interface::OnNextStream)
gbazin's avatar
   
gbazin committed
198
199
    EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
    EVT_MENU(FastStream_Event, Interface::OnFastStream)
gbazin's avatar
   
gbazin committed
200

201
202
203
204
205
    /* Disc Buttons events */
    EVT_BUTTON(DiscMenu_Event, Interface::OnDiscMenu)
    EVT_BUTTON(DiscPrev_Event, Interface::OnDiscPrev)
    EVT_BUTTON(DiscNext_Event, Interface::OnDiscNext)

gbazin's avatar
 
gbazin committed
206
207
    /* Slider events */
    EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
zorglub's avatar
zorglub committed
208

gbazin's avatar
gbazin committed
209
    /* Custom events */
210
211
    EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
    EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
zorglub's avatar
zorglub committed
212
213

    EVT_TIMER(ID_CONTROLS_TIMER, Interface::OnControlsTimer)
zorglub's avatar
zorglub committed
214
    EVT_TIMER(ID_SLIDER_TIMER, Interface::OnSliderTimer)
gbazin's avatar
 
gbazin committed
215
216
217
218
219
END_EVENT_TABLE()

/*****************************************************************************
 * Constructor.
 *****************************************************************************/
220
Interface::Interface( intf_thread_t *_p_intf, long style ):
gbazin's avatar
   
gbazin committed
221
    wxFrame( NULL, -1, wxT("VLC media player"),
222
             wxDefaultPosition, wxSize(700,100), style )
gbazin's avatar
 
gbazin committed
223
224
225
{
    /* Initializations */
    p_intf = _p_intf;
gbazin's avatar
   
gbazin committed
226
    i_old_playing_status = PAUSE_S;
zorglub's avatar
zorglub committed
227
    b_extra = VLC_FALSE;
228
229
//    b_undock = VLC_FALSE;

230

231
    extra_window = NULL;
gbazin's avatar
 
gbazin committed
232

gbazin's avatar
   
gbazin committed
233
    /* Give our interface a nice little icon */
234
    SetIcon( wxIcon( vlc_xpm ) );
gbazin's avatar
   
gbazin committed
235
236

    /* Create a sizer for the main frame */
zorglub's avatar
zorglub committed
237
    frame_sizer = new wxBoxSizer( wxVERTICAL );
gbazin's avatar
   
gbazin committed
238
239
    SetSizer( frame_sizer );

240
241
242
243
    /* Create a dummy widget that can get the keyboard focus */
    wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
                                      wxSize(0,0) );
    p_dummy->SetFocus();
244
    frame_sizer->Add( p_dummy, 0, 0 );
zorglub's avatar
zorglub committed
245

246
#ifdef wxHAS_TASK_BAR_ICON
247
248
249
250
    /* Systray integration */
    p_systray = NULL;
    if ( config_GetInt( p_intf, "wxwin-systray" ) )
    {
251
        p_systray = new Systray(this, p_intf);
252
        p_systray->SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
253
254
255
256
257
        if ( (! p_systray->IsOk()) || (! p_systray->IsIconInstalled()) )
        {
            msg_Warn(p_intf, "Cannot set systray icon, weird things may happen");
        }
    }
258
#endif
259

gbazin's avatar
   
gbazin committed
260
261
262
263
264
265
    /* Creation of the menu bar */
    CreateOurMenuBar();

    /* Creation of the tool bar */
    CreateOurToolBar();

zorglub's avatar
zorglub committed
266
    /* Create the extra panel */
267
    extra_frame = new ExtraPanel( p_intf, this );
zorglub's avatar
zorglub committed
268
269
270
    frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
    frame_sizer->Hide( extra_frame );

271
    /* Creation of the status bar
gbazin's avatar
   
gbazin committed
272
273
     * Helptext for menu items and toolbar tools will automatically get
     * displayed here. */
gbazin's avatar
   
gbazin committed
274
275
276
277
278
    int i_status_width[3] = {-6, -2, -9};
    statusbar = CreateStatusBar( 3 );                            /* 2 fields */
    statusbar->SetStatusWidths( 3, i_status_width );
    statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );

gbazin's avatar
gbazin committed
279
    /* Video window */
280
    video_window = 0;
gbazin's avatar
gbazin committed
281
282
    if( config_GetInt( p_intf, "wxwin-embed" ) )
    {
283
284
        video_window = CreateVideoWindow( p_intf, this );
        frame_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
gbazin's avatar
gbazin committed
285
286
    }

287
288
289
290
291
292
293
294
    /* Creation of the slider sub-window */
    CreateOurSlider();
    frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
    frame_sizer->Hide( slider_frame );

    /* Make sure we've got the right background colour */
    SetBackgroundColour( slider_frame->GetBackgroundColour() );

gbazin's avatar
   
gbazin committed
295
296
    /* Layout everything */
    frame_sizer->Layout();
gbazin's avatar
   
gbazin committed
297
    frame_sizer->Fit(this);
gbazin's avatar
   
gbazin committed
298

299
#if wxUSE_DRAG_AND_DROP
gbazin's avatar
   
gbazin committed
300
301
    /* Associate drop targets with the main interface */
    SetDropTarget( new DragAndDrop( p_intf ) );
gbazin's avatar
   
gbazin committed
302
#endif
303

304
    SetupHotkeys();
gbazin's avatar
   
gbazin committed
305

zorglub's avatar
zorglub committed
306
    m_controls_timer.SetOwner(this, ID_CONTROLS_TIMER);
zorglub's avatar
zorglub committed
307
    m_slider_timer.SetOwner(this, ID_SLIDER_TIMER);
zorglub's avatar
zorglub committed
308

gbazin's avatar
   
gbazin committed
309
310
    /* Start timer */
    timer = new Timer( p_intf, this );
311
312
313
314
315
316
317
318
319
320
321

    /* */
    WindowSettings *ws = p_intf->p_sys->p_window_settings;
    wxPoint p;
    wxSize  s;
    bool    b_shown;

    ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
                   wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );

    if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) )
322
        Move( p );
gbazin's avatar
   
gbazin committed
323
324
325
326
}

Interface::~Interface()
{
327
328
329
330
331
    WindowSettings *ws = p_intf->p_sys->p_window_settings;

    ws->SetSettings( WindowSettings::ID_MAIN, true,
                     GetPosition(), GetSize() );

332
333
    if( video_window ) delete video_window;

334
#ifdef wxHAS_TASK_BAR_ICON
335
    if( p_systray ) delete p_systray;
336
#endif
337

338
    if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
gbazin's avatar
   
gbazin committed
339

gbazin's avatar
   
gbazin committed
340
    /* Clean up */
gbazin's avatar
   
gbazin committed
341
    delete timer;
gbazin's avatar
   
gbazin committed
342
}
gbazin's avatar
 
gbazin committed
343

344
345
346
347
348
349
void Interface::Init()
{
    /* Misc init */
    SetupHotkeys();
}

350
351
352
void Interface::Update()
{
    /* Misc updates */
353
    ((VLCVolCtrl *)volctrl)->UpdateVolume();
354
    
355
356
}

357
void Interface::OnControlEvent( wxCommandEvent& event )
gbazin's avatar
gbazin committed
358
{
359
360
361
    switch( event.GetId() )
    {
    case 0:
zorglub's avatar
zorglub committed
362
        {
363
          if( p_intf->p_sys->b_video_autosize )
zorglub's avatar
zorglub committed
364
          {
365
366
        frame_sizer->Layout();
        frame_sizer->Fit(this);
zorglub's avatar
zorglub committed
367
368
          }
        }
369
370
371
372
373
374
375
376
377
        break;

    case 1:
        long i_style = GetWindowStyle();
        if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
        else i_style &= ~wxSTAY_ON_TOP;
        SetWindowStyle( i_style );
        break;
    }
gbazin's avatar
gbazin committed
378
379
}

gbazin's avatar
   
gbazin committed
380
381
382
383
384
/*****************************************************************************
 * Private methods.
 *****************************************************************************/
void Interface::CreateOurMenuBar()
{
385
386
    int minimal = config_GetInt( p_intf, "wxwin-minimal" );

gbazin's avatar
   
gbazin committed
387
    /* Create the "File" menu */
gbazin's avatar
 
gbazin committed
388
    wxMenu *file_menu = new wxMenu;
389
390
391

    if (!minimal)
    {
392
    file_menu->Append( OpenFileSimple_Event,
gbazin's avatar
gbazin committed
393
                       wxU(_("Quick &Open File...\tCtrl-O")) );
zorglub's avatar
zorglub committed
394
395

    file_menu->AppendSeparator();
gbazin's avatar
gbazin committed
396
    file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
397
    file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
gbazin's avatar
gbazin committed
398
    file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
399
    file_menu->Append( OpenNet_Event,
gbazin's avatar
gbazin committed
400
401
                       wxU(_("Open &Network Stream...\tCtrl-N")) );
    file_menu->Append( OpenCapture_Event,
402
                       wxU(_("Open C&apture Device...\tCtrl-A")) );
zorglub's avatar
zorglub committed
403

gbazin's avatar
 
gbazin committed
404
    file_menu->AppendSeparator();
405
    file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
gbazin's avatar
 
gbazin committed
406
    file_menu->AppendSeparator();
407
    }
gbazin's avatar
gbazin committed
408
    file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
gbazin's avatar
 
gbazin committed
409

gbazin's avatar
   
gbazin committed
410
    /* Create the "View" menu */
gbazin's avatar
 
gbazin committed
411
    wxMenu *view_menu = new wxMenu;
412
413
    if (!minimal)
    {
gbazin's avatar
gbazin committed
414
    view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
415
    }
gbazin's avatar
gbazin committed
416
    view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
417
    view_menu->Append( FileInfo_Event,
gbazin's avatar
gbazin committed
418
                       wxU(_("Stream and Media &info...\tCtrl-I")) );
gbazin's avatar
 
gbazin committed
419

420
421
422
423
424
    /* Create the "Auto-generated" menus */
    p_settings_menu = SettingsMenu( p_intf, this );
    p_audio_menu = AudioMenu( p_intf, this );
    p_video_menu = VideoMenu( p_intf, this );
    p_navig_menu = NavigMenu( p_intf, this );
gbazin's avatar
   
gbazin committed
425

gbazin's avatar
   
gbazin committed
426
    /* Create the "Help" menu */
gbazin's avatar
 
gbazin committed
427
    wxMenu *help_menu = new wxMenu;
gbazin's avatar
gbazin committed
428
    help_menu->Append( About_Event, wxU(_("About VLC media player")) );
gbazin's avatar
 
gbazin committed
429
430

    /* Append the freshly created menus to the menu bar... */
431
    wxMenuBar *menubar = new wxMenuBar();
gbazin's avatar
   
gbazin committed
432
433
    menubar->Append( file_menu, wxU(_("&File")) );
    menubar->Append( view_menu, wxU(_("&View")) );
gbazin's avatar
   
gbazin committed
434
    menubar->Append( p_settings_menu, wxU(_("&Settings")) );
gbazin's avatar
   
gbazin committed
435
436
    menubar->Append( p_audio_menu, wxU(_("&Audio")) );
    menubar->Append( p_video_menu, wxU(_("&Video")) );
gbazin's avatar
   
gbazin committed
437
    menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
gbazin's avatar
   
gbazin committed
438
    menubar->Append( help_menu, wxU(_("&Help")) );
gbazin's avatar
 
gbazin committed
439
440
441
442

    /* Attach the menu bar to the frame */
    SetMenuBar( menubar );

443
444
    /* Find out size of menu bar */
    int i_size = 0;
445
    for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
446
447
448
    {
        int i_width, i_height;
        menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
449
450
        i_size += i_width +
#if defined(__WXGTK__)
451
            22 /* approximate margin */;
452
#else
453
#if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
454
            4 /* approximate margin */;
455
#else
456
            18 /* approximate margin */;
457
#endif
458
#endif
459
460
461
    }
    frame_sizer->SetMinSize( i_size, -1 );

gbazin's avatar
   
gbazin committed
462
463
464
    /* Intercept all menu events in our custom event handler */
    PushEventHandler( new MenuEvtHandler( p_intf, this ) );

465
#if wxUSE_DRAG_AND_DROP
gbazin's avatar
   
gbazin committed
466
467
    /* Associate drop targets with the menubar */
    menubar->SetDropTarget( new DragAndDrop( p_intf ) );
gbazin's avatar
   
gbazin committed
468
#endif
gbazin's avatar
   
gbazin committed
469
470
471
472
}

void Interface::CreateOurToolBar()
{
473
#define HELP_OPEN N_("Open")
hartman's avatar
hartman committed
474
475
476
477
#define HELP_STOP N_("Stop")
#define HELP_PLAY N_("Play")
#define HELP_PAUSE N_("Pause")
#define HELP_PLO N_("Playlist")
gbazin's avatar
 
gbazin committed
478
479
#define HELP_PLP N_("Previous playlist item")
#define HELP_PLN N_("Next playlist item")
gbazin's avatar
   
gbazin committed
480
481
#define HELP_SLOW N_("Play slower")
#define HELP_FAST N_("Play faster")
gbazin's avatar
   
gbazin committed
482

483
484
    int minimal = config_GetInt( p_intf, "wxwin-minimal" );

gbazin's avatar
   
gbazin committed
485
486
    wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
                         * version because we don't include wx.rc */
gbazin's avatar
 
gbazin committed
487

488
    wxToolBar *toolbar =
489
        CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
gbazin's avatar
 
gbazin committed
490

gbazin's avatar
   
gbazin committed
491
492
    toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );

493
494
    if (!minimal)
    {
495
496
497
    toolbar->AddTool( OpenFile_Event, wxT(""),
                      wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
    toolbar->AddSeparator();
498
    }
499
500
501
502
503

    wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
                      wxBitmap( play_xpm ), wxU(_(HELP_PLAY)) );
    p_tool->SetClientData( p_tool );

504
505
    if (!minimal)
    {
506
507
    toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
                      wxU(_(HELP_STOP)) );
gbazin's avatar
 
gbazin committed
508
    toolbar->AddSeparator();
509

gbazin's avatar
   
gbazin committed
510
    toolbar->AddTool( PrevStream_Event, wxT(""),
511
512
513
514
515
                      wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
    toolbar->AddTool( SlowStream_Event, wxT(""),
                      wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
    toolbar->AddTool( FastStream_Event, wxT(""),
                      wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
gbazin's avatar
   
gbazin committed
516
    toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
gbazin's avatar
   
gbazin committed
517
                      wxU(_(HELP_PLN)) );
518
    toolbar->AddSeparator();
519
    toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
520
                      wxU(_(HELP_PLO)) );
521
    }
gbazin's avatar
 
gbazin committed
522

523
    wxControl *p_dummy_ctrl =
524
        new wxControl( toolbar, -1, wxDefaultPosition,
525
                       wxSize(35, 16 ), wxBORDER_NONE );
526

527
    toolbar->AddControl( p_dummy_ctrl );
gbazin's avatar
 
gbazin committed
528

529
530
    volctrl = new VLCVolCtrl( p_intf, toolbar );
    toolbar->AddControl( volctrl );
531
532

    toolbar->Realize();
gbazin's avatar
   
gbazin committed
533

534
#if wxUSE_DRAG_AND_DROP
gbazin's avatar
   
gbazin committed
535
536
    /* Associate drop targets with the toolbar */
    toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
gbazin's avatar
   
gbazin committed
537
#endif
gbazin's avatar
 
gbazin committed
538
539
}

gbazin's avatar
   
gbazin committed
540
void Interface::CreateOurSlider()
gbazin's avatar
 
gbazin committed
541
{
gbazin's avatar
   
gbazin committed
542
    /* Create a new frame and sizer containing the slider */
gbazin's avatar
   
gbazin committed
543
    slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
gbazin's avatar
   
gbazin committed
544
    slider_frame->SetAutoLayout( TRUE );
545
546
    slider_sizer = new wxBoxSizer( wxHORIZONTAL );
    //slider_sizer->SetMinSize( -1, 50 );
gbazin's avatar
   
gbazin committed
547
548
549
550

    /* Create slider */
    slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
                           SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
gbazin's avatar
   
gbazin committed
551

552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
    /* Add Disc Buttons */
    disc_frame = new wxPanel( slider_frame, -1, wxDefaultPosition,
                              wxDefaultSize );
    disc_frame->SetAutoLayout( TRUE );
    disc_sizer = new wxBoxSizer( wxHORIZONTAL );

    disc_menu_button = new wxBitmapButton( disc_frame, DiscMenu_Event,
                                           wxBitmap( playlist_xpm ) );
    disc_prev_button = new wxBitmapButton( disc_frame, DiscPrev_Event,
                                           wxBitmap( prev_xpm ) );
    disc_next_button = new wxBitmapButton( disc_frame, DiscNext_Event,
                                           wxBitmap( next_xpm ) );

    disc_sizer->Add( disc_menu_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
    disc_sizer->Add( disc_prev_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
    disc_sizer->Add( disc_next_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );

    disc_frame->SetSizer( disc_sizer );
    disc_sizer->Layout();

gbazin's avatar
   
gbazin committed
572
    /* Add everything to the frame */
573
574
575
576
577
578
579
580
581
    slider_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
    slider_sizer->Add( disc_frame, 0, wxALL, 2 );
    slider_frame->SetSizer( slider_sizer );

    disc_frame->Hide();
    slider_sizer->Hide( disc_frame );

    slider_sizer->Layout();
    slider_sizer->Fit( slider_frame );
gbazin's avatar
   
gbazin committed
582
583
584

    /* Hide the slider by default */
    slider_frame->Hide();
gbazin's avatar
 
gbazin committed
585
586
}

587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
static int ConvertHotkeyModifiers( int i_hotkey )
{
    int i_accel_flags = 0;
    if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
    if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
    if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
    if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
    return i_accel_flags;
}

static int ConvertHotkey( int i_hotkey )
{
    int i_key = i_hotkey & ~KEY_MODIFIER;
    if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
    else if( i_key & KEY_SPECIAL )
    {
        switch ( i_key )
        {
        case KEY_LEFT: return WXK_LEFT;
        case KEY_RIGHT: return WXK_RIGHT;
        case KEY_UP: return WXK_UP;
        case KEY_DOWN: return WXK_DOWN;
        case KEY_SPACE: return WXK_SPACE;
        case KEY_ENTER: return WXK_RETURN;
        case KEY_F1: return WXK_F1;
        case KEY_F2: return WXK_F2;
        case KEY_F3: return WXK_F3;
        case KEY_F4: return WXK_F4;
        case KEY_F5: return WXK_F5;
        case KEY_F6: return WXK_F6;
        case KEY_F7: return WXK_F7;
        case KEY_F8: return WXK_F8;
        case KEY_F9: return WXK_F9;
        case KEY_F10: return WXK_F10;
        case KEY_F11: return WXK_F11;
        case KEY_F12: return WXK_F12;
        case KEY_HOME: return WXK_HOME;
624
625
626
        case KEY_END: return WXK_END;
        case KEY_INSERT: return WXK_INSERT;
        case KEY_DELETE: return WXK_DELETE;
627
628
629
630
631
632
633
634
635
636
637
        case KEY_MENU: return WXK_MENU;
        case KEY_ESC: return WXK_ESCAPE;
        case KEY_PAGEUP: return WXK_PRIOR;
        case KEY_PAGEDOWN: return WXK_NEXT;
        case KEY_TAB: return WXK_TAB;
        case KEY_BACKSPACE: return WXK_BACK;
        }
    }
    return WXK_F24;
}

638
void Interface::SetupHotkeys()
639
{
640
641
    struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
    int i_hotkeys;
642

643
644
645
646
647
648
    /* Count number of hoteys */
    for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );

    p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
    p_intf->p_sys->i_hotkeys = i_hotkeys;

649
    wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
650
651

    /* Setup the hotkeys as accelerators */
652
    for( int i = 0; i < i_hotkeys; i++ )
653
    {
654
655
656
657
        int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
        int i_key = ConvertHotkey( p_hotkeys[i].i_key );

#ifdef WIN32
658
659
        if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
            i_key = toupper(i_key);
660
661
662
#endif

        p_entries[i].Set( i_mod, i_key,
663
664
                          p_intf->p_sys->i_first_hotkey_event + i );
    }
zorglub's avatar
zorglub committed
665

666
    wxAcceleratorTable accel( i_hotkeys, p_entries );
zorglub's avatar
zorglub committed
667

668
669
670
671
672
673
674
675
    if( !accel.Ok() )
    {
        msg_Err( p_intf, "invalid accelerator table" );
    }
    else
    {
        SetAcceleratorTable( accel );
    }
676
677

    delete [] p_entries;
678
679
}

680
void Interface::HideSlider( bool layout )
zorglub's avatar
zorglub committed
681
{
682
    ShowSlider( false, layout );
zorglub's avatar
zorglub committed
683
684
}

685
void Interface::ShowSlider( bool show, bool layout )
zorglub's avatar
zorglub committed
686
{
687
    if( show )
688
    {
689
690
691
        //prevent the hide timers from hiding it now
        m_slider_timer.Stop();
        m_controls_timer.Stop();
692

693
694
        //prevent continuous layout
        if( slider_frame->IsShown() ) return;
695

696
697
        slider_frame->Show();
        frame_sizer->Show( slider_frame );
698
    }
699
700
701
702
    else
    {
        //prevent continuous layout
        if( !slider_frame->IsShown() ) return;
703

704
705
706
        slider_frame->Hide();
        frame_sizer->Hide( slider_frame );
    }
zorglub's avatar
zorglub committed
707

708
    if( layout )
zorglub's avatar
zorglub committed
709
    {
710
711
712
713
714
715
        frame_sizer->Layout();
        if( p_intf->p_sys->b_video_autosize )
        {
            UpdateVideoWindow( p_intf, video_window );
            frame_sizer->Fit( this );
        }
zorglub's avatar
zorglub committed
716
717
718
    }
}

719
void Interface::HideDiscFrame( bool layout )
zorglub's avatar
zorglub committed
720
{
721
    ShowDiscFrame( false, layout );
zorglub's avatar
zorglub committed
722
723
}

724
void Interface::ShowDiscFrame( bool show, bool layout )
zorglub's avatar
zorglub committed
725
{
726
    if( show )
727
    {
728
729
        //prevent the hide timer from hiding it now
        m_controls_timer.Stop();
730

731
732
        //prevent continuous layout
        if( disc_frame->IsShown() ) return;
733

734
735
        disc_frame->Show();
        slider_sizer->Show( disc_frame );
736
    }
737
738
739
740
    else
    {
        //prevent continuous layout
        if( !disc_frame->IsShown() ) return;
741

742
743
744
        disc_frame->Hide();
        slider_sizer->Hide( disc_frame );
    }
zorglub's avatar
zorglub committed
745

746
    if( layout )
zorglub's avatar
zorglub committed
747
    {
748
749
750
751
752
753
        slider_sizer->Layout();
        if( p_intf->p_sys->b_video_autosize )
        {
            UpdateVideoWindow( p_intf, video_window );
            slider_sizer->Fit( slider_frame );
        }
zorglub's avatar
zorglub committed
754
755
756
    }
}

gbazin's avatar
 
gbazin committed
757
/*****************************************************************************
gbazin's avatar
   
gbazin committed
758
 * Event Handlers.
gbazin's avatar
 
gbazin committed
759
 *****************************************************************************/
760
void Interface::OnControlsTimer( wxTimerEvent& WXUNUSED(event) )
zorglub's avatar
zorglub committed
761
{
762
763
764
765
766
767
768
769
770
771
772
773
    /* Hide slider and Disc Buttons */
    //postpone layout, we'll do it ourselves
    HideDiscFrame( false );
    HideSlider( false );

    slider_sizer->Layout();
    if( p_intf->p_sys->b_video_autosize )
    {
        slider_sizer->Fit( slider_frame );
        UpdateVideoWindow( p_intf, video_window );
        frame_sizer->Fit( this );
    }
zorglub's avatar
zorglub committed
774
}
zorglub's avatar
zorglub committed
775

776
777
778
void Interface::OnSliderTimer( wxTimerEvent& WXUNUSED(event) )
{
    HideSlider();
zorglub's avatar
zorglub committed
779
780
}

781
void Interface::OnMenuOpen( wxMenuEvent& event )
gbazin's avatar
   
gbazin committed
782
{
783
784
#if defined( __WXMSW__ )
#   define GetEventObject GetMenu
785
#endif
786
787

    if( event.GetEventObject() == p_settings_menu )
gbazin's avatar
   
gbazin committed
788
    {
789
790
791
792
        p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );

        /* Add static items */
        p_settings_menu->AppendCheckItem( Extended_Event,
793
            wxU(_("Extended &GUI\tCtrl-G") ) );
794
        if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
795
796
797
798
799
#if 0
        p_settings_menu->AppendCheckItem( Undock_Event,
            wxU(_("&Undock Ext. GUI") ) );
        if( b_undock ) p_settings_menu->Check( Undock_Event, TRUE );
#endif
800
801
802
803
        p_settings_menu->Append( Bookmarks_Event,
                                 wxU(_("&Bookmarks...\tCtrl-B") ) );
        p_settings_menu->Append( Prefs_Event,
                                 wxU(_("Preference&s...\tCtrl-S")) );
gbazin's avatar
   
gbazin committed
804
    }
805

gbazin's avatar
   
gbazin committed
806
    else if( event.GetEventObject() == p_audio_menu )
gbazin's avatar
   
gbazin committed
807
    {
808
        p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
gbazin's avatar
   
gbazin committed
809
    }
810

gbazin's avatar
   
gbazin committed
811
812
    else if( event.GetEventObject() == p_video_menu )
    {
813
        p_video_menu = VideoMenu( p_intf, this, p_video_menu );
gbazin's avatar
   
gbazin committed
814
    }
815

gbazin's avatar
   
gbazin committed
816
817
    else if( event.GetEventObject() == p_navig_menu )
    {
818
        p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
gbazin's avatar
   
gbazin committed
819
    }
820
821
822
823

#if defined( __WXMSW__ )
#   undef GetEventObject
#endif
gbazin's avatar
   
gbazin committed
824
825
}

gbazin's avatar
   
gbazin committed
826
#if defined( __WXMSW__ ) || defined( __WXMAC__ )
gbazin's avatar
   
gbazin committed
827
void Interface::OnContextMenu2(wxContextMenuEvent& event)
gbazin's avatar
   
gbazin committed
828
{
gbazin's avatar
   
gbazin committed
829
830
831
832
833
834
835
    /* Only show the context menu for the main interface */
    if( GetId() != event.GetId() )
    {
        event.Skip();
        return;
    }

gbazin's avatar
   
gbazin committed
836
    if( p_intf->p_sys->pf_show_dialog )
837
        p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
gbazin's avatar
   
gbazin committed
838
}
gbazin's avatar
   
gbazin committed
839
#endif
gbazin's avatar
   
gbazin committed
840
841
void Interface::OnContextMenu(wxMouseEvent& event)
{
gbazin's avatar
   
gbazin committed
842
    if( p_intf->p_sys->pf_show_dialog )
843
        p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
gbazin's avatar
   
gbazin committed
844
}
gbazin's avatar
   
gbazin committed
845

gbazin's avatar
 
gbazin committed
846
847
848
849
850
851
852
853
854
void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
{
    /* TRUE is to force the frame to close. */
    Close(TRUE);
}

void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
{
    wxString msg;
Sam Hocevar's avatar
Sam Hocevar committed
855
    msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
gbazin's avatar
   
gbazin committed
856
        wxU(_(" (wxWindows interface)\n\n")) +
dionoea's avatar
dionoea committed
857
        wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
zorglub's avatar
zorglub committed
858
        wxU( vlc_wraptext(INTF_ABOUT_MSG,WRAPCOUNT,ISUTF8) ) + wxT("\n\n") +
gbazin's avatar
   
gbazin committed
859
        wxU(_("The VideoLAN team <videolan@videolan.org>\n"
gbazin's avatar
   
gbazin committed
860
              "http://www.videolan.org/\n\n")) );
gbazin's avatar
   
gbazin committed
861

gbazin's avatar
   
gbazin committed
862
863
    wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
                  wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
gbazin's avatar
 
gbazin committed
864
865
}

gbazin's avatar
   
gbazin committed
866
void Interface::OnShowDialog( wxCommandEvent& event )
gbazin's avatar
   
gbazin committed
867
{
gbazin's avatar
   
gbazin committed
868
    if( p_intf->p_sys->pf_show_dialog )
gbazin's avatar
   
gbazin committed
869
    {
gbazin's avatar
   
gbazin committed
870
        int i_id;
gbazin's avatar
   
gbazin committed
871

gbazin's avatar
   
gbazin committed
872
873
874
875
876
        switch( event.GetId() )
        {
        case OpenFileSimple_Event:
            i_id = INTF_DIALOG_FILE_SIMPLE;
            break;
zorglub's avatar
zorglub committed
877
878
        case OpenAdv_Event:
            i_id = INTF_DIALOG_FILE;
gbazin's avatar
   
gbazin committed
879
880
881
        case OpenFile_Event:
            i_id = INTF_DIALOG_FILE;
            break;
882
883
884
        case OpenDir_Event:
            i_id = INTF_DIALOG_DIRECTORY;
            break;
gbazin's avatar
   
gbazin committed
885
886
887
888
889
890
        case OpenDisc_Event:
            i_id = INTF_DIALOG_DISC;
            break;
        case OpenNet_Event:
            i_id = INTF_DIALOG_NET;
            break;
gbazin's avatar
gbazin committed
891
892
893
        case OpenCapture_Event:
            i_id = INTF_DIALOG_CAPTURE;
            break;
gbazin's avatar
   
gbazin committed
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
        case OpenSat_Event:
            i_id = INTF_DIALOG_SAT;
            break;
        case Playlist_Event:
            i_id = INTF_DIALOG_PLAYLIST;
            break;
        case Logs_Event:
            i_id = INTF_DIALOG_MESSAGES;
            break;
        case FileInfo_Event:
            i_id = INTF_DIALOG_FILEINFO;
            break;
        case Prefs_Event:
            i_id = INTF_DIALOG_PREFS;
            break;
909
910
911
        case Wizard_Event:
            i_id = INTF_DIALOG_WIZARD;
            break;
gbazin's avatar
gbazin committed
912
913
914
        case Bookmarks_Event:
            i_id = INTF_DIALOG_BOOKMARKS;
            break;
gbazin's avatar
   
gbazin committed
915
916
917
918
        default:
            i_id = INTF_DIALOG_FILE;
            break;
        }
gbazin's avatar
   
gbazin committed
919

gbazin's avatar
   
gbazin committed
920
        p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
gbazin's avatar
   
gbazin committed
921
    }
gbazin's avatar
 
gbazin committed
922
923
}

gbazin's avatar
gbazin committed
924
void Interface::OnExtended(wxCommandEvent& event)
zorglub's avatar
zorglub committed
925
{
926
927
928
    b_extra = (b_extra == VLC_TRUE ? VLC_FALSE : VLC_TRUE );

    if( b_extra == VLC_FALSE )
zorglub's avatar
zorglub committed
929
    {
930
931
        extra_frame->Hide();
        frame_sizer->Hide( extra_frame );
zorglub's avatar
zorglub committed
932
933
934
    }
    else
    {