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
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
27
#include <vlc/vlc.h>
Gildas Bazin's avatar
 
Gildas Bazin committed
28
#include <vlc/aout.h>
29
#include <vlc/vout.h>
30
#include <vlc/input.h>
Gildas Bazin's avatar
 
Gildas Bazin committed
31
#include <vlc/intf.h>
Gildas Bazin's avatar
 
Gildas Bazin 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"
Gildas Bazin's avatar
 
Gildas Bazin committed
40
#include "bitmaps/next.xpm"
41
#include "bitmaps/eject.xpm"
Gildas Bazin's avatar
 
Gildas Bazin 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"
Gildas Bazin's avatar
 
Gildas Bazin committed
47

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

Gildas Bazin's avatar
 
Gildas Bazin 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
Gildas Bazin's avatar
 
Gildas Bazin committed
57 58 59 60

/*****************************************************************************
 * Local class declarations.
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin 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:

};
Gildas Bazin's avatar
 
Gildas Bazin committed
80

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

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

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

95 96
    wxVolCtrl *gauge;
    int i_y_offset;
97
    vlc_bool_t b_mute;
Gildas Bazin's avatar
 
Gildas Bazin committed
98 99 100
    intf_thread_t *p_intf;
};

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

Gildas Bazin's avatar
 
Gildas Bazin committed
104
    /* Mouse events */
105
    EVT_LEFT_UP(VLCVolCtrl::OnChange)
Gildas Bazin's avatar
 
Gildas Bazin committed
106 107
END_EVENT_TABLE()

Gildas Bazin's avatar
 
Gildas Bazin committed
108 109 110 111
/*****************************************************************************
 * Event Table.
 *****************************************************************************/

Gildas Bazin's avatar
Gildas Bazin committed
112 113
DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );

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

131
    Wizard_Event,
132

133
    Playlist_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
134
    Logs_Event,
135
    FileInfo_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
136 137

    Prefs_Event,
Gildas Bazin's avatar
Gildas Bazin committed
138
    Extended_Event,
139
//    Undock_Event,
Gildas Bazin's avatar
Gildas Bazin committed
140
    Bookmarks_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
141
    Skins_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
142 143 144 145 146

    SliderScroll_Event,
    StopStream_Event,
    PlayStream_Event,
    PrevStream_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
147
    NextStream_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
148 149
    SlowStream_Event,
    FastStream_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
150

151 152 153 154
    DiscMenu_Event,
    DiscPrev_Event,
    DiscNext_Event,

Gildas Bazin's avatar
 
Gildas Bazin committed
155 156 157
    /* 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) */
158
    About_Event = wxID_ABOUT,
159
    UpdateVLC_Event,
160 161

    Iconize_Event
Gildas Bazin's avatar
 
Gildas Bazin committed
162 163 164 165 166 167
};

BEGIN_EVENT_TABLE(Interface, wxFrame)
    /* Menu events */
    EVT_MENU(Exit_Event, Interface::OnExit)
    EVT_MENU(About_Event, Interface::OnAbout)
168
    EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
Gildas Bazin's avatar
 
Gildas Bazin committed
169 170 171 172 173

    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
174

Gildas Bazin's avatar
 
Gildas Bazin committed
175 176
    EVT_MENU_OPEN(Interface::OnMenuOpen)

177 178
    EVT_MENU( Extended_Event, Interface::OnExtended )
//    EVT_MENU( Undock_Event, Interface::OnUndock )
Clément Stenac's avatar
Clément Stenac committed
179

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

Gildas Bazin's avatar
 
Gildas Bazin committed
182
#if defined( __WXMSW__ ) || defined( __WXMAC__ )
Gildas Bazin's avatar
 
Gildas Bazin committed
183
    EVT_CONTEXT_MENU(Interface::OnContextMenu2)
Gildas Bazin's avatar
 
Gildas Bazin committed
184
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
185
    EVT_RIGHT_UP(Interface::OnContextMenu)
Gildas Bazin's avatar
 
Gildas Bazin committed
186

Gildas Bazin's avatar
 
Gildas Bazin committed
187
    /* Toolbar events */
Gildas Bazin's avatar
 
Gildas Bazin committed
188
    EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
189
    EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
Gildas Bazin's avatar
 
Gildas Bazin committed
190
    EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
191
    EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
Gildas Bazin's avatar
 
Gildas Bazin committed
192 193
    EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
    EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
Gildas Bazin's avatar
Gildas Bazin committed
194
    EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
Gildas Bazin's avatar
 
Gildas Bazin committed
195
    EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
196
    EVT_MENU(Wizard_Event, Interface::OnShowDialog)
Gildas Bazin's avatar
 
Gildas Bazin committed
197 198 199 200
    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
201 202
    EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
    EVT_MENU(FastStream_Event, Interface::OnFastStream)
Gildas Bazin's avatar
 
Gildas Bazin committed
203

204 205 206 207 208
    /* 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
209 210
    /* Slider events */
    EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
Clément Stenac's avatar
Clément Stenac committed
211

Gildas Bazin's avatar
Gildas Bazin committed
212
    /* Custom events */
213 214
    EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
    EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
Clément Stenac's avatar
Clément Stenac committed
215 216

    EVT_TIMER(ID_CONTROLS_TIMER, Interface::OnControlsTimer)
Clément Stenac's avatar
Clément Stenac committed
217
    EVT_TIMER(ID_SLIDER_TIMER, Interface::OnSliderTimer)
Gildas Bazin's avatar
 
Gildas Bazin committed
218 219 220 221 222
END_EVENT_TABLE()

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

233

234
    extra_window = NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
235

Gildas Bazin's avatar
 
Gildas Bazin committed
236
    /* Give our interface a nice little icon */
237
    SetIcon( wxIcon( vlc_xpm ) );
Gildas Bazin's avatar
 
Gildas Bazin committed
238 239

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

243 244 245
    /* Create a dummy widget that can get the keyboard focus */
    wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
                                      wxSize(0,0) );
246 247 248 249
#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;
250
    m_imData = 0;
251
#endif
252
    p_dummy->SetFocus();
253
    frame_sizer->Add( p_dummy, 0, 0 );
Clément Stenac's avatar
Clément Stenac committed
254

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

Gildas Bazin's avatar
 
Gildas Bazin committed
269 270 271 272 273 274
    /* Creation of the menu bar */
    CreateOurMenuBar();

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

Clément Stenac's avatar
Clément Stenac committed
275
    /* Create the extra panel */
276
    extra_frame = new ExtraPanel( p_intf, this );
Clément Stenac's avatar
Clément Stenac committed
277 278 279
    frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
    frame_sizer->Hide( extra_frame );

280
    /* Creation of the status bar
Gildas Bazin's avatar
 
Gildas Bazin committed
281 282
     * Helptext for menu items and toolbar tools will automatically get
     * displayed here. */
Gildas Bazin's avatar
 
Gildas Bazin committed
283 284 285 286 287
    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
288
    /* Video window */
289
    video_window = 0;
Gildas Bazin's avatar
Gildas Bazin committed
290 291
    if( config_GetInt( p_intf, "wxwin-embed" ) )
    {
292 293
        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
294 295
    }

296 297 298 299 300 301 302 303
    /* 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
304 305
    /* Layout everything */
    frame_sizer->Layout();
Gildas Bazin's avatar
 
Gildas Bazin committed
306
    frame_sizer->Fit(this);
Gildas Bazin's avatar
 
Gildas Bazin committed
307

308
#if wxUSE_DRAG_AND_DROP
Gildas Bazin's avatar
 
Gildas Bazin committed
309 310
    /* Associate drop targets with the main interface */
    SetDropTarget( new DragAndDrop( p_intf ) );
Gildas Bazin's avatar
 
Gildas Bazin committed
311
#endif
312

313
    SetupHotkeys();
Gildas Bazin's avatar
 
Gildas Bazin committed
314

Clément Stenac's avatar
Clément Stenac committed
315
    m_controls_timer.SetOwner(this, ID_CONTROLS_TIMER);
Clément Stenac's avatar
Clément Stenac committed
316
    m_slider_timer.SetOwner(this, ID_SLIDER_TIMER);
Clément Stenac's avatar
Clément Stenac committed
317

Gildas Bazin's avatar
 
Gildas Bazin committed
318 319
    /* Start timer */
    timer = new Timer( p_intf, this );
320 321 322 323 324 325 326 327 328 329 330

    /* */
    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 ) )
331
        Move( p );
Gildas Bazin's avatar
 
Gildas Bazin committed
332 333 334 335
}

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

338 339 340 341 342
    if( !IsIconized() )
    {
        ws->SetSettings( WindowSettings::ID_MAIN, true,
                         GetPosition(), GetSize() );
    }
343

344 345
    if( video_window ) delete video_window;

346
#ifdef wxHAS_TASK_BAR_ICON
347
    if( p_systray ) delete p_systray;
348
#endif
349

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

Gildas Bazin's avatar
 
Gildas Bazin committed
352
    /* Clean up */
Gildas Bazin's avatar
 
Gildas Bazin committed
353
    delete timer;
Gildas Bazin's avatar
 
Gildas Bazin committed
354
}
Gildas Bazin's avatar
 
Gildas Bazin committed
355

356 357 358 359 360 361
void Interface::Init()
{
    /* Misc init */
    SetupHotkeys();
}

362 363 364
void Interface::Update()
{
    /* Misc updates */
365
    ((VLCVolCtrl *)volctrl)->UpdateVolume();
366 367
}

368
void Interface::OnControlEvent( wxCommandEvent& event )
Gildas Bazin's avatar
Gildas Bazin committed
369
{
370 371 372
    switch( event.GetId() )
    {
    case 0:
Clément Stenac's avatar
Clément Stenac committed
373
        {
374
          if( p_intf->p_sys->b_video_autosize )
Clément Stenac's avatar
Clément Stenac committed
375
          {
376 377
        frame_sizer->Layout();
        frame_sizer->Fit(this);
Clément Stenac's avatar
Clément Stenac committed
378 379
          }
        }
380 381 382 383 384 385 386 387 388
        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
389 390
}

Gildas Bazin's avatar
 
Gildas Bazin committed
391 392 393 394 395
/*****************************************************************************
 * Private methods.
 *****************************************************************************/
void Interface::CreateOurMenuBar()
{
396 397
    int minimal = config_GetInt( p_intf, "wxwin-minimal" );

Gildas Bazin's avatar
 
Gildas Bazin committed
398
    /* Create the "File" menu */
Gildas Bazin's avatar
 
Gildas Bazin committed
399
    wxMenu *file_menu = new wxMenu;
400 401 402

    if (!minimal)
    {
403
    file_menu->Append( OpenFileSimple_Event,
Gildas Bazin's avatar
Gildas Bazin committed
404
                       wxU(_("Quick &Open File...\tCtrl-O")) );
405 406

    file_menu->AppendSeparator();
Gildas Bazin's avatar
Gildas Bazin committed
407
    file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
408
    file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
Gildas Bazin's avatar
Gildas Bazin committed
409
    file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
410
    file_menu->Append( OpenNet_Event,
Gildas Bazin's avatar
Gildas Bazin committed
411 412
                       wxU(_("Open &Network Stream...\tCtrl-N")) );
    file_menu->Append( OpenCapture_Event,
413
                       wxU(_("Open C&apture Device...\tCtrl-A")) );
414

Gildas Bazin's avatar
 
Gildas Bazin committed
415
    file_menu->AppendSeparator();
416
    file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
417
    file_menu->AppendSeparator();
418
    }
Gildas Bazin's avatar
Gildas Bazin committed
419
    file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
420

Gildas Bazin's avatar
 
Gildas Bazin committed
421
    /* Create the "View" menu */
Gildas Bazin's avatar
 
Gildas Bazin committed
422
    wxMenu *view_menu = new wxMenu;
423 424
    if (!minimal)
    {
Gildas Bazin's avatar
Gildas Bazin committed
425
    view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
426
    }
Gildas Bazin's avatar
Gildas Bazin committed
427
    view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
428
    view_menu->Append( FileInfo_Event,
Gildas Bazin's avatar
Gildas Bazin committed
429
                       wxU(_("Stream and Media &info...\tCtrl-I")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
430

431 432 433 434 435
    /* 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
436

Gildas Bazin's avatar
 
Gildas Bazin committed
437
    /* Create the "Help" menu */
Gildas Bazin's avatar
 
Gildas Bazin committed
438
    wxMenu *help_menu = new wxMenu;
Gildas Bazin's avatar
Gildas Bazin committed
439
    help_menu->Append( About_Event, wxU(_("About VLC media player")) );
440 441
    help_menu->AppendSeparator();
    help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
442 443

    /* Append the freshly created menus to the menu bar... */
444
    wxMenuBar *menubar = new wxMenuBar();
Gildas Bazin's avatar
 
Gildas Bazin committed
445 446
    menubar->Append( file_menu, wxU(_("&File")) );
    menubar->Append( view_menu, wxU(_("&View")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
447
    menubar->Append( p_settings_menu, wxU(_("&Settings")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
448 449
    menubar->Append( p_audio_menu, wxU(_("&Audio")) );
    menubar->Append( p_video_menu, wxU(_("&Video")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
450
    menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
451
    menubar->Append( help_menu, wxU(_("&Help")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
452 453 454 455

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

456 457
    /* Find out size of menu bar */
    int i_size = 0;
458
    for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
459 460 461
    {
        int i_width, i_height;
        menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
462 463
        i_size += i_width +
#if defined(__WXGTK__)
464
            22 /* approximate margin */;
465
#else
466
#if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
467
            4 /* approximate margin */;
468
#else
469
            18 /* approximate margin */;
470
#endif
471
#endif
472 473 474
    }
    frame_sizer->SetMinSize( i_size, -1 );

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

478
#if wxUSE_DRAG_AND_DROP
Gildas Bazin's avatar
 
Gildas Bazin committed
479 480
    /* Associate drop targets with the menubar */
    menubar->SetDropTarget( new DragAndDrop( p_intf ) );
Gildas Bazin's avatar
 
Gildas Bazin committed
481
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
482 483 484 485
}

void Interface::CreateOurToolBar()
{
486
#define HELP_OPEN N_("Open")
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
487 488 489 490
#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
491 492
#define HELP_PLP N_("Previous playlist item")
#define HELP_PLN N_("Next playlist item")
Gildas Bazin's avatar
 
Gildas Bazin committed
493 494
#define HELP_SLOW N_("Play slower")
#define HELP_FAST N_("Play faster")
Gildas Bazin's avatar
 
Gildas Bazin committed
495

496 497
    int minimal = config_GetInt( p_intf, "wxwin-minimal" );

Gildas Bazin's avatar
 
Gildas Bazin committed
498 499
    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
500

501
    wxToolBar *toolbar =
502
        CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
Gildas Bazin's avatar
 
Gildas Bazin committed
503

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

506 507
    if (!minimal)
    {
508 509 510
    toolbar->AddTool( OpenFile_Event, wxT(""),
                      wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
    toolbar->AddSeparator();
511
    }
512 513

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

517 518
    if (!minimal)
    {
519 520
    toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
                      wxU(_(HELP_STOP)) );
Gildas Bazin's avatar
 
Gildas Bazin committed
521
    toolbar->AddSeparator();
522

Gildas Bazin's avatar
 
Gildas Bazin committed
523
    toolbar->AddTool( PrevStream_Event, wxT(""),
524 525 526 527 528
                      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
529
    toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
Gildas Bazin's avatar
 
Gildas Bazin committed
530
                      wxU(_(HELP_PLN)) );
531
    toolbar->AddSeparator();
532
    toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
533
                      wxU(_(HELP_PLO)) );
534
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
535

536
    wxControl *p_dummy_ctrl =
537
        new wxControl( toolbar, -1, wxDefaultPosition,
538
                       wxSize(35, 16 ), wxBORDER_NONE );
539

540
    toolbar->AddControl( p_dummy_ctrl );
Gildas Bazin's avatar
 
Gildas Bazin committed
541

542 543
    volctrl = new VLCVolCtrl( p_intf, toolbar );
    toolbar->AddControl( volctrl );
544 545

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

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

Gildas Bazin's avatar
 
Gildas Bazin committed
553
void Interface::CreateOurSlider()
Gildas Bazin's avatar
 
Gildas Bazin committed
554
{
Gildas Bazin's avatar
 
Gildas Bazin committed
555
    /* Create a new frame and sizer containing the slider */
Gildas Bazin's avatar
 
Gildas Bazin committed
556
    slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
Gildas Bazin's avatar
 
Gildas Bazin committed
557
    slider_frame->SetAutoLayout( TRUE );
558 559
    slider_sizer = new wxBoxSizer( wxHORIZONTAL );
    //slider_sizer->SetMinSize( -1, 50 );
Gildas Bazin's avatar
 
Gildas Bazin committed
560 561 562 563

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

565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
    /* 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
585
    /* Add everything to the frame */
586 587 588 589 590 591 592 593 594
    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
595 596 597

    /* Hide the slider by default */
    slider_frame->Hide();
Gildas Bazin's avatar
 
Gildas Bazin committed
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 624 625 626 627 628 629 630 631 632 633 634 635 636
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;
637 638 639
        case KEY_END: return WXK_END;
        case KEY_INSERT: return WXK_INSERT;
        case KEY_DELETE: return WXK_DELETE;
640 641 642 643 644 645 646 647 648 649 650
        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;
}

651
void Interface::SetupHotkeys()
652
{
653 654
    struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
    int i_hotkeys;
655

656 657 658 659 660 661
    /* 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;

662
    wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
663 664

    /* Setup the hotkeys as accelerators */
665
    for( int i = 0; i < i_hotkeys; i++ )
666
    {
667 668 669 670
        int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
        int i_key = ConvertHotkey( p_hotkeys[i].i_key );

#ifdef WIN32
671 672
        if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
            i_key = toupper(i_key);
673 674 675
#endif

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

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

681 682 683 684 685 686 687 688
    if( !accel.Ok() )
    {
        msg_Err( p_intf, "invalid accelerator table" );
    }
    else
    {
        SetAcceleratorTable( accel );
    }
689 690

    delete [] p_entries;
691 692
}

693
void Interface::HideSlider( bool layout )
Clément Stenac's avatar
Clément Stenac committed
694
{
695
    ShowSlider( false, layout );
Clément Stenac's avatar
Clément Stenac committed
696 697
}

698
void Interface::ShowSlider( bool show, bool layout )
Clément Stenac's avatar
Clément Stenac committed
699
{
700
    if( show )
701
    {
702 703 704
        //prevent the hide timers from hiding it now
        m_slider_timer.Stop();
        m_controls_timer.Stop();
705

706 707
        //prevent continuous layout
        if( slider_frame->IsShown() ) return;
708
    }
709 710 711 712 713
    else
    {
        //prevent continuous layout
        if( !slider_frame->IsShown() ) return;
    }
Clément Stenac's avatar
Clément Stenac committed
714

715 716 717 718 719 720
    if( layout && p_intf->p_sys->b_video_autosize )
        UpdateVideoWindow( p_intf, video_window );

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

721
    if( layout )
Clément Stenac's avatar
Clément Stenac committed
722
    {
723
        frame_sizer->Layout();
724
        if( p_intf->p_sys->b_video_autosize ) frame_sizer->Fit( this );
Clément Stenac's avatar
Clément Stenac committed
725 726 727
    }
}

728
void Interface::HideDiscFrame( bool layout )
Clément Stenac's avatar
Clément Stenac committed
729
{
730
    ShowDiscFrame( false, layout );
Clément Stenac's avatar
Clément Stenac committed
731 732
}

733
void Interface::ShowDiscFrame( bool show, bool layout )
Clément Stenac's avatar
Clément Stenac committed
734
{
735
    if( show )
736
    {
737 738
        //prevent the hide timer from hiding it now
        m_controls_timer.Stop();
739

740 741
        //prevent continuous layout
        if( disc_frame->IsShown() ) return;
742
    }
743 744 745 746 747
    else
    {
        //prevent continuous layout
        if( !disc_frame->IsShown() ) return;
    }
Clément Stenac's avatar
Clément Stenac committed
748

749 750 751 752 753 754
    if( layout && p_intf->p_sys->b_video_autosize )
        UpdateVideoWindow( p_intf, video_window );

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

755
    if( layout )
Clément Stenac's avatar
Clément Stenac committed
756
    {
757 758 759
        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
760 761 762
    }
}

Gildas Bazin's avatar
 
Gildas Bazin committed
763
/*****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
764
 * Event Handlers.
Gildas Bazin's avatar
 
Gildas Bazin committed
765
 *****************************************************************************/
766
void Interface::OnControlsTimer( wxTimerEvent& WXUNUSED(event) )
Clément Stenac's avatar
Clément Stenac committed
767
{
768 769 770
    if( p_intf->p_sys->b_video_autosize )
        UpdateVideoWindow( p_intf, video_window );

771 772 773 774 775 776 777 778 779 780 781
    /* 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
782
}
Clément Stenac's avatar
Clément Stenac committed
783

784 785 786
void Interface::OnSliderTimer( wxTimerEvent& WXUNUSED(event) )
{
    HideSlider();
Clément Stenac's avatar
Clément Stenac committed
787 788
}

789
void Interface::OnMenuOpen( wxMenuEvent& event )
Gildas Bazin's avatar
 
Gildas Bazin committed
790
{
791 792
#if defined( __WXMSW__ )
#   define GetEventObject GetMenu
793
#endif
794 795

    if( event.GetEventObject() == p_settings_menu )
Gildas Bazin's avatar
 
Gildas Bazin committed
796
    {
797 798 799 800
        p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );

        /* Add static items */
        p_settings_menu->AppendCheckItem( Extended_Event,
801
            wxU(_("Extended &GUI\tCtrl-G") ) );
802
        if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
803 804 805 806 807
#if 0
        p_settings_menu->AppendCheckItem( Undock_Event,
            wxU(_("&Undock Ext. GUI") ) );
        if( b_undock ) p_settings_menu->Check( Undock_Event, TRUE );
#endif
808 809 810 811
        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
812
    }
813

Gildas Bazin's avatar
 
Gildas Bazin committed
814
    else if( event.GetEventObject() == p_audio_menu )
Gildas Bazin's avatar
 
Gildas Bazin committed
815
    {
816
        p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
Gildas Bazin's avatar
 
Gildas Bazin committed
817
    }
818

Gildas Bazin's avatar
 
Gildas Bazin committed
819 820
    else if( event.GetEventObject() == p_video_menu )
    {
821
        p_video_menu = VideoMenu( p_intf, this, p_video_menu );
Gildas Bazin's avatar
 
Gildas Bazin committed
822
    }
823

Gildas Bazin's avatar
 
Gildas Bazin committed
824 825
    else if( event.GetEventObject() == p_navig_menu )
    {
826
        p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
Gildas Bazin's avatar
 
Gildas Bazin committed
827
    }
828 829 830 831

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

Gildas Bazin's avatar
 
Gildas Bazin committed
834
#if defined( __WXMSW__ ) || defined( __WXMAC__ )
Gildas Bazin's avatar
 
Gildas Bazin committed
835
void Interface::OnContextMenu2(wxContextMenuEvent& event)
Gildas Bazin's avatar
 
Gildas Bazin committed
836
{
Gildas Bazin's avatar
 
Gildas Bazin committed
837 838 839 840 841 842 843
    /* Only show the context menu for the main interface */
    if( GetId() != event.GetId() )
    {
        event.Skip();
        return;
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
844
    if( p_intf->p_sys->pf_show_dialog )
845
        p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
Gildas Bazin's avatar
 
Gildas Bazin committed
846
}
Gildas Bazin's avatar
 
Gildas Bazin committed
847
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
848 849
void Interface::OnContextMenu(wxMouseEvent& event)
{
Gildas Bazin's avatar
 
Gildas Bazin committed
850
    if( p_intf->p_sys->pf_show_dialog )
851
        p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
Gildas Bazin's avatar
 
Gildas Bazin committed
852
}
Gildas Bazin's avatar
 
Gildas Bazin committed
853

Gildas Bazin's avatar
 
Gildas Bazin committed
854 855 856 857 858 859 860 861 862
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
863
    msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
864
        wxU(_(" (wxWidgets interface)\n\n")) +
865
        wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
Antoine Cellerier's avatar
Antoine Cellerier committed
866
        wxU( INTF_ABOUT_MSG ) + wxT("\n\n") +
Gildas Bazin's avatar
 
Gildas Bazin committed
867
        wxU(_("The VideoLAN team <videolan@videolan.org>\n"
Gildas Bazin's avatar
 
Gildas Bazin committed
868
              "http://www.videolan.org/\n\n")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
869

Gildas Bazin's avatar
 
Gildas Bazin committed
870 871
    wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
                  wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
Gildas Bazin's avatar
 
Gildas Bazin committed
872 873
}

Gildas Bazin's avatar
 
Gildas Bazin committed
874
void Interface::OnShowDialog( wxCommandEvent& event )
Gildas Bazin's avatar
 
Gildas Bazin committed
875
{
Gildas Bazin's avatar
 
Gildas Bazin committed
876
    if( p_intf->p_sys->pf_show_dialog )
Gildas Bazin's avatar
 
Gildas Bazin committed
877
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
878
        int i_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
879

Gildas Bazin's avatar
 
Gildas Bazin committed
880 881 882 883 884
        switch( event.GetId() )
        {
        case OpenFileSimple_Event:
            i_id = INTF_DIALOG_FILE_SIMPLE;
            break;
885 886
        case OpenAdv_Event:
            i_id = INTF_DIALOG_FILE;
Gildas Bazin's avatar
 
Gildas Bazin committed
887 888 889
        case OpenFile_Event:
            i_id = INTF_DIALOG_FILE;
            break;
890 891 892
        case OpenDir_Event:
            i_id = INTF_DIALOG_DIRECTORY;
            break;
Gildas Bazin's avatar
 
Gildas Bazin committed
893 894 895 896 897 898
        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
899 900 901
        case OpenCapture_Event:
            i_id = INTF_DIALOG_CAPTURE;
            break;
Gildas Bazin's avatar
 
Gildas Bazin committed
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
        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;
917 918 919
        case Wizard_Event:
            i_id = INTF_DIALOG_WIZARD;
            break;
Gildas Bazin's avatar
Gildas Bazin committed
920 921 922
        case Bookmarks_Event:
            i_id = INTF_DIALOG_BOOKMARKS;
            break;
923 924 925
        case UpdateVLC_Event:
            i_id = INTF_DIALOG_UPDATEVLC;
            break;
Gildas Bazin's avatar
 
Gildas Bazin committed
926 927 928 929
        default:
            i_id = INTF_DIALOG_FILE;
            break;
        }
Gildas Bazin's avatar
 
Gildas Bazin committed
930

Gildas Bazin's avatar
 
Gildas Bazin committed
931
        p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
Gildas Bazin's avatar
 
Gildas Bazin committed
932
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
933 934
}

Gildas Bazin's avatar
Gildas Bazin committed
935
void Interface::OnExtended(wxCommandEvent& event)
Clément Stenac's avatar
Clément Stenac committed
936
{
937 938 939
    b_extra = (b_extra == VLC_TRUE ? VLC_FALSE : VLC_TRUE );

    if( b_extra == VLC_FALSE )
Clément Stenac's avatar
Clément Stenac committed
940
    {
941 942
        extra_frame->Hide();
        frame_sizer->Hide( extra_frame );
Clément Stenac's avatar
Clément Stenac committed
943 944 945
    }
    else
    {
946 947
        extra_frame->Show();
        frame_sizer->Show( extra_frame );
Clément Stenac's avatar
Clément Stenac committed
948 949 950 951 952
    }
    frame_sizer->Layout();
    frame_sizer->Fit(this);
}

953 954
#if 0
        if( b_undock == VLC_TRUE )
Clément Stenac's avatar
Clément Stenac committed
955
        {
956 957 958 959 960 961
                fprintf(stderr,"Deleting window\n");
            if( extra_window )
            {
                delete extra_window;
                extra_window = NULL;
            }
Clément Stenac's avatar
Clément Stenac committed
962 963 964
        }
        else
        {
965 966 967 968
            extra_frame->Hide();
            frame_sizer->Hide( extra_frame );
            frame_sizer->Layout();
            frame_sizer->Fit(this);
Clément Stenac's avatar
Clément Stenac committed
969 970 971 972
        }
    }
    else
    {
973
        if( b_undock == VLC_TRUE )
Clément Stenac's avatar
Clément Stenac committed
974
        {
975 976 977
                fprintf(stderr,"Creating window\n");
            extra_frame->Hide();
            frame_sizer->Hide( extra_frame );
Clément Stenac's avatar
Clément Stenac committed
978
#if (wxCHECK_VERSION(2,5,0))
979
            frame_sizer->Detach( extra_frame );
Clément Stenac's avatar
Clément Stenac committed
980 981 982
#else
            frame_sizer->Remove( extra_frame );
#endif
983 984 985 986 987 988 989 990
            frame_sizer->Layout();
            frame_sizer->Fit(this);
            extra_window = new ExtraWindow( p_intf, this, extra_frame );
        }
        else
        {
                fprintf(stderr,"Deleting window\n");
            if( extra_window )
991
            {
992
                delete extra_window;
993
            }
994 995 996 997
            extra_frame->Show();
            frame_sizer->Show( extra_frame );
            frame_sizer->Layout();
            frame_sizer->Fit(this);
Clément Stenac's avatar
Clément Stenac committed
998 999 1000 1001
        }
    }
}

1002
void Interface::OnUndock(wxCommandEvent& event)
Clément Stenac's avatar
Clément Stenac committed
1003
{
1004
    b_undock = (b_undock == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
Clément Stenac's avatar
Clément Stenac committed
1005

1006 1007 1008
    if( b_extra == VLC_TRUE )
    {
        if( b_undock == VLC_FALSE )
1009
        {
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
                fprintf(stderr,"Deleting window\n");
            if( extra_window )
            {
                delete extra_window;
                extra_window = NULL;
            }
            extra_frame->Show();
            frame_sizer->Show( extra_frame );
            frame_sizer->Layout();
            frame_sizer->Fit(this);
1020
        }
1021
        else
1022
        {
1023 1024 1025
                fprintf(stderr,"Creating window\n");
            extra_frame->Hide();
            frame_sizer->Hide( extra_frame );
Clément Stenac's avatar
Clément Stenac committed
1026
#if (wxCHECK_VERSION(2,5,0))
1027
            frame_sizer->Detach( extra_frame );
Clément Stenac's avatar
Clément Stenac committed
1028 1029 1030
#else
            frame_sizer->Remove( extra_frame );
#endif
1031 1032 1033
            frame_sizer->Layout();
            frame_sizer->Fit(this);
            extra_window = new ExtraWindow( p_intf, this, extra_frame );
1034
        }
1035 1036
    }
}
1037
#endif
1038

1039

Gildas Bazin's avatar
 
Gildas Bazin committed
1040
void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1041 1042 1043 1044 1045
{
    PlayStream();
}

void Interface::PlayStream()
Gildas Bazin's avatar
 
Gildas Bazin committed
1046 1047 1048 1049 1050
{
    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
1051
    if( p_playlist == NULL ) return;
Gildas Bazin's avatar
 
Gildas Bazin committed
1052

Clément Stenac's avatar
Clément Stenac committed
1053
    if( p_playlist->i_size && p_playlist->i_enabled )
Gildas Bazin's avatar
 
Gildas Bazin committed
1054
    {
1055 1056
        vlc_value_t state;

Gildas Bazin's avatar
 
Gildas Bazin committed
1057 1058 1059 1060 1061 1062 1063
        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
1064
            TogglePlayButton( PLAYING_S );
Gildas Bazin's avatar
 
Gildas Bazin committed
1065 1066 1067 1068
            vlc_object_release( p_playlist );
            return;
        }

1069 1070 1071
        var_Get( p_input, "state", &state );

        if( state.i_int != PAUSE_S )
Gildas Bazin's avatar
 
Gildas Bazin committed
1072 1073
        {
            /* A stream is being played, pause it */
1074
            state.i_int = PAUSE_S;
Gildas Bazin's avatar
 
Gildas Bazin committed
1075
        }
1076 1077 1078 1079 1080 1081
        else
        {
            /* Stream is paused, resume it */
            state.i_int = PLAYING_S;
        }
        var_Set( p_input, "state", state );
Gildas Bazin's avatar
 
Gildas Bazin committed
1082

1083
        TogglePlayButton( state.i_int );
Gildas Bazin's avatar
 
Gildas Bazin committed
1084
        vlc_object_release( p_input );
Gildas Bazin's avatar
 
Gildas Bazin committed
1085 1086 1087 1088
        vlc_object_release( p_playlist );
    }
    else
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
1089
        /* If the playlist is empty, open a file requester instead */
Gildas Bazin's avatar
 
Gildas Bazin committed
1090
        vlc_object_release( p_playlist );
Gildas Bazin's avatar
 
Gildas Bazin committed
1091
        OnShowDialog( dummy );
Gildas Bazin's avatar
 
Gildas Bazin committed
1092 1093 1094 1095
    }
}

void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1096 1097 1098 1099
{
    StopStream();
}
void Interface::StopStream()
Gildas Bazin's avatar
 
Gildas Bazin committed
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
{
    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
1110
    TogglePlayButton( PAUSE_S );
Gildas Bazin's avatar
 
Gildas Bazin committed
1111 1112 1113 1114 1115
    vlc_object_release( p_playlist );
}

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

Gildas Bazin's avatar
 
Gildas Bazin committed
1118
#ifdef WIN32
Gildas Bazin's avatar
 
Gildas Bazin committed
1119
    if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
Gildas Bazin's avatar
 
Gildas Bazin committed
1120
        || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
Gildas Bazin's avatar
 
Gildas Bazin committed
1121
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
1122
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
1123 1124 1125
        if( p_intf->p_sys->i_slider_pos != event.GetPosition()
            && p_intf->p_sys->p_input )
        {
1126 1127 1128 1129
            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
1130
        }
Gildas Bazin's avatar
 
Gildas Bazin committed
1131

Gildas Bazin's avatar
 
Gildas Bazin committed
1132
#ifdef WIN32
Gildas Bazin's avatar
 
Gildas Bazin committed
1133 1134 1135 1136 1137 1138
        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
1139 1140 1141
        if( p_intf->p_sys->p_input )
        {
            /* Update stream date */
1142 1143 1144
            char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
            mtime_t i_seconds;

1145 1146
            i_seconds = var_GetTime( p_intf->p_sys->p_input, "length" ) /
                        I64C(1000000 );
1147
            secstotimestr( psz_total, i_seconds );
Gildas Bazin's avatar
 
Gildas Bazin committed
1148

1149 1150
            i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) /
                        I64C(1000000 );
1151 1152
            secstotimestr( psz_time, i_seconds );

1153 1154
            statusbar->SetStatusText( wxU(psz_time) + wxString(wxT(" / ") ) +
                                      wxU(psz_total), 0 );
Gildas Bazin's avatar
 
Gildas Bazin committed
1155
        }
Gildas Bazin's avatar
 
Gildas Bazin committed
1156
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
1157
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
1158

1159
#undef WIN32
Gildas Bazin's avatar
 
Gildas Bazin committed
1160
    vlc_mutex_unlock( &p_intf->change_lock );
Gildas Bazin's avatar
 
Gildas Bazin committed
1161 1162 1163
}

void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1164 1165 1166 1167 1168
{
    PrevStream();
}

void Interface::PrevStream()
Gildas Bazin's avatar
 
Gildas Bazin committed
1169 1170 1171 1172 1173 1174 1175 1176 1177
{
    playlist_t * p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

1178 1179
    /* FIXME --fenrir */
#if 0
Gildas Bazin's avatar
 
Gildas Bazin committed
1180 1181 1182 1183 1184 1185
    if( p_playlist->p_input != NULL )
    {
        vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
        if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
        {
            vlc_value_t val; val.b_bool = VLC_TRUE;
Sam Hocevar's avatar
Sam Hocevar committed
1186
            vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
Gildas Bazin's avatar
 
Gildas Bazin committed
1187
            var_Set( p_playlist->p_input, "prev-title", val );
Sam Hocevar's avatar
Sam Hocevar committed
1188 1189
        } else
            vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
Gildas Bazin's avatar
 
Gildas Bazin committed
1190 1191
    }
    vlc_mutex_unlock( &p_playlist->object_lock );
1192
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
1193

Gildas Bazin's avatar
 
Gildas Bazin committed
1194 1195 1196 1197 1198
    playlist_Prev( p_playlist );
    vlc_object_release( p_playlist );
}

void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1199 1200 1201 1202 1203
{
    NextStream();
}

void Interface::NextStream()
Gildas Bazin's avatar
 
Gildas Bazin committed
1204 1205 1206 1207 1208 1209 1210 1211 1212
{
    playlist_t * p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

1213 1214 1215
    /* FIXME --fenrir */
#if 0
    var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
Gildas Bazin's avatar
 
Gildas Bazin committed
1216 1217 1218 1219 1220 1221 1222 1223 1224
    vlc_mutex_lock( &p_playlist->object_lock );
    if( p_playlist->p_input != NULL )
    {
        vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
        if( p_playlist->p_input->stream.i_area_nb > 1 &&
            p_playlist->p_input->stream.p_selected_area->i_id <
              p_playlist->p_input->stream.i_area_nb - 1 )
        {
            vlc_value_t val; val.b_bool = VLC_TRUE;
Sam Hocevar's avatar
Sam Hocevar committed
1225
            vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
Gildas Bazin's avatar
 
Gildas Bazin committed
1226
            var_Set( p_playlist->p_input, "next-title", val );
Sam Hocevar's avatar
Sam Hocevar committed
1227 1228
        } else
            vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
Gildas Bazin's avatar
 
Gildas Bazin committed
1229 1230
    }
    vlc_mutex_unlock( &p_playlist->object_lock );
1231
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
1232 1233 1234
    playlist_Next( p_playlist );
    vlc_object_release( p_playlist );
}
Gildas Bazin's avatar
 
Gildas Bazin committed
1235

Gildas Bazin's avatar
 
Gildas Bazin committed
1236 1237 1238 1239 1240 1241 1242
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 )
    {
1243 1244 1245
        vlc_value_t val; val.b_bool = VLC_TRUE;

        var_Set( p_input, "rate-slower", val );
Gildas Bazin's avatar
 
Gildas Bazin committed
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256
        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 )
    {
1257 1258 1259
        vlc_value_t val; val.b_bool = VLC_TRUE;

        var_Set( p_input, "rate-faster", val );
Gildas Bazin's avatar
 
Gildas Bazin committed
1260 1261 1262 1263
        vlc_object_release( p_input );
    }
}

Gildas Bazin's avatar
 
Gildas Bazin committed
1264
void Interface::TogglePlayButton( int i_playing_status )
Gildas Bazin's avatar
 
Gildas Bazin committed
1265
{
Gildas Bazin's avatar
 
Gildas Bazin committed
1266 1267 1268
    if( i_playing_status == i_old_playing_status )
        return;

1269 1270
    wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
        GetToolBar()->GetToolClientData( PlayStream_Event );
1271
    if( !p_tool ) return;
Gildas Bazin's avatar
 
Gildas Bazin committed
1272 1273 1274

    if( i_playing_status == PLAYING_S )
    {
1275 1276 1277
        p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
        p_tool->SetLabel( wxU(_("Pause")) );
        p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
Gildas Bazin's avatar
 
Gildas Bazin committed
1278 1279 1280
    }
    else
    {
1281 1282 1283
        p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
        p_tool->SetLabel( wxU(_("Play")) );
        p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
Gildas Bazin's avatar
 
Gildas Bazin committed
1284 1285 1286
    }

    GetToolBar()->Realize();
1287 1288
    GetToolBar()->ToggleTool( PlayStream_Event, true );
    GetToolBar()->ToggleTool( PlayStream_Event, false );
Gildas Bazin's avatar
 
Gildas Bazin committed
1289 1290

    i_old_playing_status = i_playing_status;
Gildas Bazin's avatar
 
Gildas Bazin committed
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 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
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 );
    }
}

1341
#if wxUSE_DRAG_AND_DROP
Gildas Bazin's avatar
 
Gildas Bazin committed
1342 1343 1344
/*****************************************************************************
 * Definition of DragAndDrop class.
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
1345
DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
Gildas Bazin's avatar
 
Gildas Bazin committed
1346 1347
{
    p_intf = _p_intf;
Gildas Bazin's avatar
 
Gildas Bazin committed
1348
    b_enqueue = _b_enqueue;
Gildas Bazin's avatar
 
Gildas Bazin committed
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363
}

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
1364
    for( size_t i = 0; i < filenames.GetCount(); i++ )
1365 1366
        playlist_Add( p_playlist, (const char *)filenames[i].mb_str(),
                      (const char *)filenames[i].mb_str(),
Gildas Bazin's avatar
 
Gildas Bazin committed
1367 1368
                      PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
                      PLAYLIST_END );
Gildas Bazin's avatar
 
Gildas Bazin committed
1369 1370 1371 1372 1373

    vlc_object_release( p_playlist );

    return TRUE;
}
Gildas Bazin's avatar
 
Gildas Bazin committed
1374
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
1375 1376

/*****************************************************************************
1377
 * Definition of VolCtrl class.
Gildas Bazin's avatar
 
Gildas Bazin committed
1378
 *****************************************************************************/
1379 1380 1381 1382 1383 1384 1385 1386 1387
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();
1388
    int GetVolume();
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403

    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()

1404 1405 1406
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
1407 1408
{
    p_intf = _p_intf;
1409
    UpdateVolume();
Gildas Bazin's avatar
 
Gildas Bazin committed
1410 1411 1412 1413
}

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

1416
    int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1417 1418
    aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
    UpdateVolume();
Gildas Bazin's avatar
 
Gildas Bazin committed
1419 1420
}

1421
void wxVolCtrl::UpdateVolume()
Gildas Bazin's avatar
 
Gildas Bazin committed
1422
{
1423 1424 1425 1426 1427 1428 1429
    audio_volume_t i_volume;
    aout_VolumeGet( p_intf, &i_volume );

    int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
    if( i_gauge_volume == GetValue() ) return;

    SetValue( i_gauge_volume );
Gildas Bazin's avatar
 
Gildas Bazin committed
1430
    SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1431
                i_gauge_volume / 2 ) );
Gildas Bazin's avatar
 
Gildas Bazin committed
1432
}
1433

1434 1435 1436 1437 1438 1439 1440 1441 1442
#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),
1443
   b_mute(0), p_intf(_p_intf)
1444 1445 1446 1447 1448 1449 1450 1451
{
    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 );
1452
    wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1453 1454 1455 1456 1457 1458 1459 1460 1461
    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 );
1462 1463 1464

        b_mute = !b_mute;
        Refresh();
1465 1466 1467 1468 1469 1470
    }
}

void VLCVolCtrl::UpdateVolume()
{
    gauge->UpdateVolume();
1471 1472 1473 1474

    int i_volume = gauge->GetValue();
    if( !!i_volume == !b_mute ) return;
    b_mute = !b_mute;
1475
    Refresh();
1476 1477
}

1478
/*****************************************************************************
1479
 * Systray class.
1480 1481
 *****************************************************************************/

1482
#ifdef wxHAS_TASK_BAR_ICON
1483 1484 1485 1486 1487 1488 1489 1490 1491

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 */
1492
    EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1493 1494 1495 1496 1497 1498 1499
    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()

1500
Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1501 1502
{
    p_main_interface = _p_main_interface;
1503
    p_intf = _p_intf;
1504 1505 1506
}

/* Event handlers */
1507
void Systray::OnMenuIconize( wxCommandEvent& event )
1508 1509
{
    p_main_interface->Show( ! p_main_interface->IsShown() );
1510
    if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1511 1512
}

1513 1514 1515 1516 1517 1518
void Systray::OnLeftClick( wxTaskBarIconEvent& event )
{
    wxCommandEvent cevent;
    OnMenuIconize(cevent);
}

1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546
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()
{
1547 1548
    int minimal = config_GetInt( p_intf, "wxwin-minimal" );

1549 1550 1551 1552
    wxMenu* systray_menu = new wxMenu;
    systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
    systray_menu->AppendSeparator();
    systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1553 1554 1555

    if (!minimal)
    {
1556 1557 1558
    systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
    systray_menu->Append( NextStream_Event, wxU(_("Next")) );
    systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1559
    }
1560 1561 1562 1563
    systray_menu->AppendSeparator();
    systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
    return systray_menu;
}
1564 1565 1566 1567 1568

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