diff --git a/src/Fl_MacOS_Sys_Menu_Bar.mm b/src/Fl_MacOS_Sys_Menu_Bar.mm index f41db31b4..8924a0a52 100644 --- a/src/Fl_MacOS_Sys_Menu_Bar.mm +++ b/src/Fl_MacOS_Sys_Menu_Bar.mm @@ -231,10 +231,9 @@ + (int) addNewItem:(const Fl_Menu_Item*)mitem menu:(NSMenu*)menu action:(SEL)sel keyEquivalent:@""]; if (mitem->labelfont() & FL_BOLD) { NSFont *boldFont = [NSFont boldSystemFontOfSize:[NSFont systemFontSize]]; + NSDictionary *attrib = [NSDictionary dictionaryWithObject:boldFont forKey:NSFontAttributeName]; NSAttributedString *attributed = - [ [ [NSAttributedString alloc] initWithString:title - attributes:@{ NSFontAttributeName: boldFont }] - autorelease]; + [ [ [NSAttributedString alloc] initWithString:title attributes:attrib] autorelease]; item.attributedTitle = attributed; } // >= 0 if mitem is in the menu items of fl_sys_menu_bar, -1 if not @@ -379,10 +378,9 @@ static void createSubMenu( NSMenu *mh, pFl_Menu_Item &mm, const Fl_Menu_Item *m menuItem = [mh itemAtIndex:cnt]; if (mitem->labelfont() & FL_BOLD) { NSFont *boldFont = [NSFont boldSystemFontOfSize:[NSFont systemFontSize]]; + NSDictionary *attrib = [NSDictionary dictionaryWithObject:boldFont forKey:NSFontAttributeName]; NSAttributedString *attributed = - [ [ [NSAttributedString alloc] initWithString:title - attributes:@{ NSFontAttributeName: boldFont }] - autorelease]; + [ [ [NSAttributedString alloc] initWithString:title attributes:attrib] autorelease]; menuItem.attributedTitle = attributed; } [menuItem setSubmenu:submenu]; diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 8ccda6dbb..524e16c75 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -47,9 +47,9 @@ #include #include -#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 || \ - MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7 -# error macOS SDK and deployment target version 10.7 or higher is required. +#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 || \ + MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6 +# error macOS SDK and deployment target version 10.6 or higher is required. // Note: change also the warning in Fl_Darwin_System_Driver::calc_mac_os_version() below #endif @@ -179,7 +179,9 @@ const NSUInteger NSWindowStyleMaskMiniaturizable = NSMiniaturizableWindowMask; const NSUInteger NSWindowStyleMaskClosable = NSClosableWindowMask; const NSUInteger NSWindowStyleMaskTitled = NSTitledWindowMask; +# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 const NSUInteger NSWindowStyleMaskFullScreen = NSFullScreenWindowMask; +#endif const NSUInteger NSEventMaskAny = NSAnyEventMask; const NSUInteger NSEventMaskSystemDefined = NSSystemDefinedMask; @@ -548,13 +550,19 @@ - (void)setSubwindowFrame; - (void)checkSubwindowFrame; - (void)waitForExpose; - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - (NSPoint)convertBaseToScreen:(NSPoint)aPoint; +#endif - (NSBitmapImageRep*)rect_to_NSBitmapImageRep:(Fl_Rect*)r; - (void)makeKeyWindow; @end -@interface FLView : NSView { +@interface FLView : NSView = MAC_OS_X_VERSION_10_7 +, NSDraggingSource +#endif +> { BOOL in_key_event; // YES means keypress is being processed by handleEvent BOOL need_handle; // YES means Fl::handle(FL_KEYBOARD,) is needed after handleEvent processing NSRange selectedRange; @@ -594,9 +602,11 @@ - (BOOL)performDragOperation:(id )sender; - (void)draggingExited:(id < NSDraggingInfo >)sender; - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal; - (void)updateTrackingAreas; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context; - (void)draggingSession:(NSDraggingSession *)session endedAtPoint:(NSPoint)screenPoint operation:(NSDragOperation)operation; +#endif - (BOOL)did_view_resolution_change; #if defined(FLTK_HAVE_PEN_SUPPORT) - (void)tabletProximity:(NSEvent *)theEvent; @@ -627,11 +637,18 @@ - (void)close // and before the FLWindow receives the final dealloc message w = NULL; } +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - (NSPoint)convertBaseToScreen:(NSPoint)aPoint { - NSRect r = [self convertRectToScreen:NSMakeRect(aPoint.x, aPoint.y, 0, 0)]; - return r.origin; + if (fl_mac_os_version >= 100700) { + NSRect r = [self convertRectToScreen:NSMakeRect(aPoint.x, aPoint.y, 0, 0)]; + return r.origin; + } + else { + return [super convertBaseToScreen:aPoint]; + } } +#endif - (FLWindow*)initWithFl_W:(Fl_Window *)flw contentRect:(NSRect)rect styleMask:(NSUInteger)windowStyle @@ -639,7 +656,7 @@ - (FLWindow*)initWithFl_W:(Fl_Window *)flw self = [super initWithContentRect:rect styleMask:windowStyle backing:NSBackingStoreBuffered defer:NO]; if (self) { w = flw; - [self setRestorable:NO]; + if (fl_mac_os_version >= 100700) [self setRestorable:NO]; } return self; } @@ -1334,7 +1351,11 @@ - (void)windowDidBecomeKey:(NSNotification *)notif FLWindow *nsw = (FLWindow*)[notif object]; Fl_Window *w = [nsw getFl_Window]; /* Restore previous fullscreen level */ - if (w->fullscreen_active() && !(nsw.styleMask & NSWindowStyleMaskFullScreen)) { + if (w->fullscreen_active() +# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 + && (fl_mac_os_version < 100700 || !(nsw.styleMask & NSWindowStyleMaskFullScreen)) +#endif + ) { [nsw setLevel:NSStatusWindowLevel]; fixup_window_levels(); } @@ -2192,27 +2213,31 @@ That situation is identified by the condition (views_use_CA && !through_drawRect @implementation FLView - (BOOL)did_view_resolution_change { - // determine whether window is mapped to a retina display - Fl_Window *window = [(FLWindow*)[self window] getFl_Window]; - Fl_Cocoa_Window_Driver *d = Fl_Cocoa_Window_Driver::driver(window); - bool previous = d->mapped_to_retina(); - NSView *view = (!views_use_CA && window->parent() && !window->as_gl_window()) ? - [fl_xid(window->top_window()) contentView] : self; - if (view) { - NSSize s = [view convertSizeToBacking:NSMakeSize(10, 10)]; // 10.7 - d->mapped_to_retina( int(s.width + 0.5) > 10 ); - } - BOOL retval = (d->wait_for_expose_value == 0 && previous != d->mapped_to_retina()); - if (retval) { - d->changed_resolution(true); -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 - if (views_use_CA && !window->as_gl_window() ) { - [self reset_aux_bitmap]; - window->redraw(); +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 + if (fl_mac_os_version >= 100700) { // determine whether window is mapped to a retina display + Fl_Window *window = [(FLWindow*)[self window] getFl_Window]; + Fl_Cocoa_Window_Driver *d = Fl_Cocoa_Window_Driver::driver(window); + bool previous = d->mapped_to_retina(); + NSView *view = (!views_use_CA && window->parent() && !window->as_gl_window()) ? + [fl_xid(window->top_window()) contentView] : self; + if (view) { + NSSize s = [view convertSizeToBacking:NSMakeSize(10, 10)]; // 10.7 + d->mapped_to_retina( int(s.width + 0.5) > 10 ); } + BOOL retval = (d->wait_for_expose_value == 0 && previous != d->mapped_to_retina()); + if (retval) { + d->changed_resolution(true); +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 + if (views_use_CA && !window->as_gl_window() ) { + [self reset_aux_bitmap]; + window->redraw(); + } #endif + } + return retval; } - return retval; +#endif + return NO; } #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 - (void)create_aux_bitmap:(CGContextRef)gc retina:(BOOL)r { @@ -2817,6 +2842,7 @@ - (NSInteger)windowLevel { return [[self window] level]; } +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context { return NSDragOperationCopy; @@ -2832,6 +2858,7 @@ - (void)draggingSession:(NSDraggingSession *)session Fl::pushed( 0 ); } } +#endif @end @@ -2922,6 +2949,36 @@ - (void)draggingSession:(NSDraggingSession *)session changed_resolution(false); NSRect crect; + if (w->fullscreen_active() && fl_mac_os_version < 100700) { + int top, bottom, left, right; + int sx, sy, sw, sh, X, Y, W, H; + + top = fullscreen_screen_top(); + bottom = fullscreen_screen_bottom(); + left = fullscreen_screen_left(); + right = fullscreen_screen_right(); + + if ((top < 0) || (bottom < 0) || (left < 0) || (right < 0)) { + top = Fl::screen_num(w->x(), w->y(), w->w(), w->h()); + bottom = top; + left = top; + right = top; + } + + Fl::screen_xywh(sx, sy, sw, sh, top); + Y = sy; + Fl::screen_xywh(sx, sy, sw, sh, bottom); + H = sy + sh - Y; + Fl::screen_xywh(sx, sy, sw, sh, left); + X = sx; + Fl::screen_xywh(sx, sy, sw, sh, right); + W = sx + sw - X; + + w->resize(X, Y, W, H); + + winstyle = NSWindowStyleMaskBorderless; + winlevel = NSStatusWindowLevel; + } float s = Fl::screen_driver()->scale(0); crect.origin.x = round(s * w->x()); // correct origin set later for subwindows crect.origin.y = main_screen_height - round(s * (w->y() + w->h())); @@ -3034,7 +3091,7 @@ - (void)draggingSession:(NSDraggingSession *)session } else { // a top-level window if ([cw canBecomeKeyWindow]) [cw makeKeyAndOrderFront:nil]; else [cw orderFront:nil]; - if (w->fullscreen_active()) { + if (w->fullscreen_active() && fl_mac_os_version >= 100700) { if (fullscreen_screen_top() >= 0) { #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12 if (fl_mac_os_version >= 101200) @@ -3060,20 +3117,22 @@ - (void)draggingSession:(NSDraggingSession *)session } +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 static BOOL fullscreen_screen_border = NO; // YES means the multi-screened window had a border before - +#endif static NSUInteger calc_win_style(Fl_Window *win); void Fl_Cocoa_Window_Driver::fullscreen_on() { pWindow->_set_fullscreen(); +# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 bool has_border = pWindow->border(); - if (fullscreen_screen_top() >= 0 && has_border) { + if (fl_mac_os_version >= 100700 && fullscreen_screen_top() >= 0 && has_border) { fullscreen_screen_border = YES; has_border = false; } - if (has_border) { + if (fl_mac_os_version >= 100700 && has_border) { NSWindow *nswin = fl_xid(pWindow); # if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_13 if (fl_mac_os_version >= 101300) { @@ -3088,9 +3147,12 @@ - (void)draggingSession:(NSDraggingSession *)session pWindow->_set_fullscreen(); } [nswin toggleFullScreen:nil]; - } else { + } else +#endif + { FLWindow *nswin = fl_xid(pWindow); - if (nswin.styleMask & NSWindowStyleMaskFullScreen) { +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 + if (fl_mac_os_version >= 100700 && (nswin.styleMask & NSWindowStyleMaskFullScreen)) { // from single-screen fullscreen to "All Screens" fullscreen, with border #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12 if (fl_mac_os_version >= 101200) { @@ -3100,7 +3162,7 @@ - (void)draggingSession:(NSDraggingSession *)session if (allscreens_on) nswin.collectionBehavior |= NSWindowCollectionBehaviorFullScreenNone; } else #endif - [nswin toggleFullScreen:nil]; + [nswin toggleFullScreen:nil]; if (*no_fullscreen_w() == 0) { *no_fullscreen_x() = x(); *no_fullscreen_y() = y(); @@ -3109,6 +3171,7 @@ - (void)draggingSession:(NSDraggingSession *)session } pWindow->_set_fullscreen(); } +#endif [nswin setStyleMask:NSWindowStyleMaskBorderless]; // 10.6 if ([nswin isKeyWindow]) { if ([nswin level] != NSStatusWindowLevel) { @@ -3184,7 +3247,8 @@ static void restore_window_title_and_icon(Fl_Window *pWindow, NSImage *icon) { void Fl_Cocoa_Window_Driver::fullscreen_off(int X, int Y, int W, int H) { NSWindow *nswin = fl_xid(pWindow); pWindow->_clear_fullscreen(); - if ([nswin styleMask] & NSWindowStyleMaskFullScreen) { +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 + if (fl_mac_os_version >= 100700 && ([nswin styleMask] & NSWindowStyleMaskFullScreen)) { # if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_13 if (fl_mac_os_version >= 101300) { NSWindow *active_tab = [[nswin tabGroup] selectedWindow]; @@ -3193,7 +3257,9 @@ static void restore_window_title_and_icon(Fl_Window *pWindow, NSImage *icon) { # endif [nswin toggleFullScreen:nil]; pWindow->resize(*no_fullscreen_x(), *no_fullscreen_y(), *no_fullscreen_w(), *no_fullscreen_h()); - } else { + } else +#endif + { // Transition from multi-screen fullscreen mode to normal mode NSInteger level = NSNormalWindowLevel; if (pWindow->modal()) level = modal_window_level(); @@ -3214,7 +3280,9 @@ static void restore_window_title_and_icon(Fl_Window *pWindow, NSImage *icon) { else [nswin orderFront:nil]; } Fl::handle(FL_FULLSCREEN, pWindow); +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 fullscreen_screen_border = NO; +#endif } @@ -4096,12 +4164,36 @@ static void createAppleMenu(void) NSPoint pt = [theEvent locationInWindow]; pt.x -= width/2; pt.y -= height/2; - NSPasteboardItem *pbItem = [[[NSPasteboardItem alloc] init] autorelease]; - [pbItem setData:(NSData*)text forType:NSPasteboardTypeString]; - NSDraggingItem *dragItem = [[[NSDraggingItem alloc] initWithPasteboardWriter:pbItem] autorelease]; - NSRect r = {pt, {CGFloat(width), CGFloat(height)}}; - [dragItem setDraggingFrame:r contents:image]; - [myview beginDraggingSessionWithItems:[NSArray arrayWithObject:dragItem] event:theEvent source:myview]; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 + if (fl_mac_os_version >= 100700) { + NSPasteboardItem *pbItem = [[[NSPasteboardItem alloc] init] autorelease]; + [pbItem setData:(NSData*)text forType:NSPasteboardTypeString]; + NSDraggingItem *dragItem = [[[NSDraggingItem alloc] initWithPasteboardWriter:pbItem] autorelease]; + NSRect r = {pt, {CGFloat(width), CGFloat(height)}}; + [dragItem setDraggingFrame:r contents:image]; + [myview beginDraggingSessionWithItems:[NSArray arrayWithObject:dragItem] event:theEvent source:myview]; + } else +#endif + { + static NSSize offset={0,0}; + // the 2 deprecation warnings can be ignored because this runs only for macOS < 10.7 +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + // deprecated in 10.13 + NSPasteboard *mypasteboard = [NSPasteboard pasteboardWithName:NSDragPboard]; + [mypasteboard declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil]; + [mypasteboard setData:(NSData*)text forType:NSPasteboardTypeString]; + [myview dragImage:image at:pt offset:offset // deprecated in 10.7 + event:theEvent pasteboard:mypasteboard + source:myview slideBack:YES]; +#pragma clang diagnostic pop + if ( w ) { + int old_event = Fl::e_number; + w->handle(Fl::e_number = FL_RELEASE); + Fl::e_number = old_event; + Fl::pushed( 0 ); + } + } CFRelease(text); [localPool release]; return true; @@ -4521,8 +4613,8 @@ static CGImageRef capture_window_titlebar(Fl_Window *win, Fl_Cocoa_Window_Driver #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 if (fl_mac_os_version >= 101400) views_use_CA = YES; #endif - if (fl_mac_os_version < 100700) - fprintf(stderr, "Warning: FLTK expects macOS version 10.7 or higher"); + if (fl_mac_os_version < 100600) + fprintf(stderr, "Warning: FLTK expects macOS version 10.6 or higher"); return fl_mac_os_version; } diff --git a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm index 41180641a..c56fd8d00 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm +++ b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm @@ -117,8 +117,10 @@ attribs[n++] = NSOpenGLPFASampleBuffers; attribs[n++] = (NSOpenGLPixelFormatAttribute)1; attribs[n++] = NSOpenGLPFASamples; attribs[n++] = (NSOpenGLPixelFormatAttribute)4; } +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 attribs[n++] = NSOpenGLPFAOpenGLProfile; attribs[n++] = (m & FL_OPENGL3) ? NSOpenGLProfileVersion3_2Core : NSOpenGLProfileVersionLegacy; +#endif } else { while (alistp[n] && n < 30) { attribs[n] = (NSOpenGLPixelFormatAttribute)alistp[n];