ring_bell () { if (! FRAME_TERMCAP_P (selected_frame)) { (*ring_bell_hook) (); return; } OUTPUT (TS_visible_bell && visible_bell ? TS_visible_bell : TS_bell); }
/* Encode a menu string as appropriate for menu-updating-frame's type. */ static Lisp_Object encode_menu_string (Lisp_Object str) { /* TTY menu strings are encoded by write_glyphs, when they are delivered to the glass, so no need to encode them here. */ if (FRAME_TERMCAP_P (XFRAME (Vmenu_updating_frame))) return str; return ENCODE_MENU_STRING (str); }
/* Signal to the main thread that we have file notifications for it to process. */ static void send_notifications (BYTE *info, DWORD info_size, void *desc, volatile int *terminate) { int done = 0; struct frame *f = SELECTED_FRAME (); /* A single buffer is used to communicate all notifications to the main thread. Since both the main thread and several watcher threads could be active at the same time, we use a critical area and an "in-use" flag to synchronize them. A watcher thread can only put its notifications in the buffer if it acquires the critical area and finds the "in-use" flag reset. The main thread resets the flag after it is done processing notifications. FIXME: is there a better way of dealing with this? */ while (!done && !*terminate) { enter_crit (); if (!notification_buffer_in_use) { if (info_size) memcpy (file_notifications, info, min (info_size, sizeof (file_notifications))); notifications_size = min (info_size, sizeof (file_notifications)); notifications_desc = desc; /* If PostMessage fails, the message queue is full. If that happens, the last thing they will worry about is file notifications. So we effectively discard the notification in that case. */ if ((FRAME_TERMCAP_P (f) /* We send the message to the main (a.k.a. "Lisp") thread, where it will wake up MsgWaitForMultipleObjects inside sys_select, causing it to report that there's some keyboard input available. This will in turn cause w32_console_read_socket to be called, which will pick up the file notifications. */ && PostThreadMessage (dwMainThreadId, WM_EMACS_FILENOTIFY, 0, 0)) || (FRAME_W32_P (f) && PostMessage (FRAME_W32_WINDOW (f), WM_EMACS_FILENOTIFY, 0, 0)) /* When we are running in batch mode, there's no one to send a message, so we just signal the data is available and hope sys_select will be called soon and will read the data. */ || (FRAME_INITIAL_P (f) && noninteractive)) notification_buffer_in_use = 1; done = 1; } leave_crit (); if (!done) Sleep (5); } }
set_terminal_modes () { if (! FRAME_TERMCAP_P (selected_frame)) { (*set_terminal_modes_hook) (); return; } OUTPUT_IF (TS_termcap_modes); OUTPUT_IF (TS_visual_mode); OUTPUT_IF (TS_keypad_mode); losecursor (); }
reset_terminal_modes () { if (! FRAME_TERMCAP_P (selected_frame)) { (*reset_terminal_modes_hook) (); return; } if (TN_standout_width < 0) turn_off_highlight (); turn_off_insert (); OUTPUT_IF (TS_end_keypad_mode); OUTPUT_IF (TS_end_visual_mode); OUTPUT_IF (TS_end_termcap_modes); /* Output raw CR so kernel can track the cursor hpos. */ /* But on magic-cookie terminals this can erase an end-standout marker and cause the rest of the frame to be in standout, so move down first. */ if (TN_standout_width >= 0) cmputc ('\n'); cmputc ('\r'); }
/* Signal to the main thread that we have file notifications for it to process. */ static void send_notifications (struct notifications_set *ns) { struct frame *f = SELECTED_FRAME (); /* We add the current notification set to the linked list. Use the critical section to make sure only one thread will access the linked list. */ enter_crit (); ns->next = notifications_set_head; ns->prev = notifications_set_head->prev; ns->prev->next = ns; notifications_set_head->prev = ns; leave_crit(); /* If PostMessage fails, the message queue is full. If that happens, the last thing they will worry about is file notifications. So we effectively discard the notification in that case. */ if (FRAME_TERMCAP_P (f)) /* We send the message to the main (a.k.a. "Lisp") thread, where it will wake up MsgWaitForMultipleObjects inside sys_select, causing it to report that there's some keyboard input available. This will in turn cause w32_console_read_socket to be called, which will pick up the file notifications. */ PostThreadMessage (dwMainThreadId, WM_EMACS_FILENOTIFY, 0, 0); else if (FRAME_W32_P (f)) PostMessage (FRAME_W32_WINDOW (f), WM_EMACS_FILENOTIFY, 0, 0); /* When we are running in batch mode, there's no one to send a message, so we just signal the data is available and hope sys_select will be called soon and will read the data. */ #if 0 else if (FRAME_INITIAL_P (f) && noninteractive) ; #endif }
widget_value * digest_single_submenu (int start, int end, bool top_level_items) { widget_value *wv, *prev_wv, *save_wv, *first_wv; int i; int submenu_depth = 0; widget_value **submenu_stack; bool panes_seen = 0; struct frame *f = XFRAME (Vmenu_updating_frame); USE_SAFE_ALLOCA; SAFE_NALLOCA (submenu_stack, 1, menu_items_used); wv = make_widget_value ("menu", NULL, true, Qnil); wv->button_type = BUTTON_TYPE_NONE; first_wv = wv; save_wv = 0; prev_wv = 0; /* Loop over all panes and items made by the preceding call to parse_single_submenu and construct a tree of widget_value objects. Ignore the panes and items used by previous calls to digest_single_submenu, even though those are also in menu_items. */ i = start; while (i < end) { if (EQ (AREF (menu_items, i), Qnil)) { submenu_stack[submenu_depth++] = save_wv; save_wv = prev_wv; prev_wv = 0; i++; } else if (EQ (AREF (menu_items, i), Qlambda)) { prev_wv = save_wv; save_wv = submenu_stack[--submenu_depth]; i++; } else if (EQ (AREF (menu_items, i), Qt) && submenu_depth != 0) i += MENU_ITEMS_PANE_LENGTH; /* Ignore a nil in the item list. It's meaningful only for dialog boxes. */ else if (EQ (AREF (menu_items, i), Qquote)) i += 1; else if (EQ (AREF (menu_items, i), Qt)) { /* Create a new pane. */ Lisp_Object pane_name; const char *pane_string; panes_seen = 1; pane_name = AREF (menu_items, i + MENU_ITEMS_PANE_NAME); /* TTY menus display menu items via tty_write_glyphs, which will encode the strings as appropriate. */ if (!FRAME_TERMCAP_P (f)) { #ifdef HAVE_NTGUI if (STRINGP (pane_name)) { if (unicode_append_menu) /* Encode as UTF-8 for now. */ pane_name = ENCODE_UTF_8 (pane_name); else if (STRING_MULTIBYTE (pane_name)) pane_name = ENCODE_SYSTEM (pane_name); ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name); } #elif defined (USE_LUCID) && defined (HAVE_XFT) if (STRINGP (pane_name)) { pane_name = ENCODE_UTF_8 (pane_name); ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name); } #elif !defined (HAVE_MULTILINGUAL_MENU) if (STRINGP (pane_name) && STRING_MULTIBYTE (pane_name)) { pane_name = ENCODE_MENU_STRING (pane_name); ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name); } #endif } pane_string = (NILP (pane_name) ? "" : SSDATA (pane_name)); /* If there is just one top-level pane, put all its items directly under the top-level menu. */ if (menu_items_n_panes == 1) pane_string = ""; /* If the pane has a meaningful name, make the pane a top-level menu item with its items as a submenu beneath it. */ if (strcmp (pane_string, "")) { /* Set value to 1 so update_submenu_strings can handle '@'. */ wv = make_widget_value (NULL, (char *) 1, true, Qnil); if (save_wv) save_wv->next = wv; else first_wv->contents = wv; wv->lname = pane_name; wv->button_type = BUTTON_TYPE_NONE; save_wv = wv; } else save_wv = first_wv; prev_wv = 0; i += MENU_ITEMS_PANE_LENGTH; } else { /* Create a new item within current pane. */ Lisp_Object item_name, enable, descrip, def, type, selected; Lisp_Object help; /* All items should be contained in panes. */ if (! panes_seen) emacs_abort (); item_name = AREF (menu_items, i + MENU_ITEMS_ITEM_NAME); enable = AREF (menu_items, i + MENU_ITEMS_ITEM_ENABLE); descrip = AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY); def = AREF (menu_items, i + MENU_ITEMS_ITEM_DEFINITION); type = AREF (menu_items, i + MENU_ITEMS_ITEM_TYPE); selected = AREF (menu_items, i + MENU_ITEMS_ITEM_SELECTED); help = AREF (menu_items, i + MENU_ITEMS_ITEM_HELP); /* TTY menu items and their descriptions will be encoded by tty_write_glyphs. */ if (!FRAME_TERMCAP_P (f)) { #ifdef HAVE_NTGUI if (STRINGP (item_name)) { if (unicode_append_menu) item_name = ENCODE_UTF_8 (item_name); else if (STRING_MULTIBYTE (item_name)) item_name = ENCODE_SYSTEM (item_name); ASET (menu_items, i + MENU_ITEMS_ITEM_NAME, item_name); } if (STRINGP (descrip) && STRING_MULTIBYTE (descrip)) { descrip = ENCODE_SYSTEM (descrip); ASET (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY, descrip); } #elif USE_LUCID if (STRINGP (item_name)) { item_name = ENCODE_UTF_8 (item_name); ASET (menu_items, i + MENU_ITEMS_ITEM_NAME, item_name); } if (STRINGP (descrip)) { descrip = ENCODE_UTF_8 (descrip); ASET (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY, descrip); } #elif !defined (HAVE_MULTILINGUAL_MENU) if (STRING_MULTIBYTE (item_name)) { item_name = ENCODE_MENU_STRING (item_name); ASET (menu_items, i + MENU_ITEMS_ITEM_NAME, item_name); } if (STRINGP (descrip) && STRING_MULTIBYTE (descrip)) { descrip = ENCODE_MENU_STRING (descrip); ASET (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY, descrip); } #endif } wv = make_widget_value (NULL, NULL, !NILP (enable), STRINGP (help) ? help : Qnil); if (prev_wv) prev_wv->next = wv; else save_wv->contents = wv; wv->lname = item_name; if (!NILP (descrip)) wv->lkey = descrip; /* The intptr_t cast avoids a warning. There's no problem as long as pointers have enough bits to hold small integers. */ wv->call_data = (!NILP (def) ? (void *) (intptr_t) i : 0); if (NILP (type)) wv->button_type = BUTTON_TYPE_NONE; else if (EQ (type, QCradio)) wv->button_type = BUTTON_TYPE_RADIO; else if (EQ (type, QCtoggle)) wv->button_type = BUTTON_TYPE_TOGGLE; else emacs_abort (); wv->selected = !NILP (selected); prev_wv = wv; i += MENU_ITEMS_ITEM_LENGTH; } } /* If we have just one "menu item" that was originally a button, return it by itself. */ if (top_level_items && first_wv->contents && first_wv->contents->next == 0) { wv = first_wv; first_wv = first_wv->contents; xfree (wv); } SAFE_FREE (); return first_wv; }
static void single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void *skp_v) { Lisp_Object map, item_string, enabled; struct gcpro gcpro1, gcpro2; bool res; struct skp *skp = skp_v; /* Parse the menu item and leave the result in item_properties. */ GCPRO2 (key, item); res = parse_menu_item (item, 0); UNGCPRO; if (!res) return; /* Not a menu item. */ map = AREF (item_properties, ITEM_PROPERTY_MAP); enabled = AREF (item_properties, ITEM_PROPERTY_ENABLE); item_string = AREF (item_properties, ITEM_PROPERTY_NAME); if (!NILP (map) && SREF (item_string, 0) == '@') { if (!NILP (enabled)) /* An enabled separate pane. Remember this to handle it later. */ skp->pending_maps = Fcons (Fcons (map, Fcons (item_string, key)), skp->pending_maps); return; } /* Simulate radio buttons and toggle boxes by putting a prefix in front of them. */ if (!have_boxes ()) { char const *prefix = 0; Lisp_Object type = AREF (item_properties, ITEM_PROPERTY_TYPE); if (!NILP (type)) { Lisp_Object selected = AREF (item_properties, ITEM_PROPERTY_SELECTED); if (skp->notbuttons) /* The first button. Line up previous items in this menu. */ { int idx = skp->notbuttons; /* Index for first item this menu. */ int submenu = 0; Lisp_Object tem; while (idx < menu_items_used) { tem = AREF (menu_items, idx + MENU_ITEMS_ITEM_NAME); if (NILP (tem)) { idx++; submenu++; /* Skip sub menu. */ } else if (EQ (tem, Qlambda)) { idx++; submenu--; /* End sub menu. */ } else if (EQ (tem, Qt)) idx += 3; /* Skip new pane marker. */ else if (EQ (tem, Qquote)) idx++; /* Skip a left, right divider. */ else { if (!submenu && SREF (tem, 0) != '\0' && SREF (tem, 0) != '-') ASET (menu_items, idx + MENU_ITEMS_ITEM_NAME, concat2 (SCOPED_STRING (" "), tem)); idx += MENU_ITEMS_ITEM_LENGTH; } } skp->notbuttons = 0; } /* Calculate prefix, if any, for this item. */ if (EQ (type, QCtoggle)) prefix = NILP (selected) ? "[ ] " : "[X] "; else if (EQ (type, QCradio)) prefix = NILP (selected) ? "( ) " : "(*) "; } /* Not a button. If we have earlier buttons, then we need a prefix. */ else if (!skp->notbuttons && SREF (item_string, 0) != '\0' && SREF (item_string, 0) != '-') prefix = " "; if (prefix) item_string = concat2 (SCOPED_STRING (prefix), item_string); } if ((FRAME_TERMCAP_P (XFRAME (Vmenu_updating_frame)) || FRAME_MSDOS_P (XFRAME (Vmenu_updating_frame))) && !NILP (map)) /* Indicate visually that this is a submenu. */ item_string = concat2 (item_string, SCOPED_STRING (" >")); push_menu_item (item_string, enabled, key, AREF (item_properties, ITEM_PROPERTY_DEF), AREF (item_properties, ITEM_PROPERTY_KEYEQ), AREF (item_properties, ITEM_PROPERTY_TYPE), AREF (item_properties, ITEM_PROPERTY_SELECTED), AREF (item_properties, ITEM_PROPERTY_HELP)); #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (HAVE_NTGUI) /* Display a submenu using the toolkit. */ if (FRAME_WINDOW_P (XFRAME (Vmenu_updating_frame)) && ! (NILP (map) || NILP (enabled))) { push_submenu_start (); single_keymap_panes (map, Qnil, key, skp->maxdepth - 1); push_submenu_end (); } #endif }