1 /*****************************************************************************
2 * popup.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: popup.cpp,v 1.5 2003/04/01 00:18:29 gbazin Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
34 #ifdef WIN32 /* mingw32 hack */
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
42 #include <wx/wxprec.h>
44 #include <wx/listctrl.h>
48 #include "wxwindows.h"
50 /*****************************************************************************
52 *****************************************************************************/
54 /* IDs for the controls and the menu commands */
58 Close_Event = wxID_HIGHEST + 1000,
63 BEGIN_EVENT_TABLE(PopupMenu, wxMenu)
65 EVT_MENU(Close_Event, PopupMenu::OnClose)
66 EVT_MENU(MenuDummy_Event, PopupMenu::OnEntrySelected)
70 BEGIN_EVENT_TABLE(PopupEvtHandler, wxEvtHandler)
71 EVT_MENU(-1, PopupEvtHandler::OnMenuEvent)
74 /*****************************************************************************
76 *****************************************************************************/
77 PopupMenu::PopupMenu( intf_thread_t *_p_intf, Interface *_p_main_interface ):
80 vlc_object_t *p_object;
84 p_main_interface = _p_main_interface;
85 i_item_id = MenuLast_Event;
88 Append( MenuDummy_Event, _("Audio menu") );
90 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
92 if( p_object == NULL ) return;
94 CreateMenuEntry( "audio-device", p_object );
95 CreateMenuEntry( "audio-channels", p_object );
97 vlc_object_release( p_object );
101 Append( MenuDummy_Event, _("Video menu") );
103 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
105 if( p_object == NULL ) return;
107 CreateMenuEntry( "fullscreen", p_object );
109 vlc_object_release( p_object );
113 Append( MenuDummy_Event, _("Input menu") );
115 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
117 if( p_object == NULL ) return;
119 CreateMenuEntry( "title", p_object );
120 CreateMenuEntry( "chapter", p_object );
121 CreateMenuEntry( "navigation", p_object );
123 vlc_object_release( p_object );
127 Append( Close_Event, _("&Close") );
129 /* Intercept all menu events in our custom event handler */
130 p_main_interface->p_popup_menu = this;
131 p_main_interface->PushEventHandler(
132 new PopupEvtHandler( p_intf, p_main_interface ) );
134 wxPoint mousepos = wxGetMousePosition();
135 p_main_interface->PopupMenu( this,
136 p_main_interface->ScreenToClient(mousepos).x,
137 p_main_interface->ScreenToClient(mousepos).y
141 PopupMenu::~PopupMenu()
145 /*****************************************************************************
147 *****************************************************************************/
148 void PopupMenu::OnClose( wxCommandEvent& WXUNUSED(event) )
150 p_intf->b_die = VLC_TRUE;
153 void PopupMenu::OnEntrySelected( wxCommandEvent& WXUNUSED(event) )
157 void PopupMenu::CreateMenuEntry( char *psz_var, vlc_object_t *p_object )
159 vlc_value_t val, val1;
162 /* Check the type of the object variable */
163 i_type = var_Type( p_object, psz_var );
165 if( i_type & VLC_VAR_HASCHOICE )
167 Append( MenuDummy_Event, psz_var,
168 CreateSubMenu( psz_var, p_object ),
169 "YEAAAARRRGGGHHH HEEELLPPPPPP" );
173 if( var_Get( p_object, psz_var, &val ) < 0 )
178 wxMenuItemExt *menuitem;
183 menuitem = new wxMenuItemExt( this, i_item_id++, psz_var,
184 "", wxITEM_NORMAL, strdup(psz_var),
185 p_object->i_object_id, val );
190 val1.b_bool = !val.b_bool;
191 menuitem = new wxMenuItemExt( this, i_item_id++, psz_var,
192 "", wxITEM_CHECK, strdup(psz_var),
193 p_object->i_object_id, val1 );
195 Check( i_item_id - 1, val.b_bool ? TRUE : FALSE );
207 wxMenu *PopupMenu::CreateSubMenu( char *psz_var, vlc_object_t *p_object )
209 wxMenu *menu = new wxMenu;
211 vlc_value_t val_list;
214 /* Check the type of the object variable */
215 i_type = var_Type( p_object, psz_var );
217 if( var_Get( p_object, psz_var, &val ) < 0 )
222 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list ) < 0 )
227 for( i = 0; i < val_list.p_list->i_count; i++ )
229 vlc_value_t another_val;
230 wxMenuItemExt *menuitem;
232 switch( i_type & VLC_VAR_TYPE )
234 case VLC_VAR_VARIABLE:
235 menu->Append( MenuDummy_Event,
236 val_list.p_list->p_values[i].psz_string,
237 CreateSubMenu( val_list.p_list->p_values[i].psz_string,
239 "YEAAAARRRGGGHHH HEEELLPPPPPP" );
243 another_val.psz_string =
244 strdup(val_list.p_list->p_values[i].psz_string);
246 new wxMenuItemExt( this, i_item_id++, another_val.psz_string,
247 "", wxITEM_RADIO, strdup(psz_var),
248 p_object->i_object_id,
251 menu->Append( menuitem );
253 if( !strcmp( val.psz_string,
254 val_list.p_list->p_values[i].psz_string ) )
255 menu->Check( i_item_id - 1, TRUE );
258 case VLC_VAR_INTEGER:
260 new wxMenuItemExt( this, i_item_id++,
261 wxString::Format("%d",
262 val_list.p_list->p_values[i].i_int),
263 "", wxITEM_RADIO, strdup(psz_var),
264 p_object->i_object_id,
265 val_list.p_list->p_values[i] );
267 menu->Append( menuitem );
269 if( !((i_type & VLC_VAR_FLAGS) & VLC_VAR_ISCOMMAND) &&
270 val_list.p_list->p_values[i].i_int == val.i_int )
271 menu->Check( i_item_id - 1, TRUE );
279 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list );
284 /*****************************************************************************
285 * A small helper class which intercepts all popup menu events
286 *****************************************************************************/
287 PopupEvtHandler::PopupEvtHandler( intf_thread_t *_p_intf,
288 Interface *_p_main_interface )
290 /* Initializations */
292 p_main_interface = _p_main_interface;
295 PopupEvtHandler::~PopupEvtHandler()
299 void PopupEvtHandler::OnMenuEvent( wxCommandEvent& event )
301 wxMenuItemExt *p_menuitem = (wxMenuItemExt *)
302 p_main_interface->p_popup_menu->FindItem( event.GetId() );
306 vlc_object_t *p_object;
308 p_object = (vlc_object_t *)vlc_object_get( p_intf,
309 p_menuitem->i_object_id );
310 if( p_object == NULL ) return;
312 var_Set( p_object, p_menuitem->psz_var, p_menuitem->val );
314 vlc_object_release( p_object );