/* * messagebox.c * d1x-rebirth * * Display an error or warning messagebox using the OS's window server. * */ #ifdef __APPLE__ #include #else #include #endif #include "window.h" #include "event.h" #include "messagebox.h" void display_mac_alert(char *message, int error) { int16_t itemHit; uint response; bool osX = FALSE; d_event event = { EVENT_WINDOW_DEACTIVATED }; window *wind; // Handle Descent's windows properly if ((wind = window_get_front())) window_send_event(window_get_front(), &event); event.type = EVENT_WINDOW_ACTIVATED; osX = ( Gestalt(gestaltSystemVersion, (long *) &response) == noErr) && (response >= 0x01000 ); if (osX) { #ifdef TARGET_API_MAC_CARBON DialogRef alert; CFStringRef error_text = CFSTR("Sorry, a critical error has occurred."); CFStringRef text = NULL; text = CFStringCreateWithCString(CFAllocatorGetDefault(), message, kCFStringEncodingMacRoman); if (!text) { if (wind) window_send_event(window_get_front(), &event); return; } if (CreateStandardAlert(error ? kAlertStopAlert : kAlertNoteAlert, error ? error_text : text, error ? text : NULL, 0, &alert) != noErr) { CFRelease(text); if (wind) window_send_event(window_get_front(), &event); return; } RunStandardAlert(alert, 0, &itemHit); CFRelease(text); #endif } else { Str255 error_text = "\pSorry, a critical error has occurred."; Str255 text; #if !defined(MAC_OS_X_VERSION_MAX_ALLOWED) || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4) // kill warning CopyCStringToPascal(message, text); #endif StandardAlert(error ? kAlertStopAlert : kAlertNoteAlert, error ? error_text : text, error ? text : NULL, 0, &itemHit); } if (wind) window_send_event(window_get_front(), &event); } void msgbox_warning(char *message) { display_mac_alert(message, 0); } void msgbox_error(char *message) { display_mac_alert(message, 1); }