macOS: remove a bunch of deprecation warnings
This commit is contained in:
parent
d1436f4f63
commit
bb7e1635ad
@ -17,7 +17,7 @@
|
||||
/** \file Fl_Graphics_Driver.cxx
|
||||
\brief Implementation of class Fl_Graphics_Driver.
|
||||
*/
|
||||
|
||||
#include <config.h> // for HAVE_GL
|
||||
#include <FL/Fl_Graphics_Driver.H>
|
||||
/** Points to the driver that currently receives all graphics requests */
|
||||
FL_EXPORT Fl_Graphics_Driver *fl_graphics_driver;
|
||||
|
@ -43,6 +43,17 @@ static void move_tab_cb(Fl_Widget *, void *data);
|
||||
static void merge_all_windows_cb(Fl_Widget *, void *data);
|
||||
#endif
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_13
|
||||
const NSInteger NSControlStateValueOn = NSOnState;
|
||||
const NSInteger NSControlStateValueOff = NSOffState;
|
||||
#endif
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
|
||||
const NSUInteger NSEventModifierFlagCommand = NSCommandKeyMask;
|
||||
const NSUInteger NSEventModifierFlagOption = NSAlternateKeyMask;
|
||||
const NSUInteger NSEventModifierFlagControl = NSControlKeyMask;
|
||||
const NSUInteger NSEventModifierFlagShift = NSShiftKeyMask;
|
||||
#endif
|
||||
|
||||
void Fl_MacOS_Sys_Menu_Bar_Driver::draw() {
|
||||
bar->deactivate(); // prevent Fl_Sys_Menu_Bar object from receiving events
|
||||
@ -114,7 +125,7 @@ const char *Fl_Mac_App_Menu::quit = "Quit %@";
|
||||
menu->picked(item);
|
||||
Fl::flush();
|
||||
if ( item->flags & FL_MENU_TOGGLE ) { // update the menu toggle symbol
|
||||
[self setState:(item->value() ? NSOnState : NSOffState)];
|
||||
[self setState:(item->value() ? NSControlStateValueOn : NSControlStateValueOff)];
|
||||
}
|
||||
else if ( item->flags & FL_MENU_RADIO ) { // update the menu radio symbols
|
||||
NSMenu* this_menu = [self menu];
|
||||
@ -136,7 +147,7 @@ const char *Fl_Mac_App_Menu::quit = "Quit %@";
|
||||
}
|
||||
for(int i = from; i <= to; i++) {
|
||||
NSMenuItem *nsitem = [this_menu itemAtIndex:i];
|
||||
[nsitem setState:(nsitem != self ? NSOffState : NSOnState)];
|
||||
[nsitem setState:(nsitem != self ? NSControlStateValueOff : NSControlStateValueOn)];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -162,10 +173,10 @@ const char *Fl_Mac_App_Menu::quit = "Quit %@";
|
||||
- (void) setKeyEquivalentModifierMask:(int)value
|
||||
{
|
||||
NSUInteger macMod = 0;
|
||||
if ( value & FL_META ) macMod = NSCommandKeyMask;
|
||||
if ( value & FL_SHIFT || isupper(value) ) macMod |= NSShiftKeyMask;
|
||||
if ( value & FL_ALT ) macMod |= NSAlternateKeyMask;
|
||||
if ( value & FL_CTRL ) macMod |= NSControlKeyMask;
|
||||
if ( value & FL_META ) macMod = NSEventModifierFlagCommand;
|
||||
if ( value & FL_SHIFT || isupper(value) ) macMod |= NSEventModifierFlagShift;
|
||||
if ( value & FL_ALT ) macMod |= NSEventModifierFlagOption;
|
||||
if ( value & FL_CTRL ) macMod |= NSEventModifierFlagControl;
|
||||
[super setKeyEquivalentModifierMask:macMod];
|
||||
}
|
||||
- (void) setFltkShortcut:(int)key
|
||||
@ -309,11 +320,11 @@ static void setMenuFlags( NSMenu* mh, int miCnt, const Fl_Menu_Item *m )
|
||||
if ( m->flags & FL_MENU_TOGGLE )
|
||||
{
|
||||
NSMenuItem *menuItem = [mh itemAtIndex:miCnt];
|
||||
[menuItem setState:(m->flags & FL_MENU_VALUE ? NSOnState : NSOffState)];
|
||||
[menuItem setState:(m->flags & FL_MENU_VALUE ? NSControlStateValueOn : NSControlStateValueOff)];
|
||||
}
|
||||
else if ( m->flags & FL_MENU_RADIO ) {
|
||||
NSMenuItem *menuItem = [mh itemAtIndex:miCnt];
|
||||
[menuItem setState:(m->flags & FL_MENU_VALUE ? NSOnState : NSOffState)];
|
||||
[menuItem setState:(m->flags & FL_MENU_VALUE ? NSControlStateValueOn : NSControlStateValueOff)];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,14 @@
|
||||
#define MAXFILTERS 80
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_9
|
||||
const NSInteger NSModalResponseOK = NSFileHandlingPanelOKButton;
|
||||
#endif
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
|
||||
const NSUInteger NSControlSizeRegular = NSRegularControlSize;
|
||||
#endif
|
||||
|
||||
class Fl_Quartz_Native_File_Chooser_Driver : public Fl_Native_File_Chooser_Driver {
|
||||
private:
|
||||
int _btype; // kind-of browser to show()
|
||||
@ -562,7 +570,11 @@ static char *prepareMacFilter(int count, const char *filter, char **patterns) {
|
||||
@end
|
||||
@implementation FLHiddenFilesAction
|
||||
- (void)action {
|
||||
[panel setShowsHiddenFiles:[button intValue]];
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
|
||||
if (fl_mac_os_version >= 100600) {
|
||||
[panel setShowsHiddenFiles:[button intValue]]; // 10.6
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@end
|
||||
|
||||
@ -603,7 +615,7 @@ static NSPopUpButton *createPopupAccessory(NSSavePanel *panel, const char *filte
|
||||
NSString *nstitle = [[NSString alloc] initWithUTF8String:title];
|
||||
[box setTitle:nstitle];
|
||||
[nstitle release];
|
||||
NSFont *font = [NSFont controlContentFontOfSize:NSRegularControlSize];
|
||||
NSFont *font = [NSFont controlContentFontOfSize:NSControlSizeRegular];
|
||||
[box setTitleFont:font];
|
||||
[box sizeToFit];
|
||||
// horizontally move box to fit the locale-dependent width of its title
|
||||
@ -675,12 +687,12 @@ int Fl_Quartz_Native_File_Chooser_Driver::runmodal()
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
retval = [(id)_panel runModalForDirectory:dir file:fname];
|
||||
{ // the deprecation warning can be ignored because runs only for macOS < 10.6
|
||||
retval = [_panel runModalForDirectory:dir file:fname];
|
||||
}
|
||||
[dir release];
|
||||
[preset release];
|
||||
return (retval == NSFileHandlingPanelOKButton ? 1 : 0);
|
||||
return (retval == NSModalResponseOK ? 1 : 0);
|
||||
}
|
||||
|
||||
// POST BROWSER
|
||||
|
354
src/Fl_cocoa.mm
354
src/Fl_cocoa.mm
@ -1,7 +1,7 @@
|
||||
//
|
||||
// macOS-Cocoa specific code for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
// Copyright 1998-2022 by Bill Spitzak and others.
|
||||
// Copyright 1998-2023 by Bill Spitzak and others.
|
||||
//
|
||||
// This library is free software. Distribution and use rights are outlined in
|
||||
// the file "COPYING" which should have been included with this file. If this
|
||||
@ -99,10 +99,20 @@ static int im_enabled = -1;
|
||||
# define NSPasteboardTypePDF @"com.adobe.pdf"
|
||||
# define NSPasteboardTypeString @"public.utf8-plain-text"
|
||||
#endif
|
||||
|
||||
// the next 5 deprecation warnings can be ignored because deprecated symbols
|
||||
// are used only for macOS versions where they are not deprecated
|
||||
static NSString *TIFF_pasteboard_type = (fl_mac_os_version >= 100600 ? NSPasteboardTypeTIFF : NSTIFFPboardType);
|
||||
static NSString *PDF_pasteboard_type = (fl_mac_os_version >= 100600 ? NSPasteboardTypePDF : NSPDFPboardType);
|
||||
static NSString *PICT_pasteboard_type = (fl_mac_os_version >= 100600 ? @"com.apple.pict" : NSPICTPboardType);
|
||||
static NSString *UTF8_pasteboard_type = (fl_mac_os_version >= 100600 ? NSPasteboardTypeString : NSStringPboardType);
|
||||
static NSString *fl_filenames_pboard_type =
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_13
|
||||
NSFilenamesPboardType;
|
||||
#else
|
||||
(fl_mac_os_version >= 101300 ? NSPasteboardTypeFileURL : NSFilenamesPboardType);
|
||||
#endif
|
||||
|
||||
static bool in_nsapp_run = false; // true during execution of [NSApp run]
|
||||
static NSMutableArray *dropped_files_list = nil; // list of files dropped at app launch
|
||||
typedef void (*open_cb_f_type)(const char *);
|
||||
@ -135,6 +145,47 @@ static CFStringRef kTISPropertyInputSourceType;
|
||||
typedef void (*KeyScript_type)(short);
|
||||
static KeyScript_type KeyScript;
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_13
|
||||
const NSInteger NSControlStateValueOn = NSOnState;
|
||||
const NSInteger NSControlStateValueOff = NSOffState;
|
||||
#endif
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
|
||||
const NSUInteger NSEventModifierFlagCommand = NSCommandKeyMask;
|
||||
const NSUInteger NSEventModifierFlagOption = NSAlternateKeyMask;
|
||||
const NSUInteger NSEventModifierFlagControl = NSControlKeyMask;
|
||||
const NSUInteger NSEventModifierFlagShift = NSShiftKeyMask;
|
||||
const NSUInteger NSEventModifierFlagCapsLock = NSAlphaShiftKeyMask;
|
||||
|
||||
const NSEventType NSEventTypeLeftMouseDown = NSLeftMouseDown;
|
||||
const NSEventType NSEventTypeRightMouseDown = NSRightMouseDown;
|
||||
const NSEventType NSEventTypeOtherMouseDown = NSOtherMouseDown;
|
||||
const NSEventType NSEventTypeLeftMouseUp = NSLeftMouseUp;
|
||||
const NSEventType NSEventTypeRightMouseUp = NSRightMouseUp;
|
||||
const NSEventType NSEventTypeOtherMouseUp = NSOtherMouseUp;
|
||||
const NSEventType NSEventTypeLeftMouseDragged = NSLeftMouseDragged;
|
||||
const NSEventType NSEventTypeRightMouseDragged = NSRightMouseDragged;
|
||||
const NSEventType NSEventTypeOtherMouseDragged = NSOtherMouseDragged;
|
||||
const NSEventType NSEventTypeMouseMoved = NSMouseMoved;
|
||||
const NSEventType NSEventTypeMouseEntered = NSMouseEntered;
|
||||
const NSEventType NSEventTypeMouseExited = NSMouseExited;
|
||||
const NSEventType NSEventTypeKeyUp = NSKeyUp;
|
||||
const NSEventType NSEventTypeApplicationDefined = NSApplicationDefined;
|
||||
|
||||
const NSUInteger NSWindowStyleMaskResizable = NSResizableWindowMask;
|
||||
const NSUInteger NSWindowStyleMaskBorderless = NSBorderlessWindowMask;
|
||||
const NSUInteger NSWindowStyleMaskMiniaturizable = NSMiniaturizableWindowMask;
|
||||
const NSUInteger NSWindowStyleMaskClosable = NSClosableWindowMask;
|
||||
const NSUInteger NSWindowStyleMaskTitled = NSTitledWindowMask;
|
||||
|
||||
const NSUInteger NSEventMaskAny = NSAnyEventMask;
|
||||
const NSUInteger NSEventMaskSystemDefined = NSSystemDefinedMask;
|
||||
|
||||
# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||
const NSUInteger NSBitmapFormatAlphaFirst = NSAlphaFirstBitmapFormat;
|
||||
const NSUInteger NSBitmapFormatAlphaNonpremultiplied = NSAlphaNonpremultipliedBitmapFormat;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Mac keyboard lookup table
|
||||
@ -147,11 +198,11 @@ static unsigned short* macKeyLookUp = NULL;
|
||||
static unsigned int mods_to_e_state( NSUInteger mods )
|
||||
{
|
||||
unsigned int state = 0;
|
||||
if ( mods & NSCommandKeyMask ) state |= FL_META;
|
||||
if ( mods & NSAlternateKeyMask ) state |= FL_ALT;
|
||||
if ( mods & NSControlKeyMask ) state |= FL_CTRL;
|
||||
if ( mods & NSShiftKeyMask ) state |= FL_SHIFT;
|
||||
if ( mods & NSAlphaShiftKeyMask ) state |= FL_CAPS_LOCK;
|
||||
if ( mods & NSEventModifierFlagCommand ) state |= FL_META;
|
||||
if ( mods & NSEventModifierFlagOption ) state |= FL_ALT;
|
||||
if ( mods & NSEventModifierFlagControl ) state |= FL_CTRL;
|
||||
if ( mods & NSEventModifierFlagShift ) state |= FL_SHIFT;
|
||||
if ( mods & NSEventModifierFlagCapsLock ) state |= FL_CAPS_LOCK;
|
||||
unsigned int ret = ( Fl::e_state & 0xff000000 ) | state;
|
||||
Fl::e_state = ret;
|
||||
//printf( "State 0x%08x (%04x)\n", Fl::e_state, mods );
|
||||
@ -363,7 +414,7 @@ void* DataReady::DataReadyThread(void *o)
|
||||
{ return(NULL); } // just exit
|
||||
DEBUGMSG("CHILD THREAD: DATA IS READY\n");
|
||||
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
|
||||
NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined
|
||||
NSEvent *event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
|
||||
location:NSMakePoint(0,0)
|
||||
modifierFlags:0
|
||||
timestamp:0
|
||||
@ -435,8 +486,10 @@ void Fl_Darwin_System_Driver::remove_fd(int n)
|
||||
int Fl_Darwin_System_Driver::ready()
|
||||
|
||||
{
|
||||
NSEvent *retval = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0]
|
||||
inMode:NSDefaultRunLoopMode dequeue:NO];
|
||||
NSEvent *retval = [NSApp nextEventMatchingMask:NSEventMaskAny
|
||||
untilDate:[NSDate dateWithTimeIntervalSinceNow:0]
|
||||
inMode:NSDefaultRunLoopMode
|
||||
dequeue:NO];
|
||||
return retval != nil;
|
||||
}
|
||||
|
||||
@ -468,9 +521,13 @@ static void processFLTKEvent(void) {
|
||||
*/
|
||||
void Fl_Cocoa_Screen_Driver::breakMacEventLoop()
|
||||
{
|
||||
NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined location:NSMakePoint(0,0)
|
||||
NSEvent *event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
|
||||
location:NSMakePoint(0,0)
|
||||
modifierFlags:0 timestamp:0
|
||||
windowNumber:0 context:NULL subtype:FLTKTimerEvent data1:0 data2:0];
|
||||
windowNumber:0 context:NULL
|
||||
subtype:FLTKTimerEvent
|
||||
data1:0
|
||||
data2:0];
|
||||
[NSApp postEvent:event atStart:NO];
|
||||
}
|
||||
|
||||
@ -762,7 +819,7 @@ static int do_queued_events( double time = 0.0 )
|
||||
|
||||
fl_unlock_function();
|
||||
NSEvent *event;
|
||||
while ( (event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
||||
while ( (event = [NSApp nextEventMatchingMask:NSEventMaskAny
|
||||
untilDate:[NSDate dateWithTimeIntervalSinceNow:time]
|
||||
inMode:NSDefaultRunLoopMode
|
||||
dequeue:YES]) != nil ) {
|
||||
@ -783,7 +840,7 @@ double Fl_Darwin_System_Driver::wait(double time_to_wait)
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
time_to_wait = Fl_System_Driver::wait(time_to_wait);
|
||||
|
||||
// the deprecation warnings can be ignored because they run only for macOS < 10.11
|
||||
if (fl_mac_os_version < 101100) NSDisableScreenUpdates(); // 10.3 Makes updates to all windows appear as a single event
|
||||
Fl::flush();
|
||||
if (fl_mac_os_version < 101100) NSEnableScreenUpdates(); // 10.3
|
||||
@ -992,21 +1049,23 @@ static void cocoaMouseHandler(NSEvent *theEvent)
|
||||
int sendEvent = 0;
|
||||
|
||||
NSEventType etype = [theEvent type];
|
||||
if (etype == NSLeftMouseDown || etype == NSRightMouseDown || etype == NSOtherMouseDown) {
|
||||
if (etype == NSEventTypeLeftMouseDown || etype == NSEventTypeRightMouseDown ||
|
||||
etype == NSEventTypeOtherMouseDown) {
|
||||
if (btn == 1) Fl::e_state |= FL_BUTTON1;
|
||||
else if (btn == 3) Fl::e_state |= FL_BUTTON2;
|
||||
else if (btn == 2) Fl::e_state |= FL_BUTTON3;
|
||||
}
|
||||
else if (etype == NSLeftMouseUp || etype == NSRightMouseUp || etype == NSOtherMouseUp) {
|
||||
else if (etype == NSEventTypeLeftMouseUp || etype == NSEventTypeRightMouseUp ||
|
||||
etype == NSEventTypeOtherMouseUp) {
|
||||
if (btn == 1) Fl::e_state &= ~FL_BUTTON1;
|
||||
else if (btn == 3) Fl::e_state &= ~FL_BUTTON2;
|
||||
else if (btn == 2) Fl::e_state &= ~FL_BUTTON3;
|
||||
}
|
||||
|
||||
switch ( etype ) {
|
||||
case NSLeftMouseDown:
|
||||
case NSRightMouseDown:
|
||||
case NSOtherMouseDown:
|
||||
case NSEventTypeLeftMouseDown:
|
||||
case NSEventTypeRightMouseDown:
|
||||
case NSEventTypeOtherMouseDown:
|
||||
sendEvent = FL_PUSH;
|
||||
Fl::e_is_click = 1;
|
||||
px = (int)pos.x; py = (int)pos.y;
|
||||
@ -1015,23 +1074,23 @@ static void cocoaMouseHandler(NSEvent *theEvent)
|
||||
else
|
||||
Fl::e_clicks = 0;
|
||||
// fall through
|
||||
case NSLeftMouseUp:
|
||||
case NSRightMouseUp:
|
||||
case NSOtherMouseUp:
|
||||
case NSEventTypeLeftMouseUp:
|
||||
case NSEventTypeRightMouseUp:
|
||||
case NSEventTypeOtherMouseUp:
|
||||
if ( !window ) break;
|
||||
if ( !sendEvent ) {
|
||||
sendEvent = FL_RELEASE;
|
||||
}
|
||||
Fl::e_keysym = keysym[ btn ];
|
||||
// fall through
|
||||
case NSMouseMoved:
|
||||
case NSEventTypeMouseMoved:
|
||||
if ( !sendEvent ) {
|
||||
sendEvent = FL_MOVE;
|
||||
}
|
||||
// fall through
|
||||
case NSLeftMouseDragged:
|
||||
case NSRightMouseDragged:
|
||||
case NSOtherMouseDragged: {
|
||||
case NSEventTypeLeftMouseDragged:
|
||||
case NSEventTypeRightMouseDragged:
|
||||
case NSEventTypeOtherMouseDragged: {
|
||||
if ( !sendEvent ) {
|
||||
sendEvent = FL_MOVE; // Fl::handle will convert into FL_DRAG
|
||||
if (fabs(pos.x-px)>5 || fabs(pos.y-py)>5)
|
||||
@ -1055,10 +1114,10 @@ static void cocoaMouseHandler(NSEvent *theEvent)
|
||||
Fl::handle( sendEvent, window );
|
||||
}
|
||||
break;
|
||||
case NSMouseEntered :
|
||||
case NSEventTypeMouseEntered :
|
||||
Fl::handle(FL_ENTER, window);
|
||||
break;
|
||||
case NSMouseExited :
|
||||
case NSEventTypeMouseExited :
|
||||
Fl::handle(FL_LEAVE, window);
|
||||
break;
|
||||
default:
|
||||
@ -1647,7 +1706,7 @@ void Fl_Darwin_System_Driver::open_callback(void (*cb)(const char *)) {
|
||||
return;
|
||||
|
||||
NSEventType type = [theEvent type];
|
||||
if (type == NSLeftMouseDown) {
|
||||
if (type == NSEventTypeLeftMouseDown) {
|
||||
fl_lock_function();
|
||||
Fl_Window *grab = Fl::grab();
|
||||
if (grab) {
|
||||
@ -1659,12 +1718,12 @@ void Fl_Darwin_System_Driver::open_callback(void (*cb)(const char *)) {
|
||||
}
|
||||
}
|
||||
fl_unlock_function();
|
||||
} else if (type == NSApplicationDefined) {
|
||||
} else if (type == NSEventTypeApplicationDefined) {
|
||||
if ([theEvent subtype] == FLTKDataReadyEvent) {
|
||||
processFLTKEvent();
|
||||
}
|
||||
return;
|
||||
} else if (type == NSKeyUp) {
|
||||
} else if (type == NSEventTypeKeyUp) {
|
||||
// The default sendEvent turns key downs into performKeyEquivalent when
|
||||
// modifiers are down, but swallows the key up if the modifiers include
|
||||
// command. This one makes all modifiers consistent by always sending key ups.
|
||||
@ -1735,13 +1794,16 @@ void Fl_Cocoa_Screen_Driver::open_display_platform() {
|
||||
[NSApp finishLaunching];
|
||||
// Unbundled app may require this so delegate receives applicationDidFinishLaunching:
|
||||
// even if doc states this is sent at the end of finishLaunching.
|
||||
if (!is_bundled()) [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:NO];
|
||||
if (!is_bundled()) [NSApp nextEventMatchingMask:NSEventMaskAny
|
||||
untilDate:nil
|
||||
inMode:NSDefaultRunLoopMode
|
||||
dequeue:NO];
|
||||
}
|
||||
}
|
||||
|
||||
// empty the event queue but keep system events for drag&drop of files at launch
|
||||
NSEvent *ign_event;
|
||||
do ign_event = [NSApp nextEventMatchingMask:(NSAnyEventMask & ~NSSystemDefinedMask)
|
||||
do ign_event = [NSApp nextEventMatchingMask:(NSEventMaskAny & ~NSEventMaskSystemDefined)
|
||||
untilDate:[NSDate dateWithTimeIntervalSinceNow:0]
|
||||
inMode:NSDefaultRunLoopMode
|
||||
dequeue:YES];
|
||||
@ -1810,7 +1872,7 @@ void Fl_Cocoa_Screen_Driver::enable_im() {
|
||||
[NSApp updateWindows]; // triggers [FLAppDelegate applicationDidUpdate]
|
||||
}
|
||||
else
|
||||
KeyScript(smKeyEnableKybds);
|
||||
KeyScript(-7/*smKeyEnableKybds*/);
|
||||
}
|
||||
|
||||
void Fl_Cocoa_Screen_Driver::disable_im() {
|
||||
@ -1839,7 +1901,8 @@ static int get_window_frame_sizes(Fl_Window *win, int *pbx, int *pby) {
|
||||
if (!top) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSRect inside = { {20,20}, {100,100} };
|
||||
NSRect outside = [NSWindow frameRectForContentRect:inside styleMask:NSTitledWindowMask];
|
||||
NSRect outside = [NSWindow frameRectForContentRect:inside
|
||||
styleMask:NSWindowStyleMaskTitled];
|
||||
left = int(outside.origin.x - inside.origin.x);
|
||||
bottom = int(outside.origin.y - inside.origin.y);
|
||||
top = int(outside.size.height - inside.size.height) - bottom;
|
||||
@ -2337,9 +2400,9 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
|
||||
BOOL handled;
|
||||
NSUInteger mods = [theEvent modifierFlags];
|
||||
Fl_Window *w = [(FLWindow*)[theEvent window] getFl_Window];
|
||||
if ( (mods & NSControlKeyMask) || (mods & NSCommandKeyMask) ) {
|
||||
if ( (mods & NSEventModifierFlagControl) || (mods & NSEventModifierFlagCommand) ) {
|
||||
NSString *s = [theEvent characters];
|
||||
if ( (mods & NSShiftKeyMask) && (mods & NSCommandKeyMask) ) {
|
||||
if ( (mods & NSEventModifierFlagShift) && (mods & NSEventModifierFlagCommand) ) {
|
||||
s = [s uppercaseString]; // US keyboards return lowercase letter in s if cmd-shift-key is hit
|
||||
}
|
||||
[FLView prepareEtext:s];
|
||||
@ -2539,15 +2602,38 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
|
||||
pboard = [sender draggingPasteboard];
|
||||
update_e_xy_and_e_xy_root([self window]);
|
||||
if (DragData) { free(DragData); DragData = NULL; }
|
||||
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
|
||||
CFArrayRef files = (CFArrayRef)[pboard propertyListForType:NSFilenamesPboardType];
|
||||
CFStringRef all = CFStringCreateByCombiningStrings(NULL, files, CFSTR("\n"));
|
||||
int l = (int)CFStringGetMaximumSizeForEncoding(CFStringGetLength(all), kCFStringEncodingUTF8);
|
||||
DragData = (char *)malloc(l + 1);
|
||||
CFStringGetCString(all, DragData, l + 1, kCFStringEncodingUTF8);
|
||||
CFRelease(all);
|
||||
}
|
||||
else if ( [[pboard types] containsObject:UTF8_pasteboard_type] ) {
|
||||
if ([[pboard types] containsObject:fl_filenames_pboard_type]) {
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_13
|
||||
if (fl_mac_os_version >= 101300) {
|
||||
NSArray *a = [pboard readObjectsForClasses:[NSArray arrayWithObject:[NSURL class]]
|
||||
options:nil]; // 10.6
|
||||
NSEnumerator *enumerator = [a objectEnumerator];
|
||||
NSURL *url;
|
||||
while ((url = (NSURL*)[enumerator nextObject]) != nil) {
|
||||
const char *p = [url fileSystemRepresentation]; // 10.9
|
||||
if (!DragData) {
|
||||
DragData = strdup(p);
|
||||
} else {
|
||||
int l = strlen(DragData) + strlen(p) + 2;
|
||||
char *drag2 = (char*)malloc(l);
|
||||
snprintf(drag2, l, "%s\n%s", DragData, p);
|
||||
free(DragData);
|
||||
DragData = drag2;
|
||||
}
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
CFArrayRef files = (CFArrayRef)[pboard
|
||||
propertyListForType:fl_filenames_pboard_type];
|
||||
CFStringRef all = CFStringCreateByCombiningStrings(NULL, files, CFSTR("\n"));
|
||||
int l = (int)CFStringGetMaximumSizeForEncoding(CFStringGetLength(all),
|
||||
kCFStringEncodingUTF8);
|
||||
DragData = (char *)malloc(l + 1);
|
||||
CFStringGetCString(all, DragData, l + 1, kCFStringEncodingUTF8);
|
||||
CFRelease(all);
|
||||
}
|
||||
} else if ([[pboard types] containsObject:UTF8_pasteboard_type]) {
|
||||
NSData *data = [pboard dataForType:UTF8_pasteboard_type];
|
||||
DragData = (char *)malloc([data length] + 1);
|
||||
[data getBytes:DragData length:[data length]];
|
||||
@ -2873,11 +2959,12 @@ void Fl_Cocoa_Window_Driver::makeWindow()
|
||||
show_iconic(0);
|
||||
}
|
||||
if (w->border()) {
|
||||
winstyle = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask;
|
||||
winstyle = (NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
|
||||
NSWindowStyleMaskMiniaturizable);
|
||||
if (is_resizable())
|
||||
winstyle |= NSResizableWindowMask;
|
||||
winstyle |= NSWindowStyleMaskResizable;
|
||||
} else {
|
||||
winstyle = NSBorderlessWindowMask;
|
||||
winstyle = NSWindowStyleMaskBorderless;
|
||||
}
|
||||
if (show_iconic() && !w->parent()) { // prevent window from being out of work area when created iconized
|
||||
int sx, sy, sw, sh;
|
||||
@ -2897,7 +2984,7 @@ void Fl_Cocoa_Window_Driver::makeWindow()
|
||||
}
|
||||
}
|
||||
if (w->modal()) {
|
||||
winstyle &= ~NSMiniaturizableWindowMask;
|
||||
winstyle &= ~NSWindowStyleMaskMiniaturizable;
|
||||
winlevel = modal_window_level();
|
||||
}
|
||||
else if (w->non_modal()) {
|
||||
@ -2949,7 +3036,7 @@ void Fl_Cocoa_Window_Driver::makeWindow()
|
||||
|
||||
w->resize(X, Y, W, H);
|
||||
|
||||
winstyle = NSBorderlessWindowMask;
|
||||
winstyle = NSWindowStyleMaskBorderless;
|
||||
winlevel = NSStatusWindowLevel;
|
||||
}
|
||||
float s = Fl::screen_driver()->scale(0);
|
||||
@ -2963,8 +3050,9 @@ void Fl_Cocoa_Window_Driver::makeWindow()
|
||||
[cw setFrameOrigin:crect.origin];
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
|
||||
if (fl_mac_os_version >= 101200) {
|
||||
if (!w->parent() && (winstyle & NSTitledWindowMask) && (winstyle & NSResizableWindowMask)
|
||||
&& !w->modal() && !w->non_modal() && Fl_MacOS_Sys_Menu_Bar_Driver::window_menu_style() > Fl_Sys_Menu_Bar::tabbing_mode_none) {
|
||||
if (!w->parent() && (winstyle & NSWindowStyleMaskTitled) &&
|
||||
(winstyle & NSWindowStyleMaskResizable) && !w->modal() && !w->non_modal() &&
|
||||
(Fl_MacOS_Sys_Menu_Bar_Driver::window_menu_style() > Fl_Sys_Menu_Bar::tabbing_mode_none)) {
|
||||
if (Fl_MacOS_Sys_Menu_Bar_Driver::window_menu_style() == Fl_Sys_Menu_Bar::tabbing_mode_preferred)
|
||||
[cw setTabbingMode:NSWindowTabbingModePreferred];
|
||||
else [cw setTabbingMode:NSWindowTabbingModeAutomatic];
|
||||
@ -3004,7 +3092,7 @@ void Fl_Cocoa_Window_Driver::makeWindow()
|
||||
q_set_window_title(cw, w->label(), w->iconlabel());
|
||||
NSImage *icon = icon_image; // is a window or default icon present?
|
||||
if (!icon) icon = ((Fl_Cocoa_Screen_Driver*)Fl::screen_driver())->default_icon;
|
||||
if (icon && (winstyle & NSTitledWindowMask) && w->label() && strlen(w->label())>0) {
|
||||
if (icon && (winstyle & NSWindowStyleMaskTitled) && w->label() && strlen(w->label()) > 0) {
|
||||
[cw setRepresentedFilename:[NSString stringWithFormat:@"/%@", [cw title]]];
|
||||
NSButton *icon_button = [cw standardWindowButton:NSWindowDocumentIconButton];
|
||||
if (icon_button) {
|
||||
@ -3029,7 +3117,8 @@ void Fl_Cocoa_Window_Driver::makeWindow()
|
||||
[cw setAlphaValue:0.97];
|
||||
}
|
||||
// Install DnD handlers
|
||||
[myview registerForDraggedTypes:[NSArray arrayWithObjects:UTF8_pasteboard_type, NSFilenamesPboardType, nil]];
|
||||
[myview registerForDraggedTypes:[NSArray arrayWithObjects:UTF8_pasteboard_type,
|
||||
fl_filenames_pboard_type, nil]];
|
||||
|
||||
if (size_range_set()) size_range();
|
||||
|
||||
@ -3083,7 +3172,7 @@ void Fl_Cocoa_Window_Driver::fullscreen_on() {
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
|
||||
if (fl_mac_os_version >= 100600) {
|
||||
FLWindow *nswin = fl_xid(pWindow);
|
||||
[nswin setStyleMask:NSBorderlessWindowMask]; // 10.6
|
||||
[nswin setStyleMask:NSWindowStyleMaskBorderless]; // 10.6
|
||||
if ([nswin isKeyWindow]) {
|
||||
if ([nswin level] != NSStatusWindowLevel) {
|
||||
[nswin setLevel:NSStatusWindowLevel];
|
||||
@ -3126,10 +3215,10 @@ void Fl_Cocoa_Window_Driver::fullscreen_on() {
|
||||
static NSUInteger calc_win_style(Fl_Window *win) {
|
||||
NSUInteger winstyle;
|
||||
if (win->border() && !win->fullscreen_active()) {
|
||||
winstyle = NSTitledWindowMask | NSClosableWindowMask;
|
||||
if (win->resizable()) winstyle |= NSResizableWindowMask;
|
||||
if (!win->modal()) winstyle |= NSMiniaturizableWindowMask;
|
||||
} else winstyle = NSBorderlessWindowMask;
|
||||
winstyle = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable;
|
||||
if (win->resizable()) winstyle |= NSWindowStyleMaskResizable;
|
||||
if (!win->modal()) winstyle |= NSWindowStyleMaskMiniaturizable;
|
||||
} else winstyle = NSWindowStyleMaskBorderless;
|
||||
return winstyle;
|
||||
}
|
||||
|
||||
@ -3137,7 +3226,8 @@ static void restore_window_title_and_icon(Fl_Window *pWindow, NSImage *icon) {
|
||||
FLWindow *nswin = fl_xid(pWindow);
|
||||
q_set_window_title(nswin, pWindow->label(), pWindow->iconlabel());
|
||||
if (!icon) icon = ((Fl_Cocoa_Screen_Driver*)Fl::screen_driver())->default_icon;
|
||||
if (icon && ([nswin styleMask] & NSTitledWindowMask) && pWindow->label() && strlen(pWindow->label())>0) {
|
||||
if (icon && ([nswin styleMask] & NSWindowStyleMaskTitled) && pWindow->label() &&
|
||||
(strlen(pWindow->label()) > 0)) {
|
||||
NSButton *icon_button = [nswin standardWindowButton:NSWindowDocumentIconButton];
|
||||
if (icon_button) {
|
||||
[icon setSize:[icon_button frame].size];
|
||||
@ -3344,7 +3434,8 @@ void Fl_Cocoa_Window_Driver::make_current()
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
NSGraphicsContext *nsgc = through_drawRect ? [NSGraphicsContext currentContext] : [NSGraphicsContext graphicsContextWithWindow:fl_window];
|
||||
NSGraphicsContext *nsgc = (through_drawRect ? [NSGraphicsContext currentContext] :
|
||||
[NSGraphicsContext graphicsContextWithWindow:fl_window]);
|
||||
static SEL gc_sel = fl_mac_os_version >= 101000 ? @selector(CGContext) : @selector(graphicsPort);
|
||||
gc = (CGContextRef)[nsgc performSelector:gc_sel];
|
||||
}
|
||||
@ -3424,7 +3515,8 @@ static NSBitmapImageRep *pdf_to_nsbitmapimagerep(NSData *pdfdata) {
|
||||
#endif
|
||||
{
|
||||
[image lockFocus];
|
||||
bitmap = [bitmap initWithFocusedViewRect:dest_r]; // deprecated 10.14
|
||||
// the deprecation warning at 10.14 can be ignored because runs only for macOS < 10.9
|
||||
bitmap = [bitmap initWithFocusedViewRect:dest_r];
|
||||
[image unlockFocus];
|
||||
}
|
||||
[bitmap setSize:[image size]];
|
||||
@ -3518,11 +3610,10 @@ static int get_plain_text_from_clipboard(int clipboard)
|
||||
char *aux_c = NULL;
|
||||
if (![found isEqualToString:UTF8_pasteboard_type]) {
|
||||
NSString *auxstring;
|
||||
auxstring = (NSString *)CFStringCreateWithBytes(NULL,
|
||||
(const UInt8*)[data bytes],
|
||||
[data length],
|
||||
[found isEqualToString:@"public.utf16-plain-text"] ? kCFStringEncodingUnicode : kCFStringEncodingMacRoman,
|
||||
false);
|
||||
auxstring = (NSString *)CFStringCreateWithBytes(NULL, (const UInt8*)[data bytes],
|
||||
[data length],
|
||||
([found isEqualToString:@"public.utf16-plain-text"] ?
|
||||
kCFStringEncodingUnicode : kCFStringEncodingMacRoman), false);
|
||||
aux_c = fl_strdup([auxstring UTF8String]);
|
||||
[auxstring release];
|
||||
len = strlen(aux_c) + 1;
|
||||
@ -3671,18 +3762,21 @@ static NSImage *CGBitmapContextToNSImage(CGContextRef c)
|
||||
else
|
||||
#endif
|
||||
{
|
||||
NSBitmapImageRep *imagerep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
|
||||
pixelsWide:CGBitmapContextGetWidth(c)
|
||||
pixelsHigh:CGBitmapContextGetHeight(c)
|
||||
bitsPerSample:8
|
||||
samplesPerPixel:4
|
||||
hasAlpha:YES
|
||||
isPlanar:NO
|
||||
colorSpaceName:NSDeviceRGBColorSpace
|
||||
bytesPerRow:CGBitmapContextGetBytesPerRow(c)
|
||||
bitsPerPixel:CGBitmapContextGetBitsPerPixel(c)];
|
||||
memcpy([imagerep bitmapData], CGBitmapContextGetData(c), [imagerep bytesPerRow] * [imagerep pixelsHigh]);
|
||||
image = [[NSImage alloc] initWithSize:NSMakeSize([imagerep pixelsWide], [imagerep pixelsHigh])];
|
||||
NSBitmapImageRep *imagerep =
|
||||
[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
|
||||
pixelsWide:CGBitmapContextGetWidth(c)
|
||||
pixelsHigh:CGBitmapContextGetHeight(c)
|
||||
bitsPerSample:8
|
||||
samplesPerPixel:4
|
||||
hasAlpha:YES
|
||||
isPlanar:NO
|
||||
colorSpaceName:NSDeviceRGBColorSpace
|
||||
bytesPerRow:CGBitmapContextGetBytesPerRow(c)
|
||||
bitsPerPixel:CGBitmapContextGetBitsPerPixel(c)];
|
||||
memcpy([imagerep bitmapData], CGBitmapContextGetData(c),
|
||||
[imagerep bytesPerRow] * [imagerep pixelsHigh]);
|
||||
image = [[NSImage alloc] initWithSize:NSMakeSize([imagerep pixelsWide],
|
||||
[imagerep pixelsHigh])];
|
||||
[image addRepresentation:imagerep];
|
||||
[imagerep release];
|
||||
}
|
||||
@ -3741,7 +3835,8 @@ int Fl_Cocoa_Window_Driver::set_cursor(const Fl_RGB_Image *image, int hotx, int
|
||||
samplesPerPixel:image->d()
|
||||
hasAlpha:!(image->d() & 1)
|
||||
isPlanar:NO
|
||||
colorSpaceName:(image->d()<=2) ? NSDeviceWhiteColorSpace : NSDeviceRGBColorSpace
|
||||
colorSpaceName:(image->d() <= 2 ?
|
||||
NSDeviceWhiteColorSpace : NSDeviceRGBColorSpace)
|
||||
bytesPerRow:(image->data_w() * image->d())
|
||||
bitsPerPixel:(image->d()*8)];
|
||||
|
||||
@ -3801,11 +3896,11 @@ int Fl_Cocoa_Window_Driver::set_cursor(const Fl_RGB_Image *image, int hotx, int
|
||||
- (void) toggleCallback {
|
||||
NSMenuItem *item = [self representedObject];
|
||||
const char *title;
|
||||
if ([self state] == NSOnState) {
|
||||
[self setState:NSOffState];
|
||||
if ([self state] == NSControlStateValueOn) {
|
||||
[self setState:NSControlStateValueOff];
|
||||
title = Fl_Mac_App_Menu::print_no_titlebar;
|
||||
} else {
|
||||
[self setState:NSOnState];
|
||||
[self setState:NSControlStateValueOn];
|
||||
title = Fl_Mac_App_Menu::print;
|
||||
}
|
||||
[item setTitle:NSLocalizedString([NSString stringWithUTF8String:title], nil)];
|
||||
@ -3841,7 +3936,7 @@ static PrintWithTitlebarItem *print_with_titlebar_item = NULL;
|
||||
}
|
||||
- (void)printPanel
|
||||
{
|
||||
bool grab_decoration = ([print_with_titlebar_item state] == NSOnState);
|
||||
bool grab_decoration = ([print_with_titlebar_item state] == NSControlStateValueOn);
|
||||
fl_lock_function();
|
||||
fl_print_or_copy_window(Fl::first_window(), grab_decoration, 1);
|
||||
fl_unlock_function();
|
||||
@ -3889,7 +3984,7 @@ static void createAppleMenu(void)
|
||||
[appleMenu addItem:print_with_titlebar_item];
|
||||
[print_with_titlebar_item setTarget:print_with_titlebar_item];
|
||||
[print_with_titlebar_item setRepresentedObject:menuItem];
|
||||
[print_with_titlebar_item setState:NSOnState];
|
||||
[print_with_titlebar_item setState:NSControlStateValueOn];
|
||||
[print_with_titlebar_item setEnabled:YES];
|
||||
[appleMenu addItem:[NSMenuItem separatorItem]];
|
||||
}
|
||||
@ -3909,16 +4004,20 @@ static void createAppleMenu(void)
|
||||
keyEquivalent:@"h"];
|
||||
// Hide Others
|
||||
menuItem = [appleMenu
|
||||
addItemWithTitle:NSLocalizedString([NSString stringWithUTF8String:Fl_Mac_App_Menu::hide_others] , nil)
|
||||
addItemWithTitle:NSLocalizedString(
|
||||
[NSString stringWithUTF8String:Fl_Mac_App_Menu::hide_others] , nil)
|
||||
action:@selector(hideOtherApplications:)
|
||||
keyEquivalent:@"h"];
|
||||
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
|
||||
[menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption|NSEventModifierFlagCommand)];
|
||||
// Show All
|
||||
[appleMenu addItemWithTitle:NSLocalizedString([NSString stringWithUTF8String:Fl_Mac_App_Menu::show] , nil)
|
||||
action:@selector(unhideAllApplications:) keyEquivalent:@""];
|
||||
[appleMenu addItemWithTitle:NSLocalizedString(
|
||||
[NSString stringWithUTF8String:Fl_Mac_App_Menu::show], nil)
|
||||
action:@selector(unhideAllApplications:)
|
||||
keyEquivalent:@""];
|
||||
[appleMenu addItem:[NSMenuItem separatorItem]];
|
||||
// Quit AppName
|
||||
title = [NSString stringWithFormat:NSLocalizedString([NSString stringWithUTF8String:Fl_Mac_App_Menu::quit] , nil),
|
||||
title = [NSString stringWithFormat:NSLocalizedString(
|
||||
[NSString stringWithUTF8String:Fl_Mac_App_Menu::quit], nil),
|
||||
nsappname];
|
||||
menuItem = [appleMenu addItemWithTitle:title
|
||||
action:@selector(terminate:)
|
||||
@ -4015,7 +4114,8 @@ static NSImage *defaultDragImage(int *pwidth, int *pheight)
|
||||
fl_font(FL_HELVETICA, 20);
|
||||
fl_color(FL_BLACK);
|
||||
char str[4];
|
||||
int l = fl_utf8encode(0x1F69A, str); // the "Delivery truck" Unicode character from "Apple Color Emoji" font
|
||||
// the "Delivery truck" Unicode character from "Apple Color Emoji" font
|
||||
int l = fl_utf8encode(0x1F69A, str);
|
||||
fl_draw(str, l, 1, 16);
|
||||
}
|
||||
else { // draw two squares
|
||||
@ -4067,7 +4167,7 @@ int Fl_Cocoa_Screen_Driver::dnd(int use_selection)
|
||||
[myview beginDraggingSessionWithItems:[NSArray arrayWithObject:dragItem] event:theEvent source:myview];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
{ // the 2 deprecation warnings can be ignored because this runs only for macOS < 10.7
|
||||
static NSSize offset={0,0};
|
||||
NSPasteboard *mypasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
|
||||
[mypasteboard declareTypes:[NSArray arrayWithObject:UTF8_pasteboard_type] owner:nil];
|
||||
@ -4104,8 +4204,9 @@ static NSBitmapImageRep *scale_nsbitmapimagerep(NSBitmapImageRep *img, float sca
|
||||
colorSpaceName:NSDeviceRGBColorSpace
|
||||
bytesPerRow:scaled_w*4
|
||||
bitsPerPixel:32];
|
||||
NSDictionary *dict = [NSDictionary dictionaryWithObject:scaled
|
||||
forKey:NSGraphicsContextDestinationAttributeName];
|
||||
NSDictionary *dict =
|
||||
[NSDictionary dictionaryWithObject:scaled
|
||||
forKey:NSGraphicsContextDestinationAttributeName];
|
||||
NSGraphicsContext *oldgc = [NSGraphicsContext currentContext];
|
||||
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithAttributes:dict]];
|
||||
[[NSColor clearColor] set];
|
||||
@ -4127,12 +4228,13 @@ static void write_bitmap_inside(NSBitmapImageRep *to, int to_width, NSBitmapImag
|
||||
const uchar *from_data = [from bitmapData];
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||
if (fl_mac_os_version >= 100400) { // 10.4 required by the bitmapFormat message
|
||||
if (([to bitmapFormat] & NSAlphaFirstBitmapFormat) && !([from bitmapFormat] & NSAlphaFirstBitmapFormat) ) {
|
||||
if (([to bitmapFormat] & NSBitmapFormatAlphaFirst) &&
|
||||
!([from bitmapFormat] & NSBitmapFormatAlphaFirst) ) {
|
||||
// "to" is ARGB and "from" is RGBA --> convert "from" to ARGB
|
||||
// it is enough to read "from" starting one byte earlier, because A is always 0xFF:
|
||||
// RGBARGBA becomes (A)RGBARGB
|
||||
from_data--;
|
||||
} else if ( !([to bitmapFormat] & NSAlphaFirstBitmapFormat) && ([from bitmapFormat] & NSAlphaFirstBitmapFormat) ) {
|
||||
} else if ( !([to bitmapFormat] & NSBitmapFormatAlphaFirst) && ([from bitmapFormat] & NSBitmapFormatAlphaFirst) ) {
|
||||
// "from" is ARGB and "to" is RGBA --> convert "from" to RGBA
|
||||
// it is enough to offset reading by one byte because A is always 0xFF
|
||||
// so ARGBARGB becomes RGBARGB(A) as needed
|
||||
@ -4241,16 +4343,25 @@ static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y,
|
||||
rect = NSMakeRect(int(x*s), int(view_h-y*s-int(h*s)), int(w*s), int(h*s));
|
||||
// lock focus to win's view
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||
if (fl_mac_os_version >= 101100) [[fl_xid(win) graphicsContext] saveGraphicsState]; // necessary under 10.11
|
||||
if (fl_mac_os_version >= 101100) {
|
||||
NSGraphicsContext *ctxt = [fl_xid(win)
|
||||
performSelector:@selector(graphicsContext)];
|
||||
[ctxt saveGraphicsState]; // necessary under 10.11
|
||||
}
|
||||
#endif
|
||||
[winview lockFocus];
|
||||
[winview performSelector:@selector(lockFocus)];
|
||||
}
|
||||
// The image depth is 3 until 10.5 and 4 with 10.6 and above
|
||||
// The image depth is 3 until macOS 10.5 and 4 with 10.6 and above
|
||||
// the deprecation warning can be ignored because runs only for macOS < 10.14
|
||||
bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:rect];
|
||||
if ( !( through_Fl_X_flush && Fl_Window::current() == win) ) {
|
||||
[winview unlockFocus];
|
||||
[winview performSelector:@selector(unlockFocus)];
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||
if (fl_mac_os_version >= 101100) [[fl_xid(win) graphicsContext] restoreGraphicsState];
|
||||
if (fl_mac_os_version >= 101100) {
|
||||
NSGraphicsContext *ctxt = [fl_xid(win)
|
||||
performSelector:@selector(graphicsContext)];
|
||||
[ctxt restoreGraphicsState];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -4282,12 +4393,14 @@ static NSBitmapImageRep* rect_to_NSBitmapImageRep_subwins(Fl_Window *win, int x,
|
||||
win->h() - clip.origin.y - sub->y() - clip.size.height, clip.size.width, clip.size.height, true);
|
||||
if (childbitmap) {
|
||||
// if bitmap is high res and childbitmap is not, childbitmap must be rescaled
|
||||
if (!win->as_gl_window() && Fl_Cocoa_Window_Driver::driver(win)->mapped_to_retina() && sub->as_gl_window() && !Fl::use_high_res_GL()) {
|
||||
if (!win->as_gl_window() && Fl_Cocoa_Window_Driver::driver(win)->mapped_to_retina() &&
|
||||
sub->as_gl_window() && !Fl::use_high_res_GL()) {
|
||||
childbitmap = scale_nsbitmapimagerep(childbitmap, 2);
|
||||
}
|
||||
float s = Fl_Graphics_Driver::default_driver().scale();
|
||||
write_bitmap_inside(bitmap, w*s, childbitmap,
|
||||
(clip.origin.x - x)*s, (win->h() - clip.origin.y - clip.size.height - y)*s );
|
||||
write_bitmap_inside(bitmap, w * s, childbitmap,
|
||||
(clip.origin.x - x) * s,
|
||||
(win->h() - clip.origin.y - clip.size.height - y) * s );
|
||||
}
|
||||
[childbitmap release];
|
||||
}
|
||||
@ -4313,12 +4426,14 @@ CGImageRef Fl_Cocoa_Window_Driver::CGImage_from_window_rect(int x, int y, int w,
|
||||
[bitmap release];
|
||||
} else {
|
||||
CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
|
||||
CGDataProviderRef provider = CGDataProviderCreateWithData(bitmap, [bitmap bitmapData],
|
||||
[bitmap bytesPerRow]*[bitmap pixelsHigh],
|
||||
nsbitmapProviderReleaseData);
|
||||
img = CGImageCreate([bitmap pixelsWide], [bitmap pixelsHigh], 8, [bitmap bitsPerPixel], [bitmap bytesPerRow],
|
||||
cspace,
|
||||
[bitmap bitsPerPixel] == 32 ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNone,
|
||||
CGDataProviderRef provider =
|
||||
CGDataProviderCreateWithData(bitmap, [bitmap bitmapData],
|
||||
[bitmap bytesPerRow] * [bitmap pixelsHigh],
|
||||
nsbitmapProviderReleaseData);
|
||||
img = CGImageCreate([bitmap pixelsWide], [bitmap pixelsHigh], 8, [bitmap bitsPerPixel],
|
||||
[bitmap bytesPerRow], cspace,
|
||||
([bitmap bitsPerPixel] == 32 ? kCGImageAlphaPremultipliedLast :
|
||||
kCGImageAlphaNone) ,
|
||||
provider, NULL, false, kCGRenderingIntentDefault);
|
||||
CGColorSpaceRelease(cspace);
|
||||
CGDataProviderRelease(provider);
|
||||
@ -4349,7 +4464,7 @@ void Fl_Cocoa_Window_Driver::draw_titlebar_to_context(CGContextRef gc, int w, in
|
||||
{
|
||||
FLWindow *nswin = fl_xid(pWindow);
|
||||
[nswin makeMainWindow];
|
||||
[NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:NO];
|
||||
[NSApp nextEventMatchingMask:NSEventMaskAny untilDate:nil inMode:NSDefaultRunLoopMode dequeue:NO];
|
||||
CGImageRef img;
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
||||
if (fl_mac_os_version >= 100600) { // verified OK from 10.6
|
||||
@ -4481,10 +4596,19 @@ static NSImage* rgb_to_nsimage(const Fl_RGB_Image *rgb) {
|
||||
NSImage *win_icon = nil;
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||
if (fl_mac_os_version >= 101000) {
|
||||
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:rgb->data_w() pixelsHigh:rgb->data_h()
|
||||
bitsPerSample:8 samplesPerPixel:rgb->d() hasAlpha:!(rgb->d() & 1) isPlanar:NO
|
||||
colorSpaceName:(rgb->d()<=2) ? NSDeviceWhiteColorSpace : NSDeviceRGBColorSpace
|
||||
bitmapFormat:NSAlphaNonpremultipliedBitmapFormat bytesPerRow:ld bitsPerPixel:rgb->d()*8]; // 10.4
|
||||
NSBitmapImageRep *bitmap =
|
||||
[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
|
||||
pixelsWide:rgb->data_w()
|
||||
pixelsHigh:rgb->data_h()
|
||||
bitsPerSample:8
|
||||
samplesPerPixel:rgb->d()
|
||||
hasAlpha:!(rgb->d() & 1)
|
||||
isPlanar:NO
|
||||
colorSpaceName:(rgb->d() <= 2 ? NSDeviceWhiteColorSpace :
|
||||
NSDeviceRGBColorSpace)
|
||||
bitmapFormat:NSBitmapFormatAlphaNonpremultiplied
|
||||
bytesPerRow:ld
|
||||
bitsPerPixel:rgb->d() * 8]; // 10.4
|
||||
memcpy([bitmap bitmapData], rgb->array, rgb->data_h() * ld);
|
||||
win_icon = [[NSImage alloc] initWithSize:NSMakeSize(0, 0)];
|
||||
[win_icon addRepresentation:bitmap];
|
||||
|
@ -106,7 +106,7 @@ static NSOpenGLPixelFormat* mode_to_NSOpenGLPixelFormat(int m, const int *alistp
|
||||
}
|
||||
if (m & FL_STEREO) {
|
||||
//list[n++] = AGL_STEREO;
|
||||
attribs[n++] = NSOpenGLPFAStereo;
|
||||
attribs[n++] = 6/*NSOpenGLPFAStereo*/;
|
||||
}
|
||||
if ((m & FL_MULTISAMPLE) && fl_mac_os_version >= 100400) {
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||
|
@ -126,7 +126,10 @@ int Fl_Cocoa_Printer_Driver::begin_job (int pagecount, int *frompage, int *topag
|
||||
[main makeKeyAndOrderFront:nil];
|
||||
} else
|
||||
retval = [panel runModalWithPrintInfo:info]; //from 10.5
|
||||
if (retval != NSOKButton) return 1;
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_9
|
||||
const NSInteger NSModalResponseOK = NSOKButton;
|
||||
#endif
|
||||
if (retval != NSModalResponseOK) return 1;
|
||||
printSession = (PMPrintSession)[info PMPrintSession];//from 10.5
|
||||
pageFormat = (PMPageFormat)[info PMPageFormat];//from 10.5
|
||||
printSettings = (PMPrintSettings)[info PMPrintSettings];//from 10.5
|
||||
|
@ -77,6 +77,10 @@
|
||||
#include <FL/fl_utf8.h> // for fl_utf8toUtf16()
|
||||
#include <FL/fl_string_functions.h> // fl_strdup()
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8
|
||||
const NSUInteger kCTFontOrientationHorizontal = kCTFontHorizontalOrientation;
|
||||
#endif
|
||||
|
||||
Fl_Fontdesc* fl_fonts = NULL;
|
||||
|
||||
static CGAffineTransform font_mx = { 1, 0, 0, -1, 0, 0 };
|
||||
@ -418,14 +422,14 @@ void Fl_Quartz_Graphics_Driver::ADD_SUFFIX(descriptor_init, _CoreText)(const cha
|
||||
CTFontGetGlyphsForCharacters(d->fontref, A, glyph, 2);
|
||||
CGSize advances[2];
|
||||
double w;
|
||||
CTFontGetAdvancesForGlyphs(d->fontref, kCTFontHorizontalOrientation, glyph, advances, 2);
|
||||
CTFontGetAdvancesForGlyphs(d->fontref, kCTFontOrientationHorizontal, glyph, advances, 2);
|
||||
w = advances[0].width;
|
||||
if ( fabs(advances[0].width - advances[1].width) < 1E-2 ) {//this is a fixed-width font
|
||||
// slightly rescale fixed-width fonts so the character width has an integral value
|
||||
CFRelease(d->fontref);
|
||||
CGFloat fsize = size / ( w/floor(w + 0.5) );
|
||||
d->fontref = CTFontCreateWithName(str, fsize, NULL);
|
||||
w = CTFontGetAdvancesForGlyphs(d->fontref, kCTFontHorizontalOrientation, glyph, NULL, 1);
|
||||
w = CTFontGetAdvancesForGlyphs(d->fontref, kCTFontOrientationHorizontal, glyph, NULL, 1);
|
||||
}
|
||||
CFRelease(str);
|
||||
d->ascent = (short)(CTFontGetAscent(d->fontref) + 0.5);
|
||||
@ -473,7 +477,7 @@ static CGFloat surrogate_width(const UniChar *txt, Fl_Quartz_Font_Descriptor *fl
|
||||
CFRelease(str);
|
||||
b = CTFontGetGlyphsForCharacters(font2, txt, glyphs, 2);
|
||||
}
|
||||
if (b) CTFontGetAdvancesForGlyphs(font2, kCTFontHorizontalOrientation, glyphs, &a, 1);
|
||||
if (b) CTFontGetAdvancesForGlyphs(font2, kCTFontOrientationHorizontal, glyphs, &a, 1);
|
||||
else a.width = fl_fontsize->q_width;
|
||||
if(must_release) CFRelease(font2);
|
||||
return a.width;
|
||||
@ -525,7 +529,7 @@ double Fl_Quartz_Graphics_Driver::ADD_SUFFIX(width, _CoreText)(const UniChar* tx
|
||||
// ii spans all characters of this block
|
||||
bool b = CTFontGetGlyphsForCharacters(fl_fontsize->fontref, &ii, &glyph, 1);
|
||||
if (b)
|
||||
CTFontGetAdvancesForGlyphs(fl_fontsize->fontref, kCTFontHorizontalOrientation, &glyph, &advance_size, 1);
|
||||
CTFontGetAdvancesForGlyphs(fl_fontsize->fontref, kCTFontOrientationHorizontal, &glyph, &advance_size, 1);
|
||||
else
|
||||
advance_size.width = -1e9; // calculate this later
|
||||
// the width of one character of this block of characters
|
||||
@ -549,7 +553,7 @@ double Fl_Quartz_Graphics_Driver::ADD_SUFFIX(width, _CoreText)(const UniChar* tx
|
||||
CFRelease(str);
|
||||
b = CTFontGetGlyphsForCharacters(font2, &uni, &glyph, 1);
|
||||
}
|
||||
if (b) CTFontGetAdvancesForGlyphs(font2, kCTFontHorizontalOrientation, &glyph, &advance_size, 1);
|
||||
if (b) CTFontGetAdvancesForGlyphs(font2, kCTFontOrientationHorizontal, &glyph, &advance_size, 1);
|
||||
else advance_size.width = 0.;
|
||||
// the width of the 'uni' character
|
||||
wdt = fl_fontsize->width[r][uni & (block-1)] = advance_size.width;
|
||||
|
Loading…
x
Reference in New Issue
Block a user