menus.cpp 32.5 KB
Newer Older
Gildas Bazin's avatar
 
Gildas Bazin committed
1
/*****************************************************************************
2
 * menus.cpp : wxWidgets plugin for vlc
Gildas Bazin's avatar
 
Gildas Bazin committed
3
 *****************************************************************************
4
 * Copyright (C) 2000-2004 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 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
 *
 * 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.
 *
 * 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
 *****************************************************************************/
#include <stdlib.h>                                      /* malloc(), free() */
#include <errno.h>                                                 /* ENOMEM */
#include <string.h>                                            /* strerror() */
#include <stdio.h>

#include <vlc/vlc.h>
#include <vlc/intf.h>

35
#include "wxwidgets.h"
Gildas Bazin's avatar
 
Gildas Bazin committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

class wxMenuItemExt: public wxMenuItem
{
public:
    /* Constructor */
    wxMenuItemExt( 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 ~wxMenuItemExt();

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

private:

};

57 58 59 60
class Menu: public wxMenu
{
public:
    /* Constructor */
61
    Menu( intf_thread_t *p_intf, int i_start_id );
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    virtual ~Menu();

    void Populate( int i_count, char **ppsz_names, int *pi_objects );
    void Clear();

private:
    wxMenu *Menu::CreateDummyMenu();
    void   Menu::CreateMenuItem( wxMenu *, char *, vlc_object_t * );
    wxMenu *Menu::CreateChoicesMenu( char *, vlc_object_t *, bool );

    DECLARE_EVENT_TABLE();

    intf_thread_t *p_intf;

    int i_start_id;
    int i_item_id;
};

Gildas Bazin's avatar
 
Gildas Bazin committed
80 81 82 83 84 85 86 87
/*****************************************************************************
 * Event Table.
 *****************************************************************************/

/* IDs for the controls and the menu commands */
enum
{
    /* menu items */
Gildas Bazin's avatar
 
Gildas Bazin committed
88
    MenuDummy_Event = wxID_HIGHEST + 1000,
89
    OpenFileSimple_Event = wxID_HIGHEST + 1100,
Gildas Bazin's avatar
 
Gildas Bazin committed
90 91 92
    OpenFile_Event,
    OpenDisc_Event,
    OpenNet_Event,
93
    OpenCapture_Event,
94 95
    MediaInfo_Event,
    Messages_Event,
96
    Preferences_Event,
97 98 99 100 101
    Play_Event,
    Pause_Event,
    Previous_Event,
    Next_Event,
    Stop_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
102
    FirstAutoGenerated_Event = wxID_HIGHEST + 1999,
Gildas Bazin's avatar
 
Gildas Bazin committed
103
    SettingsMenu_Events = wxID_HIGHEST + 5000,
Gildas Bazin's avatar
 
Gildas Bazin committed
104 105 106
    AudioMenu_Events = wxID_HIGHEST + 2000,
    VideoMenu_Events = wxID_HIGHEST + 3000,
    NavigMenu_Events = wxID_HIGHEST + 4000,
107 108
    PopupMenu_Events = wxID_HIGHEST + 6000,
    Hotkeys_Events = wxID_HIGHEST + 7000
Gildas Bazin's avatar
 
Gildas Bazin committed
109 110 111 112 113 114
};

BEGIN_EVENT_TABLE(Menu, wxMenu)
END_EVENT_TABLE()

BEGIN_EVENT_TABLE(MenuEvtHandler, wxEvtHandler)
Gildas Bazin's avatar
 
Gildas Bazin committed
115 116 117 118
    EVT_MENU(OpenFileSimple_Event, MenuEvtHandler::OnShowDialog)
    EVT_MENU(OpenFile_Event, MenuEvtHandler::OnShowDialog)
    EVT_MENU(OpenDisc_Event, MenuEvtHandler::OnShowDialog)
    EVT_MENU(OpenNet_Event, MenuEvtHandler::OnShowDialog)
119
    EVT_MENU(OpenCapture_Event, MenuEvtHandler::OnShowDialog)
120 121
    EVT_MENU(MediaInfo_Event, MenuEvtHandler::OnShowDialog)
    EVT_MENU(Messages_Event, MenuEvtHandler::OnShowDialog)
122
    EVT_MENU(Preferences_Event, MenuEvtHandler::OnShowDialog)
Gildas Bazin's avatar
 
Gildas Bazin committed
123 124 125
    EVT_MENU(-1, MenuEvtHandler::OnMenuEvent)
END_EVENT_TABLE()

Gildas Bazin's avatar
 
Gildas Bazin committed
126 127 128
wxMenu *OpenStreamMenu( intf_thread_t *p_intf )
{
    wxMenu *menu = new wxMenu;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
129
    menu->Append( OpenFileSimple_Event, wxU(_("Quick &Open File...")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
130 131 132
    menu->Append( OpenFile_Event, wxU(_("Open &File...")) );
    menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")) );
    menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")) );
133
    menu->Append( OpenCapture_Event, wxU(_("Open &Capture Device...")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
134 135 136
    return menu;
}

137 138 139 140 141 142 143 144 145
wxMenu *MiscMenu( intf_thread_t *p_intf )
{
    wxMenu *menu = new wxMenu;
    menu->Append( MediaInfo_Event, wxU(_("Media &Info...")) );
    menu->Append( Messages_Event, wxU(_("&Messages...")) );
    menu->Append( Preferences_Event, wxU(_("&Preferences...")) );
    return menu;
}

Gildas Bazin's avatar
 
Gildas Bazin committed
146
void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
Gildas Bazin's avatar
 
Gildas Bazin committed
147
                const wxPoint& pos )
Gildas Bazin's avatar
 
Gildas Bazin committed
148
{
149
#define MAX_POPUP_ITEMS 45
Gildas Bazin's avatar
 
Gildas Bazin committed
150

151
    int minimal = config_GetInt( p_intf, "wx-minimal" );
152

153
    vlc_object_t *p_object, *p_input;
Gildas Bazin's avatar
 
Gildas Bazin committed
154 155
    char *ppsz_varnames[MAX_POPUP_ITEMS];
    int pi_objects[MAX_POPUP_ITEMS];
156
    int i = 0, i_last_separator = 0;
Gildas Bazin's avatar
 
Gildas Bazin committed
157 158

    /* Initializations */
Gildas Bazin's avatar
 
Gildas Bazin committed
159
    memset( pi_objects, 0, MAX_POPUP_ITEMS * sizeof(int) );
Gildas Bazin's avatar
 
Gildas Bazin committed
160

161 162
    /* Input menu */
    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
Gildas Bazin's avatar
 
Gildas Bazin committed
163 164 165
                                                FIND_ANYWHERE );
    if( p_object != NULL )
    {
166
        ppsz_varnames[i] = "bookmark";
Gildas Bazin's avatar
 
Gildas Bazin committed
167
        pi_objects[i++] = p_object->i_object_id;
168
        ppsz_varnames[i] = "title";
Gildas Bazin's avatar
 
Gildas Bazin committed
169
        pi_objects[i++] = p_object->i_object_id;
170
        ppsz_varnames[i] = "chapter";
Gildas Bazin's avatar
 
Gildas Bazin committed
171
        pi_objects[i++] = p_object->i_object_id;
172 173 174 175 176 177 178 179 180 181 182 183
        ppsz_varnames[i] = "program";
        pi_objects[i++] = p_object->i_object_id;
        ppsz_varnames[i] = "navigation";
        pi_objects[i++] = p_object->i_object_id;
        ppsz_varnames[i] = "dvd_menus";
        pi_objects[i++] = p_object->i_object_id;

        ppsz_varnames[i] = "video-es";
        pi_objects[i++] = p_object->i_object_id;
        ppsz_varnames[i] = "audio-es";
        pi_objects[i++] = p_object->i_object_id;
        ppsz_varnames[i] = "spu-es";
184
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
185
    }
186 187
    p_input = p_object;
    if( !p_input ) goto interfacemenu;
Gildas Bazin's avatar
 
Gildas Bazin committed
188 189

    /* Video menu */
190 191
    if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
    i_last_separator = i;
Gildas Bazin's avatar
 
Gildas Bazin committed
192

Gildas Bazin's avatar
 
Gildas Bazin committed
193
    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
Gildas Bazin's avatar
 
Gildas Bazin committed
194 195 196
                                                FIND_ANYWHERE );
    if( p_object != NULL )
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
197 198
        vlc_object_t *p_dec_obj;

Gildas Bazin's avatar
 
Gildas Bazin committed
199 200
        ppsz_varnames[i] = "fullscreen";
        pi_objects[i++] = p_object->i_object_id;
201 202
        ppsz_varnames[i] = "zoom";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
203 204
        ppsz_varnames[i] = "deinterlace";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
205 206 207 208
        ppsz_varnames[i] = "aspect-ratio";
        pi_objects[i++] = p_object->i_object_id;
        ppsz_varnames[i] = "crop";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
209
        ppsz_varnames[i] = "video-on-top";
Gildas Bazin's avatar
 
Gildas Bazin committed
210
        pi_objects[i++] = p_object->i_object_id;
211 212
        ppsz_varnames[i] = "directx-wallpaper";
        pi_objects[i++] = p_object->i_object_id;
213 214
        ppsz_varnames[i] = "video-snapshot";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
215 216 217 218 219 220 221 222 223 224 225

        p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
                                                     VLC_OBJECT_DECODER,
                                                     FIND_PARENT );
        if( p_dec_obj != NULL )
        {
            ppsz_varnames[i] = "ffmpeg-pp-q";
            pi_objects[i++] = p_dec_obj->i_object_id;
            vlc_object_release( p_dec_obj );
        }

Gildas Bazin's avatar
 
Gildas Bazin committed
226 227 228
        vlc_object_release( p_object );
    }

229 230 231
    /* Audio menu */
    if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
    i_last_separator  = i;
Gildas Bazin's avatar
 
Gildas Bazin committed
232

233
    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
Gildas Bazin's avatar
 
Gildas Bazin committed
234 235 236
                                                FIND_ANYWHERE );
    if( p_object != NULL )
    {
237
        ppsz_varnames[i] = "audio-device";
Gildas Bazin's avatar
 
Gildas Bazin committed
238
        pi_objects[i++] = p_object->i_object_id;
239
        ppsz_varnames[i] = "audio-channels";
Gildas Bazin's avatar
 
Gildas Bazin committed
240
        pi_objects[i++] = p_object->i_object_id;
241
        ppsz_varnames[i] = "visual";
Gildas Bazin's avatar
 
Gildas Bazin committed
242
        pi_objects[i++] = p_object->i_object_id;
243
        ppsz_varnames[i] = "equalizer";
Gildas Bazin's avatar
 
Gildas Bazin committed
244
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
245 246 247
        vlc_object_release( p_object );
    }

248
 interfacemenu:
Gildas Bazin's avatar
 
Gildas Bazin committed
249
    /* Interface menu */
250 251
    if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
    i_last_separator = i;
Gildas Bazin's avatar
 
Gildas Bazin committed
252 253 254 255 256 257

    /* vlc_object_find is needed because of the dialogs provider case */
    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
                                                FIND_PARENT );
    if( p_object != NULL )
    {
258
#if (wxCHECK_VERSION(2,5,0))
Gildas Bazin's avatar
 
Gildas Bazin committed
259 260
        ppsz_varnames[i] = "intf-switch";
        pi_objects[i++] = p_object->i_object_id;
261
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
262 263
        ppsz_varnames[i] = "intf-add";
        pi_objects[i++] = p_object->i_object_id;
264 265
        ppsz_varnames[i] = "intf-skins";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
266 267 268 269

        vlc_object_release( p_object );
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
270
    /* Build menu */
271
    Menu popupmenu( p_intf, PopupMenu_Events );
272
    popupmenu.Populate( i, ppsz_varnames, pi_objects );
Gildas Bazin's avatar
 
Gildas Bazin committed
273

Gildas Bazin's avatar
 
Gildas Bazin committed
274
    /* Add static entries */
275 276 277 278
    if( p_input != NULL )
    {
        vlc_value_t val;
        popupmenu.InsertSeparator( 0 );
279 280
        if (!minimal)
        {
281 282 283
        popupmenu.Insert( 0, Stop_Event, wxU(_("Stop")) );
        popupmenu.Insert( 0, Previous_Event, wxU(_("Previous")) );
        popupmenu.Insert( 0, Next_Event, wxU(_("Next")) );
284
        }
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306

        var_Get( p_input, "state", &val );
        if( val.i_int == PAUSE_S )
            popupmenu.Insert( 0, Play_Event, wxU(_("Play")) );
        else
            popupmenu.Insert( 0, Pause_Event, wxU(_("Pause")) );

        vlc_object_release( p_input );
    }
    else
    {
        playlist_t * p_playlist =
            (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                           FIND_ANYWHERE );
        if( p_playlist && p_playlist->i_size )
        {
            popupmenu.InsertSeparator( 0 );
            popupmenu.Insert( 0, Play_Event, wxU(_("Play")) );
        }
        if( p_playlist ) vlc_object_release( p_playlist );
    }

307
    popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")),
308
                      MiscMenu( p_intf ), wxT("") );
309 310
    if (!minimal)
    {
311 312
    popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
                      OpenStreamMenu( p_intf ), wxT("") );
313
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
314

Gildas Bazin's avatar
 
Gildas Bazin committed
315 316 317
    p_intf->p_sys->p_popup_menu = &popupmenu;
    p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
    p_intf->p_sys->p_popup_menu = NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
318 319
}

320
wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
Gildas Bazin's avatar
 
Gildas Bazin committed
321
{
Gildas Bazin's avatar
 
Gildas Bazin committed
322 323
#define MAX_AUDIO_ITEMS 10

Gildas Bazin's avatar
 
Gildas Bazin committed
324
    vlc_object_t *p_object;
Gildas Bazin's avatar
 
Gildas Bazin committed
325 326
    char *ppsz_varnames[MAX_AUDIO_ITEMS];
    int pi_objects[MAX_AUDIO_ITEMS];
Gildas Bazin's avatar
 
Gildas Bazin committed
327 328 329
    int i = 0;

    /* Initializations */
Gildas Bazin's avatar
 
Gildas Bazin committed
330
    memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
Gildas Bazin's avatar
 
Gildas Bazin committed
331

Gildas Bazin's avatar
 
Gildas Bazin committed
332 333 334
    p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
                                                FIND_ANYWHERE );
    if( p_object != NULL )
Gildas Bazin's avatar
 
Gildas Bazin committed
335 336
    {
        ppsz_varnames[i] = "audio-es";
Gildas Bazin's avatar
 
Gildas Bazin committed
337 338
        pi_objects[i++] = p_object->i_object_id;
        vlc_object_release( p_object );
Gildas Bazin's avatar
 
Gildas Bazin committed
339 340
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
341 342 343
    p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
                                                FIND_ANYWHERE );
    if( p_object != NULL )
Gildas Bazin's avatar
 
Gildas Bazin committed
344
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
345 346 347 348
        ppsz_varnames[i] = "audio-device";
        pi_objects[i++] = p_object->i_object_id;
        ppsz_varnames[i] = "audio-channels";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
349
        ppsz_varnames[i] = "visual";
Gildas Bazin's avatar
 
Gildas Bazin committed
350
        pi_objects[i++] = p_object->i_object_id;
351 352
        ppsz_varnames[i] = "equalizer";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
353
        vlc_object_release( p_object );
Gildas Bazin's avatar
 
Gildas Bazin committed
354 355
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
356
    /* Build menu */
357 358
    Menu *p_vlc_menu = (Menu *)p_menu;
    if( !p_vlc_menu )
359
        p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
360 361 362 363 364 365
    else
        p_vlc_menu->Clear();

    p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );

    return p_vlc_menu;
Gildas Bazin's avatar
 
Gildas Bazin committed
366 367
}

368
wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
Gildas Bazin's avatar
 
Gildas Bazin committed
369
{
Gildas Bazin's avatar
 
Gildas Bazin committed
370 371
#define MAX_VIDEO_ITEMS 15

Gildas Bazin's avatar
 
Gildas Bazin committed
372
    vlc_object_t *p_object;
Gildas Bazin's avatar
 
Gildas Bazin committed
373 374
    char *ppsz_varnames[MAX_VIDEO_ITEMS];
    int pi_objects[MAX_VIDEO_ITEMS];
Gildas Bazin's avatar
 
Gildas Bazin committed
375 376 377
    int i = 0;

    /* Initializations */
Gildas Bazin's avatar
 
Gildas Bazin committed
378
    memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
Gildas Bazin's avatar
 
Gildas Bazin committed
379

Gildas Bazin's avatar
 
Gildas Bazin committed
380 381 382 383 384 385 386 387 388 389 390
    p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
                                                FIND_ANYWHERE );
    if( p_object != NULL )
    {
        ppsz_varnames[i] = "video-es";
        pi_objects[i++] = p_object->i_object_id;
        ppsz_varnames[i] = "spu-es";
        pi_objects[i++] = p_object->i_object_id;
        vlc_object_release( p_object );
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
391 392 393 394
    p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
                                                FIND_ANYWHERE );
    if( p_object != NULL )
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
395 396
        vlc_object_t *p_dec_obj;

Gildas Bazin's avatar
 
Gildas Bazin committed
397 398
        ppsz_varnames[i] = "fullscreen";
        pi_objects[i++] = p_object->i_object_id;
399 400
        ppsz_varnames[i] = "zoom";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
401 402
        ppsz_varnames[i] = "deinterlace";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
403 404 405 406
        ppsz_varnames[i] = "aspect-ratio";
        pi_objects[i++] = p_object->i_object_id;
        ppsz_varnames[i] = "crop";
        pi_objects[i++] = p_object->i_object_id;
407
        ppsz_varnames[i] = "video-on-top";
Gildas Bazin's avatar
 
Gildas Bazin committed
408
        pi_objects[i++] = p_object->i_object_id;
409 410
        ppsz_varnames[i] = "directx-wallpaper";
        pi_objects[i++] = p_object->i_object_id;
411 412
        ppsz_varnames[i] = "video-snapshot";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
413 414 415 416 417 418 419 420 421 422 423 424

        p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
                                                     VLC_OBJECT_DECODER,
                                                     FIND_PARENT );
        if( p_dec_obj != NULL )
        {
            ppsz_varnames[i] = "ffmpeg-pp-q";
            pi_objects[i++] = p_dec_obj->i_object_id;
            vlc_object_release( p_dec_obj );
        }

        vlc_object_release( p_object );
Gildas Bazin's avatar
 
Gildas Bazin committed
425 426 427
    }

    /* Build menu */
428 429
    Menu *p_vlc_menu = (Menu *)p_menu;
    if( !p_vlc_menu )
430
        p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
431 432 433 434 435 436
    else
        p_vlc_menu->Clear();

    p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );

    return p_vlc_menu;
Gildas Bazin's avatar
 
Gildas Bazin committed
437 438
}

439
wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
Gildas Bazin's avatar
 
Gildas Bazin committed
440
{
441
#define MAX_NAVIG_ITEMS 15
Gildas Bazin's avatar
 
Gildas Bazin committed
442

Gildas Bazin's avatar
 
Gildas Bazin committed
443
    vlc_object_t *p_object;
Gildas Bazin's avatar
 
Gildas Bazin committed
444 445
    char *ppsz_varnames[MAX_NAVIG_ITEMS];
    int pi_objects[MAX_NAVIG_ITEMS];
Gildas Bazin's avatar
 
Gildas Bazin committed
446 447 448
    int i = 0;

    /* Initializations */
Gildas Bazin's avatar
 
Gildas Bazin committed
449
    memset( pi_objects, 0, MAX_NAVIG_ITEMS * sizeof(int) );
Gildas Bazin's avatar
 
Gildas Bazin committed
450 451 452 453 454

    p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
                                                FIND_ANYWHERE );
    if( p_object != NULL )
    {
Gildas Bazin's avatar
Gildas Bazin committed
455 456
        ppsz_varnames[i] = "bookmark";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
457 458 459 460
        ppsz_varnames[i] = "title";
        pi_objects[i++] = p_object->i_object_id;
        ppsz_varnames[i] = "chapter";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
461 462
        ppsz_varnames[i] = "program";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
463 464
        ppsz_varnames[i] = "navigation";
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
465
        ppsz_varnames[i] = "dvd_menus";
Gildas Bazin's avatar
 
Gildas Bazin committed
466
        pi_objects[i++] = p_object->i_object_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
467 468 469 470 471 472 473 474 475 476 477

        ppsz_varnames[i] = "prev-title";
        pi_objects[i++] = p_object->i_object_id;
        ppsz_varnames[i] = "next-title";
        pi_objects[i++] = p_object->i_object_id;
        ppsz_varnames[i] = "prev-chapter";
        pi_objects[i++] = p_object->i_object_id;
        ppsz_varnames[i] = "next-chapter";
        pi_objects[i++] = p_object->i_object_id;

        vlc_object_release( p_object );
Gildas Bazin's avatar
 
Gildas Bazin committed
478 479 480
    }

    /* Build menu */
481 482
    Menu *p_vlc_menu = (Menu *)p_menu;
    if( !p_vlc_menu )
483
        p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
484 485 486 487 488 489
    else
        p_vlc_menu->Clear();

    p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );

    return p_vlc_menu;
Gildas Bazin's avatar
 
Gildas Bazin committed
490 491
}

492 493
wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
                      wxMenu *p_menu )
Gildas Bazin's avatar
 
Gildas Bazin committed
494
{
Gildas Bazin's avatar
 
Gildas Bazin committed
495
#define MAX_SETTINGS_ITEMS 10
Gildas Bazin's avatar
 
Gildas Bazin committed
496

Gildas Bazin's avatar
 
Gildas Bazin committed
497
    vlc_object_t *p_object;
Gildas Bazin's avatar
 
Gildas Bazin committed
498 499
    char *ppsz_varnames[MAX_SETTINGS_ITEMS];
    int pi_objects[MAX_SETTINGS_ITEMS];
Gildas Bazin's avatar
 
Gildas Bazin committed
500 501 502
    int i = 0;

    /* Initializations */
Gildas Bazin's avatar
 
Gildas Bazin committed
503
    memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
Gildas Bazin's avatar
 
Gildas Bazin committed
504 505 506 507 508

    p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
                                                FIND_PARENT );
    if( p_object != NULL )
    {
509
#if (wxCHECK_VERSION(2,5,0))
Gildas Bazin's avatar
 
Gildas Bazin committed
510 511
        ppsz_varnames[i] = "intf-switch";
        pi_objects[i++] = p_object->i_object_id;
512
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
513 514 515 516 517 518
        ppsz_varnames[i] = "intf-add";
        pi_objects[i++] = p_object->i_object_id;
        vlc_object_release( p_object );
    }

    /* Build menu */
519 520
    Menu *p_vlc_menu = (Menu *)p_menu;
    if( !p_vlc_menu )
521
        p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
522 523 524 525 526 527
    else
        p_vlc_menu->Clear();

    p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );

    return p_vlc_menu;
Gildas Bazin's avatar
 
Gildas Bazin committed
528 529
}

Gildas Bazin's avatar
 
Gildas Bazin committed
530 531 532
/*****************************************************************************
 * Constructor.
 *****************************************************************************/
533
Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
534 535 536 537 538 539 540 541 542 543 544 545 546 547
{
    /* Initializations */
    p_intf = _p_intf;
    i_start_id = _i_start_id;
}

Menu::~Menu()
{
}

/*****************************************************************************
 * Public methods.
 *****************************************************************************/
void Menu::Populate( int i_count, char **ppsz_varnames, int *pi_objects )
Gildas Bazin's avatar
 
Gildas Bazin committed
548 549
{
    vlc_object_t *p_object;
550
    vlc_bool_t b_section_empty = VLC_FALSE;
Gildas Bazin's avatar
 
Gildas Bazin committed
551 552
    int i;

Gildas Bazin's avatar
 
Gildas Bazin committed
553
    i_item_id = i_start_id;
Gildas Bazin's avatar
 
Gildas Bazin committed
554 555 556 557 558

    for( i = 0; i < i_count; i++ )
    {
        if( !ppsz_varnames[i] )
        {
559 560 561 562 563 564
            if( b_section_empty )
            {
                Append( MenuDummy_Event + i, wxU(_("Empty")) );
                Enable( MenuDummy_Event + i, FALSE );
            }

Gildas Bazin's avatar
 
Gildas Bazin committed
565
            AppendSeparator();
566
            b_section_empty = VLC_TRUE;
Gildas Bazin's avatar
 
Gildas Bazin committed
567 568 569 570 571
            continue;
        }

        if( !pi_objects[i] )
        {
Gildas Bazin's avatar
 
Gildas Bazin committed
572
            Append( MenuDummy_Event, wxU(ppsz_varnames[i]) );
573
            b_section_empty = VLC_FALSE;
Gildas Bazin's avatar
 
Gildas Bazin committed
574 575 576 577 578 579
            continue;
        }

        p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
        if( p_object == NULL ) continue;

580
        b_section_empty = VLC_FALSE;
Gildas Bazin's avatar
 
Gildas Bazin committed
581 582 583 584
        CreateMenuItem( this, ppsz_varnames[i], p_object );
        vlc_object_release( p_object );
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
585
    /* Special case for empty menus */
586
    if( GetMenuItemCount() == 0 || b_section_empty )
Gildas Bazin's avatar
 
Gildas Bazin committed
587
    {
588 589
        Append( MenuDummy_Event + i, wxU(_("Empty")) );
        Enable( MenuDummy_Event + i, FALSE );
Gildas Bazin's avatar
 
Gildas Bazin committed
590
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
591 592
}

593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
/* Work-around helper for buggy wxGTK */
static void RecursiveDestroy( wxMenu *menu )
{
    wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
    for( ; node; )
    {
        wxMenuItem *item = node->GetData();
        node = node->GetNext();

        /* Delete the submenus */
        wxMenu *submenu = item->GetSubMenu();
        if( submenu )
        {
            RecursiveDestroy( submenu );
        }
608
        menu->Delete( item );
609 610 611 612
    }
}

void Menu::Clear( )
Gildas Bazin's avatar
 
Gildas Bazin committed
613
{
614
    RecursiveDestroy( this );
Gildas Bazin's avatar
 
Gildas Bazin committed
615 616 617 618 619
}

/*****************************************************************************
 * Private methods.
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
                         bool b_root = TRUE )
{
    vlc_value_t val, val_list;
    int i_type, i_result, i;

    /* Check the type of the object variable */
    i_type = var_Type( p_object, psz_var );

    /* Check if we want to display the variable */
    if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;

    var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
    if( val.i_int == 0 ) return TRUE;

    if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
    {
        if( val.i_int == 1 && b_root ) return TRUE;
        else return FALSE;
    }

    /* Check children variables in case of VLC_VAR_VARIABLE */
    if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
    {
        return TRUE;
    }

    for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
    {
        if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
                          p_object, FALSE ) )
        {
            i_result = FALSE;
            break;
        }
    }

    /* clean up everything */
    var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );

    return i_result;
}

Gildas Bazin's avatar
 
Gildas Bazin committed
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
                           vlc_object_t *p_object )
{
    wxMenuItemExt *menuitem;
    vlc_value_t val, text;
    int i_type;

    /* Check the type of the object variable */
    i_type = var_Type( p_object, psz_var );

    switch( i_type & VLC_VAR_TYPE )
    {
    case VLC_VAR_VOID:
    case VLC_VAR_BOOL:
    case VLC_VAR_VARIABLE:
    case VLC_VAR_STRING:
    case VLC_VAR_INTEGER:
680
    case VLC_VAR_FLOAT:
Gildas Bazin's avatar
 
Gildas Bazin committed
681 682 683 684 685 686 687
        break;
    default:
        /* Variable doesn't exist or isn't handled */
        return;
    }

    /* Make sure we want to display the variable */
Gildas Bazin's avatar
 
Gildas Bazin committed
688
    if( IsMenuEmpty( psz_var, p_object ) ) return;
Gildas Bazin's avatar
 
Gildas Bazin committed
689 690 691 692 693 694 695

    /* Get the descriptive name of the variable */
    var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );

    if( i_type & VLC_VAR_HASCHOICE )
    {
        menu->Append( MenuDummy_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
696
                      wxU(text.psz_string ? text.psz_string : psz_var),
Gildas Bazin's avatar
 
Gildas Bazin committed
697
                      CreateChoicesMenu( psz_var, p_object, TRUE ),
Gildas Bazin's avatar
 
Gildas Bazin committed
698
                      wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
Gildas Bazin's avatar
 
Gildas Bazin committed
699 700 701 702 703 704 705 706 707

        if( text.psz_string ) free( text.psz_string );
        return;
    }


    switch( i_type & VLC_VAR_TYPE )
    {
    case VLC_VAR_VOID:
Gildas Bazin's avatar
 
Gildas Bazin committed
708
        var_Get( p_object, psz_var, &val );
Gildas Bazin's avatar
 
Gildas Bazin committed
709
        menuitem = new wxMenuItemExt( menu, ++i_item_id,
Gildas Bazin's avatar
 
Gildas Bazin committed
710 711 712
                                      wxU(text.psz_string ?
                                        text.psz_string : psz_var),
                                      wxT(""), wxITEM_NORMAL, strdup(psz_var),
Gildas Bazin's avatar
 
Gildas Bazin committed
713 714 715 716 717
                                      p_object->i_object_id, val, i_type );
        menu->Append( menuitem );
        break;

    case VLC_VAR_BOOL:
Gildas Bazin's avatar
 
Gildas Bazin committed
718
        var_Get( p_object, psz_var, &val );
Gildas Bazin's avatar
 
Gildas Bazin committed
719
        val.b_bool = !val.b_bool;
Gildas Bazin's avatar
 
Gildas Bazin committed
720
        menuitem = new wxMenuItemExt( menu, ++i_item_id,
Gildas Bazin's avatar
 
Gildas Bazin committed
721 722 723
                                      wxU(text.psz_string ?
                                        text.psz_string : psz_var),
                                      wxT(""), wxITEM_CHECK, strdup(psz_var),
Gildas Bazin's avatar
 
Gildas Bazin committed
724 725
                                      p_object->i_object_id, val, i_type );
        menu->Append( menuitem );
Gildas Bazin's avatar
 
Gildas Bazin committed
726
        Check( i_item_id, val.b_bool ? FALSE : TRUE );
Gildas Bazin's avatar
 
Gildas Bazin committed
727 728 729 730 731 732
        break;
    }

    if( text.psz_string ) free( text.psz_string );
}

Gildas Bazin's avatar
 
Gildas Bazin committed
733 734
wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
                                 bool b_root )
Gildas Bazin's avatar
 
Gildas Bazin committed
735 736 737 738 739 740 741 742
{
    vlc_value_t val, val_list, text_list;
    int i_type, i;

    /* Check the type of the object variable */
    i_type = var_Type( p_object, psz_var );

    /* Make sure we want to display the variable */
Gildas Bazin's avatar
 
Gildas Bazin committed
743
    if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
Gildas Bazin's avatar
 
Gildas Bazin committed
744 745 746 747 748 749 750 751

    switch( i_type & VLC_VAR_TYPE )
    {
    case VLC_VAR_VOID:
    case VLC_VAR_BOOL:
    case VLC_VAR_VARIABLE:
    case VLC_VAR_STRING:
    case VLC_VAR_INTEGER:
752
    case VLC_VAR_FLOAT:
Gildas Bazin's avatar
 
Gildas Bazin committed
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
        break;
    default:
        /* Variable doesn't exist or isn't handled */
        return NULL;
    }

    if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
                    &val_list, &text_list ) < 0 )
    {
        return NULL;
    }

    wxMenu *menu = new wxMenu;
    for( i = 0; i < val_list.p_list->i_count; i++ )
    {
        vlc_value_t another_val;
        wxMenuItemExt *menuitem;

        switch( i_type & VLC_VAR_TYPE )
        {
        case VLC_VAR_VARIABLE:
          menu->Append( MenuDummy_Event,
Gildas Bazin's avatar
 
Gildas Bazin committed
775
                        wxU(text_list.p_list->p_values[i].psz_string ?
Gildas Bazin's avatar
 
Gildas Bazin committed
776
                        text_list.p_list->p_values[i].psz_string :
Gildas Bazin's avatar
 
Gildas Bazin committed
777
                        val_list.p_list->p_values[i].psz_string),
Gildas Bazin's avatar
 
Gildas Bazin committed
778 779
                        CreateChoicesMenu(
                            val_list.p_list->p_values[i].psz_string,
Gildas Bazin's avatar
 
Gildas Bazin committed
780
                            p_object, FALSE ), wxT("") );
Gildas Bazin's avatar
 
Gildas Bazin committed
781 782 783
          break;

        case VLC_VAR_STRING:
Gildas Bazin's avatar
 
Gildas Bazin committed
784 785
          var_Get( p_object, psz_var, &val );

Gildas Bazin's avatar
 
Gildas Bazin committed
786 787 788
          another_val.psz_string =
              strdup(val_list.p_list->p_values[i].psz_string);
          menuitem =
Gildas Bazin's avatar
 
Gildas Bazin committed
789
              new wxMenuItemExt( menu, ++i_item_id,
Gildas Bazin's avatar
 
Gildas Bazin committed
790
                                 wxU(text_list.p_list->p_values[i].psz_string ?
Gildas Bazin's avatar
 
Gildas Bazin committed
791
                                 text_list.p_list->p_values[i].psz_string :
Gildas Bazin's avatar
 
Gildas Bazin committed
792 793 794 795
                                 another_val.psz_string), wxT(""),
                                 i_type & VLC_VAR_ISCOMMAND ?
                                   wxITEM_NORMAL : wxITEM_RADIO,
                                 strdup(psz_var),
Gildas Bazin's avatar
 
Gildas Bazin committed
796 797 798 799
                                 p_object->i_object_id, another_val, i_type );

          menu->Append( menuitem );

Gildas Bazin's avatar
 
Gildas Bazin committed
800
          if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
Gildas Bazin's avatar
 
Gildas Bazin committed
801
              !strcmp( val.psz_string,
Gildas Bazin's avatar
 
Gildas Bazin committed
802 803
                       val_list.p_list->p_values[i].psz_string ) )
              menu->Check( i_item_id, TRUE );
Gildas Bazin's avatar
 
Gildas Bazin committed
804 805

          if( val.psz_string ) free( val.psz_string );
Gildas Bazin's avatar
 
Gildas Bazin committed
806 807 808
          break;

        case VLC_VAR_INTEGER:
Gildas Bazin's avatar
 
Gildas Bazin committed
809 810
          var_Get( p_object, psz_var, &val );

Gildas Bazin's avatar
 
Gildas Bazin committed
811
          menuitem =
Gildas Bazin's avatar
 
Gildas Bazin committed
812
              new wxMenuItemExt( menu, ++i_item_id,
Gildas Bazin's avatar
 
Gildas Bazin committed
813
                                 text_list.p_list->p_values[i].psz_string ?
Gildas Bazin's avatar
 
Gildas Bazin committed
814 815
                                 (wxString)wxU(
                                   text_list.p_list->p_values[i].psz_string) :
Gildas Bazin's avatar
 
Gildas Bazin committed
816
                                 wxString::Format(wxT("%d"),
Gildas Bazin's avatar
 
Gildas Bazin committed
817 818 819 820
                                 val_list.p_list->p_values[i].i_int), wxT(""),
                                 i_type & VLC_VAR_ISCOMMAND ?
                                   wxITEM_NORMAL : wxITEM_RADIO,
                                 strdup(psz_var),
Gildas Bazin's avatar
 
Gildas Bazin committed
821 822 823 824 825
                                 p_object->i_object_id,
                                 val_list.p_list->p_values[i], i_type );

          menu->Append( menuitem );

Gildas Bazin's avatar
 
Gildas Bazin committed
826 827
          if( !(i_type & VLC_VAR_ISCOMMAND) &&
              val_list.p_list->p_values[i].i_int == val.i_int )
Gildas Bazin's avatar
 
Gildas Bazin committed
828 829 830
              menu->Check( i_item_id, TRUE );
          break;

831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
        case VLC_VAR_FLOAT:
          var_Get( p_object, psz_var, &val );

          menuitem =
              new wxMenuItemExt( menu, ++i_item_id,
                                 text_list.p_list->p_values[i].psz_string ?
                                 (wxString)wxU(
                                   text_list.p_list->p_values[i].psz_string) :
                                 wxString::Format(wxT("%.2f"),
                                 val_list.p_list->p_values[i].f_float),wxT(""),
                                 i_type & VLC_VAR_ISCOMMAND ?
                                   wxITEM_NORMAL : wxITEM_RADIO,
                                 strdup(psz_var),
                                 p_object->i_object_id,
                                 val_list.p_list->p_values[i], i_type );

          menu->Append( menuitem );

          if( !(i_type & VLC_VAR_ISCOMMAND) &&
              val_list.p_list->p_values[i].f_float == val.f_float )
              menu->Check( i_item_id, TRUE );
          break;

Gildas Bazin's avatar
 
Gildas Bazin committed
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
        default:
          break;
        }
    }

    /* clean up everything */
    var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );

    return menu;
}

/*****************************************************************************
 * A small helper class which intercepts all popup menu events
 *****************************************************************************/
MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
                                Interface *_p_main_interface )
{
    /* Initializations */
    p_intf = _p_intf;
    p_main_interface = _p_main_interface;
}

MenuEvtHandler::~MenuEvtHandler()
{
}

Gildas Bazin's avatar
 
Gildas Bazin committed
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
{
    if( p_intf->p_sys->pf_show_dialog )
    {
        int i_id;

        switch( event.GetId() )
        {
        case OpenFileSimple_Event:
            i_id = INTF_DIALOG_FILE_SIMPLE;
            break;
        case OpenFile_Event:
            i_id = INTF_DIALOG_FILE;
            break;
        case OpenDisc_Event:
            i_id = INTF_DIALOG_DISC;
            break;
        case OpenNet_Event:
            i_id = INTF_DIALOG_NET;
            break;
900 901 902
        case OpenCapture_Event:
            i_id = INTF_DIALOG_CAPTURE;
            break;
903 904 905 906 907 908
        case MediaInfo_Event:
            i_id = INTF_DIALOG_FILEINFO;
            break;
        case Messages_Event:
            i_id = INTF_DIALOG_MESSAGES;
            break;
909 910 911
        case Preferences_Event:
            i_id = INTF_DIALOG_PREFS;
            break;
Gildas Bazin's avatar
 
Gildas Bazin committed
912 913 914 915 916 917
        default:
            i_id = INTF_DIALOG_FILE;
            break;

        }

Gildas Bazin's avatar
 
Gildas Bazin committed
918
        p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
Gildas Bazin's avatar
 
Gildas Bazin committed
919 920 921
    }
}

Gildas Bazin's avatar
 
Gildas Bazin committed
922 923
void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
{
Gildas Bazin's avatar
 
Gildas Bazin committed
924
    wxMenuItem *p_menuitem = NULL;
925 926
    int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
    int i_hotkeys = p_intf->p_sys->i_hotkeys;
Gildas Bazin's avatar
 
Gildas Bazin committed
927

928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968
    if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
    {
        input_thread_t *p_input;
        playlist_t * p_playlist =
            (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                           FIND_ANYWHERE );
        if( !p_playlist ) return;

        switch( event.GetId() )
        {
        case Play_Event:
        case Pause_Event:
            p_input =
                (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                                   FIND_ANYWHERE );
            if( !p_input ) playlist_Play( p_playlist );
            else
            {
                vlc_value_t val;
                var_Get( p_input, "state", &val );
                if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
                else val.i_int = PLAYING_S;
                var_Set( p_input, "state", val );
                vlc_object_release( p_input );
            }
            break;
        case Stop_Event:
            playlist_Stop( p_playlist );
            break;
        case Previous_Event:
            playlist_Prev( p_playlist );
            break;
        case Next_Event:
            playlist_Next( p_playlist );
            break;
        }

        vlc_object_release( p_playlist );
        return;
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
969 970 971 972 973 974 975
    /* Check if this is an auto generated menu item */
    if( event.GetId() < FirstAutoGenerated_Event )
    {
        event.Skip();
        return;
    }

976 977 978 979 980 981 982 983 984 985 986 987 988 989
    /* Check if this is an hotkey event */
    if( event.GetId() >= i_hotkey_event &&
        event.GetId() < i_hotkey_event + i_hotkeys )
    {
        vlc_value_t val;

        val.i_int =
            p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;

        /* Get the key combination and send it to the hotkey handler */
        var_Set( p_intf->p_vlc, "key-pressed", val );
        return;
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
990 991
    if( !p_main_interface ||
        (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
Gildas Bazin's avatar
 
Gildas Bazin committed
992 993
        == NULL )
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
994
        if( p_intf->p_sys->p_popup_menu )
Gildas Bazin's avatar
 
Gildas Bazin committed
995
        {
996
            p_menuitem =
Gildas Bazin's avatar
 
Gildas Bazin committed
997
                p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
Gildas Bazin's avatar
 
Gildas Bazin committed
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
        }
    }

    if( p_menuitem )
    {
        wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
        vlc_object_t *p_object;

        p_object = (vlc_object_t *)vlc_object_get( p_intf,
                                       p_menuitemext->i_object_id );
        if( p_object == NULL ) return;

1010
        wxMutexGuiLeave(); // We don't want deadlocks
Gildas Bazin's avatar
 
Gildas Bazin committed
1011
        var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1012
        //wxMutexGuiEnter();
Gildas Bazin's avatar
 
Gildas Bazin committed
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041

        vlc_object_release( p_object );
    }
    else
        event.Skip();
}

/*****************************************************************************
 * A small helper class which encapsulate wxMenuitem with some other useful
 * things.
 *****************************************************************************/
wxMenuItemExt::wxMenuItemExt( 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 ):
    wxMenuItem( parentMenu, id, text, helpString, kind )
{
    /* Initializations */
    psz_var = _psz_var;
    i_val_type = _i_val_type;
    i_object_id = _i_object_id;
    val = _val;
};

wxMenuItemExt::~wxMenuItemExt()
{
    if( psz_var ) free( psz_var );
    if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
        && val.psz_string ) free( val.psz_string );
};