src/video/SDL_video.c
changeset 7453 91c3bb321036
parent 7452 fae80e5464e2
child 7463 f2f794cf85c0
     1.1 --- a/src/video/SDL_video.c	Sun Jul 14 11:11:42 2013 -0700
     1.2 +++ b/src/video/SDL_video.c	Sun Jul 14 11:41:57 2013 -0700
     1.3 @@ -3052,6 +3052,20 @@
     1.4  #include "x11/SDL_x11messagebox.h"
     1.5  #endif
     1.6  
     1.7 +static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messageboxdata, SDL_SYSWM_TYPE drivertype)
     1.8 +{
     1.9 +    SDL_SysWMinfo info;
    1.10 +    SDL_Window *window = messageboxdata->window;
    1.11 +
    1.12 +    if (!window) {
    1.13 +        return SDL_TRUE;
    1.14 +    }
    1.15 +
    1.16 +    SDL_VERSION(&info.version);
    1.17 +    SDL_GetWindowWMInfo(window, &info);
    1.18 +    return (info.subsystem == drivertype);
    1.19 +}
    1.20 +
    1.21  int
    1.22  SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
    1.23  {
    1.24 @@ -3071,35 +3085,42 @@
    1.25      if (!buttonid) {
    1.26          buttonid = &dummybutton;
    1.27      }
    1.28 +
    1.29      if (_this && _this->ShowMessageBox) {
    1.30          retval = _this->ShowMessageBox(_this, messageboxdata, buttonid);
    1.31 -    } else {
    1.32 -        /* It's completely fine to call this function before video is initialized */
    1.33 -        if (messageboxdata->window == NULL) {
    1.34 +    }
    1.35 +
    1.36 +    /* It's completely fine to call this function before video is initialized */
    1.37  #if SDL_VIDEO_DRIVER_WINDOWS
    1.38 -            if ((retval == -1) && (WIN_ShowMessageBox(messageboxdata, buttonid) == 0)) {
    1.39 -                retval = 0;
    1.40 -            }
    1.41 +    if (retval == -1 &&
    1.42 +        SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINDOWS) &&
    1.43 +        WIN_ShowMessageBox(messageboxdata, buttonid) == 0) {
    1.44 +        retval = 0;
    1.45 +    }
    1.46  #endif
    1.47  #if SDL_VIDEO_DRIVER_COCOA
    1.48 -            if ((retval == -1) && (Cocoa_ShowMessageBox(messageboxdata, buttonid) == 0)) {
    1.49 -                retval = 0;
    1.50 -            }
    1.51 +    if (retval == -1 &&
    1.52 +        SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_COCOA) &&
    1.53 +        Cocoa_ShowMessageBox(messageboxdata, buttonid) == 0) {
    1.54 +        retval = 0;
    1.55 +    }
    1.56  #endif
    1.57  #if SDL_VIDEO_DRIVER_UIKIT
    1.58 -            if ((retval == -1) && (UIKit_ShowMessageBox(messageboxdata, buttonid) == 0)) {
    1.59 -                retval = 0;
    1.60 -            }
    1.61 +    if (retval == -1 &&
    1.62 +        SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_UIKIT) &&
    1.63 +        UIKit_ShowMessageBox(messageboxdata, buttonid) == 0) {
    1.64 +        retval = 0;
    1.65 +    }
    1.66  #endif
    1.67  #if SDL_VIDEO_DRIVER_X11
    1.68 -            if ((retval == -1) && (X11_ShowMessageBox(messageboxdata, buttonid) == 0)) {
    1.69 -                retval = 0;
    1.70 -            }
    1.71 +    if (retval == -1 &&
    1.72 +        SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_X11) &&
    1.73 +        X11_ShowMessageBox(messageboxdata, buttonid) == 0) {
    1.74 +        retval = 0;
    1.75 +    }
    1.76  #endif
    1.77 -        }
    1.78 -        if (retval == -1) {
    1.79 -            SDL_SetError("No message system available");
    1.80 -        }
    1.81 +    if (retval == -1) {
    1.82 +        SDL_SetError("No message system available");
    1.83      }
    1.84  
    1.85      SDL_ShowCursor(show_cursor_prev);