Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | /* |
2 | * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
||
3 | * It is copyright by its individual contributors, as recorded in the |
||
4 | * project's Git history. See COPYING.txt at the top level for license |
||
5 | * terms and a link to the Git history. |
||
6 | */ |
||
7 | /* |
||
8 | * messagebox.c |
||
9 | * d1x-rebirth |
||
10 | * |
||
11 | * Display an error or warning messagebox using the OS's window server. |
||
12 | * |
||
13 | */ |
||
14 | |||
15 | #ifdef __APPLE__ |
||
16 | #include <Carbon/Carbon.h> |
||
17 | #else |
||
18 | #include <Carbon.h> |
||
19 | #endif |
||
20 | |||
21 | #include "window.h" |
||
22 | #include "event.h" |
||
23 | #include "messagebox.h" |
||
24 | |||
25 | void display_mac_alert(const char *message, int error) |
||
26 | { |
||
27 | window *wind; |
||
28 | d_event event; |
||
29 | int fullscreen; |
||
30 | bool osX = FALSE; |
||
31 | uint response; |
||
32 | int16_t itemHit; |
||
33 | |||
34 | // Handle Descent's windows properly |
||
35 | if ((wind = window_get_front())) |
||
36 | WINDOW_SEND_EVENT(wind, EVENT_WINDOW_DEACTIVATED); |
||
37 | |||
38 | if (grd_curscreen && (fullscreen = gr_check_fullscreen())) |
||
39 | gr_toggle_fullscreen(); |
||
40 | |||
41 | osX = ( Gestalt(gestaltSystemVersion, (long *) &response) == noErr) |
||
42 | && (response >= 0x01000 ); |
||
43 | |||
44 | ShowCursor(); |
||
45 | |||
46 | if (osX) |
||
47 | { |
||
48 | #ifdef TARGET_API_MAC_CARBON |
||
49 | DialogRef alert; |
||
50 | CFStringRef error_text = CFSTR("Sorry, a critical error has occurred."); |
||
51 | CFStringRef text = NULL; |
||
52 | |||
53 | text = CFStringCreateWithCString(CFAllocatorGetDefault(), message, kCFStringEncodingMacRoman); |
||
54 | if (!text) |
||
55 | { |
||
56 | if (wind) WINDOW_SEND_EVENT(wind, EVENT_WINDOW_ACTIVATED); |
||
57 | return; |
||
58 | } |
||
59 | |||
60 | if (CreateStandardAlert(error ? kAlertStopAlert : kAlertNoteAlert, error ? error_text : text, error ? text : NULL, 0, &alert) != noErr) |
||
61 | { |
||
62 | CFRelease(text); |
||
63 | if (wind) WINDOW_SEND_EVENT(wind, EVENT_WINDOW_ACTIVATED); |
||
64 | return; |
||
65 | } |
||
66 | |||
67 | RunStandardAlert(alert, 0, &itemHit); |
||
68 | CFRelease(text); |
||
69 | #endif |
||
70 | } |
||
71 | else |
||
72 | { |
||
73 | // This #if guard removes both compiler warnings |
||
74 | // and complications if we didn't link the (older) Mac OS X SDK that actually supports the following. |
||
75 | #if !defined(MAC_OS_X_VERSION_MAX_ALLOWED) || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4) |
||
76 | Str255 error_text = "\pSorry, a critical error has occurred."; |
||
77 | Str255 text; |
||
78 | |||
79 | CopyCStringToPascal(message, text); |
||
80 | StandardAlert(error ? kAlertStopAlert : kAlertNoteAlert, error ? error_text : text, error ? text : NULL, 0, &itemHit); |
||
81 | #endif |
||
82 | } |
||
83 | |||
84 | if ((wind = window_get_front())) |
||
85 | WINDOW_SEND_EVENT(wind, EVENT_WINDOW_ACTIVATED); |
||
86 | |||
87 | if (grd_curscreen && !error && fullscreen) |
||
88 | gr_toggle_fullscreen(); |
||
89 | } |
||
90 | |||
91 | void msgbox_warning(const char *message) |
||
92 | { |
||
93 | display_mac_alert(message, 0); |
||
94 | } |
||
95 | |||
96 | void msgbox_error(const char *message) |
||
97 | { |
||
98 | display_mac_alert(message, 1); |
||
99 | } |