22# pragma clang diagnostic ignored "-Wdeprecated-declarations"
25#ifdef WITH_METAL_BACKEND
29#ifdef WITH_VULKAN_BACKEND
38#include <Carbon/Carbon.h>
129 case kVK_ANSI_Keypad0:
131 case kVK_ANSI_Keypad1:
133 case kVK_ANSI_Keypad2:
135 case kVK_ANSI_Keypad3:
137 case kVK_ANSI_Keypad4:
139 case kVK_ANSI_Keypad5:
141 case kVK_ANSI_Keypad6:
143 case kVK_ANSI_Keypad7:
145 case kVK_ANSI_Keypad8:
147 case kVK_ANSI_Keypad9:
149 case kVK_ANSI_KeypadDecimal:
151 case kVK_ANSI_KeypadEnter:
153 case kVK_ANSI_KeypadPlus:
155 case kVK_ANSI_KeypadMinus:
157 case kVK_ANSI_KeypadMultiply:
159 case kVK_ANSI_KeypadDivide:
161 case kVK_ANSI_KeypadClear:
218 case kVK_ForwardDelete:
259 if ((recvChar >=
'A') && (recvChar <=
'Z')) {
263 if ((recvChar >=
'a') && (recvChar <=
'z')) {
268 const TISInputSourceRef kbdTISHandle = TISCopyCurrentKeyboardLayoutInputSource();
270 const CFDataRef uchrHandle =
static_cast<CFDataRef
>(
271 TISGetInputSourceProperty(kbdTISHandle, kTISPropertyUnicodeKeyLayoutData));
272 CFRelease(kbdTISHandle);
278 UInt32 deadKeyState = 0;
279 UniCharCount actualStrLength = 0;
281 UCKeyTranslate((UCKeyboardLayout *)CFDataGetBytePtr(uchrHandle),
286 kUCKeyTranslateNoDeadKeysMask,
332#define FIRSTFILEBUFLG 512
362- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
363- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
364- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
365- (void)applicationWillTerminate:(NSNotification *)aNotification;
366- (void)applicationWillBecomeActive:(NSNotification *)aNotification;
367- (void)toggleFullScreen:(NSNotification *)notification;
368- (void)windowWillClose:(NSNotification *)notification;
370- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app;
385 selector:@selector(windowWillClose:)
386 name:NSWindowWillCloseNotification
398 [
center removeObserver:
self name:NSWindowWillCloseNotification object:nil];
403- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
405 if (system_cocoa_->window_focus_) {
410 [
NSApp activateIgnoringOtherApps:YES];
413 [
NSEvent setMouseCoalescingEnabled:NO];
416- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
421- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
426 system_cocoa_->handleQuitRequest();
427 return NSTerminateCancel;
433- (void)applicationWillTerminate:(NSNotification *)aNotification
436 WM_exit(
C, EXIT_SUCCESS);
440- (void)applicationWillBecomeActive:(NSNotification *)aNotification
442 system_cocoa_->handleApplicationBecomeActiveEvent();
445- (void)toggleFullScreen:(NSNotification *)notification
466- (void)windowWillClose:(NSNotification *)notification
469 NSWindow *closing_window = (NSWindow *)[notification
object];
471 if (![closing_window isKeyWindow]) {
482 const NSInteger
index = [[
NSApp orderedWindows] indexOfObject:closing_window];
483 if (
index != NSNotFound) {
487 for (NSWindow *current_window
in [NSApp orderedWindows]) {
488 if (current_window == closing_window) {
491 if (current_window.isOnActiveSpace && current_window.canBecomeKeyWindow) {
497 for (NSNumber *window_number
in [NSWindow windowNumbersWithOptions:0]) {
498 NSWindow *current_window = [
NSApp windowWithWindowNumber:[
window_number integerValue]];
499 if (current_window == closing_window) {
502 if ([current_window canBecomeKeyWindow]) {
518- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
553 [
NSApp setDelegate:nil];
564#ifdef WITH_INPUT_NDOF
572 if (!GetCurrentProcess(&psn)) {
573 TransformProcessType(&psn, kProcessTransformToForegroundApplication);
574 SetFrontProcess(&psn);
581 if ([NSApp mainMenu] == nil) {
582 NSMenu *mainMenubar = [[
NSMenu alloc] init];
583 NSMenuItem *menuItem;
588 appMenu = [[
NSMenu alloc] initWithTitle:@"Blender"];
590 [
appMenu addItemWithTitle:@"About Blender"
591 action:@selector(orderFrontStandardAboutPanel:)
595 menuItem = [
appMenu addItemWithTitle:@"Hide Blender"
596 action:@selector(hide:)
598 menuItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
600 menuItem = [
appMenu addItemWithTitle:@"Hide Others"
601 action:@selector(hideOtherApplications:)
603 menuItem.keyEquivalentModifierMask = (NSEventModifierFlagOption |
604 NSEventModifierFlagCommand);
606 [
appMenu addItemWithTitle:@"Show All"
607 action:@selector(unhideAllApplications:)
610 menuItem = [
appMenu addItemWithTitle:@"Quit Blender"
611 action:@selector(terminate:)
613 menuItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
616 menuItem.submenu = appMenu;
623 windowMenu = [[
NSMenu alloc] initWithTitle:@"Window"];
625 menuItem = [
windowMenu addItemWithTitle:@"Minimize"
626 action:@selector(performMiniaturize:)
628 menuItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
630 [
windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
632 menuItem = [
windowMenu addItemWithTitle:@"Enter Full Screen"
633 action:@selector(toggleFullScreen:)
635 menuItem.keyEquivalentModifierMask = NSEventModifierFlagControl |
636 NSEventModifierFlagCommand;
638 menuItem = [
windowMenu addItemWithTitle:@"Close"
639 action:@selector(performClose:)
641 menuItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
644 menuItem.submenu = windowMenu;
649 [
NSApp setMainMenu:mainMenubar];
650 [
NSApp setWindowsMenu:windowMenu];
654 if ([NSApp delegate] == nil) {
656 [
NSApp setDelegate:appDelegate];
662 NSWindow.allowsAutomaticWindowTabbing = NO;
667 [
NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited];
670 [
NSApp finishLaunching];
700 const NSRect contentRect = [
NSWindow
701 contentRectForFrameRect:frame
702 styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
703 NSWindowStyleMaskMiniaturizable)];
705 width = contentRect.size.width;
706 height = contentRect.size.height;
724 const bool is_dialog,
731 const NSRect primaryScreenFrame = [
GHOST_WindowCocoa::getPrimaryScreen() visibleFrame];
732 const NSRect primaryScreenContentRect = [
NSWindow
733 contentRectForFrameRect:primaryScreenFrame
734 styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
735 NSWindowStyleMaskMiniaturizable)];
737 const int32_t bottom = primaryScreenContentRect.size.height - top - height;
764 GHOST_PRINT(
"GHOST_SystemCocoa::createWindow(): window invalid\n");
783#ifdef WITH_VULKAN_BACKEND
784 case GHOST_kDrawingContextTypeVulkan: {
787 if (context->initializeDrawingContext()) {
795#ifdef WITH_METAL_BACKEND
796 case GHOST_kDrawingContextTypeMetal: {
798 if (context->initializeDrawingContext()) {
826 const NSPoint scr_co = NSMakePoint(
x,
y);
829 const int windowNumberAtPoint = [
NSWindow windowNumberAtPoint:scr_co
830 belowWindowWithWindowNumber:0];
831 NSWindow *nswindow = [
NSApp windowWithWindowNumber:windowNumberAtPoint];
833 if (nswindow == nil) {
846 const NSPoint mouseLoc = [
NSEvent mouseLocation];
870 const CGFloat default_size = 21.0;
876 return lround(default_size *
scale);
891 CGAssociateMouseAndMouseCursorPosition(
false);
893 CGAssociateMouseAndMouseCursorPosition(
true);
896 pushEvent(std::make_unique<GHOST_EventCursor>(
907 __block BOOL selectCompleted = NO;
908 __block BOOL samplingSucceeded = NO;
910 [sampler showSamplerWithSelectionHandler:^(NSColor *selectedColor) {
911 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)),
912 dispatch_get_main_queue(),
914 if (selectedColor != nil) {
916 colorUsingColorSpace:[
NSColorSpace deviceRGBColorSpace]];
919 r_color[1] = [
rgbColor greenComponent];
920 r_color[2] = [
rgbColor blueComponent];
922 samplingSucceeded = YES;
924 selectCompleted = YES;
928 while (!selectCompleted) {
929 [[
NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
930 beforeDate:[
NSDate dateWithTimeIntervalSinceNow:0.05]];
946 NSScreen *windowScreen = window->
getScreen();
947 const NSRect screenRect = windowScreen.frame;
950 xf -= screenRect.origin.x;
951 yf -= screenRect.origin.y;
954 yf = screenRect.size.height - yf;
956 CGDisplayMoveCursorToPoint((CGDirectDisplayID)[[[windowScreen deviceDescription]
957 objectForKey:
@"NSScreenNumber"] unsignedIntValue],
958 CGPointMake(xf, yf));
965 CGAssociateMouseAndMouseCursorPosition(
true);
984 const UInt32 button_state = GetCurrentEventButtonState();
1019 bool anyProcessed =
false;
1032 timeOut = kEventDurationForever;
1036 if (timeOut < 0.0) {
1041 ::ReceiveNextEvent(0,
nullptr, timeOut,
false, &event);
1045 anyProcessed =
true;
1050 event = [
NSApp nextEventMatchingMask:NSEventMaskAny
1051 untilDate:[
NSDate distantPast]
1052 inMode:NSDefaultRunLoopMode
1058 anyProcessed =
true;
1068 if (event.type == NSEventTypeKeyDown && event.keyCode == kVK_Tab &&
1069 (event.modifierFlags & NSEventModifierFlagControl))
1077 if (event.type == NSEventTypeKeyUp &&
1078 (event.modifierFlags & (NSEventModifierFlagCommand | NSEventModifierFlagOption)))
1083 [
NSApp sendEvent:event];
1086 }
while (event != nil);
1088 }
while (waitForEvent && !anyProcessed);
1102 return anyProcessed;
1112 [
window->getViewWindow() makeKeyAndOrderFront:nil];
1127 const unsigned int modifiers = [[[
NSApplication sharedApplication] currentEvent]
1130 if ((modifiers & NSEventModifierFlagShift) != (
modifier_mask_ & NSEventModifierFlagShift)) {
1131 pushEvent(std::make_unique<GHOST_EventKey>(
1138 if ((modifiers & NSEventModifierFlagControl) != (
modifier_mask_ & NSEventModifierFlagControl))
1140 pushEvent(std::make_unique<GHOST_EventKey>(
1147 if ((modifiers & NSEventModifierFlagOption) != (
modifier_mask_ & NSEventModifierFlagOption)) {
1148 pushEvent(std::make_unique<GHOST_EventKey>(
1155 if ((modifiers & NSEventModifierFlagCommand) != (
modifier_mask_ & NSEventModifierFlagCommand))
1157 pushEvent(std::make_unique<GHOST_EventKey>(
1195 switch (eventType) {
1213 pushEvent(std::make_unique<GHOST_Event>(
1236 GHOST_TABLET_DATA_NONE));
1245 pushEvent(std::make_unique<GHOST_Event>(
1267 NSImageRep *imageRepresentation = [[image representations] firstObject];
1268 return NSMakeSize(imageRepresentation.pixelsWide, imageRepresentation.pixelsHigh);
1288 NSBitmapImageRep *bitmapImage = nil;
1289 for (NSImageRep *representation
in [
image representations]) {
1290 if ([representation isKindOfClass:[NSBitmapImageRep
class]]) {
1291 bitmapImage = (NSBitmapImageRep *)representation;
1296 if (bitmapImage == nil || bitmapImage.bitsPerPixel != 32 || bitmapImage.isPlanar ||
1297 bitmapImage.bitmapFormat & (NSBitmapFormatAlphaFirst | NSBitmapFormatFloatingPointSamples))
1303 uint8_t *bmp_data = (uint8_t *)bitmapImage.bitmapData;
1307 const int row_byte_count = 4 *
imageSize.width;
1308 const int ibuf_off = (
imageSize.height -
y - 1) * row_byte_count;
1309 const int bmp_off =
y * row_byte_count;
1310 memcpy(ibuf_data + ibuf_off, bmp_data + bmp_off, row_byte_count);
1328 switch (eventType) {
1333 pushEvent(std::make_unique<GHOST_EventDragnDrop>(
1334 getMilliSeconds(), eventType, draggedObjectType, window, mouseX, mouseY,
nullptr));
1344 switch (draggedObjectType) {
1346 NSArray *droppedArray = (NSArray *)data;
1354 strArray->
count = droppedArray.count;
1355 if (strArray->
count == 0) {
1360 strArray->
strings = (uint8_t **)malloc(strArray->
count *
sizeof(uint8_t *));
1362 for (
int i = 0; i < strArray->
count; i++) {
1365 lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1366 uint8_t *temp_buff = (uint8_t *)malloc(pastedTextSize + 1);
1369 strArray->
count = i;
1374 [droppedStr cStringUsingEncoding:NSUTF8StringEncoding],
1385 NSString *droppedStr = (NSString *)data;
1387 lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1388 uint8_t *temp_buff = (uint8_t *)malloc(pastedTextSize + 1);
1390 if (temp_buff ==
nullptr) {
1395 temp_buff, [droppedStr cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize);
1402 NSImage *droppedImg =
static_cast<NSImage *
>(data);
1417 pushEvent(std::make_unique<GHOST_EventDragnDrop>(
1418 getMilliSeconds(), eventType, draggedObjectType, window, mouseX, mouseY, eventData));
1445 NSString *filepath = (NSString *)filepathStr;
1451 NSArray *windowsList = [
NSApp orderedWindows];
1452 if ([windowsList count]) {
1453 [[
windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
1470 const size_t filenameTextSize = [
filepath lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1471 char *temp_buff = (
char *)malloc(filenameTextSize + 1);
1473 if (temp_buff ==
nullptr) {
1477 memcpy(temp_buff, [filepath cStringUsingEncoding:NSUTF8StringEncoding], filenameTextSize);
1490 NSEvent *
event = (NSEvent *)eventPtr;
1493 (
const void *)event.window);
1501 switch (eventType) {
1502 case NSEventTypeTabletPoint:
1512 ct.
Xtilt =
event.tilt.x;
1516 ct.
Ytilt = -
event.tilt.y;
1519 case NSEventTypeTabletProximity:
1521 ct = GHOST_TABLET_DATA_NONE;
1522 if (event.isEnteringProximity) {
1524 switch (event.pointingDeviceType) {
1525 case NSPointingDeviceTypePen:
1528 case NSPointingDeviceTypeEraser:
1531 case NSPointingDeviceTypeCursor:
1532 case NSPointingDeviceTypeUnknown:
1540 GHOST_ASSERT(FALSE,
"GHOST_SystemCocoa::handleTabletEvent : unknown event received");
1549 NSEvent *
event = (NSEvent *)eventPtr;
1551 switch (event.subtype) {
1552 case NSEventSubtypeTabletPoint:
1555 case NSEventSubtypeTabletProximity:
1566 NSEvent *
event = (NSEvent *)eventPtr;
1572 ->getWindowAssociatedWithOSWindow((
const void *)event.window);
1581 switch (event.type) {
1582 case NSEventTypeLeftMouseDown:
1584 pushEvent(std::make_unique<GHOST_EventButton>(event.timestamp * 1000,
1590 case NSEventTypeRightMouseDown:
1592 pushEvent(std::make_unique<GHOST_EventButton>(event.timestamp * 1000,
1598 case NSEventTypeOtherMouseDown:
1600 pushEvent(std::make_unique<GHOST_EventButton>(event.timestamp * 1000,
1606 case NSEventTypeLeftMouseUp:
1608 pushEvent(std::make_unique<GHOST_EventButton>(event.timestamp * 1000,
1614 case NSEventTypeRightMouseUp:
1616 pushEvent(std::make_unique<GHOST_EventButton>(event.timestamp * 1000,
1622 case NSEventTypeOtherMouseUp:
1624 pushEvent(std::make_unique<GHOST_EventButton>(event.timestamp * 1000,
1630 case NSEventTypeLeftMouseDragged:
1631 case NSEventTypeRightMouseDragged:
1632 case NSEventTypeOtherMouseDragged:
1635 case NSEventTypeMouseMoved: {
1637 bool is_tablet =
false;
1651 corrected_bounds.
t_ = 0;
1652 corrected_bounds.
l_ = 0;
1654 NSWindow *cocoa_window = (NSWindow *)window->
getOSWindow();
1655 const NSSize frame_size = cocoa_window.frame.size;
1657 corrected_bounds.
b_ = frame_size.height;
1658 corrected_bounds.
r_ = frame_size.width;
1668 corrected_bounds.
b_ = (window_bounds.
b_ - window_bounds.
t_) - corrected_bounds.
b_;
1669 corrected_bounds.
t_ = (window_bounds.
b_ - window_bounds.
t_) - corrected_bounds.
t_;
1674 NSWindow *cocoa_window = (NSWindow *)window->
getOSWindow();
1675 NSRect screen_visible_frame = window->
getScreen().visibleFrame;
1676 NSRect window_visible_frame = NSIntersectionRect(cocoa_window.frame, screen_visible_frame);
1677 NSRect local_visible_frame = [
cocoa_window convertRectFromScreen:window_visible_frame];
1680 visible_rect.
l_ = local_visible_frame.origin.x;
1681 visible_rect.
t_ = local_visible_frame.origin.y;
1682 visible_rect.
r_ = local_visible_frame.origin.x + local_visible_frame.size.width;
1683 visible_rect.
b_ = local_visible_frame.origin.y + local_visible_frame.size.height;
1686 visible_rect.
clip(corrected_bounds);
1695 const NSPoint mousePos =
event.window.mouseLocationOutsideOfEventStream;
1697 const int32_t x_mouse = mousePos.x;
1698 const int32_t y_mouse = mousePos.y;
1701 int32_t warped_x_mouse = x_mouse;
1702 int32_t warped_y_mouse = y_mouse;
1706 if (x_mouse != warped_x_mouse || y_mouse != warped_y_mouse) {
1711 const NSTimeInterval timestamp =
event.timestamp;
1712 const NSTimeInterval stale_event_threshold = 0.003;
1721 y_accum + (y_mouse - warped_y_mouse));
1730 pushEvent(std::make_unique<GHOST_EventCursor>(event.timestamp * 1000,
1739 const NSPoint mousePos =
event.locationInWindow;
1743 pushEvent(std::make_unique<GHOST_EventCursor>(event.timestamp * 1000,
1752 case NSEventTypeScrollWheel: {
1753 const NSEventPhase momentumPhase =
event.momentumPhase;
1754 const NSEventPhase phase =
event.phase;
1760 if (momentumPhase) {
1775 else if (phase == NSEventPhaseEnded) {
1783 if (event.deltaX != 0.0) {
1784 const int32_t delta =
event.deltaX > 0.0 ? 1 : -1;
1792 pushEvent(std::make_unique<GHOST_EventWheel>(
1793 event.timestamp * 1000, window, direction, delta));
1796 if (event.deltaY != 0.0) {
1797 const int32_t delta =
event.deltaY > 0.0 ? 1 : -1;
1798 pushEvent(std::make_unique<GHOST_EventWheel>(
1803 const NSPoint mousePos =
event.locationInWindow;
1806 double dx =
event.scrollingDeltaX;
1807 double dy =
event.scrollingDeltaY;
1811 if (phase == NSEventPhaseNone && momentumPhase == NSEventPhaseNone) {
1823 convertPointToBacking:NSMakePoint(dx, dy)];
1824 pushEvent(std::make_unique<GHOST_EventTrackpad>(event.timestamp * 1000,
1831 event.isDirectionInvertedFromDevice));
1836 case NSEventTypeMagnify: {
1837 const NSPoint mousePos =
event.locationInWindow;
1840 pushEvent(std::make_unique<GHOST_EventTrackpad>(event.timestamp * 1000,
1845 event.magnification * 125.0 + 0.1,
1850 case NSEventTypeSmartMagnify: {
1851 const NSPoint mousePos =
event.locationInWindow;
1854 pushEvent(std::make_unique<GHOST_EventTrackpad>(
1858 case NSEventTypeRotate: {
1859 const NSPoint mousePos =
event.locationInWindow;
1862 pushEvent(std::make_unique<GHOST_EventTrackpad>(event.timestamp * 1000,
1867 event.rotation * -5.0,
1880 NSEvent *
event = (NSEvent *)eventPtr;
1882 (
const void *)event.window);
1889 switch (event.type) {
1890 case NSEventTypeKeyDown:
1891 case NSEventTypeKeyUp: {
1894 char utf8_buf[6] = {
'\0'};
1897 NSString *charsIgnoringModifiers =
event.charactersIgnoringModifiers;
1898 if (charsIgnoringModifiers.length > 0) {
1899 keyCode =
convertKey(event.keyCode, [charsIgnoringModifiers characterAtIndex:0]);
1905 NSString *characters =
event.characters;
1906 if ([characters
length] > 0) {
1907 NSData *convertedCharacters = [
characters dataUsingEncoding:NSUTF8StringEncoding];
1909 for (
int x = 0;
x < convertedCharacters.length;
x++) {
1910 utf8_buf[x] = ((
char *)convertedCharacters.bytes)[x];
1934 if (event.type == NSEventTypeKeyDown) {
1935 pushEvent(std::make_unique<GHOST_EventKey>(event.timestamp * 1000,
1942 printf(
"Key down rawCode=0x%x charsIgnoringModifiers=%c keyCode=%u utf8=%s\n",
1944 charsIgnoringModifiers.length > 0 ? [charsIgnoringModifiers characterAtIndex:0] :
1951 pushEvent(std::make_unique<GHOST_EventKey>(
1954 printf(
"Key up rawCode=0x%x charsIgnoringModifiers=%c keyCode=%u utf8=%s\n",
1956 charsIgnoringModifiers.length > 0 ? [charsIgnoringModifiers characterAtIndex:0] :
1965 case NSEventTypeFlagsChanged: {
1966 const unsigned int modifiers =
event.modifierFlags;
1968 if ((modifiers & NSEventModifierFlagShift) != (
modifier_mask_ & NSEventModifierFlagShift)) {
1969 pushEvent(std::make_unique<GHOST_EventKey>(
1970 event.timestamp * 1000,
1976 if ((modifiers & NSEventModifierFlagControl) !=
1979 pushEvent(std::make_unique<GHOST_EventKey>(
1980 event.timestamp * 1000,
1986 if ((modifiers & NSEventModifierFlagOption) != (
modifier_mask_ & NSEventModifierFlagOption))
1988 pushEvent(std::make_unique<GHOST_EventKey>(
1989 event.timestamp * 1000,
1995 if ((modifiers & NSEventModifierFlagCommand) !=
1998 pushEvent(std::make_unique<GHOST_EventKey>(
1999 event.timestamp * 1000,
2025 NSPasteboard *pasteBoard = [
NSPasteboard generalPasteboard];
2026 NSString *textPasted = [
pasteBoard stringForType:NSPasteboardTypeString];
2028 if (textPasted == nil) {
2032 const size_t pastedTextSize = [
textPasted lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
2034 char *temp_buff = (
char *)malloc(pastedTextSize + 1);
2036 if (temp_buff ==
nullptr) {
2040 memcpy(temp_buff, [textPasted cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize);
2057 NSPasteboard *pasteBoard = NSPasteboard.generalPasteboard;
2060 NSString *textToCopy = [
NSString stringWithCString:buffer encoding:NSUTF8StringEncoding];
2061 [
pasteBoard setString:textToCopy forType:NSPasteboardTypeString];
2067 NSURL *pasteboardImageFile = nil;
2070 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
2071 NSDictionary *pasteboardFilteringOptions = @{
2072 NSPasteboardURLReadingFileURLsOnlyKey : @YES,
2073 NSPasteboardURLReadingContentsConformToTypesKey : [NSImage imageTypes]
2076 NSArray *pasteboardMatches = [pasteboard readObjectsForClasses:@[ [NSURL class] ]
2077 options:pasteboardFilteringOptions];
2079 if (!pasteboardMatches || !pasteboardMatches.count) {
2083 pasteboardImageFile = [[pasteboardMatches firstObject] copy];
2086 return [pasteboardImageFile autorelease];
2092 NSPasteboard *pasteboard = [
NSPasteboard generalPasteboard];
2093 NSArray *supportedTypes = [
NSArray
2094 arrayWithObjects:NSPasteboardTypeFileURL, NSPasteboardTypeTIFF, NSPasteboardTypePNG, nil];
2096 NSPasteboardType availableType = [
pasteboard availableTypeFromArray:supportedTypes];
2098 if (!availableType) {
2103 if ([pasteboard availableTypeFromArray:@[ NSPasteboardTypeFileURL ]] &&
2120 NSPasteboard *pasteboard = [
NSPasteboard generalPasteboard];
2122 NSImage *clipboardImage = nil;
2125 clipboardImage = [[[
NSImage alloc] initWithContentsOfURL:pasteboardImageFile] autorelease];
2129 clipboardImage = [[[
NSImage alloc] initWithPasteboard:pasteboard] autorelease];
2132 if (!clipboardImage) {
2140 const size_t byteCount = clipboardImageSize.width * clipboardImageSize.height * 4;
2141 uint *rgba = (uint *)malloc(byteCount);
2148 memcpy(rgba, ibuf->
byte_data(), byteCount);
2151 *r_width = clipboardImageSize.width;
2152 *r_height = clipboardImageSize.height;
2164 const size_t rowByteCount = width * 4;
2167 initWithBitmapDataPlanes:nil
2174 colorSpaceName:NSDeviceRGBColorSpace
2175 bytesPerRow:rowByteCount
2179 uint8_t *srcBuffer =
reinterpret_cast<uint8_t *
>(rgba);
2180 uint8_t *dstBuffer =
static_cast<uint8_t *
>([
imageRep bitmapData]);
2182 for (
int y = 0;
y < height;
y++) {
2183 const int dstOff = (height -
y - 1) * rowByteCount;
2184 const int srcOff =
y * rowByteCount;
2185 memcpy(dstBuffer + dstOff, srcBuffer + srcOff, rowByteCount);
2188 NSImage *
image = [[[
NSImage alloc] initWithSize:NSMakeSize(width, height)] autorelease];
2189 [image addRepresentation:imageRep];
2191 NSPasteboard *pasteboard = [
NSPasteboard generalPasteboard];
2194 BOOL pasteSuccess = [
pasteboard writeObjects:@[ image ]];
2196 if (!pasteSuccess) {
2204 const char *message,
2205 const char *help_label,
2206 const char *continue_label,
2211 NSAlert *alert = [[[
NSAlert alloc] init] autorelease];
2212 alert.accessoryView = [[[
NSView alloc] initWithFrame:NSMakeRect(0, 0, 500, 0)] autorelease];
2214 NSString *titleString = [
NSString stringWithCString:title];
2215 NSString *messageString = [
NSString stringWithCString:message];
2216 NSString *continueString = [
NSString stringWithCString:continue_label];
2217 NSString *helpString = [
NSString stringWithCString:help_label];
2220 alert.alertStyle = NSAlertStyleCritical;
2223 alert.alertStyle = NSAlertStyleWarning;
2226 alert.alertStyle = NSAlertStyleInformational;
2229 alert.messageText = titleString;
2230 alert.informativeText = messageString;
2232 [
alert addButtonWithTitle:continueString];
2233 if (link && strlen(link)) {
2234 [
alert addButtonWithTitle:helpString];
2237 const NSModalResponse response = [
alert runModal];
2238 if (response == NSAlertSecondButtonReturn) {
2239 NSString *linkString = [
NSString stringWithCString:link];
#define GHOST_ASSERT(x, info)
CGError CGSGetCursorScale(CGSConnectionID connection, CGFloat *scale)
static GHOST_TKey convertKey(int rawCode, unichar recvChar)
int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG])
static char g_firstFileBuf[FIRSTFILEBUFLG]
static NSSize getNSImagePixelSize(NSImage *image)
static bool g_hasFirstFile
static GHOST_TButton convertButton(int button)
static blender::ImBuf * NSImageToImBuf(NSImage *image)
CGSConnectionID CGSMainConnectionID(void)
static NSURL * NSPasteboardGetImageFile()
@ GHOST_kEventWheelAxisVertical
@ GHOST_kEventWheelAxisHorizontal
const void * GHOST_TEventDataPtr
@ GHOST_kTrackpadEventMagnify
@ GHOST_kTrackpadEventSmartMagnify
@ GHOST_kTrackpadEventRotate
@ GHOST_kTrackpadEventScroll
@ GHOST_kEventWindowClose
@ GHOST_kEventDraggingDropDone
@ GHOST_kEventDraggingExited
@ GHOST_kEventNativeResolutionChange
@ GHOST_kEventDraggingUpdated
@ GHOST_kEventOpenMainFile
@ GHOST_kEventDraggingEntered
@ GHOST_kEventWindowActivate
@ GHOST_kEventWindowUpdate
@ GHOST_kEventWindowDeactivate
@ GHOST_kEventQuitRequest
@ GHOST_kTabletModeEraser
@ GHOST_kTabletModeStylus
@ GHOST_kCapabilityClipboardPrimary
@ GHOST_kCapabilityKeyboardHyperKey
@ GHOST_kCapabilityCursorGenerator
#define GHOST_CONTEXT_PARAMS_FROM_GPU_SETTINGS(gpu_settings)
#define GHOST_CAPABILITY_FLAG_ALL
void * GHOST_TDragnDropDataPtr
@ GHOST_kKeyNumpadAsterisk
@ GHOST_kModifierKeyLeftControl
@ GHOST_kModifierKeyLeftAlt
@ GHOST_kModifierKeyLeftShift
@ GHOST_kModifierKeyLeftOS
#define GHOST_CONTEXT_PARAMS_FROM_GPU_SETTINGS_OFFSCREEN(gpu_settings)
@ GHOST_kDragnDropTypeFilenames
@ GHOST_kDragnDropTypeBitmap
@ GHOST_kDragnDropTypeString
@ GHOST_kButtonMaskButton4
@ GHOST_kButtonMaskButton7
@ GHOST_kButtonMaskButton6
@ GHOST_kButtonMaskButton5
@ GHOST_kButtonMaskMiddle
unsigned long long int uint64_t
GHOST_ContextMTL(const GHOST_ContextParams &context_params, NSView *metalView, CAMetalLayer *metalLayer)
GHOST_ContextVK(const GHOST_ContextParams &context_params, GHOST_TVulkanPlatformType platform, Window window, Display *display, wl_surface *wayland_surface, wl_display *wayland_display, const GHOST_ContextVK_WindowInfo *wayland_window_info, int contextMajorVersion, int contextMinorVersion, const GHOST_GPUDevice &preferred_device, const GHOST_WindowHDRInfo *hdr_info_=nullptr)
virtual bool getValid() const =0
GHOST_NDOFManagerCocoa(GHOST_System &)
virtual bool clip(GHOST_Rect &r) const
virtual void wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAxisFlag axis)
bool processEvents(bool waitForEvent) override
uint * getClipboardImage(int *r_width, int *r_height) const override
GHOST_TSuccess disposeContext(GHOST_IContext *context) override
void getAllDisplayDimensions(uint32_t &width, uint32_t &height) const override
GHOST_TSuccess getCursorPosition(int32_t &x, int32_t &y) const override
GHOST_TSuccess handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa *window)
GHOST_TSuccess handleDraggingEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType, GHOST_WindowCocoa *window, int mouseX, int mouseY, void *data)
GHOST_TSuccess handleApplicationBecomeActiveEvent()
GHOST_TSuccess hasClipboardImage() const override
GHOST_TSuccess handleMouseEvent(void *eventPtr)
GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys &keys) const override
void notifyExternalEventProcessed()
GHOST_TSuccess handleKeyEvent(void *eventPtr)
~GHOST_SystemCocoa() override
GHOST_TSuccess init() override
bool ignore_momentum_scroll_
GHOST_TSuccess getPixelAtCursor(float r_color[3]) const override
uint64_t getMilliSeconds() const override
GHOST_TCapabilityFlag getCapabilities() const override
GHOST_TSuccess showMessageBox(const char *title, const char *message, const char *help_label, const char *continue_label, const char *link, GHOST_DialogOptions dialog_options) const override
uint8_t getNumDisplays() const override
void getMainDisplayDimensions(uint32_t &width, uint32_t &height) const override
GHOST_TSuccess handleTabletEvent(void *eventPtr, short eventType)
bool handleOpenDocumentRequest(void *filepathStr)
GHOST_TSuccess setCursorPosition(int32_t x, int32_t y) override
bool ignore_window_sized_messages_
char * getClipboard(bool selection) const override
GHOST_TSuccess setMouseCursorPosition(int32_t x, int32_t y)
void putClipboard(const char *buffer, bool selection) const override
GHOST_TSuccess getButtons(GHOST_Buttons &buttons) const override
double last_warp_timestamp_
GHOST_IWindow * getWindowUnderCursor(int32_t x, int32_t y) override
GHOST_IContext * createOffscreenContext(GHOST_GPUSettings gpu_settings) override
uint32_t getCursorPreferredLogicalSize() const override
GHOST_IWindow * createWindow(const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_GPUSettings gpu_settings, const bool exclusive=false, const bool is_dialog=false, const GHOST_IWindow *parent_window=nullptr) override
bool outside_loop_event_processed_
bool need_delayed_application_become_active_event_processing_
GHOST_TSuccess putClipboardImage(uint *rgba, int width, int height) const override
GHOST_WindowManager * window_manager_
GHOST_TSuccess init() override
GHOST_TimerManager * getTimerManager() const
bool validWindow(GHOST_IWindow *window) override
GHOST_TSuccess pushEvent(std::unique_ptr< const GHOST_IEvent > event)
bool multitouch_gestures_
bool fireTimers(uint64_t time)
bool isDialog() const override
NSScreen * getScreen() const
void clientToScreenIntern(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const
void * getOSWindow() const override
GHOST_TabletData & GetCocoaTabletData()
void getClientBounds(GHOST_Rect &bounds) const override
void screenToClient(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const override
GHOST_WindowCocoa(GHOST_SystemCocoa *systemCocoa, const char *title, int32_t left, int32_t bottom, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_TDrawingContextType type, const GHOST_ContextParams &context_params, bool dialog, GHOST_WindowCocoa *parent_window, const GHOST_GPUDevice &preferred_device)
void setNativePixelSize()
void loadCursor(bool visible, GHOST_TStandardCursor cursor) const
GHOST_TSuccess addWindow(GHOST_IWindow *window)
GHOST_IWindow * getWindowAssociatedWithOSWindow(const void *osWindow)
const std::vector< GHOST_IWindow * > & getWindows() const
GHOST_IWindow * getActiveWindow() const
GHOST_TSuccess setActiveWindow(GHOST_IWindow *window)
void setWindowInactive(const GHOST_IWindow *window)
virtual GHOST_TSuccess getCursorGrabBounds(GHOST_Rect &bounds) const
void setCursorGrabAccum(int32_t x, int32_t y)
GHOST_TAxisFlag getCursorGrabAxis() const
GHOST_TStandardCursor getCursorShape() const override
bool getCursorVisibility() const override
GHOST_TGrabCursorMode getCursorGrabMode() const
GHOST_TSuccess updateDrawingContext()
bool getCursorGrabModeIsWarp() const
void getCursorGrabAccum(int32_t &x, int32_t &y) const
#define image(slot, qualifiers, format)
float length(VecOp< float, D >) RET
IMG_TEMPLATE SizeVec imageSize(const T &) RET
float3x3 scale(float3x3 mat, float2 scale)
GHOST_SystemCocoa * systemCocoa
void IMB_freeImBuf(ImBuf *ibuf)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, ImBufFlags flags)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
GHOST_TDrawingContextType context_type
GHOST_GPUDevice preferred_device
void set(GHOST_TModifierKey mask, bool down)
const uint8_t * byte_data() const
uint8_t * byte_data_for_write()