Do not use global Lisp_Object in composition macros.
[bpt/emacs.git] / src / w32menu.c
index 4d82047..34020fa 100644 (file)
@@ -1,6 +1,6 @@
 /* Menu support for GNU Emacs on the Microsoft Windows API.
-   Copyright (C) 1986, 1988, 1993-1994, 1996, 1998-1999, 2001-2012
-                 Free Software Foundation, Inc.
+   Copyright (C) 1986, 1988, 1993-1994, 1996, 1998-1999, 2001-2013 Free
+   Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -56,7 +56,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "dispextern.h"
 
-#include "w32heap.h"   /* for osinfo_cache */
+#include "w32common.h" /* for osinfo_cache */
 
 #undef HAVE_DIALOGS /* TODO: Implement native dialogs.  */
 
@@ -100,13 +100,13 @@ MessageBoxW_Proc unicode_message_box = NULL;
 
 Lisp_Object Qdebug_on_next_call;
 
-void set_frame_menubar (FRAME_PTR, int, int);
+void set_frame_menubar (struct frame *, bool, bool);
 
 #ifdef HAVE_DIALOGS
-static Lisp_Object w32_dialog_show (FRAME_PTR, int, Lisp_Object, char**);
+static Lisp_Object w32_dialog_show (struct frame *, int, Lisp_Object, char**);
 #else
 static int is_simple_dialog (Lisp_Object);
-static Lisp_Object simple_dialog_show (FRAME_PTR, Lisp_Object, Lisp_Object);
+static Lisp_Object simple_dialog_show (struct frame *, Lisp_Object, Lisp_Object);
 #endif
 
 static void utf8to16 (unsigned char *, int, WCHAR *);
@@ -114,17 +114,6 @@ static int fill_in_menu (HMENU, widget_value *);
 
 void w32_free_menu_strings (HWND);
 
-\f
-
-/* This is set nonzero after the user activates the menu bar, and set
-   to zero again after the menu bars are redisplayed by prepare_menu_bar.
-   While it is nonzero, all calls to set_frame_menubar go deep.
-
-   I don't understand why this is needed, but it does seem to be
-   needed on Motif, according to Marcus Daniels <marcus@sysc.pdx.edu>.  */
-
-int pending_menu_activation;
-\f
 #ifdef HAVE_MENUS
 
 DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 3, 0,
@@ -148,11 +137,9 @@ If HEADER is non-nil, the frame title for the box is "Information",
 otherwise it is "Question". */)
   (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
 {
-  FRAME_PTR f = NULL;
+  struct frame *f = NULL;
   Lisp_Object window;
 
-  check_w32 ();
-
   /* Decode the first argument: find the window or frame to use.  */
   if (EQ (position, Qt)
       || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar)
@@ -160,7 +147,7 @@ otherwise it is "Question". */)
     {
 #if 0 /* Using the frame the mouse is on may not be right.  */
       /* Use the mouse's current position.  */
-      FRAME_PTR new_f = SELECTED_FRAME ();
+      struct frame *new_f = SELECTED_FRAME ();
       Lisp_Object bar_window;
       enum scroll_bar_part part;
       Time time;
@@ -205,6 +192,8 @@ otherwise it is "Question". */)
        but I don't want to make one now.  */
     CHECK_WINDOW (window);
 
+  check_window_system (f);
+
 #ifndef HAVE_DIALOGS
 
   {
@@ -217,8 +206,8 @@ otherwise it is "Question". */)
           in the middle of frame F.  */
        Lisp_Object x, y, frame, newpos;
        XSETFRAME (frame, f);
-       XSETINT (x, x_pixel_width (f) / 2);
-       XSETINT (y, x_pixel_height (f) / 2);
+       XSETINT (x, FRAME_PIXEL_WIDTH (f) / 2);
+       XSETINT (y, FRAME_PIXEL_HEIGHT (f) / 2);
        newpos = Fcons (Fcons (x, Fcons (y, Qnil)), Fcons (frame, Qnil));
        return Fx_popup_menu (newpos,
                              Fcons (Fcar (contents), Fcons (contents, Qnil)));
@@ -237,9 +226,9 @@ otherwise it is "Question". */)
     list_of_panes (Fcons (contents, Qnil));
 
     /* Display them in a dialog box.  */
-    BLOCK_INPUT;
+    block_input ();
     selection = w32_dialog_show (f, 0, title, header, &error_name);
-    UNBLOCK_INPUT;
+    unblock_input ();
 
     discard_menu_items ();
     FRAME_X_DISPLAY_INFO (f)->grabbed = 0;
@@ -263,7 +252,7 @@ otherwise it is "Question". */)
    This way we can safely execute Lisp code.  */
 
 void
-x_activate_menubar (FRAME_PTR f)
+x_activate_menubar (struct frame *f)
 {
   set_frame_menubar (f, 0, 1);
 
@@ -280,7 +269,7 @@ x_activate_menubar (FRAME_PTR f)
    and put the appropriate events into the keyboard buffer.  */
 
 void
-menubar_selection_callback (FRAME_PTR f, void * client_data)
+menubar_selection_callback (struct frame *f, void * client_data)
 {
   Lisp_Object prefix, entry;
   Lisp_Object vector;
@@ -372,7 +361,7 @@ menubar_selection_callback (FRAME_PTR f, void * client_data)
    it is set the first time this is called, from initialize_frame_menubar.  */
 
 void
-set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
+set_frame_menubar (struct frame *f, bool first_time, bool deep_p)
 {
   HMENU menubar_widget = f->output_data.w32->menubar_widget;
   Lisp_Object items;
@@ -389,8 +378,6 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
 
   if (! menubar_widget)
     deep_p = 1;
-  else if (pending_menu_activation && !deep_p)
-    deep_p = 1;
 
   if (deep_p)
     {
@@ -409,7 +396,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
       if (! menubar_widget)
        previous_menu_items_used = 0;
 
-      buffer = XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer;
+      buffer = XWINDOW (FRAME_SELECTED_WINDOW (f))->contents;
       specbind (Qinhibit_quit, Qt);
       /* Don't let the debugger step into this code
         because it is not reentrant.  */
@@ -587,7 +574,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
 
   /* Create or update the menu bar widget.  */
 
-  BLOCK_INPUT;
+  block_input ();
 
   if (menubar_widget)
     {
@@ -617,7 +604,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
       x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
   }
 
-  UNBLOCK_INPUT;
+  unblock_input ();
 }
 
 /* Called from Fx_create_frame to create the initial menubar of a frame
@@ -626,7 +613,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
    is visible.  */
 
 void
-initialize_frame_menubar (FRAME_PTR f)
+initialize_frame_menubar (struct frame *f)
 {
   /* This function is called before the first chance to redisplay
      the frame.  It has to be, so the frame will have the right size.  */
@@ -638,9 +625,9 @@ initialize_frame_menubar (FRAME_PTR f)
    This is used when deleting a frame, and when turning off the menu bar.  */
 
 void
-free_frame_menubar (FRAME_PTR f)
+free_frame_menubar (struct frame *f)
 {
-  BLOCK_INPUT;
+  block_input ();
 
   {
     HMENU old = GetMenu (FRAME_W32_WINDOW (f));
@@ -649,7 +636,7 @@ free_frame_menubar (FRAME_PTR f)
     DestroyMenu (old);
   }
 
-  UNBLOCK_INPUT;
+  unblock_input ();
 }
 
 \f
@@ -669,7 +656,7 @@ free_frame_menubar (FRAME_PTR f)
    (We return nil on failure, but the value doesn't actually matter.)  */
 
 Lisp_Object
-w32_menu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
+w32_menu_show (struct frame *f, int x, int y, int for_click, int keymaps,
               Lisp_Object title, const char **error)
 {
   int i;
@@ -996,7 +983,7 @@ static char * button_names [] = {
   "button6", "button7", "button8", "button9", "button10" };
 
 static Lisp_Object
-w32_dialog_show (FRAME_PTR f, int keymaps,
+w32_dialog_show (struct frame *f, int keymaps,
                 Lisp_Object title, Lisp_Object header,
                 char **error)
 {
@@ -1232,7 +1219,7 @@ is_simple_dialog (Lisp_Object contents)
 }
 
 static Lisp_Object
-simple_dialog_show (FRAME_PTR f, Lisp_Object contents, Lisp_Object header)
+simple_dialog_show (struct frame *f, Lisp_Object contents, Lisp_Object header)
 {
   int answer;
   UINT type;
@@ -1503,8 +1490,8 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
 
       utf8to16 (out_string, utf8_len, utf16_string);
       return_value = unicode_append_menu (menu, fuFlags,
-                                         item != NULL ? (UINT) item
-                                           : (UINT) wv->call_data,
+                                         item != NULL ? (UINT_PTR) item
+                                           : (UINT_PTR) wv->call_data,
                                          utf16_string);
 
 #ifndef NTGUI_UNICODE /* Fallback does not apply when always UNICODE */
@@ -1518,7 +1505,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
             of minor importance compared with menus not working at all.  */
          return_value =
            AppendMenu (menu, fuFlags,
-                       item != NULL ? (UINT) item: (UINT) wv->call_data,
+                       item != NULL ? (UINT_PTR) item: (UINT_PTR) wv->call_data,
                        out_string);
          /* Don't use Unicode menus in future, unless this is Windows
             NT or later, where a failure of AppendMenuW does NOT mean
@@ -1536,7 +1523,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
       return_value =
        AppendMenu (menu,
                    fuFlags,
-                   item != NULL ? (UINT) item : (UINT) wv->call_data,
+                   item != NULL ? (UINT_PTR) item : (UINT_PTR) wv->call_data,
                    out_string );
     }
 
@@ -1573,7 +1560,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
            }
 
          set_menu_item_info (menu,
-                             item != NULL ? (UINT) item : (UINT) wv->call_data,
+                             item != NULL ? (UINT_PTR) item : (UINT_PTR) wv->call_data,
                              FALSE, &info);
        }
     }
@@ -1712,7 +1699,7 @@ DEFUN ("menu-or-popup-active-p", Fmenu_or_popup_active_p, Smenu_or_popup_active_
   (void)
 {
 #ifdef HAVE_MENUS
-  FRAME_PTR f;
+  struct frame *f;
   f = SELECTED_FRAME ();
   return (f->output_data.w32->menubar_active > 0) ? Qt : Qnil;
 #else