| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
#include <config.h> |
|---|
| 24 |
#include <signal.h> |
|---|
| 25 |
|
|---|
| 26 |
#include <stdio.h> |
|---|
| 27 |
#include "lisp.h" |
|---|
| 28 |
#include "termhooks.h" |
|---|
| 29 |
#include "frame.h" |
|---|
| 30 |
#include "window.h" |
|---|
| 31 |
#include "keyboard.h" |
|---|
| 32 |
#include "blockinput.h" |
|---|
| 33 |
#include "buffer.h" |
|---|
| 34 |
#include "charset.h" |
|---|
| 35 |
#include "coding.h" |
|---|
| 36 |
|
|---|
| 37 |
#include <MacTypes.h> |
|---|
| 38 |
#include <Menus.h> |
|---|
| 39 |
#include <QuickDraw.h> |
|---|
| 40 |
#include <ToolUtils.h> |
|---|
| 41 |
#include <Fonts.h> |
|---|
| 42 |
#include <Controls.h> |
|---|
| 43 |
#include <Windows.h> |
|---|
| 44 |
#include <Events.h> |
|---|
| 45 |
#if defined (__MRC__) || defined (CODEWARRIOR_VERSION_6) |
|---|
| 46 |
#include <ControlDefinitions.h> |
|---|
| 47 |
#endif |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
#include "macterm.h" |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
#ifndef makedev |
|---|
| 56 |
#include <sys/types.h> |
|---|
| 57 |
#endif |
|---|
| 58 |
|
|---|
| 59 |
#include "dispextern.h" |
|---|
| 60 |
|
|---|
| 61 |
#define POPUP_SUBMENU_ID 235 |
|---|
| 62 |
#define MIN_MENU_ID 256 |
|---|
| 63 |
#define MIN_SUBMENU_ID 1 |
|---|
| 64 |
|
|---|
| 65 |
#define DIALOG_WINDOW_RESOURCE 130 |
|---|
| 66 |
|
|---|
| 67 |
#define HAVE_DIALOGS 1 |
|---|
| 68 |
|
|---|
| 69 |
#undef HAVE_MULTILINGUAL_MENU |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
typedef void * XtPointer; |
|---|
| 75 |
|
|---|
| 76 |
#define True 1 |
|---|
| 77 |
#define False 0 |
|---|
| 78 |
|
|---|
| 79 |
enum button_type |
|---|
| 80 |
{ |
|---|
| 81 |
BUTTON_TYPE_NONE, |
|---|
| 82 |
BUTTON_TYPE_TOGGLE, |
|---|
| 83 |
BUTTON_TYPE_RADIO |
|---|
| 84 |
}; |
|---|
| 85 |
|
|---|
| 86 |
typedef struct _widget_value |
|---|
| 87 |
{ |
|---|
| 88 |
|
|---|
| 89 |
char* name; |
|---|
| 90 |
|
|---|
| 91 |
char* value; |
|---|
| 92 |
|
|---|
| 93 |
char* key; |
|---|
| 94 |
|
|---|
| 95 |
char *help; |
|---|
| 96 |
|
|---|
| 97 |
Boolean enabled; |
|---|
| 98 |
|
|---|
| 99 |
Boolean selected; |
|---|
| 100 |
|
|---|
| 101 |
enum button_type button_type; |
|---|
| 102 |
|
|---|
| 103 |
Boolean title; |
|---|
| 104 |
#if 0 |
|---|
| 105 |
|
|---|
| 106 |
Boolean edited; |
|---|
| 107 |
|
|---|
| 108 |
change_type change; |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
change_type this_one_change; |
|---|
| 112 |
#endif |
|---|
| 113 |
|
|---|
| 114 |
struct _widget_value* contents; |
|---|
| 115 |
|
|---|
| 116 |
XtPointer call_data; |
|---|
| 117 |
|
|---|
| 118 |
struct _widget_value* next; |
|---|
| 119 |
#if 0 |
|---|
| 120 |
|
|---|
| 121 |
void* toolkit_data; |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
Boolean free_toolkit_data; |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
struct _widget_value *free_list; |
|---|
| 130 |
#endif |
|---|
| 131 |
} widget_value; |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
#define malloc_widget_value() (void *)memset (xmalloc (sizeof (widget_value)),\ |
|---|
| 135 |
0, (sizeof (widget_value))) |
|---|
| 136 |
#define free_widget_value(wv) xfree (wv) |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
#define min(x,y) (((x) < (y)) ? (x) : (y)) |
|---|
| 141 |
#define max(x,y) (((x) > (y)) ? (x) : (y)) |
|---|
| 142 |
|
|---|
| 143 |
#ifndef TRUE |
|---|
| 144 |
#define TRUE 1 |
|---|
| 145 |
#define FALSE 0 |
|---|
| 146 |
#endif |
|---|
| 147 |
|
|---|
| 148 |
Lisp_Object Vmenu_updating_frame; |
|---|
| 149 |
|
|---|
| 150 |
Lisp_Object Qdebug_on_next_call; |
|---|
| 151 |
|
|---|
| 152 |
extern Lisp_Object Qmenu_bar; |
|---|
| 153 |
extern Lisp_Object Qmouse_click, Qevent_kind; |
|---|
| 154 |
|
|---|
| 155 |
extern Lisp_Object QCtoggle, QCradio; |
|---|
| 156 |
|
|---|
| 157 |
extern Lisp_Object Voverriding_local_map; |
|---|
| 158 |
extern Lisp_Object Voverriding_local_map_menu_flag; |
|---|
| 159 |
|
|---|
| 160 |
extern Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map; |
|---|
| 161 |
|
|---|
| 162 |
extern Lisp_Object Qmenu_bar_update_hook; |
|---|
| 163 |
|
|---|
| 164 |
void set_frame_menubar (); |
|---|
| 165 |
|
|---|
| 166 |
static void push_menu_item P_ ((Lisp_Object, Lisp_Object, Lisp_Object, |
|---|
| 167 |
Lisp_Object, Lisp_Object, Lisp_Object, |
|---|
| 168 |
Lisp_Object, Lisp_Object)); |
|---|
| 169 |
static Lisp_Object mac_dialog_show (); |
|---|
| 170 |
static Lisp_Object mac_menu_show (); |
|---|
| 171 |
|
|---|
| 172 |
static void keymap_panes (); |
|---|
| 173 |
static void single_keymap_panes (); |
|---|
| 174 |
static void single_menu_item (); |
|---|
| 175 |
static void list_of_panes (); |
|---|
| 176 |
static void list_of_items (); |
|---|
| 177 |
|
|---|
| 178 |
static void fill_submenu (MenuHandle, widget_value *, int); |
|---|
| 179 |
static void fill_menubar (widget_value *); |
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
#define MENU_ITEMS_PANE_NAME 1 |
|---|
| 205 |
#define MENU_ITEMS_PANE_PREFIX 2 |
|---|
| 206 |
#define MENU_ITEMS_PANE_LENGTH 3 |
|---|
| 207 |
|
|---|
| 208 |
enum menu_item_idx |
|---|
| 209 |
{ |
|---|
| 210 |
MENU_ITEMS_ITEM_NAME = 0, |
|---|
| 211 |
MENU_ITEMS_ITEM_ENABLE, |
|---|
| 212 |
MENU_ITEMS_ITEM_VALUE, |
|---|
| 213 |
MENU_ITEMS_ITEM_EQUIV_KEY, |
|---|
| 214 |
MENU_ITEMS_ITEM_DEFINITION, |
|---|
| 215 |
MENU_ITEMS_ITEM_TYPE, |
|---|
| 216 |
MENU_ITEMS_ITEM_SELECTED, |
|---|
| 217 |
MENU_ITEMS_ITEM_HELP, |
|---|
| 218 |
MENU_ITEMS_ITEM_LENGTH |
|---|
| 219 |
}; |
|---|
| 220 |
|
|---|
| 221 |
static Lisp_Object menu_items; |
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
static int menu_items_allocated; |
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
static int menu_items_used; |
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
static int menu_items_n_panes; |
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
static int menu_items_submenu_depth; |
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
static int popup_activated_flag; |
|---|
| 239 |
|
|---|
| 240 |
static int next_menubar_widget_id; |
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
int pending_menu_activation; |
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
static void |
|---|
| 255 |
init_menu_items () |
|---|
| 256 |
{ |
|---|
| 257 |
if (NILP (menu_items)) |
|---|
| 258 |
{ |
|---|
| 259 |
menu_items_allocated = 60; |
|---|
| 260 |
menu_items = Fmake_vector (make_number (menu_items_allocated), Qnil); |
|---|
| 261 |
} |
|---|
| 262 |
|
|---|
| 263 |
menu_items_used = 0; |
|---|
| 264 |
menu_items_n_panes = 0; |
|---|
| 265 |
menu_items_submenu_depth = 0; |
|---|
| 266 |
} |
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
static void |
|---|
| 272 |
finish_menu_items () |
|---|
| 273 |
{ |
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
static void |
|---|
| 280 |
discard_menu_items () |
|---|
| 281 |
{ |
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
if (menu_items_allocated > 200) |
|---|
| 285 |
{ |
|---|
| 286 |
menu_items = Qnil; |
|---|
| 287 |
menu_items_allocated = 0; |
|---|
| 288 |
} |
|---|
| 289 |
} |
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
static void |
|---|
| 294 |
grow_menu_items () |
|---|
| 295 |
{ |
|---|
| 296 |
Lisp_Object old; |
|---|
| 297 |
int old_size = menu_items_allocated; |
|---|
| 298 |
old = menu_items; |
|---|
| 299 |
|
|---|
| 300 |
menu_items_allocated *= 2; |
|---|
| 301 |
menu_items = Fmake_vector (make_number (menu_items_allocated), Qnil); |
|---|
| 302 |
bcopy (XVECTOR (old)->contents, XVECTOR (menu_items)->contents, |
|---|
| 303 |
old_size * sizeof (Lisp_Object)); |
|---|
| 304 |
} |
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
static void |
|---|
| 309 |
push_submenu_start () |
|---|
| 310 |
{ |
|---|
| 311 |
if (menu_items_used + 1 > menu_items_allocated) |
|---|
| 312 |
grow_menu_items (); |
|---|
| 313 |
|
|---|
| 314 |
XVECTOR (menu_items)->contents[menu_items_used++] = Qnil; |
|---|
| 315 |
menu_items_submenu_depth++; |
|---|
| 316 |
} |
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
static void |
|---|
| 321 |
push_submenu_end () |
|---|
| 322 |
{ |
|---|
| 323 |
if (menu_items_used + 1 > menu_items_allocated) |
|---|
| 324 |
grow_menu_items (); |
|---|
| 325 |
|
|---|
| 326 |
XVECTOR (menu_items)->contents[menu_items_used++] = Qlambda; |
|---|
| 327 |
menu_items_submenu_depth--; |
|---|
| 328 |
} |
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
static void |
|---|
| 333 |
push_left_right_boundary () |
|---|
| 334 |
{ |
|---|
| 335 |
if (menu_items_used + 1 > menu_items_allocated) |
|---|
| 336 |
grow_menu_items (); |
|---|
| 337 |
|
|---|
| 338 |
XVECTOR (menu_items)->contents[menu_items_used++] = Qquote; |
|---|
| 339 |
} |
|---|
| 340 |
|
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
static void |
|---|
| 345 |
push_menu_pane (name, prefix_vec) |
|---|
| 346 |
Lisp_Object name, prefix_vec; |
|---|
| 347 |
{ |
|---|
| 348 |
if (menu_items_used + MENU_ITEMS_PANE_LENGTH > menu_items_allocated) |
|---|
| 349 |
grow_menu_items (); |
|---|
| 350 |
|
|---|
| 351 |
if (menu_items_submenu_depth == 0) |
|---|
| 352 |
menu_items_n_panes++; |
|---|
| 353 |
XVECTOR (menu_items)->contents[menu_items_used++] = Qt; |
|---|
| 354 |
XVECTOR (menu_items)->contents[menu_items_used++] = name; |
|---|
| 355 |
XVECTOR (menu_items)->contents[menu_items_used++] = prefix_vec; |
|---|
| 356 |
} |
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
static void |
|---|
| 367 |
push_menu_item (name, enable, key, def, equiv, type, selected, help) |
|---|
| 368 |
Lisp_Object name, enable, key, def, equiv, type, selected, help; |
|---|
| 369 |
{ |
|---|
| 370 |
if (menu_items_used + MENU_ITEMS_ITEM_LENGTH > menu_items_allocated) |
|---|
| 371 |
grow_menu_items (); |
|---|
| 372 |
|
|---|
| 373 |
XVECTOR (menu_items)->contents[menu_items_used++] = name; |
|---|
| 374 |
XVECTOR (menu_items)->contents[menu_items_used++] = enable; |
|---|
| 375 |
XVECTOR (menu_items)->contents[menu_items_used++] = key; |
|---|
| 376 |
XVECTOR (menu_items)->contents[menu_items_used++] = equiv; |
|---|
| 377 |
XVECTOR (menu_items)->contents[menu_items_used++] = def; |
|---|
| 378 |
XVECTOR (menu_items)->contents[menu_items_used++] = type; |
|---|
| 379 |
XVECTOR (menu_items)->contents[menu_items_used++] = selected; |
|---|
| 380 |
XVECTOR (menu_items)->contents[menu_items_used++] = help; |
|---|
| 381 |
} |
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 |
static void |
|---|
| 389 |
keymap_panes (keymaps, nmaps, notreal) |
|---|
| 390 |
Lisp_Object *keymaps; |
|---|
| 391 |
int nmaps; |
|---|
| 392 |
int notreal; |
|---|
| 393 |
{ |
|---|
| 394 |
int mapno; |
|---|
| 395 |
|
|---|
| 396 |
init_menu_items (); |
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 |
for (mapno = 0; mapno < nmaps; mapno++) |
|---|
| 402 |
single_keymap_panes (keymaps[mapno], Qnil, Qnil, notreal, 10); |
|---|
| 403 |
|
|---|
| 404 |
finish_menu_items (); |
|---|
| 405 |
} |
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 |
|
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
|
|---|
| 416 |
static void |
|---|
| 417 |
single_keymap_panes (keymap, pane_name, prefix, notreal, maxdepth) |
|---|
| 418 |
Lisp_Object keymap; |
|---|
| 419 |
Lisp_Object pane_name; |
|---|
| 420 |
Lisp_Object prefix; |
|---|
| 421 |
int notreal; |
|---|
| 422 |
int maxdepth; |
|---|
| 423 |
{ |
|---|
| 424 |
Lisp_Object pending_maps = Qnil; |
|---|
| 425 |
Lisp_Object tail, item; |
|---|
| 426 |
struct gcpro gcpro1, gcpro2; |
|---|
| 427 |
|
|---|
| 428 |
if (maxdepth <= 0) |
|---|
| 429 |
return; |
|---|
| 430 |
|
|---|
| 431 |
push_menu_pane (pane_name, prefix); |
|---|
| 432 |
|
|---|
| 433 |
for (tail = keymap; CONSP (tail); tail = XCDR (tail)) |
|---|
| 434 |
{ |
|---|
| 435 |
GCPRO2 (keymap, pending_maps); |
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
item = XCAR (tail); |
|---|
| 439 |
if (CONSP (item)) |
|---|
| 440 |
single_menu_item (XCAR (item), XCDR (item), |
|---|
| 441 |
&pending_maps, notreal, maxdepth); |
|---|
| 442 |
else if (VECTORP (item)) |
|---|
| 443 |
{ |
|---|
| 444 |
|
|---|
| 445 |
int len = XVECTOR (item)->size; |
|---|
| 446 |
int c; |
|---|
| 447 |
for (c = 0; c < len; c++) |
|---|
| 448 |
{ |
|---|
| 449 |
Lisp_Object character; |
|---|
| 450 |
XSETFASTINT (character, c); |
|---|
| 451 |
single_menu_item (character, XVECTOR (item)->contents[c], |
|---|
| 452 |
&pending_maps, notreal, maxdepth); |
|---|
| 453 |
} |
|---|
| 454 |
} |
|---|
| 455 |
UNGCPRO; |
|---|
| 456 |
} |
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
while (!NILP (pending_maps)) |
|---|
| 460 |
{ |
|---|
| 461 |
Lisp_Object elt, eltcdr, string; |
|---|
| 462 |
elt = Fcar (pending_maps); |
|---|
| 463 |
eltcdr = XCDR (elt); |
|---|
| 464 |
string = XCAR (eltcdr); |
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
single_keymap_panes (Fcar (elt), string, |
|---|
| 468 |
XCDR (eltcdr), notreal, maxdepth - 1); |
|---|
| 469 |
pending_maps = Fcdr (pending_maps); |
|---|
| 470 |
} |
|---|
| 471 |
} |
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
static void |
|---|
| 483 |
single_menu_item (key, item, pending_maps_ptr, notreal, maxdepth) |
|---|
| 484 |
Lisp_Object key, item; |
|---|
| 485 |
Lisp_Object *pending_maps_ptr; |
|---|
| 486 |
int maxdepth, notreal; |
|---|
| 487 |
{ |
|---|
| 488 |
Lisp_Object map, item_string, enabled; |
|---|
| 489 |
struct gcpro gcpro1, gcpro2; |
|---|
| 490 |
int res; |
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
GCPRO2 (key, item); |
|---|
| 494 |
res = parse_menu_item (item, notreal, 0); |
|---|
| 495 |
UNGCPRO; |
|---|
| 496 |
if (!res) |
|---|
| 497 |
return; |
|---|
| 498 |
|
|---|
| 499 |
map = XVECTOR (item_properties)->contents[ITEM_PROPERTY_MAP]; |
|---|
| 500 |
|
|---|
| 501 |
if (notreal) |
|---|
| 502 |
{ |
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 |
if (!NILP (map)) |
|---|
| 506 |
single_keymap_panes (map, Qnil, key, 1, maxdepth - 1); |
|---|
| 507 |
return; |
|---|
| 508 |
} |
|---|
| 509 |
|
|---|
| 510 |
enabled = XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE]; |
|---|
| 511 |
item_string = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME]; |
|---|
| 512 |
|
|---|
| 513 |
if (!NILP (map) && XSTRING (item_string)->data[0] == '@') |
|---|
| 514 |
{ |
|---|
| 515 |
if (!NILP (enabled)) |
|---|
| 516 |
|
|---|
| 517 |
*pending_maps_ptr = Fcons (Fcons (map, Fcons (item_string, key)), |
|---|
| 518 |
*pending_maps_ptr); |
|---|
| 519 |
return; |
|---|
| 520 |
} |
|---|
| 521 |
|
|---|
| 522 |
push_menu_item (item_string, enabled, key, |
|---|
| 523 |
XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF], |
|---|
| 524 |
XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ], |
|---|
| 525 |
XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE], |
|---|
| 526 |
XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED], |
|---|
| 527 |
XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP]); |
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
if (! (NILP (map) || NILP (enabled))) |
|---|
| 531 |
{ |
|---|
| 532 |
push_submenu_start (); |
|---|
| 533 |
single_keymap_panes (map, Qnil, key, 0, maxdepth - 1); |
|---|
| 534 |
push_submenu_end (); |
|---|
| 535 |
} |
|---|
| 536 |
} |
|---|
| 537 |
|
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 |
|
|---|
| 541 |
|
|---|
| 542 |
static void |
|---|
| 543 |
list_of_panes (menu) |
|---|
| 544 |
Lisp_Object menu; |
|---|
| 545 |
{ |
|---|
| 546 |
Lisp_Object tail; |
|---|
| 547 |
|
|---|
| 548 |
init_menu_items (); |
|---|
| 549 |
|
|---|
| 550 |
for (tail = menu; !NILP (tail); tail = Fcdr (tail)) |
|---|
| 551 |
{ |
|---|
| 552 |
Lisp_Object elt, pane_name, pane_data; |
|---|
| 553 |
elt = Fcar (tail); |
|---|
| 554 |
pane_name = Fcar (elt); |
|---|
| 555 |
CHECK_STRING (pane_name, 0); |
|---|
| 556 |
push_menu_pane (pane_name, Qnil); |
|---|
| 557 |
pane_data = Fcdr (elt); |
|---|
| 558 |
CHECK_CONS (pane_data, 0); |
|---|
| 559 |
list_of_items (pane_data); |
|---|
| 560 |
} |
|---|
| 561 |
|
|---|
| 562 |
finish_menu_items (); |
|---|
| 563 |
} |
|---|
| 564 |
|
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
static void |
|---|
| 568 |
list_of_items (pane) |
|---|
| 569 |
Lisp_Object pane; |
|---|
| 570 |
{ |
|---|
| 571 |
Lisp_Object tail, item, item1; |
|---|
| 572 |
|
|---|
| 573 |
for (tail = pane; !NILP (tail); tail = Fcdr (tail)) |
|---|
| 574 |
{ |
|---|
| 575 |
item = Fcar (tail); |
|---|
| 576 |
if (STRINGP (item)) |
|---|
| 577 |
push_menu_item (item, Qnil, Qnil, Qt, Qnil, Qnil, Qnil, Qnil); |
|---|
| 578 |
else if (NILP (item)) |
|---|
| 579 |
push_left_right_boundary (); |
|---|
| 580 |
else |
|---|
| 581 |
{ |
|---|
| 582 |
CHECK_CONS (item, 0); |
|---|
| 583 |
item1 = Fcar (item); |
|---|
| 584 |
CHECK_STRING (item1, 1); |
|---|
| 585 |
push_menu_item (item1, Qt, Fcdr (item), Qt, Qnil, Qnil, Qnil, Qnil); |
|---|
| 586 |
} |
|---|
| 587 |
} |
|---|
| 588 |
} |
|---|
| 589 |
|
|---|
| 590 |
DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0, |
|---|
| 591 |
"Pop up a deck-of-cards menu and return user's selection.\n\ |
|---|
| 592 |
POSITION is a position specification. This is either a mouse button event\n\ |
|---|
| 593 |
or a list ((XOFFSET YOFFSET) WINDOW)\n\ |
|---|
| 594 |
where XOFFSET and YOFFSET are positions in pixels from the top left\n\ |
|---|
| 595 |
corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.)\n\ |
|---|
| 596 |
This controls the position of the center of the first line\n\ |
|---|
| 597 |
in the first pane of the menu, not the top left of the menu as a whole.\n\ |
|---|
| 598 |
If POSITION is t, it means to use the current mouse position.\n\ |
|---|
| 599 |
\n\ |
|---|
| 600 |
MENU is a specifier for a menu. For the simplest case, MENU is a keymap.\n\ |
|---|
| 601 |
The menu items come from key bindings that have a menu string as well as\n\ |
|---|
| 602 |
a definition; actually, the \"definition\" in such a key binding looks like\n\ |
|---|
| 603 |
\(STRING . REAL-DEFINITION). To give the menu a title, put a string into\n\ |
|---|
| 604 |
the keymap as a top-level element.\n\n\ |
|---|
| 605 |
If REAL-DEFINITION is nil, that puts a nonselectable string in the menu.\n\ |
|---|
| 606 |
Otherwise, REAL-DEFINITION should be a valid key binding definition.\n\ |
|---|
| 607 |
\n\ |
|---|
| 608 |
You can also use a list of keymaps as MENU.\n\ |
|---|
| 609 |
Then each keymap makes a separate pane.\n\ |
|---|
| 610 |
When MENU is a keymap or a list of keymaps, the return value\n\ |
|---|
| 611 |
is a list of events.\n\n\ |
|---|
| 612 |
\n\ |
|---|
| 613 |
Alternatively, you can specify a menu of multiple panes\n\ |
|---|
| 614 |
with a list of the form (TITLE PANE1 PANE2...),\n\ |
|---|
| 615 |
where each pane is a list of form (TITLE ITEM1 ITEM2...).\n\ |
|---|
| 616 |
Each ITEM is normally a cons cell (STRING . VALUE);\n\ |
|---|
| 617 |
but a string can appear as an item--that makes a nonselectable line\n\ |
|---|
| 618 |
in the menu.\n\ |
|---|
| 619 |
With this form of menu, the return value is VALUE from the chosen item.\n\ |
|---|
| 620 |
\n\ |
|---|
| 621 |
If POSITION is nil, don't display the menu at all, just precalculate the\n\ |
|---|
| 622 |
cached information about equivalent key sequences.") |
|---|
| 623 |
(position, menu) |
|---|
| 624 |
Lisp_Object position, menu; |
|---|
| 625 |
{ |
|---|
| 626 |
Lisp_Object keymap, tem; |
|---|
| 627 |
int xpos, ypos; |
|---|
| 628 |
Lisp_Object title; |
|---|
| 629 |
char *error_name; |
|---|
| 630 |
Lisp_Object selection; |
|---|
| 631 |
FRAME_PTR f; |
|---|
| 632 |
Lisp_Object x, y, window; |
|---|
| 633 |
int keymaps = 0; |
|---|
| 634 |
int for_click = 0; |
|---|
| 635 |
struct gcpro gcpro1; |
|---|
| 636 |
|
|---|
| 637 |
#ifdef HAVE_MENUS |
|---|
| 638 |
if (! NILP (position)) |
|---|
| 639 |
{ |
|---|
| 640 |
check_mac (); |
|---|
| 641 |
|
|---|
| 642 |
|
|---|
| 643 |
if (EQ (position, Qt) |
|---|
| 644 |
|| (CONSP (position) && EQ (XCAR (position), Qmenu_bar))) |
|---|
| 645 |
{ |
|---|
| 646 |
|
|---|
| 647 |
FRAME_PTR new_f = SELECTED_FRAME (); |
|---|
| 648 |
Lisp_Object bar_window; |
|---|
| 649 |
enum scroll_bar_part part; |
|---|
| 650 |
unsigned long time; |
|---|
| 651 |
|
|---|
| 652 |
if (mouse_position_hook) |
|---|
| 653 |
(*mouse_position_hook) (&new_f, 1, &bar_window, |
|---|
| 654 |
&part, &x, &y, &time); |
|---|
| 655 |
if (new_f != 0) |
|---|
| 656 |
XSETFRAME (window, new_f); |
|---|
| 657 |
else |
|---|
| 658 |
{ |
|---|
| 659 |
window = selected_window; |
|---|
| 660 |
XSETFASTINT (x, 0); |
|---|
| 661 |
XSETFASTINT (y, 0); |
|---|
|
|---|