test/testmessage.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 14 Jul 2013 11:57:45 -0700
changeset 7456 193c9a1723ad
parent 7088 664d8532219b
child 7458 648067e9073a
permissions -rw-r--r--
Added testing of messagebox with a parent window
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     3
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
  This software is provided 'as-is', without any express or implied
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
  arising from the use of this software.
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
  freely.
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
*/
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
/* Simple test of the SDL MessageBox API*/
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
#include <stdio.h>
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
#include <stdlib.h>
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
#include <signal.h>
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
#include "SDL.h"
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
#include "SDL_thread.h"
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
static int alive = 0;
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
static void
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
quit(int rc)
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
{
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
    SDL_Quit();
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
    exit(rc);
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
}
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    32
static int
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    33
button_messagebox(void *eventNumber)
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    34
{
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    35
    const SDL_MessageBoxButtonData buttons[] = {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    36
        {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    37
            SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    38
            0,
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    39
            "OK"
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    40
        },{
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    41
            SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    42
            1,
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    43
            "Cancel"
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    44
        },
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    45
    };
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    46
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    47
    SDL_MessageBoxData data = {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    48
        SDL_MESSAGEBOX_INFORMATION,
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    49
        NULL, // no parent window
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    50
        "Custom MessageBox",
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    51
        "This is a custom messagebox",
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    52
        2,
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    53
        buttons,
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    54
        NULL // Default color scheme
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    55
    };
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    56
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    57
    int button = -1;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    58
    int success = 0;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    59
    if (eventNumber) {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    60
        data.message = "This is a custom messagebox from a background thread.";
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    61
    }
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    62
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    63
    success =SDL_ShowMessageBox(&data, &button);
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    64
    if (success == -1) {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    65
        printf("Error Presenting MessageBox: %s\n", SDL_GetError());
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    66
        if (eventNumber) {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    67
            SDL_UserEvent event;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    68
            event.type = (intptr_t)eventNumber;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    69
            SDL_PushEvent((SDL_Event*)&event);
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    70
            return 1;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    71
        } else {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    72
            quit(2);
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    73
        }
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    74
    }
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    75
    printf("Pressed button: %d, %s\n", button, button == 1 ? "Cancel" : "OK");
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    76
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    77
    if (eventNumber) {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    78
        SDL_UserEvent event;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    79
        event.type = (intptr_t)eventNumber;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    80
        SDL_PushEvent((SDL_Event*)&event);
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    81
    }
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    82
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    83
    return 0;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    84
}
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    85
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
int
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
main(int argc, char *argv[])
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
{
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
    int success;
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    /* Load the SDL library */
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    92
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
        return (1);
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
    }
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
7456
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
    97
#if 0
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
                "Simple MessageBox",
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
                "This is a simple error MessageBox",
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
                NULL);
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
    if (success == -1) {
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
        printf("Error Presenting MessageBox: %s\n", SDL_GetError());
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
        quit(1);
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
    }
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
6758
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   107
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   108
                "Simple MessageBox",
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   109
                "This is a simple MessageBox with a newline:\r\nHello world!",
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   110
                NULL);
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   111
    if (success == -1) {
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   112
        printf("Error Presenting MessageBox: %s\n", SDL_GetError());
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   113
        quit(1);
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   114
    }
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   115
6722
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   116
    /* Google says this is Traditional Chinese for "beef with broccoli" */
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   117
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   118
                "UTF-8 Simple MessageBox",
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   119
                "Unicode text: '牛肉西蘭花' ...",
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   120
                NULL);
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   121
    if (success == -1) {
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   122
        printf("Error Presenting MessageBox: %s\n", SDL_GetError());
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   123
        quit(1);
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   124
    }
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   125
6758
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   126
    /* Google says this is Traditional Chinese for "beef with broccoli" */
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   127
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   128
                "UTF-8 Simple MessageBox",
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   129
                "Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'",
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   130
                NULL);
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   131
    if (success == -1) {
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   132
        printf("Error Presenting MessageBox: %s\n", SDL_GetError());
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   133
        quit(1);
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   134
    }
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   135
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   136
    button_messagebox(NULL);
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   137
7456
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   138
    /* Test showing a message box from a background thread */
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
    {
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   140
        int status = 0;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   141
        SDL_Event event;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   142
        intptr_t eventNumber = SDL_RegisterEvents(1);
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   143
        SDL_Thread* thread = SDL_CreateThread(&button_messagebox, "MessageBox", (void*)eventNumber);
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   145
        while (SDL_WaitEvent(&event))
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   146
        {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   147
            if (event.type == eventNumber) {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   148
                break;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   149
            }
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   150
        }
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   152
        SDL_WaitThread(thread, &status);
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   153
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   154
        printf("Message box thread return %i\n", status);
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
    }
7456
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   156
#endif
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   157
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   158
    /* Test showing a message box with a parent window */
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   159
    {
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   160
        SDL_Event event;
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   161
        SDL_Window *window = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   162
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   163
        success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   164
                    "Simple MessageBox",
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   165
                    "This is a simple error MessageBox with a parent window",
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   166
                    window);
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   167
        if (success == -1) {
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   168
            printf("Error Presenting MessageBox: %s\n", SDL_GetError());
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   169
            quit(1);
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   170
        }
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   171
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   172
        while (SDL_WaitEvent(&event))
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   173
        {
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   174
            if (event.type == SDL_QUIT || event.type == SDL_KEYUP) {
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   175
                break;
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   176
            }
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   177
        }
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   178
    }
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
    SDL_Quit();
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
    return (0);
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
}