aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYAMAMOTO Mitsuharu2007-01-09 08:53:48 +0000
committerYAMAMOTO Mitsuharu2007-01-09 08:53:48 +0000
commit7dcebea43a35214da6861d47505e79fa11eed950 (patch)
tree17bf618ceb404c13311cf2ce4f51767f8a5e7282 /src
parentb0b2caf8cfa1f9c25693d0294d9d2800cb4bcb7e (diff)
downloademacs-7dcebea43a35214da6861d47505e79fa11eed950.tar.gz
emacs-7dcebea43a35214da6861d47505e79fa11eed950.zip
(mac_dialog_modal_filter) [MAC_OSX]: New function.
(Fx_popup_dialog) [MAC_OSX]: Use standard alert if called from Fmessage_box, Fyes_or_no_p, or Fy_or_n_p. [MAC_OS_X_VERSION_MAX_ALLOWED >= 1030] (menu_quit_handler): Use mac_quit_char_key_p.
Diffstat (limited to 'src')
-rw-r--r--src/macmenu.c121
1 files changed, 117 insertions, 4 deletions
diff --git a/src/macmenu.c b/src/macmenu.c
index 9981250979a..a70a80d32ed 100644
--- a/src/macmenu.c
+++ b/src/macmenu.c
@@ -876,6 +876,32 @@ no quit occurs and `x-popup-menu' returns nil. */)
876 876
877#ifdef HAVE_MENUS 877#ifdef HAVE_MENUS
878 878
879/* Regard ESC and C-g as Cancel even without the Cancel button. */
880
881#ifdef MAC_OSX
882static Boolean
883mac_dialog_modal_filter (dialog, event, item_hit)
884 DialogRef dialog;
885 EventRecord *event;
886 DialogItemIndex *item_hit;
887{
888 Boolean result;
889
890 result = StdFilterProc (dialog, event, item_hit);
891 if (result == false
892 && (event->what == keyDown || event->what == autoKey)
893 && ((event->message & charCodeMask) == kEscapeCharCode
894 || mac_quit_char_key_p (event->modifiers,
895 (event->message & keyCodeMask) >> 8)))
896 {
897 *item_hit = kStdCancelItemIndex;
898 return true;
899 }
900
901 return result;
902}
903#endif
904
879DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 3, 0, 905DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 3, 0,
880 doc: /* Pop up a dialog box and return user's selection. 906 doc: /* Pop up a dialog box and return user's selection.
881POSITION specifies which frame to use. 907POSITION specifies which frame to use.
@@ -961,6 +987,96 @@ for instance using the window manager, then this produces a quit and
961 but I don't want to make one now. */ 987 but I don't want to make one now. */
962 CHECK_WINDOW (window); 988 CHECK_WINDOW (window);
963 989
990#ifdef MAC_OSX
991 /* Special treatment for Fmessage_box, Fyes_or_no_p, and Fy_or_n_p. */
992 if (EQ (position, Qt)
993 && STRINGP (Fcar (contents))
994 && ((!NILP (Fequal (XCDR (contents),
995 Fcons (Fcons (build_string ("OK"), Qt), Qnil)))
996 && EQ (header, Qt))
997 || (!NILP (Fequal (XCDR (contents),
998 Fcons (Fcons (build_string ("Yes"), Qt),
999 Fcons (Fcons (build_string ("No"), Qnil),
1000 Qnil))))
1001 && NILP (header))))
1002 {
1003 OSStatus err = noErr;
1004 AlertStdCFStringAlertParamRec param;
1005 CFStringRef error_string, explanation_string;
1006 DialogRef alert;
1007 DialogItemIndex item_hit;
1008 Lisp_Object tem;
1009
1010 tem = Fstring_match (concat3 (build_string ("\\("),
1011 call0 (intern ("sentence-end")),
1012 build_string ("\\)\n")),
1013 XCAR (contents), Qnil);
1014 BLOCK_INPUT;
1015 if (NILP (tem))
1016 {
1017 error_string = cfstring_create_with_string (XCAR (contents));
1018 if (error_string == NULL)
1019 err = memFullErr;
1020 explanation_string = NULL;
1021 }
1022 else
1023 {
1024 tem = Fmatch_end (make_number (1));
1025 error_string =
1026 cfstring_create_with_string (Fsubstring (XCAR (contents),
1027 make_number (0), tem));
1028 if (error_string == NULL)
1029 err = memFullErr;
1030 else
1031 {
1032 XSETINT (tem, XINT (tem) + 1);
1033 explanation_string =
1034 cfstring_create_with_string (Fsubstring (XCAR (contents),
1035 tem, Qnil));
1036 if (explanation_string == NULL)
1037 {
1038 CFRelease (error_string);
1039 err = memFullErr;
1040 }
1041 }
1042 }
1043 if (err == noErr)
1044 err = GetStandardAlertDefaultParams (&param,
1045 kStdCFStringAlertVersionOne);
1046 if (err == noErr)
1047 {
1048 param.movable = true;
1049 param.position = kWindowAlertPositionParentWindow;
1050 if (NILP (header))
1051 {
1052 param.defaultText = CFSTR ("Yes");
1053 param.otherText = CFSTR ("No");
1054#if 0
1055 param.cancelText = CFSTR ("Cancel");
1056 param.cancelButton = kAlertStdAlertCancelButton;
1057#endif
1058 }
1059 err = CreateStandardAlert (kAlertNoteAlert, error_string,
1060 explanation_string, &param, &alert);
1061 CFRelease (error_string);
1062 if (explanation_string)
1063 CFRelease (explanation_string);
1064 }
1065 if (err == noErr)
1066 err = RunStandardAlert (alert, mac_dialog_modal_filter, &item_hit);
1067 UNBLOCK_INPUT;
1068
1069 if (err == noErr)
1070 {
1071 if (item_hit == kStdCancelItemIndex)
1072 Fsignal (Qquit, Qnil);
1073 else if (item_hit == kStdOkItemIndex)
1074 return Qt;
1075 else
1076 return Qnil;
1077 }
1078 }
1079#endif
964#ifndef HAVE_DIALOGS 1080#ifndef HAVE_DIALOGS
965 /* Display a menu with these alternatives 1081 /* Display a menu with these alternatives
966 in the middle of frame F. */ 1082 in the middle of frame F. */
@@ -1537,8 +1653,6 @@ menu_quit_handler (nextHandler, theEvent, userData)
1537 OSStatus err; 1653 OSStatus err;
1538 UInt32 keyCode; 1654 UInt32 keyCode;
1539 UInt32 keyModifiers; 1655 UInt32 keyModifiers;
1540 extern int mac_quit_char_modifiers;
1541 extern int mac_quit_char_keycode;
1542 1656
1543 err = GetEventParameter (theEvent, kEventParamKeyCode, 1657 err = GetEventParameter (theEvent, kEventParamKeyCode,
1544 typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode); 1658 typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode);
@@ -1548,8 +1662,7 @@ menu_quit_handler (nextHandler, theEvent, userData)
1548 typeUInt32, NULL, sizeof(UInt32), 1662 typeUInt32, NULL, sizeof(UInt32),
1549 NULL, &keyModifiers); 1663 NULL, &keyModifiers);
1550 1664
1551 if (err == noErr && keyCode == mac_quit_char_keycode 1665 if (err == noErr && mac_quit_char_key_p (keyModifiers, keyCode))
1552 && keyModifiers == mac_quit_char_modifiers)
1553 { 1666 {
1554 MenuRef menu = userData != 0 1667 MenuRef menu = userData != 0
1555 ? (MenuRef)userData : AcquireRootMenu (); 1668 ? (MenuRef)userData : AcquireRootMenu ();