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