📄 menus.cpp
字号:
CreateChoicesMenu( psz_var, p_object, TRUE ), wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ ); if( text.psz_string ) free( text.psz_string ); return; } switch( i_type & VLC_VAR_TYPE ) { case VLC_VAR_VOID: var_Get( p_object, psz_var, &val ); menuitem = new wxMenuItemExt( menu, ++i_item_id, wxU(text.psz_string ? text.psz_string : psz_var), wxT(""), wxITEM_NORMAL, strdup(psz_var), p_object->i_object_id, val, i_type ); menu->Append( menuitem ); break; case VLC_VAR_BOOL: var_Get( p_object, psz_var, &val ); val.b_bool = !val.b_bool; menuitem = new wxMenuItemExt( menu, ++i_item_id, wxU(text.psz_string ? text.psz_string : psz_var), wxT(""), wxITEM_CHECK, strdup(psz_var), p_object->i_object_id, val, i_type ); menu->Append( menuitem ); Check( i_item_id, val.b_bool ? FALSE : TRUE ); break; } if( text.psz_string ) free( text.psz_string );}wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object, bool b_root ){ 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 */ if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL; 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: case VLC_VAR_FLOAT: 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, wxU(text_list.p_list->p_values[i].psz_string ? text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string), CreateChoicesMenu( val_list.p_list->p_values[i].psz_string, p_object, FALSE ), wxT("") ); break; case VLC_VAR_STRING: var_Get( p_object, psz_var, &val ); another_val.psz_string = strdup(val_list.p_list->p_values[i].psz_string); menuitem = new wxMenuItemExt( menu, ++i_item_id, wxU(text_list.p_list->p_values[i].psz_string ? text_list.p_list->p_values[i].psz_string : another_val.psz_string), wxT(""), i_type & VLC_VAR_ISCOMMAND ? wxITEM_NORMAL : wxITEM_RADIO, strdup(psz_var), p_object->i_object_id, another_val, i_type ); menu->Append( menuitem ); if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string && !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) ) menu->Check( i_item_id, TRUE ); if( val.psz_string ) free( val.psz_string ); break; case VLC_VAR_INTEGER: 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("%d"), val_list.p_list->p_values[i].i_int), 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].i_int == val.i_int ) menu->Check( i_item_id, TRUE ); break; 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; 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(){}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; case OpenCapture_Event: i_id = INTF_DIALOG_CAPTURE; break; case MediaInfo_Event: i_id = INTF_DIALOG_FILEINFO; break; case Messages_Event: i_id = INTF_DIALOG_MESSAGES; break; case Preferences_Event: i_id = INTF_DIALOG_PREFS; break; default: i_id = INTF_DIALOG_FILE; break; } p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 ); }}void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event ){ wxMenuItem *p_menuitem = NULL; int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event; int i_hotkeys = p_intf->p_sys->i_hotkeys; 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; } /* Check if this is an auto generated menu item */ if( event.GetId() < FirstAutoGenerated_Event ) { event.Skip(); return; } /* 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; } if( !p_main_interface || (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId())) == NULL ) { if( p_intf->p_sys->p_popup_menu ) { p_menuitem = p_intf->p_sys->p_popup_menu->FindItem( event.GetId() ); } } 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; wxMutexGuiLeave(); // We don't want deadlocks var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val ); //wxMutexGuiEnter(); 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 );};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -