Skip to content

Commit

Permalink
Start implementing ui_cocoa_msg_window.m
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Jun 8, 2016
1 parent 1fc0009 commit aa81c1d
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 5 deletions.
94 changes: 91 additions & 3 deletions ui/drivers/cocoa/ui_cocoa_msg_window.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion ui/drivers/ui_cocoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "../../system.h"
#include "../../tasks/tasks_internal.h"

static id apple_platform;
id apple_platform;

static void app_terminate(void)
{
Expand Down
11 changes: 10 additions & 1 deletion ui/ui_companion_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit aa81c1d

Please sign in to comment.