125
125
if (SDL_X11_HAVE_UTF8) {
126
126
XRectangle overall_ink, overall_logical;
127
Xutf8TextExtents(data->font_set, str, nbytes, &overall_ink, &overall_logical);
127
X11_Xutf8TextExtents(data->font_set, str, nbytes, &overall_ink, &overall_logical);
128
128
*pwidth = overall_logical.width;
129
129
*pheight = overall_logical.height;
131
131
XCharStruct text_structure;
132
132
int font_direction, font_ascent, font_descent;
133
XTextExtents( data->font_struct, str, nbytes,
133
X11_XTextExtents( data->font_struct, str, nbytes,
134
134
&font_direction, &font_ascent, &font_descent,
135
135
&text_structure );
136
136
*pwidth = text_structure.width;
188
188
if (SDL_X11_HAVE_UTF8) {
189
189
char **missing = NULL;
190
190
int num_missing = 0;
191
data->font_set = XCreateFontSet(data->display, g_MessageBoxFont,
191
data->font_set = X11_XCreateFontSet(data->display, g_MessageBoxFont,
192
192
&missing, &num_missing, NULL);
193
193
if ( missing != NULL ) {
194
XFreeStringList(missing);
194
X11_XFreeStringList(missing);
196
196
if ( data->font_set == NULL ) {
197
197
return SDL_SetError("Couldn't load font %s", g_MessageBoxFont);
200
data->font_struct = XLoadQueryFont( data->display, g_MessageBoxFontLatin1 );
200
data->font_struct = X11_XLoadQueryFont( data->display, g_MessageBoxFontLatin1 );
201
201
if ( data->font_struct == NULL ) {
202
202
return SDL_SetError("Couldn't load font %s", g_MessageBoxFontLatin1);
338
338
X11_MessageBoxShutdown( SDL_MessageBoxDataX11 *data )
340
340
if ( data->font_set != NULL ) {
341
XFreeFontSet( data->display, data->font_set );
341
X11_XFreeFontSet( data->display, data->font_set );
342
342
data->font_set = NULL;
345
345
if ( data->font_struct != NULL ) {
346
XFreeFont( data->display, data->font_struct );
346
X11_XFreeFont( data->display, data->font_struct );
347
347
data->font_struct = NULL;
350
350
if ( data->display ) {
351
351
if ( data->window != None ) {
352
XWithdrawWindow( data->display, data->window, data->screen );
353
XDestroyWindow( data->display, data->window );
352
X11_XWithdrawWindow( data->display, data->window, data->screen );
353
X11_XDestroyWindow( data->display, data->window );
354
354
data->window = None;
357
XCloseDisplay( data->display );
357
X11_XCloseDisplay( data->display );
358
358
data->display = NULL;
384
384
StructureNotifyMask | FocusChangeMask | PointerMotionMask;
385
385
wnd_attr.event_mask = data->event_mask;
387
data->window = XCreateWindow(
387
data->window = X11_XCreateWindow(
388
388
display, RootWindow(display, data->screen),
390
390
data->dialog_width, data->dialog_height,
397
397
if ( windowdata ) {
398
398
/* http://tronche.com/gui/x/icccm/sec-4.html#WM_TRANSIENT_FOR */
399
XSetTransientForHint( display, data->window, windowdata->xwindow );
399
X11_XSetTransientForHint( display, data->window, windowdata->xwindow );
402
XStoreName( display, data->window, messageboxdata->title );
402
X11_XStoreName( display, data->window, messageboxdata->title );
404
404
/* Allow the window to be deleted by the window manager */
405
data->wm_protocols = XInternAtom( display, "WM_PROTOCOLS", False );
406
data->wm_delete_message = XInternAtom( display, "WM_DELETE_WINDOW", False );
407
XSetWMProtocols( display, data->window, &data->wm_delete_message, 1 );
405
data->wm_protocols = X11_XInternAtom( display, "WM_PROTOCOLS", False );
406
data->wm_delete_message = X11_XInternAtom( display, "WM_DELETE_WINDOW", False );
407
X11_XSetWMProtocols( display, data->window, &data->wm_delete_message, 1 );
409
409
if ( windowdata ) {
410
410
XWindowAttributes attrib;
413
XGetWindowAttributes(display, windowdata->xwindow, &attrib);
413
X11_XGetWindowAttributes(display, windowdata->xwindow, &attrib);
414
414
x = attrib.x + ( attrib.width - data->dialog_width ) / 2;
415
415
y = attrib.y + ( attrib.height - data->dialog_height ) / 3 ;
416
XTranslateCoordinates(display, windowdata->xwindow, RootWindow(display, data->screen), x, y, &x, &y, &dummy);
416
X11_XTranslateCoordinates(display, windowdata->xwindow, RootWindow(display, data->screen), x, y, &x, &y, &dummy);
418
418
x = ( DisplayWidth( display, data->screen ) - data->dialog_width ) / 2;
419
419
y = ( DisplayHeight( display, data->screen ) - data->dialog_height ) / 3 ;
421
XMoveWindow( display, data->window, x, y );
421
X11_XMoveWindow( display, data->window, x, y );
423
sizehints = XAllocSizeHints();
423
sizehints = X11_XAllocSizeHints();
424
424
if ( sizehints ) {
425
425
sizehints->flags = USPosition | USSize | PMaxSize | PMinSize;
426
426
sizehints->x = x;
431
431
sizehints->min_width = sizehints->max_width = data->dialog_width;
432
432
sizehints->min_height = sizehints->max_height = data->dialog_height;
434
XSetWMNormalHints( display, data->window, sizehints );
434
X11_XSetWMNormalHints( display, data->window, sizehints );
436
X11_XFree( sizehints );
439
XMapRaised( display, data->window );
439
X11_XMapRaised( display, data->window );
448
448
Window window = data->window;
449
449
Display *display = data->display;
451
XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BACKGROUND ] );
452
XFillRectangle( display, window, ctx, 0, 0, data->dialog_width, data->dialog_height );
451
X11_XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BACKGROUND ] );
452
X11_XFillRectangle( display, window, ctx, 0, 0, data->dialog_width, data->dialog_height );
454
XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
454
X11_XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
455
455
for ( i = 0; i < data->numlines; i++ ) {
456
456
TextLineData *plinedata = &data->linedata[ i ];
458
458
if (SDL_X11_HAVE_UTF8) {
459
Xutf8DrawString( display, window, data->font_set, ctx,
459
X11_Xutf8DrawString( display, window, data->font_set, ctx,
460
460
data->xtext, data->ytext + i * data->text_height,
461
461
plinedata->text, plinedata->length );
463
XDrawString( display, window, ctx,
463
X11_XDrawString( display, window, ctx,
464
464
data->xtext, data->ytext + i * data->text_height,
465
465
plinedata->text, plinedata->length );
472
472
int border = ( buttondata->flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT ) ? 2 : 0;
473
473
int offset = ( ( data->mouse_over_index == i ) && ( data->button_press_index == data->mouse_over_index ) ) ? 1 : 0;
475
XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND ] );
476
XFillRectangle( display, window, ctx,
475
X11_XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND ] );
476
X11_XFillRectangle( display, window, ctx,
477
477
buttondatax11->rect.x - border, buttondatax11->rect.y - border,
478
478
buttondatax11->rect.w + 2 * border, buttondatax11->rect.h + 2 * border );
480
XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_BORDER ] );
481
XDrawRectangle( display, window, ctx,
480
X11_XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_BORDER ] );
481
X11_XDrawRectangle( display, window, ctx,
482
482
buttondatax11->rect.x, buttondatax11->rect.y,
483
483
buttondatax11->rect.w, buttondatax11->rect.h );
485
XSetForeground( display, ctx, ( data->mouse_over_index == i ) ?
485
X11_XSetForeground( display, ctx, ( data->mouse_over_index == i ) ?
486
486
data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED ] :
487
487
data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
489
489
if (SDL_X11_HAVE_UTF8) {
490
Xutf8DrawString( display, window, data->font_set, ctx,
490
X11_Xutf8DrawString( display, window, data->font_set, ctx,
491
491
buttondatax11->x + offset,
492
492
buttondatax11->y + offset,
493
493
buttondata->text, buttondatax11->length );
495
XDrawString( display, window, ctx,
495
X11_XDrawString( display, window, ctx,
496
496
buttondatax11->x + offset, buttondatax11->y + offset,
497
497
buttondata->text, buttondatax11->length );
519
519
ctx_vals.font = data->font_struct->fid;
522
ctx = XCreateGC( data->display, data->window, gcflags, &ctx_vals );
522
ctx = X11_XCreateGC( data->display, data->window, gcflags, &ctx_vals );
523
523
if ( ctx == None ) {
524
524
return SDL_SetError("Couldn't create graphics context");
532
532
SDL_bool draw = SDL_TRUE;
534
XWindowEvent( data->display, data->window, data->event_mask, &e );
534
X11_XWindowEvent( data->display, data->window, data->event_mask, &e );
536
/* If XFilterEvent returns True, then some input method has filtered the
536
/* If X11_XFilterEvent returns True, then some input method has filtered the
537
537
event, and the client should discard the event. */
538
if ( ( e.type != Expose ) && XFilterEvent( &e, None ) )
538
if ( ( e.type != Expose ) && X11_XFilterEvent( &e, None ) )
541
541
switch( e.type ) {
576
576
/* Store key press - we make sure in key release that we got both. */
577
last_key_pressed = XLookupKeysym( &e.xkey, 0 );
577
last_key_pressed = X11_XLookupKeysym( &e.xkey, 0 );
580
580
case KeyRelease: {
582
KeySym key = XLookupKeysym( &e.xkey, 0 );
582
KeySym key = X11_XLookupKeysym( &e.xkey, 0 );
584
584
/* If this is a key release for something we didn't get the key down for, then bail. */
585
585
if ( key != last_key_pressed )