aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2013-09-17 20:38:40 +0300
committerEli Zaretskii2013-09-17 20:38:40 +0300
commitf1303b5259c58809845b1f223b34567786afbac4 (patch)
tree4b96ce91be99b12be632181f1d60191359229e16 /src
parentdfe3ac02961bc586122ba9d5063889076f85fadd (diff)
downloademacs-f1303b5259c58809845b1f223b34567786afbac4.tar.gz
emacs-f1303b5259c58809845b1f223b34567786afbac4.zip
Converted compile-time tests to run-time tests. Menus display!
Diffstat (limited to 'src')
-rw-r--r--src/menu.c147
1 files changed, 75 insertions, 72 deletions
diff --git a/src/menu.c b/src/menu.c
index 2560b00b3c1..6ec2c411e31 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -50,10 +50,16 @@ extern HMENU current_popup_menu;
50 50
51#include "menu.h" 51#include "menu.h"
52 52
53/* Define HAVE_BOXES if menus can handle radio and toggle buttons. */ 53/* Return non-zero if menus can handle radio and toggle buttons. */
54static bool
55have_boxes (void)
56{
54#if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI) 57#if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
55#define HAVE_BOXES 1 58 if (FRAME_WINDOW_P (XFRAME (Vmenu_updating_frame)))
59 return 1;
56#endif 60#endif
61 return 0;
62}
57 63
58Lisp_Object menu_items; 64Lisp_Object menu_items;
59 65
@@ -283,13 +289,14 @@ single_keymap_panes (Lisp_Object keymap, Lisp_Object pane_name,
283 289
284 push_menu_pane (pane_name, prefix); 290 push_menu_pane (pane_name, prefix);
285 291
286#ifndef HAVE_BOXES 292 if (!have_boxes ())
287 /* Remember index for first item in this pane so we can go back and 293 {
288 add a prefix when (if) we see the first button. After that, notbuttons 294 /* Remember index for first item in this pane so we can go back
289 is set to 0, to mark that we have seen a button and all non button 295 and add a prefix when (if) we see the first button. After
290 items need a prefix. */ 296 that, notbuttons is set to 0, to mark that we have seen a
291 skp.notbuttons = menu_items_used; 297 button and all non button items need a prefix. */
292#endif 298 skp.notbuttons = menu_items_used;
299 }
293 300
294 GCPRO1 (skp.pending_maps); 301 GCPRO1 (skp.pending_maps);
295 map_keymap_canonical (keymap, single_menu_item, Qnil, &skp); 302 map_keymap_canonical (keymap, single_menu_item, Qnil, &skp);
@@ -345,77 +352,72 @@ single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void *sk
345 return; 352 return;
346 } 353 }
347 354
348#if defined (HAVE_X_WINDOWS) || defined (MSDOS)
349#ifndef HAVE_BOXES
350 /* Simulate radio buttons and toggle boxes by putting a prefix in 355 /* Simulate radio buttons and toggle boxes by putting a prefix in
351 front of them. */ 356 front of them. */
352 { 357 if (!have_boxes ())
353 Lisp_Object prefix = Qnil; 358 {
354 Lisp_Object type = AREF (item_properties, ITEM_PROPERTY_TYPE); 359 Lisp_Object prefix = Qnil;
355 if (!NILP (type)) 360 Lisp_Object type = AREF (item_properties, ITEM_PROPERTY_TYPE);
356 { 361 if (!NILP (type))
357 Lisp_Object selected 362 {
358 = AREF (item_properties, ITEM_PROPERTY_SELECTED); 363 Lisp_Object selected
364 = AREF (item_properties, ITEM_PROPERTY_SELECTED);
359 365
360 if (skp->notbuttons) 366 if (skp->notbuttons)
361 /* The first button. Line up previous items in this menu. */ 367 /* The first button. Line up previous items in this menu. */
362 { 368 {
363 int idx = skp->notbuttons; /* Index for first item this menu. */ 369 int idx = skp->notbuttons; /* Index for first item this menu. */
364 int submenu = 0; 370 int submenu = 0;
365 Lisp_Object tem; 371 Lisp_Object tem;
366 while (idx < menu_items_used) 372 while (idx < menu_items_used)
367 { 373 {
368 tem 374 tem
369 = AREF (menu_items, idx + MENU_ITEMS_ITEM_NAME); 375 = AREF (menu_items, idx + MENU_ITEMS_ITEM_NAME);
370 if (NILP (tem)) 376 if (NILP (tem))
371 { 377 {
372 idx++; 378 idx++;
373 submenu++; /* Skip sub menu. */ 379 submenu++; /* Skip sub menu. */
374 } 380 }
375 else if (EQ (tem, Qlambda)) 381 else if (EQ (tem, Qlambda))
376 { 382 {
377 idx++; 383 idx++;
378 submenu--; /* End sub menu. */ 384 submenu--; /* End sub menu. */
379 } 385 }
380 else if (EQ (tem, Qt)) 386 else if (EQ (tem, Qt))
381 idx += 3; /* Skip new pane marker. */ 387 idx += 3; /* Skip new pane marker. */
382 else if (EQ (tem, Qquote)) 388 else if (EQ (tem, Qquote))
383 idx++; /* Skip a left, right divider. */ 389 idx++; /* Skip a left, right divider. */
384 else 390 else
385 { 391 {
386 if (!submenu && SREF (tem, 0) != '\0' 392 if (!submenu && SREF (tem, 0) != '\0'
387 && SREF (tem, 0) != '-') 393 && SREF (tem, 0) != '-')
388 ASET (menu_items, idx + MENU_ITEMS_ITEM_NAME, 394 ASET (menu_items, idx + MENU_ITEMS_ITEM_NAME,
389 concat2 (build_string (" "), tem)); 395 concat2 (build_string (" "), tem));
390 idx += MENU_ITEMS_ITEM_LENGTH; 396 idx += MENU_ITEMS_ITEM_LENGTH;
391 } 397 }
392 } 398 }
393 skp->notbuttons = 0; 399 skp->notbuttons = 0;
394 } 400 }
395 401
396 /* Calculate prefix, if any, for this item. */ 402 /* Calculate prefix, if any, for this item. */
397 if (EQ (type, QCtoggle)) 403 if (EQ (type, QCtoggle))
398 prefix = build_string (NILP (selected) ? "[ ] " : "[X] "); 404 prefix = build_string (NILP (selected) ? "[ ] " : "[X] ");
399 else if (EQ (type, QCradio)) 405 else if (EQ (type, QCradio))
400 prefix = build_string (NILP (selected) ? "( ) " : "(*) "); 406 prefix = build_string (NILP (selected) ? "( ) " : "(*) ");
401 } 407 }
402 /* Not a button. If we have earlier buttons, then we need a prefix. */ 408 /* Not a button. If we have earlier buttons, then we need a prefix. */
403 else if (!skp->notbuttons && SREF (item_string, 0) != '\0' 409 else if (!skp->notbuttons && SREF (item_string, 0) != '\0'
404 && SREF (item_string, 0) != '-') 410 && SREF (item_string, 0) != '-')
405 prefix = build_string (" "); 411 prefix = build_string (" ");
406 412
407 if (!NILP (prefix)) 413 if (!NILP (prefix))
408 item_string = concat2 (prefix, item_string); 414 item_string = concat2 (prefix, item_string);
409 } 415 }
410#endif /* not HAVE_BOXES */
411 416
412#if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK) 417 if (FRAME_TERMCAP_P (XFRAME (Vmenu_updating_frame))
413 if (!NILP (map)) 418 && !NILP (map))
414 /* Indicate visually that this is a submenu. */ 419 /* Indicate visually that this is a submenu. */
415 item_string = concat2 (item_string, build_string (" >")); 420 item_string = concat2 (item_string, build_string (" >"));
416#endif
417
418#endif /* HAVE_X_WINDOWS || MSDOS */
419 421
420 push_menu_item (item_string, enabled, key, 422 push_menu_item (item_string, enabled, key,
421 AREF (item_properties, ITEM_PROPERTY_DEF), 423 AREF (item_properties, ITEM_PROPERTY_DEF),
@@ -426,7 +428,8 @@ single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void *sk
426 428
427#if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (HAVE_NTGUI) 429#if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (HAVE_NTGUI)
428 /* Display a submenu using the toolkit. */ 430 /* Display a submenu using the toolkit. */
429 if (! (NILP (map) || NILP (enabled))) 431 if (FRAME_WINDOW_P (XFRAME (Vmenu_updating_frame))
432 && ! (NILP (map) || NILP (enabled)))
430 { 433 {
431 push_submenu_start (); 434 push_submenu_start ();
432 single_keymap_panes (map, Qnil, key, skp->maxdepth - 1); 435 single_keymap_panes (map, Qnil, key, skp->maxdepth - 1);