2002-11-14 23:47:11 +00:00
|
|
|
|
2005-10-26 00:07:43 +00:00
|
|
|
#include "config.h"
|
2006-03-30 06:40:58 +00:00
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "help_mp.h"
|
2002-11-14 23:47:11 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
2002-12-28 18:51:10 +00:00
|
|
|
#include <string.h>
|
2002-11-14 23:47:11 +00:00
|
|
|
|
2006-08-18 13:58:03 +00:00
|
|
|
#include "libmpcodecs/img_format.h"
|
|
|
|
#include "libmpcodecs/mp_image.h"
|
2002-11-14 23:47:11 +00:00
|
|
|
|
2005-10-26 00:07:43 +00:00
|
|
|
#include "m_option.h"
|
|
|
|
#include "m_struct.h"
|
|
|
|
#include "asxparser.h"
|
2002-11-14 23:47:11 +00:00
|
|
|
#include "menu.h"
|
|
|
|
#include "menu_list.h"
|
|
|
|
|
2005-10-26 00:07:43 +00:00
|
|
|
#include "libvo/font_load.h"
|
2002-11-14 23:47:11 +00:00
|
|
|
|
2005-10-26 00:07:43 +00:00
|
|
|
#include "input/input.h"
|
|
|
|
#include "version.h"
|
2002-11-14 23:47:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct list_entry_s {
|
|
|
|
struct list_entry p;
|
|
|
|
|
|
|
|
char* ok;
|
|
|
|
char* cancel;
|
2006-03-25 17:32:10 +00:00
|
|
|
char* left;
|
|
|
|
char* right;
|
2002-11-14 23:47:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct menu_priv_s {
|
|
|
|
menu_list_priv_t p;
|
2006-06-25 21:24:46 +00:00
|
|
|
int auto_close;
|
2002-11-14 23:47:11 +00:00
|
|
|
};
|
|
|
|
|
2006-06-25 21:24:46 +00:00
|
|
|
#define ST_OFF(m) M_ST_OFF(struct menu_priv_s, m)
|
|
|
|
|
2002-11-14 23:47:11 +00:00
|
|
|
static struct menu_priv_s cfg_dflt = {
|
2006-06-25 21:24:46 +00:00
|
|
|
MENU_LIST_PRIV_DFLT,
|
|
|
|
0,
|
2002-11-14 23:47:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static m_option_t cfg_fields[] = {
|
|
|
|
MENU_LIST_PRIV_FIELDS,
|
|
|
|
{ "title",M_ST_OFF(struct menu_priv_s,p.title), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
2006-06-25 21:24:46 +00:00
|
|
|
{ "auto-close", ST_OFF(auto_close), CONF_TYPE_FLAG, 0, 0, 1, NULL },
|
2002-11-14 23:47:11 +00:00
|
|
|
{ NULL, NULL, NULL, 0,0,0,NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
#define mpriv (menu->priv)
|
|
|
|
|
|
|
|
static void read_cmd(menu_t* menu,int cmd) {
|
|
|
|
switch(cmd) {
|
2006-03-25 17:32:10 +00:00
|
|
|
case MENU_CMD_RIGHT:
|
|
|
|
if(mpriv->p.current->right) {
|
|
|
|
mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->right);
|
|
|
|
if(c) mp_input_queue_cmd(c);
|
|
|
|
break;
|
|
|
|
} // fallback on ok if right is not defined
|
2002-11-14 23:47:11 +00:00
|
|
|
case MENU_CMD_OK: {
|
|
|
|
if(mpriv->p.current->ok) {
|
|
|
|
mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->ok);
|
|
|
|
if(c)
|
2006-06-25 21:24:46 +00:00
|
|
|
{
|
|
|
|
if (mpriv->auto_close)
|
|
|
|
mp_input_queue_cmd (mp_input_parse_cmd ("menu hide"));
|
2002-11-14 23:47:11 +00:00
|
|
|
mp_input_queue_cmd(c);
|
2006-06-25 21:24:46 +00:00
|
|
|
}
|
2002-11-14 23:47:11 +00:00
|
|
|
}
|
|
|
|
} break;
|
2006-03-25 17:32:10 +00:00
|
|
|
case MENU_CMD_LEFT:
|
|
|
|
if(mpriv->p.current->left) {
|
|
|
|
mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->left);
|
|
|
|
if(c) mp_input_queue_cmd(c);
|
|
|
|
break;
|
|
|
|
} // fallback on cancel if left is not defined
|
2002-11-14 23:47:11 +00:00
|
|
|
case MENU_CMD_CANCEL:
|
|
|
|
if(mpriv->p.current->cancel) {
|
|
|
|
mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->cancel);
|
|
|
|
if(c)
|
|
|
|
mp_input_queue_cmd(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
menu_list_read_cmd(menu,cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_entry(list_entry_t* entry) {
|
|
|
|
if(entry->ok)
|
|
|
|
free(entry->ok);
|
|
|
|
if(entry->cancel)
|
|
|
|
free(entry->cancel);
|
|
|
|
free(entry->p.txt);
|
|
|
|
free(entry);
|
|
|
|
}
|
|
|
|
|
2006-06-25 20:59:12 +00:00
|
|
|
static void close_menu(menu_t* menu) {
|
2002-11-14 23:47:11 +00:00
|
|
|
menu_list_uninit(menu,free_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_args(menu_t* menu,char* args) {
|
2006-03-25 17:32:10 +00:00
|
|
|
char *element,*body, **attribs, *name;
|
2002-11-14 23:47:11 +00:00
|
|
|
list_entry_t* m = NULL;
|
|
|
|
int r;
|
|
|
|
ASX_Parser_t* parser = asx_parser_new();
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
r = asx_get_element(parser,&args,&element,&body,&attribs);
|
|
|
|
if(r < 0) {
|
2006-03-30 06:40:58 +00:00
|
|
|
mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_SyntaxErrorAtLine,parser->line);
|
2002-11-14 23:47:11 +00:00
|
|
|
asx_parser_free(parser);
|
|
|
|
return -1;
|
|
|
|
} else if(r == 0) {
|
|
|
|
asx_parser_free(parser);
|
|
|
|
if(!m)
|
2006-03-30 06:40:58 +00:00
|
|
|
mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_NoEntryFoundInTheMenuDefinition);
|
2002-11-14 23:47:11 +00:00
|
|
|
return m ? 1 : 0;
|
|
|
|
}
|
|
|
|
// Has it a name ?
|
|
|
|
name = asx_get_attrib("name",attribs);
|
|
|
|
if(!name) {
|
2006-03-30 06:40:58 +00:00
|
|
|
mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ListMenuEntryDefinitionsNeedAName,parser->line);
|
2002-11-14 23:47:11 +00:00
|
|
|
free(element);
|
|
|
|
if(body) free(body);
|
|
|
|
asx_free_attribs(attribs);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
m = calloc(1,sizeof(struct list_entry_s));
|
|
|
|
m->p.txt = name;
|
2006-03-25 17:32:10 +00:00
|
|
|
m->ok = asx_get_attrib("ok",attribs);
|
|
|
|
m->cancel = asx_get_attrib("cancel",attribs);
|
|
|
|
m->left = asx_get_attrib("left",attribs);
|
|
|
|
m->right = asx_get_attrib("right",attribs);
|
2002-11-14 23:47:11 +00:00
|
|
|
menu_list_add_entry(menu,m);
|
|
|
|
|
|
|
|
free(element);
|
|
|
|
if(body) free(body);
|
|
|
|
asx_free_attribs(attribs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-25 10:26:39 +00:00
|
|
|
static int open_cmdlist(menu_t* menu, char* args) {
|
2002-11-14 23:47:11 +00:00
|
|
|
menu->draw = menu_list_draw;
|
|
|
|
menu->read_cmd = read_cmd;
|
2006-06-25 20:59:12 +00:00
|
|
|
menu->close = close_menu;
|
2002-11-14 23:47:11 +00:00
|
|
|
|
|
|
|
if(!args) {
|
2006-03-31 05:49:05 +00:00
|
|
|
mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ListMenuNeedsAnArgument);
|
2002-11-14 23:47:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
menu_list_init(menu);
|
|
|
|
if(!parse_args(menu,args))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const menu_info_t menu_info_cmdlist = {
|
|
|
|
"Command list menu",
|
|
|
|
"cmdlist",
|
|
|
|
"Albeu",
|
|
|
|
"",
|
|
|
|
{
|
|
|
|
"cmdlist_cfg",
|
|
|
|
sizeof(struct menu_priv_s),
|
|
|
|
&cfg_dflt,
|
|
|
|
cfg_fields
|
|
|
|
},
|
2007-05-25 10:26:39 +00:00
|
|
|
open_cmdlist
|
2002-11-14 23:47:11 +00:00
|
|
|
};
|