2015-12-30 06:41:46 +00:00
|
|
|
#if defined(Hiro_MessageWindow)
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
namespace hiro {
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
enum class MessageWindowType : uint { Error, Information, Question, Warning };
|
|
|
|
|
|
|
|
auto MessageWindow_dialog(MessageWindow::State& state, MessageWindowType type) -> MessageWindow::Response {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSAlert* alert = [[[NSAlert alloc] init] autorelease];
|
2013-03-19 08:48:50 +00:00
|
|
|
if(state.title) [alert setMessageText:[NSString stringWithUTF8String:state.title]];
|
|
|
|
[alert setInformativeText:[NSString stringWithUTF8String:state.text]];
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2013-03-19 08:48:50 +00:00
|
|
|
switch(state.buttons) {
|
2013-03-15 13:11:33 +00:00
|
|
|
case MessageWindow::Buttons::Ok:
|
|
|
|
[alert addButtonWithTitle:@"Ok"];
|
|
|
|
break;
|
|
|
|
case MessageWindow::Buttons::OkCancel:
|
|
|
|
[alert addButtonWithTitle:@"Ok"];
|
|
|
|
[alert addButtonWithTitle:@"Cancel"];
|
|
|
|
break;
|
|
|
|
case MessageWindow::Buttons::YesNo:
|
|
|
|
[alert addButtonWithTitle:@"Yes"];
|
|
|
|
[alert addButtonWithTitle:@"No"];
|
|
|
|
break;
|
|
|
|
case MessageWindow::Buttons::YesNoCancel:
|
|
|
|
[alert addButtonWithTitle:@"Yes"];
|
|
|
|
[alert addButtonWithTitle:@"No"];
|
|
|
|
[alert addButtonWithTitle:@"Cancel"];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(type) {
|
2013-03-19 08:48:50 +00:00
|
|
|
case MessageWindowType::Error: [alert setAlertStyle:NSCriticalAlertStyle]; break;
|
|
|
|
case MessageWindowType::Information: [alert setAlertStyle:NSInformationalAlertStyle]; break;
|
|
|
|
case MessageWindowType::Question: [alert setAlertStyle:NSInformationalAlertStyle]; break;
|
|
|
|
case MessageWindowType::Warning: [alert setAlertStyle:NSWarningAlertStyle]; break;
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NSInteger response = [alert runModal];
|
|
|
|
//[alert beginSheetModalForWindow:parent.p.cocoaWindow modalDelegate:self didEndSelector:@selector(...) contextInfo:nil];
|
|
|
|
|
2013-03-19 08:48:50 +00:00
|
|
|
switch(state.buttons) {
|
2013-03-15 13:11:33 +00:00
|
|
|
case MessageWindow::Buttons::Ok:
|
|
|
|
if(response == NSAlertFirstButtonReturn) return MessageWindow::Response::Ok;
|
|
|
|
break;
|
|
|
|
case MessageWindow::Buttons::OkCancel:
|
|
|
|
if(response == NSAlertFirstButtonReturn) return MessageWindow::Response::Ok;
|
|
|
|
if(response == NSAlertSecondButtonReturn) return MessageWindow::Response::Cancel;
|
|
|
|
break;
|
|
|
|
case MessageWindow::Buttons::YesNo:
|
|
|
|
if(response == NSAlertFirstButtonReturn) return MessageWindow::Response::Yes;
|
|
|
|
if(response == NSAlertSecondButtonReturn) return MessageWindow::Response::No;
|
|
|
|
break;
|
|
|
|
case MessageWindow::Buttons::YesNoCancel:
|
|
|
|
if(response == NSAlertFirstButtonReturn) return MessageWindow::Response::Yes;
|
|
|
|
if(response == NSAlertSecondButtonReturn) return MessageWindow::Response::No;
|
|
|
|
if(response == NSAlertThirdButtonReturn) return MessageWindow::Response::Cancel;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-19 08:48:50 +00:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pMessageWindow::error(MessageWindow::State& state) -> MessageWindow::Response {
|
2013-03-19 08:48:50 +00:00
|
|
|
return MessageWindow_dialog(state, MessageWindowType::Error);
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pMessageWindow::information(MessageWindow::State& state) -> MessageWindow::Response {
|
2013-03-19 08:48:50 +00:00
|
|
|
return MessageWindow_dialog(state, MessageWindowType::Information);
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pMessageWindow::question(MessageWindow::State& state) -> MessageWindow::Response {
|
2013-03-19 08:48:50 +00:00
|
|
|
return MessageWindow_dialog(state, MessageWindowType::Question);
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pMessageWindow::warning(MessageWindow::State& state) -> MessageWindow::Response {
|
2013-03-19 08:48:50 +00:00
|
|
|
return MessageWindow_dialog(state, MessageWindowType::Warning);
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-12-30 06:41:46 +00:00
|
|
|
|
|
|
|
#endif
|