~ubuntu-branches/ubuntu/vivid/libsdl2/vivid

« back to all changes in this revision

Viewing changes to src/video/x11/SDL_x11messagebox.c

  • Committer: Package Import Robot
  • Author(s): Manuel A. Fernandez Montecelo, Felix Geyer
  • Date: 2013-12-28 12:31:19 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20131228123119-e0k27gckmnzskfgb
Tags: 2.0.1+dfsg1-1
* New upstream release (Closes: #728974)
  - Remove patch applied upstream:
    bug-723797-false_positives_in_mouse_wheel_code.patch
* Bump Standards-Version to 3.9.5, no changes needed.

[ Felix Geyer ]
* Import upstream gpg key for uscan to verify the orig tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
} SDL_MessageBoxDataX11;
113
113
 
114
114
/* Maximum helper for ints. */
115
 
static __inline__ int
 
115
static SDL_INLINE int
116
116
IntMax( int a, int b )
117
117
{
118
118
    return ( a > b  ) ? a : b;
124
124
{
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;
130
130
    } else {
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;
180
180
    data->numbuttons = numbuttons;
181
181
    data->pbuttonid = pbuttonid;
182
182
 
183
 
    data->display = XOpenDisplay( NULL );
 
183
    data->display = X11_XOpenDisplay( NULL );
184
184
    if ( !data->display ) {
185
185
        return SDL_SetError("Couldn't open X11 display");
186
186
    }
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);
195
195
        }
196
196
        if ( data->font_set == NULL ) {
197
197
            return SDL_SetError("Couldn't load font %s", g_MessageBoxFont);
198
198
        }
199
199
    } else {
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);
203
203
        }
338
338
X11_MessageBoxShutdown( SDL_MessageBoxDataX11 *data )
339
339
{
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;
343
343
    }
344
344
 
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;
348
348
    }
349
349
 
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;
355
355
        }
356
356
 
357
 
        XCloseDisplay( data->display );
 
357
        X11_XCloseDisplay( data->display );
358
358
        data->display = NULL;
359
359
    }
360
360
}
384
384
                       StructureNotifyMask | FocusChangeMask | PointerMotionMask;
385
385
    wnd_attr.event_mask = data->event_mask;
386
386
 
387
 
    data->window = XCreateWindow(
 
387
    data->window = X11_XCreateWindow(
388
388
                       display, RootWindow(display, data->screen),
389
389
                       0, 0,
390
390
                       data->dialog_width, data->dialog_height,
396
396
 
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 );
400
400
    }
401
401
 
402
 
    XStoreName( display, data->window, messageboxdata->title );
 
402
    X11_XStoreName( display, data->window, messageboxdata->title );
403
403
 
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 );
408
408
 
409
409
    if ( windowdata ) {
410
410
        XWindowAttributes attrib;
411
411
        Window dummy;
412
412
 
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);
417
417
    } else {
418
418
        x = ( DisplayWidth( display, data->screen ) - data->dialog_width ) / 2;
419
419
        y = ( DisplayHeight( display, data->screen ) - data->dialog_height ) / 3 ;
420
420
    }
421
 
    XMoveWindow( display, data->window, x, y );
 
421
    X11_XMoveWindow( display, data->window, x, y );
422
422
 
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;
433
433
 
434
 
        XSetWMNormalHints( display, data->window, sizehints );
 
434
        X11_XSetWMNormalHints( display, data->window, sizehints );
435
435
 
436
 
        XFree( sizehints );
 
436
        X11_XFree( sizehints );
437
437
    }
438
438
 
439
 
    XMapRaised( display, data->window );
 
439
    X11_XMapRaised( display, data->window );
440
440
    return 0;
441
441
}
442
442
 
448
448
    Window window = data->window;
449
449
    Display *display = data->display;
450
450
 
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 );
453
453
 
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 ];
457
457
 
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 );
462
462
        } else {
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 );
466
466
        }
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;
474
474
 
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 );
479
479
 
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 );
484
484
 
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 ] );
488
488
 
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 );
494
494
        } else {
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 );
498
498
        }
519
519
        ctx_vals.font = data->font_struct->fid;
520
520
    }
521
521
 
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");
525
525
    }
531
531
        XEvent e;
532
532
        SDL_bool draw = SDL_TRUE;
533
533
 
534
 
        XWindowEvent( data->display, data->window, data->event_mask, &e );
 
534
        X11_XWindowEvent( data->display, data->window, data->event_mask, &e );
535
535
 
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 ) )
539
539
            continue;
540
540
 
541
541
        switch( e.type ) {
574
574
 
575
575
        case KeyPress:
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 );
578
578
            break;
579
579
 
580
580
        case KeyRelease: {
581
581
            Uint32 mask = 0;
582
 
            KeySym key = XLookupKeysym( &e.xkey, 0 );
 
582
            KeySym key = X11_XLookupKeysym( &e.xkey, 0 );
583
583
 
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 )
637
637
        }
638
638
    }
639
639
 
640
 
    XFreeGC( data->display, ctx );
 
640
    X11_XFreeGC( data->display, ctx );
641
641
    return 0;
642
642
}
643
643
 
667
667
#endif
668
668
 
669
669
    /* This code could get called from multiple threads maybe? */
670
 
    XInitThreads();
 
670
    X11_XInitThreads();
671
671
 
672
672
    /* Initialize the return buttonid value to -1 (for error or dialogbox closed). */
673
673
    *buttonid = -1;
707
707
    int status = 0;
708
708
 
709
709
    /* Need to flush here in case someone has turned grab off and it hasn't gone through yet, etc. */
710
 
    XFlush(data->display);
 
710
    X11_XFlush(data->display);
711
711
 
712
712
    if (pipe(fds) == -1) {
713
713
        return X11_ShowMessageBoxImpl(messageboxdata, buttonid); /* oh well. */