From e0e0753505cc2efefcee16bbed99ec6b9e5bcb39 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Dj=C3=A4rv?= Date: Fri, 15 May 2015 16:21:59 +0200 Subject: [PATCH] Fix warnings on OSX 10.10. * nsfns.m (MODAL_OK_RESPONSE): New define for different OSX versions. (Fns_read_file_name): Check against MODAL_OK_RESPONSE. (compute_tip_xy): Use convertRectToScreen for OSX >= 10.7 * nsmenu.m (initWithContentRect:styleMask:backing:defer:) * nsimage.m (allocInitFromFile, setPixmapData): Only call setScalesWhenResized for OSX < 10.6. * nsterm.h (EmacsScroller): Declare scrollerWidth. * nsterm.m (ns_copy_bits): New function that does not use deprecated NSCopyBits. (ns_scroll_run, ns_shift_glyphs_for_insert): Call ns_copy_bits. (runAlertPanel): New function. (applicationShouldTerminate:): Call runAlertPanel. (initFrameFromEmacs, toggleFullScreen:): Only call useOptimizedDrawing for OSX < 10.10. (initFrameFromEmacs:): Only call allocateGState for OSX < 10.10. (windowWillUseStandardFrame:defaultFrame:): Cast arg to abs to int. (draggingEntered:): Returns NSDragOperation. (scrollerWidth): Use scrollerWidthForControlSize for OSX >= 10.7. --- src/nsfns.m | 20 ++++++++++++- src/nsimage.m | 8 +++++ src/nsmenu.m | 4 +++ src/nsterm.h | 1 + src/nsterm.m | 83 ++++++++++++++++++++++++++++++++++++++------------- 5 files changed, 95 insertions(+), 21 deletions(-) diff --git a/src/nsfns.m b/src/nsfns.m index f8863e6d40..5f584e1c1b 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -1455,6 +1455,15 @@ ns_run_file_dialog (void) ns_fd_data.panel = nil; } +#ifdef NS_IMPL_COCOA +#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_9 +#define MODAL_OK_RESPONSE NSModalResponseOK +#endif +#endif +#ifndef MODAL_OK_RESPONSE +#define MODAL_OK_RESPONSE NSOKButton +#endif + DEFUN ("ns-read-file-name", Fns_read_file_name, Sns_read_file_name, 1, 5, 0, doc: /* Use a graphical panel to read a file name, using prompt PROMPT. Optional arg DIR, if non-nil, supplies a default directory. @@ -1549,7 +1558,7 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */) while (ns_fd_data.panel != nil) [NSApp run]; - ret = (ns_fd_data.ret == NSOKButton); + ret = (ns_fd_data.ret == MODAL_OK_RESPONSE); if (ret) { @@ -2677,7 +2686,16 @@ compute_tip_xy (struct frame *f, pt.y = dpyinfo->last_mouse_motion_y; /* Convert to screen coordinates */ pt = [view convertPoint: pt toView: nil]; +#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 pt = [[view window] convertBaseToScreen: pt]; +#else + { + NSRect r = NSMakeRect (pt.x, pt.y, 0, 0); + r = [[view window] convertRectToScreen: r]; + pt.x = r.origin.x; + pt.y = r.origin.y; + } +#endif } else { diff --git a/src/nsimage.m b/src/nsimage.m index 3e90226cbf..4d01419edf 100644 --- a/src/nsimage.m +++ b/src/nsimage.m @@ -187,7 +187,11 @@ ns_set_alpha (void *img, int x, int y, unsigned char a) /* The next two lines cause the DPI of the image to be ignored. This seems to be the behavior users expect. */ +#ifdef NS_IMPL_COCOA +#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 [image setScalesWhenResized: YES]; +#endif +#endif [image setSize: NSMakeSize([imgRep pixelsWide], [imgRep pixelsHigh])]; [image setName: [NSString stringWithUTF8String: SSDATA (file)]]; @@ -353,7 +357,11 @@ ns_set_alpha (void *img, int x, int y, unsigned char a) /* The next two lines cause the DPI of the image to be ignored. This seems to be the behavior users expect. */ +#ifdef NS_IMPL_COCOA +#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 [self setScalesWhenResized: YES]; +#endif +#endif [self setSize: NSMakeSize([bmr pixelsWide], [bmr pixelsHigh])]; break; diff --git a/src/nsmenu.m b/src/nsmenu.m index 26fe26e5e0..a4c26fe82b 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -1506,7 +1506,11 @@ ns_popup_dialog (struct frame *f, Lisp_Object header, Lisp_Object contents) area.size.width = ICONSIZE; area.size.height= ICONSIZE; img = [[NSImage imageNamed: @"NSApplicationIcon"] copy]; +#ifdef NS_IMPL_COCOA +#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 [img setScalesWhenResized: YES]; +#endif +#endif [img setSize: NSMakeSize (ICONSIZE, ICONSIZE)]; imgView = [[NSImageView alloc] initWithFrame: area]; [imgView setImage: img]; diff --git a/src/nsterm.h b/src/nsterm.h index d8ffd93a71..c06b7c49a6 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -396,6 +396,7 @@ typedef float EmacsCGFloat; - condemn; - reprieve; - (bool)judge; ++ (CGFloat)scrollerWidth; @end diff --git a/src/nsterm.m b/src/nsterm.m index 6a4d0a6ad2..11656a780c 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -2093,6 +2093,18 @@ ns_clear_frame_area (struct frame *f, int x, int y, int width, int height) return; } +static void +ns_copy_bits (struct frame *f, NSRect src, NSRect dest) +{ + if (FRAME_NS_VIEW (f)) + { + ns_focus (f, &dest, 1); + [FRAME_NS_VIEW (f) scrollRect: src + by: NSMakeSize (dest.origin.x - src.origin.x, + dest.origin.y - src.origin.y)]; + ns_unfocus (f); + } +} static void ns_scroll_run (struct window *w, struct run *run) @@ -2145,11 +2157,8 @@ ns_scroll_run (struct window *w, struct run *run) { NSRect srcRect = NSMakeRect (x, from_y, width, height); NSRect dstRect = NSMakeRect (x, to_y, width, height); - NSPoint dstOrigin = NSMakePoint (x, to_y); - ns_focus (f, &dstRect, 1); - NSCopyBits (0, srcRect , dstOrigin); - ns_unfocus (f); + ns_copy_bits (f, srcRect , dstRect); } unblock_input (); @@ -2205,13 +2214,10 @@ ns_shift_glyphs_for_insert (struct frame *f, { NSRect srcRect = NSMakeRect (x, y, width, height); NSRect dstRect = NSMakeRect (x+shift_by, y, width, height); - NSPoint dstOrigin = dstRect.origin; NSTRACE (ns_shift_glyphs_for_insert); - ns_focus (f, &dstRect, 1); - NSCopyBits (0, srcRect, dstOrigin); - ns_unfocus (f); + ns_copy_bits (f, srcRect, dstRect); } @@ -4886,21 +4892,43 @@ ns_term_shutdown (int sig) EV_TRAILER ((id)nil); } +static bool +runAlertPanel(NSString *title, + NSString *msgFormat, + NSString *defaultButton, + NSString *alternateButton) +{ +#if !defined (NS_IMPL_COCOA) || \ + MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9 + return NSRunAlertPanel(title, msgFormat, defaultButton, alternateButton, nil) + == NSAlertDefaultReturn; +#else + NSAlert *alert = [[NSAlert alloc] init]; + [alert setAlertStyle: NSCriticalAlertStyle]; + [alert setMessageText: msgFormat]; + [alert addButtonWithTitle: defaultButton]; + [alert addButtonWithTitle: alternateButton]; + NSInteger ret = [alert runModal]; + [alert release]; + return ret == NSAlertFirstButtonReturn; +#endif +} + - (NSApplicationTerminateReply)applicationShouldTerminate: (id)sender { - int ret; + bool ret; if (NILP (ns_confirm_quit)) // || ns_shutdown_properly --> TO DO return NSTerminateNow; - ret = NSRunAlertPanel(ns_app_name, - @"Exit requested. Would you like to Save Buffers and Exit, or Cancel the request?", - @"Save Buffers and Exit", @"Cancel", nil); + ret = runAlertPanel(ns_app_name, + @"Exit requested. Would you like to Save Buffers and Exit, or Cancel the request?", + @"Save Buffers and Exit", @"Cancel"); - if (ret == NSAlertDefaultReturn) + if (ret) return NSTerminateNow; - else if (ret == NSAlertAlternateReturn) + else return NSTerminateCancel; return NSTerminateNow; /* just in case */ } @@ -6251,8 +6279,10 @@ if (cols > 0 && rows > 0) [win setAcceptsMouseMovedEvents: YES]; [win setDelegate: self]; +#if !defined (NS_IMPL_COCOA) || \ + MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9 [win useOptimizedDrawing: YES]; - +#endif sz.width = frame_resize_pixelwise ? 1 : FRAME_COLUMN_WIDTH (f); sz.height = frame_resize_pixelwise ? 1 : FRAME_LINE_HEIGHT (f); [win setResizeIncrements: sz]; @@ -6313,8 +6343,10 @@ if (cols > 0 && rows > 0) if ([col alphaComponent] != (EmacsCGFloat) 1.0) [win setOpaque: NO]; +#if !defined (NS_IMPL_COCOA) || \ + MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9 [self allocateGState]; - +#endif [NSApp registerServicesMenuSendTypes: ns_send_types returnTypes: nil]; @@ -6369,7 +6401,7 @@ if (cols > 0 && rows > 0) } else if (next_maximized == FULLSCREEN_HEIGHT || (next_maximized == -1 - && abs (defaultFrame.size.height - result.size.height) + && abs ((int)(defaultFrame.size.height - result.size.height)) > FRAME_LINE_HEIGHT (emacsframe))) { /* first click */ @@ -6392,7 +6424,7 @@ if (cols > 0 && rows > 0) } else if (next_maximized == FULLSCREEN_MAXIMIZED || (next_maximized == -1 - && abs (defaultFrame.size.width - result.size.width) + && abs ((int)(defaultFrame.size.width - result.size.width)) > FRAME_COLUMN_WIDTH (emacsframe))) { result = defaultFrame; /* second click */ @@ -6639,7 +6671,10 @@ if (cols > 0 && rows > 0) [fw setTitle:[w title]]; [fw setDelegate:self]; [fw setAcceptsMouseMovedEvents: YES]; +#if !defined (NS_IMPL_COCOA) || \ + MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9 [fw useOptimizedDrawing: YES]; +#endif [fw setResizeIncrements: sz]; [fw setBackgroundColor: col]; if ([col alphaComponent] != (EmacsCGFloat) 1.0) @@ -6882,7 +6917,7 @@ if (cols > 0 && rows > 0) /* NSDraggingDestination protocol methods. Actually this is not really a protocol, but a category of Object. O well... */ --(NSUInteger) draggingEntered: (id ) sender +-(NSDragOperation) draggingEntered: (id ) sender { NSTRACE (draggingEntered); return NSDragOperationGeneric; @@ -7263,7 +7298,15 @@ if (cols > 0 && rows > 0) { /* TODO: if we want to allow variable widths, this is the place to do it, however neither GNUstep nor Cocoa support it very well */ - return [NSScroller scrollerWidth]; + CGFloat r; +#if !defined (NS_IMPL_COCOA) || \ + MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 + r = [NSScroller scrollerWidth]; +#else + r = [NSScroller scrollerWidthForControlSize: NSRegularControlSize + scrollerStyle: NSScrollerStyleLegacy]; +#endif + return r; } -- 2.39.2