unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Antipov <dmantipov@yandex.ru>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Using Qunsupported__w32_dialog
Date: Wed, 04 Jun 2014 16:22:00 +0400	[thread overview]
Message-ID: <538F0F68.6020107@yandex.ru> (raw)
In-Reply-To: <83mwdt8zkw.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 211 bytes --]

Eli,

could you please review this? This is similar to r117255 but for
popup dialogs, and Qunsupported__w32_dialog really confuses me
(especially taking into account that I can't build for MS-Windows).

Dmitry


[-- Attachment #2: popup_dialog_hook.patch --]
[-- Type: text/x-patch, Size: 9221 bytes --]

=== modified file 'src/menu.c'
--- src/menu.c	2014-06-04 04:58:31 +0000
+++ src/menu.c	2014-06-04 12:07:36 +0000
@@ -1434,6 +1434,38 @@
   return selection;
 }
 
+/* If F's terminal is not capable to display popup dialog,
+   emulate it with a menu.  */
+
+Lisp_Object
+emulate_dialog_with_menu (struct frame *f, Lisp_Object contents)
+{
+  Lisp_Object x, y, frame, newpos, prompt = Fcar (contents);
+  int x_coord, y_coord;
+
+  if (FRAME_WINDOW_P (f))
+    {
+      x_coord = FRAME_PIXEL_WIDTH (f);
+      y_coord = FRAME_PIXEL_HEIGHT (f);
+    }
+  else
+    {
+      x_coord = FRAME_COLS (f);
+      /* Center the title at frame middle.  (TTY menus have
+	 their upper-left corner at the given position.)  */
+      if (STRINGP (prompt))
+	x_coord -= SCHARS (prompt);
+      y_coord = FRAME_LINES (f);
+    }
+  
+  XSETFRAME (frame, f);
+  XSETINT (x, x_coord / 2);
+  XSETINT (y, y_coord / 2);
+  newpos = list2 (list2 (x, y), frame);
+
+  return Fx_popup_menu (newpos, list2 (prompt, contents));
+}
+
 DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 3, 0,
        doc: /* Pop up a dialog box and return user's selection.
 POSITION specifies which frame to use.
@@ -1466,24 +1498,7 @@
   if (EQ (position, Qt)
       || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar)
 			       || EQ (XCAR (position), Qtool_bar))))
-    {
-#if 0 /* Using the frame the mouse is on may not be right.  */
-      /* Use the mouse's current position.  */
-      struct frame *new_f = SELECTED_FRAME ();
-      Lisp_Object bar_window;
-      enum scroll_bar_part part;
-      Time time;
-      Lisp_Object x, y;
-
-      (*mouse_position_hook) (&new_f, 1, &bar_window, &part, &x, &y, &time);
-
-      if (new_f != 0)
-	XSETFRAME (window, new_f);
-      else
-	window = selected_window;
-#endif
-      window = selected_window;
-    }
+    window = selected_window;
   else if (CONSP (position))
     {
       Lisp_Object tem = XCAR (position);
@@ -1525,51 +1540,12 @@
      string contents, because Fredisplay may GC and relocate them.  */
   Fredisplay (Qt);
 
-#if defined USE_X_TOOLKIT || defined USE_GTK
-  if (FRAME_WINDOW_P (f))
-    return xw_popup_dialog (f, header, contents);
-#endif
-#ifdef HAVE_NTGUI
-  if (FRAME_W32_P (f))
-    {
-      Lisp_Object selection = w32_popup_dialog (f, header, contents);
-
-      if (!EQ (selection, Qunsupported__w32_dialog))
-	return selection;
-    }
-#endif
-#ifdef HAVE_NS
-  if (FRAME_NS_P (f))
-    return ns_popup_dialog (position, header, contents);
-#endif
-  /* Display a menu with these alternatives
-     in the middle of frame F.  */
-  {
-    Lisp_Object x, y, frame, newpos, prompt;
-    int x_coord, y_coord;
-
-    prompt = Fcar (contents);
-    if (FRAME_WINDOW_P (f))
-      {
-	x_coord = FRAME_PIXEL_WIDTH (f);
-	y_coord = FRAME_PIXEL_HEIGHT (f);
-      }
-    else
-      {
-	x_coord = FRAME_COLS (f);
-	/* Center the title at frame middle.  (TTY menus have their
-	   upper-left corner at the given position.)  */
-	if (STRINGP (prompt))
-	  x_coord -= SCHARS (prompt);
-	y_coord = FRAME_LINES (f);
-      }
-    XSETFRAME (frame, f);
-    XSETINT (x, x_coord / 2);
-    XSETINT (y, y_coord / 2);
-    newpos = list2 (list2 (x, y), frame);
-
-    return Fx_popup_menu (newpos, list2 (prompt, contents));
-  }
+  /* Display the popup dialog by a terminal-specific hook ... */
+  if (FRAME_TERMINAL (f)->popup_dialog_hook)
+    return FRAME_TERMINAL (f)->popup_dialog_hook (f, header, contents);
+
+  /* ... or emulate it with a menu.  */
+  return emulate_dialog_with_menu (f, contents);
 }
 
 void

=== modified file 'src/menu.h'
--- src/menu.h	2014-06-04 04:58:31 +0000
+++ src/menu.h	2014-06-04 12:07:43 +0000
@@ -22,10 +22,6 @@
 #include "systime.h" /* for Time */
 #include "../lwlib/lwlib-widget.h"
 
-#ifdef HAVE_NTGUI
-extern Lisp_Object Qunsupported__w32_dialog;
-#endif
-
 /* Bit fields used by terminal-specific menu_show_hook.  */
 
 enum {
@@ -72,4 +68,6 @@
 extern Lisp_Object tty_menu_show (struct frame *, int, int, int,
 				  Lisp_Object, const char **);
 extern ptrdiff_t menu_item_width (const unsigned char *);
+extern Lisp_Object emulate_dialog_with_menu (struct frame *, Lisp_Object);
+
 #endif /* MENU_H */

=== modified file 'src/nsmenu.m'
--- src/nsmenu.m	2014-06-04 04:58:31 +0000
+++ src/nsmenu.m	2014-06-04 11:52:07 +0000
@@ -1428,11 +1428,10 @@
 
 
 Lisp_Object
-ns_popup_dialog (Lisp_Object position, Lisp_Object header, Lisp_Object contents)
+ns_popup_dialog (struct frame *f, Lisp_Object header, Lisp_Object contents)
 {
   id dialog;
   Lisp_Object window, tem, title;
-  struct frame *f;
   NSPoint p;
   BOOL isQ;
   NSAutoreleasePool *pool;
@@ -1441,41 +1440,6 @@
 
   isQ = NILP (header);
 
-  if (EQ (position, Qt)
-      || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar)
-                               || EQ (XCAR (position), Qtool_bar))))
-    {
-      window = selected_window;
-    }
-  else if (CONSP (position))
-    {
-      Lisp_Object tem;
-      tem = Fcar (position);
-      if (XTYPE (tem) == Lisp_Cons)
-        window = Fcar (Fcdr (position));
-      else
-        {
-          tem = Fcar (Fcdr (position));  /* EVENT_START (position) */
-          window = Fcar (tem);	     /* POSN_WINDOW (tem) */
-        }
-    }
-  else if (WINDOWP (position) || FRAMEP (position))
-    {
-      window = position;
-    }
-  else
-    window = Qnil;
-
-  if (FRAMEP (window))
-    f = XFRAME (window);
-  else if (WINDOWP (window))
-    {
-      CHECK_LIVE_WINDOW (window);
-      f = XFRAME (WINDOW_FRAME (XWINDOW (window)));
-    }
-  else
-    CHECK_WINDOW (window);
-
   check_window_system (f);
 
   p.x = (int)f->left_pos + ((int)FRAME_COLUMN_WIDTH (f) * f->text_cols)/2;

=== modified file 'src/nsterm.h'
--- src/nsterm.h	2014-05-26 11:16:47 +0000
+++ src/nsterm.h	2014-06-04 12:13:45 +0000
@@ -855,7 +855,7 @@
 extern Lisp_Object find_and_return_menu_selection (struct frame *f,
                                                    bool keymaps,
                                                    void *client_data);
-extern Lisp_Object ns_popup_dialog (Lisp_Object position, Lisp_Object header,
+extern Lisp_Object ns_popup_dialog (struct frame *, Lisp_Object header,
                                     Lisp_Object contents);
 
 #define NSAPP_DATA2_RUNASSCRIPT 10

=== modified file 'src/nsterm.m'
--- src/nsterm.m	2014-06-04 04:58:31 +0000
+++ src/nsterm.m	2014-06-04 11:58:49 +0000
@@ -4165,6 +4165,7 @@
   terminal->frame_raise_lower_hook = ns_frame_raise_lower;
   terminal->fullscreen_hook = ns_fullscreen_hook;
   terminal->menu_show_hook = ns_menu_show;
+  terminal->popup_dialog_hook = ns_popup_dialog;
   terminal->set_vertical_scroll_bar_hook = ns_set_vertical_scroll_bar;
   terminal->condemn_scroll_bars_hook = ns_condemn_scroll_bars;
   terminal->redeem_scroll_bar_hook = ns_redeem_scroll_bar;

=== modified file 'src/termhooks.h'
--- src/termhooks.h	2014-06-04 04:58:31 +0000
+++ src/termhooks.h	2014-06-04 12:00:07 +0000
@@ -482,6 +482,10 @@
   Lisp_Object (*menu_show_hook) (struct frame *f, int x, int y, int menuflags,
 				 Lisp_Object title, const char **error_name);
 
+  /* This hook is called to display popup dialog.  */
+  Lisp_Object (*popup_dialog_hook) (struct frame *f, Lisp_Object header,
+				    Lisp_Object contents);
+
   /* Scroll bar hooks.  */
 
   /* The representation of scroll bars is determined by the code which

=== modified file 'src/w32menu.c'
--- src/w32menu.c	2014-06-04 04:58:31 +0000
+++ src/w32menu.c	2014-06-04 12:07:50 +0000
@@ -98,7 +98,8 @@
 MessageBoxW_Proc unicode_message_box = NULL;
 #endif /* NTGUI_UNICODE */
 
-Lisp_Object Qdebug_on_next_call, Qunsupported__w32_dialog;
+Lisp_Object Qdebug_on_next_call;
+static Lisp_Object Qunsupported__w32_dialog;
 
 void set_frame_menubar (struct frame *, bool, bool);
 
@@ -148,6 +149,8 @@
       FRAME_DISPLAY_INFO (f)->grabbed = 0;
 
       if (error_name) error (error_name);
+      if (EQ (selection, Qunsupported__w32_dialog))
+	return emulate_dialog_with_menu (f, contents);
       return selection;
     }
 #endif /* HAVE_DIALOGS */

=== modified file 'src/w32term.c'
--- src/w32term.c	2014-06-04 04:58:31 +0000
+++ src/w32term.c	2014-06-04 11:58:08 +0000
@@ -6274,6 +6274,7 @@
   terminal->frame_raise_lower_hook = w32_frame_raise_lower;
   terminal->fullscreen_hook = w32fullscreen_hook;
   terminal->menu_show_hook = w32_menu_show;
+  terminal->popup_dialog_hook = w32_popup_dialog;
   terminal->set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar;
   terminal->condemn_scroll_bars_hook = w32_condemn_scroll_bars;
   terminal->redeem_scroll_bar_hook = w32_redeem_scroll_bar;

=== modified file 'src/xterm.c'
--- src/xterm.c	2014-06-04 04:58:31 +0000
+++ src/xterm.c	2014-06-04 11:59:10 +0000
@@ -10533,6 +10533,9 @@
   terminal->frame_raise_lower_hook = XTframe_raise_lower;
   terminal->fullscreen_hook = XTfullscreen_hook;
   terminal->menu_show_hook = x_menu_show;
+#if defined (USE_X_TOOLKIT) || defined (USE_GTK)
+  terminal->popup_dialog_hook = xw_popup_dialog;
+#endif  
   terminal->set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar;
   terminal->condemn_scroll_bars_hook = XTcondemn_scroll_bars;
   terminal->redeem_scroll_bar_hook = XTredeem_scroll_bar;


  parent reply	other threads:[~2014-06-04 12:22 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-03 20:00 Latest EMACS on BZR trunk does not compile with MinGW Vincent Belaïche
2014-06-03 20:22 ` Paul Eggert
2014-06-03 20:56   ` Óscar Fuentes
2014-06-03 21:15   ` Eli Zaretskii
2014-06-03 21:21     ` Vincent Belaïche
2014-06-04  6:47       ` Eli Zaretskii
2014-06-04 13:17         ` Vincent Belaïche
2014-06-04 13:31           ` Eli Zaretskii
2014-06-04 15:28             ` Vincent Belaïche
2014-06-04 15:44               ` Eli Zaretskii
2014-06-04 15:54                 ` Dani Moncayo
2014-06-04 16:05                   ` Eli Zaretskii
2014-06-04 21:50                     ` Dani Moncayo
2014-06-05  0:42                       ` Stefan Monnier
2014-06-05  2:51                         ` Eli Zaretskii
2014-06-05  3:40                           ` Óscar Fuentes
2014-06-05  7:03                             ` Dani Moncayo
2014-06-05  9:03                               ` Vincent Belaïche
2014-06-05 15:09                                 ` Eli Zaretskii
2014-06-05 14:51                             ` Eli Zaretskii
2014-06-05 16:19                               ` Óscar Fuentes
2014-06-05 17:52                                 ` Eli Zaretskii
2014-06-05 13:31                           ` Stefan Monnier
2014-06-05 15:15                             ` Eli Zaretskii
2014-06-05 16:50                               ` Stefan Monnier
2014-06-05 18:07                                 ` Eli Zaretskii
2014-06-05 19:35                                   ` Paul Eggert
2014-06-05 19:54                                     ` Eli Zaretskii
2014-06-10 19:25                                     ` Dani Moncayo
2014-06-10 20:21                                       ` Eli Zaretskii
2014-06-05 20:54                                   ` Stefan Monnier
2014-06-05  2:47                       ` Eli Zaretskii
2014-06-04 12:22     ` Dmitry Antipov [this message]
2014-06-04 13:09       ` Using Qunsupported__w32_dialog Eli Zaretskii
2014-06-04 13:37         ` Dmitry Antipov
2014-06-04 13:47           ` Eli Zaretskii
2014-06-04 14:06             ` Eli Zaretskii
2014-06-03 21:14 ` Latest EMACS on BZR trunk does not compile with MinGW Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=538F0F68.6020107@yandex.ru \
    --to=dmantipov@yandex.ru \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).