Mercurial > mplayer.hg
annotate libmenu/menu_cmdlist.c @ 9491:21f7d83507ca
draw_slice support
author | arpi |
---|---|
date | Sun, 23 Feb 2003 20:40:46 +0000 |
parents | 440301fef3fe |
children | 931bdbc37ee0 |
rev | line source |
---|---|
8197 | 1 |
2 #include "../config.h" | |
3 | |
4 #include <stdlib.h> | |
5 #include <stdio.h> | |
6 #include <ctype.h> | |
8623
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8197
diff
changeset
|
7 #include <string.h> |
8197 | 8 |
9 #include "img_format.h" | |
10 #include "mp_image.h" | |
11 | |
12 #include "../m_option.h" | |
13 #include "../m_struct.h" | |
14 #include "../asxparser.h" | |
15 #include "menu.h" | |
16 #include "menu_list.h" | |
17 | |
18 #include "../libvo/font_load.h" | |
19 | |
20 #include "../input/input.h" | |
21 #include "../version.h" | |
22 | |
23 | |
24 | |
25 struct list_entry_s { | |
26 struct list_entry p; | |
27 | |
28 char* ok; | |
29 char* cancel; | |
30 }; | |
31 | |
32 struct menu_priv_s { | |
33 menu_list_priv_t p; | |
34 }; | |
35 | |
36 static struct menu_priv_s cfg_dflt = { | |
37 MENU_LIST_PRIV_DFLT | |
38 }; | |
39 | |
40 static m_option_t cfg_fields[] = { | |
41 MENU_LIST_PRIV_FIELDS, | |
42 { "title",M_ST_OFF(struct menu_priv_s,p.title), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
43 { NULL, NULL, NULL, 0,0,0,NULL } | |
44 }; | |
45 | |
46 #define mpriv (menu->priv) | |
47 | |
48 static void read_cmd(menu_t* menu,int cmd) { | |
49 switch(cmd) { | |
50 case MENU_CMD_OK: { | |
51 if(mpriv->p.current->ok) { | |
52 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->ok); | |
53 if(c) | |
54 mp_input_queue_cmd(c); | |
55 } | |
56 } break; | |
57 case MENU_CMD_CANCEL: | |
58 if(mpriv->p.current->cancel) { | |
59 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->cancel); | |
60 if(c) | |
61 mp_input_queue_cmd(c); | |
62 break; | |
63 } | |
64 default: | |
65 menu_list_read_cmd(menu,cmd); | |
66 } | |
67 } | |
68 | |
69 static void read_key(menu_t* menu,int c){ | |
70 menu_list_read_key(menu,c,0); | |
71 } | |
72 | |
73 static void free_entry(list_entry_t* entry) { | |
74 if(entry->ok) | |
75 free(entry->ok); | |
76 if(entry->cancel) | |
77 free(entry->cancel); | |
78 free(entry->p.txt); | |
79 free(entry); | |
80 } | |
81 | |
82 static void close(menu_t* menu) { | |
83 menu_list_uninit(menu,free_entry); | |
84 } | |
85 | |
86 static int parse_args(menu_t* menu,char* args) { | |
87 char *element,*body, **attribs, *name, *ok, *cancel; | |
88 list_entry_t* m = NULL; | |
89 int r; | |
90 ASX_Parser_t* parser = asx_parser_new(); | |
91 | |
92 while(1) { | |
93 r = asx_get_element(parser,&args,&element,&body,&attribs); | |
94 if(r < 0) { | |
95 printf("Syntax error at line %d\n",parser->line); | |
96 asx_parser_free(parser); | |
97 return -1; | |
98 } else if(r == 0) { | |
99 asx_parser_free(parser); | |
100 if(!m) | |
101 printf("No entry found in the menu definition\n"); | |
102 return m ? 1 : 0; | |
103 } | |
104 // Has it a name ? | |
105 name = asx_get_attrib("name",attribs); | |
106 if(!name) { | |
107 printf("List menu entry definitions need a name (line %d)\n",parser->line); | |
108 free(element); | |
109 if(body) free(body); | |
110 asx_free_attribs(attribs); | |
111 continue; | |
112 } | |
113 ok = asx_get_attrib("ok",attribs); | |
114 cancel = asx_get_attrib("cancel",attribs); | |
115 m = calloc(1,sizeof(struct list_entry_s)); | |
116 m->p.txt = name; | |
117 m->ok = ok; | |
118 m->cancel = cancel; | |
119 menu_list_add_entry(menu,m); | |
120 | |
121 free(element); | |
122 if(body) free(body); | |
123 asx_free_attribs(attribs); | |
124 } | |
125 } | |
126 | |
127 static int open(menu_t* menu, char* args) { | |
128 menu->draw = menu_list_draw; | |
129 menu->read_cmd = read_cmd; | |
130 menu->read_key = read_key; | |
131 menu->close = close; | |
132 | |
133 if(!args) { | |
134 printf("List menu need an argument\n"); | |
135 return 0; | |
136 } | |
137 | |
138 menu_list_init(menu); | |
139 if(!parse_args(menu,args)) | |
140 return 0; | |
141 return 1; | |
142 } | |
143 | |
144 const menu_info_t menu_info_cmdlist = { | |
145 "Command list menu", | |
146 "cmdlist", | |
147 "Albeu", | |
148 "", | |
149 { | |
150 "cmdlist_cfg", | |
151 sizeof(struct menu_priv_s), | |
152 &cfg_dflt, | |
153 cfg_fields | |
154 }, | |
155 open | |
156 }; |