src/video/x11/SDL_x11messagebox.c
author Michael Sartain <mikesart@valvesoftware.com>
Tue, 05 Feb 2013 12:10:54 -0800
changeset 6835 c259f0817583
parent 6817 93103b719488
child 6885 700f1b25f77f
permissions -rw-r--r--
Add defines to disable setlocale and fork. Disable that code by default for now.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
  Simple DirectMedia Layer
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
  This software is provided 'as-is', without any express or implied
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
  arising from the use of this software.
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
  freely, subject to the following restrictions:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
     claim that you wrote the original software. If you use this software
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
     appreciated but is not required.
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
     misrepresented as being the original software.
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
    21
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
#include "SDL_config.h"
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
#if SDL_VIDEO_DRIVER_X11
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "SDL.h"
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include "SDL_x11video.h"
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "SDL_x11dyn.h"
6726
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
    29
#include "SDL_assert.h"
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
    31
#include <locale.h>
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
    32
6726
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
    33
6835
c259f0817583 Add defines to disable setlocale and fork. Disable that code by default for now.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6817
diff changeset
    34
#define SDL_FORK_MESSAGEBOX 0
c259f0817583 Add defines to disable setlocale and fork. Disable that code by default for now.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6817
diff changeset
    35
#define SDL_SET_LOCALE      0
6726
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
    36
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
    37
#if SDL_FORK_MESSAGEBOX
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
    38
#include <sys/types.h>
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
    39
#include <sys/wait.h>
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
    40
#include <unistd.h>
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
    41
#include <errno.h>
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
    42
#endif
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
    43
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
#define MAX_BUTTONS             8       /* Maximum number of buttons supported */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
#define MAX_TEXT_LINES          32      /* Maximum number of text lines supported */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
#define MIN_BUTTON_WIDTH        64      /* Minimum button width */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
#define MIN_DIALOG_WIDTH        200     /* Minimum dialog width */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
#define MIN_DIALOG_HEIGHT       100     /* Minimum dialog height */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
    50
static const char g_MessageBoxFontLatin1[] = "-*-*-medium-r-normal--0-120-*-*-p-0-iso8859-1";
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
    51
static const char g_MessageBoxFont[] = "-*-*-*-*-*-*-*-*-*-*-*-*-*-*";
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
    53
static const SDL_MessageBoxColor g_default_colors[ SDL_MESSAGEBOX_COLOR_MAX ] = {
6817
93103b719488 Cleaned out a few C++ single-line comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 6758
diff changeset
    54
    { 56,  54,  53  }, /* SDL_MESSAGEBOX_COLOR_BACKGROUND, */
93103b719488 Cleaned out a few C++ single-line comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 6758
diff changeset
    55
    { 209, 207, 205 }, /* SDL_MESSAGEBOX_COLOR_TEXT, */
93103b719488 Cleaned out a few C++ single-line comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 6758
diff changeset
    56
    { 140, 135, 129 }, /* SDL_MESSAGEBOX_COLOR_BUTTON_BORDER, */
93103b719488 Cleaned out a few C++ single-line comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 6758
diff changeset
    57
    { 105, 102, 99  }, /* SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND, */
93103b719488 Cleaned out a few C++ single-line comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 6758
diff changeset
    58
    { 205, 202, 53  }, /* SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED, */
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
};
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
#define SDL_MAKE_RGB( _r, _g, _b )  ( ( ( Uint32 )( _r ) << 16 ) | \
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
                                      ( ( Uint32 )( _g ) << 8 ) |  \
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
                                      ( ( Uint32 )( _b ) ) )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
    65
typedef struct SDL_MessageBoxButtonDataX11 {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
    int x, y;                           /* Text position */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
    int length;                         /* Text length */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
    int text_width;                     /* Text width */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
    SDL_Rect rect;                      /* Rectangle for entire button */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
    const SDL_MessageBoxButtonData *buttondata;   /* Button data from caller */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
} SDL_MessageBoxButtonDataX11;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
    75
typedef struct TextLineData {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
    int width;                          /* Width of this text line */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
    int length;                         /* String length of this text line */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
    const char *text;                   /* Text for this line */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
} TextLineData;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
    81
typedef struct SDL_MessageBoxDataX11 {
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
    82
    XFontSet font_set;                  /* for UTF-8 systems */
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
    83
    XFontStruct *font_struct;            /* Latin1 (ASCII) fallback. */
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
    Window window;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    Display *display;
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
    86
    long event_mask;
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
    Atom wm_protocols;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
    Atom wm_delete_message;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
    int dialog_width;                   /* Dialog box width. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    int dialog_height;                  /* Dialog box height. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
    int xtext, ytext;                   /* Text position to start drawing at. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
    int numlines;                       /* Count of Text lines. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
    int text_height;                    /* Height for text lines. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
    TextLineData linedata[ MAX_TEXT_LINES ];
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
    int *pbuttonid;                     /* Pointer to user return buttonid value. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
    int button_press_index;             /* Index into buttondata/buttonpos for button which is pressed (or -1). */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
    int mouse_over_index;               /* Index into buttondata/buttonpos for button mouse is over (or -1). */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
    int numbuttons;                     /* Count of buttons. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
    const SDL_MessageBoxButtonData *buttondata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
    SDL_MessageBoxButtonDataX11 buttonpos[ MAX_BUTTONS ];
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   107
    Uint32 color[ SDL_MESSAGEBOX_COLOR_MAX ];
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
    const SDL_MessageBoxData *messageboxdata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
} SDL_MessageBoxDataX11;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
/* Maximum helper for ints. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
static __inline__ int
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
IntMax( int a, int b )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
    return ( a > b  ) ? a : b;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
/* Return width and height for a string. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
static void
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   121
GetTextWidthHeight( SDL_MessageBoxDataX11 *data, const char *str, int nbytes, int *pwidth, int *pheight )
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
{
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   123
    if (SDL_X11_HAVE_UTF8) {
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   124
        XRectangle overall_ink, overall_logical;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   125
        Xutf8TextExtents(data->font_set, str, nbytes, &overall_ink, &overall_logical);
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   126
        *pwidth = overall_logical.width;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   127
        *pheight = overall_logical.height;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   128
    } else {
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   129
        XCharStruct text_structure;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   130
        int font_direction, font_ascent, font_descent;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   131
        XTextExtents( data->font_struct, str, nbytes,
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   132
                      &font_direction, &font_ascent, &font_descent,
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   133
                      &text_structure );
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   134
        *pwidth = text_structure.width;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   135
        *pheight = text_structure.ascent + text_structure.descent;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   136
    }
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
/* Return index of button if position x,y is contained therein. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
static int
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
GetHitButtonIndex( SDL_MessageBoxDataX11 *data, int x, int y )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
    int i;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
    int numbuttons = data->numbuttons;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
    SDL_MessageBoxButtonDataX11 *buttonpos = data->buttonpos;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   147
    for ( i = 0; i < numbuttons; i++ ) {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
        SDL_Rect *rect = &buttonpos[ i ].rect;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
        if ( ( x >= rect->x ) &&
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   151
             ( x <= ( rect->x + rect->w ) ) &&
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   152
             ( y >= rect->y ) &&
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   153
             ( y <= ( rect->y + rect->h ) ) ) {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
            return i;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
        }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
    return -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
/* Initialize SDL_MessageBoxData structure and Display, etc. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
static int
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
X11_MessageBoxInit( SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData * messageboxdata, int * pbuttonid )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
{
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   165
    int i;
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
    int numbuttons = messageboxdata->numbuttons;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
    const SDL_MessageBoxButtonData *buttondata = messageboxdata->buttons;
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   168
    const SDL_MessageBoxColor *colorhints;
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
    if ( numbuttons > MAX_BUTTONS ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
        SDL_SetError("Too many buttons (%d max allowed)", MAX_BUTTONS);
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
        return -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
    data->dialog_width = MIN_DIALOG_WIDTH;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
    data->dialog_height = MIN_DIALOG_HEIGHT;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
    data->messageboxdata = messageboxdata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
    data->buttondata = buttondata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
    data->numbuttons = numbuttons;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
    data->pbuttonid = pbuttonid;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
    data->display = XOpenDisplay( NULL );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
    if ( !data->display ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
        SDL_SetError("Couldn't open X11 display");
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
        return -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   188
    if (SDL_X11_HAVE_UTF8) {
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   189
        char **missing = NULL;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   190
        int num_missing = 0;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   191
        data->font_set = XCreateFontSet(data->display, g_MessageBoxFont,
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   192
                                        &missing, &num_missing, NULL);
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   193
        if ( missing != NULL ) {
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   194
            XFreeStringList(missing);
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   195
        }
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   196
        if ( data->font_set == NULL ) {
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   197
            SDL_SetError("Couldn't load font %s", g_MessageBoxFont);
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   198
            return -1;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   199
        }
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   200
    } else {
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   201
        data->font_struct = XLoadQueryFont( data->display, g_MessageBoxFontLatin1 );
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   202
        if ( data->font_struct == NULL ) {
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   203
            SDL_SetError("Couldn't load font %s", g_MessageBoxFontLatin1);
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   204
            return -1;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   205
        }
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   208
    if ( messageboxdata->colorScheme ) {
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   209
        colorhints = messageboxdata->colorScheme->colors;
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   210
    } else {
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   211
        colorhints = g_default_colors;
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   212
    }
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   214
    /* Convert our SDL_MessageBoxColor r,g,b values to packed RGB format. */
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   215
    for ( i = 0; i < SDL_MESSAGEBOX_COLOR_MAX; i++ ) {
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   216
        data->color[ i ] = SDL_MAKE_RGB( colorhints[ i ].r, colorhints[ i ].g, colorhints[ i ].b );
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   217
    }
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
    return 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
/* Calculate and initialize text and button locations. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
static int
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
X11_MessageBoxInitPositions( SDL_MessageBoxDataX11 *data )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
    int i;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
    int ybuttons;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
    int text_width_max = 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
    int button_text_height = 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
    int button_width = MIN_BUTTON_WIDTH;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
    const SDL_MessageBoxData *messageboxdata = data->messageboxdata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
    /* Go over text and break linefeeds into separate lines. */
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   234
    if ( messageboxdata->message && messageboxdata->message[ 0 ] ) {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
        const char *text = messageboxdata->message;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
        TextLineData *plinedata = data->linedata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   238
        for ( i = 0; i < MAX_TEXT_LINES; i++, plinedata++ ) {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
            int height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
            char *lf = SDL_strchr( ( char * )text, '\n' );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
            data->numlines++;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
            /* Only grab length up to lf if it exists and isn't the last line. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
            plinedata->length = ( lf && ( i < MAX_TEXT_LINES - 1 ) ) ? ( lf - text ) : SDL_strlen( text );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
            plinedata->text = text;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   248
            GetTextWidthHeight( data, text, plinedata->length, &plinedata->width, &height );
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
            /* Text and widths are the largest we've ever seen. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
            data->text_height = IntMax( data->text_height, height );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
            text_width_max = IntMax( text_width_max, plinedata->width );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
6758
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6726
diff changeset
   254
            if (lf && (lf > text) && (lf[-1] == '\r')) {
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6726
diff changeset
   255
                plinedata->length--;
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6726
diff changeset
   256
            }
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6726
diff changeset
   257
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
            text += plinedata->length + 1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
            /* Break if there are no more linefeeds. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
            if ( !lf )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
                break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
        }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
        /* Bump up the text height slightly. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   266
        data->text_height += 2;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
    /* Loop through all buttons and calculate the button widths and height. */
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   270
    for ( i = 0; i < data->numbuttons; i++ ) {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
        int height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
        data->buttonpos[ i ].buttondata = &data->buttondata[ i ];
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
        data->buttonpos[ i ].length = SDL_strlen( data->buttondata[ i ].text );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   276
        GetTextWidthHeight( data, data->buttondata[ i ].text, SDL_strlen( data->buttondata[ i ].text ),
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   277
                            &data->buttonpos[ i ].text_width, &height );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   278
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
        button_width = IntMax( button_width, data->buttonpos[ i ].text_width );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
        button_text_height = IntMax( button_text_height, height );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   283
    if ( data->numlines ) {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
        /* x,y for this line of text. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
        data->xtext = data->text_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   286
        data->ytext = data->text_height + data->text_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
        /* Bump button y down to bottom of text. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
        ybuttons = 3 * data->ytext / 2 + ( data->numlines - 1 ) * data->text_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
        /* Bump the dialog box width and height up if needed. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
        data->dialog_width = IntMax( data->dialog_width, 2 * data->xtext + text_width_max );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
        data->dialog_height = IntMax( data->dialog_height, ybuttons );
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   294
    } else {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
        /* Button y starts at height of button text. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
        ybuttons = button_text_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   299
    if ( data->numbuttons ) {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
        int x, y;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
        int width_of_buttons;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
        int button_spacing = button_text_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
        int button_height = 2 * button_text_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
        /* Bump button width up a bit. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
        button_width += button_text_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
        /* Get width of all buttons lined up. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
        width_of_buttons = data->numbuttons * button_width + ( data->numbuttons - 1 ) * button_spacing;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
        /* Bump up dialog width and height if buttons are wider than text. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
        data->dialog_width = IntMax( data->dialog_width, width_of_buttons + 2 * button_spacing );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
        data->dialog_height = IntMax( data->dialog_height, ybuttons + 2 * button_height );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
        /* Location for first button. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
        x = ( data->dialog_width - width_of_buttons ) / 2;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
        y = ybuttons + ( data->dialog_height - ybuttons - button_height ) / 2;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   319
        for ( i = 0; i < data->numbuttons; i++ ) {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
            /* Button coordinates. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
            data->buttonpos[ i ].rect.x = x;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   322
            data->buttonpos[ i ].rect.y = y;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
            data->buttonpos[ i ].rect.w = button_width;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
            data->buttonpos[ i ].rect.h = button_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
            /* Button text coordinates. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
            data->buttonpos[ i ].x = x + ( button_width - data->buttonpos[ i ].text_width ) / 2;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
            data->buttonpos[ i ].y = y + ( button_height - button_text_height - 1 ) / 2 + button_text_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
            /* Scoot over for next button. */
6615
d7a463bde4d7 Use the correct variable for the button spacing (even though they end up being the same thing)
Sam Lantinga <slouken@libsdl.org>
parents: 6603
diff changeset
   331
            x += button_width + button_spacing;
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   332
        }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   333
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   334
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
    return 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
/* Free SDL_MessageBoxData data. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
static void
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
X11_MessageBoxShutdown( SDL_MessageBoxDataX11 *data )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
{
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   342
    if ( data->font_set != NULL ) {
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   343
        XFreeFontSet( data->display, data->font_set );
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   344
        data->font_set = NULL;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   345
    }
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   346
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   347
    if ( data->font_struct != NULL ) {
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   348
        XFreeFont( data->display, data->font_struct );
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   349
        data->font_struct = NULL;
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   350
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   351
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   352
    if ( data->display ) {
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   353
        if ( data->window != None ) {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   354
            XUnmapWindow( data->display, data->window );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   355
            XDestroyWindow( data->display, data->window );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
            data->window = None;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
        }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
        XCloseDisplay( data->display );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
        data->display = NULL;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   364
/* Create and set up our X11 dialog box indow. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   365
static int
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   366
X11_MessageBoxCreateWindow( SDL_MessageBoxDataX11 *data )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   367
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   368
    int x, y;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   369
    XSizeHints *sizehints;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   370
    XSetWindowAttributes wnd_attr;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
    Display *display = data->display;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   372
    SDL_WindowData *windowdata = NULL;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   373
    const SDL_MessageBoxData *messageboxdata = data->messageboxdata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
    if ( messageboxdata->window ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   376
        windowdata = (SDL_WindowData *)messageboxdata->window->driverdata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   377
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   378
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   379
    data->event_mask = ExposureMask |
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   380
                       ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   381
                       StructureNotifyMask | FocusChangeMask | PointerMotionMask;
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   382
    wnd_attr.event_mask = data->event_mask;
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   383
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   384
    data->window = XCreateWindow(
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   385
                       display, DefaultRootWindow( display ),
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   386
                       0, 0,
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   387
                       data->dialog_width, data->dialog_height,
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   388
                       0, CopyFromParent, InputOutput, CopyFromParent,
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   389
                       CWEventMask, &wnd_attr );
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
    if ( data->window == None ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   391
        SDL_SetError("Couldn't create X window");
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   392
        return -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   393
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
    if ( windowdata ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
        /* http://tronche.com/gui/x/icccm/sec-4.html#WM_TRANSIENT_FOR */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
        XSetTransientForHint( display, data->window, windowdata->xwindow );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
    XStoreName( display, data->window, messageboxdata->title );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
    /* Allow the window to be deleted by the window manager */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
    data->wm_protocols = XInternAtom( display, "WM_PROTOCOLS", False );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
    data->wm_delete_message = XInternAtom( display, "WM_DELETE_WINDOW", False );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   405
    XSetWMProtocols( display, data->window, &data->wm_delete_message, 1 );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   406
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   407
    if ( windowdata ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   408
        XWindowAttributes attrib;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
        Window dummy;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   410
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   411
        XGetWindowAttributes(display, windowdata->xwindow, &attrib);
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   412
        x = attrib.x + ( attrib.width - data->dialog_width ) / 2;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   413
        y = attrib.y + ( attrib.height - data->dialog_height ) / 3 ;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   414
        XTranslateCoordinates(display, windowdata->xwindow, DefaultRootWindow( display ), x, y, &x, &y, &dummy);
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   415
    } else {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   416
        int screen = DefaultScreen( display );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   417
        x = ( DisplayWidth( display, screen ) - data->dialog_width ) / 2;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   418
        y = ( DisplayHeight( display, screen ) - data->dialog_height ) / 3 ;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   419
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   420
    XMoveWindow( display, data->window, x, y );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   421
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   422
    sizehints = XAllocSizeHints();
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   423
    if ( sizehints ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   424
        sizehints->flags = USPosition | USSize | PMaxSize | PMinSize;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   425
        sizehints->x = x;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   426
        sizehints->y = y;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   427
        sizehints->width = data->dialog_width;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   428
        sizehints->height = data->dialog_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   429
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   430
        sizehints->min_width = sizehints->max_width = data->dialog_width;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   431
        sizehints->min_height = sizehints->max_height = data->dialog_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   432
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   433
        XSetWMNormalHints( display, data->window, sizehints );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   434
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   435
        XFree( sizehints );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   436
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   437
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   438
    XMapRaised( display, data->window );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   439
    return 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   440
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   441
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   442
/* Draw our message box. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   443
static void
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   444
X11_MessageBoxDraw( SDL_MessageBoxDataX11 *data, GC ctx )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   445
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   446
    int i;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   447
    Window window = data->window;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   448
    Display *display = data->display;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   449
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   450
    XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BACKGROUND ] );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   451
    XFillRectangle( display, window, ctx, 0, 0, data->dialog_width, data->dialog_height );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   452
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   453
    XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   454
    for ( i = 0; i < data->numlines; i++ ) {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   455
        TextLineData *plinedata = &data->linedata[ i ];
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   456
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   457
        if (SDL_X11_HAVE_UTF8) {
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   458
            Xutf8DrawString( display, window, data->font_set, ctx,
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   459
                             data->xtext, data->ytext + i * data->text_height,
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   460
                             plinedata->text, plinedata->length );
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   461
        } else {
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   462
            XDrawString( display, window, ctx,
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   463
                         data->xtext, data->ytext + i * data->text_height,
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   464
                         plinedata->text, plinedata->length );
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   465
        }
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   466
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   467
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   468
    for ( i = 0; i < data->numbuttons; i++ ) {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   469
        SDL_MessageBoxButtonDataX11 *buttondatax11 = &data->buttonpos[ i ];
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   470
        const SDL_MessageBoxButtonData *buttondata = buttondatax11->buttondata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   471
        int border = ( buttondata->flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT ) ? 2 : 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   472
        int offset = ( ( data->mouse_over_index == i ) && ( data->button_press_index == data->mouse_over_index ) ) ? 1 : 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   473
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   474
        XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND ] );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   475
        XFillRectangle( display, window, ctx,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   476
                        buttondatax11->rect.x - border, buttondatax11->rect.y - border,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   477
                        buttondatax11->rect.w + 2 * border, buttondatax11->rect.h + 2 * border );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   478
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   479
        XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_BORDER ] );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   480
        XDrawRectangle( display, window, ctx,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   481
                        buttondatax11->rect.x, buttondatax11->rect.y,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   482
                        buttondatax11->rect.w, buttondatax11->rect.h );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   483
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   484
        XSetForeground( display, ctx, ( data->mouse_over_index == i ) ?
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   485
                        data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED ] :
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   486
                        data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   487
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   488
        if (SDL_X11_HAVE_UTF8) {
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   489
            Xutf8DrawString( display, window, data->font_set, ctx,
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   490
                             buttondatax11->x + offset,
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   491
                             buttondatax11->y + offset,
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   492
                             buttondata->text, buttondatax11->length );
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   493
        } else {
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   494
            XDrawString( display, window, ctx,
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   495
                         buttondatax11->x + offset, buttondatax11->y + offset,
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   496
                         buttondata->text, buttondatax11->length );
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   497
        }
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   498
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   499
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   500
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   501
/* Loop and handle message box event messages until something kills it. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   502
static int
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   503
X11_MessageBoxLoop( SDL_MessageBoxDataX11 *data )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   504
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   505
    GC ctx;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   506
    XGCValues ctx_vals;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   507
    SDL_bool close_dialog = SDL_FALSE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   508
    SDL_bool has_focus = SDL_TRUE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   509
    KeySym last_key_pressed = XK_VoidSymbol;
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   510
    unsigned long gcflags = GCForeground | GCBackground;
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   511
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   512
    SDL_zero(ctx_vals);
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   513
    ctx_vals.foreground = data->color[ SDL_MESSAGEBOX_COLOR_BACKGROUND ];
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   514
    ctx_vals.background = data->color[ SDL_MESSAGEBOX_COLOR_BACKGROUND ];
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   515
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   516
    if (!SDL_X11_HAVE_UTF8) {
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   517
        gcflags |= GCFont;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   518
        ctx_vals.font = data->font_struct->fid;
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   519
    }
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   520
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   521
    ctx = XCreateGC( data->display, data->window, gcflags, &ctx_vals );
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   522
    if ( ctx == None ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   523
        SDL_SetError("Couldn't create graphics context");
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   524
        return -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   525
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   526
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   527
    data->button_press_index = -1;  /* Reset what button is currently depressed. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   528
    data->mouse_over_index = -1;    /* Reset what button the mouse is over. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   529
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   530
    while( !close_dialog ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   531
        XEvent e;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   532
        SDL_bool draw = SDL_TRUE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   533
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   534
        XWindowEvent( data->display, data->window, data->event_mask, &e );
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   535
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   536
        /* If XFilterEvent returns True, then some input method has filtered the
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   537
           event, and the client should discard the event. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   538
        if ( ( e.type != Expose ) && XFilterEvent( &e, None ) )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   539
            continue;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   540
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   541
        switch( e.type ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   542
        case Expose:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   543
            if ( e.xexpose.count > 0 ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   544
                draw = SDL_FALSE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   545
            }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   546
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   547
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   548
        case FocusIn:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   549
            /* Got focus. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   550
            has_focus = SDL_TRUE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   551
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   552
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   553
        case FocusOut:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   554
            /* lost focus. Reset button and mouse info. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   555
            has_focus = SDL_FALSE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   556
            data->button_press_index = -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   557
            data->mouse_over_index = -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   558
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   559
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   560
        case MotionNotify:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   561
            if ( has_focus ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   562
                /* Mouse moved... */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   563
                data->mouse_over_index = GetHitButtonIndex( data, e.xbutton.x, e.xbutton.y );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   564
            }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   565
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   566
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   567
        case ClientMessage:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   568
            if ( e.xclient.message_type == data->wm_protocols &&
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   569
                 e.xclient.format == 32 &&
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   570
                 e.xclient.data.l[ 0 ] == data->wm_delete_message ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   571
                close_dialog = SDL_TRUE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   572
            }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   573
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   574
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   575
        case KeyPress:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   576
            /* Store key press - we make sure in key release that we got both. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   577
            last_key_pressed = XLookupKeysym( &e.xkey, 0 );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   578
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   579
6725
a7a99a9d419a astyle to the rescue!
Sam Lantinga <slouken@libsdl.org>
parents: 6724
diff changeset
   580
        case KeyRelease: {
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
            Uint32 mask = 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   582
            KeySym key = XLookupKeysym( &e.xkey, 0 );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   583
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   584
            /* If this is a key release for something we didn't get the key down for, then bail. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
            if ( key != last_key_pressed )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   586
                break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   588
            if ( key == XK_Escape )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   589
                mask = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   590
            else if ( ( key == XK_Return ) || ( key == XK_KP_Enter ) )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   591
                mask = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   592
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   593
            if ( mask ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   594
                int i;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   595
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   596
                /* Look for first button with this mask set, and return it if found. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   597
                for ( i = 0; i < data->numbuttons; i++ ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   598
                    SDL_MessageBoxButtonDataX11 *buttondatax11 = &data->buttonpos[ i ];
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   599
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   600
                    if ( buttondatax11->buttondata->flags & mask ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   601
                        *data->pbuttonid = buttondatax11->buttondata->buttonid;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   602
                        close_dialog = SDL_TRUE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   603
                        break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   604
                    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   605
                }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   606
            }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   607
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   608
        }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   609
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   610
        case ButtonPress:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   611
            data->button_press_index = -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   612
            if ( e.xbutton.button == Button1 ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   613
                /* Find index of button they clicked on. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   614
                data->button_press_index = GetHitButtonIndex( data, e.xbutton.x, e.xbutton.y );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   615
            }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   616
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   617
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   618
        case ButtonRelease:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   619
            /* If button is released over the same button that was clicked down on, then return it. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   620
            if ( ( e.xbutton.button == Button1 ) && ( data->button_press_index >= 0 ) ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   621
                int button = GetHitButtonIndex( data, e.xbutton.x, e.xbutton.y );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   622
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   623
                if ( data->button_press_index == button ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   624
                    SDL_MessageBoxButtonDataX11 *buttondatax11 = &data->buttonpos[ button ];
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   625
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   626
                    *data->pbuttonid = buttondatax11->buttondata->buttonid;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   627
                    close_dialog = SDL_TRUE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   628
                }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   629
            }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   630
            data->button_press_index = -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   631
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   632
        }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   633
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   634
        if ( draw ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   635
            /* Draw our dialog box. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   636
            X11_MessageBoxDraw( data, ctx );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   637
        }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   638
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   639
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   640
    XFreeGC( data->display, ctx );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   641
    return 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   642
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   643
6726
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   644
static int
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   645
X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid)
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   646
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   647
    int ret;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   648
    SDL_MessageBoxDataX11 data;
6835
c259f0817583 Add defines to disable setlocale and fork. Disable that code by default for now.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6817
diff changeset
   649
#if SDL_SET_LOCALE
6724
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   650
    char *origlocale;
6835
c259f0817583 Add defines to disable setlocale and fork. Disable that code by default for now.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6817
diff changeset
   651
#endif
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   652
6723
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   653
    SDL_zero(data);
7c464a9ecf48 X11 message boxes should work with UTF-8 strings if possible.
Ryan C. Gordon <icculus@icculus.org>
parents: 6615
diff changeset
   654
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   655
    if ( !SDL_X11_LoadSymbols() )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   656
        return -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   657
6835
c259f0817583 Add defines to disable setlocale and fork. Disable that code by default for now.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6817
diff changeset
   658
#if SDL_SET_LOCALE
6724
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   659
    origlocale = setlocale(LC_ALL, NULL);
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   660
    if (origlocale != NULL) {
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   661
        origlocale = SDL_strdup(origlocale);
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   662
        if (origlocale == NULL) {
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   663
            SDL_OutOfMemory();
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   664
            return -1;
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   665
        }
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   666
        setlocale(LC_ALL, "");
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   667
    }
6835
c259f0817583 Add defines to disable setlocale and fork. Disable that code by default for now.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6817
diff changeset
   668
#endif
6724
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   669
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   670
    /* This code could get called from multiple threads maybe? */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   671
    XInitThreads();
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   672
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   673
    /* Initialize the return buttonid value to -1 (for error or dialogbox closed). */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   674
    *buttonid = -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   675
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   676
    /* Init and display the message box. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   677
    ret = X11_MessageBoxInit( &data, messageboxdata, buttonid );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   678
    if ( ret != -1 ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   679
        ret = X11_MessageBoxInitPositions( &data );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   680
        if ( ret != -1 ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   681
            ret = X11_MessageBoxCreateWindow( &data );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   682
            if ( ret != -1 ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   683
                ret = X11_MessageBoxLoop( &data );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   684
            }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   685
        }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   686
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   687
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   688
    X11_MessageBoxShutdown( &data );
6724
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   689
6835
c259f0817583 Add defines to disable setlocale and fork. Disable that code by default for now.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6817
diff changeset
   690
#if SDL_SET_LOCALE
6724
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   691
    if (origlocale) {
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   692
        setlocale(LC_ALL, origlocale);
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   693
        SDL_free(origlocale);
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   694
    }
6835
c259f0817583 Add defines to disable setlocale and fork. Disable that code by default for now.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6817
diff changeset
   695
#endif
6724
6c5ed0c4cc6d X11 msgbox: try to protect the existing setlocale() state.
Ryan C. Gordon <icculus@icculus.org>
parents: 6723
diff changeset
   696
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   697
    return ret;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   698
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   699
6726
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   700
/* Display an x11 message box. */
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   701
int
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   702
X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   703
{
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   704
#if SDL_FORK_MESSAGEBOX
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   705
    /* Use a child process to protect against setlocale(). Annoying. */
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   706
    pid_t pid;
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   707
    int fds[2];
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   708
    int status = 0;
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   709
6835
c259f0817583 Add defines to disable setlocale and fork. Disable that code by default for now.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6817
diff changeset
   710
	/* Need to flush here in case someone has turned grab off and it hasn't gone through yet, etc. */
c259f0817583 Add defines to disable setlocale and fork. Disable that code by default for now.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6817
diff changeset
   711
	XFlush(data->display);
c259f0817583 Add defines to disable setlocale and fork. Disable that code by default for now.
Michael Sartain <mikesart@valvesoftware.com>
parents: 6817
diff changeset
   712
6726
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   713
    if (pipe(fds) == -1) {
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   714
        return X11_ShowMessageBoxImpl(messageboxdata, buttonid); /* oh well. */
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   715
    }
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   716
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   717
    pid = fork();
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   718
    if (pid == -1) {  /* failed */
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   719
        close(fds[0]);
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   720
        close(fds[1]);
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   721
        return X11_ShowMessageBoxImpl(messageboxdata, buttonid); /* oh well. */
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   722
    } else if (pid == 0) {  /* we're the child */
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   723
        int exitcode = 0;
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   724
        close(fds[0]);
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   725
        status = X11_ShowMessageBoxImpl(messageboxdata, buttonid);
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   726
        if (write(fds[1], &status, sizeof (int)) != sizeof (int))
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   727
            exitcode = 1;
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   728
        else if (write(fds[1], buttonid, sizeof (int)) != sizeof (int))
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   729
            exitcode = 1;
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   730
        close(fds[1]);
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   731
        _exit(exitcode);  /* don't run atexit() stuff, static destructors, etc. */
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   732
    } else {  /* we're the parent */
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   733
        pid_t rc;
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   734
        close(fds[1]);
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   735
        do {
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   736
            rc = waitpid(pid, &status, 0);
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   737
        } while ((rc == -1) && (errno == EINTR));
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   738
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   739
        SDL_assert(rc == pid);  /* not sure what to do if this fails. */
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   740
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   741
        if ((rc == -1) || (!WIFEXITED(status)) || (WEXITSTATUS(status) != 0)) {
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   742
            SDL_SetError("msgbox child process failed");
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   743
            return -1;
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   744
        }
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   745
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   746
        if (read(fds[0], &status, sizeof (int)) != sizeof (int))
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   747
            status = -1;
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   748
        else if (read(fds[0], buttonid, sizeof (int)) != sizeof (int))
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   749
            status = -1;
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   750
        close(fds[0]);
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   751
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   752
        return status;
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   753
    }
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   754
#else
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   755
    return X11_ShowMessageBoxImpl(messageboxdata, buttonid);
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   756
#endif
f2898757eaae Fork a child process for X11 message boxes, so setlocale() doesn't break stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 6725
diff changeset
   757
}
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   758
#endif /* SDL_VIDEO_DRIVER_X11 */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   759
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   760
/* vi: set ts=4 sw=4 expandtab: */