BUTTON_TYPE_RADIO
};
+/* This structure is based on the one in ../lwlib/lwlib.h, modified
+ for Windows. */
typedef struct _widget_value
{
/* name of widget */
char* value;
/* keyboard equivalent. no implications for XtTranslations */
char* key;
- /* Help string or null if none. */
- char *help;
+ /* Help string or nil if none.
+ GC finds this string through the frame's menu_bar_vector
+ or through menu_items. */
+ Lisp_Object help;
/* true if enabled */
Boolean enabled;
/* true if selected */
#define FALSE 0
#endif /* no TRUE */
+static HMENU current_popup_menu;
+
+FARPROC get_menu_item_info;
+FARPROC set_menu_item_info;
+
Lisp_Object Vmenu_updating_frame;
Lisp_Object Qdebug_on_next_call;
static void push_menu_item P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
Lisp_Object, Lisp_Object, Lisp_Object,
Lisp_Object, Lisp_Object));
+#ifdef HAVE_DIALOGS
static Lisp_Object w32_dialog_show ();
+#endif
static Lisp_Object w32_menu_show ();
static void keymap_panes ();
XVECTOR (menu_items)->contents[menu_items_used++] = Qquote;
}
-/* Start a new menu pane in menu_items..
+/* Start a new menu pane in menu_items.
NAME is the pane name. PREFIX_VEC is a prefix key for this pane. */
static void
Lisp_Object elt, pane_name, pane_data;
elt = Fcar (tail);
pane_name = Fcar (elt);
- CHECK_STRING (pane_name, 0);
+ CHECK_STRING (pane_name);
push_menu_pane (pane_name, Qnil);
pane_data = Fcdr (elt);
- CHECK_CONS (pane_data, 0);
+ CHECK_CONS (pane_data);
list_of_items (pane_data);
}
push_left_right_boundary ();
else
{
- CHECK_CONS (item, 0);
+ CHECK_CONS (item);
item1 = Fcar (item);
- CHECK_STRING (item1, 1);
+ CHECK_STRING (item1);
push_menu_item (item1, Qt, Fcdr (item), Qt, Qnil, Qnil, Qnil, Qnil);
}
}
}
\f
DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0,
- "Pop up a deck-of-cards menu and return user's selection.\n\
-POSITION is a position specification. This is either a mouse button event\n\
-or a list ((XOFFSET YOFFSET) WINDOW)\n\
-where XOFFSET and YOFFSET are positions in pixels from the top left\n\
-corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.)\n\
-This controls the position of the center of the first line\n\
-in the first pane of the menu, not the top left of the menu as a whole.\n\
-If POSITION is t, it means to use the current mouse position.\n\
-\n\
-MENU is a specifier for a menu. For the simplest case, MENU is a keymap.\n\
-The menu items come from key bindings that have a menu string as well as\n\
-a definition; actually, the \"definition\" in such a key binding looks like\n\
-\(STRING . REAL-DEFINITION). To give the menu a title, put a string into\n\
-the keymap as a top-level element.\n\n\
-If REAL-DEFINITION is nil, that puts a nonselectable string in the menu.\n\
-Otherwise, REAL-DEFINITION should be a valid key binding definition.\n\
-\n\
-You can also use a list of keymaps as MENU.\n\
- Then each keymap makes a separate pane.\n\
-When MENU is a keymap or a list of keymaps, the return value\n\
-is a list of events.\n\n\
-\n\
-Alternatively, you can specify a menu of multiple panes\n\
- with a list of the form (TITLE PANE1 PANE2...),\n\
-where each pane is a list of form (TITLE ITEM1 ITEM2...).\n\
-Each ITEM is normally a cons cell (STRING . VALUE);\n\
-but a string can appear as an item--that makes a nonselectable line\n\
-in the menu.\n\
-With this form of menu, the return value is VALUE from the chosen item.\n\
-\n\
-If POSITION is nil, don't display the menu at all, just precalculate the\n\
-cached information about equivalent key sequences.")
+ doc: /* Pop up a deck-of-cards menu and return user's selection.
+POSITION is a position specification. This is either a mouse button
+event or a list ((XOFFSET YOFFSET) WINDOW) where XOFFSET and YOFFSET
+are positions in pixels from the top left corner of WINDOW's frame
+\(WINDOW may be a frame object instead of a window). This controls the
+position of the center of the first line in the first pane of the
+menu, not the top left of the menu as a whole. If POSITION is t, it
+means to use the current mouse position.
+
+MENU is a specifier for a menu. For the simplest case, MENU is a keymap.
+The menu items come from key bindings that have a menu string as well as
+a definition; actually, the \"definition\" in such a key binding looks like
+\(STRING . REAL-DEFINITION). To give the menu a title, put a string into
+the keymap as a top-level element.
+
+If REAL-DEFINITION is nil, that puts a nonselectable string in the menu.
+Otherwise, REAL-DEFINITION should be a valid key binding definition.
+
+You can also use a list of keymaps as MENU. Then each keymap makes a
+separate pane. When MENU is a keymap or a list of keymaps, the return
+value is a list of events.
+
+Alternatively, you can specify a menu of multiple panes with a list of
+the form (TITLE PANE1 PANE2...), where each pane is a list of
+form (TITLE ITEM1 ITEM2...).
+Each ITEM is normally a cons cell (STRING . VALUE); but a string can
+appear as an item--that makes a nonselectable line in the menu.
+With this form of menu, the return value is VALUE from the chosen item.
+
+If POSITION is nil, don't display the menu at all, just precalculate the
+cached information about equivalent key sequences. */)
(position, menu)
Lisp_Object position, menu;
{
Lisp_Object keymap, tem;
- int xpos, ypos;
+ int xpos = 0, ypos = 0;
Lisp_Object title;
char *error_name;
Lisp_Object selection;
- FRAME_PTR f;
+ FRAME_PTR f = NULL;
Lisp_Object x, y, window;
int keymaps = 0;
int for_click = 0;
}
}
- CHECK_NUMBER (x, 0);
- CHECK_NUMBER (y, 0);
+ CHECK_NUMBER (x);
+ CHECK_NUMBER (y);
/* Decode where to put the menu. */
}
else if (WINDOWP (window))
{
- CHECK_LIVE_WINDOW (window, 0);
+ CHECK_LIVE_WINDOW (window);
f = XFRAME (WINDOW_FRAME (XWINDOW (window)));
xpos = (FONT_WIDTH (FRAME_FONT (f))
else
/* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
but I don't want to make one now. */
- CHECK_WINDOW (window, 0);
+ CHECK_WINDOW (window);
xpos += XINT (x);
ypos += XINT (y);
{
/* We were given an old-fashioned menu. */
title = Fcar (menu);
- CHECK_STRING (title, 1);
+ CHECK_STRING (title);
list_of_panes (Fcdr (menu));
#ifdef HAVE_MENUS
DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 2, 0,
- "Pop up a dialog box and return user's selection.\n\
-POSITION specifies which frame to use.\n\
-This is normally a mouse button event or a window or frame.\n\
-If POSITION is t, it means to use the frame the mouse is on.\n\
-The dialog box appears in the middle of the specified frame.\n\
-\n\
-CONTENTS specifies the alternatives to display in the dialog box.\n\
-It is a list of the form (TITLE ITEM1 ITEM2...).\n\
-Each ITEM is a cons cell (STRING . VALUE).\n\
-The return value is VALUE from the chosen item.\n\n\
-An ITEM may also be just a string--that makes a nonselectable item.\n\
-An ITEM may also be nil--that means to put all preceding items\n\
-on the left of the dialog box and all following items on the right.\n\
-\(By default, approximately half appear on each side.)")
+ doc: /* Pop up a dialog box and return user's selection.
+POSITION specifies which frame to use.
+This is normally a mouse button event or a window or frame.
+If POSITION is t, it means to use the frame the mouse is on.
+The dialog box appears in the middle of the specified frame.
+
+CONTENTS specifies the alternatives to display in the dialog box.
+It is a list of the form (TITLE ITEM1 ITEM2...).
+Each ITEM is a cons cell (STRING . VALUE).
+The return value is VALUE from the chosen item.
+
+An ITEM may also be just a string--that makes a nonselectable item.
+An ITEM may also be nil--that means to put all preceding items
+on the left of the dialog box and all following items on the right.
+\(By default, approximately half appear on each side.) */)
(position, contents)
Lisp_Object position, contents;
{
- FRAME_PTR f;
+ FRAME_PTR f = NULL;
Lisp_Object window;
check_w32 ();
f = XFRAME (window);
else if (WINDOWP (window))
{
- CHECK_LIVE_WINDOW (window, 0);
+ CHECK_LIVE_WINDOW (window);
f = XFRAME (WINDOW_FRAME (XWINDOW (window)));
}
else
/* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
but I don't want to make one now. */
- CHECK_WINDOW (window, 0);
+ CHECK_WINDOW (window);
#ifndef HAVE_DIALOGS
/* Display a menu with these alternatives
/* Decode the dialog items from what was specified. */
title = Fcar (contents);
- CHECK_STRING (title, 1);
+ CHECK_STRING (title);
list_of_panes (Fcons (contents, Qnil));
wv->value = 0;
wv->enabled = 1;
wv->button_type = BUTTON_TYPE_NONE;
+ wv->help = Qnil;
first_wv = wv;
save_wv = 0;
prev_wv = 0;
/* Create a new pane. */
Lisp_Object pane_name, prefix;
char *pane_string;
+
pane_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_NAME];
prefix = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
+
#ifndef HAVE_MULTILINGUAL_MENU
if (STRINGP (pane_name) && STRING_MULTIBYTE (pane_name))
- pane_name = ENCODE_SYSTEM (pane_name);
+ {
+ pane_name = ENCODE_SYSTEM (pane_name);
+ AREF (menu_items, i + MENU_ITEMS_PANE_NAME) = pane_name;
+ }
#endif
pane_string = (NILP (pane_name)
? "" : (char *) XSTRING (pane_name)->data);
wv->value = 0;
wv->enabled = 1;
wv->button_type = BUTTON_TYPE_NONE;
+ wv->help = Qnil;
}
save_wv = wv;
prev_wv = 0;
Lisp_Object item_name, enable, descrip, def, type, selected;
Lisp_Object help;
- 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];
- def = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_DEFINITION];
- type = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_TYPE];
- selected = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_SELECTED];
- help = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_HELP];
+ 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);
#ifndef HAVE_MULTILINGUAL_MENU
if (STRING_MULTIBYTE (item_name))
- item_name = ENCODE_SYSTEM (item_name);
+ {
+ item_name = ENCODE_SYSTEM (item_name);
+ AREF (menu_items, i + MENU_ITEMS_ITEM_NAME) = item_name;
+ }
+
if (STRINGP (descrip) && STRING_MULTIBYTE (descrip))
- descrip = ENCODE_SYSTEM (descrip);
-#endif
+ {
+ descrip = ENCODE_SYSTEM (descrip);
+ AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY) = descrip;
+ }
+#endif /* not HAVE_MULTILINGUAL_MENU */
wv = xmalloc_widget_value ();
if (prev_wv)
abort ();
wv->selected = !NILP (selected);
- if (STRINGP (help))
- wv->help = (char *) XSTRING (help)->data;
- else
- wv->help = NULL;
+ if (!STRINGP (help))
+ help = Qnil;
+
+ wv->help = help;
prev_wv = wv;
wv->value = 0;
wv->enabled = 1;
wv->button_type = BUTTON_TYPE_NONE;
+ wv->help = Qnil;
first_wv = wv;
if (deep_p)
}
/* Now GC cannot happen during the lifetime of the widget_value,
- so it's safe to store data from a Lisp_String. */
+ so it's safe to store data from a Lisp_String, as long as
+ local copies are made when the actual menu is created.
+ Windows takes care of this for normal string items, but
+ not for owner-drawn items or additional item-info. */
wv = first_wv->contents;
for (i = 0; i < XVECTOR (items)->size; i += 4)
{
wv->value = 0;
wv->enabled = 1;
wv->button_type = BUTTON_TYPE_NONE;
+ wv->help = Qnil;
/* This prevents lwlib from assuming this
menu item is really supposed to be empty. */
/* The EMACS_INT cast avoids a warning.
f->output_data.w32->menubar_widget = NULL;
DestroyMenu (old);
}
-
+
UNBLOCK_INPUT;
}
wv->value = 0;
wv->enabled = 1;
wv->button_type = BUTTON_TYPE_NONE;
+ wv->help = Qnil;
first_wv = wv;
first_pane = 1;
/* Create a new pane. */
Lisp_Object pane_name, prefix;
char *pane_string;
- pane_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_NAME];
- prefix = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
+ pane_name = AREF (menu_items, i + MENU_ITEMS_PANE_NAME);
+ prefix = AREF (menu_items, i + MENU_ITEMS_PANE_PREFIX);
#ifndef HAVE_MULTILINGUAL_MENU
- if (!NILP (pane_name) && STRING_MULTIBYTE (pane_name))
- pane_name = ENCODE_SYSTEM (pane_name);
+ if (STRINGP (pane_name) && STRING_MULTIBYTE (pane_name))
+ {
+ pane_name = ENCODE_SYSTEM (pane_name);
+ AREF (menu_items, i + MENU_ITEMS_PANE_NAME) = pane_name;
+ }
#endif
pane_string = (NILP (pane_name)
? "" : (char *) XSTRING (pane_name)->data);
wv->value = 0;
wv->enabled = 1;
wv->button_type = BUTTON_TYPE_NONE;
+ wv->help = Qnil;
save_wv = wv;
prev_wv = 0;
}
/* Create a new item within current pane. */
Lisp_Object item_name, enable, descrip, def, type, selected, help;
- 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];
- def = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_DEFINITION];
- type = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_TYPE];
- selected = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_SELECTED];
- help = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_HELP];
+ 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);
#ifndef HAVE_MULTILINGUAL_MENU
if (STRINGP (item_name) && STRING_MULTIBYTE (item_name))
- item_name = ENCODE_SYSTEM (item_name);
+ {
+ item_name = ENCODE_SYSTEM (item_name);
+ AREF (menu_items, i + MENU_ITEMS_ITEM_NAME) = item_name;
+ }
if (STRINGP (descrip) && STRING_MULTIBYTE (descrip))
- descrip = ENCODE_SYSTEM (descrip);
-#endif
+ {
+ descrip = ENCODE_SYSTEM (descrip);
+ AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY) = descrip;
+ }
+#endif /* not HAVE_MULTILINGUAL_MENU */
wv = xmalloc_widget_value ();
if (prev_wv)
wv->key = (char *) XSTRING (descrip)->data;
wv->value = 0;
/* Use the contents index as call_data, since we are
- restricted to 16-bits.. */
+ restricted to 16-bits. */
wv->call_data = !NILP (def) ? (void *) (EMACS_INT) i : 0;
wv->enabled = !NILP (enable);
abort ();
wv->selected = !NILP (selected);
+ if (!STRINGP (help))
+ help = Qnil;
- if (STRINGP (help))
- wv->help = (char *) XSTRING (help)->data;
- else
- wv->help = NULL;
+ wv->help = help;
prev_wv = wv;
so that it looks better. Having two separators looks odd. */
wv_sep->name = "--";
wv_sep->next = first_wv->contents;
+ wv_sep->help = Qnil;
#ifndef HAVE_MULTILINGUAL_MENU
if (STRING_MULTIBYTE (title))
wv_title->enabled = TRUE;
wv_title->title = TRUE;
wv_title->button_type = BUTTON_TYPE_NONE;
+ wv_title->help = Qnil;
wv_title->next = wv_sep;
first_wv->contents = wv_title;
}
/* Actually create the menu. */
- menu = CreatePopupMenu ();
+ current_popup_menu = menu = CreatePopupMenu ();
fill_in_menu (menu, first_wv->contents);
/* Adjust coordinates to be root-window-relative. */
}
\f
+#ifdef HAVE_DIALOGS
static char * button_names [] = {
"button1", "button2", "button3", "button4", "button5",
"button6", "button7", "button8", "button9", "button10" };
prev_wv->name++;
prev_wv->enabled = 1;
prev_wv->name = "message";
+ prev_wv->help = Qnil;
first_wv = prev_wv;
/* Loop over all panes and items, filling in the tree. */
wv->value = (char *) XSTRING (item_name)->data;
wv->call_data = (void *) &XVECTOR (menu_items)->contents[i];
wv->enabled = !NILP (enable);
+ wv->help = Qnil;
prev_wv = wv;
if (! boundary_seen)
wv = xmalloc_widget_value ();
wv->name = dialog_name;
+ wv->help = Qnil;
/* Dialog boxes use a really stupid name encoding
which specifies how many buttons to use
}
/* Actually create the dialog. */
-#ifdef HAVE_DIALOGS
dialog_id = widget_id_tick++;
menu = lw_create_widget (first_wv->name, "dialog", dialog_id, first_wv,
f->output_data.w32->widget, 1, 0,
dialog_selection_callback, 0);
lw_modify_all_widgets (dialog_id, first_wv->contents, TRUE);
-#endif
/* Free the widget_value objects we used to specify the contents. */
free_menubar_widget_value_tree (first_wv);
menu_item_selection = 0;
/* Display the menu. */
-#ifdef HAVE_DIALOGS
lw_pop_up_all_widgets (dialog_id);
popup_activated_flag = 1;
popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), dialog_id);
lw_destroy_all_widgets (dialog_id);
-#endif
/* Find the selected item, and its pane, to return
the proper value. */
return Qnil;
}
+#endif /* HAVE_DIALOGS */
\f
/* Is this item a separator? */
else
out_string = wv->name;
- if (wv->title || wv->call_data == 0)
+ if (item != NULL)
+ fuFlags = MF_POPUP;
+ else if (wv->title || wv->call_data == 0)
{
-#if 0 /* no GC while popup menu is active */
- out_string = LocalAlloc (0, strlen (wv->name) + 1);
- strcpy (out_string, wv->name);
+ /* Only use MF_OWNERDRAW if GetMenuItemInfo is usable, since
+ we can't deallocate the memory otherwise. */
+ if (get_menu_item_info)
+ {
+ out_string = (char *) LocalAlloc (LPTR, strlen (wv->name) + 1);
+#ifdef MENU_DEBUG
+ DebPrint ("Menu: allocing %ld for owner-draw", info.dwItemData);
#endif
- fuFlags = MF_OWNERDRAW | MF_DISABLED;
+ strcpy (out_string, wv->name);
+ fuFlags = MF_OWNERDRAW | MF_DISABLED;
+ }
+ else
+ fuFlags = MF_DISABLED;
}
+
/* Draw radio buttons and tickboxes. */
else if (wv->selected && (wv->button_type == BUTTON_TYPE_TOGGLE ||
- wv->button_type == BUTTON_TYPE_RADIO))
+ wv->button_type == BUTTON_TYPE_RADIO))
fuFlags |= MF_CHECKED;
else
fuFlags |= MF_UNCHECKED;
}
- if (item != NULL)
- fuFlags = MF_POPUP;
-
return_value =
AppendMenu (menu,
fuFlags,
out_string );
/* This must be done after the menu item is created. */
- if ((fuFlags & MF_STRING) != 0)
+ if (!wv->title && wv->call_data != 0)
{
- HMODULE user32 = GetModuleHandle ("user32.dll");
- FARPROC set_menu_item_info = GetProcAddress (user32, "SetMenuItemInfoA");
-
if (set_menu_item_info)
{
MENUITEMINFO info;
info.cbSize = sizeof (info);
info.fMask = MIIM_DATA;
- /* Set help string for menu item. */
- info.dwItemData = (DWORD)wv->help;
+ /* Set help string for menu item. Leave it as a Lisp_Object
+ until it is ready to be displayed, since GC can happen while
+ menus are active. */
+ if (wv->help)
+ info.dwItemData = (DWORD) wv->help;
if (wv->button_type == BUTTON_TYPE_RADIO)
{
supported on NT 3.51 and earlier, as GetMenuItemInfo is not
available. */
void
-w32_menu_display_help (HMENU menu, UINT item, UINT flags)
+w32_menu_display_help (HWND owner, HMENU menu, UINT item, UINT flags)
{
- int pane = 0; /* TODO: Set this to pane number. */
+ if (get_menu_item_info)
+ {
+ struct frame *f = x_window_to_frame (&one_w32_display_info, owner);
+ Lisp_Object frame, help;
- HMODULE user32 = GetModuleHandle ("user32.dll");
- FARPROC get_menu_item_info = GetProcAddress (user32, "GetMenuItemInfoA");
+ // No help echo on owner-draw menu items.
+ if (flags & MF_OWNERDRAW || flags & MF_POPUP)
+ help = Qnil;
+ else
+ {
+ MENUITEMINFO info;
- if (get_menu_item_info)
+ bzero (&info, sizeof (info));
+ info.cbSize = sizeof (info);
+ info.fMask = MIIM_DATA;
+ get_menu_item_info (menu, item, FALSE, &info);
+
+ help = info.dwItemData ? (Lisp_Object) info.dwItemData : Qnil;
+ }
+
+ /* Store the help echo in the keyboard buffer as the X toolkit
+ version does, rather than directly showing it. This seems to
+ solve the GC problems that were present when we based the
+ Windows code on the non-toolkit version. */
+ if (f)
+ {
+ XSETFRAME (frame, f);
+ kbd_buffer_store_help_event (frame, help);
+ }
+ else
+ /* X version has a loop through frames here, which doesn't
+ appear to do anything, unless it has some side effect. */
+ show_help_echo (help, Qnil, Qnil, Qnil, 1);
+ }
+}
+
+/* Free memory used by owner-drawn strings. */
+static void
+w32_free_submenu_strings (menu)
+ HMENU menu;
+{
+ int i, num = GetMenuItemCount (menu);
+ for (i = 0; i < num; i++)
{
- extern Lisp_Object Qmenu_item;
- Lisp_Object *first_item;
- Lisp_Object pane_name;
- Lisp_Object menu_object;
MENUITEMINFO info;
-
bzero (&info, sizeof (info));
info.cbSize = sizeof (info);
- info.fMask = MIIM_DATA;
- get_menu_item_info (menu, item, FALSE, &info);
-
- first_item = XVECTOR (menu_items)->contents;
- if (EQ (first_item[0], Qt))
- pane_name = first_item[MENU_ITEMS_PANE_NAME];
- else if (EQ (first_item[0], Qquote))
- /* This shouldn't happen, see w32_menu_show. */
- pane_name = build_string ("");
- else
- pane_name = first_item[MENU_ITEMS_ITEM_NAME];
+ info.fMask = MIIM_DATA | MIIM_TYPE | MIIM_SUBMENU;
- /* (menu-item MENU-NAME PANE-NUMBER) */
- menu_object = Fcons (Qmenu_item,
- Fcons (pane_name,
- Fcons (make_number (pane), Qnil)));
+ get_menu_item_info (menu, i, TRUE, &info);
+
+ /* Owner-drawn names are held in dwItemData. */
+ if ((info.fType & MF_OWNERDRAW) && info.dwItemData)
+ {
+#ifdef MENU_DEBUG
+ DebPrint ("Menu: freeing %ld for owner-draw", info.dwItemData);
+#endif
+ LocalFree (info.dwItemData);
+ }
- show_help_echo (info.dwItemData ?
- build_string ((char *) info.dwItemData) : Qnil,
- Qnil, menu_object, make_number (item), 1);
+ /* Recurse down submenus. */
+ if (info.hSubMenu)
+ w32_free_submenu_strings (info.hSubMenu);
}
}
+void
+w32_free_menu_strings (hwnd)
+ HWND hwnd;
+{
+ HMENU menu = current_popup_menu;
+ if (get_menu_item_info)
+ {
+ /* If there is no popup menu active, free the strings from the frame's
+ menubar. */
+ if (!menu)
+ menu = GetMenu (hwnd);
+
+ if (menu)
+ w32_free_submenu_strings (menu);
+ }
+
+ current_popup_menu = NULL;
+}
#endif /* HAVE_MENUS */
+
\f
syms_of_w32menu ()
{
+ /* See if Get/SetMenuItemInfo functions are available. */
+ HMODULE user32 = GetModuleHandle ("user32.dll");
+ get_menu_item_info = GetProcAddress (user32, "GetMenuItemInfoA");
+ set_menu_item_info = GetProcAddress (user32, "SetMenuItemInfoA");
+
staticpro (&menu_items);
menu_items = Qnil;
+ current_popup_menu = NULL;
+
Qdebug_on_next_call = intern ("debug-on-next-call");
staticpro (&Qdebug_on_next_call);
DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame,
- "Frame for which we are updating a menu.\n\
-The enable predicate for a menu command should check this variable.");
+ doc: /* Frame for which we are updating a menu.
+The enable predicate for a menu command should check this variable. */);
Vmenu_updating_frame = Qnil;
defsubr (&Sx_popup_menu);