src/video/x11/SDL_x11messagebox.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 30 Oct 2012 12:21:15 -0700
changeset 6615 d7a463bde4d7
parent 6603 fc815cb0a2de
child 6723 7c464a9ecf48
permissions -rw-r--r--
Use the correct variable for the button spacing (even though they end up being the same thing)
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
*/
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
#if SDL_VIDEO_DRIVER_X11
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "SDL.h"
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "SDL_x11video.h"
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include "SDL_x11dyn.h"
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#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
    30
#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
    31
#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
    32
#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
    33
#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
    34
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
static const char g_MessageBoxFont[] = "-*-*-medium-r-normal--0-120-*-*-p-0-iso8859-1";
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
static const SDL_MessageBoxColor g_default_colors[ SDL_MESSAGEBOX_COLOR_MAX ] =
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
{
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
    39
    { 56,  54,  53  }, // SDL_MESSAGEBOX_COLOR_BACKGROUND,       
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
    40
    { 209, 207, 205 }, // SDL_MESSAGEBOX_COLOR_TEXT,             
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
    41
    { 140, 135, 129 }, // SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,    
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
    42
    { 105, 102, 99  }, // SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
    43
    { 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
    44
};
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
#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
    47
                                      ( ( Uint32 )( _g ) << 8 ) |  \
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
                                      ( ( Uint32 )( _b ) ) )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
typedef struct SDL_MessageBoxButtonDataX11
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
    int x, y;                           /* Text position */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
    int length;                         /* Text length */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
    int text_width;                     /* Text width */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
    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
    57
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
    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
    59
} SDL_MessageBoxButtonDataX11;
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
typedef struct TextLineData
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
    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
    64
    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
    65
    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
    66
} TextLineData;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
typedef struct SDL_MessageBoxDataX11
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
    Font hfont;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
    Window window;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
    Display *display;
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
    73
    long event_mask;
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
    Atom wm_protocols;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
    Atom wm_delete_message;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
    int dialog_width;                   /* Dialog box width. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
    int dialog_height;                  /* Dialog box height. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
    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
    81
    int numlines;                       /* Count of Text lines. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
    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
    83
    TextLineData linedata[ MAX_TEXT_LINES ];
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    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
    86
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
    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
    88
    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
    89
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
    int numbuttons;                     /* Count of buttons. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    const SDL_MessageBoxButtonData *buttondata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
    SDL_MessageBoxButtonDataX11 buttonpos[ MAX_BUTTONS ];
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
    94
    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
    95
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
    const SDL_MessageBoxData *messageboxdata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
} SDL_MessageBoxDataX11;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
/* Maximum helper for ints. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
static __inline__ int
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
IntMax( int a, int b )
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
    return ( a > b  ) ? a : b;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
/* 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
   107
static void
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
GetTextWidthHeight( XFontStruct *font_struct, const char *str, int nchars, int *pwidth, int *pheight )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
    XCharStruct text_structure;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
    int font_direction, font_ascent, font_descent;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
    XTextExtents( font_struct, str, nchars,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
                     &font_direction, &font_ascent, &font_descent,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
                     &text_structure );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
    *pwidth = text_structure.width;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
    *pheight = text_structure.ascent + text_structure.descent;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
/* 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
   122
static int
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
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
   124
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
    int i;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
    int numbuttons = data->numbuttons;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
    SDL_MessageBoxButtonDataX11 *buttonpos = data->buttonpos;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
    for ( i = 0; i < numbuttons; i++ )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
    {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
        SDL_Rect *rect = &buttonpos[ i ].rect;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
        if ( ( x >= rect->x ) &&
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
            ( x <= ( rect->x + rect->w ) ) &&
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
            ( y >= rect->y ) &&
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
            ( y <= ( rect->y + rect->h ) ) )
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
            return i;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
        }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
    return -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
/* 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
   146
static int
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
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
   148
{
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   149
    int i;
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
    int numbuttons = messageboxdata->numbuttons;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
    const SDL_MessageBoxButtonData *buttondata = messageboxdata->buttons;
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   152
    const SDL_MessageBoxColor *colorhints;
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
    if ( numbuttons > MAX_BUTTONS ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
        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
   156
        return -1;
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
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
    data->dialog_width = MIN_DIALOG_WIDTH;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
    data->dialog_height = MIN_DIALOG_HEIGHT;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
    data->messageboxdata = messageboxdata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
    data->buttondata = buttondata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
    data->numbuttons = numbuttons;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
    data->pbuttonid = pbuttonid;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
    data->display = XOpenDisplay( NULL );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
    if ( !data->display ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
        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
   169
        return -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
    data->hfont = XLoadFont( data->display, g_MessageBoxFont );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
    if ( data->hfont == None ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
        SDL_SetError("Couldn't load font %s", g_MessageBoxFont);
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
        return -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   178
    if ( messageboxdata->colorScheme ) {
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   179
        colorhints = messageboxdata->colorScheme->colors;
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   180
    } else {
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   181
        colorhints = g_default_colors;
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   182
    }
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   184
    /* 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
   185
    for ( i = 0; i < SDL_MESSAGEBOX_COLOR_MAX; i++ ) {
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   186
        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
   187
    }
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
    return 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
/* 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
   193
static int
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
X11_MessageBoxInitPositions( SDL_MessageBoxDataX11 *data )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
    int i;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
    int ybuttons;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
    int text_width_max = 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
    int button_text_height = 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
    int button_width = MIN_BUTTON_WIDTH;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
    const SDL_MessageBoxData *messageboxdata = data->messageboxdata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   202
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
    XFontStruct *fontinfo = XQueryFont( data->display, data->hfont );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
    if ( !fontinfo ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
        SDL_SetError("Couldn't get font info");
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
        return -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
    /* Go over text and break linefeeds into separate lines. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
    if ( messageboxdata->message && messageboxdata->message[ 0 ] )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
    {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
        const char *text = messageboxdata->message;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
        TextLineData *plinedata = data->linedata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
        for ( i = 0; i < MAX_TEXT_LINES; i++, plinedata++ )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
        {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
            int height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
            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
   219
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
            data->numlines++;
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
            /* 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
   223
            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
   224
            plinedata->text = text;
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
            GetTextWidthHeight( fontinfo, text, plinedata->length, &plinedata->width, &height );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
            /* 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
   229
            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
   230
            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
   231
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
            text += plinedata->length + 1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
            /* 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
   235
            if ( !lf )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
                break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
        }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
        /* Bump up the text height slightly. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
        data->text_height += 2;
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
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
    /* Loop through all buttons and calculate the button widths and height. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
    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
   245
    {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
        int height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
        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
   249
        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
   250
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
        GetTextWidthHeight( fontinfo, data->buttondata[ i ].text, SDL_strlen( data->buttondata[ i ].text ),
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
                            &data->buttonpos[ i ].text_width, &height );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
        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
   255
        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
   256
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
    if ( data->numlines )
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
        /* 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
   261
        data->xtext = data->text_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
        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
   263
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
        /* 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
   265
        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
   266
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
        /* 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
   268
        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
   269
        data->dialog_height = IntMax( data->dialog_height, ybuttons );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
    else
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
        /* 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
   274
        ybuttons = button_text_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   277
    if ( data->numbuttons )
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
        int x, y;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
        int width_of_buttons;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
        int button_spacing = button_text_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
        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
   283
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
        /* Bump button width up a bit. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
        button_width += button_text_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   286
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
        /* 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
   288
        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
   289
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
        /* 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
   291
        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
   292
        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
   293
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
        /* Location for first button. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
        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
   296
        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
   297
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
        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
   299
        {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
            /* Button coordinates. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
            data->buttonpos[ i ].rect.x = x;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
            data->buttonpos[ i ].rect.y = y;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
            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
   304
            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
   305
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
            /* Button text coordinates. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
            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
   308
            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
   309
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
            /* 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
   311
            x += button_width + button_spacing;
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
        }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
    }
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
    XFreeFontInfo( NULL, fontinfo, 1 );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
    return 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
/* Free SDL_MessageBoxData data. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
static void
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
X11_MessageBoxShutdown( SDL_MessageBoxDataX11 *data )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   322
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
    if ( data->hfont != None )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
    {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
        XUnloadFont( data->display, data->hfont );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
        data->hfont = None;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
    if ( data->display )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
    {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
        if ( data->window != None )
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
            XUnmapWindow( data->display, data->window );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   334
            XDestroyWindow( data->display, data->window );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
            data->window = None;
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
        XCloseDisplay( data->display );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
        data->display = NULL;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
}
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   343
/* 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
   344
static int
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
X11_MessageBoxCreateWindow( SDL_MessageBoxDataX11 *data )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
    int x, y;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
    XSizeHints *sizehints;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   349
    XSetWindowAttributes wnd_attr;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   350
    Display *display = data->display;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   351
    SDL_WindowData *windowdata = NULL;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   352
    const SDL_MessageBoxData *messageboxdata = data->messageboxdata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   354
    if ( messageboxdata->window ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   355
        windowdata = (SDL_WindowData *)messageboxdata->window->driverdata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
    }
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
    data->event_mask = ExposureMask |
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
        ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
        StructureNotifyMask | FocusChangeMask | PointerMotionMask;
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   361
    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
   362
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
    data->window = XCreateWindow(
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   364
                            display, DefaultRootWindow( display ),
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   365
                            0, 0,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   366
                            data->dialog_width, data->dialog_height,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   367
                            0, CopyFromParent, InputOutput, CopyFromParent,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   368
                            CWEventMask, &wnd_attr );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   369
    if ( data->window == None ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   370
        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
   371
        return -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   372
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   373
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
    if ( windowdata ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
        /* 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
   376
        XSetTransientForHint( display, data->window, windowdata->xwindow );
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
    XStoreName( display, data->window, messageboxdata->title );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   380
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   381
    /* 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
   382
    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
   383
    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
   384
    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
   385
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   386
    if ( windowdata ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   387
        XWindowAttributes attrib;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   388
        Window dummy;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   389
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
        XGetWindowAttributes(display, windowdata->xwindow, &attrib);
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   391
        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
   392
        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
   393
        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
   394
    } else {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
        int screen = DefaultScreen( display );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
        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
   397
        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
   398
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
    XMoveWindow( display, data->window, x, y );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
    sizehints = XAllocSizeHints();
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
    if ( sizehints ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
        sizehints->flags = USPosition | USSize | PMaxSize | PMinSize;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
        sizehints->x = x;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   405
        sizehints->y = y;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   406
        sizehints->width = data->dialog_width;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   407
        sizehints->height = data->dialog_height;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   408
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
        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
   410
        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
   411
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   412
        XSetWMNormalHints( display, data->window, sizehints );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   413
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   414
        XFree( sizehints );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   415
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   416
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   417
    XMapRaised( display, data->window );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   418
    return 0;
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
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   421
/* Draw our message box. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   422
static void
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   423
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
   424
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   425
    int i;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   426
    Window window = data->window;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   427
    Display *display = data->display;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   428
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   429
    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
   430
    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
   431
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   432
    XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   433
    for ( i = 0; i < data->numlines; i++ )
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
        TextLineData *plinedata = &data->linedata[ i ];
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
        XDrawString( display, window, ctx,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   438
                     data->xtext, data->ytext + i * data->text_height,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   439
                     plinedata->text, plinedata->length );
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
    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
   443
    {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   444
        SDL_MessageBoxButtonDataX11 *buttondatax11 = &data->buttonpos[ i ];
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   445
        const SDL_MessageBoxButtonData *buttondata = buttondatax11->buttondata;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   446
        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
   447
        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
   448
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   449
        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
   450
        XFillRectangle( display, window, ctx,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   451
                        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
   452
                        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
   453
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   454
        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
   455
        XDrawRectangle( display, window, ctx,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   456
                        buttondatax11->rect.x, buttondatax11->rect.y,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   457
                        buttondatax11->rect.w, buttondatax11->rect.h );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   458
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   459
        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
   460
                        data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED ] :
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   461
                        data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
6602
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   462
        XDrawString( display, window, ctx,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   463
            buttondatax11->x + offset, buttondatax11->y + offset,
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   464
            buttondata->text, buttondatax11->length );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   465
    }
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
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   468
/* 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
   469
static int
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   470
X11_MessageBoxLoop( SDL_MessageBoxDataX11 *data )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   471
{
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   472
    GC ctx;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   473
    XGCValues ctx_vals;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   474
    SDL_bool close_dialog = SDL_FALSE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   475
    SDL_bool has_focus = SDL_TRUE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   476
    KeySym last_key_pressed = XK_VoidSymbol;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   477
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   478
    ctx_vals.font = data->hfont;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   479
    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
   480
    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
   481
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   482
    ctx = XCreateGC( data->display, data->window, GCForeground | GCBackground | GCFont, &ctx_vals );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   483
    if ( ctx == None ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   484
        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
   485
        return -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   486
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   487
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   488
    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
   489
    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
   490
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   491
    while( !close_dialog ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   492
        XEvent e;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   493
        SDL_bool draw = SDL_TRUE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   494
6603
fc815cb0a2de Fixed tab spacing
Sam Lantinga <slouken@libsdl.org>
parents: 6602
diff changeset
   495
        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
   496
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   497
        /* 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
   498
           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
   499
        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
   500
            continue;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   501
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   502
        switch( e.type ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   503
        case Expose:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   504
            if ( e.xexpose.count > 0 ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   505
                draw = SDL_FALSE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   506
            }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   507
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   508
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   509
        case FocusIn:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   510
            /* Got focus. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   511
            has_focus = SDL_TRUE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   512
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   513
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   514
        case FocusOut:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   515
            /* 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
   516
            has_focus = SDL_FALSE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   517
            data->button_press_index = -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   518
            data->mouse_over_index = -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   519
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   520
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   521
        case MotionNotify:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   522
            if ( has_focus ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   523
                /* Mouse moved... */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   524
                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
   525
            }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   526
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   527
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   528
        case ClientMessage:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   529
            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
   530
                 e.xclient.format == 32 &&
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   531
                 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
   532
                close_dialog = SDL_TRUE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   533
            }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   534
            break;
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
        case KeyPress:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   537
            /* 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
   538
            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
   539
            break;
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
        case KeyRelease:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   542
        {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   543
            Uint32 mask = 0;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   544
            KeySym key = XLookupKeysym( &e.xkey, 0 );
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
            /* 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
   547
            if ( key != last_key_pressed )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   548
                break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   549
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   550
            if ( key == XK_Escape )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   551
                mask = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   552
            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
   553
                mask = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   554
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   555
            if ( mask ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   556
                int i;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   557
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   558
                /* 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
   559
                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
   560
                    SDL_MessageBoxButtonDataX11 *buttondatax11 = &data->buttonpos[ i ];
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   561
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   562
                    if ( buttondatax11->buttondata->flags & mask ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   563
                        *data->pbuttonid = buttondatax11->buttondata->buttonid;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   564
                        close_dialog = SDL_TRUE;
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
                }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   568
            }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   569
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   570
        }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   571
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   572
        case ButtonPress:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   573
            data->button_press_index = -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   574
            if ( e.xbutton.button == Button1 ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   575
                /* 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
   576
                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
   577
            }
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
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   580
        case ButtonRelease:
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
            /* 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
   582
            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
   583
                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
   584
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
                if ( data->button_press_index == button ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   586
                    SDL_MessageBoxButtonDataX11 *buttondatax11 = &data->buttonpos[ button ];
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
                    *data->pbuttonid = buttondatax11->buttondata->buttonid;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   589
                    close_dialog = SDL_TRUE;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   590
                }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   591
            }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   592
            data->button_press_index = -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   593
            break;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   594
        }
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
        if ( draw ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   597
            /* Draw our dialog box. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   598
            X11_MessageBoxDraw( data, ctx );
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
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   601
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   602
    XFreeGC( data->display, ctx );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   603
    return 0;
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
/* Display an x11 message box. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   607
int
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   608
X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
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
    int ret;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   611
    SDL_MessageBoxDataX11 data;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   612
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   613
    SDL_memset( &data, 0, sizeof( data ) );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   614
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   615
    if ( !SDL_X11_LoadSymbols() )
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   616
        return -1;
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
    /* 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
   619
    XInitThreads();
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   620
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   621
    /* 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
   622
    *buttonid = -1;
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   623
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   624
    /* Init and display the message box. */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   625
    ret = X11_MessageBoxInit( &data, messageboxdata, buttonid );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   626
    if ( ret != -1 ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   627
        ret = X11_MessageBoxInitPositions( &data );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   628
        if ( ret != -1 ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   629
            ret = X11_MessageBoxCreateWindow( &data );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   630
            if ( ret != -1 ) {
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   631
                ret = X11_MessageBoxLoop( &data );
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
    }
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   635
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   636
    X11_MessageBoxShutdown( &data );
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   637
    return ret;
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
#endif /* SDL_VIDEO_DRIVER_X11 */
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   641
533131e24aeb Added API for simple messagebox, courtesy of Mike Sartain
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   642
/* vi: set ts=4 sw=4 expandtab: */