diff options
| author | Dmitry Antipov | 2014-06-04 18:59:09 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2014-06-04 18:59:09 +0400 |
| commit | 680a6ad9327fc056854cac0a3e7679a32cb63a93 (patch) | |
| tree | e0bf50ef593d2b32ff034b0eb700f7a664f8d4ee /src | |
| parent | 350aea695f9ad367e066bf073da2a0bb1d9a56bd (diff) | |
| download | emacs-680a6ad9327fc056854cac0a3e7679a32cb63a93.tar.gz emacs-680a6ad9327fc056854cac0a3e7679a32cb63a93.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 14 | ||||
| -rw-r--r-- | src/menu.c | 102 | ||||
| -rw-r--r-- | src/nsmenu.m | 38 | ||||
| -rw-r--r-- | src/nsterm.h | 2 | ||||
| -rw-r--r-- | src/nsterm.m | 1 | ||||
| -rw-r--r-- | src/termhooks.h | 4 | ||||
| -rw-r--r-- | src/w32term.c | 1 | ||||
| -rw-r--r-- | src/xterm.c | 3 |
8 files changed, 67 insertions, 98 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 424a828e1fa..8cbd4c54e33 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,17 @@ | |||
| 1 | 2014-06-04 Dmitry Antipov <dmantipov@yandex.ru> | ||
| 2 | |||
| 3 | Use terminal-specific hooks to display popup dialogs. | ||
| 4 | * termhooks.h (struct terminal): New field popup_dialog_hook. | ||
| 5 | * menu.c (emulate_dialog_with_menu): New function, refactored from ... | ||
| 6 | (Fx_popup_dialog): ... adjusted user. Also remove old #if 0 | ||
| 7 | code and use popup_dialog_hook. | ||
| 8 | * nsmenu.m (ns_popup_dialog): Make hook-compatible. | ||
| 9 | * nsterm.h (ns_popup_dialog): Adjust prototype. | ||
| 10 | * nsterm.m (ns_create_terminal): | ||
| 11 | * w32term.c (w32_create_terminal): | ||
| 12 | * xterm.c (x_create_terminal) [USE_X_TOOLKIT || USE_GTK]: Setup | ||
| 13 | popup_dialog_hook. | ||
| 14 | |||
| 1 | 2014-06-04 Eli Zaretskii <eliz@gnu.org> | 15 | 2014-06-04 Eli Zaretskii <eliz@gnu.org> |
| 2 | 16 | ||
| 3 | * w32heap.c (report_temacs_memory_usage): Improve the report by | 17 | * w32heap.c (report_temacs_memory_usage): Improve the report by |
diff --git a/src/menu.c b/src/menu.c index b65401c6f4f..b75e3dd6219 100644 --- a/src/menu.c +++ b/src/menu.c | |||
| @@ -1434,6 +1434,38 @@ no quit occurs and `x-popup-menu' returns nil. */) | |||
| 1434 | return selection; | 1434 | return selection; |
| 1435 | } | 1435 | } |
| 1436 | 1436 | ||
| 1437 | /* If F's terminal is not capable to display popup dialog, | ||
| 1438 | emulate it with a menu. */ | ||
| 1439 | |||
| 1440 | static Lisp_Object | ||
| 1441 | emulate_dialog_with_menu (struct frame *f, Lisp_Object contents) | ||
| 1442 | { | ||
| 1443 | Lisp_Object x, y, frame, newpos, prompt = Fcar (contents); | ||
| 1444 | int x_coord, y_coord; | ||
| 1445 | |||
| 1446 | if (FRAME_WINDOW_P (f)) | ||
| 1447 | { | ||
| 1448 | x_coord = FRAME_PIXEL_WIDTH (f); | ||
| 1449 | y_coord = FRAME_PIXEL_HEIGHT (f); | ||
| 1450 | } | ||
| 1451 | else | ||
| 1452 | { | ||
| 1453 | x_coord = FRAME_COLS (f); | ||
| 1454 | /* Center the title at frame middle. (TTY menus have | ||
| 1455 | their upper-left corner at the given position.) */ | ||
| 1456 | if (STRINGP (prompt)) | ||
| 1457 | x_coord -= SCHARS (prompt); | ||
| 1458 | y_coord = FRAME_LINES (f); | ||
| 1459 | } | ||
| 1460 | |||
| 1461 | XSETFRAME (frame, f); | ||
| 1462 | XSETINT (x, x_coord / 2); | ||
| 1463 | XSETINT (y, y_coord / 2); | ||
| 1464 | newpos = list2 (list2 (x, y), frame); | ||
| 1465 | |||
| 1466 | return Fx_popup_menu (newpos, list2 (prompt, contents)); | ||
| 1467 | } | ||
| 1468 | |||
| 1437 | DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 3, 0, | 1469 | DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 3, 0, |
| 1438 | doc: /* Pop up a dialog box and return user's selection. | 1470 | doc: /* Pop up a dialog box and return user's selection. |
| 1439 | POSITION specifies which frame to use. | 1471 | POSITION specifies which frame to use. |
| @@ -1466,24 +1498,7 @@ for instance using the window manager, then this produces a quit and | |||
| 1466 | if (EQ (position, Qt) | 1498 | if (EQ (position, Qt) |
| 1467 | || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar) | 1499 | || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar) |
| 1468 | || EQ (XCAR (position), Qtool_bar)))) | 1500 | || EQ (XCAR (position), Qtool_bar)))) |
| 1469 | { | 1501 | window = selected_window; |
| 1470 | #if 0 /* Using the frame the mouse is on may not be right. */ | ||
| 1471 | /* Use the mouse's current position. */ | ||
| 1472 | struct frame *new_f = SELECTED_FRAME (); | ||
| 1473 | Lisp_Object bar_window; | ||
| 1474 | enum scroll_bar_part part; | ||
| 1475 | Time time; | ||
| 1476 | Lisp_Object x, y; | ||
| 1477 | |||
| 1478 | (*mouse_position_hook) (&new_f, 1, &bar_window, &part, &x, &y, &time); | ||
| 1479 | |||
| 1480 | if (new_f != 0) | ||
| 1481 | XSETFRAME (window, new_f); | ||
| 1482 | else | ||
| 1483 | window = selected_window; | ||
| 1484 | #endif | ||
| 1485 | window = selected_window; | ||
| 1486 | } | ||
| 1487 | else if (CONSP (position)) | 1502 | else if (CONSP (position)) |
| 1488 | { | 1503 | { |
| 1489 | Lisp_Object tem = XCAR (position); | 1504 | Lisp_Object tem = XCAR (position); |
| @@ -1525,51 +1540,18 @@ for instance using the window manager, then this produces a quit and | |||
| 1525 | string contents, because Fredisplay may GC and relocate them. */ | 1540 | string contents, because Fredisplay may GC and relocate them. */ |
| 1526 | Fredisplay (Qt); | 1541 | Fredisplay (Qt); |
| 1527 | 1542 | ||
| 1528 | #if defined USE_X_TOOLKIT || defined USE_GTK | 1543 | /* Display the popup dialog by a terminal-specific hook ... */ |
| 1529 | if (FRAME_WINDOW_P (f)) | 1544 | if (FRAME_TERMINAL (f)->popup_dialog_hook) |
| 1530 | return xw_popup_dialog (f, header, contents); | ||
| 1531 | #endif | ||
| 1532 | #ifdef HAVE_NTGUI | ||
| 1533 | if (FRAME_W32_P (f)) | ||
| 1534 | { | 1545 | { |
| 1535 | Lisp_Object selection = w32_popup_dialog (f, header, contents); | 1546 | Lisp_Object selection |
| 1536 | 1547 | = FRAME_TERMINAL (f)->popup_dialog_hook (f, header, contents); | |
| 1548 | #ifdef HAVE_NTGUI | ||
| 1537 | if (!EQ (selection, Qunsupported__w32_dialog)) | 1549 | if (!EQ (selection, Qunsupported__w32_dialog)) |
| 1538 | return selection; | 1550 | #endif |
| 1551 | return selection; | ||
| 1539 | } | 1552 | } |
| 1540 | #endif | 1553 | /* ... or emulate it with a menu. */ |
| 1541 | #ifdef HAVE_NS | 1554 | return emulate_dialog_with_menu (f, contents); |
| 1542 | if (FRAME_NS_P (f)) | ||
| 1543 | return ns_popup_dialog (position, header, contents); | ||
| 1544 | #endif | ||
| 1545 | /* Display a menu with these alternatives | ||
| 1546 | in the middle of frame F. */ | ||
| 1547 | { | ||
| 1548 | Lisp_Object x, y, frame, newpos, prompt; | ||
| 1549 | int x_coord, y_coord; | ||
| 1550 | |||
| 1551 | prompt = Fcar (contents); | ||
| 1552 | if (FRAME_WINDOW_P (f)) | ||
| 1553 | { | ||
| 1554 | x_coord = FRAME_PIXEL_WIDTH (f); | ||
| 1555 | y_coord = FRAME_PIXEL_HEIGHT (f); | ||
| 1556 | } | ||
| 1557 | else | ||
| 1558 | { | ||
| 1559 | x_coord = FRAME_COLS (f); | ||
| 1560 | /* Center the title at frame middle. (TTY menus have their | ||
| 1561 | upper-left corner at the given position.) */ | ||
| 1562 | if (STRINGP (prompt)) | ||
| 1563 | x_coord -= SCHARS (prompt); | ||
| 1564 | y_coord = FRAME_LINES (f); | ||
| 1565 | } | ||
| 1566 | XSETFRAME (frame, f); | ||
| 1567 | XSETINT (x, x_coord / 2); | ||
| 1568 | XSETINT (y, y_coord / 2); | ||
| 1569 | newpos = list2 (list2 (x, y), frame); | ||
| 1570 | |||
| 1571 | return Fx_popup_menu (newpos, list2 (prompt, contents)); | ||
| 1572 | } | ||
| 1573 | } | 1555 | } |
| 1574 | 1556 | ||
| 1575 | void | 1557 | void |
diff --git a/src/nsmenu.m b/src/nsmenu.m index 65494cb2582..24c1189584b 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m | |||
| @@ -1428,11 +1428,10 @@ pop_down_menu (void *arg) | |||
| 1428 | 1428 | ||
| 1429 | 1429 | ||
| 1430 | Lisp_Object | 1430 | Lisp_Object |
| 1431 | ns_popup_dialog (Lisp_Object position, Lisp_Object header, Lisp_Object contents) | 1431 | ns_popup_dialog (struct frame *f, Lisp_Object header, Lisp_Object contents) |
| 1432 | { | 1432 | { |
| 1433 | id dialog; | 1433 | id dialog; |
| 1434 | Lisp_Object window, tem, title; | 1434 | Lisp_Object window, tem, title; |
| 1435 | struct frame *f; | ||
| 1436 | NSPoint p; | 1435 | NSPoint p; |
| 1437 | BOOL isQ; | 1436 | BOOL isQ; |
| 1438 | NSAutoreleasePool *pool; | 1437 | NSAutoreleasePool *pool; |
| @@ -1441,41 +1440,6 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object header, Lisp_Object contents) | |||
| 1441 | 1440 | ||
| 1442 | isQ = NILP (header); | 1441 | isQ = NILP (header); |
| 1443 | 1442 | ||
| 1444 | if (EQ (position, Qt) | ||
| 1445 | || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar) | ||
| 1446 | || EQ (XCAR (position), Qtool_bar)))) | ||
| 1447 | { | ||
| 1448 | window = selected_window; | ||
| 1449 | } | ||
| 1450 | else if (CONSP (position)) | ||
| 1451 | { | ||
| 1452 | Lisp_Object tem; | ||
| 1453 | tem = Fcar (position); | ||
| 1454 | if (XTYPE (tem) == Lisp_Cons) | ||
| 1455 | window = Fcar (Fcdr (position)); | ||
| 1456 | else | ||
| 1457 | { | ||
| 1458 | tem = Fcar (Fcdr (position)); /* EVENT_START (position) */ | ||
| 1459 | window = Fcar (tem); /* POSN_WINDOW (tem) */ | ||
| 1460 | } | ||
| 1461 | } | ||
| 1462 | else if (WINDOWP (position) || FRAMEP (position)) | ||
| 1463 | { | ||
| 1464 | window = position; | ||
| 1465 | } | ||
| 1466 | else | ||
| 1467 | window = Qnil; | ||
| 1468 | |||
| 1469 | if (FRAMEP (window)) | ||
| 1470 | f = XFRAME (window); | ||
| 1471 | else if (WINDOWP (window)) | ||
| 1472 | { | ||
| 1473 | CHECK_LIVE_WINDOW (window); | ||
| 1474 | f = XFRAME (WINDOW_FRAME (XWINDOW (window))); | ||
| 1475 | } | ||
| 1476 | else | ||
| 1477 | CHECK_WINDOW (window); | ||
| 1478 | |||
| 1479 | check_window_system (f); | 1443 | check_window_system (f); |
| 1480 | 1444 | ||
| 1481 | p.x = (int)f->left_pos + ((int)FRAME_COLUMN_WIDTH (f) * f->text_cols)/2; | 1445 | p.x = (int)f->left_pos + ((int)FRAME_COLUMN_WIDTH (f) * f->text_cols)/2; |
diff --git a/src/nsterm.h b/src/nsterm.h index 49dd9d79008..d2c42c553d9 100644 --- a/src/nsterm.h +++ b/src/nsterm.h | |||
| @@ -855,7 +855,7 @@ extern void find_and_call_menu_selection (struct frame *f, | |||
| 855 | extern Lisp_Object find_and_return_menu_selection (struct frame *f, | 855 | extern Lisp_Object find_and_return_menu_selection (struct frame *f, |
| 856 | bool keymaps, | 856 | bool keymaps, |
| 857 | void *client_data); | 857 | void *client_data); |
| 858 | extern Lisp_Object ns_popup_dialog (Lisp_Object position, Lisp_Object header, | 858 | extern Lisp_Object ns_popup_dialog (struct frame *, Lisp_Object header, |
| 859 | Lisp_Object contents); | 859 | Lisp_Object contents); |
| 860 | 860 | ||
| 861 | #define NSAPP_DATA2_RUNASSCRIPT 10 | 861 | #define NSAPP_DATA2_RUNASSCRIPT 10 |
diff --git a/src/nsterm.m b/src/nsterm.m index 295cfc5c86d..6b617be4c0d 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -4165,6 +4165,7 @@ ns_create_terminal (struct ns_display_info *dpyinfo) | |||
| 4165 | terminal->frame_raise_lower_hook = ns_frame_raise_lower; | 4165 | terminal->frame_raise_lower_hook = ns_frame_raise_lower; |
| 4166 | terminal->fullscreen_hook = ns_fullscreen_hook; | 4166 | terminal->fullscreen_hook = ns_fullscreen_hook; |
| 4167 | terminal->menu_show_hook = ns_menu_show; | 4167 | terminal->menu_show_hook = ns_menu_show; |
| 4168 | terminal->popup_dialog_hook = ns_popup_dialog; | ||
| 4168 | terminal->set_vertical_scroll_bar_hook = ns_set_vertical_scroll_bar; | 4169 | terminal->set_vertical_scroll_bar_hook = ns_set_vertical_scroll_bar; |
| 4169 | terminal->condemn_scroll_bars_hook = ns_condemn_scroll_bars; | 4170 | terminal->condemn_scroll_bars_hook = ns_condemn_scroll_bars; |
| 4170 | terminal->redeem_scroll_bar_hook = ns_redeem_scroll_bar; | 4171 | terminal->redeem_scroll_bar_hook = ns_redeem_scroll_bar; |
diff --git a/src/termhooks.h b/src/termhooks.h index 76adc539e48..7aef3ae619d 100644 --- a/src/termhooks.h +++ b/src/termhooks.h | |||
| @@ -482,6 +482,10 @@ struct terminal | |||
| 482 | Lisp_Object (*menu_show_hook) (struct frame *f, int x, int y, int menuflags, | 482 | Lisp_Object (*menu_show_hook) (struct frame *f, int x, int y, int menuflags, |
| 483 | Lisp_Object title, const char **error_name); | 483 | Lisp_Object title, const char **error_name); |
| 484 | 484 | ||
| 485 | /* This hook is called to display popup dialog. */ | ||
| 486 | Lisp_Object (*popup_dialog_hook) (struct frame *f, Lisp_Object header, | ||
| 487 | Lisp_Object contents); | ||
| 488 | |||
| 485 | /* Scroll bar hooks. */ | 489 | /* Scroll bar hooks. */ |
| 486 | 490 | ||
| 487 | /* The representation of scroll bars is determined by the code which | 491 | /* The representation of scroll bars is determined by the code which |
diff --git a/src/w32term.c b/src/w32term.c index 213cff4f138..cbaf823ae29 100644 --- a/src/w32term.c +++ b/src/w32term.c | |||
| @@ -6274,6 +6274,7 @@ w32_create_terminal (struct w32_display_info *dpyinfo) | |||
| 6274 | terminal->frame_raise_lower_hook = w32_frame_raise_lower; | 6274 | terminal->frame_raise_lower_hook = w32_frame_raise_lower; |
| 6275 | terminal->fullscreen_hook = w32fullscreen_hook; | 6275 | terminal->fullscreen_hook = w32fullscreen_hook; |
| 6276 | terminal->menu_show_hook = w32_menu_show; | 6276 | terminal->menu_show_hook = w32_menu_show; |
| 6277 | terminal->popup_dialog_hook = w32_popup_dialog; | ||
| 6277 | terminal->set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar; | 6278 | terminal->set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar; |
| 6278 | terminal->condemn_scroll_bars_hook = w32_condemn_scroll_bars; | 6279 | terminal->condemn_scroll_bars_hook = w32_condemn_scroll_bars; |
| 6279 | terminal->redeem_scroll_bar_hook = w32_redeem_scroll_bar; | 6280 | terminal->redeem_scroll_bar_hook = w32_redeem_scroll_bar; |
diff --git a/src/xterm.c b/src/xterm.c index df4ab349104..6f1807d4176 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -10533,6 +10533,9 @@ x_create_terminal (struct x_display_info *dpyinfo) | |||
| 10533 | terminal->frame_raise_lower_hook = XTframe_raise_lower; | 10533 | terminal->frame_raise_lower_hook = XTframe_raise_lower; |
| 10534 | terminal->fullscreen_hook = XTfullscreen_hook; | 10534 | terminal->fullscreen_hook = XTfullscreen_hook; |
| 10535 | terminal->menu_show_hook = x_menu_show; | 10535 | terminal->menu_show_hook = x_menu_show; |
| 10536 | #if defined (USE_X_TOOLKIT) || defined (USE_GTK) | ||
| 10537 | terminal->popup_dialog_hook = xw_popup_dialog; | ||
| 10538 | #endif | ||
| 10536 | terminal->set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar; | 10539 | terminal->set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar; |
| 10537 | terminal->condemn_scroll_bars_hook = XTcondemn_scroll_bars; | 10540 | terminal->condemn_scroll_bars_hook = XTcondemn_scroll_bars; |
| 10538 | terminal->redeem_scroll_bar_hook = XTredeem_scroll_bar; | 10541 | terminal->redeem_scroll_bar_hook = XTredeem_scroll_bar; |