Use terminal-specific hooks to display popup dialogs.
* termhooks.h (struct terminal): New field popup_dialog_hook. * menu.c (emulate_dialog_with_menu): New function, refactored from ... (Fx_popup_dialog): ... adjusted user. Also remove old #if 0 code and use popup_dialog_hook. * nsmenu.m (ns_popup_dialog): Make hook-compatible. * nsterm.h (ns_popup_dialog): Adjust prototype. * nsterm.m (ns_create_terminal): * w32term.c (w32_create_terminal): * xterm.c (x_create_terminal) [USE_X_TOOLKIT || USE_GTK]: Setup popup_dialog_hook.
This commit is contained in:
parent
350aea695f
commit
680a6ad932
8 changed files with 67 additions and 98 deletions
|
@ -1,3 +1,17 @@
|
|||
2014-06-04 Dmitry Antipov <dmantipov@yandex.ru>
|
||||
|
||||
Use terminal-specific hooks to display popup dialogs.
|
||||
* termhooks.h (struct terminal): New field popup_dialog_hook.
|
||||
* menu.c (emulate_dialog_with_menu): New function, refactored from ...
|
||||
(Fx_popup_dialog): ... adjusted user. Also remove old #if 0
|
||||
code and use popup_dialog_hook.
|
||||
* nsmenu.m (ns_popup_dialog): Make hook-compatible.
|
||||
* nsterm.h (ns_popup_dialog): Adjust prototype.
|
||||
* nsterm.m (ns_create_terminal):
|
||||
* w32term.c (w32_create_terminal):
|
||||
* xterm.c (x_create_terminal) [USE_X_TOOLKIT || USE_GTK]: Setup
|
||||
popup_dialog_hook.
|
||||
|
||||
2014-06-04 Eli Zaretskii <eliz@gnu.org>
|
||||
|
||||
* w32heap.c (report_temacs_memory_usage): Improve the report by
|
||||
|
|
102
src/menu.c
102
src/menu.c
|
@ -1434,6 +1434,38 @@ no quit occurs and `x-popup-menu' returns nil. */)
|
|||
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.
|
||||
|
@ -1466,24 +1498,7 @@ for instance using the window manager, then this produces a quit and
|
|||
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,18 @@ for instance using the window manager, then this produces a quit and
|
|||
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
|
||||
|
|
38
src/nsmenu.m
38
src/nsmenu.m
|
@ -1428,11 +1428,10 @@ - (NSRect) frame
|
|||
|
||||
|
||||
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 @@ - (NSRect) frame
|
|||
|
||||
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;
|
||||
|
|
|
@ -855,7 +855,7 @@ extern void find_and_call_menu_selection (struct frame *f,
|
|||
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
|
||||
|
|
|
@ -4165,6 +4165,7 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
|
|||
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;
|
||||
|
|
|
@ -482,6 +482,10 @@ struct terminal
|
|||
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
|
||||
|
|
|
@ -6274,6 +6274,7 @@ w32_create_terminal (struct w32_display_info *dpyinfo)
|
|||
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;
|
||||
|
|
|
@ -10533,6 +10533,9 @@ x_create_terminal (struct x_display_info *dpyinfo)
|
|||
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue