Start implementing ui_cocoa_msg_window.m

This commit is contained in:
Twinaphex 2016-06-08 06:56:25 +02:00
parent 1fc0009cdc
commit aa81c1d82f
3 changed files with 102 additions and 5 deletions

View File

@ -19,21 +19,109 @@
#include <stdlib.h>
#include <string.h>
#include <string/stdstring.h>
#include "cocoa_common.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)
{
NSInteger response;
NSAlert* alert = [[NSAlert new] autorelease];
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:NSCriticalAlertStyle];
break;
case UI_MSG_WINDOW_TYPE_WARNING:
[alert setAlertStyle:NSWarningAlertStyle];
break;
case UI_MSG_WINDOW_TYPE_QUESTION:
[alert setAlertStyle:NSInformationalAlertStyle];
break;
case UI_MSG_WINDOW_TYPE_INFORMATION:
[alert setAlertStyle:NSInformationalAlertStyle];
break;
}
[alert beginSheetModalForWindow:((RetroArch_OSX*)[[NSApplication sharedApplication] delegate]).window
modalDelegate:apple_platform
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:nil];
response = [[NSApplication sharedApplication] runModalForWindow:[alert window]];
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_RESPONSE_CANCEL;
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_RESPONSE_CANCEL;
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_RESPONSE_CANCEL;
return ui_msg_window_cocoa_dialog(state, UI_MSG_WINDOW_TYPE_QUESTION);
}
const ui_msg_window_t ui_msg_window_cocoa = {

View File

@ -35,7 +35,7 @@
#include "../../system.h"
#include "../../tasks/tasks_internal.h"
static id apple_platform;
id apple_platform;
static void app_terminate(void)
{

View File

@ -41,12 +41,21 @@ enum ui_msg_window_buttons
enum ui_msg_window_response
{
UI_MSG_RESPONSE_OK = 0,
UI_MSG_RESPONSE_NA = 0,
UI_MSG_RESPONSE_OK,
UI_MSG_RESPONSE_CANCEL,
UI_MSG_RESPONSE_YES,
UI_MSG_RESPONSE_NO
};
enum ui_msg_window_type
{
UI_MSG_WINDOW_TYPE_ERROR = 0,
UI_MSG_WINDOW_TYPE_INFORMATION,
UI_MSG_WINDOW_TYPE_QUESTION,
UI_MSG_WINDOW_TYPE_WARNING
};
typedef struct ui_msg_window_state
{
enum ui_msg_window_buttons buttons;