22# pragma clang diagnostic ignored "-Wdeprecated-declarations"
25#ifdef WITH_METAL_BACKEND
29#ifdef WITH_VULKAN_BACKEND
37#include "AssertMacros.h"
39#import <Cocoa/Cocoa.h>
42#include <Carbon/Carbon.h>
44#include <sys/sysctl.h>
48#include <mach/mach_time.h>
138 case kVK_ANSI_Keypad0:
140 case kVK_ANSI_Keypad1:
142 case kVK_ANSI_Keypad2:
144 case kVK_ANSI_Keypad3:
146 case kVK_ANSI_Keypad4:
148 case kVK_ANSI_Keypad5:
150 case kVK_ANSI_Keypad6:
152 case kVK_ANSI_Keypad7:
154 case kVK_ANSI_Keypad8:
156 case kVK_ANSI_Keypad9:
158 case kVK_ANSI_KeypadDecimal:
160 case kVK_ANSI_KeypadEnter:
162 case kVK_ANSI_KeypadPlus:
164 case kVK_ANSI_KeypadMinus:
166 case kVK_ANSI_KeypadMultiply:
168 case kVK_ANSI_KeypadDivide:
170 case kVK_ANSI_KeypadClear:
227 case kVK_ForwardDelete:
268 if ((recvChar >=
'A') && (recvChar <=
'Z')) {
272 if ((recvChar >=
'a') && (recvChar <=
'z')) {
277 const TISInputSourceRef kbdTISHandle = TISCopyCurrentKeyboardLayoutInputSource();
279 const CFDataRef uchrHandle =
static_cast<CFDataRef
>(
280 TISGetInputSourceProperty(kbdTISHandle, kTISPropertyUnicodeKeyLayoutData));
281 CFRelease(kbdTISHandle);
287 UInt32 deadKeyState = 0;
288 UniCharCount actualStrLength = 0;
290 UCKeyTranslate((UCKeyboardLayout *)CFDataGetBytePtr(uchrHandle),
295 kUCKeyTranslateNoDeadKeysMask,
341#define FIRSTFILEBUFLG 512
371- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
372- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
373- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
374- (void)applicationWillTerminate:(NSNotification *)aNotification;
375- (void)applicationWillBecomeActive:(NSNotification *)aNotification;
376- (void)toggleFullScreen:(NSNotification *)notification;
377- (void)windowWillClose:(NSNotification *)notification;
379- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app;
394 selector:@selector(windowWillClose:)
395 name:NSWindowWillCloseNotification
407 [
center removeObserver:
self name:NSWindowWillCloseNotification object:nil];
412- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
414 if (system_cocoa_->window_focus_) {
419 [
NSApp activateIgnoringOtherApps:YES];
422 [
NSEvent setMouseCoalescingEnabled:NO];
425- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
427 return system_cocoa_->handleOpenDocumentRequest(filename);
430- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
435 system_cocoa_->handleQuitRequest();
436 return NSTerminateCancel;
442- (void)applicationWillTerminate:(NSNotification *)aNotification
449- (void)applicationWillBecomeActive:(NSNotification *)aNotification
451 system_cocoa_->handleApplicationBecomeActiveEvent();
454- (void)toggleFullScreen:(NSNotification *)notification
475- (void)windowWillClose:(NSNotification *)notification
478 NSWindow *closing_window = (NSWindow *)[notification
object];
480 if (![closing_window isKeyWindow]) {
491 const NSInteger index = [[
NSApp orderedWindows] indexOfObject:closing_window];
492 if (index != NSNotFound) {
496 for (NSWindow *current_window
in [NSApp orderedWindows]) {
497 if (current_window == closing_window) {
500 if (current_window.isOnActiveSpace && current_window.canBecomeKeyWindow) {
506 for (NSNumber *window_number
in [NSWindow windowNumbersWithOptions:0]) {
507 NSWindow *current_window = [
NSApp windowWithWindowNumber:[
window_number integerValue]];
508 if (current_window == closing_window) {
511 if ([current_window canBecomeKeyWindow]) {
527- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
560 [
NSApp setDelegate:nil];
571#ifdef WITH_INPUT_NDOF
579 if (!GetCurrentProcess(&psn)) {
580 TransformProcessType(&psn, kProcessTransformToForegroundApplication);
581 SetFrontProcess(&psn);
588 if ([NSApp mainMenu] == nil) {
589 NSMenu *mainMenubar = [[
NSMenu alloc] init];
590 NSMenuItem *menuItem;
595 appMenu = [[
NSMenu alloc] initWithTitle:@"Blender"];
597 [
appMenu addItemWithTitle:@"About Blender"
598 action:@selector(orderFrontStandardAboutPanel:)
602 menuItem = [
appMenu addItemWithTitle:@"Hide Blender"
603 action:@selector(hide:)
605 menuItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
607 menuItem = [
appMenu addItemWithTitle:@"Hide Others"
608 action:@selector(hideOtherApplications:)
610 menuItem.keyEquivalentModifierMask = (NSEventModifierFlagOption |
611 NSEventModifierFlagCommand);
613 [
appMenu addItemWithTitle:@"Show All"
614 action:@selector(unhideAllApplications:)
617 menuItem = [
appMenu addItemWithTitle:@"Quit Blender"
618 action:@selector(terminate:)
620 menuItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
623 menuItem.submenu = appMenu;
630 windowMenu = [[
NSMenu alloc] initWithTitle:@"Window"];
632 menuItem = [
windowMenu addItemWithTitle:@"Minimize"
633 action:@selector(performMiniaturize:)
635 menuItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
637 [
windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
639 menuItem = [
windowMenu addItemWithTitle:@"Enter Full Screen"
640 action:@selector(toggleFullScreen:)
642 menuItem.keyEquivalentModifierMask = NSEventModifierFlagControl |
643 NSEventModifierFlagCommand;
645 menuItem = [
windowMenu addItemWithTitle:@"Close"
646 action:@selector(performClose:)
648 menuItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
651 menuItem.submenu = windowMenu;
656 [
NSApp setMainMenu:mainMenubar];
657 [
NSApp setWindowsMenu:windowMenu];
661 if ([NSApp delegate] == nil) {
663 [
NSApp setDelegate:appDelegate];
669 NSWindow.allowsAutomaticWindowTabbing = NO;
671 [
NSApp finishLaunching];
701 const NSRect contentRect = [
NSWindow
702 contentRectForFrameRect:frame
703 styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
704 NSWindowStyleMaskMiniaturizable)];
706 width = contentRect.size.width;
707 height = contentRect.size.height;
725 const bool is_dialog,
732 const NSRect primaryScreenFrame = [
GHOST_WindowCocoa::getPrimaryScreen() visibleFrame];
733 const NSRect primaryScreenContentRect = [
NSWindow
734 contentRectForFrameRect:primaryScreenFrame
735 styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
736 NSWindowStyleMaskMiniaturizable)];
738 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) {
837 return window_manager_->getWindowAssociatedWithOSWindow((
const void *)nswindow);
846 const NSPoint mouseLoc = [
NSEvent mouseLocation];
866 CGAssociateMouseAndMouseCursorPosition(
false);
868 CGAssociateMouseAndMouseCursorPosition(
true);
882 __block BOOL selectCompleted = NO;
883 __block BOOL samplingSucceeded = NO;
885 [
sampler showSamplerWithSelectionHandler:^(NSColor *selectedColor) {
886 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)),
887 dispatch_get_main_queue(),
889 if (selectedColor != nil) {
891 colorUsingColorSpace:[
NSColorSpace deviceRGBColorSpace]];
894 r_color[1] = [
rgbColor greenComponent];
895 r_color[2] = [
rgbColor blueComponent];
897 samplingSucceeded = YES;
899 selectCompleted = YES;
903 while (!selectCompleted) {
904 [[
NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
905 beforeDate:[
NSDate dateWithTimeIntervalSinceNow:0.05]];
921 NSScreen *windowScreen = window->
getScreen();
922 const NSRect screenRect = windowScreen.frame;
925 xf -= screenRect.origin.x;
926 yf -= screenRect.origin.y;
929 yf = screenRect.size.height - yf;
931 CGDisplayMoveCursorToPoint((CGDirectDisplayID)[[[windowScreen deviceDescription]
932 objectForKey:
@"NSScreenNumber"] unsignedIntValue],
933 CGPointMake(xf, yf));
940 CGAssociateMouseAndMouseCursorPosition(
true);
959 const UInt32 button_state = GetCurrentEventButtonState();
996 bool anyProcessed =
false;
1009 timeOut = kEventDurationForever;
1013 if (timeOut < 0.0) {
1018 ::ReceiveNextEvent(0,
nullptr, timeOut,
false, &event);
1022 anyProcessed =
true;
1027 event = [
NSApp nextEventMatchingMask:NSEventMaskAny
1028 untilDate:[
NSDate distantPast]
1029 inMode:NSDefaultRunLoopMode
1035 anyProcessed =
true;
1045 if (event.type == NSEventTypeKeyDown && event.keyCode == kVK_Tab &&
1046 (event.modifierFlags & NSEventModifierFlagControl))
1054 if (event.type == NSEventTypeKeyUp &&
1055 (event.modifierFlags & (NSEventModifierFlagCommand | NSEventModifierFlagOption)))
1060 [
NSApp sendEvent:event];
1063 }
while (event != nil);
1065 }
while (waitForEvent && !anyProcessed);
1079 return anyProcessed;
1089 [
window->getViewWindow() makeKeyAndOrderFront:nil];
1104 const unsigned int modifiers = [[[
NSApplication sharedApplication] currentEvent]
1107 if ((modifiers & NSEventModifierFlagShift) != (
modifier_mask_ & NSEventModifierFlagShift)) {
1115 if ((modifiers & NSEventModifierFlagControl) != (
modifier_mask_ & NSEventModifierFlagControl))
1124 if ((modifiers & NSEventModifierFlagOption) != (
modifier_mask_ & NSEventModifierFlagOption)) {
1132 if ((modifiers & NSEventModifierFlagCommand) != (
modifier_mask_ & NSEventModifierFlagCommand))
1172 switch (eventType) {
1236 NSImageRep *imageRepresentation = [[image representations] firstObject];
1237 return NSMakeSize(imageRepresentation.pixelsWide, imageRepresentation.pixelsHigh);
1256 NSBitmapImageRep *bitmapImage = nil;
1257 for (NSImageRep *representation
in [image representations]) {
1258 if ([representation isKindOfClass:[NSBitmapImageRep
class]]) {
1259 bitmapImage = (NSBitmapImageRep *)representation;
1264 if (bitmapImage == nil || bitmapImage.bitsPerPixel != 32 || bitmapImage.isPlanar ||
1265 bitmapImage.bitmapFormat & (NSBitmapFormatAlphaFirst | NSBitmapFormatFloatingPointSamples))
1271 uint8_t *bmp_data = (uint8_t *)bitmapImage.bitmapData;
1275 const int row_byte_count = 4 *
imageSize.width;
1276 const int ibuf_off = (
imageSize.height -
y - 1) * row_byte_count;
1277 const int bmp_off =
y * row_byte_count;
1278 memcpy(ibuf_data + ibuf_off, bmp_data + bmp_off, row_byte_count);
1296 switch (eventType) {
1302 getMilliSeconds(), eventType, draggedObjectType, window, mouseX, mouseY,
nullptr));
1312 switch (draggedObjectType) {
1314 NSArray *droppedArray = (NSArray *)
data;
1322 strArray->
count = droppedArray.count;
1323 if (strArray->
count == 0) {
1328 strArray->
strings = (uint8_t **)malloc(strArray->
count *
sizeof(uint8_t *));
1330 for (
int i = 0;
i < strArray->
count;
i++) {
1333 lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1334 uint8_t *temp_buff = (uint8_t *)malloc(pastedTextSize + 1);
1342 [droppedStr cStringUsingEncoding:NSUTF8StringEncoding],
1346 strArray->
strings[i] = temp_buff;
1353 NSString *droppedStr = (NSString *)
data;
1355 lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1356 uint8_t *temp_buff = (uint8_t *)malloc(pastedTextSize + 1);
1358 if (temp_buff ==
nullptr) {
1363 temp_buff, [droppedStr cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize);
1370 NSImage *droppedImg =
static_cast<NSImage *
>(
data);
1386 getMilliSeconds(), eventType, draggedObjectType, window, mouseX, mouseY, eventData));
1413 NSString *filepath = (NSString *)filepathStr;
1419 NSArray *windowsList = [
NSApp orderedWindows];
1420 if ([windowsList
count]) {
1421 [[
windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
1438 const size_t filenameTextSize = [
filepath lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1439 char *temp_buff = (
char *)malloc(filenameTextSize + 1);
1441 if (temp_buff ==
nullptr) {
1445 memcpy(temp_buff, [filepath cStringUsingEncoding:NSUTF8StringEncoding], filenameTextSize);
1458 NSEvent *
event = (NSEvent *)eventPtr;
1461 (
const void *)event.window);
1469 switch (eventType) {
1470 case NSEventTypeTabletPoint:
1480 ct.
Xtilt =
event.tilt.x;
1484 ct.
Ytilt = -
event.tilt.y;
1487 case NSEventTypeTabletProximity:
1490 if (event.isEnteringProximity) {
1492 switch (event.pointingDeviceType) {
1493 case NSPointingDeviceTypePen:
1496 case NSPointingDeviceTypeEraser:
1499 case NSPointingDeviceTypeCursor:
1500 case NSPointingDeviceTypeUnknown:
1508 GHOST_ASSERT(
FALSE,
"GHOST_SystemCocoa::handleTabletEvent : unknown event received");
1517 NSEvent *
event = (NSEvent *)eventPtr;
1519 switch (event.subtype) {
1520 case NSEventSubtypeTabletPoint:
1523 case NSEventSubtypeTabletProximity:
1534 NSEvent *
event = (NSEvent *)eventPtr;
1540 ->getWindowAssociatedWithOSWindow((
const void *)event.window);
1549 switch (event.type) {
1550 case NSEventTypeLeftMouseDown:
1558 case NSEventTypeRightMouseDown:
1566 case NSEventTypeOtherMouseDown:
1574 case NSEventTypeLeftMouseUp:
1582 case NSEventTypeRightMouseUp:
1590 case NSEventTypeOtherMouseUp:
1598 case NSEventTypeLeftMouseDragged:
1599 case NSEventTypeRightMouseDragged:
1600 case NSEventTypeOtherMouseDragged:
1603 case NSEventTypeMouseMoved: {
1605 bool is_tablet =
false;
1619 corrected_bounds.
t_ = 0;
1620 corrected_bounds.
l_ = 0;
1622 NSWindow *cocoa_window = (NSWindow *)window->
getOSWindow();
1623 const NSSize frame_size = cocoa_window.frame.size;
1625 corrected_bounds.
b_ = frame_size.height;
1626 corrected_bounds.
r_ = frame_size.width;
1636 corrected_bounds.
b_ = (window_bounds.
b_ - window_bounds.
t_) - corrected_bounds.
b_;
1637 corrected_bounds.
t_ = (window_bounds.
b_ - window_bounds.
t_) - corrected_bounds.
t_;
1642 NSWindow *cocoa_window = (NSWindow *)window->
getOSWindow();
1643 NSRect screen_visible_frame = window->
getScreen().visibleFrame;
1644 NSRect window_visible_frame = NSIntersectionRect(cocoa_window.frame, screen_visible_frame);
1645 NSRect local_visible_frame = [
cocoa_window convertRectFromScreen:window_visible_frame];
1648 visible_rect.
l_ = local_visible_frame.origin.x;
1649 visible_rect.
t_ = local_visible_frame.origin.y;
1650 visible_rect.
r_ = local_visible_frame.origin.x + local_visible_frame.size.width;
1651 visible_rect.
b_ = local_visible_frame.origin.y + local_visible_frame.size.height;
1654 visible_rect.
clip(corrected_bounds);
1663 const NSPoint mousePos =
event.window.mouseLocationOutsideOfEventStream;
1665 const int32_t x_mouse = mousePos.x;
1666 const int32_t y_mouse = mousePos.y;
1669 int32_t warped_x_mouse = x_mouse;
1670 int32_t warped_y_mouse = y_mouse;
1674 if (x_mouse != warped_x_mouse || y_mouse != warped_y_mouse) {
1679 const NSTimeInterval timestamp =
event.timestamp;
1680 const NSTimeInterval stale_event_threshold = 0.003;
1689 y_accum + (y_mouse - warped_y_mouse));
1707 const NSPoint mousePos =
event.locationInWindow;
1720 case NSEventTypeScrollWheel: {
1721 const NSEventPhase momentumPhase =
event.momentumPhase;
1722 const NSEventPhase phase =
event.phase;
1728 if (momentumPhase) {
1743 else if (phase == NSEventPhaseEnded) {
1751 if (event.deltaX != 0.0) {
1752 const int32_t delta =
event.deltaX > 0.0 ? 1 : -1;
1763 if (event.deltaY != 0.0) {
1764 const int32_t delta =
event.deltaY > 0.0 ? 1 : -1;
1770 const NSPoint mousePos =
event.locationInWindow;
1773 double dx =
event.scrollingDeltaX;
1774 double dy =
event.scrollingDeltaY;
1778 if (phase == NSEventPhaseNone && momentumPhase == NSEventPhaseNone) {
1790 convertPointToBacking:NSMakePoint(dx, dy)];
1798 event.isDirectionInvertedFromDevice));
1803 case NSEventTypeMagnify: {
1804 const NSPoint mousePos =
event.locationInWindow;
1812 event.magnification * 125.0 + 0.1,
1817 case NSEventTypeSmartMagnify: {
1818 const NSPoint mousePos =
event.locationInWindow;
1825 case NSEventTypeRotate: {
1826 const NSPoint mousePos =
event.locationInWindow;
1834 event.rotation * -5.0,
1847 NSEvent *
event = (NSEvent *)eventPtr;
1849 (
const void *)event.window);
1856 switch (event.type) {
1857 case NSEventTypeKeyDown:
1858 case NSEventTypeKeyUp: {
1861 char utf8_buf[6] = {
'\0'};
1864 NSString *charsIgnoringModifiers =
event.charactersIgnoringModifiers;
1865 if (charsIgnoringModifiers.length > 0) {
1866 keyCode =
convertKey(event.keyCode, [charsIgnoringModifiers characterAtIndex:0]);
1872 NSString *characters =
event.characters;
1873 if ([characters
length] > 0) {
1874 NSData *convertedCharacters = [
characters dataUsingEncoding:NSUTF8StringEncoding];
1876 for (
int x = 0;
x < convertedCharacters.length;
x++) {
1877 utf8_buf[x] = ((
char *)convertedCharacters.bytes)[x];
1901 if (event.type == NSEventTypeKeyDown) {
1909 printf(
"Key down rawCode=0x%x charsIgnoringModifiers=%c keyCode=%u utf8=%s\n",
1911 charsIgnoringModifiers.length > 0 ? [charsIgnoringModifiers characterAtIndex:0] :
1921 printf(
"Key up rawCode=0x%x charsIgnoringModifiers=%c keyCode=%u utf8=%s\n",
1923 charsIgnoringModifiers.length > 0 ? [charsIgnoringModifiers characterAtIndex:0] :
1932 case NSEventTypeFlagsChanged: {
1933 const unsigned int modifiers =
event.modifierFlags;
1935 if ((modifiers & NSEventModifierFlagShift) != (
modifier_mask_ & NSEventModifierFlagShift)) {
1943 if ((modifiers & NSEventModifierFlagControl) !=
1947 event.timestamp * 1000,
1953 if ((modifiers & NSEventModifierFlagOption) != (
modifier_mask_ & NSEventModifierFlagOption))
1956 event.timestamp * 1000,
1962 if ((modifiers & NSEventModifierFlagCommand) !=
1966 event.timestamp * 1000,
1992 NSPasteboard *pasteBoard = [
NSPasteboard generalPasteboard];
1993 NSString *textPasted = [
pasteBoard stringForType:NSPasteboardTypeString];
1995 if (textPasted == nil) {
1999 const size_t pastedTextSize = [
textPasted lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
2001 char *temp_buff = (
char *)malloc(pastedTextSize + 1);
2003 if (temp_buff ==
nullptr) {
2007 memcpy(temp_buff, [textPasted cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize);
2024 NSPasteboard *pasteBoard = NSPasteboard.generalPasteboard;
2027 NSString *textToCopy = [
NSString stringWithCString:buffer encoding:NSUTF8StringEncoding];
2028 [
pasteBoard setString:textToCopy forType:NSPasteboardTypeString];
2034 NSURL *pasteboardImageFile = nil;
2037 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
2038 NSDictionary *pasteboardFilteringOptions = @{
2039 NSPasteboardURLReadingFileURLsOnlyKey : @YES,
2040 NSPasteboardURLReadingContentsConformToTypesKey : [NSImage imageTypes]
2043 NSArray *pasteboardMatches = [pasteboard readObjectsForClasses:@[ [NSURL class] ]
2044 options:pasteboardFilteringOptions];
2046 if (!pasteboardMatches || !pasteboardMatches.count) {
2050 pasteboardImageFile = [[pasteboardMatches firstObject] copy];
2053 return [pasteboardImageFile autorelease];
2059 NSPasteboard *pasteboard = [
NSPasteboard generalPasteboard];
2060 NSArray *supportedTypes = [
NSArray
2061 arrayWithObjects:NSPasteboardTypeFileURL, NSPasteboardTypeTIFF, NSPasteboardTypePNG, nil];
2063 NSPasteboardType availableType = [
pasteboard availableTypeFromArray:supportedTypes];
2065 if (!availableType) {
2070 if ([pasteboard availableTypeFromArray:@[ NSPasteboardTypeFileURL ]] &&
2087 NSPasteboard *pasteboard = [
NSPasteboard generalPasteboard];
2089 NSImage *clipboardImage = nil;
2092 clipboardImage = [[[
NSImage alloc] initWithContentsOfURL:pasteboardImageFile] autorelease];
2096 clipboardImage = [[[
NSImage alloc] initWithPasteboard:pasteboard] autorelease];
2099 if (!clipboardImage) {
2107 const size_t byteCount = clipboardImageSize.width * clipboardImageSize.height * 4;
2108 uint *rgba = (
uint *)malloc(byteCount);
2118 *r_width = clipboardImageSize.width;
2119 *r_height = clipboardImageSize.height;
2131 const size_t rowByteCount = width * 4;
2134 initWithBitmapDataPlanes:nil
2141 colorSpaceName:NSDeviceRGBColorSpace
2142 bytesPerRow:rowByteCount
2146 uint8_t *srcBuffer =
reinterpret_cast<uint8_t *
>(rgba);
2147 uint8_t *dstBuffer =
static_cast<uint8_t *
>([
imageRep bitmapData]);
2149 for (
int y = 0;
y < height;
y++) {
2150 const int dstOff = (height -
y - 1) * rowByteCount;
2151 const int srcOff =
y * rowByteCount;
2152 memcpy(dstBuffer + dstOff, srcBuffer + srcOff, rowByteCount);
2155 NSImage *image = [[[
NSImage alloc] initWithSize:NSMakeSize(width, height)] autorelease];
2156 [
image addRepresentation:imageRep];
2158 NSPasteboard *pasteboard = [
NSPasteboard generalPasteboard];
2163 if (!pasteSuccess) {
2171 const char *message,
2172 const char *help_label,
2173 const char *continue_label,
2178 NSAlert *alert = [[[
NSAlert alloc] init] autorelease];
2179 alert.accessoryView = [[[
NSView alloc] initWithFrame:NSMakeRect(0, 0, 500, 0)] autorelease];
2181 NSString *titleString = [
NSString stringWithCString:title];
2182 NSString *messageString = [
NSString stringWithCString:message];
2183 NSString *continueString = [
NSString stringWithCString:continue_label];
2184 NSString *helpString = [
NSString stringWithCString:help_label];
2187 alert.alertStyle = NSAlertStyleCritical;
2190 alert.alertStyle = NSAlertStyleWarning;
2193 alert.alertStyle = NSAlertStyleInformational;
2196 alert.messageText = titleString;
2197 alert.informativeText = messageString;
2199 [
alert addButtonWithTitle:continueString];
2200 if (link && strlen(link)) {
2201 [
alert addButtonWithTitle:helpString];
2204 const NSModalResponse response = [
alert runModal];
2205 if (response == NSAlertSecondButtonReturn) {
2206 NSString *linkString = [
NSString stringWithCString:link];
void BLI_kdtree_nd_ free(KDTree *tree)
#define GHOST_ASSERT(x, info)
static GHOST_TKey convertKey(int rawCode, unichar recvChar)
static ImBuf * NSImageToImBuf(NSImage *image)
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 NSURL * NSPasteboardGetImageFile()
@ GHOST_kEventWheelAxisVertical
@ GHOST_kEventWheelAxisHorizontal
@ 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
static const GHOST_TabletData GHOST_TABLET_DATA_NONE
@ GHOST_kTabletModeEraser
@ GHOST_kTabletModeStylus
@ GHOST_kCapabilityClipboardPrimary
@ GHOST_kCapabilityKeyboardHyperKey
@ GHOST_kCapabilityCursorRGBA
@ GHOST_kCapabilityCursorGenerator
#define GHOST_CONTEXT_PARAMS_FROM_GPU_SETTINGS(gpu_settings)
void * GHOST_TDragnDropDataPtr
#define GHOST_CAPABILITY_FLAG_ALL
@ GHOST_kKeyNumpadAsterisk
const void * GHOST_TEventDataPtr
@ 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
void IMB_freeImBuf(ImBuf *ibuf)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
BMesh const char void * data
unsigned long long int uint64_t
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
virtual bool getValid() const =0
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
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
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
void setNativePixelSize()
void loadCursor(bool visible, GHOST_TStandardCursor cursor) const
GHOST_TSuccess getCursorGrabBounds(GHOST_Rect &bounds) const override
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
float length(VecOp< float, D >) RET
IMG_TEMPLATE SizeVec imageSize(const T &) RET
GHOST_SystemCocoa * systemCocoa
GHOST_TDrawingContextType context_type
GHOST_GPUDevice preferred_device
void set(GHOST_TModifierKey mask, bool down)
ImBufByteBuffer byte_buffer
void WM_exit(bContext *C, const int exit_code)