1 /* Menu support for GNU Emacs on the Microsoft Windows API.
2 Copyright (C) 1986, 1988, 1993-1994, 1996, 1998-1999, 2001-2013 Free
3 Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
30 #include "termhooks.h"
32 #include "blockinput.h"
33 #include "character.h"
39 /* This may include sys/types.h, and that somehow loses
40 if this is not done before the other system files. */
43 /* Cygwin does not support the multibyte string functions declared in
44 * mbstring.h below --- but that's okay: because Cygwin is
45 * UNICODE-only, we don't need to use these functions anyway. */
49 #endif /* !NTGUI_UNICODE */
51 /* Load sys/types.h if not already loaded.
52 In some systems loading it twice is suicidal. */
54 #include <sys/types.h>
57 #include "dispextern.h"
59 #include "w32common.h" /* for osinfo_cache */
61 #undef HAVE_DIALOGS /* TODO: Implement native dialogs. */
68 HMENU current_popup_menu
;
70 void syms_of_w32menu (void);
71 void globals_of_w32menu (void);
73 typedef BOOL (WINAPI
* GetMenuItemInfoA_Proc
) (
77 IN OUT LPMENUITEMINFOA
);
78 typedef BOOL (WINAPI
* SetMenuItemInfoA_Proc
) (
83 typedef int (WINAPI
* MessageBoxW_Proc
) (
90 #define get_menu_item_info GetMenuItemInfoA
91 #define set_menu_item_info SetMenuItemInfoA
92 #define unicode_append_menu AppendMenuW
93 #define unicode_message_box MessageBoxW
94 #else /* !NTGUI_UNICODE */
95 GetMenuItemInfoA_Proc get_menu_item_info
= NULL
;
96 SetMenuItemInfoA_Proc set_menu_item_info
= NULL
;
97 AppendMenuW_Proc unicode_append_menu
= NULL
;
98 MessageBoxW_Proc unicode_message_box
= NULL
;
99 #endif /* NTGUI_UNICODE */
101 Lisp_Object Qdebug_on_next_call
;
103 void set_frame_menubar (FRAME_PTR
, bool, bool);
106 static Lisp_Object
w32_dialog_show (FRAME_PTR
, int, Lisp_Object
, char**);
108 static int is_simple_dialog (Lisp_Object
);
109 static Lisp_Object
simple_dialog_show (FRAME_PTR
, Lisp_Object
, Lisp_Object
);
112 static void utf8to16 (unsigned char *, int, WCHAR
*);
113 static int fill_in_menu (HMENU
, widget_value
*);
115 void w32_free_menu_strings (HWND
);
119 DEFUN ("x-popup-dialog", Fx_popup_dialog
, Sx_popup_dialog
, 2, 3, 0,
120 doc
: /* Pop up a dialog box and return user's selection.
121 POSITION specifies which frame to use.
122 This is normally a mouse button event or a window or frame.
123 If POSITION is t, it means to use the frame the mouse is on.
124 The dialog box appears in the middle of the specified frame.
126 CONTENTS specifies the alternatives to display in the dialog box.
127 It is a list of the form (TITLE ITEM1 ITEM2...).
128 Each ITEM is a cons cell (STRING . VALUE).
129 The return value is VALUE from the chosen item.
131 An ITEM may also be just a string--that makes a nonselectable item.
132 An ITEM may also be nil--that means to put all preceding items
133 on the left of the dialog box and all following items on the right.
134 \(By default, approximately half appear on each side.)
136 If HEADER is non-nil, the frame title for the box is "Information",
137 otherwise it is "Question". */)
138 (Lisp_Object position
, Lisp_Object contents
, Lisp_Object header
)
143 /* Decode the first argument: find the window or frame to use. */
144 if (EQ (position
, Qt
)
145 || (CONSP (position
) && (EQ (XCAR (position
), Qmenu_bar
)
146 || EQ (XCAR (position
), Qtool_bar
))))
148 #if 0 /* Using the frame the mouse is on may not be right. */
149 /* Use the mouse's current position. */
150 FRAME_PTR new_f
= SELECTED_FRAME ();
151 Lisp_Object bar_window
;
152 enum scroll_bar_part part
;
156 (*mouse_position_hook
) (&new_f
, 1, &bar_window
, &part
, &x
, &y
, &time
);
159 XSETFRAME (window
, new_f
);
161 window
= selected_window
;
163 window
= selected_window
;
165 else if (CONSP (position
))
167 Lisp_Object tem
= XCAR (position
);
169 window
= Fcar (XCDR (position
));
172 tem
= Fcar (XCDR (position
)); /* EVENT_START (position) */
173 window
= Fcar (tem
); /* POSN_WINDOW (tem) */
176 else if (WINDOWP (position
) || FRAMEP (position
))
181 /* Decode where to put the menu. */
185 else if (WINDOWP (window
))
187 CHECK_LIVE_WINDOW (window
);
188 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
191 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
192 but I don't want to make one now. */
193 CHECK_WINDOW (window
);
195 check_window_system (f
);
200 /* Handle simple Yes/No choices as MessageBox popups. */
201 if (is_simple_dialog (contents
))
202 return simple_dialog_show (f
, contents
, header
);
205 /* Display a menu with these alternatives
206 in the middle of frame F. */
207 Lisp_Object x
, y
, frame
, newpos
;
208 XSETFRAME (frame
, f
);
209 XSETINT (x
, x_pixel_width (f
) / 2);
210 XSETINT (y
, x_pixel_height (f
) / 2);
211 newpos
= Fcons (Fcons (x
, Fcons (y
, Qnil
)), Fcons (frame
, Qnil
));
212 return Fx_popup_menu (newpos
,
213 Fcons (Fcar (contents
), Fcons (contents
, Qnil
)));
216 #else /* HAVE_DIALOGS */
220 Lisp_Object selection
;
222 /* Decode the dialog items from what was specified. */
223 title
= Fcar (contents
);
224 CHECK_STRING (title
);
226 list_of_panes (Fcons (contents
, Qnil
));
228 /* Display them in a dialog box. */
230 selection
= w32_dialog_show (f
, 0, title
, header
, &error_name
);
233 discard_menu_items ();
234 FRAME_X_DISPLAY_INFO (f
)->grabbed
= 0;
236 if (error_name
) error (error_name
);
239 #endif /* HAVE_DIALOGS */
242 /* Activate the menu bar of frame F.
243 This is called from keyboard.c when it gets the
244 MENU_BAR_ACTIVATE_EVENT out of the Emacs event queue.
246 To activate the menu bar, we signal to the input thread that it can
247 return from the WM_INITMENU message, allowing the normal Windows
248 processing of the menus.
250 But first we recompute the menu bar contents (the whole tree).
252 This way we can safely execute Lisp code. */
255 x_activate_menubar (FRAME_PTR f
)
257 set_frame_menubar (f
, 0, 1);
259 /* Lock out further menubar changes while active. */
260 f
->output_data
.w32
->menubar_active
= 1;
262 /* Signal input thread to return from WM_INITMENU. */
263 complete_deferred_msg (FRAME_W32_WINDOW (f
), WM_INITMENU
, 0);
266 /* This callback is called from the menu bar pulldown menu
267 when the user makes a selection.
268 Figure out what the user chose
269 and put the appropriate events into the keyboard buffer. */
272 menubar_selection_callback (FRAME_PTR f
, void * client_data
)
274 Lisp_Object prefix
, entry
;
276 Lisp_Object
*subprefix_stack
;
277 int submenu_depth
= 0;
283 subprefix_stack
= (Lisp_Object
*) alloca (f
->menu_bar_items_used
* word_size
);
284 vector
= f
->menu_bar_vector
;
287 while (i
< f
->menu_bar_items_used
)
289 if (EQ (AREF (vector
, i
), Qnil
))
291 subprefix_stack
[submenu_depth
++] = prefix
;
295 else if (EQ (AREF (vector
, i
), Qlambda
))
297 prefix
= subprefix_stack
[--submenu_depth
];
300 else if (EQ (AREF (vector
, i
), Qt
))
302 prefix
= AREF (vector
, i
+ MENU_ITEMS_PANE_PREFIX
);
303 i
+= MENU_ITEMS_PANE_LENGTH
;
307 entry
= AREF (vector
, i
+ MENU_ITEMS_ITEM_VALUE
);
308 /* The EMACS_INT cast avoids a warning. There's no problem
309 as long as pointers have enough bits to hold small integers. */
310 if ((int) (EMACS_INT
) client_data
== i
)
313 struct input_event buf
;
317 XSETFRAME (frame
, f
);
318 buf
.kind
= MENU_BAR_EVENT
;
319 buf
.frame_or_window
= frame
;
321 kbd_buffer_store_event (&buf
);
323 for (j
= 0; j
< submenu_depth
; j
++)
324 if (!NILP (subprefix_stack
[j
]))
326 buf
.kind
= MENU_BAR_EVENT
;
327 buf
.frame_or_window
= frame
;
328 buf
.arg
= subprefix_stack
[j
];
329 kbd_buffer_store_event (&buf
);
334 buf
.kind
= MENU_BAR_EVENT
;
335 buf
.frame_or_window
= frame
;
337 kbd_buffer_store_event (&buf
);
340 buf
.kind
= MENU_BAR_EVENT
;
341 buf
.frame_or_window
= frame
;
343 /* Free memory used by owner-drawn and help-echo strings. */
344 w32_free_menu_strings (FRAME_W32_WINDOW (f
));
345 kbd_buffer_store_event (&buf
);
347 f
->output_data
.w32
->menubar_active
= 0;
350 i
+= MENU_ITEMS_ITEM_LENGTH
;
353 /* Free memory used by owner-drawn and help-echo strings. */
354 w32_free_menu_strings (FRAME_W32_WINDOW (f
));
355 f
->output_data
.w32
->menubar_active
= 0;
359 /* Set the contents of the menubar widgets of frame F.
360 The argument FIRST_TIME is currently ignored;
361 it is set the first time this is called, from initialize_frame_menubar. */
364 set_frame_menubar (FRAME_PTR f
, bool first_time
, bool deep_p
)
366 HMENU menubar_widget
= f
->output_data
.w32
->menubar_widget
;
368 widget_value
*wv
, *first_wv
, *prev_wv
= 0;
370 int *submenu_start
, *submenu_end
;
371 int *submenu_top_level_items
, *submenu_n_panes
;
373 /* We must not change the menubar when actually in use. */
374 if (f
->output_data
.w32
->menubar_active
)
377 XSETFRAME (Vmenu_updating_frame
, f
);
379 if (! menubar_widget
)
384 /* Make a widget-value tree representing the entire menu trees. */
386 struct buffer
*prev
= current_buffer
;
388 ptrdiff_t specpdl_count
= SPECPDL_INDEX ();
389 int previous_menu_items_used
= f
->menu_bar_items_used
;
390 Lisp_Object
*previous_items
391 = (Lisp_Object
*) alloca (previous_menu_items_used
394 /* If we are making a new widget, its contents are empty,
395 do always reinitialize them. */
396 if (! menubar_widget
)
397 previous_menu_items_used
= 0;
399 buffer
= XWINDOW (FRAME_SELECTED_WINDOW (f
))->contents
;
400 specbind (Qinhibit_quit
, Qt
);
401 /* Don't let the debugger step into this code
402 because it is not reentrant. */
403 specbind (Qdebug_on_next_call
, Qnil
);
405 record_unwind_save_match_data ();
407 if (NILP (Voverriding_local_map_menu_flag
))
409 specbind (Qoverriding_terminal_local_map
, Qnil
);
410 specbind (Qoverriding_local_map
, Qnil
);
413 set_buffer_internal_1 (XBUFFER (buffer
));
416 safe_run_hooks (Qactivate_menubar_hook
);
417 safe_run_hooks (Qmenu_bar_update_hook
);
418 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
420 items
= FRAME_MENU_BAR_ITEMS (f
);
422 /* Save the frame's previous menu bar contents data. */
423 if (previous_menu_items_used
)
424 memcpy (previous_items
, XVECTOR (f
->menu_bar_vector
)->contents
,
425 previous_menu_items_used
* word_size
);
427 /* Fill in menu_items with the current menu bar contents.
428 This can evaluate Lisp code. */
431 menu_items
= f
->menu_bar_vector
;
432 menu_items_allocated
= VECTORP (menu_items
) ? ASIZE (menu_items
) : 0;
433 submenu_start
= (int *) alloca (ASIZE (items
) * sizeof (int));
434 submenu_end
= (int *) alloca (ASIZE (items
) * sizeof (int));
435 submenu_n_panes
= (int *) alloca (ASIZE (items
) * sizeof (int));
436 submenu_top_level_items
= (int *) alloca (ASIZE (items
) * sizeof (int));
438 for (i
= 0; i
< ASIZE (items
); i
+= 4)
440 Lisp_Object key
, string
, maps
;
444 key
= AREF (items
, i
);
445 string
= AREF (items
, i
+ 1);
446 maps
= AREF (items
, i
+ 2);
450 submenu_start
[i
] = menu_items_used
;
452 menu_items_n_panes
= 0;
453 submenu_top_level_items
[i
]
454 = parse_single_submenu (key
, string
, maps
);
455 submenu_n_panes
[i
] = menu_items_n_panes
;
457 submenu_end
[i
] = menu_items_used
;
460 finish_menu_items ();
462 /* Convert menu_items into widget_value trees
463 to display the menu. This cannot evaluate Lisp code. */
465 wv
= xmalloc_widget_value ();
466 wv
->name
= "menubar";
469 wv
->button_type
= BUTTON_TYPE_NONE
;
473 for (i
= 0; i
< last_i
; i
+= 4)
475 menu_items_n_panes
= submenu_n_panes
[i
];
476 wv
= digest_single_submenu (submenu_start
[i
], submenu_end
[i
],
477 submenu_top_level_items
[i
]);
481 first_wv
->contents
= wv
;
482 /* Don't set wv->name here; GC during the loop might relocate it. */
484 wv
->button_type
= BUTTON_TYPE_NONE
;
488 set_buffer_internal_1 (prev
);
490 /* If there has been no change in the Lisp-level contents
491 of the menu bar, skip redisplaying it. Just exit. */
493 for (i
= 0; i
< previous_menu_items_used
; i
++)
494 if (menu_items_used
== i
495 || (!EQ (previous_items
[i
], AREF (menu_items
, i
))))
497 if (i
== menu_items_used
&& i
== previous_menu_items_used
&& i
!= 0)
499 free_menubar_widget_value_tree (first_wv
);
500 discard_menu_items ();
501 unbind_to (specpdl_count
, Qnil
);
505 fset_menu_bar_vector (f
, menu_items
);
506 f
->menu_bar_items_used
= menu_items_used
;
508 /* This undoes save_menu_items. */
509 unbind_to (specpdl_count
, Qnil
);
511 /* Now GC cannot happen during the lifetime of the widget_value,
512 so it's safe to store data from a Lisp_String, as long as
513 local copies are made when the actual menu is created.
514 Windows takes care of this for normal string items, but
515 not for owner-drawn items or additional item-info. */
516 wv
= first_wv
->contents
;
517 for (i
= 0; i
< ASIZE (items
); i
+= 4)
520 string
= AREF (items
, i
+ 1);
523 wv
->name
= SSDATA (string
);
524 update_submenu_strings (wv
->contents
);
530 /* Make a widget-value tree containing
531 just the top level menu bar strings. */
533 wv
= xmalloc_widget_value ();
534 wv
->name
= "menubar";
537 wv
->button_type
= BUTTON_TYPE_NONE
;
541 items
= FRAME_MENU_BAR_ITEMS (f
);
542 for (i
= 0; i
< ASIZE (items
); i
+= 4)
546 string
= AREF (items
, i
+ 1);
550 wv
= xmalloc_widget_value ();
551 wv
->name
= SSDATA (string
);
554 wv
->button_type
= BUTTON_TYPE_NONE
;
556 /* This prevents lwlib from assuming this
557 menu item is really supposed to be empty. */
558 /* The EMACS_INT cast avoids a warning.
559 This value just has to be different from small integers. */
560 wv
->call_data
= (void *) (EMACS_INT
) (-1);
565 first_wv
->contents
= wv
;
569 /* Forget what we thought we knew about what is in the
570 detailed contents of the menu bar menus.
571 Changing the top level always destroys the contents. */
572 f
->menu_bar_items_used
= 0;
575 /* Create or update the menu bar widget. */
581 /* Empty current menubar, rather than creating a fresh one. */
582 while (DeleteMenu (menubar_widget
, 0, MF_BYPOSITION
))
587 menubar_widget
= CreateMenu ();
589 fill_in_menu (menubar_widget
, first_wv
->contents
);
591 free_menubar_widget_value_tree (first_wv
);
594 HMENU old_widget
= f
->output_data
.w32
->menubar_widget
;
596 f
->output_data
.w32
->menubar_widget
= menubar_widget
;
597 SetMenu (FRAME_W32_WINDOW (f
), f
->output_data
.w32
->menubar_widget
);
598 /* Causes flicker when menu bar is updated
599 DrawMenuBar (FRAME_W32_WINDOW (f)); */
601 /* Force the window size to be recomputed so that the frame's text
602 area remains the same, if menubar has just been created. */
603 if (old_widget
== NULL
)
604 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
610 /* Called from Fx_create_frame to create the initial menubar of a frame
611 before it is mapped, so that the window is mapped with the menubar already
612 there instead of us tacking it on later and thrashing the window after it
616 initialize_frame_menubar (FRAME_PTR f
)
618 /* This function is called before the first chance to redisplay
619 the frame. It has to be, so the frame will have the right size. */
620 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
621 set_frame_menubar (f
, 1, 1);
624 /* Get rid of the menu bar of frame F, and free its storage.
625 This is used when deleting a frame, and when turning off the menu bar. */
628 free_frame_menubar (FRAME_PTR f
)
633 HMENU old
= GetMenu (FRAME_W32_WINDOW (f
));
634 SetMenu (FRAME_W32_WINDOW (f
), NULL
);
635 f
->output_data
.w32
->menubar_widget
= NULL
;
643 /* w32_menu_show actually displays a menu using the panes and items in
644 menu_items and returns the value selected from it; we assume input
645 is blocked by the caller. */
647 /* F is the frame the menu is for.
648 X and Y are the frame-relative specified position,
649 relative to the inside upper left corner of the frame F.
650 FOR_CLICK is nonzero if this menu was invoked for a mouse click.
651 KEYMAPS is 1 if this menu was specified with keymaps;
652 in that case, we return a list containing the chosen item's value
653 and perhaps also the pane's prefix.
654 TITLE is the specified menu title.
655 ERROR is a place to store an error message string in case of failure.
656 (We return nil on failure, but the value doesn't actually matter.) */
659 w32_menu_show (FRAME_PTR f
, int x
, int y
, int for_click
, int keymaps
,
660 Lisp_Object title
, const char **error
)
663 int menu_item_selection
;
666 widget_value
*wv
, *save_wv
= 0, *first_wv
= 0, *prev_wv
= 0;
667 widget_value
**submenu_stack
668 = (widget_value
**) alloca (menu_items_used
* sizeof (widget_value
*));
669 Lisp_Object
*subprefix_stack
670 = (Lisp_Object
*) alloca (menu_items_used
* word_size
);
671 int submenu_depth
= 0;
676 if (menu_items_n_panes
== 0)
679 if (menu_items_used
<= MENU_ITEMS_PANE_LENGTH
)
681 *error
= "Empty menu";
685 /* Create a tree of widget_value objects
686 representing the panes and their items. */
687 wv
= xmalloc_widget_value ();
691 wv
->button_type
= BUTTON_TYPE_NONE
;
696 /* Loop over all panes and items, filling in the tree. */
698 while (i
< menu_items_used
)
700 if (EQ (AREF (menu_items
, i
), Qnil
))
702 submenu_stack
[submenu_depth
++] = save_wv
;
708 else if (EQ (AREF (menu_items
, i
), Qlambda
))
711 save_wv
= submenu_stack
[--submenu_depth
];
715 else if (EQ (AREF (menu_items
, i
), Qt
)
716 && submenu_depth
!= 0)
717 i
+= MENU_ITEMS_PANE_LENGTH
;
718 /* Ignore a nil in the item list.
719 It's meaningful only for dialog boxes. */
720 else if (EQ (AREF (menu_items
, i
), Qquote
))
722 else if (EQ (AREF (menu_items
, i
), Qt
))
724 /* Create a new pane. */
725 Lisp_Object pane_name
, prefix
;
727 pane_name
= AREF (menu_items
, i
+ MENU_ITEMS_PANE_NAME
);
728 prefix
= AREF (menu_items
, i
+ MENU_ITEMS_PANE_PREFIX
);
730 if (STRINGP (pane_name
))
732 if (unicode_append_menu
)
733 pane_name
= ENCODE_UTF_8 (pane_name
);
734 else if (STRING_MULTIBYTE (pane_name
))
735 pane_name
= ENCODE_SYSTEM (pane_name
);
737 ASET (menu_items
, i
+ MENU_ITEMS_PANE_NAME
, pane_name
);
740 pane_string
= (NILP (pane_name
)
741 ? "" : SSDATA (pane_name
));
742 /* If there is just one top-level pane, put all its items directly
743 under the top-level menu. */
744 if (menu_items_n_panes
== 1)
747 /* If the pane has a meaningful name,
748 make the pane a top-level menu item
749 with its items as a submenu beneath it. */
750 if (!keymaps
&& strcmp (pane_string
, ""))
752 wv
= xmalloc_widget_value ();
756 first_wv
->contents
= wv
;
757 wv
->name
= pane_string
;
758 if (keymaps
&& !NILP (prefix
))
762 wv
->button_type
= BUTTON_TYPE_NONE
;
773 i
+= MENU_ITEMS_PANE_LENGTH
;
777 /* Create a new item within current pane. */
778 Lisp_Object item_name
, enable
, descrip
, def
, type
, selected
, help
;
780 item_name
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_NAME
);
781 enable
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_ENABLE
);
782 descrip
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_EQUIV_KEY
);
783 def
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_DEFINITION
);
784 type
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_TYPE
);
785 selected
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_SELECTED
);
786 help
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_HELP
);
788 if (STRINGP (item_name
))
790 if (unicode_append_menu
)
791 item_name
= ENCODE_UTF_8 (item_name
);
792 else if (STRING_MULTIBYTE (item_name
))
793 item_name
= ENCODE_SYSTEM (item_name
);
795 ASET (menu_items
, i
+ MENU_ITEMS_ITEM_NAME
, item_name
);
798 if (STRINGP (descrip
) && STRING_MULTIBYTE (descrip
))
800 descrip
= ENCODE_SYSTEM (descrip
);
801 ASET (menu_items
, i
+ MENU_ITEMS_ITEM_EQUIV_KEY
, descrip
);
804 wv
= xmalloc_widget_value ();
808 save_wv
->contents
= wv
;
809 wv
->name
= SSDATA (item_name
);
811 wv
->key
= SSDATA (descrip
);
813 /* Use the contents index as call_data, since we are
814 restricted to 16-bits. */
815 wv
->call_data
= !NILP (def
) ? (void *) (EMACS_INT
) i
: 0;
816 wv
->enabled
= !NILP (enable
);
819 wv
->button_type
= BUTTON_TYPE_NONE
;
820 else if (EQ (type
, QCtoggle
))
821 wv
->button_type
= BUTTON_TYPE_TOGGLE
;
822 else if (EQ (type
, QCradio
))
823 wv
->button_type
= BUTTON_TYPE_RADIO
;
827 wv
->selected
= !NILP (selected
);
836 i
+= MENU_ITEMS_ITEM_LENGTH
;
840 /* Deal with the title, if it is non-nil. */
843 widget_value
*wv_title
= xmalloc_widget_value ();
844 widget_value
*wv_sep
= xmalloc_widget_value ();
846 /* Maybe replace this separator with a bitmap or owner-draw item
847 so that it looks better. Having two separators looks odd. */
849 wv_sep
->next
= first_wv
->contents
;
852 if (unicode_append_menu
)
853 title
= ENCODE_UTF_8 (title
);
854 else if (STRING_MULTIBYTE (title
))
855 title
= ENCODE_SYSTEM (title
);
857 wv_title
->name
= SSDATA (title
);
858 wv_title
->enabled
= TRUE
;
859 wv_title
->title
= TRUE
;
860 wv_title
->button_type
= BUTTON_TYPE_NONE
;
861 wv_title
->help
= Qnil
;
862 wv_title
->next
= wv_sep
;
863 first_wv
->contents
= wv_title
;
866 /* No selection has been chosen yet. */
867 menu_item_selection
= 0;
869 /* Actually create the menu. */
870 current_popup_menu
= menu
= CreatePopupMenu ();
871 fill_in_menu (menu
, first_wv
->contents
);
873 /* Adjust coordinates to be root-window-relative. */
876 ClientToScreen (FRAME_W32_WINDOW (f
), &pos
);
878 /* Display the menu. */
879 menu_item_selection
= SendMessage (FRAME_W32_WINDOW (f
),
880 WM_EMACS_TRACKPOPUPMENU
,
881 (WPARAM
)menu
, (LPARAM
)&pos
);
883 /* Clean up extraneous mouse events which might have been generated
885 discard_mouse_events ();
886 FRAME_X_DISPLAY_INFO (f
)->grabbed
= 0;
888 /* Free the widget_value objects we used to specify the contents. */
889 free_menubar_widget_value_tree (first_wv
);
893 /* Free the owner-drawn and help-echo menu strings. */
894 w32_free_menu_strings (FRAME_W32_WINDOW (f
));
895 f
->output_data
.w32
->menubar_active
= 0;
897 /* Find the selected item, and its pane, to return
899 if (menu_item_selection
!= 0)
901 Lisp_Object prefix
, entry
;
903 prefix
= entry
= Qnil
;
905 while (i
< menu_items_used
)
907 if (EQ (AREF (menu_items
, i
), Qnil
))
909 subprefix_stack
[submenu_depth
++] = prefix
;
913 else if (EQ (AREF (menu_items
, i
), Qlambda
))
915 prefix
= subprefix_stack
[--submenu_depth
];
918 else if (EQ (AREF (menu_items
, i
), Qt
))
920 prefix
= AREF (menu_items
, i
+ MENU_ITEMS_PANE_PREFIX
);
921 i
+= MENU_ITEMS_PANE_LENGTH
;
923 /* Ignore a nil in the item list.
924 It's meaningful only for dialog boxes. */
925 else if (EQ (AREF (menu_items
, i
), Qquote
))
929 entry
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_VALUE
);
930 if (menu_item_selection
== i
)
936 entry
= Fcons (entry
, Qnil
);
938 entry
= Fcons (prefix
, entry
);
939 for (j
= submenu_depth
- 1; j
>= 0; j
--)
940 if (!NILP (subprefix_stack
[j
]))
941 entry
= Fcons (subprefix_stack
[j
], entry
);
945 i
+= MENU_ITEMS_ITEM_LENGTH
;
950 /* Make "Cancel" equivalent to C-g. */
951 Fsignal (Qquit
, Qnil
);
958 /* TODO: On Windows, there are two ways of defining a dialog.
960 1. Create a predefined dialog resource and include it in nt/emacs.rc.
961 Using this method, we could then set the titles and make unneeded
962 buttons invisible before displaying the dialog. Everything would
963 be a fixed size though, so there is a risk that text does not
965 2. Create the dialog template in memory on the fly. This allows us
966 to size the dialog and buttons dynamically, probably giving more
967 natural looking results for dialogs with few buttons, and eliminating
968 the problem of text overflowing the buttons. But the API for this is
969 quite complex - structures have to be allocated in particular ways,
970 text content is tacked onto the end of structures in variable length
971 arrays with further structures tacked on after these, there are
972 certain alignment requirements for all this, and we have to
973 measure all the text and convert to "dialog coordinates" to figure
974 out how big to make everything.
976 For now, we'll just stick with menus for dialogs that are more
977 complicated than simple yes/no type questions for which we can use
978 the MessageBox function.
981 static char * button_names
[] = {
982 "button1", "button2", "button3", "button4", "button5",
983 "button6", "button7", "button8", "button9", "button10" };
986 w32_dialog_show (FRAME_PTR f
, int keymaps
,
987 Lisp_Object title
, Lisp_Object header
,
990 int i
, nb_buttons
= 0;
992 int menu_item_selection
;
994 widget_value
*wv
, *first_wv
= 0, *prev_wv
= 0;
996 /* Number of elements seen so far, before boundary. */
998 /* 1 means we've seen the boundary between left-hand elts and right-hand. */
999 int boundary_seen
= 0;
1003 if (menu_items_n_panes
> 1)
1005 *error
= "Multiple panes in dialog box";
1009 /* Create a tree of widget_value objects
1010 representing the text label and buttons. */
1012 Lisp_Object pane_name
, prefix
;
1014 pane_name
= AREF (menu_items
, MENU_ITEMS_PANE_NAME
);
1015 prefix
= AREF (menu_items
, MENU_ITEMS_PANE_PREFIX
);
1016 pane_string
= (NILP (pane_name
)
1017 ? "" : SSDATA (pane_name
));
1018 prev_wv
= xmalloc_widget_value ();
1019 prev_wv
->value
= pane_string
;
1020 if (keymaps
&& !NILP (prefix
))
1022 prev_wv
->enabled
= 1;
1023 prev_wv
->name
= "message";
1024 prev_wv
->help
= Qnil
;
1027 /* Loop over all panes and items, filling in the tree. */
1028 i
= MENU_ITEMS_PANE_LENGTH
;
1029 while (i
< menu_items_used
)
1032 /* Create a new item within current pane. */
1033 Lisp_Object item_name
, enable
, descrip
, help
;
1035 item_name
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_NAME
);
1036 enable
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_ENABLE
);
1037 descrip
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_EQUIV_KEY
);
1038 help
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_HELP
);
1040 if (NILP (item_name
))
1042 free_menubar_widget_value_tree (first_wv
);
1043 *error
= "Submenu in dialog items";
1046 if (EQ (item_name
, Qquote
))
1048 /* This is the boundary between left-side elts
1049 and right-side elts. Stop incrementing right_count. */
1054 if (nb_buttons
>= 9)
1056 free_menubar_widget_value_tree (first_wv
);
1057 *error
= "Too many dialog items";
1061 wv
= xmalloc_widget_value ();
1063 wv
->name
= (char *) button_names
[nb_buttons
];
1064 if (!NILP (descrip
))
1065 wv
->key
= SSDATA (descrip
);
1066 wv
->value
= SSDATA (item_name
);
1067 wv
->call_data
= aref_addr (menu_items
, i
);
1068 wv
->enabled
= !NILP (enable
);
1072 if (! boundary_seen
)
1076 i
+= MENU_ITEMS_ITEM_LENGTH
;
1079 /* If the boundary was not specified,
1080 by default put half on the left and half on the right. */
1081 if (! boundary_seen
)
1082 left_count
= nb_buttons
- nb_buttons
/ 2;
1084 wv
= xmalloc_widget_value ();
1085 wv
->name
= dialog_name
;
1088 /* Frame title: 'Q' = Question, 'I' = Information.
1089 Can also have 'E' = Error if, one day, we want
1090 a popup for errors. */
1092 dialog_name
[0] = 'Q';
1094 dialog_name
[0] = 'I';
1096 /* Dialog boxes use a really stupid name encoding
1097 which specifies how many buttons to use
1098 and how many buttons are on the right. */
1099 dialog_name
[1] = '0' + nb_buttons
;
1100 dialog_name
[2] = 'B';
1101 dialog_name
[3] = 'R';
1102 /* Number of buttons to put on the right. */
1103 dialog_name
[4] = '0' + nb_buttons
- left_count
;
1105 wv
->contents
= first_wv
;
1109 /* Actually create the dialog. */
1110 dialog_id
= widget_id_tick
++;
1111 menu
= lw_create_widget (first_wv
->name
, "dialog", dialog_id
, first_wv
,
1112 f
->output_data
.w32
->widget
, 1, 0,
1113 dialog_selection_callback
, 0);
1114 lw_modify_all_widgets (dialog_id
, first_wv
->contents
, TRUE
);
1116 /* Free the widget_value objects we used to specify the contents. */
1117 free_menubar_widget_value_tree (first_wv
);
1119 /* No selection has been chosen yet. */
1120 menu_item_selection
= 0;
1122 /* Display the menu. */
1123 lw_pop_up_all_widgets (dialog_id
);
1125 /* Process events that apply to the menu. */
1126 popup_get_selection ((XEvent
*) 0, FRAME_X_DISPLAY_INFO (f
), dialog_id
);
1128 lw_destroy_all_widgets (dialog_id
);
1130 /* Find the selected item, and its pane, to return
1131 the proper value. */
1132 if (menu_item_selection
!= 0)
1138 while (i
< menu_items_used
)
1142 if (EQ (AREF (menu_items
, i
), Qt
))
1144 prefix
= AREF (menu_items
, i
+ MENU_ITEMS_PANE_PREFIX
);
1145 i
+= MENU_ITEMS_PANE_LENGTH
;
1149 entry
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_VALUE
);
1150 if (menu_item_selection
== i
)
1154 entry
= Fcons (entry
, Qnil
);
1156 entry
= Fcons (prefix
, entry
);
1160 i
+= MENU_ITEMS_ITEM_LENGTH
;
1165 /* Make "Cancel" equivalent to C-g. */
1166 Fsignal (Qquit
, Qnil
);
1170 #else /* !HAVE_DIALOGS */
1172 /* Currently we only handle Yes No dialogs (y-or-n-p and yes-or-no-p) as
1173 simple dialogs. We could handle a few more, but I'm not aware of
1174 anywhere in Emacs that uses the other specific dialog choices that
1175 MessageBox provides. */
1178 is_simple_dialog (Lisp_Object contents
)
1180 Lisp_Object options
;
1181 Lisp_Object name
, yes
, no
, other
;
1183 if (!CONSP (contents
))
1185 options
= XCDR (contents
);
1187 yes
= build_string ("Yes");
1188 no
= build_string ("No");
1190 if (!CONSP (options
))
1193 name
= XCAR (options
);
1198 if (!NILP (Fstring_equal (name
, yes
)))
1200 else if (!NILP (Fstring_equal (name
, no
)))
1205 options
= XCDR (options
);
1206 if (!CONSP (options
))
1209 name
= XCAR (options
);
1213 if (NILP (Fstring_equal (name
, other
)))
1216 /* Check there are no more options. */
1217 options
= XCDR (options
);
1218 return !(CONSP (options
));
1222 simple_dialog_show (FRAME_PTR f
, Lisp_Object contents
, Lisp_Object header
)
1226 Lisp_Object lispy_answer
= Qnil
, temp
= XCAR (contents
);
1230 /* Since we only handle Yes/No dialogs, and we already checked
1231 is_simple_dialog, we don't need to worry about checking contents
1232 to see what type of dialog to use. */
1234 /* Use Unicode if possible, so any language can be displayed. */
1235 if (unicode_message_box
)
1237 WCHAR
*text
, *title
;
1242 char *utf8_text
= SDATA (ENCODE_UTF_8 (temp
));
1243 /* Be pessimistic about the number of characters needed.
1244 Remember characters outside the BMP will take more than
1245 one utf16 word, so we cannot simply use the character
1247 int utf8_len
= strlen (utf8_text
);
1248 text
= SAFE_ALLOCA ((utf8_len
+ 1) * sizeof (WCHAR
));
1249 utf8to16 (utf8_text
, utf8_len
, text
);
1258 title
= L
"Question";
1259 type
|= MB_ICONQUESTION
;
1263 title
= L
"Information";
1264 type
|= MB_ICONINFORMATION
;
1267 answer
= unicode_message_box (FRAME_W32_WINDOW (f
), text
, title
, type
);
1274 /* Fall back on ANSI message box, but at least use system
1275 encoding so questions representable by the system codepage
1276 are encoded properly. */
1278 text
= SDATA (ENCODE_SYSTEM (temp
));
1285 type
|= MB_ICONQUESTION
;
1289 title
= "Information";
1290 type
|= MB_ICONINFORMATION
;
1293 answer
= MessageBox (FRAME_W32_WINDOW (f
), text
, title
, type
);
1296 if (answer
== IDYES
)
1297 lispy_answer
= build_string ("Yes");
1298 else if (answer
== IDNO
)
1299 lispy_answer
= build_string ("No");
1301 Fsignal (Qquit
, Qnil
);
1303 for (temp
= XCDR (contents
); CONSP (temp
); temp
= XCDR (temp
))
1305 Lisp_Object item
, name
, value
;
1310 value
= XCDR (item
);
1318 if (!NILP (Fstring_equal (name
, lispy_answer
)))
1323 Fsignal (Qquit
, Qnil
);
1326 #endif /* !HAVE_DIALOGS */
1329 /* UTF8: 0xxxxxxx, 110xxxxx 10xxxxxx, 1110xxxx, 10xxxxxx, 10xxxxxx */
1331 utf8to16 (unsigned char * src
, int len
, WCHAR
* dest
)
1337 *dest
= (WCHAR
) *src
;
1338 dest
++; src
++; len
--;
1340 /* Since we might get >3 byte sequences which we don't handle, ignore the extra parts. */
1341 else if (*src
< 0xC0)
1345 /* 2 char UTF-8 sequence. */
1346 else if (*src
< 0xE0)
1348 *dest
= (WCHAR
) (((*src
& 0x1f) << 6)
1349 | (*(src
+ 1) & 0x3f));
1350 src
+= 2; len
-= 2; dest
++;
1352 else if (*src
< 0xF0)
1354 *dest
= (WCHAR
) (((*src
& 0x0f) << 12)
1355 | ((*(src
+ 1) & 0x3f) << 6)
1356 | (*(src
+ 2) & 0x3f));
1357 src
+= 3; len
-= 3; dest
++;
1359 else /* Not encodable. Insert Unicode Substitution char. */
1361 *dest
= (WCHAR
) 0xfffd;
1362 src
++; len
--; dest
++;
1369 add_menu_item (HMENU menu
, widget_value
*wv
, HMENU item
)
1372 char *out_string
, *p
, *q
;
1374 size_t nlen
, orig_len
;
1377 if (menu_separator_name_p (wv
->name
))
1379 fuFlags
= MF_SEPARATOR
;
1385 fuFlags
= MF_STRING
;
1387 fuFlags
= MF_STRING
| MF_GRAYED
;
1389 if (wv
->key
!= NULL
)
1391 out_string
= SAFE_ALLOCA (strlen (wv
->name
) + strlen (wv
->key
) + 2);
1392 strcpy (out_string
, wv
->name
);
1393 strcat (out_string
, "\t");
1394 strcat (out_string
, wv
->key
);
1397 out_string
= (char *)wv
->name
;
1399 /* Quote any special characters within the menu item's text and
1401 nlen
= orig_len
= strlen (out_string
);
1402 if (unicode_append_menu
)
1404 /* With UTF-8, & cannot be part of a multibyte character. */
1405 for (p
= out_string
; *p
; p
++)
1411 #ifndef NTGUI_UNICODE
1414 /* If encoded with the system codepage, use multibyte string
1415 functions in case of multibyte characters that contain '&'. */
1416 for (p
= out_string
; *p
; p
= _mbsinc (p
))
1418 if (_mbsnextc (p
) == '&')
1422 #endif /* !NTGUI_UNICODE */
1424 if (nlen
> orig_len
)
1427 out_string
= SAFE_ALLOCA (nlen
+ 1);
1431 if (unicode_append_menu
)
1437 #ifndef NTGUI_UNICODE
1440 if (_mbsnextc (p
) == '&')
1449 #endif /* !NTGUI_UNICODE */
1456 else if (wv
->title
|| wv
->call_data
== 0)
1458 /* Only use MF_OWNERDRAW if GetMenuItemInfo is usable, since
1459 we can't deallocate the memory otherwise. */
1460 if (get_menu_item_info
)
1462 out_string
= (char *) local_alloc (strlen (wv
->name
) + 1);
1463 strcpy (out_string
, wv
->name
);
1465 DebPrint ("Menu: allocating %ld for owner-draw", out_string
);
1467 fuFlags
= MF_OWNERDRAW
| MF_DISABLED
;
1470 fuFlags
= MF_DISABLED
;
1473 /* Draw radio buttons and tickboxes. */
1474 else if (wv
->selected
&& (wv
->button_type
== BUTTON_TYPE_TOGGLE
||
1475 wv
->button_type
== BUTTON_TYPE_RADIO
))
1476 fuFlags
|= MF_CHECKED
;
1478 fuFlags
|= MF_UNCHECKED
;
1481 if (unicode_append_menu
&& out_string
)
1483 /* Convert out_string from UTF-8 to UTF-16-LE. */
1484 int utf8_len
= strlen (out_string
);
1485 WCHAR
* utf16_string
;
1486 if (fuFlags
& MF_OWNERDRAW
)
1487 utf16_string
= local_alloc ((utf8_len
+ 1) * sizeof (WCHAR
));
1489 utf16_string
= SAFE_ALLOCA ((utf8_len
+ 1) * sizeof (WCHAR
));
1491 utf8to16 (out_string
, utf8_len
, utf16_string
);
1492 return_value
= unicode_append_menu (menu
, fuFlags
,
1493 item
!= NULL
? (UINT_PTR
) item
1494 : (UINT_PTR
) wv
->call_data
,
1497 #ifndef NTGUI_UNICODE /* Fallback does not apply when always UNICODE */
1500 /* On W9x/ME, Unicode menus are not supported, though AppendMenuW
1501 apparently does exist at least in some cases and appears to be
1502 stubbed out to do nothing. out_string is UTF-8, but since
1503 our standard menus are in English and this is only going to
1504 happen the first time a menu is used, the encoding is
1505 of minor importance compared with menus not working at all. */
1507 AppendMenu (menu
, fuFlags
,
1508 item
!= NULL
? (UINT_PTR
) item
: (UINT_PTR
) wv
->call_data
,
1510 /* Don't use Unicode menus in future, unless this is Windows
1511 NT or later, where a failure of AppendMenuW does NOT mean
1512 Unicode menus are unsupported. */
1513 if (osinfo_cache
.dwPlatformId
!= VER_PLATFORM_WIN32_NT
)
1514 unicode_append_menu
= NULL
;
1516 #endif /* NTGUI_UNICODE */
1518 if (unicode_append_menu
&& (fuFlags
& MF_OWNERDRAW
))
1519 local_free (out_string
);
1526 item
!= NULL
? (UINT_PTR
) item
: (UINT_PTR
) wv
->call_data
,
1530 /* This must be done after the menu item is created. */
1531 if (!wv
->title
&& wv
->call_data
!= 0)
1533 if (set_menu_item_info
)
1536 memset (&info
, 0, sizeof (info
));
1537 info
.cbSize
= sizeof (info
);
1538 info
.fMask
= MIIM_DATA
;
1540 /* Set help string for menu item. Leave it as a Lisp_Object
1541 until it is ready to be displayed, since GC can happen while
1542 menus are active. */
1543 if (!NILP (wv
->help
))
1545 /* As of Jul-2012, w32api headers say that dwItemData
1546 has DWORD type, but that's a bug: it should actually
1547 be ULONG_PTR, which is correct for 32-bit and 64-bit
1548 Windows alike. MSVC headers get it right; hopefully,
1549 MinGW headers will, too. */
1550 info
.dwItemData
= (ULONG_PTR
) XLI (wv
->help
);
1552 if (wv
->button_type
== BUTTON_TYPE_RADIO
)
1554 /* CheckMenuRadioItem allows us to differentiate TOGGLE and
1555 RADIO items, but is not available on NT 3.51 and earlier. */
1556 info
.fMask
|= MIIM_TYPE
| MIIM_STATE
;
1557 info
.fType
= MFT_RADIOCHECK
| MFT_STRING
;
1558 info
.dwTypeData
= out_string
;
1559 info
.fState
= wv
->selected
? MFS_CHECKED
: MFS_UNCHECKED
;
1562 set_menu_item_info (menu
,
1563 item
!= NULL
? (UINT_PTR
) item
: (UINT_PTR
) wv
->call_data
,
1568 return return_value
;
1571 /* Construct native Windows menu(bar) based on widget_value tree. */
1573 fill_in_menu (HMENU menu
, widget_value
*wv
)
1575 for ( ; wv
!= NULL
; wv
= wv
->next
)
1579 HMENU sub_menu
= CreatePopupMenu ();
1581 if (sub_menu
== NULL
)
1584 if (!fill_in_menu (sub_menu
, wv
->contents
) ||
1585 !add_menu_item (menu
, wv
, sub_menu
))
1587 DestroyMenu (sub_menu
);
1593 if (!add_menu_item (menu
, wv
, NULL
))
1600 /* Display help string for currently pointed to menu item. Not
1601 supported on NT 3.51 and earlier, as GetMenuItemInfo is not
1604 w32_menu_display_help (HWND owner
, HMENU menu
, UINT item
, UINT flags
)
1606 if (get_menu_item_info
)
1608 struct frame
*f
= x_window_to_frame (&one_w32_display_info
, owner
);
1609 Lisp_Object frame
, help
;
1611 /* No help echo on owner-draw menu items, or when the keyboard is used
1612 to navigate the menus, since tooltips are distracting if they pop
1614 if (flags
& MF_OWNERDRAW
|| flags
& MF_POPUP
1615 || !(flags
& MF_MOUSESELECT
))
1621 memset (&info
, 0, sizeof (info
));
1622 info
.cbSize
= sizeof (info
);
1623 info
.fMask
= MIIM_DATA
;
1624 get_menu_item_info (menu
, item
, FALSE
, &info
);
1626 help
= info
.dwItemData
? XIL (info
.dwItemData
) : Qnil
;
1629 /* Store the help echo in the keyboard buffer as the X toolkit
1630 version does, rather than directly showing it. This seems to
1631 solve the GC problems that were present when we based the
1632 Windows code on the non-toolkit version. */
1635 XSETFRAME (frame
, f
);
1636 kbd_buffer_store_help_event (frame
, help
);
1639 /* X version has a loop through frames here, which doesn't
1640 appear to do anything, unless it has some side effect. */
1641 show_help_echo (help
, Qnil
, Qnil
, Qnil
);
1645 /* Free memory used by owner-drawn strings. */
1647 w32_free_submenu_strings (HMENU menu
)
1649 int i
, num
= GetMenuItemCount (menu
);
1650 for (i
= 0; i
< num
; i
++)
1653 memset (&info
, 0, sizeof (info
));
1654 info
.cbSize
= sizeof (info
);
1655 info
.fMask
= MIIM_DATA
| MIIM_TYPE
| MIIM_SUBMENU
;
1657 get_menu_item_info (menu
, i
, TRUE
, &info
);
1659 /* Owner-drawn names are held in dwItemData. */
1660 if ((info
.fType
& MF_OWNERDRAW
) && info
.dwItemData
)
1663 DebPrint ("Menu: freeing %ld for owner-draw", info
.dwItemData
);
1665 local_free (info
.dwItemData
);
1668 /* Recurse down submenus. */
1670 w32_free_submenu_strings (info
.hSubMenu
);
1675 w32_free_menu_strings (HWND hwnd
)
1677 HMENU menu
= current_popup_menu
;
1679 if (get_menu_item_info
)
1681 /* If there is no popup menu active, free the strings from the frame's
1684 menu
= GetMenu (hwnd
);
1687 w32_free_submenu_strings (menu
);
1690 current_popup_menu
= NULL
;
1693 #endif /* HAVE_MENUS */
1695 /* The following is used by delayed window autoselection. */
1697 DEFUN ("menu-or-popup-active-p", Fmenu_or_popup_active_p
, Smenu_or_popup_active_p
, 0, 0, 0,
1698 doc
: /* Return t if a menu or popup dialog is active on selected frame. */)
1703 f
= SELECTED_FRAME ();
1704 return (f
->output_data
.w32
->menubar_active
> 0) ? Qt
: Qnil
;
1707 #endif /* HAVE_MENUS */
1711 syms_of_w32menu (void)
1713 globals_of_w32menu ();
1715 current_popup_menu
= NULL
;
1717 DEFSYM (Qdebug_on_next_call
, "debug-on-next-call");
1719 defsubr (&Smenu_or_popup_active_p
);
1721 defsubr (&Sx_popup_dialog
);
1726 globals_of_w32menu is used to initialize those global variables that
1727 must always be initialized on startup even when the global variable
1728 initialized is non zero (see the function main in emacs.c).
1729 globals_of_w32menu is called from syms_of_w32menu when the global
1730 variable initialized is 0 and directly from main when initialized
1734 globals_of_w32menu (void)
1736 #ifndef NTGUI_UNICODE
1737 /* See if Get/SetMenuItemInfo functions are available. */
1738 HMODULE user32
= GetModuleHandle ("user32.dll");
1739 get_menu_item_info
= (GetMenuItemInfoA_Proc
) GetProcAddress (user32
, "GetMenuItemInfoA");
1740 set_menu_item_info
= (SetMenuItemInfoA_Proc
) GetProcAddress (user32
, "SetMenuItemInfoA");
1741 unicode_append_menu
= (AppendMenuW_Proc
) GetProcAddress (user32
, "AppendMenuW");
1742 unicode_message_box
= (MessageBoxW_Proc
) GetProcAddress (user32
, "MessageBoxW");
1743 #endif /* !NTGUI_UNICODE */