sdlayer: Clean up wm_msgbox and wm_ynbox and fix them under GTK. DONT_BUILD.

git-svn-id: https://svn.eduke32.com/eduke32@5976 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2016-12-29 02:57:33 +00:00
parent 346f391d4a
commit b107d3e0de
5 changed files with 63 additions and 91 deletions

View file

@ -7,8 +7,8 @@ extern "C" {
extern void gtkbuild_init(int32_t *argc, char ***argv); extern void gtkbuild_init(int32_t *argc, char ***argv);
extern void gtkbuild_exit(int32_t r); extern void gtkbuild_exit(int32_t r);
extern int32_t gtkbuild_msgbox(const char *name, const char *msg); extern int gtkbuild_msgbox(const char *name, const char *msg);
extern int32_t gtkbuild_ynbox(const char *name, const char *msg); extern int gtkbuild_ynbox(const char *name, const char *msg);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -6,8 +6,8 @@
extern "C" { extern "C" {
#endif #endif
int32_t osx_msgbox(const char *name, const char *msg); int osx_msgbox(const char *name, const char *msg);
int32_t osx_ynbox(const char *name, const char *msg); int osx_ynbox(const char *name, const char *msg);
char *osx_gethomedir(void); char *osx_gethomedir(void);
char *osx_getsupportdir(int32_t local); char *osx_getsupportdir(int32_t local);

View file

@ -16,7 +16,7 @@ int32_t gtkenabled = 0;
static GdkPixbuf *appicon = NULL; static GdkPixbuf *appicon = NULL;
int32_t gtkbuild_msgbox(const char *name, const char *msg) int gtkbuild_msgbox(const char *name, const char *msg)
{ {
GtkWidget *dialog; GtkWidget *dialog;
@ -34,7 +34,7 @@ int32_t gtkbuild_msgbox(const char *name, const char *msg)
return 1; return 1;
} }
int32_t gtkbuild_ynbox(const char *name, const char *msg) int gtkbuild_ynbox(const char *name, const char *msg)
{ {
int32_t r; int32_t r;
GtkWidget *dialog; GtkWidget *dialog;

View file

@ -170,29 +170,29 @@ int32_t wm_msgbox(const char *name, const char *fmt, ...)
#if defined EDUKE32_OSX #if defined EDUKE32_OSX
return osx_msgbox(name, buf); return osx_msgbox(name, buf);
#elif defined HAVE_GTK2
if (gtkbuild_msgbox(name, buf) >= 0) return 1;
#elif defined _WIN32 #elif defined _WIN32
MessageBox(win_gethwnd(),buf,name,MB_OK|MB_TASKMODAL); MessageBox(win_gethwnd(),buf,name,MB_OK|MB_TASKMODAL);
return 0; return 0;
#elif defined EDUKE32_TOUCH_DEVICES #elif defined EDUKE32_TOUCH_DEVICES
initprintf("wm_msgbox called. Message: %s: %s",name,buf); initprintf("wm_msgbox called. Message: %s: %s",name,buf);
return 0; return 0;
#elif SDL_MAJOR_VERSION==2
# if !defined _WIN32
// Replace all tab chars with spaces because the hand-rolled SDL message
// box diplays the former as N/L instead of whitespace.
{
size_t i;
for (i=0; i<sizeof(buf); i++)
if (buf[i] == '\t')
buf[i] = ' ';
}
# endif
return SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, name, buf, NULL);
#elif defined GEKKO #elif defined GEKKO
puts(buf); puts(buf);
return 0; return 0;
#else
# if defined HAVE_GTK2
if (gtkbuild_msgbox(name, buf) >= 0)
return 0;
# endif
# if SDL_MAJOR_VERSION > 1
# if !defined _WIN32
// Replace all tab chars with spaces because the hand-rolled SDL message
// box diplays the former as N/L instead of whitespace.
for (size_t i=0; i<sizeof(buf); i++)
if (buf[i] == '\t')
buf[i] = ' ';
# endif
return SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, name, buf, NULL);
# else # else
puts(buf); puts(buf);
puts(" (press Return or Enter to continue)"); puts(" (press Return or Enter to continue)");
@ -200,9 +200,9 @@ int32_t wm_msgbox(const char *name, const char *fmt, ...)
return 0; return 0;
# endif # endif
#endif
} }
#if SDL_MAJOR_VERSION != 1
int32_t wm_ynbox(const char *name, const char *fmt, ...) int32_t wm_ynbox(const char *name, const char *fmt, ...)
{ {
char buf[2048]; char buf[2048];
@ -211,26 +211,29 @@ int32_t wm_ynbox(const char *name, const char *fmt, ...)
UNREFERENCED_PARAMETER(name); UNREFERENCED_PARAMETER(name);
va_start(va,fmt); va_start(va,fmt);
vsprintf(buf,fmt,va); vsnprintf(buf,sizeof(buf),fmt,va);
va_end(va); va_end(va);
#if defined EDUKE32_OSX #if defined EDUKE32_OSX
return osx_ynbox(name, buf); return osx_ynbox(name, buf);
#elif defined HAVE_GTK2
{
int32_t r = gtkbuild_ynbox(name, buf);
return r >= 0 ? r : 0;
}
#elif defined _WIN32 #elif defined _WIN32
return (MessageBox(win_gethwnd(),buf,name,MB_YESNO|MB_ICONQUESTION|MB_TASKMODAL) == IDYES); return (MessageBox(win_gethwnd(),buf,name,MB_YESNO|MB_ICONQUESTION|MB_TASKMODAL) == IDYES);
#elif defined EDUKE32_TOUCH_DEVICES #elif defined EDUKE32_TOUCH_DEVICES
initprintf("wm_ynbox called, this is bad! Message: %s: %s",name,buf); initprintf("wm_ynbox called, this is bad! Message: %s: %s",name,buf);
initprintf("Returning false.."); initprintf("Returning false..");
return 0; return 0;
#elif defined GEKKO
puts(buf);
puts("Assuming yes...");
return 1;
#else #else
{ # if defined HAVE_GTK2
int32_t r = -1; int ret = gtkbuild_ynbox(name, buf);
if (ret >= 0)
return ret;
# endif
# if SDL_MAJOR_VERSION > 1
int r = -1;
const SDL_MessageBoxButtonData buttons[] = { const SDL_MessageBoxButtonData buttons[] = {
{ {
@ -257,10 +260,16 @@ int32_t wm_ynbox(const char *name, const char *fmt, ...)
SDL_ShowMessageBox(&data, &r); SDL_ShowMessageBox(&data, &r);
return r; return r;
} # else
char c;
puts(buf);
puts(" (type 'Y' or 'N', and press Return or Enter to continue)");
do c = getchar(); while (c != 'Y' && c != 'y' && c != 'N' && c != 'n');
return c == 'Y' || c == 'y';
# endif
#endif #endif
} }
#endif
void wm_setapptitle(const char *name) void wm_setapptitle(const char *name)
{ {

View file

@ -2,43 +2,6 @@
#include <SDL/SDL_events.h> #include <SDL/SDL_events.h>
int32_t wm_ynbox(const char *name, const char *fmt, ...)
{
char buf[2048];
char c;
va_list va;
UNREFERENCED_PARAMETER(name);
va_start(va, fmt);
vsprintf(buf, fmt, va);
va_end(va);
#if defined __APPLE__
return osx_ynbox(name, buf);
#elif defined HAVE_GTK2
{
int32_t r = gtkbuild_ynbox(name, buf);
if (r >= 0)
return r;
}
#elif defined _WIN32
return (MessageBox(win_gethwnd(),buf,name,MB_YESNO|MB_ICONQUESTION|MB_TASKMODAL) == IDYES);
#elif defined GEKKO
puts(buf);
puts("Assuming yes...");
return 1;
#endif
// NOTE: this is dead code for most #ifdef cases above.
puts(buf);
puts(" (type 'Y' or 'N', and press Return or Enter to continue)");
do c = getchar(); while (c != 'Y' && c != 'y' && c != 'N' && c != 'n');
if (c == 'Y' || c == 'y') return 1;
return 0;
}
#ifdef _WIN32 #ifdef _WIN32
HWND win_gethwnd(void) HWND win_gethwnd(void)
{ {