diff options
| author | YAMAMOTO Mitsuharu | 2008-04-06 01:57:47 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2008-04-06 01:57:47 +0000 |
| commit | 9ef833acf43ab762ead83ec8dc5fe162d4db40c0 (patch) | |
| tree | dc19eb1f01f4799d9fcf299ea575cab04f57a6e7 | |
| parent | cc69f23aedadf9cc6463cc47b431910694467a99 (diff) | |
| download | emacs-9ef833acf43ab762ead83ec8dc5fe162d4db40c0.tar.gz emacs-9ef833acf43ab762ead83ec8dc5fe162d4db40c0.zip | |
(x_set_background_color, mac_window, x_create_tip_frame):
Use mac_set_frame_window_background instead of XSetWindowBackground.
(x_set_tool_bar_lines) [USE_MAC_TOOLBAR]:
Use mac_is_window_toolbar_visible instead of IsWindowToolbarVisible.
(x_set_name_internal) [TARGET_API_MAC_CARBON]: Use mac_set_window_title
instead of SetWindowTitleWithCFString.
(mac_update_proxy_icon) [TARGET_API_MAC_CARBON]: Remove BLOCK_INPUT.
Move function to mactoolbox.c.
(mac_update_title_bar) [TARGET_API_MAC_CARBON]:
Use mac_set_window_modified instead of SetWindowModified.
Add BLOCK_INPUT around mac_set_window_modified/mac_update_proxy_icon.
(mac_window, x_create_tip_frame): Use mac_create_frame_window.
(Fx_focus_frame): Use mac_front_non_floating_window instead of
FrontNonFloatingWindow. Use mac_activate_window instead of
ActivateWindow. Use mac_active_non_floating_window instead of
ActiveNonFloatingWindow.
(show_hourglass, hide_hourglass) [TARGET_API_MAC_CARBON]:
Use mac_show_hourglass and mac_hide_hourglass.
(compute_tip_xy) [TARGET_API_MAC_CARBON]: Use mac_get_global_mouse
instead of GetGlobalMouse.
(Fx_show_tip): Use mac_move_window/mac_size_window/mac_show_window
instead of MoveWindow/SizeWindow/ShowWindow, respectively.
Use mac_bring_window_to_front instead of BringToFront.
(Qfile_name_history) [TARGET_API_MAC_CARBON]: Move extern to
mactoolbox.c.
(Fx_file_dialog) [TARGET_API_MAC_CARBON]: Move function body to
mac_file_dialog in mactoolbox.c. Use mac_file_dialog.
(mac_nav_event_callback) [TARGET_API_MAC_CARBON]: Move function to
mactoolbox.c.
| -rw-r--r-- | src/macfns.c | 427 |
1 files changed, 35 insertions, 392 deletions
diff --git a/src/macfns.c b/src/macfns.c index 23c2fca7cb0..d66c56e6d84 100644 --- a/src/macfns.c +++ b/src/macfns.c | |||
| @@ -1347,7 +1347,7 @@ x_set_background_color (f, arg, oldval) | |||
| 1347 | BLOCK_INPUT; | 1347 | BLOCK_INPUT; |
| 1348 | XSetBackground (dpy, mac->normal_gc, bg); | 1348 | XSetBackground (dpy, mac->normal_gc, bg); |
| 1349 | XSetForeground (dpy, mac->reverse_gc, bg); | 1349 | XSetForeground (dpy, mac->reverse_gc, bg); |
| 1350 | XSetWindowBackground (dpy, FRAME_MAC_WINDOW (f), bg); | 1350 | mac_set_frame_window_background (f, bg); |
| 1351 | XSetForeground (dpy, mac->cursor_gc, bg); | 1351 | XSetForeground (dpy, mac->cursor_gc, bg); |
| 1352 | 1352 | ||
| 1353 | UNBLOCK_INPUT; | 1353 | UNBLOCK_INPUT; |
| @@ -1687,7 +1687,8 @@ x_set_tool_bar_lines (f, value, oldval) | |||
| 1687 | if (nlines) | 1687 | if (nlines) |
| 1688 | { | 1688 | { |
| 1689 | FRAME_EXTERNAL_TOOL_BAR (f) = 1; | 1689 | FRAME_EXTERNAL_TOOL_BAR (f) = 1; |
| 1690 | if (FRAME_MAC_P (f) && !IsWindowToolbarVisible (FRAME_MAC_WINDOW (f))) | 1690 | if (FRAME_MAC_P (f) |
| 1691 | && !mac_is_window_toolbar_visible (FRAME_MAC_WINDOW (f))) | ||
| 1691 | /* Make sure next redisplay shows the tool bar. */ | 1692 | /* Make sure next redisplay shows the tool bar. */ |
| 1692 | XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = Qt; | 1693 | XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = Qt; |
| 1693 | } | 1694 | } |
| @@ -1773,7 +1774,7 @@ x_set_name_internal (f, name) | |||
| 1773 | CFStringRef windowTitle = | 1774 | CFStringRef windowTitle = |
| 1774 | cfstring_create_with_utf8_cstring (SDATA (name)); | 1775 | cfstring_create_with_utf8_cstring (SDATA (name)); |
| 1775 | 1776 | ||
| 1776 | SetWindowTitleWithCFString (FRAME_MAC_WINDOW (f), windowTitle); | 1777 | mac_set_window_title (FRAME_MAC_WINDOW (f), windowTitle); |
| 1777 | CFRelease (windowTitle); | 1778 | CFRelease (windowTitle); |
| 1778 | #else | 1779 | #else |
| 1779 | Str255 windowTitle; | 1780 | Str255 windowTitle; |
| @@ -1938,98 +1939,6 @@ mac_set_font (f, arg, oldval) | |||
| 1938 | #endif | 1939 | #endif |
| 1939 | } | 1940 | } |
| 1940 | 1941 | ||
| 1941 | #if TARGET_API_MAC_CARBON | ||
| 1942 | static void | ||
| 1943 | mac_update_proxy_icon (f) | ||
| 1944 | struct frame *f; | ||
| 1945 | { | ||
| 1946 | OSStatus err; | ||
| 1947 | Lisp_Object file_name = | ||
| 1948 | XBUFFER (XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer)->filename; | ||
| 1949 | Window w = FRAME_MAC_WINDOW (f); | ||
| 1950 | AliasHandle alias = NULL; | ||
| 1951 | |||
| 1952 | BLOCK_INPUT; | ||
| 1953 | |||
| 1954 | err = GetWindowProxyAlias (w, &alias); | ||
| 1955 | if (err == errWindowDoesNotHaveProxy && !STRINGP (file_name)) | ||
| 1956 | goto out; | ||
| 1957 | |||
| 1958 | if (STRINGP (file_name)) | ||
| 1959 | { | ||
| 1960 | AEDesc desc; | ||
| 1961 | #ifdef MAC_OSX | ||
| 1962 | FSRef fref, fref_proxy; | ||
| 1963 | #else | ||
| 1964 | FSSpec fss, fss_proxy; | ||
| 1965 | #endif | ||
| 1966 | Boolean changed; | ||
| 1967 | Lisp_Object encoded_file_name = ENCODE_FILE (file_name); | ||
| 1968 | |||
| 1969 | #ifdef MAC_OSX | ||
| 1970 | err = AECoercePtr (TYPE_FILE_NAME, SDATA (encoded_file_name), | ||
| 1971 | SBYTES (encoded_file_name), typeFSRef, &desc); | ||
| 1972 | #else | ||
| 1973 | SetPortWindowPort (w); | ||
| 1974 | err = AECoercePtr (TYPE_FILE_NAME, SDATA (encoded_file_name), | ||
| 1975 | SBYTES (encoded_file_name), typeFSS, &desc); | ||
| 1976 | #endif | ||
| 1977 | if (err == noErr) | ||
| 1978 | { | ||
| 1979 | #ifdef MAC_OSX | ||
| 1980 | err = AEGetDescData (&desc, &fref, sizeof (FSRef)); | ||
| 1981 | #else | ||
| 1982 | err = AEGetDescData (&desc, &fss, sizeof (FSSpec)); | ||
| 1983 | #endif | ||
| 1984 | AEDisposeDesc (&desc); | ||
| 1985 | } | ||
| 1986 | if (err == noErr) | ||
| 1987 | { | ||
| 1988 | if (alias) | ||
| 1989 | { | ||
| 1990 | /* (FS)ResolveAlias never sets `changed' to true if | ||
| 1991 | `alias' is minimal. */ | ||
| 1992 | #ifdef MAC_OSX | ||
| 1993 | err = FSResolveAlias (NULL, alias, &fref_proxy, &changed); | ||
| 1994 | if (err == noErr) | ||
| 1995 | err = FSCompareFSRefs (&fref, &fref_proxy); | ||
| 1996 | #else | ||
| 1997 | err = ResolveAlias (NULL, alias, &fss_proxy, &changed); | ||
| 1998 | if (err == noErr) | ||
| 1999 | err = !(fss.vRefNum == fss_proxy.vRefNum | ||
| 2000 | && fss.parID == fss_proxy.parID | ||
| 2001 | && EqualString (fss.name, fss_proxy.name, | ||
| 2002 | false, true)); | ||
| 2003 | #endif | ||
| 2004 | } | ||
| 2005 | if (err != noErr || alias == NULL) | ||
| 2006 | { | ||
| 2007 | if (alias) | ||
| 2008 | DisposeHandle ((Handle) alias); | ||
| 2009 | #ifdef MAC_OSX | ||
| 2010 | err = FSNewAliasMinimal (&fref, &alias); | ||
| 2011 | #else | ||
| 2012 | err = NewAliasMinimal (&fss, &alias); | ||
| 2013 | #endif | ||
| 2014 | changed = true; | ||
| 2015 | } | ||
| 2016 | } | ||
| 2017 | if (err == noErr) | ||
| 2018 | if (changed) | ||
| 2019 | err = SetWindowProxyAlias (w, alias); | ||
| 2020 | } | ||
| 2021 | |||
| 2022 | if (alias) | ||
| 2023 | DisposeHandle ((Handle) alias); | ||
| 2024 | |||
| 2025 | if (err != noErr || !STRINGP (file_name)) | ||
| 2026 | RemoveWindowProxy (w); | ||
| 2027 | |||
| 2028 | out: | ||
| 2029 | UNBLOCK_INPUT; | ||
| 2030 | } | ||
| 2031 | #endif | ||
| 2032 | |||
| 2033 | void | 1942 | void |
| 2034 | mac_update_title_bar (f, save_match_data) | 1943 | mac_update_title_bar (f, save_match_data) |
| 2035 | struct frame *f; | 1944 | struct frame *f; |
| @@ -2051,9 +1960,11 @@ mac_update_title_bar (f, save_match_data) | |||
| 2051 | || (!MINI_WINDOW_P (w) | 1960 | || (!MINI_WINDOW_P (w) |
| 2052 | && (modified_p != !NILP (w->last_had_star)))) | 1961 | && (modified_p != !NILP (w->last_had_star)))) |
| 2053 | { | 1962 | { |
| 2054 | SetWindowModified (FRAME_MAC_WINDOW (f), | 1963 | BLOCK_INPUT; |
| 2055 | !MINI_WINDOW_P (w) && modified_p); | 1964 | mac_set_window_modified (FRAME_MAC_WINDOW (f), |
| 1965 | !MINI_WINDOW_P (w) && modified_p); | ||
| 2056 | mac_update_proxy_icon (f); | 1966 | mac_update_proxy_icon (f); |
| 1967 | UNBLOCK_INPUT; | ||
| 2057 | } | 1968 | } |
| 2058 | #endif | 1969 | #endif |
| 2059 | } | 1970 | } |
| @@ -2248,52 +2159,12 @@ static void | |||
| 2248 | mac_window (f) | 2159 | mac_window (f) |
| 2249 | struct frame *f; | 2160 | struct frame *f; |
| 2250 | { | 2161 | { |
| 2251 | Rect r; | ||
| 2252 | |||
| 2253 | BLOCK_INPUT; | 2162 | BLOCK_INPUT; |
| 2254 | 2163 | ||
| 2255 | SetRect (&r, f->left_pos, f->top_pos, | 2164 | mac_create_frame_window (f, 0); |
| 2256 | f->left_pos + FRAME_PIXEL_WIDTH (f), | ||
| 2257 | f->top_pos + FRAME_PIXEL_HEIGHT (f)); | ||
| 2258 | #if TARGET_API_MAC_CARBON | ||
| 2259 | CreateNewWindow (kDocumentWindowClass, | ||
| 2260 | kWindowStandardDocumentAttributes | ||
| 2261 | #ifdef MAC_OSX | ||
| 2262 | | kWindowToolbarButtonAttribute | ||
| 2263 | #endif | ||
| 2264 | , &r, &FRAME_MAC_WINDOW (f)); | ||
| 2265 | if (FRAME_MAC_WINDOW (f)) | ||
| 2266 | { | ||
| 2267 | SetWRefCon (FRAME_MAC_WINDOW (f), (long) f->output_data.mac); | ||
| 2268 | if (install_window_handler (FRAME_MAC_WINDOW (f)) != noErr) | ||
| 2269 | { | ||
| 2270 | DisposeWindow (FRAME_MAC_WINDOW (f)); | ||
| 2271 | FRAME_MAC_WINDOW (f) = NULL; | ||
| 2272 | } | ||
| 2273 | } | ||
| 2274 | #else /* !TARGET_API_MAC_CARBON */ | ||
| 2275 | FRAME_MAC_WINDOW (f) | ||
| 2276 | = NewCWindow (NULL, &r, "\p", false, zoomDocProc, | ||
| 2277 | (WindowRef) -1, 1, (long) f->output_data.mac); | ||
| 2278 | #endif /* !TARGET_API_MAC_CARBON */ | ||
| 2279 | /* so that update events can find this mac_output struct */ | ||
| 2280 | f->output_data.mac->mFP = f; /* point back to emacs frame */ | ||
| 2281 | |||
| 2282 | #ifndef MAC_OSX | ||
| 2283 | if (FRAME_MAC_WINDOW (f)) | ||
| 2284 | { | ||
| 2285 | ControlRef root_control; | ||
| 2286 | 2165 | ||
| 2287 | if (CreateRootControl (FRAME_MAC_WINDOW (f), &root_control) != noErr) | ||
| 2288 | { | ||
| 2289 | DisposeWindow (FRAME_MAC_WINDOW (f)); | ||
| 2290 | FRAME_MAC_WINDOW (f) = NULL; | ||
| 2291 | } | ||
| 2292 | } | ||
| 2293 | #endif | ||
| 2294 | if (FRAME_MAC_WINDOW (f)) | 2166 | if (FRAME_MAC_WINDOW (f)) |
| 2295 | XSetWindowBackground (FRAME_MAC_DISPLAY(f), FRAME_MAC_WINDOW (f), | 2167 | mac_set_frame_window_background (f, FRAME_BACKGROUND_PIXEL (f)); |
| 2296 | FRAME_BACKGROUND_PIXEL (f)); | ||
| 2297 | 2168 | ||
| 2298 | #if USE_MAC_TOOLBAR | 2169 | #if USE_MAC_TOOLBAR |
| 2299 | /* At the moment, the size of the tool bar is not yet known. We | 2170 | /* At the moment, the size of the tool bar is not yet known. We |
| @@ -2880,7 +2751,7 @@ FRAME nil means use the selected frame. */) | |||
| 2880 | if (!front_p) | 2751 | if (!front_p) |
| 2881 | { | 2752 | { |
| 2882 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | 2753 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 |
| 2883 | if (FrontNonFloatingWindow () == FRAME_MAC_WINDOW (f)) | 2754 | if (mac_front_non_floating_window () == FRAME_MAC_WINDOW (f)) |
| 2884 | SetFrontProcessWithOptions (¤t_psn, | 2755 | SetFrontProcessWithOptions (¤t_psn, |
| 2885 | kSetFrontProcessFrontWindowOnly); | 2756 | kSetFrontProcessFrontWindowOnly); |
| 2886 | else | 2757 | else |
| @@ -2889,8 +2760,8 @@ FRAME nil means use the selected frame. */) | |||
| 2889 | } | 2760 | } |
| 2890 | 2761 | ||
| 2891 | #ifdef MAC_OSX | 2762 | #ifdef MAC_OSX |
| 2892 | ActivateWindow (ActiveNonFloatingWindow (), false); | 2763 | mac_activate_window (mac_active_non_floating_window (), false); |
| 2893 | ActivateWindow (FRAME_MAC_WINDOW (f), true); | 2764 | mac_activate_window (FRAME_MAC_WINDOW (f), true); |
| 2894 | #else | 2765 | #else |
| 2895 | #if !TARGET_API_MAC_CARBON | 2766 | #if !TARGET_API_MAC_CARBON |
| 2896 | /* SelectWindow (Non-Carbon) does not issue deactivate events if the | 2767 | /* SelectWindow (Non-Carbon) does not issue deactivate events if the |
| @@ -3678,26 +3549,7 @@ show_hourglass (timer) | |||
| 3678 | 3549 | ||
| 3679 | if (FRAME_LIVE_P (f) && FRAME_MAC_P (f) | 3550 | if (FRAME_LIVE_P (f) && FRAME_MAC_P (f) |
| 3680 | && FRAME_MAC_WINDOW (f) != tip_window) | 3551 | && FRAME_MAC_WINDOW (f) != tip_window) |
| 3681 | { | 3552 | mac_show_hourglass (f); |
| 3682 | #if USE_CG_DRAWING | ||
| 3683 | mac_prepare_for_quickdraw (f); | ||
| 3684 | #endif | ||
| 3685 | if (!f->output_data.mac->hourglass_control) | ||
| 3686 | { | ||
| 3687 | Window w = FRAME_MAC_WINDOW (f); | ||
| 3688 | Rect r; | ||
| 3689 | ControlRef c; | ||
| 3690 | |||
| 3691 | GetWindowPortBounds (w, &r); | ||
| 3692 | r.left = r.right - HOURGLASS_WIDTH; | ||
| 3693 | r.bottom = r.top + HOURGLASS_HEIGHT; | ||
| 3694 | if (CreateChasingArrowsControl (w, &r, &c) == noErr) | ||
| 3695 | f->output_data.mac->hourglass_control = c; | ||
| 3696 | } | ||
| 3697 | |||
| 3698 | if (f->output_data.mac->hourglass_control) | ||
| 3699 | ShowControl (f->output_data.mac->hourglass_control); | ||
| 3700 | } | ||
| 3701 | } | 3553 | } |
| 3702 | 3554 | ||
| 3703 | hourglass_shown_p = 1; | 3555 | hourglass_shown_p = 1; |
| @@ -3723,15 +3575,8 @@ hide_hourglass () | |||
| 3723 | { | 3575 | { |
| 3724 | struct frame *f = XFRAME (frame); | 3576 | struct frame *f = XFRAME (frame); |
| 3725 | 3577 | ||
| 3726 | if (FRAME_MAC_P (f) | 3578 | if (FRAME_MAC_P (f)) |
| 3727 | /* Watch out for newly created frames. */ | 3579 | mac_hide_hourglass (f); |
| 3728 | && f->output_data.mac->hourglass_control) | ||
| 3729 | { | ||
| 3730 | #if USE_CG_DRAWING | ||
| 3731 | mac_prepare_for_quickdraw (f); | ||
| 3732 | #endif | ||
| 3733 | HideControl (f->output_data.mac->hourglass_control); | ||
| 3734 | } | ||
| 3735 | } | 3580 | } |
| 3736 | 3581 | ||
| 3737 | hourglass_shown_p = 0; | 3582 | hourglass_shown_p = 0; |
| @@ -3972,33 +3817,17 @@ x_create_tip_frame (dpyinfo, parms, text) | |||
| 3972 | 3817 | ||
| 3973 | window_prompting = x_figure_window_size (f, parms, 0); | 3818 | window_prompting = x_figure_window_size (f, parms, 0); |
| 3974 | 3819 | ||
| 3975 | { | 3820 | BLOCK_INPUT; |
| 3976 | Rect r; | ||
| 3977 | 3821 | ||
| 3978 | BLOCK_INPUT; | 3822 | mac_create_frame_window (f, 1); |
| 3979 | SetRect (&r, 0, 0, 1, 1); | 3823 | |
| 3980 | #if TARGET_API_MAC_CARBON | 3824 | if (FRAME_MAC_WINDOW (f)) |
| 3981 | if (CreateNewWindow (kHelpWindowClass, | 3825 | { |
| 3982 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | 3826 | mac_set_frame_window_background (f, FRAME_BACKGROUND_PIXEL (f)); |
| 3983 | kWindowIgnoreClicksAttribute | | 3827 | tip_window = FRAME_MAC_WINDOW (f); |
| 3984 | #endif | 3828 | } |
| 3985 | kWindowNoUpdatesAttribute | | 3829 | |
| 3986 | kWindowNoActivatesAttribute, | 3830 | UNBLOCK_INPUT; |
| 3987 | &r, &tip_window) == noErr) | ||
| 3988 | #else | ||
| 3989 | if (tip_window = NewCWindow (NULL, &r, "\p", false, plainDBox, | ||
| 3990 | NULL, false, 0L)) | ||
| 3991 | #endif | ||
| 3992 | { | ||
| 3993 | FRAME_MAC_WINDOW (f) = tip_window; | ||
| 3994 | XSetWindowBackground (FRAME_MAC_DISPLAY(f), tip_window, | ||
| 3995 | FRAME_BACKGROUND_PIXEL (f)); | ||
| 3996 | SetWRefCon (tip_window, (long) f->output_data.mac); | ||
| 3997 | /* so that update events can find this mac_output struct */ | ||
| 3998 | f->output_data.mac->mFP = f; | ||
| 3999 | } | ||
| 4000 | UNBLOCK_INPUT; | ||
| 4001 | } | ||
| 4002 | 3831 | ||
| 4003 | x_make_gc (f); | 3832 | x_make_gc (f); |
| 4004 | 3833 | ||
| @@ -4095,7 +3924,7 @@ compute_tip_xy (f, parms, dx, dy, width, height, root_x, root_y) | |||
| 4095 | 3924 | ||
| 4096 | BLOCK_INPUT; | 3925 | BLOCK_INPUT; |
| 4097 | #if TARGET_API_MAC_CARBON | 3926 | #if TARGET_API_MAC_CARBON |
| 4098 | GetGlobalMouse (&mouse_pos); | 3927 | mac_get_global_mouse (&mouse_pos); |
| 4099 | #else | 3928 | #else |
| 4100 | GetMouse (&mouse_pos); | 3929 | GetMouse (&mouse_pos); |
| 4101 | LocalToGlobal (&mouse_pos); | 3930 | LocalToGlobal (&mouse_pos); |
| @@ -4219,7 +4048,7 @@ Text larger than the specified size is clipped. */) | |||
| 4219 | BLOCK_INPUT; | 4048 | BLOCK_INPUT; |
| 4220 | compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f), | 4049 | compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f), |
| 4221 | FRAME_PIXEL_HEIGHT (f), &root_x, &root_y); | 4050 | FRAME_PIXEL_HEIGHT (f), &root_x, &root_y); |
| 4222 | MoveWindow (FRAME_MAC_WINDOW (f), root_x, root_y, false); | 4051 | mac_move_window (FRAME_MAC_WINDOW (f), root_x, root_y, false); |
| 4223 | UNBLOCK_INPUT; | 4052 | UNBLOCK_INPUT; |
| 4224 | goto start_timer; | 4053 | goto start_timer; |
| 4225 | } | 4054 | } |
| @@ -4321,10 +4150,10 @@ Text larger than the specified size is clipped. */) | |||
| 4321 | compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); | 4150 | compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); |
| 4322 | 4151 | ||
| 4323 | BLOCK_INPUT; | 4152 | BLOCK_INPUT; |
| 4324 | MoveWindow (FRAME_MAC_WINDOW (f), root_x, root_y, false); | 4153 | mac_move_window (FRAME_MAC_WINDOW (f), root_x, root_y, false); |
| 4325 | SizeWindow (FRAME_MAC_WINDOW (f), width, height, true); | 4154 | mac_size_window (FRAME_MAC_WINDOW (f), width, height, true); |
| 4326 | ShowWindow (FRAME_MAC_WINDOW (f)); | 4155 | mac_show_window (FRAME_MAC_WINDOW (f)); |
| 4327 | BringToFront (FRAME_MAC_WINDOW (f)); | 4156 | mac_bring_window_to_front (FRAME_MAC_WINDOW (f)); |
| 4328 | UNBLOCK_INPUT; | 4157 | UNBLOCK_INPUT; |
| 4329 | 4158 | ||
| 4330 | FRAME_PIXEL_WIDTH (f) = width; | 4159 | FRAME_PIXEL_WIDTH (f) = width; |
| @@ -4385,25 +4214,11 @@ Value is t if tooltip was open, nil otherwise. */) | |||
| 4385 | 4214 | ||
| 4386 | 4215 | ||
| 4387 | 4216 | ||
| 4388 | #if TARGET_API_MAC_CARBON | ||
| 4389 | /*********************************************************************** | 4217 | /*********************************************************************** |
| 4390 | File selection dialog | 4218 | File selection dialog |
| 4391 | ***********************************************************************/ | 4219 | ***********************************************************************/ |
| 4392 | 4220 | ||
| 4393 | static pascal void mac_nav_event_callback P_ ((NavEventCallbackMessage, | 4221 | #if TARGET_API_MAC_CARBON |
| 4394 | NavCBRecPtr, void *)); | ||
| 4395 | |||
| 4396 | /** | ||
| 4397 | There is a relatively standard way to do this using applescript to run | ||
| 4398 | a (choose file) method. However, this doesn't do "the right thing" | ||
| 4399 | by working only if the find-file occurred during a menu or toolbar | ||
| 4400 | click. So we must do the file dialog by hand, using the navigation | ||
| 4401 | manager. This also has more flexibility in determining the default | ||
| 4402 | directory and whether or not we are going to choose a file. | ||
| 4403 | **/ | ||
| 4404 | |||
| 4405 | extern Lisp_Object Qfile_name_history; | ||
| 4406 | |||
| 4407 | DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, | 4222 | DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, |
| 4408 | doc: /* Read file name, prompting with PROMPT in directory DIR. | 4223 | doc: /* Read file name, prompting with PROMPT in directory DIR. |
| 4409 | Use a file selection dialog. | 4224 | Use a file selection dialog. |
| @@ -4413,182 +4228,10 @@ If ONLY-DIR-P is non-nil, the user can only select directories. */) | |||
| 4413 | (prompt, dir, default_filename, mustmatch, only_dir_p) | 4228 | (prompt, dir, default_filename, mustmatch, only_dir_p) |
| 4414 | Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p; | 4229 | Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p; |
| 4415 | { | 4230 | { |
| 4416 | Lisp_Object file = Qnil; | 4231 | return mac_file_dialog (prompt, dir, default_filename, mustmatch, only_dir_p); |
| 4417 | int count = SPECPDL_INDEX (); | ||
| 4418 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; | ||
| 4419 | char filename[MAXPATHLEN]; | ||
| 4420 | static NavEventUPP mac_nav_event_callbackUPP = NULL; | ||
| 4421 | |||
| 4422 | check_mac (); | ||
| 4423 | |||
| 4424 | GCPRO6 (prompt, dir, default_filename, mustmatch, file, only_dir_p); | ||
| 4425 | CHECK_STRING (prompt); | ||
| 4426 | CHECK_STRING (dir); | ||
| 4427 | |||
| 4428 | /* Create the dialog with PROMPT as title, using DIR as initial | ||
| 4429 | directory and using "*" as pattern. */ | ||
| 4430 | dir = Fexpand_file_name (dir, Qnil); | ||
| 4431 | |||
| 4432 | { | ||
| 4433 | OSStatus status; | ||
| 4434 | NavDialogCreationOptions options; | ||
| 4435 | NavDialogRef dialogRef; | ||
| 4436 | NavTypeListHandle fileTypes = NULL; | ||
| 4437 | NavUserAction userAction; | ||
| 4438 | CFStringRef message=NULL, saveName = NULL; | ||
| 4439 | |||
| 4440 | BLOCK_INPUT; | ||
| 4441 | /* No need for a callback function because we are modal */ | ||
| 4442 | NavGetDefaultDialogCreationOptions(&options); | ||
| 4443 | options.modality = kWindowModalityAppModal; | ||
| 4444 | options.location.h = options.location.v = -1; | ||
| 4445 | options.optionFlags = kNavDefaultNavDlogOptions; | ||
| 4446 | options.optionFlags |= kNavAllFilesInPopup; /* All files allowed */ | ||
| 4447 | options.optionFlags |= kNavSelectAllReadableItem; | ||
| 4448 | options.optionFlags &= ~kNavAllowMultipleFiles; | ||
| 4449 | if (!NILP(prompt)) | ||
| 4450 | { | ||
| 4451 | message = cfstring_create_with_string (prompt); | ||
| 4452 | options.message = message; | ||
| 4453 | } | ||
| 4454 | /* Don't set the application, let it use default. | ||
| 4455 | options.clientName = CFSTR ("Emacs"); | ||
| 4456 | */ | ||
| 4457 | |||
| 4458 | if (mac_nav_event_callbackUPP == NULL) | ||
| 4459 | mac_nav_event_callbackUPP = NewNavEventUPP (mac_nav_event_callback); | ||
| 4460 | |||
| 4461 | if (!NILP (only_dir_p)) | ||
| 4462 | status = NavCreateChooseFolderDialog(&options, mac_nav_event_callbackUPP, | ||
| 4463 | NULL, NULL, &dialogRef); | ||
| 4464 | else if (NILP (mustmatch)) | ||
| 4465 | { | ||
| 4466 | /* This is a save dialog */ | ||
| 4467 | options.optionFlags |= kNavDontConfirmReplacement; | ||
| 4468 | options.actionButtonLabel = CFSTR ("Ok"); | ||
| 4469 | options.windowTitle = CFSTR ("Enter name"); | ||
| 4470 | |||
| 4471 | if (STRINGP (default_filename)) | ||
| 4472 | { | ||
| 4473 | Lisp_Object utf8 = ENCODE_UTF_8 (default_filename); | ||
| 4474 | char *begPtr = SDATA(utf8); | ||
| 4475 | char *filePtr = begPtr + SBYTES(utf8); | ||
| 4476 | while (filePtr != begPtr && !IS_DIRECTORY_SEP(filePtr[-1])) | ||
| 4477 | filePtr--; | ||
| 4478 | saveName = cfstring_create_with_utf8_cstring (filePtr); | ||
| 4479 | options.saveFileName = saveName; | ||
| 4480 | options.optionFlags |= kNavSelectDefaultLocation; | ||
| 4481 | } | ||
| 4482 | status = NavCreatePutFileDialog(&options, | ||
| 4483 | 'TEXT', kNavGenericSignature, | ||
| 4484 | mac_nav_event_callbackUPP, NULL, | ||
| 4485 | &dialogRef); | ||
| 4486 | } | ||
| 4487 | else | ||
| 4488 | { | ||
| 4489 | /* This is an open dialog*/ | ||
| 4490 | status = NavCreateChooseFileDialog(&options, fileTypes, | ||
| 4491 | mac_nav_event_callbackUPP, NULL, | ||
| 4492 | NULL, NULL, &dialogRef); | ||
| 4493 | } | ||
| 4494 | |||
| 4495 | /* Set the default location and continue*/ | ||
| 4496 | if (status == noErr) | ||
| 4497 | { | ||
| 4498 | Lisp_Object encoded_dir = ENCODE_FILE (dir); | ||
| 4499 | AEDesc defLocAed; | ||
| 4500 | |||
| 4501 | status = AECreateDesc (TYPE_FILE_NAME, SDATA (encoded_dir), | ||
| 4502 | SBYTES (encoded_dir), &defLocAed); | ||
| 4503 | if (status == noErr) | ||
| 4504 | { | ||
| 4505 | NavCustomControl(dialogRef, kNavCtlSetLocation, (void*) &defLocAed); | ||
| 4506 | AEDisposeDesc(&defLocAed); | ||
| 4507 | } | ||
| 4508 | status = NavDialogRun(dialogRef); | ||
| 4509 | } | ||
| 4510 | |||
| 4511 | if (saveName) CFRelease(saveName); | ||
| 4512 | if (message) CFRelease(message); | ||
| 4513 | |||
| 4514 | if (status == noErr) { | ||
| 4515 | userAction = NavDialogGetUserAction(dialogRef); | ||
| 4516 | switch (userAction) | ||
| 4517 | { | ||
| 4518 | case kNavUserActionNone: | ||
| 4519 | case kNavUserActionCancel: | ||
| 4520 | break; /* Treat cancel like C-g */ | ||
| 4521 | case kNavUserActionOpen: | ||
| 4522 | case kNavUserActionChoose: | ||
| 4523 | case kNavUserActionSaveAs: | ||
| 4524 | { | ||
| 4525 | NavReplyRecord reply; | ||
| 4526 | Size len; | ||
| 4527 | |||
| 4528 | status = NavDialogGetReply(dialogRef, &reply); | ||
| 4529 | if (status != noErr) | ||
| 4530 | break; | ||
| 4531 | status = AEGetNthPtr (&reply.selection, 1, TYPE_FILE_NAME, | ||
| 4532 | NULL, NULL, filename, | ||
| 4533 | sizeof (filename) - 1, &len); | ||
| 4534 | if (status == noErr) | ||
| 4535 | { | ||
| 4536 | len = min (len, sizeof (filename) - 1); | ||
| 4537 | filename[len] = '\0'; | ||
| 4538 | if (reply.saveFileName) | ||
| 4539 | { | ||
| 4540 | /* If it was a saved file, we need to add the file name */ | ||
| 4541 | if (len && len < sizeof (filename) - 1 | ||
| 4542 | && filename[len-1] != '/') | ||
| 4543 | filename[len++] = '/'; | ||
| 4544 | CFStringGetCString(reply.saveFileName, filename+len, | ||
| 4545 | sizeof (filename) - len, | ||
| 4546 | #ifdef MAC_OSX | ||
| 4547 | kCFStringEncodingUTF8 | ||
| 4548 | #else | ||
| 4549 | CFStringGetSystemEncoding () | ||
| 4550 | #endif | ||
| 4551 | ); | ||
| 4552 | } | ||
| 4553 | file = DECODE_FILE (make_unibyte_string (filename, | ||
| 4554 | strlen (filename))); | ||
| 4555 | } | ||
| 4556 | NavDisposeReply(&reply); | ||
| 4557 | } | ||
| 4558 | break; | ||
| 4559 | } | ||
| 4560 | NavDialogDispose(dialogRef); | ||
| 4561 | UNBLOCK_INPUT; | ||
| 4562 | } | ||
| 4563 | else { | ||
| 4564 | UNBLOCK_INPUT; | ||
| 4565 | /* Fall back on minibuffer if there was a problem */ | ||
| 4566 | file = Fcompleting_read (prompt, intern ("read-file-name-internal"), | ||
| 4567 | dir, mustmatch, dir, Qfile_name_history, | ||
| 4568 | default_filename, Qnil); | ||
| 4569 | } | ||
| 4570 | } | ||
| 4571 | |||
| 4572 | UNGCPRO; | ||
| 4573 | |||
| 4574 | /* Make "Cancel" equivalent to C-g. */ | ||
| 4575 | if (NILP (file)) | ||
| 4576 | Fsignal (Qquit, Qnil); | ||
| 4577 | |||
| 4578 | return unbind_to (count, file); | ||
| 4579 | } | ||
| 4580 | |||
| 4581 | |||
| 4582 | /* Need to register some event callback function for enabling drag and | ||
| 4583 | drop in Navigation Service dialogs. */ | ||
| 4584 | static pascal void | ||
| 4585 | mac_nav_event_callback (selector, parms, data) | ||
| 4586 | NavEventCallbackMessage selector; | ||
| 4587 | NavCBRecPtr parms; | ||
| 4588 | void *data ; | ||
| 4589 | { | ||
| 4590 | } | 4232 | } |
| 4591 | #endif | 4233 | #endif |
| 4234 | |||
| 4592 | 4235 | ||
| 4593 | /*********************************************************************** | 4236 | /*********************************************************************** |
| 4594 | Fonts | 4237 | Fonts |