11 #include "libmpcodecs/img_format.h"
12 #include "libmpcodecs/mp_image.h"
16 #include "asxparser.h"
18 #include "menu_list.h"
20 #include "libvo/font_load.h"
22 #include "input/input.h"
41 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s, m)
43 static struct menu_priv_s cfg_dflt
= {
48 static m_option_t cfg_fields
[] = {
49 MENU_LIST_PRIV_FIELDS
,
50 { "title",M_ST_OFF(struct menu_priv_s
,p
.title
), CONF_TYPE_STRING
, 0, 0, 0, NULL
},
51 { "auto-close", ST_OFF(auto_close
), CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
52 { NULL
, NULL
, NULL
, 0,0,0,NULL
}
55 #define mpriv (menu->priv)
57 static void read_cmd(menu_t
* menu
,int cmd
) {
60 if(mpriv
->p
.current
->right
) {
61 mp_cmd_t
* c
= mp_input_parse_cmd(mpriv
->p
.current
->right
);
62 if(c
) mp_input_queue_cmd(c
);
64 } // fallback on ok if right is not defined
66 if(mpriv
->p
.current
->ok
) {
67 mp_cmd_t
* c
= mp_input_parse_cmd(mpriv
->p
.current
->ok
);
70 if (mpriv
->auto_close
)
71 mp_input_queue_cmd (mp_input_parse_cmd ("menu hide"));
72 mp_input_queue_cmd(c
);
77 if(mpriv
->p
.current
->left
) {
78 mp_cmd_t
* c
= mp_input_parse_cmd(mpriv
->p
.current
->left
);
79 if(c
) mp_input_queue_cmd(c
);
81 } // fallback on cancel if left is not defined
83 if(mpriv
->p
.current
->cancel
) {
84 mp_cmd_t
* c
= mp_input_parse_cmd(mpriv
->p
.current
->cancel
);
86 mp_input_queue_cmd(c
);
90 menu_list_read_cmd(menu
,cmd
);
94 static void read_key(menu_t
* menu
,int c
){
95 menu_list_read_key(menu
,c
,0);
98 static void free_entry(list_entry_t
* entry
) {
107 static void close_menu(menu_t
* menu
) {
108 menu_list_uninit(menu
,free_entry
);
111 static int parse_args(menu_t
* menu
,char* args
) {
112 char *element
,*body
, **attribs
, *name
;
113 list_entry_t
* m
= NULL
;
115 ASX_Parser_t
* parser
= asx_parser_new();
118 r
= asx_get_element(parser
,&args
,&element
,&body
,&attribs
);
120 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_SyntaxErrorAtLine
,parser
->line
);
121 asx_parser_free(parser
);
124 asx_parser_free(parser
);
126 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_NoEntryFoundInTheMenuDefinition
);
130 name
= asx_get_attrib("name",attribs
);
132 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_ListMenuEntryDefinitionsNeedAName
,parser
->line
);
135 asx_free_attribs(attribs
);
138 m
= calloc(1,sizeof(struct list_entry_s
));
140 m
->ok
= asx_get_attrib("ok",attribs
);
141 m
->cancel
= asx_get_attrib("cancel",attribs
);
142 m
->left
= asx_get_attrib("left",attribs
);
143 m
->right
= asx_get_attrib("right",attribs
);
144 menu_list_add_entry(menu
,m
);
148 asx_free_attribs(attribs
);
152 static int open_cmdlist(menu_t
* menu
, char* args
) {
153 menu
->draw
= menu_list_draw
;
154 menu
->read_cmd
= read_cmd
;
155 menu
->read_key
= read_key
;
156 menu
->close
= close_menu
;
159 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_ListMenuNeedsAnArgument
);
163 menu_list_init(menu
);
164 if(!parse_args(menu
,args
))
169 const menu_info_t menu_info_cmdlist
= {
176 sizeof(struct menu_priv_s
),