interface.cpp 44.6 KB
Newer Older
Gildas Bazin's avatar
 
Gildas Bazin committed
1
/*****************************************************************************
2
 * interface.cpp : wxWidgets plugin for vlc
Gildas Bazin's avatar
 
Gildas Bazin committed
3
 *****************************************************************************
4
 * Copyright (C) 2000-2005 the VideoLAN team
Gildas Bazin's avatar
Gildas Bazin committed
5
 * $Id$
Gildas Bazin's avatar
 
Gildas Bazin committed
6
 *
7
 * Authors: Gildas Bazin <gbazin@videolan.org>
Gildas Bazin's avatar
 
Gildas Bazin 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
 *
Gildas Bazin's avatar
 
Gildas Bazin 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
 *****************************************************************************/
27 28 29 30 31 32
#include "interface.hpp"
#include "extrapanel.hpp"
#include "timer.hpp"
#include "video.hpp"
#include <vlc_keys.h>

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
33
#include "charset.h"
Gildas Bazin's avatar
 
Gildas Bazin committed
34

35 36
#include <vlc/aout.h>
#include "charset.h"
Gildas Bazin's avatar
 
Gildas Bazin committed
37 38 39 40 41

/* include the toolbar graphics */
#include "bitmaps/play.xpm"
#include "bitmaps/pause.xpm"
#include "bitmaps/stop.xpm"
42
#include "bitmaps/prev.xpm"
Gildas Bazin's avatar
 
Gildas Bazin committed
43
#include "bitmaps/next.xpm"
44
#include "bitmaps/eject.xpm"
Gildas Bazin's avatar
 
Gildas Bazin committed
45
#include "bitmaps/slow.xpm"
46
#include "bitmaps/fast.xpm"
47
#include "bitmaps/playlist.xpm"
48
#include "bitmaps/speaker.xpm"
49
#include "bitmaps/speaker_mute.xpm"
Gildas Bazin's avatar
 
Gildas Bazin committed
50

51 52
#define TOOLBAR_BMP_WIDTH 16
#define TOOLBAR_BMP_HEIGHT 16
Gildas Bazin's avatar
 
Gildas Bazin committed
53

Gildas Bazin's avatar
 
Gildas Bazin committed
54
/* include the icon graphic */
Sam Hocevar's avatar
Sam Hocevar committed
55
#include "../../../share/vlc32x32.xpm"
56
/* include a small icon graphic for the systray icon */
57
#ifdef wxHAS_TASK_BAR_ICON
58
#include "../../../share/vlc16x16.xpm"
59
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
60 61 62 63

/*****************************************************************************
 * Local class declarations.
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
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:

};
Gildas Bazin's avatar
 
Gildas Bazin committed
83

84 85
class wxVolCtrl;
class VLCVolCtrl : public wxControl
Gildas Bazin's avatar
 
Gildas Bazin committed
86 87
{
public:
88 89
    VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
    virtual ~VLCVolCtrl() {};
Gildas Bazin's avatar
 
Gildas Bazin committed
90

91 92
    virtual void OnPaint( wxPaintEvent &event );
    void OnChange( wxMouseEvent& event );
93
    void UpdateVolume();
Gildas Bazin's avatar
 
Gildas Bazin committed
94

95
  private:
96
    DECLARE_EVENT_TABLE()
Gildas Bazin's avatar
 
Gildas Bazin committed
97

98 99
    wxVolCtrl *gauge;
    int i_y_offset;
100
    vlc_bool_t b_mute;
Gildas Bazin's avatar
 
Gildas Bazin committed
101 102 103
    intf_thread_t *p_intf;
};

104
BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
105
   EVT_PAINT(VLCVolCtrl::OnPaint)
106

Gildas Bazin's avatar
 
Gildas Bazin committed
107
    /* Mouse events */
108
    EVT_LEFT_UP(VLCVolCtrl::OnChange)
Gildas Bazin's avatar
 
Gildas Bazin committed
109 110
END_EVENT_TABLE()

Gildas Bazin's avatar
 
Gildas Bazin committed
111 112 113 114
/*****************************************************************************
 * Event Table.
 *****************************************************************************/

Gildas Bazin's avatar
Gildas Bazin committed
115 116
DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );

Gildas Bazin's avatar
 
Gildas Bazin committed
117 118 119 120
/* IDs for the controls and the menu commands */
enum
{
    /* menu items */
121
    MenuDummy_Event = wxID_HIGHEST + 1000,
Gildas Bazin's avatar
 
Gildas Bazin committed
122
    Exit_Event = wxID_HIGHEST,
Gildas Bazin's avatar
 
Gildas Bazin committed
123
    OpenFileSimple_Event,
124
    OpenAdv_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
125
    OpenFile_Event,
126
    OpenDir_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
127 128
    OpenDisc_Event,
    OpenNet_Event,
Gildas Bazin's avatar
Gildas Bazin committed
129
    OpenCapture_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
130
    OpenSat_Event,
131
    OpenOther_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
132 133
    EjectDisc_Event,

134
    Wizard_Event,
135

136
    Playlist_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
137
    Logs_Event,
138
    FileInfo_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
139 140

    Prefs_Event,
Gildas Bazin's avatar
Gildas Bazin committed
141
    Extended_Event,
142
//    Undock_Event,
Gildas Bazin's avatar
Gildas Bazin committed
143
    Bookmarks_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
144
    Skins_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
145 146 147 148 149

    SliderScroll_Event,
    StopStream_Event,
    PlayStream_Event,
    PrevStream_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
150
    NextStream_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
151 152
    SlowStream_Event,
    FastStream_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
153

154 155 156 157
    DiscMenu_Event,
    DiscPrev_Event,
    DiscNext_Event,

Gildas Bazin's avatar
 
Gildas Bazin committed
158 159 160
    /* 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) */
161
    About_Event = wxID_ABOUT,
162
    UpdateVLC_Event,
163
    VLM_Event,
164 165

    Iconize_Event
Gildas Bazin's avatar
 
Gildas Bazin committed
166 167 168 169 170 171
};

BEGIN_EVENT_TABLE(Interface, wxFrame)
    /* Menu events */
    EVT_MENU(Exit_Event, Interface::OnExit)
    EVT_MENU(About_Event, Interface::OnAbout)
172
    EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
173
    EVT_MENU(VLM_Event, Interface::OnShowDialog)
Gildas Bazin's avatar
 
Gildas Bazin committed
174 175 176 177 178

    EVT_MENU(Playlist_Event, Interface::OnShowDialog)
    EVT_MENU(Logs_Event, Interface::OnShowDialog)
    EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
    EVT_MENU(Prefs_Event, Interface::OnShowDialog)
Gildas Bazin's avatar
 
Gildas Bazin committed
179

Gildas Bazin's avatar
 
Gildas Bazin committed
180 181
    EVT_MENU_OPEN(Interface::OnMenuOpen)

182 183
    EVT_MENU( Extended_Event, Interface::OnExtended )
//    EVT_MENU( Undock_Event, Interface::OnUndock )
Clément Stenac's avatar
Clément Stenac committed
184

185
    EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
Clément Stenac's avatar
Clément Stenac committed
186

Gildas Bazin's avatar
 
Gildas Bazin committed
187
#if defined( __WXMSW__ ) || defined( __WXMAC__ )
Gildas Bazin's avatar
 
Gildas Bazin committed
188
    EVT_CONTEXT_MENU(Interface::OnContextMenu2)
Gildas Bazin's avatar
 
Gildas Bazin committed
189
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
190
    EVT_RIGHT_UP(Interface::OnContextMenu)
Gildas Bazin's avatar
 
Gildas Bazin committed
191

Gildas Bazin's avatar
 
Gildas Bazin committed
192
    /* Toolbar events */
Gildas Bazin's avatar
 
Gildas Bazin committed
193
    EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
194
    EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
Gildas Bazin's avatar
 
Gildas Bazin committed
195
    EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
196
    EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
Gildas Bazin's avatar
 
Gildas Bazin committed
197 198
    EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
    EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
Gildas Bazin's avatar
Gildas Bazin committed
199
    EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
Gildas Bazin's avatar
 
Gildas Bazin committed
200
    EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
201
    EVT_MENU(Wizard_Event, Interface::OnShowDialog)
Gildas Bazin's avatar
 
Gildas Bazin committed
202 203 204 205
    EVT_MENU(StopStream_Event, Interface::OnStopStream)
    EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
    EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
    EVT_MENU(NextStream_Event, Interface::OnNextStream)
Gildas Bazin's avatar
 
Gildas Bazin committed
206 207
    EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
    EVT_MENU(FastStream_Event, Interface::OnFastStream)
Gildas Bazin's avatar
 
Gildas Bazin committed
208

209 210 211 212 213
    /* Disc Buttons events */
    EVT_BUTTON(DiscMenu_Event, Interface::OnDiscMenu)
    EVT_BUTTON(DiscPrev_Event, Interface::OnDiscPrev)
    EVT_BUTTON(DiscNext_Event, Interface::OnDiscNext)

Gildas Bazin's avatar
 
Gildas Bazin committed
214 215
    /* Slider events */
    EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
Clément Stenac's avatar
Clément Stenac committed
216

Gildas Bazin's avatar
Gildas Bazin committed
217
    /* Custom events */
218 219
    EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
    EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
Clément Stenac's avatar
Clément Stenac committed
220 221

    EVT_TIMER(ID_CONTROLS_TIMER, Interface::OnControlsTimer)
Clément Stenac's avatar
Clément Stenac committed
222
    EVT_TIMER(ID_SLIDER_TIMER, Interface::OnSliderTimer)
Gildas Bazin's avatar
 
Gildas Bazin committed
223 224 225 226 227
END_EVENT_TABLE()

/*****************************************************************************
 * Constructor.
 *****************************************************************************/
228
Interface::Interface( intf_thread_t *_p_intf, long style ):
Gildas Bazin's avatar
 
Gildas Bazin committed
229
    wxFrame( NULL, -1, wxT("VLC media player"),
230
             wxDefaultPosition, wxSize(700,100), style )
Gildas Bazin's avatar
 
Gildas Bazin committed
231 232 233
{
    /* Initializations */
    p_intf = _p_intf;
Gildas Bazin's avatar
 
Gildas Bazin committed
234
    i_old_playing_status = PAUSE_S;
Clément Stenac's avatar
Clément Stenac committed
235
    b_extra = VLC_FALSE;
236 237
//    b_undock = VLC_FALSE;

238

239
    extra_window = NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
240

Gildas Bazin's avatar
 
Gildas Bazin committed
241
    /* Give our interface a nice little icon */
Benjamin Pracht's avatar
Benjamin Pracht committed
242
    SetIcon( wxIcon( vlc32x32_xpm ) );
Gildas Bazin's avatar
 
Gildas Bazin committed
243 244

    /* Create a sizer for the main frame */
Clément Stenac's avatar
Clément Stenac committed
245
    frame_sizer = new wxBoxSizer( wxVERTICAL );
Gildas Bazin's avatar
 
Gildas Bazin committed
246 247
    SetSizer( frame_sizer );

248 249 250
    /* Create a dummy widget that can get the keyboard focus */
    wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
                                      wxSize(0,0) );
251 252 253 254
#if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
    /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
     * Accelerators bug. */
    p_dummy->m_imData = 0;
255
    m_imData = 0;
256
#endif
257
    p_dummy->SetFocus();
258
    frame_sizer->Add( p_dummy, 0, 0 );
Clément Stenac's avatar
Clément Stenac committed
259

260
#ifdef wxHAS_TASK_BAR_ICON
261 262
    /* Systray integration */
    p_systray = NULL;
263
    if ( config_GetInt( p_intf, "wx-systray" ) )
264
    {
265
        p_systray = new Systray(this, p_intf);
266
        p_systray->SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
267 268 269 270 271
        if ( (! p_systray->IsOk()) || (! p_systray->IsIconInstalled()) )
        {
            msg_Warn(p_intf, "Cannot set systray icon, weird things may happen");
        }
    }
272
#endif
273

Gildas Bazin's avatar
 
Gildas Bazin committed
274 275 276 277 278 279
    /* Creation of the menu bar */
    CreateOurMenuBar();

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

Clément Stenac's avatar
Clément Stenac committed
280
    /* Create the extra panel */
281
    extra_frame = new ExtraPanel( p_intf, this );
Clément Stenac's avatar
Clément Stenac committed
282 283 284
    frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
    frame_sizer->Hide( extra_frame );

285
    /* Creation of the status bar
Gildas Bazin's avatar
 
Gildas Bazin committed
286 287
     * Helptext for menu items and toolbar tools will automatically get
     * displayed here. */
Gildas Bazin's avatar
 
Gildas Bazin committed
288 289 290 291 292
    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 );

Gildas Bazin's avatar
Gildas Bazin committed
293
    /* Video window */
294
    video_window = 0;
295
    if( config_GetInt( p_intf, "wx-embed" ) )
Gildas Bazin's avatar
Gildas Bazin committed
296
    {
297 298
        video_window = CreateVideoWindow( p_intf, this );
        frame_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
Gildas Bazin's avatar
Gildas Bazin committed
299 300
    }

301 302 303 304 305 306 307 308
    /* 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() );

Gildas Bazin's avatar
 
Gildas Bazin committed
309 310
    /* Layout everything */
    frame_sizer->Layout();
Gildas Bazin's avatar
 
Gildas Bazin committed
311
    frame_sizer->Fit(this);
Gildas Bazin's avatar
 
Gildas Bazin committed
312

313
#if wxUSE_DRAG_AND_DROP
Gildas Bazin's avatar
 
Gildas Bazin committed
314 315
    /* Associate drop targets with the main interface */
    SetDropTarget( new DragAndDrop( p_intf ) );
Gildas Bazin's avatar
 
Gildas Bazin committed
316
#endif
317

318
    SetupHotkeys();
Gildas Bazin's avatar
 
Gildas Bazin committed
319

Clément Stenac's avatar
Clément Stenac committed
320
    m_controls_timer.SetOwner(this, ID_CONTROLS_TIMER);
Clément Stenac's avatar
Clément Stenac committed
321
    m_slider_timer.SetOwner(this, ID_SLIDER_TIMER);
Clément Stenac's avatar
Clément Stenac committed
322

Gildas Bazin's avatar
 
Gildas Bazin committed
323 324
    /* Start timer */
    timer = new Timer( p_intf, this );
325 326 327 328 329 330 331 332 333 334 335

    /* */
    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 ) )
336
        Move( p );
337 338

    /* Set minimum window size to prevent user from glitching it */
339
    wxSize  s2;
340
    s = GetSize();
341 342 343 344 345 346 347 348 349 350 351 352 353 354

    /* save smallest possible default minimum size */
    default_size = GetSize();

    /* save slider size for height only for MinSizing */
    slider_size = slider_sizer->GetSize();

    /* and save extended gui size for MinSize scheme */
    s2 = extra_frame->GetSize();
    s2.SetWidth( s2.GetWidth() +
                2 * wxSystemSettings::GetMetric( wxSYS_FRAMESIZE_X ) );
    extended_size = s2;

    /* Set initial minimum window size */
355 356 357 358 359
    if( config_GetInt( p_intf, "wx-embed" ) )
    {
        s2 = video_window->GetSize();
        s.SetHeight( s.GetHeight() - s2.GetHeight() );
    }
360 361 362 363 364
    if( config_GetInt( p_intf, "wx-extended" ) )
    {
        s.SetWidth( extended_size.GetWidth() );
        s.SetHeight( s.GetHeight() + extended_size.GetHeight() );
    }
365
#if (wxCHECK_VERSION(2,5,4))
366
    SetMinSize( s );
367 368 369
#else
    frame_sizer->SetMinSize( s );
#endif
370 371 372 373

    /* Show extended GUI if requested */
    if( ( b_extra = config_GetInt( p_intf, "wx-extended" ) ) )
        frame_sizer->Show( extra_frame );
Gildas Bazin's avatar
 
Gildas Bazin committed
374 375 376 377
}

Interface::~Interface()
{
378 379
    WindowSettings *ws = p_intf->p_sys->p_window_settings;

380 381 382 383 384
    if( !IsIconized() )
    {
        ws->SetSettings( WindowSettings::ID_MAIN, true,
                         GetPosition(), GetSize() );
    }
385

386
    PopEventHandler(true);
387

388 389
    if( video_window ) delete video_window;

390
#ifdef wxHAS_TASK_BAR_ICON
391
    if( p_systray ) delete p_systray;
392
#endif
393

394
    if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
Gildas Bazin's avatar
 
Gildas Bazin committed
395

Gildas Bazin's avatar
 
Gildas Bazin committed
396
    /* Clean up */
Gildas Bazin's avatar
 
Gildas Bazin committed
397
    delete timer;
Gildas Bazin's avatar
 
Gildas Bazin committed
398
}
Gildas Bazin's avatar
 
Gildas Bazin committed
399

400 401 402
void Interface::Init()
{
    /* Misc init */
403
    SetupHotkeys();
404 405
}

406 407 408
void Interface::Update()
{
    /* Misc updates */
409
    ((VLCVolCtrl *)volctrl)->UpdateVolume();
410 411
}

412
void Interface::OnControlEvent( wxCommandEvent& event )
Gildas Bazin's avatar
Gildas Bazin committed
413
{
414 415 416
    switch( event.GetId() )
    {
    case 0:
Clément Stenac's avatar
Clément Stenac committed
417
        {
418
          if( p_intf->p_sys->b_video_autosize )
Clément Stenac's avatar
Clément Stenac committed
419
          {
420 421
        frame_sizer->Layout();
        frame_sizer->Fit(this);
Clément Stenac's avatar
Clément Stenac committed
422 423
          }
        }
424 425 426 427 428 429 430 431 432
        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;
    }
Gildas Bazin's avatar
Gildas Bazin committed
433 434
}

Gildas Bazin's avatar
 
Gildas Bazin committed
435 436 437 438 439
/*****************************************************************************
 * Private methods.
 *****************************************************************************/
void Interface::CreateOurMenuBar()
{
440
    int minimal = config_GetInt( p_intf, "wx-minimal" );
441

Gildas Bazin's avatar
 
Gildas Bazin committed
442
    /* Create the "File" menu */
Gildas Bazin's avatar
 
Gildas Bazin committed
443
    wxMenu *file_menu = new wxMenu;
444 445 446

    if (!minimal)
    {
447
    file_menu->Append( OpenFileSimple_Event,
Gildas Bazin's avatar
Gildas Bazin committed
448
                       wxU(_("Quick &Open File...\tCtrl-O")) );
449 450

    file_menu->AppendSeparator();
Gildas Bazin's avatar
Gildas Bazin committed
451
    file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
452
    file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
Gildas Bazin's avatar
Gildas Bazin committed
453
    file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
454
    file_menu->Append( OpenNet_Event,
Gildas Bazin's avatar
Gildas Bazin committed
455 456
                       wxU(_("Open &Network Stream...\tCtrl-N")) );
    file_menu->Append( OpenCapture_Event,
457
                       wxU(_("Open C&apture Device...\tCtrl-A")) );
458

Gildas Bazin's avatar
 
Gildas Bazin committed
459
    file_menu->AppendSeparator();
460
    file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
461
    file_menu->AppendSeparator();
462
    }
Gildas Bazin's avatar
Gildas Bazin committed
463
    file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
464

Gildas Bazin's avatar
 
Gildas Bazin committed
465
    /* Create the "View" menu */
Gildas Bazin's avatar
 
Gildas Bazin committed
466
    wxMenu *view_menu = new wxMenu;
467 468
    if (!minimal)
    {
Gildas Bazin's avatar
Gildas Bazin committed
469
    view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
470
    }
Gildas Bazin's avatar
Gildas Bazin committed
471
    view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
472
    view_menu->Append( FileInfo_Event,
Gildas Bazin's avatar
Gildas Bazin committed
473
                       wxU(_("Stream and Media &info...\tCtrl-I")) );
474 475
    view_menu->Append( VLM_Event,
                       wxU(_("VLM Control...\tCtrl-I")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
476

477 478 479 480 481
    /* 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 );
Gildas Bazin's avatar
 
Gildas Bazin committed
482

Gildas Bazin's avatar
 
Gildas Bazin committed
483
    /* Create the "Help" menu */
Gildas Bazin's avatar
 
Gildas Bazin committed
484
    wxMenu *help_menu = new wxMenu;
Gildas Bazin's avatar
Gildas Bazin committed
485
    help_menu->Append( About_Event, wxU(_("About VLC media player")) );
486 487
    help_menu->AppendSeparator();
    help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
488 489

    /* Append the freshly created menus to the menu bar... */
490
    wxMenuBar *menubar = new wxMenuBar();
Gildas Bazin's avatar
 
Gildas Bazin committed
491 492
    menubar->Append( file_menu, wxU(_("&File")) );
    menubar->Append( view_menu, wxU(_("&View")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
493
    menubar->Append( p_settings_menu, wxU(_("&Settings")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
494 495
    menubar->Append( p_audio_menu, wxU(_("&Audio")) );
    menubar->Append( p_video_menu, wxU(_("&Video")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
496
    menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
497
    menubar->Append( help_menu, wxU(_("&Help")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
498 499 500 501

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

502 503
    /* Find out size of menu bar */
    int i_size = 0;
504
    for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
505 506 507
    {
        int i_width, i_height;
        menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
508 509
        i_size += i_width +
#if defined(__WXGTK__)
510
            22 /* approximate margin */;
511
#else
512
#if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
513
            4 /* approximate margin */;
514
#else
515
            18 /* approximate margin */;
516
#endif
517
#endif
518
    }
519 520 521 522 523 524 525 526 527

/* Patch by zcot for menu wrapping */
#if defined(WIN32)
    /* Find out size of msw menu bar */
    i_size = 0;
    SIZE sizing;
    HDC hdc = GetDC( NULL );
    for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
    {
528 529
        GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
                                menubar->GetLabelTop(i).Length(), &sizing );
530 531 532

        // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
        i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
533 534
    }
    ReleaseDC( NULL, hdc );
535
    i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
536 537 538
#endif
/* End patch by zcot */

539 540
    frame_sizer->SetMinSize( i_size, -1 );

Gildas Bazin's avatar
 
Gildas Bazin committed
541 542 543
    /* Intercept all menu events in our custom event handler */
    PushEventHandler( new MenuEvtHandler( p_intf, this ) );

544
#if wxUSE_DRAG_AND_DROP
Gildas Bazin's avatar
 
Gildas Bazin committed
545 546
    /* Associate drop targets with the menubar */
    menubar->SetDropTarget( new DragAndDrop( p_intf ) );
Gildas Bazin's avatar
 
Gildas Bazin committed
547
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
548 549 550 551
}

void Interface::CreateOurToolBar()
{
552
#define HELP_OPEN N_("Open")
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
553 554 555 556
#define HELP_STOP N_("Stop")
#define HELP_PLAY N_("Play")
#define HELP_PAUSE N_("Pause")
#define HELP_PLO N_("Playlist")
Gildas Bazin's avatar
 
Gildas Bazin committed
557 558
#define HELP_PLP N_("Previous playlist item")
#define HELP_PLN N_("Next playlist item")
Gildas Bazin's avatar
 
Gildas Bazin committed
559 560
#define HELP_SLOW N_("Play slower")
#define HELP_FAST N_("Play faster")
Gildas Bazin's avatar
 
Gildas Bazin committed
561

562
    int minimal = config_GetInt( p_intf, "wx-minimal" );
563

Gildas Bazin's avatar
 
Gildas Bazin committed
564 565
    wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
                         * version because we don't include wx.rc */
Gildas Bazin's avatar
 
Gildas Bazin committed
566

567
    wxToolBar *toolbar =
568
        CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
Gildas Bazin's avatar
 
Gildas Bazin committed
569

Gildas Bazin's avatar
 
Gildas Bazin committed
570 571
    toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );

572 573
    if (!minimal)
    {
574 575 576
    toolbar->AddTool( OpenFile_Event, wxT(""),
                      wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
    toolbar->AddSeparator();
577
    }
578 579

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

583 584
    if (!minimal)
    {
585 586
    toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
                      wxU(_(HELP_STOP)) );
Gildas Bazin's avatar
 
Gildas Bazin committed
587
    toolbar->AddSeparator();
588

Gildas Bazin's avatar
 
Gildas Bazin committed
589
    toolbar->AddTool( PrevStream_Event, wxT(""),
590 591 592 593 594
                      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)) );
Gildas Bazin's avatar
 
Gildas Bazin committed
595
    toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
Gildas Bazin's avatar
 
Gildas Bazin committed
596
                      wxU(_(HELP_PLN)) );
597
    toolbar->AddSeparator();
598
    toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
599
                      wxU(_(HELP_PLO)) );
600
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
601

602
#if !( (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 6) && (wxRELEASE_NUMBER < 2) )
603
    wxControl *p_dummy_ctrl =
604
        new wxControl( toolbar, -1, wxDefaultPosition,
605
                       wxSize(35, 16 ), wxBORDER_NONE );
606

607
    toolbar->AddControl( p_dummy_ctrl );
608
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
609

610 611
    volctrl = new VLCVolCtrl( p_intf, toolbar );
    toolbar->AddControl( volctrl );
612 613

    toolbar->Realize();
Gildas Bazin's avatar
 
Gildas Bazin committed
614

615
#if wxUSE_DRAG_AND_DROP
Gildas Bazin's avatar
 
Gildas Bazin committed
616 617
    /* Associate drop targets with the toolbar */
    toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
Gildas Bazin's avatar
 
Gildas Bazin committed
618
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
619 620
}

Gildas Bazin's avatar
 
Gildas Bazin committed
621
void Interface::CreateOurSlider()
Gildas Bazin's avatar
 
Gildas Bazin committed
622
{
Gildas Bazin's avatar
 
Gildas Bazin committed
623
    /* Create a new frame and sizer containing the slider */
Gildas Bazin's avatar
 
Gildas Bazin committed
624
    slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
Gildas Bazin's avatar
 
Gildas Bazin committed
625
    slider_frame->SetAutoLayout( TRUE );
626 627
    slider_sizer = new wxBoxSizer( wxHORIZONTAL );
    //slider_sizer->SetMinSize( -1, 50 );
Gildas Bazin's avatar
 
Gildas Bazin committed
628 629 630 631

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

633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
    /* 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();

Gildas Bazin's avatar
 
Gildas Bazin committed
653
    /* Add everything to the frame */
654 655 656 657 658 659 660 661 662
    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 );
Gildas Bazin's avatar
 
Gildas Bazin committed
663 664 665

    /* Hide the slider by default */
    slider_frame->Hide();
Gildas Bazin's avatar
 
Gildas Bazin committed
666 667
}

668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
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;
705 706 707
        case KEY_END: return WXK_END;
        case KEY_INSERT: return WXK_INSERT;
        case KEY_DELETE: return WXK_DELETE;
708 709 710 711 712 713 714 715 716 717 718
        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;
}

719
void Interface::SetupHotkeys()
720
{
721 722
    struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
    int i_hotkeys;
723

724 725 726 727 728 729
    /* 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;

730
    wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
731 732

    /* Setup the hotkeys as accelerators */
733
    for( int i = 0; i < i_hotkeys; i++ )
734
    {
735 736 737 738
        int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
        int i_key = ConvertHotkey( p_hotkeys[i].i_key );

#ifdef WIN32
739 740
        if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
            i_key = toupper(i_key);
741 742 743
#endif

        p_entries[i].Set( i_mod, i_key,
744 745
                          p_intf->p_sys->i_first_hotkey_event + i );
    }
Clément Stenac's avatar
Clément Stenac committed
746

747
    wxAcceleratorTable accel( i_hotkeys, p_entries );
Clément Stenac's avatar
Clément Stenac committed
748

749 750 751 752 753 754 755 756
    if( !accel.Ok() )
    {
        msg_Err( p_intf, "invalid accelerator table" );
    }
    else
    {
        SetAcceleratorTable( accel );
    }
757 758

    delete [] p_entries;
759 760
}

761
void Interface::HideSlider( bool layout )
Clément Stenac's avatar
Clément Stenac committed
762
{
763
    ShowSlider( false, layout );
Clément Stenac's avatar
Clément Stenac committed
764 765
}

766
void Interface::ShowSlider( bool show, bool layout )
Clément Stenac's avatar
Clément Stenac committed
767
{
768
    if( show )
769
    {
770 771 772
        //prevent the hide timers from hiding it now
        m_slider_timer.Stop();
        m_controls_timer.Stop();
773

774 775
        //prevent continuous layout
        if( slider_frame->IsShown() ) return;
776 777 778 779 780 781 782 783
        
        wxSize ms = GetMinSize();
        ms.SetHeight( ms.GetHeight() + slider_size.GetHeight() );
#if ( wxCHECK_VERSION( 2,5,4 ) )
        SetMinSize( ms );
#else
        frame_sizer->SetMinSize( ms );
#endif
784
    }
785 786 787 788
    else
    {
        //prevent continuous layout
        if( !slider_frame->IsShown() ) return;
789 790 791 792 793 794 795 796
        
        wxSize ms = GetMinSize();
        ms.SetHeight( ms.GetHeight() - slider_size.GetHeight() );
#if ( wxCHECK_VERSION( 2,5,4 ) )
        SetMinSize( ms );
#else
        frame_sizer->SetMinSize( ms );
#endif
797
    }
Clément Stenac's avatar
Clément Stenac committed
798

799 800 801 802 803 804
    if( layout && p_intf->p_sys->b_video_autosize )
        UpdateVideoWindow( p_intf, video_window );

    slider_frame->Show( show );
    frame_sizer->Show( slider_frame, show );

805
    if( layout )
Clément Stenac's avatar
Clément Stenac committed
806
    {
807
        frame_sizer->Layout();
808
        if( p_intf->p_sys->b_video_autosize ) frame_sizer->Fit( this );
Clément Stenac's avatar
Clément Stenac committed
809 810 811
    }
}

812
void Interface::HideDiscFrame( bool layout )
Clément Stenac's avatar
Clément Stenac committed
813
{
814
    ShowDiscFrame( false, layout );
Clément Stenac's avatar
Clément Stenac committed
815 816
}

817
void Interface::ShowDiscFrame( bool show, bool layout )
Clément Stenac's avatar
Clément Stenac committed
818
{
819
    if( show )
820
    {
821 822
        //prevent the hide timer from hiding it now
        m_controls_timer.Stop();
823

824 825
        //prevent continuous layout
        if( disc_frame->IsShown() ) return;
826
    }
827 828 829 830 831
    else
    {
        //prevent continuous layout
        if( !disc_frame->IsShown() ) return;
    }
Clément Stenac's avatar
Clément Stenac committed
832

833 834 835 836 837 838
    if( layout && p_intf->p_sys->b_video_autosize )
        UpdateVideoWindow( p_intf, video_window );

    disc_frame->Show( show );
    slider_sizer->Show( disc_frame, show );

839
    if( layout )
Clément Stenac's avatar
Clément Stenac committed
840
    {
841 842 843
        slider_sizer->Layout();
        if( p_intf->p_sys->b_video_autosize )
            slider_sizer->Fit( slider_frame );
Clément Stenac's avatar
Clément Stenac committed
844 845 846
    }
}

Gildas Bazin's avatar
 
Gildas Bazin committed
847
/*****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
848
 * Event Handlers.
Gildas Bazin's avatar
 
Gildas Bazin committed
849
 *****************************************************************************/
850
void Interface::OnControlsTimer( wxTimerEvent& WXUNUSED(event) )
Clément Stenac's avatar
Clément Stenac committed
851
{
852 853 854
    if( p_intf->p_sys->b_video_autosize )
        UpdateVideoWindow( p_intf, video_window );

855 856 857 858 859 860 861 862 863 864 865
    /* 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 );
        frame_sizer->Fit( this );
    }
Clément Stenac's avatar
Clément Stenac committed
866
}
Clément Stenac's avatar
Clément Stenac committed
867

868 869 870
void Interface::OnSliderTimer( wxTimerEvent& WXUNUSED(event) )
{
    HideSlider();
Clément Stenac's avatar
Clément Stenac committed
871 872
}

873
void Interface::OnMenuOpen( wxMenuEvent& event )
Gildas Bazin's avatar
 
Gildas Bazin committed
874
{
875 876
#if defined( __WXMSW__ )
#   define GetEventObject GetMenu
877
#endif
878 879

    if( event.GetEventObject() == p_settings_menu )
Gildas Bazin's avatar
 
Gildas Bazin committed
880
    {
881 882 883 884
        p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );

        /* Add static items */
        p_settings_menu->AppendCheckItem( Extended_Event,
885
            wxU(_("Extended &GUI\tCtrl-G") ) );
886
        if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
887 888 889 890 891
#if 0
        p_settings_menu->AppendCheckItem( Undock_Event,
            wxU(_("&Undock Ext. GUI") ) );
        if( b_undock ) p_settings_menu->Check( Undock_Event, TRUE );
#endif
892 893 894 895
        p_settings_menu->Append( Bookmarks_Event,
                                 wxU(_("&Bookmarks...\tCtrl-B") ) );
        p_settings_menu->Append( Prefs_Event,
                                 wxU(_("Preference&s...\tCtrl-S")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
896
    }
897

Gildas Bazin's avatar
 
Gildas Bazin committed
898
    else if( event.GetEventObject() == p_audio_menu )
Gildas Bazin's avatar
 
Gildas Bazin committed
899
    {
900
        p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
Gildas Bazin's avatar
 
Gildas Bazin committed
901
    }
902

Gildas Bazin's avatar
 
Gildas Bazin committed
903 904
    else if( event.GetEventObject() == p_video_menu )
    {
905
        p_video_menu = VideoMenu( p_intf, this, p_video_menu );
Gildas Bazin's avatar
 
Gildas Bazin committed
906
    }
907

Gildas Bazin's avatar
 
Gildas Bazin committed
908 909
    else if( event.GetEventObject() == p_navig_menu )
    {
910
        p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
Gildas Bazin's avatar
 
Gildas Bazin committed
911
    }
912 913 914 915

#if defined( __WXMSW__ )
#   undef GetEventObject
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
916 917
}

Gildas Bazin's avatar
 
Gildas Bazin committed
918
#if defined( __WXMSW__ ) || defined( __WXMAC__ )
Gildas Bazin's avatar
 
Gildas Bazin committed
919
void Interface::OnContextMenu2(wxContextMenuEvent& event)
Gildas Bazin's avatar
 
Gildas Bazin committed
920
{
Gildas Bazin's avatar
 
Gildas Bazin committed
921 922 923 924 925 926 927
    /* Only show the context menu for the main interface */
    if( GetId() != event.GetId() )
    {
        event.Skip();
        return;
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
928
    if( p_intf->p_sys->pf_show_dialog )
929
        p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
Gildas Bazin's avatar
 
Gildas Bazin committed
930
}
Gildas Bazin's avatar
 
Gildas Bazin committed
931
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
932 933
void Interface::OnContextMenu(wxMouseEvent& event)
{
Gildas Bazin's avatar
 
Gildas Bazin committed
934
    if( p_intf->p_sys->pf_show_dialog )
935
        p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
Gildas Bazin's avatar
 
Gildas Bazin committed
936
}
Gildas Bazin's avatar
 
Gildas Bazin committed
937

Gildas Bazin's avatar
 
Gildas Bazin committed
938 939 940 941 942 943 944 945 946
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
947
    msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
948
        wxU(_(" (wxWidgets interface)\n\n")) +
949
        wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
Christophe Mutricy's avatar
Christophe Mutricy committed
950 951 952 953
       wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
       wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
       wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
       wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
954
#ifdef __WXMSW__
955
        wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
956
#else
957
        wxU( LICENSE_MSG ) + wxT("\n\n") +
958
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
959
        wxU(_("The VideoLAN team <videolan@videolan.org>\n"
Gildas Bazin's avatar
 
Gildas Bazin committed
960
              "http://www.videolan.org/\n\n")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
961

Gildas Bazin's avatar
 
Gildas Bazin committed
962 963
    wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
                  wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
Gildas Bazin's avatar
 
Gildas Bazin committed
964 965
}

Gildas Bazin's avatar
 
Gildas Bazin committed
966
void Interface::OnShowDialog( wxCommandEvent& event )
Gildas Bazin's avatar
 
Gildas Bazin committed
967
{
Gildas Bazin's avatar
 
Gildas Bazin committed
968
    if( p_intf->p_sys->pf_show_dialog )
Gildas Bazin's avatar
 
Gildas Bazin committed
969
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
970
        int i_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
971

Gildas Bazin's avatar
 
Gildas Bazin committed
972 973 974 975 976
        switch( event.GetId() )
        {
        case OpenFileSimple_Event:
            i_id = INTF_DIALOG_FILE_SIMPLE;
            break;
977 978
        case OpenAdv_Event:
            i_id = INTF_DIALOG_FILE;
979
            break;
Gildas Bazin's avatar
 
Gildas Bazin committed
980 981 982
        case OpenFile_Event:
            i_id = INTF_DIALOG_FILE;
            break;
983 984 985
        case OpenDir_Event:
            i_id = INTF_DIALOG_DIRECTORY;
            break;
Gildas Bazin's avatar
 
Gildas Bazin committed
986 987 988 989 990 991
        case OpenDisc_Event:
            i_id = INTF_DIALOG_DISC;
            break;
        case OpenNet_Event:
            i_id = INTF_DIALOG_NET;
            break;
Gildas Bazin's avatar
Gildas Bazin committed
992 993 994
        case OpenCapture_Event:
            i_id = INTF_DIALOG_CAPTURE;
            break;
Gildas Bazin's avatar
 
Gildas Bazin committed
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
        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;
1010 1011 1012
        case Wizard_Event:
            i_id = INTF_DIALOG_WIZARD;
            break;
Gildas Bazin's avatar
Gildas Bazin committed
1013 1014 1015
        case Bookmarks_Event:
            i_id = INTF_DIALOG_BOOKMARKS;
            break;
1016 1017 1018
        case UpdateVLC_Event:
            i_id = INTF_DIALOG_UPDATEVLC;
            break;
1019 1020 1021
        case VLM_Event:
            i_id = INTF_DIALOG_VLM;
            break;
Gildas Bazin's avatar
 
Gildas Bazin committed
1022 1023 1024 1025
        default:
            i_id = INTF_DIALOG_FILE;
            break;
        }
Gildas Bazin's avatar
 
Gildas Bazin committed
1026

Gildas Bazin's avatar
 
Gildas Bazin committed
1027
        p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
Gildas Bazin's avatar
 
Gildas Bazin committed
1028
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
1029 1030
}

Gildas Bazin's avatar
Gildas Bazin committed
1031
void Interface::OnExtended(wxCommandEvent& event)
Clément Stenac's avatar
Clément Stenac committed
1032
{
1033 1034 1035
    b_extra = (b_extra == VLC_TRUE ? VLC_FALSE : VLC_TRUE );

    if( b_extra == VLC_FALSE )
Clément Stenac's avatar
Clément Stenac committed
1036
    {
1037 1038
        extra_frame->Hide();
        frame_sizer->Hide( extra_frame );
1039 1040 1041 1042 1043 1044 1045 1046
        wxSize ms = GetMinSize();
        ms.SetHeight( ms.GetHeight() - extended_size.GetHeight() );
        ms.SetWidth( default_size.GetWidth() );
#if ( wxCHECK_VERSION( 2,5,4 ) )
        SetMinSize( ms );
#else
        frame_sizer->SetMinSize( ms );
#endif
Clément Stenac's avatar
Clément Stenac committed
1047 1048 1049
    }
    else
    {
1050 1051
        extra_frame->Show();
        frame_sizer->Show( extra_frame );
1052 1053 1054 1055 1056 1057 1058 1059
        wxSize ms = GetMinSize();
        ms.SetHeight( ms.GetHeight() + extended_size.GetHeight() );
        ms.SetWidth( extended_size.GetWidth() );
#if ( wxCHECK_VERSION( 2,5,4 ) )
        SetMinSize( ms );
#else
        frame_sizer->SetMinSize( ms );
#endif
Clément Stenac's avatar
Clément Stenac committed
1060 1061 1062 1063 1064
    }
    frame_sizer->Layout();
    frame_sizer->Fit(this);
}

Gildas Bazin's avatar
 
Gildas Bazin committed
1065
void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1066 1067 1068 1069 1070
{
    PlayStream();
}

void Interface::PlayStream()
Gildas Bazin's avatar
 
Gildas Bazin committed
1071 1072 1073 1074 1075
{
    wxCommandEvent dummy;
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
Gildas Bazin's avatar
 
Gildas Bazin committed
1076
    if( p_playlist == NULL ) return;
Gildas Bazin's avatar
 
Gildas Bazin committed
1077

Clément Stenac's avatar
Clément Stenac committed
1078
    if( p_playlist->i_size && p_playlist->i_enabled )
Gildas Bazin's avatar
 
Gildas Bazin committed
1079
    {
1080 1081
        vlc_value_t state;

Gildas Bazin's avatar
 
Gildas Bazin committed
1082 1083 1084 1085 1086 1087 1088
        input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
                                                       VLC_OBJECT_INPUT,
                                                       FIND_ANYWHERE );
        if( p_input == NULL )
        {
            /* No stream was playing, start one */
            playlist_Play( p_playlist );
Gildas Bazin's avatar
 
Gildas Bazin committed
1089
            TogglePlayButton( PLAYING_S );
Gildas Bazin's avatar
 
Gildas Bazin committed
1090 1091 1092 1093
            vlc_object_release( p_playlist );
            return;
        }

1094 1095 1096
        var_Get( p_input, "state", &state );

        if( state.i_int != PAUSE_S )
Gildas Bazin's avatar
 
Gildas Bazin committed
1097 1098
        {
            /* A stream is being played, pause it */
1099
            state.i_int = PAUSE_S;
Gildas Bazin's avatar
 
Gildas Bazin committed
1100
        }
1101 1102 1103 1104 1105 1106
        else
        {
            /* Stream is paused, resume it */
            state.i_int = PLAYING_S;
        }
        var_Set( p_input, "state", state );
Gildas Bazin's avatar
 
Gildas Bazin committed
1107

1108
        TogglePlayButton( state.i_int );
Gildas Bazin's avatar
 
Gildas Bazin committed
1109
        vlc_object_release( p_input );
Gildas Bazin's avatar
 
Gildas Bazin committed
1110 1111 1112 1113
        vlc_object_release( p_playlist );
    }
    else
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
1114
        /* If the playlist is empty, open a file requester instead */
Gildas Bazin's avatar
 
Gildas Bazin committed
1115
        vlc_object_release( p_playlist );
Gildas Bazin's avatar
 
Gildas Bazin committed
1116
        OnShowDialog( dummy );
Gildas Bazin's avatar
 
Gildas Bazin committed
1117 1118 1119 1120
    }
}

void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1121 1122 1123 1124
{
    StopStream();
}
void Interface::StopStream()
Gildas Bazin's avatar
 
Gildas Bazin committed
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
{
    playlist_t * p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

    playlist_Stop( p_playlist );
Gildas Bazin's avatar
 
Gildas Bazin committed
1135
    TogglePlayButton( PAUSE_S );
Gildas Bazin's avatar
 
Gildas Bazin committed
1136 1137 1138 1139 1140
    vlc_object_release( p_playlist );
}

void Interface::OnSliderUpdate( wxScrollEvent& event )
{
Gildas Bazin's avatar
 
Gildas Bazin committed
1141 1142
    vlc_mutex_lock( &p_intf->change_lock );

Gildas Bazin's avatar
 
Gildas Bazin committed
1143
#ifdef WIN32
Gildas Bazin's avatar
 
Gildas Bazin committed
1144
    if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
Gildas Bazin's avatar
 
Gildas Bazin committed
1145
        || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
Gildas Bazin's avatar
 
Gildas Bazin committed
1146
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
1147
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
1148 1149 1150
        if( p_intf->p_sys->i_slider_pos != event.GetPosition()
            && p_intf->p_sys->p_input )
        {
1151 1152 1153 1154
            vlc_value_t pos;
            pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;

            var_Set( p_intf->p_sys->p_input, "position", pos );
Gildas Bazin's avatar
 
Gildas Bazin committed
1155
        }
Gildas Bazin's avatar
 
Gildas Bazin committed
1156

Gildas Bazin's avatar
 
Gildas Bazin committed
1157
#ifdef WIN32
Gildas Bazin's avatar
 
Gildas Bazin committed
1158 1159 1160 1161 1162 1163
        p_intf->p_sys->b_slider_free = VLC_TRUE;
    }
    else
    {
        p_intf->p_sys->b_slider_free = VLC_FALSE;

Gildas Bazin's avatar
 
Gildas Bazin committed
1164 1165 1166
        if( p_intf->p_sys->p_input )
        {
            /* Update stream date */
1167 1168 1169
            char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
            mtime_t i_seconds;

1170 1171
            i_seconds = var_GetTime( p_intf->p_sys->p_input, "length" ) /
                        I64C(1000000 );
1172
            secstotimestr( psz_total, i_seconds );
Gildas Bazin's avatar
 
Gildas Bazin committed
1173

1174 1175
            i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) /
                        I64C(1000000 );
1176 1177
            secstotimestr( psz_time, i_seconds );

1178 1179
            statusbar->SetStatusText( wxU(psz_time) + wxString(wxT(" / ") ) +
                                      wxU(psz_total), 0 );
Gildas Bazin's avatar
 
Gildas Bazin committed
1180
        }
Gildas Bazin's avatar
 
Gildas Bazin committed
1181
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
1182
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
1183

1184
#undef WIN32
Gildas Bazin's avatar
 
Gildas Bazin committed
1185
    vlc_mutex_unlock( &p_intf->change_lock );
Gildas Bazin's avatar
 
Gildas Bazin committed
1186 1187 1188
}

void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1189 1190 1191 1192 1193
{
    PrevStream();
}

void Interface::PrevStream()
Gildas Bazin's avatar
 
Gildas Bazin committed
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
{
    playlist_t * p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

    playlist_Prev( p_playlist );
    vlc_object_release( p_playlist );
}

void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1208 1209 1210 1211 1212
{
    NextStream();
}

void Interface::NextStream()
Gildas Bazin's avatar
 
Gildas Bazin committed
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223
{
    playlist_t * p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }
    playlist_Next( p_playlist );
    vlc_object_release( p_playlist );
}
Gildas Bazin's avatar
 
Gildas Bazin committed
1224

Gildas Bazin's avatar
 
Gildas Bazin committed
1225 1226 1227 1228 1229 1230 1231
void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
{
    input_thread_t *p_input =
        (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                           FIND_ANYWHERE );
    if( p_input )
    {
1232 1233 1234
        vlc_value_t val; val.b_bool = VLC_TRUE;

        var_Set( p_input, "rate-slower", val );
Gildas Bazin's avatar
 
Gildas Bazin committed
1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245
        vlc_object_release( p_input );
    }
}

void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
{
    input_thread_t *p_input =
        (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                           FIND_ANYWHERE );
    if( p_input )
    {
1246 1247 1248
        vlc_value_t val; val.b_bool = VLC_TRUE;

        var_Set( p_input, "rate-faster", val );
Gildas Bazin's avatar
 
Gildas Bazin committed
1249 1250 1251 1252
        vlc_object_release( p_input );
    }
}

Gildas Bazin's avatar
 
Gildas Bazin committed
1253
void Interface::TogglePlayButton( int i_playing_status )
Gildas Bazin's avatar
 
Gildas Bazin committed
1254
{
Gildas Bazin's avatar
 
Gildas Bazin committed
1255 1256 1257
    if( i_playing_status == i_old_playing_status )
        return;

1258 1259
    wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
        GetToolBar()->GetToolClientData( PlayStream_Event );
1260
    if( !p_tool ) return;
Gildas Bazin's avatar
 
Gildas Bazin committed
1261 1262 1263

    if( i_playing_status == PLAYING_S )
    {
1264 1265 1266
        p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
        p_tool->SetLabel( wxU(_("Pause")) );
        p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
Gildas Bazin's avatar
 
Gildas Bazin committed
1267 1268 1269
    }
    else
    {
1270 1271 1272
        p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
        p_tool->SetLabel( wxU(_("Play")) );
        p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
Gildas Bazin's avatar
 
Gildas Bazin committed
1273 1274 1275
    }

    GetToolBar()->Realize();
1276 1277
    GetToolBar()->ToggleTool( PlayStream_Event, true );
    GetToolBar()->ToggleTool( PlayStream_Event, false );
Gildas Bazin's avatar
 
Gildas Bazin committed
1278 1279

    i_old_playing_status = i_playing_status;
Gildas Bazin's avatar
 
Gildas Bazin committed
1280 1281
}

1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329
void Interface::OnDiscMenu( wxCommandEvent& WXUNUSED(event) )
{
    input_thread_t *p_input =
        (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                           FIND_ANYWHERE );
    if( p_input )
    {
        vlc_value_t val; val.i_int = 2;

        var_Set( p_input, "title  0", val);
        vlc_object_release( p_input );
    }
}

void Interface::OnDiscPrev( wxCommandEvent& WXUNUSED(event) )
{
    input_thread_t *p_input =
        (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                           FIND_ANYWHERE );
    if( p_input )
    {
        int i_type = var_Type( p_input, "prev-chapter" );
        vlc_value_t val; val.b_bool = VLC_TRUE;

        var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
                 "prev-chapter" : "prev-title", val );

        vlc_object_release( p_input );
    }
}

void Interface::OnDiscNext( wxCommandEvent& WXUNUSED(event) )
{
    input_thread_t *p_input =
        (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                           FIND_ANYWHERE );
    if( p_input )
    {
        int i_type = var_Type( p_input, "next-chapter" );
        vlc_value_t val; val.b_bool = VLC_TRUE;

        var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
                 "next-chapter" : "next-title", val );

        vlc_object_release( p_input );
    }
}

1330
#if wxUSE_DRAG_AND_DROP
Gildas Bazin's avatar
 
Gildas Bazin committed
1331 1332 1333
/*****************************************************************************
 * Definition of DragAndDrop class.
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
1334
DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
Gildas Bazin's avatar
 
Gildas Bazin committed
1335 1336
{
    p_intf = _p_intf;
Gildas Bazin's avatar
 
Gildas Bazin committed
1337
    b_enqueue = _b_enqueue;
Gildas Bazin's avatar
 
Gildas Bazin committed
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
}

bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
                               const wxArrayString& filenames )
{
    /* Add dropped files to the playlist */

    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return FALSE;
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
1353
    for( size_t i = 0; i < filenames.GetCount(); i++ )
1354
    {
1355
        char *psz_utf8 = wxFromLocale( filenames[i] );
1356

1357
        playlist_Add( p_playlist, psz_utf8, psz_utf8,
Gildas Bazin's avatar
 
Gildas Bazin committed
1358 1359
                      PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
                      PLAYLIST_END );
1360
        wxLocaleFree( psz_utf8 );
1361
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
1362 1363 1364 1365 1366

    vlc_object_release( p_playlist );

    return TRUE;
}
Gildas Bazin's avatar
 
Gildas Bazin committed
1367
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
1368 1369

/*****************************************************************************
1370
 * Definition of VolCtrl class.
Gildas Bazin's avatar
 
Gildas Bazin committed
1371
 *****************************************************************************/
1372 1373 1374 1375 1376 1377 1378 1379 1380
class wxVolCtrl: public wxGauge
{
public:
    /* Constructor */
    wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
               wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
    virtual ~wxVolCtrl() {};

    void UpdateVolume();
1381
    int GetVolume();
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396

    void OnChange( wxMouseEvent& event );

private:
    intf_thread_t *p_intf;

    DECLARE_EVENT_TABLE();
};

BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
    /* Mouse events */
    EVT_LEFT_DOWN(wxVolCtrl::OnChange)
    EVT_MOTION(wxVolCtrl::OnChange)
END_EVENT_TABLE()

1397 1398 1399
wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
                      wxPoint point, wxSize size )
  : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
Gildas Bazin's avatar
 
Gildas Bazin committed
1400 1401
{
    p_intf = _p_intf;
1402
    UpdateVolume();
Gildas Bazin's avatar
 
Gildas Bazin committed
1403 1404 1405 1406
}

void wxVolCtrl::OnChange( wxMouseEvent& event )
{
1407 1408
    if( !event.LeftDown() && !event.LeftIsDown() ) return;

Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
1409 1410
    int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
    aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1411
    UpdateVolume();
Gildas Bazin's avatar
 
Gildas Bazin committed
1412 1413
}

1414
void wxVolCtrl::UpdateVolume()
Gildas Bazin's avatar
 
Gildas Bazin committed
1415
{
1416 1417
    audio_volume_t i_volume;
    aout_VolumeGet( p_intf, &i_volume );
1418

Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
1419
    int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1420
    if( i_gauge_volume == GetValue() ) return;
1421

1422
    SetValue( i_gauge_volume );
1423 1424
    SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
                i_gauge_volume / 2 ) );
Gildas Bazin's avatar
 
Gildas Bazin committed
1425
}
1426

1427 1428 1429 1430 1431 1432 1433 1434 1435
#if defined(__WXGTK__)
#define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
#else
#define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
#endif
VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
  :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
              wxBORDER_NONE ),
   i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1436
   b_mute(0), p_intf(_p_intf)
1437 1438 1439 1440 1441 1442 1443 1444
{
    gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
                           wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
}

void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
{
    wxPaintDC dc( this );
1445
    wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1446 1447 1448 1449 1450 1451 1452 1453 1454
    dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
}

void VLCVolCtrl::OnChange( wxMouseEvent& event )
{
    if( event.GetX() < TOOLBAR_BMP_WIDTH )
    {
        int i_volume;
        aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1455 1456 1457

        b_mute = !b_mute;
        Refresh();
1458 1459 1460 1461 1462 1463
    }
}

void VLCVolCtrl::UpdateVolume()
{
    gauge->UpdateVolume();
1464 1465 1466 1467

    int i_volume = gauge->GetValue();
    if( !!i_volume == !b_mute ) return;
    b_mute = !b_mute;
1468
    Refresh();
1469 1470
}

1471
/*****************************************************************************
1472
 * Systray class.
1473 1474
 *****************************************************************************/

1475
#ifdef wxHAS_TASK_BAR_ICON
1476 1477 1478 1479 1480 1481 1482 1483 1484

BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
    /* Mouse events */
#ifdef WIN32
    EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
#else
    EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
#endif
    /* Menu events */
1485
    EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1486 1487 1488 1489 1490 1491 1492
    EVT_MENU(Exit_Event, Systray::OnExit)
    EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
    EVT_MENU(NextStream_Event, Systray::OnNextStream)
    EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
    EVT_MENU(StopStream_Event, Systray::OnStopStream)
END_EVENT_TABLE()

1493
Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1494 1495
{
    p_main_interface = _p_main_interface;
1496
    p_intf = _p_intf;
1497 1498 1499
}

/* Event handlers */
1500
void Systray::OnMenuIconize( wxCommandEvent& event )
1501 1502
{
    p_main_interface->Show( ! p_main_interface->IsShown() );
1503
    if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1504 1505
}

1506 1507 1508 1509 1510 1511
void Systray::OnLeftClick( wxTaskBarIconEvent& event )
{
    wxCommandEvent cevent;
    OnMenuIconize(cevent);
}

1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539
void Systray::OnExit( wxCommandEvent& event )
{
    p_main_interface->Close(TRUE);
}

void Systray::OnPrevStream( wxCommandEvent& event )
{
    p_main_interface->PrevStream();
}

void Systray::OnNextStream( wxCommandEvent& event )
{
    p_main_interface->NextStream();
}

void Systray::OnPlayStream( wxCommandEvent& event )
{
    p_main_interface->PlayStream();
}

void Systray::OnStopStream( wxCommandEvent& event )
{
    p_main_interface->StopStream();
}

/* Systray popup menu */
wxMenu* Systray::CreatePopupMenu()
{
1540
    int minimal = config_GetInt( p_intf, "wx-minimal" );
1541

1542 1543 1544 1545
    wxMenu* systray_menu = new wxMenu;
    systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
    systray_menu->AppendSeparator();
    systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1546 1547 1548

    if (!minimal)
    {
1549 1550 1551
    systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
    systray_menu->Append( NextStream_Event, wxU(_("Next")) );
    systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1552
    }
1553 1554 1555 1556
    systray_menu->AppendSeparator();
    systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
    return systray_menu;
}
1557 1558 1559 1560 1561

void Systray::UpdateTooltip( const wxChar* tooltip )
{
    SetIcon( wxIcon( vlc16x16_xpm ), tooltip );
}
1562
#endif