return selection;
}
+/* If F's terminal is not capable to display popup dialog,
+ emulate it with a menu. */
+
+static 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.
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);
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))
+ /* Display the popup dialog by a terminal-specific hook ... */
+ if (FRAME_TERMINAL (f)->popup_dialog_hook)
{
- Lisp_Object selection = w32_popup_dialog (f, header, contents);
-
+ Lisp_Object selection
+ = FRAME_TERMINAL (f)->popup_dialog_hook (f, header, contents);
+#ifdef HAVE_NTGUI
if (!EQ (selection, Qunsupported__w32_dialog))
- return selection;
+#endif
+ 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));
- }
+ /* ... or emulate it with a menu. */
+ return emulate_dialog_with_menu (f, contents);
}
void
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;
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;