Getting GTK/W32 applications to run

Olaf Leidinger leidola at newcon.de
Tue Jan 16 08:57:27 CST 2007


Hello!

> Thank you for your elaborate diagnosis. This is probably related to the
> problem Mono has on Wine because it also uses Pango/GTK.

It seems as if this is not a problem with GTK or Pango but with cairo. GTK-2.6 (without cairo) works fine on wine.
Here is a minimal cairo-win32 example basing uppon code from Owen Taylor:

/*
 * This example code is placed in the public domain
 *
 * Author: Owen Taylor <otaylor at redhat.com>, Red Hat Inc.
 */

#include <cairo-win32.h>

#define TITLE TEXT("Cairo test")
#define BORDER_WIDTH 75.
#define SNIPPET_WIDTH  300.
#define SNIPPET_HEIGHT 300.
#define FONT_SIZE 24


static void
on_paint (HDC hdc)
{
    cairo_surface_t *surface;
    cairo_t *cr;
    double line_width;
    cairo_font_extents_t font_extents;

    surface = cairo_win32_surface_create (hdc);
    cr = cairo_create (surface);

    line_width = cairo_get_line_width (cr);

    /* Draw a box bordering the snippet */
    cairo_rectangle (cr,
		     BORDER_WIDTH - line_width / 2, BORDER_WIDTH - line_width / 2,
		     SNIPPET_WIDTH + line_width, SNIPPET_WIDTH + line_width);
    cairo_stroke (cr);

    /* And some text */
    cairo_select_font_face (cr, "Arial", CAIRO_FONT_SLANT_NORMAL,
                               CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, FONT_SIZE);
    cairo_font_extents (cr, &font_extents);

    cairo_move_to (cr,
		   BORDER_WIDTH,
		   BORDER_WIDTH + SNIPPET_WIDTH + font_extents.ascent);
    cairo_show_text (cr, "This is some example text!");

    cairo_destroy (cr);
    cairo_surface_destroy (surface);
}


/* The WinMain and window procedure are loosely based on a example
 * from the Microsoft documentation.
 */
LRESULT CALLBACK
WndProc (HWND   window,
	 UINT   message,
	 WPARAM wParam,
	 LPARAM lParam)
{
    PAINTSTRUCT paint_struct;
    HDC dc;

    switch(message) {
    case WM_CHAR:
	switch (wParam) {
	case 'q':
	case 'Q':
	    PostQuitMessage (0);
	    return 0;
	    break;
	}
	break;
    case WM_PAINT:
	dc = BeginPaint (window, &paint_struct);
	on_paint (dc);
	EndPaint (window, &paint_struct);
	return 0;
    case WM_DESTROY:
	PostQuitMessage (0);
	return 0;
    default:
	;
    }

    return DefWindowProc (window, message, wParam, lParam);
}

#define WINDOW_STYLE WS_OVERLAPPEDWINDOW & ~(WS_MAXIMIZEBOX | WS_THICKFRAME)

INT WINAPI
WinMain (HINSTANCE hInstance,
	 HINSTANCE hPrevInstance,
	 PSTR      lpCmdLine,
	 INT       iCmdShow)
{
    HWND window;
    MSG message;
    WNDCLASS window_class;
    RECT rect;

    window_class.style = CS_HREDRAW | CS_VREDRAW;
    window_class.lpfnWndProc = WndProc;
    window_class.cbClsExtra = 0;
    window_class.cbWndExtra = 0;
    window_class.hInstance = hInstance;
    window_class.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    window_class.hCursor = LoadCursor (NULL, IDC_ARROW);
    window_class.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
    window_class.lpszMenuName = NULL;
    window_class.lpszClassName = TITLE;

    RegisterClass (&window_class);

    /* Compute the window size to give us the desired client area */
    rect.left = 0;
    rect.top = 0;
    rect.right = SNIPPET_WIDTH + 2 * BORDER_WIDTH;
    rect.bottom = SNIPPET_WIDTH + 2 * BORDER_WIDTH;

    AdjustWindowRect (&rect, WINDOW_STYLE, FALSE /* no menu */);

    window = CreateWindow (TITLE, /* Class name */
			   TITLE, /* Window name */
			   WINDOW_STYLE,
			   CW_USEDEFAULT, CW_USEDEFAULT, /* initial position */
			   rect.right - rect.left, rect.bottom - rect.top, /* initial size */
			   NULL,	/* Parent */
			   NULL,	/* Menu */
			   hInstance,
			   NULL); /* WM_CREATE lpParam */

    ShowWindow (window, iCmdShow);
    UpdateWindow (window);

    while (GetMessage (&message, NULL, 0, 0)) {
	TranslateMessage (&message);
	DispatchMessage (&message);
    }

    return message.wParam;
}

/************/

The font output isn't corrent -- see [1] and [2] as reference.

[1] http://gordon.cip.physik.uni-saarland.de/~oleid/cairo-wine.png
[2] http://gordon.cip.physik.uni-saarland.de/~oleid/cairo-win32.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-devel/attachments/20070116/adb96806/attachment.pgp


More information about the wine-devel mailing list