(Cocoa/OSX) Start unifying Cocoa Metal/Cocoa codepaths - was mostly the
same code
This commit is contained in:
parent
0a6c7acbd4
commit
cb829d8552
|
@ -38,26 +38,25 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_COCOATOUCH)
|
#if defined(HAVE_COCOATOUCH)
|
||||||
|
|
||||||
#if TARGET_OS_IOS
|
#if TARGET_OS_IOS
|
||||||
#include "../ui/drivers/cocoa/cocoatouch_menu.m"
|
#include "../ui/drivers/cocoa/cocoatouch_menu.m"
|
||||||
#endif
|
#endif
|
||||||
#include "../ui/drivers/ui_cocoatouch.m"
|
#include "../ui/drivers/ui_cocoatouch.m"
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL)
|
#if defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL)
|
||||||
#include "../ui/drivers/cocoa/ui_cocoa_window.m"
|
#include "../ui/drivers/cocoa/ui_cocoa_window.m"
|
||||||
|
#include "../ui/drivers/cocoa/ui_cocoa_browser_window.m"
|
||||||
|
#include "../ui/drivers/cocoa/ui_cocoa_application.m"
|
||||||
|
#include "../ui/drivers/cocoa/ui_cocoa_msg_window.m"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_COCOA)
|
#if defined(HAVE_COCOA)
|
||||||
#include "../ui/drivers/ui_cocoa.m"
|
#include "../ui/drivers/ui_cocoa.m"
|
||||||
#include "../ui/drivers/cocoa/ui_cocoa_browser_window.m"
|
|
||||||
#include "../ui/drivers/cocoa/ui_cocoa_msg_window.m"
|
|
||||||
#include "../ui/drivers/cocoa/ui_cocoa_application.m"
|
|
||||||
#elif defined(HAVE_COCOA_METAL)
|
#elif defined(HAVE_COCOA_METAL)
|
||||||
#include "../ui/drivers/ui_cocoa_metal.m"
|
#include "../ui/drivers/ui_cocoa_metal.m"
|
||||||
#include "../ui/drivers/cocoa/ui_cocoa_browser_window_metal.m"
|
|
||||||
#include "../ui/drivers/cocoa/ui_cocoa_msg_window_metal.m"
|
|
||||||
#include "../ui/drivers/cocoa/ui_cocoa_application_metal.m"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,7 +20,11 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <objc/objc-runtime.h>
|
#include <objc/objc-runtime.h>
|
||||||
|
#if defined(HAVE_COCOA_METAL)
|
||||||
|
#include "cocoa_common_metal.h"
|
||||||
|
#elif defined(HAVE_COCOA)
|
||||||
#include "cocoa_common.h"
|
#include "cocoa_common.h"
|
||||||
|
#endif
|
||||||
#include "../../ui_companion_driver.h"
|
#include "../../ui_companion_driver.h"
|
||||||
|
|
||||||
static void* ui_application_cocoa_initialize(void)
|
static void* ui_application_cocoa_initialize(void)
|
||||||
|
@ -30,7 +34,7 @@ static void* ui_application_cocoa_initialize(void)
|
||||||
|
|
||||||
static bool ui_application_cocoa_pending_events(void)
|
static bool ui_application_cocoa_pending_events(void)
|
||||||
{
|
{
|
||||||
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
|
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
|
||||||
if (!event)
|
if (!event)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -40,12 +44,16 @@ static void ui_application_cocoa_process_events(void)
|
||||||
{
|
{
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
|
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
|
||||||
if (!event)
|
if (!event)
|
||||||
break;
|
break;
|
||||||
|
#ifndef HAVE_COCOA_METAL
|
||||||
[event retain];
|
[event retain];
|
||||||
|
#endif
|
||||||
[NSApp sendEvent: event];
|
[NSApp sendEvent: event];
|
||||||
[event release];
|
#ifndef HAVE_COCOA_METAL
|
||||||
|
[event retain];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
/* RetroArch - A frontend for libretro.
|
|
||||||
* Copyright (C) 2011-2017 - Daniel De Matteis
|
|
||||||
*
|
|
||||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
||||||
* of the GNU General Public License as published by the Free Software Found-
|
|
||||||
* ation, either version 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
||||||
* PURPOSE. See the GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <boolean.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <objc/objc-runtime.h>
|
|
||||||
#include "cocoa_common_metal.h"
|
|
||||||
#include "../../ui_companion_driver.h"
|
|
||||||
|
|
||||||
static void* ui_application_cocoa_initialize(void)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ui_application_cocoa_pending_events(void)
|
|
||||||
{
|
|
||||||
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
|
|
||||||
if (!event)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ui_application_cocoa_process_events(void)
|
|
||||||
{
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
|
|
||||||
if (!event)
|
|
||||||
break;
|
|
||||||
[NSApp sendEvent: event];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ui_application_cocoa_run(void *args)
|
|
||||||
{
|
|
||||||
(void)args;
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_application_t ui_application_cocoa = {
|
|
||||||
ui_application_cocoa_initialize,
|
|
||||||
ui_application_cocoa_pending_events,
|
|
||||||
ui_application_cocoa_process_events,
|
|
||||||
ui_application_cocoa_run,
|
|
||||||
NULL,
|
|
||||||
"cocoa"
|
|
||||||
};
|
|
|
@ -21,36 +21,53 @@
|
||||||
|
|
||||||
#include <string/stdstring.h>
|
#include <string/stdstring.h>
|
||||||
|
|
||||||
#include "cocoa_common.h"
|
#if defined(HAVE_COCOA_METAL)
|
||||||
|
#include "cocoa_common_metal.h"
|
||||||
|
#elif defined(HAVE_COCOA)
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "../../ui_companion_driver.h"
|
#include "../../ui_companion_driver.h"
|
||||||
|
|
||||||
static bool ui_browser_window_cocoa_open(ui_browser_window_state_t *state)
|
static bool ui_browser_window_cocoa_open(ui_browser_window_state_t *state)
|
||||||
{
|
{
|
||||||
NSOpenPanel* panel = (NSOpenPanel*)[NSOpenPanel openPanel];
|
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
||||||
NSArray *filetypes = NULL;
|
|
||||||
|
if (!string_is_empty(state->filters))
|
||||||
|
{
|
||||||
|
#ifdef HAVE_COCOA_METAL
|
||||||
|
[panel setAllowedFileTypes:@[BOXSTRING(state->filters), BOXSTRING(state->filters_title)]];
|
||||||
|
#else
|
||||||
|
NSArray *filetypes = [[NSArray alloc] initWithObjects:BOXSTRING(state->filters), BOXSTRING(state->filters_title), nil];
|
||||||
|
[panel setAllowedFileTypes:filetypes];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (!string_is_empty(state->filters))
|
|
||||||
filetypes = [[NSArray alloc] initWithObjects:BOXSTRING(state->filters), BOXSTRING(state->filters_title), nil];
|
|
||||||
[panel setAllowedFileTypes:filetypes];
|
|
||||||
#if defined(MAC_OS_X_VERSION_10_6)
|
#if defined(MAC_OS_X_VERSION_10_6)
|
||||||
[panel setMessage:BOXSTRING(state->title)];
|
[panel setMessage:BOXSTRING(state->title)];
|
||||||
if ([panel runModalForDirectory:BOXSTRING(state->startdir) file:nil] != 1)
|
if ([panel runModalForDirectory:BOXSTRING(state->startdir) file:nil] != 1)
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
[panel setTitle:NSLocalizedString(BOXSTRING(state->title), BOXSTRING("open panel"))];
|
panel.title = NSLocalizedString(BOXSTRING(state->title), BOXSTRING("open panel"));
|
||||||
[panel setDirectory:BOXSTRING(state->startdir)];
|
panel.directoryURL = [NSURL fileURLWithPath:BOXSTRING(state->startdir)];
|
||||||
[panel setCanChooseDirectories:NO];
|
panel.canChooseDirectories = NO;
|
||||||
[panel setCanChooseFiles:YES];
|
panel.canChooseFiles = YES;
|
||||||
[panel setAllowsMultipleSelection:NO];
|
panel.allowsMultipleSelection = NO;
|
||||||
[panel setTreatsFilePackagesAsDirectories:NO];
|
panel.treatsFilePackagesAsDirectories = NO;
|
||||||
NSInteger result = [panel runModal];
|
|
||||||
if (result != 1)
|
#if defined(HAVE_COCOA_METAL)
|
||||||
return false;
|
NSModalResponse result = [panel runModal];
|
||||||
|
if (result != NSModalResponseOK)
|
||||||
|
return false;
|
||||||
|
#elif defined(HAVE_COCOA)
|
||||||
|
NSInteger result = [panel runModal];
|
||||||
|
if (result != 1)
|
||||||
|
return false;
|
||||||
#endif
|
#endif
|
||||||
NSURL *url = (NSURL*)panel.URL;
|
#endif
|
||||||
const char *res_path = [url.path UTF8String];
|
|
||||||
state->result = strdup(res_path);
|
NSURL *url = (NSURL*)panel.URL;
|
||||||
|
const char *res_path = [url.path UTF8String];
|
||||||
|
state->result = strdup(res_path);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
/* RetroArch - A frontend for libretro.
|
|
||||||
* Copyright (C) 2011-2017 - Daniel De Matteis
|
|
||||||
*
|
|
||||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
||||||
* of the GNU General Public License as published by the Free Software Found-
|
|
||||||
* ation, either version 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
||||||
* PURPOSE. See the GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <boolean.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <string/stdstring.h>
|
|
||||||
|
|
||||||
#include "cocoa_common_metal.h"
|
|
||||||
|
|
||||||
#include "../../ui_companion_driver.h"
|
|
||||||
|
|
||||||
static bool ui_browser_window_cocoa_open(ui_browser_window_state_t *state)
|
|
||||||
{
|
|
||||||
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
|
||||||
|
|
||||||
if (!string_is_empty(state->filters))
|
|
||||||
{
|
|
||||||
[panel setAllowedFileTypes:@[BOXSTRING(state->filters), BOXSTRING(state->filters_title)]];
|
|
||||||
}
|
|
||||||
|
|
||||||
panel.title = NSLocalizedString(BOXSTRING(state->title), BOXSTRING("open panel"));
|
|
||||||
panel.directoryURL = [NSURL fileURLWithPath:BOXSTRING(state->startdir)];
|
|
||||||
panel.canChooseDirectories = NO;
|
|
||||||
panel.canChooseFiles = YES;
|
|
||||||
panel.allowsMultipleSelection = NO;
|
|
||||||
panel.treatsFilePackagesAsDirectories = NO;
|
|
||||||
NSModalResponse result = [panel runModal];
|
|
||||||
if (result != NSModalResponseOK)
|
|
||||||
return false;
|
|
||||||
const char *res_path = [panel.URL.path UTF8String];
|
|
||||||
state->result = strdup(res_path);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ui_browser_window_cocoa_save(ui_browser_window_state_t *state)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_browser_window_t ui_browser_window_cocoa = {
|
|
||||||
ui_browser_window_cocoa_open,
|
|
||||||
ui_browser_window_cocoa_save,
|
|
||||||
"cocoa"
|
|
||||||
};
|
|
|
@ -21,92 +21,108 @@
|
||||||
|
|
||||||
#include <string/stdstring.h>
|
#include <string/stdstring.h>
|
||||||
|
|
||||||
|
#if defined(HAVE_COCOA_METAL)
|
||||||
|
#include "cocoa_common_metal.h"
|
||||||
|
#elif defined(HAVE_COCOA)
|
||||||
#include "cocoa_common.h"
|
#include "cocoa_common.h"
|
||||||
|
extern id apple_platform;
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "../../ui_companion_driver.h"
|
#include "../../ui_companion_driver.h"
|
||||||
|
|
||||||
extern id apple_platform;
|
|
||||||
|
|
||||||
static enum ui_msg_window_response ui_msg_window_cocoa_dialog(ui_msg_window_state *state, enum ui_msg_window_type type)
|
static enum ui_msg_window_response ui_msg_window_cocoa_dialog(ui_msg_window_state *state, enum ui_msg_window_type type)
|
||||||
{
|
{
|
||||||
NSInteger response;
|
#if defined(HAVE_COCOA_METAL)
|
||||||
NSAlert* alert = [[NSAlert new] autorelease];
|
NSModalResponse response;
|
||||||
|
NSAlert *alert = [NSAlert new];
|
||||||
|
#elif defined(HAVE_COCOA)
|
||||||
|
NSInteger response;
|
||||||
|
NSAlert* alert = [[NSAlert new] autorelease];
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!string_is_empty(state->title))
|
if (!string_is_empty(state->title))
|
||||||
[alert setMessageText:BOXSTRING(state->title)];
|
[alert setMessageText:BOXSTRING(state->title)];
|
||||||
[alert setInformativeText:BOXSTRING(state->text)];
|
[alert setInformativeText:BOXSTRING(state->text)];
|
||||||
|
|
||||||
switch (state->buttons)
|
switch (state->buttons)
|
||||||
{
|
{
|
||||||
case UI_MSG_WINDOW_OK:
|
case UI_MSG_WINDOW_OK:
|
||||||
[alert addButtonWithTitle:BOXSTRING("OK")];
|
[alert addButtonWithTitle:BOXSTRING("OK")];
|
||||||
break;
|
break;
|
||||||
case UI_MSG_WINDOW_YESNO:
|
case UI_MSG_WINDOW_YESNO:
|
||||||
[alert addButtonWithTitle:BOXSTRING("Yes")];
|
[alert addButtonWithTitle:BOXSTRING("Yes")];
|
||||||
[alert addButtonWithTitle:BOXSTRING("No")];
|
[alert addButtonWithTitle:BOXSTRING("No")];
|
||||||
break;
|
break;
|
||||||
case UI_MSG_WINDOW_OKCANCEL:
|
case UI_MSG_WINDOW_OKCANCEL:
|
||||||
[alert addButtonWithTitle:BOXSTRING("OK")];
|
[alert addButtonWithTitle:BOXSTRING("OK")];
|
||||||
[alert addButtonWithTitle:BOXSTRING("Cancel")];
|
[alert addButtonWithTitle:BOXSTRING("Cancel")];
|
||||||
break;
|
break;
|
||||||
case UI_MSG_WINDOW_YESNOCANCEL:
|
case UI_MSG_WINDOW_YESNOCANCEL:
|
||||||
[alert addButtonWithTitle:BOXSTRING("Yes")];
|
[alert addButtonWithTitle:BOXSTRING("Yes")];
|
||||||
[alert addButtonWithTitle:BOXSTRING("No")];
|
[alert addButtonWithTitle:BOXSTRING("No")];
|
||||||
[alert addButtonWithTitle:BOXSTRING("Cancel")];
|
[alert addButtonWithTitle:BOXSTRING("Cancel")];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case UI_MSG_WINDOW_TYPE_ERROR:
|
case UI_MSG_WINDOW_TYPE_ERROR:
|
||||||
[alert setAlertStyle:NSCriticalAlertStyle];
|
[alert setAlertStyle:NSAlertStyleCritical];
|
||||||
break;
|
break;
|
||||||
case UI_MSG_WINDOW_TYPE_WARNING:
|
case UI_MSG_WINDOW_TYPE_WARNING:
|
||||||
[alert setAlertStyle:NSWarningAlertStyle];
|
[alert setAlertStyle:NSAlertStyleWarning];
|
||||||
break;
|
break;
|
||||||
case UI_MSG_WINDOW_TYPE_QUESTION:
|
case UI_MSG_WINDOW_TYPE_QUESTION:
|
||||||
[alert setAlertStyle:NSInformationalAlertStyle];
|
[alert setAlertStyle:NSAlertStyleInformational];
|
||||||
break;
|
break;
|
||||||
case UI_MSG_WINDOW_TYPE_INFORMATION:
|
case UI_MSG_WINDOW_TYPE_INFORMATION:
|
||||||
[alert setAlertStyle:NSInformationalAlertStyle];
|
[alert setAlertStyle:NSAlertStyleInformational];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_COCOA_METAL)
|
||||||
|
[alert beginSheetModalForWindow:(BRIDGE NSWindow *)ui_companion_driver_get_main_window()
|
||||||
|
completionHandler:^(NSModalResponse returnCode) {
|
||||||
|
[[NSApplication sharedApplication] stopModalWithCode:returnCode];
|
||||||
|
}];
|
||||||
|
response = [alert runModal];
|
||||||
|
#elif defined(HAVE_COCOA)
|
||||||
[alert beginSheetModalForWindow:ui_companion_driver_get_main_window()
|
[alert beginSheetModalForWindow:ui_companion_driver_get_main_window()
|
||||||
modalDelegate:apple_platform
|
modalDelegate:apple_platform
|
||||||
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
|
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
|
||||||
contextInfo:nil];
|
contextInfo:nil];
|
||||||
response = [[NSApplication sharedApplication] runModalForWindow:[alert window]];
|
response = [[NSApplication sharedApplication] runModalForWindow:[alert window]];
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (state->buttons)
|
switch (state->buttons)
|
||||||
{
|
{
|
||||||
case UI_MSG_WINDOW_OK:
|
case UI_MSG_WINDOW_OK:
|
||||||
if (response == NSAlertFirstButtonReturn)
|
if (response == NSAlertFirstButtonReturn)
|
||||||
return UI_MSG_RESPONSE_OK;
|
return UI_MSG_RESPONSE_OK;
|
||||||
break;
|
break;
|
||||||
case UI_MSG_WINDOW_OKCANCEL:
|
case UI_MSG_WINDOW_OKCANCEL:
|
||||||
if (response == NSAlertFirstButtonReturn)
|
if (response == NSAlertFirstButtonReturn)
|
||||||
return UI_MSG_RESPONSE_OK;
|
return UI_MSG_RESPONSE_OK;
|
||||||
if (response == NSAlertSecondButtonReturn)
|
if (response == NSAlertSecondButtonReturn)
|
||||||
return UI_MSG_RESPONSE_CANCEL;
|
return UI_MSG_RESPONSE_CANCEL;
|
||||||
break;
|
break;
|
||||||
case UI_MSG_WINDOW_YESNO:
|
case UI_MSG_WINDOW_YESNO:
|
||||||
if (response == NSAlertFirstButtonReturn)
|
if (response == NSAlertFirstButtonReturn)
|
||||||
return UI_MSG_RESPONSE_YES;
|
return UI_MSG_RESPONSE_YES;
|
||||||
if (response == NSAlertSecondButtonReturn)
|
if (response == NSAlertSecondButtonReturn)
|
||||||
return UI_MSG_RESPONSE_NO;
|
return UI_MSG_RESPONSE_NO;
|
||||||
break;
|
break;
|
||||||
case UI_MSG_WINDOW_YESNOCANCEL:
|
case UI_MSG_WINDOW_YESNOCANCEL:
|
||||||
if (response == NSAlertFirstButtonReturn)
|
if (response == NSAlertFirstButtonReturn)
|
||||||
return UI_MSG_RESPONSE_YES;
|
return UI_MSG_RESPONSE_YES;
|
||||||
if (response == NSAlertSecondButtonReturn)
|
if (response == NSAlertSecondButtonReturn)
|
||||||
return UI_MSG_RESPONSE_NO;
|
return UI_MSG_RESPONSE_NO;
|
||||||
if (response == NSAlertThirdButtonReturn)
|
if (response == NSAlertThirdButtonReturn)
|
||||||
return UI_MSG_RESPONSE_CANCEL;
|
return UI_MSG_RESPONSE_CANCEL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return UI_MSG_RESPONSE_NA;
|
return UI_MSG_RESPONSE_NA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum ui_msg_window_response ui_msg_window_cocoa_error(ui_msg_window_state *state)
|
static enum ui_msg_window_response ui_msg_window_cocoa_error(ui_msg_window_state *state)
|
||||||
|
|
|
@ -1,136 +0,0 @@
|
||||||
/* RetroArch - A frontend for libretro.
|
|
||||||
* Copyright (C) 2011-2017 - Daniel De Matteis
|
|
||||||
*
|
|
||||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
||||||
* of the GNU General Public License as published by the Free Software Found-
|
|
||||||
* ation, either version 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
||||||
* PURPOSE. See the GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <boolean.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <string/stdstring.h>
|
|
||||||
|
|
||||||
#include "cocoa_common_metal.h"
|
|
||||||
|
|
||||||
#include "../../ui_companion_driver.h"
|
|
||||||
|
|
||||||
static enum ui_msg_window_response ui_msg_window_cocoa_dialog(ui_msg_window_state *state, enum ui_msg_window_type type)
|
|
||||||
{
|
|
||||||
NSModalResponse response;
|
|
||||||
NSAlert *alert = [NSAlert new];
|
|
||||||
|
|
||||||
if (!string_is_empty(state->title))
|
|
||||||
[alert setMessageText:BOXSTRING(state->title)];
|
|
||||||
[alert setInformativeText:BOXSTRING(state->text)];
|
|
||||||
|
|
||||||
switch (state->buttons)
|
|
||||||
{
|
|
||||||
case UI_MSG_WINDOW_OK:
|
|
||||||
[alert addButtonWithTitle:BOXSTRING("OK")];
|
|
||||||
break;
|
|
||||||
case UI_MSG_WINDOW_YESNO:
|
|
||||||
[alert addButtonWithTitle:BOXSTRING("Yes")];
|
|
||||||
[alert addButtonWithTitle:BOXSTRING("No")];
|
|
||||||
break;
|
|
||||||
case UI_MSG_WINDOW_OKCANCEL:
|
|
||||||
[alert addButtonWithTitle:BOXSTRING("OK")];
|
|
||||||
[alert addButtonWithTitle:BOXSTRING("Cancel")];
|
|
||||||
break;
|
|
||||||
case UI_MSG_WINDOW_YESNOCANCEL:
|
|
||||||
[alert addButtonWithTitle:BOXSTRING("Yes")];
|
|
||||||
[alert addButtonWithTitle:BOXSTRING("No")];
|
|
||||||
[alert addButtonWithTitle:BOXSTRING("Cancel")];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case UI_MSG_WINDOW_TYPE_ERROR:
|
|
||||||
[alert setAlertStyle:NSAlertStyleCritical];
|
|
||||||
break;
|
|
||||||
case UI_MSG_WINDOW_TYPE_WARNING:
|
|
||||||
[alert setAlertStyle:NSAlertStyleWarning];
|
|
||||||
break;
|
|
||||||
case UI_MSG_WINDOW_TYPE_QUESTION:
|
|
||||||
[alert setAlertStyle:NSAlertStyleInformational];
|
|
||||||
break;
|
|
||||||
case UI_MSG_WINDOW_TYPE_INFORMATION:
|
|
||||||
[alert setAlertStyle:NSAlertStyleInformational];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
[alert beginSheetModalForWindow:(BRIDGE NSWindow *)ui_companion_driver_get_main_window()
|
|
||||||
completionHandler:^(NSModalResponse returnCode) {
|
|
||||||
[[NSApplication sharedApplication] stopModalWithCode:returnCode];
|
|
||||||
}];
|
|
||||||
response = [alert runModal];
|
|
||||||
|
|
||||||
switch (state->buttons)
|
|
||||||
{
|
|
||||||
case UI_MSG_WINDOW_OK:
|
|
||||||
if (response == NSAlertFirstButtonReturn)
|
|
||||||
return UI_MSG_RESPONSE_OK;
|
|
||||||
break;
|
|
||||||
case UI_MSG_WINDOW_OKCANCEL:
|
|
||||||
if (response == NSAlertFirstButtonReturn)
|
|
||||||
return UI_MSG_RESPONSE_OK;
|
|
||||||
if (response == NSAlertSecondButtonReturn)
|
|
||||||
return UI_MSG_RESPONSE_CANCEL;
|
|
||||||
break;
|
|
||||||
case UI_MSG_WINDOW_YESNO:
|
|
||||||
if (response == NSAlertFirstButtonReturn)
|
|
||||||
return UI_MSG_RESPONSE_YES;
|
|
||||||
if (response == NSAlertSecondButtonReturn)
|
|
||||||
return UI_MSG_RESPONSE_NO;
|
|
||||||
break;
|
|
||||||
case UI_MSG_WINDOW_YESNOCANCEL:
|
|
||||||
if (response == NSAlertFirstButtonReturn)
|
|
||||||
return UI_MSG_RESPONSE_YES;
|
|
||||||
if (response == NSAlertSecondButtonReturn)
|
|
||||||
return UI_MSG_RESPONSE_NO;
|
|
||||||
if (response == NSAlertThirdButtonReturn)
|
|
||||||
return UI_MSG_RESPONSE_CANCEL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return UI_MSG_RESPONSE_NA;
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum ui_msg_window_response ui_msg_window_cocoa_error(ui_msg_window_state *state)
|
|
||||||
{
|
|
||||||
return ui_msg_window_cocoa_dialog(state, UI_MSG_WINDOW_TYPE_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum ui_msg_window_response ui_msg_window_cocoa_information(ui_msg_window_state *state)
|
|
||||||
{
|
|
||||||
return ui_msg_window_cocoa_dialog(state, UI_MSG_WINDOW_TYPE_INFORMATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum ui_msg_window_response ui_msg_window_cocoa_question(ui_msg_window_state *state)
|
|
||||||
{
|
|
||||||
return ui_msg_window_cocoa_dialog(state, UI_MSG_WINDOW_TYPE_QUESTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum ui_msg_window_response ui_msg_window_cocoa_warning(ui_msg_window_state *state)
|
|
||||||
{
|
|
||||||
return ui_msg_window_cocoa_dialog(state, UI_MSG_WINDOW_TYPE_WARNING);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_msg_window_t ui_msg_window_cocoa = {
|
|
||||||
ui_msg_window_cocoa_error,
|
|
||||||
ui_msg_window_cocoa_information,
|
|
||||||
ui_msg_window_cocoa_question,
|
|
||||||
ui_msg_window_cocoa_warning,
|
|
||||||
"cocoa"
|
|
||||||
};
|
|
Loading…
Reference in New Issue