6 # include <sys/types.h>
15 # include "osx_messagebox.h"
16 # elif defined(unix) && defined(HAVE_GTK2)
22 BOOL
CreateDirectory(const char* pathname
, void*)
24 if (mkdir(pathname
, S_IRWXU
| S_IRWXG
| S_IROTH
| S_IXOTH
)) {
25 if (errno
!= EEXIST
) {
26 std::string emsg
= "mkdir(";
27 emsg
.append(pathname
);
28 emsg
.append(") failed");
37 BOOL
DeleteFile(const char* filename
)
39 return !unlink(filename
);
42 void ZeroMemory(void* dest
, int len
)
47 /* Returns milliseconds since 1970
48 * Wraps every 24 days (assuming 32-bit signed dwords)
53 gettimeofday(&tp
, NULL
);
54 return (tp
.tv_sec
* 1000) + (tp
.tv_usec
/ 1000);
57 char* itoa(int value
, char* result
, int base
)
59 // check that the base is valid
60 if (base
< 2 || base
> 16) { *result
= 0; return result
; }
67 *out
= "0123456789abcdef"[ /*std::*/abs(quot
% base
) ];
73 if (value
< 0) *out
++ = '-';
75 std::reverse(result
, out
);
80 // Fills performanceCount with microseconds passed since 1970
81 // Wraps in twenty-nine thousand years or so
82 BOOL
QueryPerformanceCounter(LARGE_INTEGER
* performanceCount
)
85 gettimeofday(&tp
, NULL
);
86 performanceCount
->QuadPart
= ((long long)tp
.tv_sec
* 1000000) + tp
.tv_usec
;
90 BOOL
QueryPerformanceFrequency(LARGE_INTEGER
* performanceCount
)
92 /* A constant, 10^6, as we give microseconds since 1970 in
93 * QueryPerformanceCounter. */
94 performanceCount
->QuadPart
= 1000000;
99 int MessageBox(HWND
*dummy
, const char *text
, const char *caption
, UINT type
)
101 bool toggle_screen
= false;
103 if (enabler
.is_fullscreen()) {
104 enabler
.toggle_fullscreen();
105 toggle_screen
= true;
107 # ifdef __APPLE__ // Cocoa code
108 if (type
& MB_YESNO
) {
109 ret
= CocoaAlertPanel(caption
, text
, "Yes", "No", NULL
);
110 ret
= (ret
== 0 ? IDNO
: IDYES
);
112 CocoaAlertPanel(caption
, text
, "OK", NULL
, NULL
);
116 if (getenv("DISPLAY")) {
117 // Have X, will dialog
118 GtkWidget
*dialog
= gtk_message_dialog_new(NULL
,
119 GTK_DIALOG_DESTROY_WITH_PARENT
,
121 GTK_MESSAGE_QUESTION
:
127 gtk_window_set_position((GtkWindow
*)dialog
, GTK_WIN_POS_CENTER_ALWAYS
);
128 gtk_window_set_title((GtkWindow
*)dialog
, caption
);
129 gint dialog_ret
= gtk_dialog_run(GTK_DIALOG(dialog
));
130 gtk_widget_destroy(dialog
);
131 while (gtk_events_pending())
132 gtk_main_iteration();
134 if (type
& MB_YESNO
) {
135 switch (dialog_ret
) {
137 case GTK_RESPONSE_DELETE_EVENT
:
138 case GTK_RESPONSE_NO
:
141 case GTK_RESPONSE_YES
:
151 gps
.force_full_display_count
= 1;
152 wattrset(*stdscr_p
, A_NORMAL
| COLOR_PAIR(1));
154 mvwaddstr(*stdscr_p
, 0, 5, caption
);
155 mvwaddstr(*stdscr_p
, 2, 2, text
);
156 nodelay(*stdscr_p
, false);
157 if (type
& MB_YESNO
) {
158 mvwaddstr(*stdscr_p
, 5, 0, "Press 'y' or 'n'.");
161 char i
= wgetch(*stdscr_p
);
173 mvwaddstr(*stdscr_p
, 5, 0, "Press any key to continue.");
177 nodelay(*stdscr_p
, -1);
178 # else /* not APPLE, not GTK, not curses - use stdio */
179 dprintf(2, "Alert %s:\n%s\n", caption
? caption
: "", text
? text
: "");
180 if (type
& MB_YESNO
) {
182 dprintf(2, "please answer with 'yes' or 'no'\n");
184 fgets(buf
, sizeof buf
, stdin
);
185 if(!strncmp(buf
, "yes", 3)) ret
= IDYES
;
186 else if(!strncmp(buf
, "no", 2)) ret
= IDNO
;
189 # endif //end ifdef HAVE_GTK2 / CURSES
196 enabler
.toggle_fullscreen();