Mercurial > emacs
comparison src/mac.c @ 57425:0867872551d9
macterm.c (x_raise_frame): Add BLOCK_INPUT around SelectWindow
(x_lower_frame): Add BLOCK_INPUT around SendBehind
(make_mac_frame): Add BLOCK_INPUT around the making of a
terminal frame
(mac_initialize): Add BLOCK_INPUT around carbon initialization
macgui.h (mktime): Use emacs_mktime
macfns.c (Fx_file_dialog): Add BLOCK_INPUT around more code.
Make a cancel file-open dialog be like C-g.
mac.c (mktime): Use emacs_mktime
(Fdo_applescript): Add BLOCK_INPUT around do_applescript
(Fmac_paste_function): Add better error handling for carbon
cut/paste
author | Steven Tamm <steventamm@mac.com> |
---|---|
date | Sun, 10 Oct 2004 16:56:21 +0000 |
parents | 8434603cae5b |
children | 4ad0594e1ac4 ff0e824afa37 |
comparison
equal
deleted
inserted
replaced
57424:b1ed4b950258 | 57425:0867872551d9 |
---|---|
45 #undef free | 45 #undef free |
46 #undef malloc | 46 #undef malloc |
47 #undef realloc | 47 #undef realloc |
48 #undef init_process | 48 #undef init_process |
49 #include <Carbon/Carbon.h> | 49 #include <Carbon/Carbon.h> |
50 #undef mktime | |
51 #define mktime emacs_mktime | |
50 #undef free | 52 #undef free |
51 #define free unexec_free | 53 #define free unexec_free |
52 #undef malloc | 54 #undef malloc |
53 #define malloc unexec_malloc | 55 #define malloc unexec_malloc |
54 #undef realloc | 56 #undef realloc |
71 | 73 |
72 #include "lisp.h" | 74 #include "lisp.h" |
73 #include "process.h" | 75 #include "process.h" |
74 #include "sysselect.h" | 76 #include "sysselect.h" |
75 #include "systime.h" | 77 #include "systime.h" |
78 #include "blockinput.h" | |
76 | 79 |
77 Lisp_Object QCLIPBOARD; | 80 Lisp_Object QCLIPBOARD; |
78 | 81 |
79 /* An instance of the AppleScript component. */ | 82 /* An instance of the AppleScript component. */ |
80 static ComponentInstance as_scripting_component; | 83 static ComponentInstance as_scripting_component; |
2546 Lisp_Object lisp_result; | 2549 Lisp_Object lisp_result; |
2547 long status; | 2550 long status; |
2548 | 2551 |
2549 CHECK_STRING (script); | 2552 CHECK_STRING (script); |
2550 | 2553 |
2554 BLOCK_INPUT; | |
2551 status = do_applescript (SDATA (script), &result); | 2555 status = do_applescript (SDATA (script), &result); |
2556 UNBLOCK_INPUT; | |
2552 if (status) | 2557 if (status) |
2553 { | 2558 { |
2554 if (!result) | 2559 if (!result) |
2555 error ("AppleScript error %d", status); | 2560 error ("AppleScript error %d", status); |
2556 else | 2561 else |
2616 DEFUN ("mac-paste-function", Fmac_paste_function, Smac_paste_function, 0, 0, 0, | 2621 DEFUN ("mac-paste-function", Fmac_paste_function, Smac_paste_function, 0, 0, 0, |
2617 doc: /* Return the contents of the Mac clipboard as a string. */) | 2622 doc: /* Return the contents of the Mac clipboard as a string. */) |
2618 () | 2623 () |
2619 { | 2624 { |
2620 #if TARGET_API_MAC_CARBON | 2625 #if TARGET_API_MAC_CARBON |
2626 OSStatus err; | |
2621 ScrapRef scrap; | 2627 ScrapRef scrap; |
2622 ScrapFlavorFlags sff; | 2628 ScrapFlavorFlags sff; |
2623 Size s; | 2629 Size s; |
2624 int i; | 2630 int i; |
2625 char *data; | 2631 char *data; |
2626 | 2632 |
2627 if (GetCurrentScrap (&scrap) != noErr) | 2633 BLOCK_INPUT; |
2628 return Qnil; | 2634 err = GetCurrentScrap (&scrap); |
2629 | 2635 if (err == noErr) |
2630 if (GetScrapFlavorFlags (scrap, kScrapFlavorTypeText, &sff) != noErr) | 2636 err = GetScrapFlavorFlags (scrap, kScrapFlavorTypeText, &sff); |
2631 return Qnil; | 2637 if (err == noErr) |
2632 | 2638 err = GetScrapFlavorSize (scrap, kScrapFlavorTypeText, &s); |
2633 if (GetScrapFlavorSize (scrap, kScrapFlavorTypeText, &s) != noErr) | 2639 if (err == noErr && (data = (char*) alloca (s))) |
2634 return Qnil; | 2640 err = GetScrapFlavorData (scrap, kScrapFlavorTypeText, &s, data); |
2635 | 2641 UNBLOCK_INPUT; |
2636 if ((data = (char*) alloca (s)) == NULL) | 2642 if (err != noErr || s == 0) |
2637 return Qnil; | |
2638 | |
2639 if (GetScrapFlavorData (scrap, kScrapFlavorTypeText, &s, data) != noErr | |
2640 || s == 0) | |
2641 return Qnil; | 2643 return Qnil; |
2642 | 2644 |
2643 /* Emacs expects clipboard contents have Unix-style eol's */ | 2645 /* Emacs expects clipboard contents have Unix-style eol's */ |
2644 for (i = 0; i < s; i++) | 2646 for (i = 0; i < s; i++) |
2645 if (data[i] == '\r') | 2647 if (data[i] == '\r') |
2700 buf[i] = '\r'; | 2702 buf[i] = '\r'; |
2701 | 2703 |
2702 #if TARGET_API_MAC_CARBON | 2704 #if TARGET_API_MAC_CARBON |
2703 { | 2705 { |
2704 ScrapRef scrap; | 2706 ScrapRef scrap; |
2707 | |
2708 BLOCK_INPUT; | |
2705 ClearCurrentScrap (); | 2709 ClearCurrentScrap (); |
2706 if (GetCurrentScrap (&scrap) != noErr) | 2710 if (GetCurrentScrap (&scrap) != noErr) |
2707 error ("cannot get current scrap"); | 2711 { |
2712 UNBLOCK_INPUT; | |
2713 error ("cannot get current scrap"); | |
2714 } | |
2708 | 2715 |
2709 if (PutScrapFlavor (scrap, kScrapFlavorTypeText, kScrapFlavorMaskNone, len, | 2716 if (PutScrapFlavor (scrap, kScrapFlavorTypeText, kScrapFlavorMaskNone, len, |
2710 buf) != noErr) | 2717 buf) != noErr) |
2711 error ("cannot put to scrap"); | 2718 { |
2719 UNBLOCK_INPUT; | |
2720 error ("cannot put to scrap"); | |
2721 } | |
2722 UNBLOCK_INPUT; | |
2712 } | 2723 } |
2713 #else /* not TARGET_API_MAC_CARBON */ | 2724 #else /* not TARGET_API_MAC_CARBON */ |
2714 ZeroScrap (); | 2725 ZeroScrap (); |
2715 PutScrap (len, 'TEXT', buf); | 2726 PutScrap (len, 'TEXT', buf); |
2716 #endif /* not TARGET_API_MAC_CARBON */ | 2727 #endif /* not TARGET_API_MAC_CARBON */ |
2741 | 2752 |
2742 #if TARGET_API_MAC_CARBON | 2753 #if TARGET_API_MAC_CARBON |
2743 ScrapRef scrap; | 2754 ScrapRef scrap; |
2744 ScrapFlavorFlags sff; | 2755 ScrapFlavorFlags sff; |
2745 | 2756 |
2757 BLOCK_INPUT; | |
2746 if (GetCurrentScrap (&scrap) == noErr) | 2758 if (GetCurrentScrap (&scrap) == noErr) |
2747 if (GetScrapFlavorFlags (scrap, kScrapFlavorTypeText, &sff) == noErr) | 2759 if (GetScrapFlavorFlags (scrap, kScrapFlavorTypeText, &sff) == noErr) |
2748 val = Qt; | 2760 val = Qt; |
2761 UNBLOCK_INPUT; | |
2749 #else /* not TARGET_API_MAC_CARBON */ | 2762 #else /* not TARGET_API_MAC_CARBON */ |
2750 Handle my_handle; | 2763 Handle my_handle; |
2751 long rc, scrap_offset; | 2764 long rc, scrap_offset; |
2752 | 2765 |
2753 my_handle = NewHandle (0); | 2766 my_handle = NewHandle (0); |
2767 #ifdef MAC_OSX | 2780 #ifdef MAC_OSX |
2768 #undef select | 2781 #undef select |
2769 | 2782 |
2770 extern int inhibit_window_system; | 2783 extern int inhibit_window_system; |
2771 extern int noninteractive; | 2784 extern int noninteractive; |
2772 | |
2773 #include "blockinput.h" | |
2774 | 2785 |
2775 /* When Emacs is started from the Finder, SELECT always immediately | 2786 /* When Emacs is started from the Finder, SELECT always immediately |
2776 returns as if input is present when file descriptor 0 is polled for | 2787 returns as if input is present when file descriptor 0 is polled for |
2777 input. Strangely, when Emacs is run as a GUI application from the | 2788 input. Strangely, when Emacs is run as a GUI application from the |
2778 command line, it blocks in the same situation. This `wrapper' of | 2789 command line, it blocks in the same situation. This `wrapper' of |