1 /* Menu support for GNU Emacs on the Microsoft W32 API.
2 Copyright (C) 1986, 1988, 1993-1994, 1996, 1998-1999, 2001-2011
3 Free 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/>. */
31 #include "termhooks.h"
33 #include "blockinput.h"
36 #include "character.h"
40 /* This may include sys/types.h, and that somehow loses
41 if this is not done before the other system files. */
44 /* Load sys/types.h if not already loaded.
45 In some systems loading it twice is suicidal. */
47 #include <sys/types.h>
50 #include "dispextern.h"
52 #undef HAVE_DIALOGS /* TODO: Implement native dialogs. */
59 HMENU current_popup_menu
;
61 void syms_of_w32menu (void);
62 void globals_of_w32menu (void);
64 typedef BOOL (WINAPI
* GetMenuItemInfoA_Proc
) (
68 IN OUT LPMENUITEMINFOA
);
69 typedef BOOL (WINAPI
* SetMenuItemInfoA_Proc
) (
74 typedef int (WINAPI
* MessageBoxW_Proc
) (
80 GetMenuItemInfoA_Proc get_menu_item_info
= NULL
;
81 SetMenuItemInfoA_Proc set_menu_item_info
= NULL
;
82 AppendMenuW_Proc unicode_append_menu
= NULL
;
83 MessageBoxW_Proc unicode_message_box
= NULL
;
85 Lisp_Object Qdebug_on_next_call
;
87 extern Lisp_Object Qmenu_bar
;
89 extern Lisp_Object QCtoggle
, QCradio
;
91 extern Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
93 extern Lisp_Object Qmenu_bar_update_hook
;
95 void set_frame_menubar (FRAME_PTR
, int, int);
98 static Lisp_Object
w32_dialog_show (FRAME_PTR
, int, Lisp_Object
, char**);
100 static int is_simple_dialog (Lisp_Object
);
101 static Lisp_Object
simple_dialog_show (FRAME_PTR
, Lisp_Object
, Lisp_Object
);
104 static void utf8to16 (unsigned char *, int, WCHAR
*);
105 static int fill_in_menu (HMENU
, widget_value
*);
107 void w32_free_menu_strings (HWND
);
110 /* This is set nonzero after the user activates the menu bar, and set
111 to zero again after the menu bars are redisplayed by prepare_menu_bar.
112 While it is nonzero, all calls to set_frame_menubar go deep.
114 I don't understand why this is needed, but it does seem to be
115 needed on Motif, according to Marcus Daniels <marcus@sysc.pdx.edu>. */
117 int pending_menu_activation
;
121 DEFUN ("x-popup-dialog", Fx_popup_dialog
, Sx_popup_dialog
, 2, 3, 0,
122 doc
: /* Pop up a dialog box and return user's selection.
123 POSITION specifies which frame to use.
124 This is normally a mouse button event or a window or frame.
125 If POSITION is t, it means to use the frame the mouse is on.
126 The dialog box appears in the middle of the specified frame.
128 CONTENTS specifies the alternatives to display in the dialog box.
129 It is a list of the form (TITLE ITEM1 ITEM2...).
130 Each ITEM is a cons cell (STRING . VALUE).
131 The return value is VALUE from the chosen item.
133 An ITEM may also be just a string--that makes a nonselectable item.
134 An ITEM may also be nil--that means to put all preceding items
135 on the left of the dialog box and all following items on the right.
136 \(By default, approximately half appear on each side.)
138 If HEADER is non-nil, the frame title for the box is "Information",
139 otherwise it is "Question". */)
140 (Lisp_Object position
, Lisp_Object contents
, Lisp_Object header
)
147 /* Decode the first argument: find the window or frame to use. */
148 if (EQ (position
, Qt
)
149 || (CONSP (position
) && (EQ (XCAR (position
), Qmenu_bar
)
150 || EQ (XCAR (position
), Qtool_bar
))))
152 #if 0 /* Using the frame the mouse is on may not be right. */
153 /* Use the mouse's current position. */
154 FRAME_PTR new_f
= SELECTED_FRAME ();
155 Lisp_Object bar_window
;
156 enum scroll_bar_part part
;
160 (*mouse_position_hook
) (&new_f
, 1, &bar_window
, &part
, &x
, &y
, &time
);
163 XSETFRAME (window
, new_f
);
165 window
= selected_window
;
167 window
= selected_window
;
169 else if (CONSP (position
))
172 tem
= Fcar (position
);
174 window
= Fcar (Fcdr (position
));
177 tem
= Fcar (Fcdr (position
)); /* EVENT_START (position) */
178 window
= Fcar (tem
); /* POSN_WINDOW (tem) */
181 else if (WINDOWP (position
) || FRAMEP (position
))
186 /* Decode where to put the menu. */
190 else if (WINDOWP (window
))
192 CHECK_LIVE_WINDOW (window
);
193 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
196 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
197 but I don't want to make one now. */
198 CHECK_WINDOW (window
);
203 /* Handle simple Yes/No choices as MessageBox popups. */
204 if (is_simple_dialog (contents
))
205 return simple_dialog_show (f
, contents
, header
);
208 /* Display a menu with these alternatives
209 in the middle of frame F. */
210 Lisp_Object x
, y
, frame
, newpos
;
211 XSETFRAME (frame
, f
);
212 XSETINT (x
, x_pixel_width (f
) / 2);
213 XSETINT (y
, x_pixel_height (f
) / 2);
214 newpos
= Fcons (Fcons (x
, Fcons (y
, Qnil
)), Fcons (frame
, Qnil
));
215 return Fx_popup_menu (newpos
,
216 Fcons (Fcar (contents
), Fcons (contents
, Qnil
)));
219 #else /* HAVE_DIALOGS */
223 Lisp_Object selection
;
225 /* Decode the dialog items from what was specified. */
226 title
= Fcar (contents
);
227 CHECK_STRING (title
);
229 list_of_panes (Fcons (contents
, Qnil
));
231 /* Display them in a dialog box. */
233 selection
= w32_dialog_show (f
, 0, title
, header
, &error_name
);
236 discard_menu_items ();
237 FRAME_X_DISPLAY_INFO (f
)->grabbed
= 0;
239 if (error_name
) error (error_name
);
242 #endif /* HAVE_DIALOGS */
245 /* Activate the menu bar of frame F.
246 This is called from keyboard.c when it gets the
247 MENU_BAR_ACTIVATE_EVENT out of the Emacs event queue.
249 To activate the menu bar, we signal to the input thread that it can
250 return from the WM_INITMENU message, allowing the normal Windows
251 processing of the menus.
253 But first we recompute the menu bar contents (the whole tree).
255 This way we can safely execute Lisp code. */
258 x_activate_menubar (FRAME_PTR f
)
260 set_frame_menubar (f
, 0, 1);
262 /* Lock out further menubar changes while active. */
263 f
->output_data
.w32
->menubar_active
= 1;
265 /* Signal input thread to return from WM_INITMENU. */
266 complete_deferred_msg (FRAME_W32_WINDOW (f
), WM_INITMENU
, 0);
269 /* This callback is called from the menu bar pulldown menu
270 when the user makes a selection.
271 Figure out what the user chose
272 and put the appropriate events into the keyboard buffer. */
275 menubar_selection_callback (FRAME_PTR f
, void * client_data
)
277 Lisp_Object prefix
, entry
;
279 Lisp_Object
*subprefix_stack
;
280 int submenu_depth
= 0;
286 subprefix_stack
= (Lisp_Object
*) alloca (f
->menu_bar_items_used
* sizeof (Lisp_Object
));
287 vector
= f
->menu_bar_vector
;
290 while (i
< f
->menu_bar_items_used
)
292 if (EQ (AREF (vector
, i
), Qnil
))
294 subprefix_stack
[submenu_depth
++] = prefix
;
298 else if (EQ (AREF (vector
, i
), Qlambda
))
300 prefix
= subprefix_stack
[--submenu_depth
];
303 else if (EQ (AREF (vector
, i
), Qt
))
305 prefix
= AREF (vector
, i
+ MENU_ITEMS_PANE_PREFIX
);
306 i
+= MENU_ITEMS_PANE_LENGTH
;
310 entry
= AREF (vector
, i
+ MENU_ITEMS_ITEM_VALUE
);
311 /* The EMACS_INT cast avoids a warning. There's no problem
312 as long as pointers have enough bits to hold small integers. */
313 if ((int) (EMACS_INT
) client_data
== i
)
316 struct input_event buf
;
320 XSETFRAME (frame
, f
);
321 buf
.kind
= MENU_BAR_EVENT
;
322 buf
.frame_or_window
= frame
;
324 kbd_buffer_store_event (&buf
);
326 for (j
= 0; j
< submenu_depth
; j
++)
327 if (!NILP (subprefix_stack
[j
]))
329 buf
.kind
= MENU_BAR_EVENT
;
330 buf
.frame_or_window
= frame
;
331 buf
.arg
= subprefix_stack
[j
];
332 kbd_buffer_store_event (&buf
);
337 buf
.kind
= MENU_BAR_EVENT
;
338 buf
.frame_or_window
= frame
;
340 kbd_buffer_store_event (&buf
);
343 buf
.kind
= MENU_BAR_EVENT
;
344 buf
.frame_or_window
= frame
;
346 /* Free memory used by owner-drawn and help-echo strings. */
347 w32_free_menu_strings (FRAME_W32_WINDOW (f
));
348 kbd_buffer_store_event (&buf
);
350 f
->output_data
.w32
->menubar_active
= 0;
353 i
+= MENU_ITEMS_ITEM_LENGTH
;
356 /* Free memory used by owner-drawn and help-echo strings. */
357 w32_free_menu_strings (FRAME_W32_WINDOW (f
));
358 f
->output_data
.w32
->menubar_active
= 0;
362 /* Set the contents of the menubar widgets of frame F.
363 The argument FIRST_TIME is currently ignored;
364 it is set the first time this is called, from initialize_frame_menubar. */
367 set_frame_menubar (FRAME_PTR f
, int first_time
, int deep_p
)
369 HMENU menubar_widget
= f
->output_data
.w32
->menubar_widget
;
371 widget_value
*wv
, *first_wv
, *prev_wv
= 0;
373 int *submenu_start
, *submenu_end
;
374 int *submenu_top_level_items
, *submenu_n_panes
;
376 /* We must not change the menubar when actually in use. */
377 if (f
->output_data
.w32
->menubar_active
)
380 XSETFRAME (Vmenu_updating_frame
, f
);
382 if (! menubar_widget
)
384 else if (pending_menu_activation
&& !deep_p
)
389 /* Make a widget-value tree representing the entire menu trees. */
391 struct buffer
*prev
= current_buffer
;
393 int specpdl_count
= SPECPDL_INDEX ();
394 int previous_menu_items_used
= f
->menu_bar_items_used
;
395 Lisp_Object
*previous_items
396 = (Lisp_Object
*) alloca (previous_menu_items_used
397 * sizeof (Lisp_Object
));
399 /* If we are making a new widget, its contents are empty,
400 do always reinitialize them. */
401 if (! menubar_widget
)
402 previous_menu_items_used
= 0;
404 buffer
= XWINDOW (FRAME_SELECTED_WINDOW (f
))->buffer
;
405 specbind (Qinhibit_quit
, Qt
);
406 /* Don't let the debugger step into this code
407 because it is not reentrant. */
408 specbind (Qdebug_on_next_call
, Qnil
);
410 record_unwind_save_match_data ();
412 if (NILP (Voverriding_local_map_menu_flag
))
414 specbind (Qoverriding_terminal_local_map
, Qnil
);
415 specbind (Qoverriding_local_map
, Qnil
);
418 set_buffer_internal_1 (XBUFFER (buffer
));
421 safe_run_hooks (Qactivate_menubar_hook
);
422 safe_run_hooks (Qmenu_bar_update_hook
);
423 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
425 items
= FRAME_MENU_BAR_ITEMS (f
);
427 /* Save the frame's previous menu bar contents data. */
428 if (previous_menu_items_used
)
429 memcpy (previous_items
, XVECTOR (f
->menu_bar_vector
)->contents
,
430 previous_menu_items_used
* sizeof (Lisp_Object
));
432 /* Fill in menu_items with the current menu bar contents.
433 This can evaluate Lisp code. */
436 menu_items
= f
->menu_bar_vector
;
437 menu_items_allocated
= VECTORP (menu_items
) ? ASIZE (menu_items
) : 0;
438 submenu_start
= (int *) alloca (XVECTOR (items
)->size
* sizeof (int *));
439 submenu_end
= (int *) alloca (XVECTOR (items
)->size
* sizeof (int *));
440 submenu_n_panes
= (int *) alloca (XVECTOR (items
)->size
* sizeof (int));
441 submenu_top_level_items
442 = (int *) alloca (XVECTOR (items
)->size
* sizeof (int *));
444 for (i
= 0; i
< ASIZE (items
); i
+= 4)
446 Lisp_Object key
, string
, maps
;
450 key
= AREF (items
, i
);
451 string
= AREF (items
, i
+ 1);
452 maps
= AREF (items
, i
+ 2);
456 submenu_start
[i
] = menu_items_used
;
458 menu_items_n_panes
= 0;
459 submenu_top_level_items
[i
]
460 = parse_single_submenu (key
, string
, maps
);
461 submenu_n_panes
[i
] = menu_items_n_panes
;
463 submenu_end
[i
] = menu_items_used
;
466 finish_menu_items ();
468 /* Convert menu_items into widget_value trees
469 to display the menu. This cannot evaluate Lisp code. */
471 wv
= xmalloc_widget_value ();
472 wv
->name
= "menubar";
475 wv
->button_type
= BUTTON_TYPE_NONE
;
479 for (i
= 0; i
< last_i
; i
+= 4)
481 menu_items_n_panes
= submenu_n_panes
[i
];
482 wv
= digest_single_submenu (submenu_start
[i
], submenu_end
[i
],
483 submenu_top_level_items
[i
]);
487 first_wv
->contents
= wv
;
488 /* Don't set wv->name here; GC during the loop might relocate it. */
490 wv
->button_type
= BUTTON_TYPE_NONE
;
494 set_buffer_internal_1 (prev
);
496 /* If there has been no change in the Lisp-level contents
497 of the menu bar, skip redisplaying it. Just exit. */
499 for (i
= 0; i
< previous_menu_items_used
; i
++)
500 if (menu_items_used
== i
501 || (!EQ (previous_items
[i
], AREF (menu_items
, i
))))
503 if (i
== menu_items_used
&& i
== previous_menu_items_used
&& i
!= 0)
505 free_menubar_widget_value_tree (first_wv
);
506 discard_menu_items ();
507 unbind_to (specpdl_count
, Qnil
);
511 f
->menu_bar_vector
= menu_items
;
512 f
->menu_bar_items_used
= menu_items_used
;
514 /* This undoes save_menu_items. */
515 unbind_to (specpdl_count
, Qnil
);
517 /* Now GC cannot happen during the lifetime of the widget_value,
518 so it's safe to store data from a Lisp_String, as long as
519 local copies are made when the actual menu is created.
520 Windows takes care of this for normal string items, but
521 not for owner-drawn items or additional item-info. */
522 wv
= first_wv
->contents
;
523 for (i
= 0; i
< ASIZE (items
); i
+= 4)
526 string
= AREF (items
, i
+ 1);
529 wv
->name
= SSDATA (string
);
530 update_submenu_strings (wv
->contents
);
536 /* Make a widget-value tree containing
537 just the top level menu bar strings. */
539 wv
= xmalloc_widget_value ();
540 wv
->name
= "menubar";
543 wv
->button_type
= BUTTON_TYPE_NONE
;
547 items
= FRAME_MENU_BAR_ITEMS (f
);
548 for (i
= 0; i
< ASIZE (items
); i
+= 4)
552 string
= AREF (items
, i
+ 1);
556 wv
= xmalloc_widget_value ();
557 wv
->name
= SSDATA (string
);
560 wv
->button_type
= BUTTON_TYPE_NONE
;
562 /* This prevents lwlib from assuming this
563 menu item is really supposed to be empty. */
564 /* The EMACS_INT cast avoids a warning.
565 This value just has to be different from small integers. */
566 wv
->call_data
= (void *) (EMACS_INT
) (-1);
571 first_wv
->contents
= wv
;
575 /* Forget what we thought we knew about what is in the
576 detailed contents of the menu bar menus.
577 Changing the top level always destroys the contents. */
578 f
->menu_bar_items_used
= 0;
581 /* Create or update the menu bar widget. */
587 /* Empty current menubar, rather than creating a fresh one. */
588 while (DeleteMenu (menubar_widget
, 0, MF_BYPOSITION
))
593 menubar_widget
= CreateMenu ();
595 fill_in_menu (menubar_widget
, first_wv
->contents
);
597 free_menubar_widget_value_tree (first_wv
);
600 HMENU old_widget
= f
->output_data
.w32
->menubar_widget
;
602 f
->output_data
.w32
->menubar_widget
= menubar_widget
;
603 SetMenu (FRAME_W32_WINDOW (f
), f
->output_data
.w32
->menubar_widget
);
604 /* Causes flicker when menu bar is updated
605 DrawMenuBar (FRAME_W32_WINDOW (f)); */
607 /* Force the window size to be recomputed so that the frame's text
608 area remains the same, if menubar has just been created. */
609 if (old_widget
== NULL
)
610 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
616 /* Called from Fx_create_frame to create the initial menubar of a frame
617 before it is mapped, so that the window is mapped with the menubar already
618 there instead of us tacking it on later and thrashing the window after it
622 initialize_frame_menubar (FRAME_PTR f
)
624 /* This function is called before the first chance to redisplay
625 the frame. It has to be, so the frame will have the right size. */
626 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
627 set_frame_menubar (f
, 1, 1);
630 /* Get rid of the menu bar of frame F, and free its storage.
631 This is used when deleting a frame, and when turning off the menu bar. */
634 free_frame_menubar (FRAME_PTR f
)
639 HMENU old
= GetMenu (FRAME_W32_WINDOW (f
));
640 SetMenu (FRAME_W32_WINDOW (f
), NULL
);
641 f
->output_data
.w32
->menubar_widget
= NULL
;
649 /* w32_menu_show actually displays a menu using the panes and items in
650 menu_items and returns the value selected from it; we assume input
651 is blocked by the caller. */
653 /* F is the frame the menu is for.
654 X and Y are the frame-relative specified position,
655 relative to the inside upper left corner of the frame F.
656 FOR_CLICK is nonzero if this menu was invoked for a mouse click.
657 KEYMAPS is 1 if this menu was specified with keymaps;
658 in that case, we return a list containing the chosen item's value
659 and perhaps also the pane's prefix.
660 TITLE is the specified menu title.
661 ERROR is a place to store an error message string in case of failure.
662 (We return nil on failure, but the value doesn't actually matter.) */
665 w32_menu_show (FRAME_PTR f
, int x
, int y
, int for_click
, int keymaps
,
666 Lisp_Object title
, const char **error
)
669 int menu_item_selection
;
672 widget_value
*wv
, *save_wv
= 0, *first_wv
= 0, *prev_wv
= 0;
673 widget_value
**submenu_stack
674 = (widget_value
**) alloca (menu_items_used
* sizeof (widget_value
*));
675 Lisp_Object
*subprefix_stack
676 = (Lisp_Object
*) alloca (menu_items_used
* sizeof (Lisp_Object
));
677 int submenu_depth
= 0;
682 if (menu_items_n_panes
== 0)
685 if (menu_items_used
<= MENU_ITEMS_PANE_LENGTH
)
687 *error
= "Empty menu";
691 /* Create a tree of widget_value objects
692 representing the panes and their items. */
693 wv
= xmalloc_widget_value ();
697 wv
->button_type
= BUTTON_TYPE_NONE
;
702 /* Loop over all panes and items, filling in the tree. */
704 while (i
< menu_items_used
)
706 if (EQ (AREF (menu_items
, i
), Qnil
))
708 submenu_stack
[submenu_depth
++] = save_wv
;
714 else if (EQ (AREF (menu_items
, i
), Qlambda
))
717 save_wv
= submenu_stack
[--submenu_depth
];
721 else if (EQ (AREF (menu_items
, i
), Qt
)
722 && submenu_depth
!= 0)
723 i
+= MENU_ITEMS_PANE_LENGTH
;
724 /* Ignore a nil in the item list.
725 It's meaningful only for dialog boxes. */
726 else if (EQ (AREF (menu_items
, i
), Qquote
))
728 else if (EQ (AREF (menu_items
, i
), Qt
))
730 /* Create a new pane. */
731 Lisp_Object pane_name
, prefix
;
733 pane_name
= AREF (menu_items
, i
+ MENU_ITEMS_PANE_NAME
);
734 prefix
= AREF (menu_items
, i
+ MENU_ITEMS_PANE_PREFIX
);
736 if (STRINGP (pane_name
))
738 if (unicode_append_menu
)
739 pane_name
= ENCODE_UTF_8 (pane_name
);
740 else if (STRING_MULTIBYTE (pane_name
))
741 pane_name
= ENCODE_SYSTEM (pane_name
);
743 ASET (menu_items
, i
+ MENU_ITEMS_PANE_NAME
, pane_name
);
746 pane_string
= (NILP (pane_name
)
747 ? "" : SSDATA (pane_name
));
748 /* If there is just one top-level pane, put all its items directly
749 under the top-level menu. */
750 if (menu_items_n_panes
== 1)
753 /* If the pane has a meaningful name,
754 make the pane a top-level menu item
755 with its items as a submenu beneath it. */
756 if (!keymaps
&& strcmp (pane_string
, ""))
758 wv
= xmalloc_widget_value ();
762 first_wv
->contents
= wv
;
763 wv
->name
= pane_string
;
764 if (keymaps
&& !NILP (prefix
))
768 wv
->button_type
= BUTTON_TYPE_NONE
;
779 i
+= MENU_ITEMS_PANE_LENGTH
;
783 /* Create a new item within current pane. */
784 Lisp_Object item_name
, enable
, descrip
, def
, type
, selected
, help
;
786 item_name
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_NAME
);
787 enable
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_ENABLE
);
788 descrip
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_EQUIV_KEY
);
789 def
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_DEFINITION
);
790 type
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_TYPE
);
791 selected
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_SELECTED
);
792 help
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_HELP
);
794 if (STRINGP (item_name
))
796 if (unicode_append_menu
)
797 item_name
= ENCODE_UTF_8 (item_name
);
798 else if (STRING_MULTIBYTE (item_name
))
799 item_name
= ENCODE_SYSTEM (item_name
);
801 ASET (menu_items
, i
+ MENU_ITEMS_ITEM_NAME
, item_name
);
804 if (STRINGP (descrip
) && STRING_MULTIBYTE (descrip
))
806 descrip
= ENCODE_SYSTEM (descrip
);
807 ASET (menu_items
, i
+ MENU_ITEMS_ITEM_EQUIV_KEY
, descrip
);
810 wv
= xmalloc_widget_value ();
814 save_wv
->contents
= wv
;
815 wv
->name
= SSDATA (item_name
);
817 wv
->key
= SSDATA (descrip
);
819 /* Use the contents index as call_data, since we are
820 restricted to 16-bits. */
821 wv
->call_data
= !NILP (def
) ? (void *) (EMACS_INT
) i
: 0;
822 wv
->enabled
= !NILP (enable
);
825 wv
->button_type
= BUTTON_TYPE_NONE
;
826 else if (EQ (type
, QCtoggle
))
827 wv
->button_type
= BUTTON_TYPE_TOGGLE
;
828 else if (EQ (type
, QCradio
))
829 wv
->button_type
= BUTTON_TYPE_RADIO
;
833 wv
->selected
= !NILP (selected
);
842 i
+= MENU_ITEMS_ITEM_LENGTH
;
846 /* Deal with the title, if it is non-nil. */
849 widget_value
*wv_title
= xmalloc_widget_value ();
850 widget_value
*wv_sep
= xmalloc_widget_value ();
852 /* Maybe replace this separator with a bitmap or owner-draw item
853 so that it looks better. Having two separators looks odd. */
855 wv_sep
->next
= first_wv
->contents
;
858 if (unicode_append_menu
)
859 title
= ENCODE_UTF_8 (title
);
860 else if (STRING_MULTIBYTE (title
))
861 title
= ENCODE_SYSTEM (title
);
863 wv_title
->name
= SSDATA (title
);
864 wv_title
->enabled
= TRUE
;
865 wv_title
->title
= TRUE
;
866 wv_title
->button_type
= BUTTON_TYPE_NONE
;
867 wv_title
->help
= Qnil
;
868 wv_title
->next
= wv_sep
;
869 first_wv
->contents
= wv_title
;
872 /* No selection has been chosen yet. */
873 menu_item_selection
= 0;
875 /* Actually create the menu. */
876 current_popup_menu
= menu
= CreatePopupMenu ();
877 fill_in_menu (menu
, first_wv
->contents
);
879 /* Adjust coordinates to be root-window-relative. */
882 ClientToScreen (FRAME_W32_WINDOW (f
), &pos
);
884 /* Display the menu. */
885 menu_item_selection
= SendMessage (FRAME_W32_WINDOW (f
),
886 WM_EMACS_TRACKPOPUPMENU
,
887 (WPARAM
)menu
, (LPARAM
)&pos
);
889 /* Clean up extraneous mouse events which might have been generated
891 discard_mouse_events ();
892 FRAME_X_DISPLAY_INFO (f
)->grabbed
= 0;
894 /* Free the widget_value objects we used to specify the contents. */
895 free_menubar_widget_value_tree (first_wv
);
899 /* Free the owner-drawn and help-echo menu strings. */
900 w32_free_menu_strings (FRAME_W32_WINDOW (f
));
901 f
->output_data
.w32
->menubar_active
= 0;
903 /* Find the selected item, and its pane, to return
905 if (menu_item_selection
!= 0)
907 Lisp_Object prefix
, entry
;
909 prefix
= entry
= Qnil
;
911 while (i
< menu_items_used
)
913 if (EQ (AREF (menu_items
, i
), Qnil
))
915 subprefix_stack
[submenu_depth
++] = prefix
;
919 else if (EQ (AREF (menu_items
, i
), Qlambda
))
921 prefix
= subprefix_stack
[--submenu_depth
];
924 else if (EQ (AREF (menu_items
, i
), Qt
))
926 prefix
= AREF (menu_items
, i
+ MENU_ITEMS_PANE_PREFIX
);
927 i
+= MENU_ITEMS_PANE_LENGTH
;
929 /* Ignore a nil in the item list.
930 It's meaningful only for dialog boxes. */
931 else if (EQ (AREF (menu_items
, i
), Qquote
))
935 entry
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_VALUE
);
936 if (menu_item_selection
== i
)
942 entry
= Fcons (entry
, Qnil
);
944 entry
= Fcons (prefix
, entry
);
945 for (j
= submenu_depth
- 1; j
>= 0; j
--)
946 if (!NILP (subprefix_stack
[j
]))
947 entry
= Fcons (subprefix_stack
[j
], entry
);
951 i
+= MENU_ITEMS_ITEM_LENGTH
;
956 /* Make "Cancel" equivalent to C-g. */
957 Fsignal (Qquit
, Qnil
);
964 /* TODO: On Windows, there are two ways of defining a dialog.
966 1. Create a predefined dialog resource and include it in nt/emacs.rc.
967 Using this method, we could then set the titles and make unneeded
968 buttons invisible before displaying the dialog. Everything would
969 be a fixed size though, so there is a risk that text does not
971 2. Create the dialog template in memory on the fly. This allows us
972 to size the dialog and buttons dynamically, probably giving more
973 natural looking results for dialogs with few buttons, and eliminating
974 the problem of text overflowing the buttons. But the API for this is
975 quite complex - structures have to be allocated in particular ways,
976 text content is tacked onto the end of structures in variable length
977 arrays with further structures tacked on after these, there are
978 certain alignment requirements for all this, and we have to
979 measure all the text and convert to "dialog coordinates" to figure
980 out how big to make everything.
982 For now, we'll just stick with menus for dialogs that are more
983 complicated than simple yes/no type questions for which we can use
984 the MessageBox function.
987 static char * button_names
[] = {
988 "button1", "button2", "button3", "button4", "button5",
989 "button6", "button7", "button8", "button9", "button10" };
992 w32_dialog_show (FRAME_PTR f
, int keymaps
,
993 Lisp_Object title
, Lisp_Object header
,
996 int i
, nb_buttons
= 0;
998 int menu_item_selection
;
1000 widget_value
*wv
, *first_wv
= 0, *prev_wv
= 0;
1002 /* Number of elements seen so far, before boundary. */
1004 /* 1 means we've seen the boundary between left-hand elts and right-hand. */
1005 int boundary_seen
= 0;
1009 if (menu_items_n_panes
> 1)
1011 *error
= "Multiple panes in dialog box";
1015 /* Create a tree of widget_value objects
1016 representing the text label and buttons. */
1018 Lisp_Object pane_name
, prefix
;
1020 pane_name
= AREF (menu_items
, MENU_ITEMS_PANE_NAME
);
1021 prefix
= AREF (menu_items
, MENU_ITEMS_PANE_PREFIX
);
1022 pane_string
= (NILP (pane_name
)
1023 ? "" : SSDATA (pane_name
));
1024 prev_wv
= xmalloc_widget_value ();
1025 prev_wv
->value
= pane_string
;
1026 if (keymaps
&& !NILP (prefix
))
1028 prev_wv
->enabled
= 1;
1029 prev_wv
->name
= "message";
1030 prev_wv
->help
= Qnil
;
1033 /* Loop over all panes and items, filling in the tree. */
1034 i
= MENU_ITEMS_PANE_LENGTH
;
1035 while (i
< menu_items_used
)
1038 /* Create a new item within current pane. */
1039 Lisp_Object item_name
, enable
, descrip
, help
;
1041 item_name
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_NAME
);
1042 enable
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_ENABLE
);
1043 descrip
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_EQUIV_KEY
);
1044 help
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_HELP
);
1046 if (NILP (item_name
))
1048 free_menubar_widget_value_tree (first_wv
);
1049 *error
= "Submenu in dialog items";
1052 if (EQ (item_name
, Qquote
))
1054 /* This is the boundary between left-side elts
1055 and right-side elts. Stop incrementing right_count. */
1060 if (nb_buttons
>= 9)
1062 free_menubar_widget_value_tree (first_wv
);
1063 *error
= "Too many dialog items";
1067 wv
= xmalloc_widget_value ();
1069 wv
->name
= (char *) button_names
[nb_buttons
];
1070 if (!NILP (descrip
))
1071 wv
->key
= SSDATA (descrip
);
1072 wv
->value
= SSDATA (item_name
);
1073 wv
->call_data
= (void *) &AREF (menu_items
, i
);
1074 wv
->enabled
= !NILP (enable
);
1078 if (! boundary_seen
)
1082 i
+= MENU_ITEMS_ITEM_LENGTH
;
1085 /* If the boundary was not specified,
1086 by default put half on the left and half on the right. */
1087 if (! boundary_seen
)
1088 left_count
= nb_buttons
- nb_buttons
/ 2;
1090 wv
= xmalloc_widget_value ();
1091 wv
->name
= dialog_name
;
1094 /* Frame title: 'Q' = Question, 'I' = Information.
1095 Can also have 'E' = Error if, one day, we want
1096 a popup for errors. */
1098 dialog_name
[0] = 'Q';
1100 dialog_name
[0] = 'I';
1102 /* Dialog boxes use a really stupid name encoding
1103 which specifies how many buttons to use
1104 and how many buttons are on the right. */
1105 dialog_name
[1] = '0' + nb_buttons
;
1106 dialog_name
[2] = 'B';
1107 dialog_name
[3] = 'R';
1108 /* Number of buttons to put on the right. */
1109 dialog_name
[4] = '0' + nb_buttons
- left_count
;
1111 wv
->contents
= first_wv
;
1115 /* Actually create the dialog. */
1116 dialog_id
= widget_id_tick
++;
1117 menu
= lw_create_widget (first_wv
->name
, "dialog", dialog_id
, first_wv
,
1118 f
->output_data
.w32
->widget
, 1, 0,
1119 dialog_selection_callback
, 0);
1120 lw_modify_all_widgets (dialog_id
, first_wv
->contents
, TRUE
);
1122 /* Free the widget_value objects we used to specify the contents. */
1123 free_menubar_widget_value_tree (first_wv
);
1125 /* No selection has been chosen yet. */
1126 menu_item_selection
= 0;
1128 /* Display the menu. */
1129 lw_pop_up_all_widgets (dialog_id
);
1131 /* Process events that apply to the menu. */
1132 popup_get_selection ((XEvent
*) 0, FRAME_X_DISPLAY_INFO (f
), dialog_id
);
1134 lw_destroy_all_widgets (dialog_id
);
1136 /* Find the selected item, and its pane, to return
1137 the proper value. */
1138 if (menu_item_selection
!= 0)
1144 while (i
< menu_items_used
)
1148 if (EQ (AREF (menu_items
, i
), Qt
))
1150 prefix
= AREF (menu_items
, i
+ MENU_ITEMS_PANE_PREFIX
);
1151 i
+= MENU_ITEMS_PANE_LENGTH
;
1155 entry
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_VALUE
);
1156 if (menu_item_selection
== i
)
1160 entry
= Fcons (entry
, Qnil
);
1162 entry
= Fcons (prefix
, entry
);
1166 i
+= MENU_ITEMS_ITEM_LENGTH
;
1171 /* Make "Cancel" equivalent to C-g. */
1172 Fsignal (Qquit
, Qnil
);
1176 #else /* !HAVE_DIALOGS */
1178 /* Currently we only handle Yes No dialogs (y-or-n-p and yes-or-no-p) as
1179 simple dialogs. We could handle a few more, but I'm not aware of
1180 anywhere in Emacs that uses the other specific dialog choices that
1181 MessageBox provides. */
1184 is_simple_dialog (Lisp_Object contents
)
1186 Lisp_Object options
= XCDR (contents
);
1187 Lisp_Object name
, yes
, no
, other
;
1189 yes
= build_string ("Yes");
1190 no
= build_string ("No");
1192 if (!CONSP (options
))
1195 name
= XCAR (XCAR (options
));
1196 if (!CONSP (options
))
1199 if (!NILP (Fstring_equal (name
, yes
)))
1201 else if (!NILP (Fstring_equal (name
, no
)))
1206 options
= XCDR (options
);
1207 if (!CONSP (options
))
1210 name
= XCAR (XCAR (options
));
1211 if (NILP (Fstring_equal (name
, other
)))
1214 /* Check there are no more options. */
1215 options
= XCDR (options
);
1216 return !(CONSP (options
));
1220 simple_dialog_show (FRAME_PTR f
, Lisp_Object contents
, Lisp_Object header
)
1224 Lisp_Object lispy_answer
= Qnil
, temp
= XCAR (contents
);
1228 /* Since we only handle Yes/No dialogs, and we already checked
1229 is_simple_dialog, we don't need to worry about checking contents
1230 to see what type of dialog to use. */
1232 /* Use unicode if possible, so any language can be displayed. */
1233 if (unicode_message_box
)
1235 WCHAR
*text
, *title
;
1239 char *utf8_text
= SDATA (ENCODE_UTF_8 (temp
));
1240 /* Be pessimistic about the number of characters needed.
1241 Remember characters outside the BMP will take more than
1242 one utf16 word, so we cannot simply use the character
1244 int utf8_len
= strlen (utf8_text
);
1245 text
= alloca ((utf8_len
+ 1) * sizeof (WCHAR
));
1246 utf8to16 (utf8_text
, utf8_len
, text
);
1255 title
= L
"Question";
1256 type
|= MB_ICONQUESTION
;
1260 title
= L
"Information";
1261 type
|= MB_ICONINFORMATION
;
1264 answer
= unicode_message_box (FRAME_W32_WINDOW (f
), text
, title
, type
);
1270 /* Fall back on ANSI message box, but at least use system
1271 encoding so questions representable by the system codepage
1272 are encoded properly. */
1274 text
= SDATA (ENCODE_SYSTEM (temp
));
1281 type
|= MB_ICONQUESTION
;
1285 title
= "Information";
1286 type
|= MB_ICONINFORMATION
;
1289 answer
= MessageBox (FRAME_W32_WINDOW (f
), text
, title
, type
);
1292 if (answer
== IDYES
)
1293 lispy_answer
= build_string ("Yes");
1294 else if (answer
== IDNO
)
1295 lispy_answer
= build_string ("No");
1297 Fsignal (Qquit
, Qnil
);
1299 for (temp
= XCDR (contents
); CONSP (temp
); temp
= XCDR (temp
))
1301 Lisp_Object item
, name
, value
;
1306 value
= XCDR (item
);
1314 if (!NILP (Fstring_equal (name
, lispy_answer
)))
1319 Fsignal (Qquit
, Qnil
);
1322 #endif /* !HAVE_DIALOGS */
1325 /* UTF8: 0xxxxxxx, 110xxxxx 10xxxxxx, 1110xxxx, 10xxxxxx, 10xxxxxx */
1327 utf8to16 (unsigned char * src
, int len
, WCHAR
* dest
)
1334 *dest
= (WCHAR
) *src
;
1335 dest
++; src
++; len
--;
1337 /* Since we might get >3 byte sequences which we don't handle, ignore the extra parts. */
1338 else if (*src
< 0xC0)
1342 /* 2 char UTF-8 sequence. */
1343 else if (*src
< 0xE0)
1345 *dest
= (WCHAR
) (((*src
& 0x1f) << 6)
1346 | (*(src
+ 1) & 0x3f));
1347 src
+= 2; len
-= 2; dest
++;
1349 else if (*src
< 0xF0)
1351 *dest
= (WCHAR
) (((*src
& 0x0f) << 12)
1352 | ((*(src
+ 1) & 0x3f) << 6)
1353 | (*(src
+ 2) & 0x3f));
1354 src
+= 3; len
-= 3; dest
++;
1356 else /* Not encodable. Insert Unicode Substitution char. */
1358 *dest
= (WCHAR
) 0xfffd;
1359 src
++; len
--; dest
++;
1366 add_menu_item (HMENU menu
, widget_value
*wv
, HMENU item
)
1369 char *out_string
, *p
, *q
;
1371 size_t nlen
, orig_len
;
1373 if (menu_separator_name_p (wv
->name
))
1375 fuFlags
= MF_SEPARATOR
;
1381 fuFlags
= MF_STRING
;
1383 fuFlags
= MF_STRING
| MF_GRAYED
;
1385 if (wv
->key
!= NULL
)
1387 out_string
= alloca (strlen (wv
->name
) + strlen (wv
->key
) + 2);
1388 strcpy (out_string
, wv
->name
);
1389 strcat (out_string
, "\t");
1390 strcat (out_string
, wv
->key
);
1393 out_string
= (char *)wv
->name
;
1395 /* Quote any special characters within the menu item's text and
1397 nlen
= orig_len
= strlen (out_string
);
1398 if (unicode_append_menu
)
1400 /* With UTF-8, & cannot be part of a multibyte character. */
1401 for (p
= out_string
; *p
; p
++)
1409 /* If encoded with the system codepage, use multibyte string
1410 functions in case of multibyte characters that contain '&'. */
1411 for (p
= out_string
; *p
; p
= _mbsinc (p
))
1413 if (_mbsnextc (p
) == '&')
1418 if (nlen
> orig_len
)
1421 out_string
= alloca (nlen
+ 1);
1425 if (unicode_append_menu
)
1433 if (_mbsnextc (p
) == '&')
1448 else if (wv
->title
|| wv
->call_data
== 0)
1450 /* Only use MF_OWNERDRAW if GetMenuItemInfo is usable, since
1451 we can't deallocate the memory otherwise. */
1452 if (get_menu_item_info
)
1454 out_string
= (char *) local_alloc (strlen (wv
->name
) + 1);
1455 strcpy (out_string
, wv
->name
);
1457 DebPrint ("Menu: allocing %ld for owner-draw", out_string
);
1459 fuFlags
= MF_OWNERDRAW
| MF_DISABLED
;
1462 fuFlags
= MF_DISABLED
;
1465 /* Draw radio buttons and tickboxes. */
1466 else if (wv
->selected
&& (wv
->button_type
== BUTTON_TYPE_TOGGLE
||
1467 wv
->button_type
== BUTTON_TYPE_RADIO
))
1468 fuFlags
|= MF_CHECKED
;
1470 fuFlags
|= MF_UNCHECKED
;
1473 if (unicode_append_menu
&& out_string
)
1475 /* Convert out_string from UTF-8 to UTF-16-LE. */
1476 int utf8_len
= strlen (out_string
);
1477 WCHAR
* utf16_string
;
1478 if (fuFlags
& MF_OWNERDRAW
)
1479 utf16_string
= local_alloc ((utf8_len
+ 1) * sizeof (WCHAR
));
1481 utf16_string
= alloca ((utf8_len
+ 1) * sizeof (WCHAR
));
1483 utf8to16 (out_string
, utf8_len
, utf16_string
);
1484 return_value
= unicode_append_menu (menu
, fuFlags
,
1485 item
!= NULL
? (UINT
) item
1486 : (UINT
) wv
->call_data
,
1490 /* On W9x/ME, unicode menus are not supported, though AppendMenuW
1491 apparently does exist at least in some cases and appears to be
1492 stubbed out to do nothing. out_string is UTF-8, but since
1493 our standard menus are in English and this is only going to
1494 happen the first time a menu is used, the encoding is
1495 of minor importance compared with menus not working at all. */
1497 AppendMenu (menu
, fuFlags
,
1498 item
!= NULL
? (UINT
) item
: (UINT
) wv
->call_data
,
1500 /* Don't use unicode menus in future. */
1501 unicode_append_menu
= NULL
;
1504 if (unicode_append_menu
&& (fuFlags
& MF_OWNERDRAW
))
1505 local_free (out_string
);
1512 item
!= NULL
? (UINT
) item
: (UINT
) wv
->call_data
,
1516 /* This must be done after the menu item is created. */
1517 if (!wv
->title
&& wv
->call_data
!= 0)
1519 if (set_menu_item_info
)
1522 memset (&info
, 0, sizeof (info
));
1523 info
.cbSize
= sizeof (info
);
1524 info
.fMask
= MIIM_DATA
;
1526 /* Set help string for menu item. Leave it as a Lisp_Object
1527 until it is ready to be displayed, since GC can happen while
1528 menus are active. */
1529 if (!NILP (wv
->help
))
1530 #ifdef USE_LISP_UNION_TYPE
1531 info
.dwItemData
= (DWORD
) (wv
->help
).i
;
1533 info
.dwItemData
= (DWORD
) (wv
->help
);
1535 if (wv
->button_type
== BUTTON_TYPE_RADIO
)
1537 /* CheckMenuRadioItem allows us to differentiate TOGGLE and
1538 RADIO items, but is not available on NT 3.51 and earlier. */
1539 info
.fMask
|= MIIM_TYPE
| MIIM_STATE
;
1540 info
.fType
= MFT_RADIOCHECK
| MFT_STRING
;
1541 info
.dwTypeData
= out_string
;
1542 info
.fState
= wv
->selected
? MFS_CHECKED
: MFS_UNCHECKED
;
1545 set_menu_item_info (menu
,
1546 item
!= NULL
? (UINT
) item
: (UINT
) wv
->call_data
,
1550 return return_value
;
1553 /* Construct native Windows menu(bar) based on widget_value tree. */
1555 fill_in_menu (HMENU menu
, widget_value
*wv
)
1557 int items_added
= 0;
1559 for ( ; wv
!= NULL
; wv
= wv
->next
)
1563 HMENU sub_menu
= CreatePopupMenu ();
1565 if (sub_menu
== NULL
)
1568 if (!fill_in_menu (sub_menu
, wv
->contents
) ||
1569 !add_menu_item (menu
, wv
, sub_menu
))
1571 DestroyMenu (sub_menu
);
1577 if (!add_menu_item (menu
, wv
, NULL
))
1584 /* Display help string for currently pointed to menu item. Not
1585 supported on NT 3.51 and earlier, as GetMenuItemInfo is not
1588 w32_menu_display_help (HWND owner
, HMENU menu
, UINT item
, UINT flags
)
1590 if (get_menu_item_info
)
1592 struct frame
*f
= x_window_to_frame (&one_w32_display_info
, owner
);
1593 Lisp_Object frame
, help
;
1595 /* No help echo on owner-draw menu items, or when the keyboard is used
1596 to navigate the menus, since tooltips are distracting if they pop
1598 if (flags
& MF_OWNERDRAW
|| flags
& MF_POPUP
1599 || !(flags
& MF_MOUSESELECT
))
1605 memset (&info
, 0, sizeof (info
));
1606 info
.cbSize
= sizeof (info
);
1607 info
.fMask
= MIIM_DATA
;
1608 get_menu_item_info (menu
, item
, FALSE
, &info
);
1610 #ifdef USE_LISP_UNION_TYPE
1611 help
= info
.dwItemData
? (Lisp_Object
) ((EMACS_INT
) info
.dwItemData
)
1614 help
= info
.dwItemData
? (Lisp_Object
) info
.dwItemData
: Qnil
;
1618 /* Store the help echo in the keyboard buffer as the X toolkit
1619 version does, rather than directly showing it. This seems to
1620 solve the GC problems that were present when we based the
1621 Windows code on the non-toolkit version. */
1624 XSETFRAME (frame
, f
);
1625 kbd_buffer_store_help_event (frame
, help
);
1628 /* X version has a loop through frames here, which doesn't
1629 appear to do anything, unless it has some side effect. */
1630 show_help_echo (help
, Qnil
, Qnil
, Qnil
, 1);
1634 /* Free memory used by owner-drawn strings. */
1636 w32_free_submenu_strings (HMENU menu
)
1638 int i
, num
= GetMenuItemCount (menu
);
1639 for (i
= 0; i
< num
; i
++)
1642 memset (&info
, 0, sizeof (info
));
1643 info
.cbSize
= sizeof (info
);
1644 info
.fMask
= MIIM_DATA
| MIIM_TYPE
| MIIM_SUBMENU
;
1646 get_menu_item_info (menu
, i
, TRUE
, &info
);
1648 /* Owner-drawn names are held in dwItemData. */
1649 if ((info
.fType
& MF_OWNERDRAW
) && info
.dwItemData
)
1652 DebPrint ("Menu: freeing %ld for owner-draw", info
.dwItemData
);
1654 local_free (info
.dwItemData
);
1657 /* Recurse down submenus. */
1659 w32_free_submenu_strings (info
.hSubMenu
);
1664 w32_free_menu_strings (HWND hwnd
)
1666 HMENU menu
= current_popup_menu
;
1668 if (get_menu_item_info
)
1670 /* If there is no popup menu active, free the strings from the frame's
1673 menu
= GetMenu (hwnd
);
1676 w32_free_submenu_strings (menu
);
1679 current_popup_menu
= NULL
;
1682 #endif /* HAVE_MENUS */
1684 /* The following is used by delayed window autoselection. */
1686 DEFUN ("menu-or-popup-active-p", Fmenu_or_popup_active_p
, Smenu_or_popup_active_p
, 0, 0, 0,
1687 doc
: /* Return t if a menu or popup dialog is active on selected frame. */)
1692 f
= SELECTED_FRAME ();
1693 return (f
->output_data
.w32
->menubar_active
> 0) ? Qt
: Qnil
;
1696 #endif /* HAVE_MENUS */
1700 syms_of_w32menu (void)
1702 globals_of_w32menu ();
1704 current_popup_menu
= NULL
;
1706 DEFSYM (Qdebug_on_next_call
, "debug-on-next-call");
1708 defsubr (&Smenu_or_popup_active_p
);
1710 defsubr (&Sx_popup_dialog
);
1715 globals_of_w32menu is used to initialize those global variables that
1716 must always be initialized on startup even when the global variable
1717 initialized is non zero (see the function main in emacs.c).
1718 globals_of_w32menu is called from syms_of_w32menu when the global
1719 variable initialized is 0 and directly from main when initialized
1723 globals_of_w32menu (void)
1725 /* See if Get/SetMenuItemInfo functions are available. */
1726 HMODULE user32
= GetModuleHandle ("user32.dll");
1727 get_menu_item_info
= (GetMenuItemInfoA_Proc
) GetProcAddress (user32
, "GetMenuItemInfoA");
1728 set_menu_item_info
= (SetMenuItemInfoA_Proc
) GetProcAddress (user32
, "SetMenuItemInfoA");
1729 unicode_append_menu
= (AppendMenuW_Proc
) GetProcAddress (user32
, "AppendMenuW");
1730 unicode_message_box
= (MessageBoxW_Proc
) GetProcAddress (user32
, "MessageBoxW");