comparison src/menubar.c @ 251:677f6a0ee643 r20-5b24

Import from CVS: tag r20-5b24
author cvs
date Mon, 13 Aug 2007 10:19:59 +0200
parents 262b8bb4a523
children 11cf20601dec
comparison
equal deleted inserted replaced
250:f385a461c9aa 251:677f6a0ee643
28 #include "lisp.h" 28 #include "lisp.h"
29 29
30 #include "buffer.h" 30 #include "buffer.h"
31 #include "device.h" 31 #include "device.h"
32 #include "frame.h" 32 #include "frame.h"
33 #include "gui.h"
33 #include "menubar.h" 34 #include "menubar.h"
34 #include "redisplay.h" 35 #include "redisplay.h"
35 #include "window.h" 36 #include "window.h"
36 37
37 int menubar_show_keybindings; 38 int menubar_show_keybindings;
89 static void 90 static void
90 menubar_visible_p_changed_in_frame (Lisp_Object specifier, struct frame *f, 91 menubar_visible_p_changed_in_frame (Lisp_Object specifier, struct frame *f,
91 Lisp_Object oldval) 92 Lisp_Object oldval)
92 { 93 {
93 update_frame_menubars (f); 94 update_frame_menubars (f);
95 }
96
97 Lisp_Object
98 current_frame_menubar (CONST struct frame* f)
99 {
100 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
101 return symbol_value_in_buffer (Qcurrent_menubar, w->buffer);
102 }
103
104 Lisp_Object
105 menu_parse_submenu_keywords (Lisp_Object desc, struct gui_item* pgui_item)
106 {
107 /* Menu descriptor should be a list */
108 CHECK_CONS (desc);
109
110 /* First element may be menu name, although can be omitted.
111 Let's think that if stuff begins with anything than a keyword
112 or a list (submenu), this is a menu name, expected to be a stirng */
113 if (!KEYWORDP (XCAR (desc)) && !CONSP (XCAR (desc)))
114 {
115 CHECK_STRING (XCAR (desc));
116 pgui_item->name = XCAR (desc);
117 desc = XCDR (desc);
118 if (!NILP (desc))
119 CHECK_CONS (desc);
120 }
121
122 /* Walk along all key-value pairs */
123 while (!NILP(desc) && KEYWORDP (XCAR (desc)))
124 {
125 Lisp_Object key, val;
126 key = XCAR (desc);
127 desc = XCDR (desc);
128 CHECK_CONS (desc);
129 val = XCAR (desc);
130 desc = XCDR (desc);
131 if (!NILP (desc))
132 CHECK_CONS (desc);
133 gui_item_add_keyval_pair (pgui_item, key, val);
134 }
135
136 /* Return the rest - supposed to be a list of items */
137 return desc;
138 }
139
140 DEFUN ("menu-find-real-submenu", Fmenu_find_real_submenu, 2, 2, 0, /*
141 Find a submenu descriptor within DESC by following PATH.
142 This function finds a submenu descriptor, either from the description
143 DESC or generated by a filter within DESC. The function regards :config
144 and :included keywords in the DESC, and expands submenus along the
145 PATH using :filter functions. Return value is a descriptor for the
146 submenu, NOT expanded and NOT checked against :config and :included.
147 Also, individual menu items are not looked for, only submenus.
148
149 See also 'find-menu-item'
150 */
151 (desc, path))
152 {
153 Lisp_Object path_entry, submenu_desc, submenu;
154 struct gcpro gcpro1;
155 struct gui_item gui_item;
156
157 gui_item_init (&gui_item);
158 GCPRO1 (gui_item);
159 gcpro1.nvars = GUI_ITEM_GCPRO_COUNT;
160
161 EXTERNAL_LIST_LOOP (path_entry, path)
162 {
163 /* Verify that DESC describes a menu, not single item */
164 if (!CONSP (desc))
165 RETURN_UNGCPRO (Qnil);
166
167 /* Parse this menu */
168 desc = menu_parse_submenu_keywords (desc, &gui_item);
169
170 /* Check that this (sub)menu is active */
171 if (!gui_item_active_p (&gui_item))
172 RETURN_UNGCPRO (Qnil);
173
174 /* Apply :filter */
175 if (!NILP (gui_item.filter))
176 desc = call1 (gui_item.filter, desc);
177
178 /* Find the next menu on the path inside this one */
179 EXTERNAL_LIST_LOOP (submenu_desc, desc)
180 {
181 submenu = XCAR (submenu_desc);
182 if (CONSP (submenu)
183 && STRINGP (XCAR (submenu))
184 && !NILP (Fstring_equal (XCAR (submenu), XCAR (path_entry))))
185 {
186 desc = submenu;
187 goto descend;
188 }
189 }
190 /* Submenu not found */
191 RETURN_UNGCPRO (Qnil);
192
193 descend:
194 /* Prepare for the next iteration */
195 gui_item_init (&gui_item);
196 }
197
198 /* We have successfully descended down the end of the path */
199 UNGCPRO;
200 return desc;
94 } 201 }
95 202
96 DEFUN ("popup-menu", Fpopup_menu, 1, 2, 0, /* 203 DEFUN ("popup-menu", Fpopup_menu, 1, 2, 0, /*
97 Pop up the given menu. 204 Pop up the given menu.
98 A menu description is a list of menu items, strings, and submenus. 205 A menu description is a list of menu items, strings, and submenus.
237 syms_of_menubar (void) 344 syms_of_menubar (void)
238 { 345 {
239 defsymbol (&Qcurrent_menubar, "current-menubar"); 346 defsymbol (&Qcurrent_menubar, "current-menubar");
240 DEFSUBR (Fpopup_menu); 347 DEFSUBR (Fpopup_menu);
241 DEFSUBR (Fnormalize_menu_item_name); 348 DEFSUBR (Fnormalize_menu_item_name);
349 DEFSUBR (Fmenu_find_real_submenu);
242 } 350 }
243 351
244 void 352 void
245 vars_of_menubar (void) 353 vars_of_menubar (void)
246 { 354 {