X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/b70d23ff742098877b929e8a4982d5e56f6513da..eab3844f965646b62e242aa622754b86d1fd3444:/src/xmenu.c diff --git a/src/xmenu.c b/src/xmenu.c index 6e175e6903..aac7fd4305 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -108,17 +108,14 @@ along with GNU Emacs. If not, see . */ #ifndef TRUE #define TRUE 1 -#define FALSE 0 #endif /* no TRUE */ -Lisp_Object Qdebug_on_next_call; +static Lisp_Object Qdebug_on_next_call; #if defined (USE_X_TOOLKIT) || defined (USE_GTK) static Lisp_Object xdialog_show (FRAME_PTR, int, Lisp_Object, Lisp_Object, const char **); #endif - -static int update_frame_menubar (struct frame *); /* Flag which when set indicates a dialog or menu has been posted by Xt on behalf of one of the widget sets. */ @@ -365,6 +362,9 @@ x_menu_set_in_use (int in_use) /* Wait for an X event to arrive or for a timer to expire. */ +#ifndef USE_MOTIF +static +#endif void x_menu_wait_for_event (void *data) { @@ -966,6 +966,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) Lisp_Object *previous_items = (Lisp_Object *) alloca (previous_menu_items_used * sizeof (Lisp_Object)); + EMACS_UINT subitems; /* If we are making a new widget, its contents are empty, do always reinitialize them. */ @@ -1010,21 +1011,21 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) menu_items = f->menu_bar_vector; menu_items_allocated = VECTORP (menu_items) ? ASIZE (menu_items) : 0; - submenu_start = (int *) alloca (XVECTOR (items)->size * sizeof (int *)); - submenu_end = (int *) alloca (XVECTOR (items)->size * sizeof (int *)); - submenu_n_panes = (int *) alloca (XVECTOR (items)->size * sizeof (int)); - submenu_top_level_items - = (int *) alloca (XVECTOR (items)->size * sizeof (int *)); + subitems = XVECTOR_SIZE (items) / 4; + submenu_start = (int *) alloca (subitems * sizeof (int *)); + submenu_end = (int *) alloca (subitems * sizeof (int *)); + submenu_n_panes = (int *) alloca (subitems * sizeof (int)); + submenu_top_level_items = (int *) alloca (subitems * sizeof (int *)); init_menu_items (); - for (i = 0; i < XVECTOR (items)->size; i += 4) + for (i = 0; i < subitems; i++) { Lisp_Object key, string, maps; last_i = i; - key = XVECTOR (items)->contents[i]; - string = XVECTOR (items)->contents[i + 1]; - maps = XVECTOR (items)->contents[i + 2]; + key = XVECTOR (items)->contents[4 * i]; + string = XVECTOR (items)->contents[4 * i + 1]; + maps = XVECTOR (items)->contents[4 * i + 2]; if (NILP (string)) break; @@ -1051,7 +1052,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) wv->help = Qnil; first_wv = wv; - for (i = 0; i < last_i; i += 4) + for (i = 0; i < last_i; i++) { menu_items_n_panes = submenu_n_panes[i]; wv = digest_single_submenu (submenu_start[i], submenu_end[i], @@ -1096,7 +1097,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) /* Now GC cannot happen during the lifetime of the widget_value, so it's safe to store data from a Lisp_String. */ wv = first_wv->contents; - for (i = 0; i < XVECTOR (items)->size; i += 4) + for (i = 0; i < XVECTOR_SIZE (items); i += 4) { Lisp_Object string; string = XVECTOR (items)->contents[i + 1]; @@ -1122,7 +1123,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) first_wv = wv; items = FRAME_MENU_BAR_ITEMS (f); - for (i = 0; i < XVECTOR (items)->size; i += 4) + for (i = 0; i < XVECTOR_SIZE (items); i += 4) { Lisp_Object string; @@ -1529,7 +1530,8 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int i; Arg av[2]; int ac = 0; - XButtonPressedEvent dummy; + XEvent dummy; + XButtonPressedEvent *event = &(dummy.xbutton); LWLIB_ID menu_id; Widget menu; @@ -1547,36 +1549,35 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, popup_deactivate_callback, menu_highlight_callback); - dummy.type = ButtonPress; - dummy.serial = 0; - dummy.send_event = 0; - dummy.display = FRAME_X_DISPLAY (f); - dummy.time = CurrentTime; - dummy.root = FRAME_X_DISPLAY_INFO (f)->root_window; - dummy.window = dummy.root; - dummy.subwindow = dummy.root; - dummy.x = x; - dummy.y = y; + event->type = ButtonPress; + event->serial = 0; + event->send_event = 0; + event->display = FRAME_X_DISPLAY (f); + event->time = CurrentTime; + event->root = FRAME_X_DISPLAY_INFO (f)->root_window; + event->window = event->subwindow = event->root; + event->x = x; + event->y = y; /* Adjust coordinates to be root-window-relative. */ x += f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); y += f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); - dummy.x_root = x; - dummy.y_root = y; + event->x_root = x; + event->y_root = y; - dummy.state = 0; - dummy.button = 0; + event->state = 0; + event->button = 0; for (i = 0; i < 5; i++) if (FRAME_X_DISPLAY_INFO (f)->grabbed & (1 << i)) - dummy.button = i; + event->button = i; /* Don't allow any geometry request from the user. */ XtSetArg (av[ac], XtNgeometry, 0); ac++; XtSetValues (menu, av, ac); /* Display the menu. */ - lw_popup_menu (menu, (XEvent *) &dummy); + lw_popup_menu (menu, &dummy); popup_activated_flag = 1; x_activate_timeout_atimer (); @@ -2181,7 +2182,7 @@ static struct frame *menu_help_frame; keyboard events. */ static void -menu_help_callback (char *help_string, int pane, int item) +menu_help_callback (char const *help_string, int pane, int item) { Lisp_Object *first_item; Lisp_Object pane_name; @@ -2241,7 +2242,7 @@ pop_down_menu (Lisp_Object arg) Lisp_Object xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, - Lisp_Object title, const char **error, EMACS_UINT timestamp) + Lisp_Object title, const char **error_name, EMACS_UINT timestamp) { Window root; XMenu *menu; @@ -2259,13 +2260,13 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, if (! FRAME_X_P (f) && ! FRAME_MSDOS_P (f)) abort (); - *error = 0; + *error_name = 0; if (menu_items_n_panes == 0) return Qnil; if (menu_items_used <= MENU_ITEMS_PANE_LENGTH) { - *error = "Empty menu"; + *error_name = "Empty menu"; return Qnil; } @@ -2278,7 +2279,7 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, menu = XMenuCreate (FRAME_X_DISPLAY (f), root, "emacs"); if (menu == NULL) { - *error = "Can't create menu"; + *error_name = "Can't create menu"; return Qnil; } @@ -2298,7 +2299,8 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, y += f->top_pos; /* Create all the necessary panes and their items. */ - maxlines = lines = i = 0; + maxwidth = maxlines = lines = i = 0; + lpane = XM_FAILURE; while (i < menu_items_used) { if (EQ (XVECTOR (menu_items)->contents[i], Qt)) @@ -2320,13 +2322,12 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, if (lpane == XM_FAILURE) { XMenuDestroy (FRAME_X_DISPLAY (f), menu); - *error = "Can't create pane"; + *error_name = "Can't create pane"; return Qnil; } i += MENU_ITEMS_PANE_LENGTH; /* Find the width of the widest item in this pane. */ - maxwidth = 0; j = i; while (j < menu_items_used) { @@ -2354,40 +2355,38 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, { /* Create a new item within current pane. */ Lisp_Object item_name, enable, descrip, help; - unsigned char *item_data; - char *help_string; + char *item_data; + char const *help_string; item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; descrip = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; help = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_HELP]; - help_string = STRINGP (help) ? SDATA (help) : NULL; + help_string = STRINGP (help) ? SSDATA (help) : NULL; if (!NILP (descrip)) { - int gap = maxwidth - SBYTES (item_name); /* if alloca is fast, use that to make the space, to reduce gc needs. */ - item_data - = (unsigned char *) alloca (maxwidth - + SBYTES (descrip) + 1); - memcpy (item_data, SDATA (item_name), SBYTES (item_name)); + item_data = (char *) alloca (maxwidth + SBYTES (descrip) + 1); + memcpy (item_data, SSDATA (item_name), SBYTES (item_name)); for (j = SCHARS (item_name); j < maxwidth; j++) item_data[j] = ' '; - memcpy (item_data + j, SDATA (descrip), SBYTES (descrip)); + memcpy (item_data + j, SSDATA (descrip), SBYTES (descrip)); item_data[j + SBYTES (descrip)] = 0; } else - item_data = SDATA (item_name); + item_data = SSDATA (item_name); - if (XMenuAddSelection (FRAME_X_DISPLAY (f), - menu, lpane, 0, item_data, - !NILP (enable), help_string) - == XM_FAILURE) + if (lpane == XM_FAILURE + || (XMenuAddSelection (FRAME_X_DISPLAY (f), + menu, lpane, 0, item_data, + !NILP (enable), help_string) + == XM_FAILURE)) { XMenuDestroy (FRAME_X_DISPLAY (f), menu); - *error = "Can't add selection to menu"; + *error_name = "Can't add selection to menu"; return Qnil; } i += MENU_ITEMS_ITEM_LENGTH; @@ -2464,6 +2463,7 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, status = XMenuActivate (FRAME_X_DISPLAY (f), menu, &pane, &selidx, x, y, ButtonReleaseMask, &datap, menu_help_callback); + entry = pane_prefix = Qnil; switch (status) { @@ -2508,16 +2508,14 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, break; case XM_FAILURE: - *error = "Can't activate menu"; + *error_name = "Can't activate menu"; case XM_IA_SELECT: - entry = Qnil; break; case XM_NO_SELECT: /* Make "Cancel" equivalent to C-g unless FOR_CLICK (which means the menu was invoked with a mouse event as POSITION). */ if (! for_click) Fsignal (Qquit, Qnil); - entry = Qnil; break; }