Ejemplo n.º 1
0
static void onbutton(GtkWidget *widget, GdkEventButton *event, void *data)
{
	gli_input_handle_click(event->x, event->y);
}
Ejemplo n.º 2
0
LRESULT CALLBACK
viewproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int x = (signed short) LOWORD(lParam);
    int y = (signed short) HIWORD(lParam);
    glui32 key;

    switch (message)
    {
    case WM_ERASEBKGND:
    return 1; // don't erase; we'll repaint it all

    case WM_PAINT:
    {
        PAINTSTRUCT ps;

        /* make sure we have a fresh bitmap */
        if (!gli_drawselect)
            gli_windows_redraw();
        else
            gli_drawselect = FALSE;

        /* and blit it to the screen */
        hdc = BeginPaint(hwnd, &ps);
        winblit(ps.rcPaint);
        hdc = NULL;
        EndPaint(hwnd, &ps);

        return 0;
    }

    case WM_SIZE:
    {
        int newwid = LOWORD(lParam);
        int newhgt = HIWORD(lParam);

        if (newwid == 0 || newhgt == 0)
        break;

        if (newwid == gli_image_w && newhgt == gli_image_h)
        break;

        gli_image_w = newwid;
        gli_image_h = newhgt;

        gli_resize_mask(gli_image_w, gli_image_h);

        gli_image_s = ((gli_image_w * 3 + 3) / 4) * 4;
        if (gli_image_rgb)
        free(gli_image_rgb);
        gli_image_rgb = malloc(gli_image_s * gli_image_h);

        gli_force_redraw = 1;

        gli_windows_size_change();

        break;
    }

    case WM_LBUTTONDOWN:
    {
        SetFocus(hwndview);
        gli_input_handle_click(x, y);
        return 0;
    }

    case WM_LBUTTONUP:
    {
        gli_copyselect = FALSE;
        SetCursor(idc_arrow);
        return 0;
    }

    case WM_MBUTTONDOWN:
    case WM_RBUTTONDOWN:
    {
        SetFocus(hwndview);
        return 0;
    }

    case WM_MOUSEWHEEL:
    {
        if (GET_WHEEL_DELTA_WPARAM(wParam) > 0)
            gli_input_handle_key(keycode_MouseWheelUp);
        else
            gli_input_handle_key(keycode_MouseWheelDown);
    }

    case WM_CAPTURECHANGED:
    {
        gli_copyselect = FALSE;
        return 0;
    }

    case WM_MOUSEMOVE:
    {
        /* catch and release */
        RECT rect;
        POINT pt = { x, y };
        GetClientRect(hwnd, &rect);
        int hover = PtInRect(&rect, pt);

        if (!hover) {
            if (GetCapture() == hwnd)
                ReleaseCapture();
        } else {
            if (GetCapture() != hwnd ) {
                SetCapture(hwnd);
            }
            if (gli_copyselect) {
                SetCursor(idc_ibeam);
                gli_move_selection(x, y);
            } else {
                if (gli_get_hyperlink(x, y)) {
                    SetCursor(idc_hand);
                } else {
                    SetCursor(idc_arrow);
                }
            }
        }

        return 0;
    }

    case WM_COPY:
    {
        gli_copyselect = FALSE;
        SetCursor(idc_arrow);
        winclipsend();
        return 0;
    }

    case WM_PASTE:
    {
        SetFocus(hwndview);
        winclipreceive();
        return 0;
    }

    case WM_KEYDOWN:

    switch (wParam)
    {
    case VK_PRIOR: gli_input_handle_key(keycode_PageUp); break;
    case VK_NEXT: gli_input_handle_key(keycode_PageDown); break;
    case VK_HOME: gli_input_handle_key(keycode_Home); break;
    case VK_END: gli_input_handle_key(keycode_End); break;
    case VK_LEFT: gli_input_handle_key(keycode_Left); break;
    case VK_RIGHT: gli_input_handle_key(keycode_Right); break;
    case VK_UP: gli_input_handle_key(keycode_Up); break;
    case VK_DOWN: gli_input_handle_key(keycode_Down); break;
    case VK_ESCAPE: gli_input_handle_key(keycode_Escape); break;
    case VK_DELETE: gli_input_handle_key(keycode_Erase); break;
    case VK_F1: gli_input_handle_key(keycode_Func1); break;
    case VK_F2: gli_input_handle_key(keycode_Func2); break;
    case VK_F3: gli_input_handle_key(keycode_Func3); break;
    case VK_F4: gli_input_handle_key(keycode_Func4); break;
    case VK_F5: gli_input_handle_key(keycode_Func5); break;
    case VK_F6: gli_input_handle_key(keycode_Func6); break;
    case VK_F7: gli_input_handle_key(keycode_Func7); break;
    case VK_F8: gli_input_handle_key(keycode_Func8); break;
    case VK_F9: gli_input_handle_key(keycode_Func9); break;
    case VK_F10: gli_input_handle_key(keycode_Func10); break;
    case VK_F11: gli_input_handle_key(keycode_Func11); break;
    case VK_F12: gli_input_handle_key(keycode_Func12); break;
    }
    return 0;

    /* unicode encoded chars, including escape, backspace etc... */
    case WM_UNICHAR:
        key = wParam;

        if (key == UNICODE_NOCHAR)
            return 1; /* yes, we like WM_UNICHAR */

        if (key == '\r' || key == '\n')
            gli_input_handle_key(keycode_Return);
        else if (key == '\b')
            gli_input_handle_key(keycode_Delete);
        else if (key == '\t')
            gli_input_handle_key(keycode_Tab);
        else if (key == 0x03 || key == 0x18)
            SendMessage(hwndview, WM_COPY, 0, 0);
        else if (key == 0x16)
            SendMessage(hwndview, WM_PASTE, 0, 0);
        else if (key != 27)
            gli_input_handle_key(key);

        return 0;

    case WM_CHAR:
        key = wParam;

        if (key == '\r' || key == '\n')
            gli_input_handle_key(keycode_Return);
        else if (key == '\b')
            gli_input_handle_key(keycode_Delete);
        else if (key == '\t')
            gli_input_handle_key(keycode_Tab);
        else if (key == 0x03 || key == 0x18)
            SendMessage(hwndview, WM_COPY, 0, 0);
        else if (key == 0x16)
            SendMessage(hwndview, WM_PASTE, 0, 0);
        else if (key != 27) {
            /* translate from ANSI code page to Unicode */
            char ansich = (char)key;
            wchar_t widebuf[2];
            int res = MultiByteToWideChar(CP_ACP, 0, &ansich, 1, widebuf, 2);
            if (res) {
                if (Uni_IsSurrogate1(widebuf[0]))
                    key = Uni_SurrogateToUTF32(widebuf[0], widebuf[1]);
                else
                    key = widebuf[0];
                gli_input_handle_key(key);
            }
        }

        return 0;
    }

    /* Pass on unhandled events to Windows */
    return DefWindowProc(hwnd, message, wParam, lParam);
}
Ejemplo n.º 3
0
LRESULT CALLBACK
viewproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int x = (signed short) LOWORD(lParam);
    int y = (signed short) HIWORD(lParam);
    glui32 key;

    switch (message)
    {
    case WM_ERASEBKGND:
	return 1; // don't erase; we'll repaint it all

    case WM_PAINT:
	{
	    PAINTSTRUCT ps;

	    /* make sure we have a fresh bitmap */
	    gli_windows_redraw();

	    /* and blit it to the screen */
	    hdc = BeginPaint(hwnd, &ps);
	    winblit(ps.rcPaint);
	    hdc = NULL;
	    EndPaint(hwnd, &ps);

	    return 0;
	}

    case WM_SIZE:
	{
	    int newwid = LOWORD(lParam);
	    int newhgt = HIWORD(lParam);

	    if (newwid == 0 || newhgt == 0)
		break;

	    if (newwid == gli_image_w && newhgt == gli_image_h)
		break;

	    gli_image_w = newwid;
	    gli_image_h = newhgt;

	    gli_image_s = ((gli_image_w * 3 + 3) / 4) * 4;
	    if (gli_image_rgb)
		free(gli_image_rgb);
	    gli_image_rgb = malloc(gli_image_s * gli_image_h);

	    gli_force_redraw = 1;

	    gli_windows_size_change();

	    break;
	}

    case WM_LBUTTONDOWN:
	gli_input_handle_click(x, y);
	return 0;

    case WM_KEYDOWN:

	switch (wParam)
	{
	case VK_PRIOR: gli_input_handle_key(keycode_PageUp); break;
	case VK_NEXT: gli_input_handle_key(keycode_PageDown); break;
	case VK_HOME: gli_input_handle_key(keycode_Home); break;
	case VK_END: gli_input_handle_key(keycode_End); break;
	case VK_LEFT: gli_input_handle_key(keycode_Left); break;
	case VK_RIGHT: gli_input_handle_key(keycode_Right); break;
	case VK_UP: gli_input_handle_key(keycode_Up); break;
	case VK_DOWN: gli_input_handle_key(keycode_Down); break;
	case VK_ESCAPE: gli_input_handle_key(keycode_Escape); break;
	case VK_F1: gli_input_handle_key(keycode_Func1); break;
	case VK_F2: gli_input_handle_key(keycode_Func2); break;
	case VK_F3: gli_input_handle_key(keycode_Func3); break;
	case VK_F4: gli_input_handle_key(keycode_Func4); break;
	case VK_F5: gli_input_handle_key(keycode_Func5); break;
	case VK_F6: gli_input_handle_key(keycode_Func6); break;
	case VK_F7: gli_input_handle_key(keycode_Func7); break;
	case VK_F8: gli_input_handle_key(keycode_Func8); break;
	case VK_F9: gli_input_handle_key(keycode_Func9); break;
	case VK_F10: gli_input_handle_key(keycode_Func10); break;
	case VK_F11: gli_input_handle_key(keycode_Func11); break;
	case VK_F12: gli_input_handle_key(keycode_Func12); break;
	}
	return 0;

	/* unicode encoded chars, including escape, backspace etc... */
	case WM_UNICHAR:
		key = wParam;

		if (key == UNICODE_NOCHAR)
			return 1; /* yes, we like WM_UNICHAR */

		if (key == '\r' || key == '\n')
			gli_input_handle_key(keycode_Return);
		else if (key == '\b')
			gli_input_handle_key(keycode_Delete);
		else if (key == '\t')
			gli_input_handle_key(keycode_Tab);
		else if (key != 27)
			gli_input_handle_key(key);

		return 0;

    case WM_CHAR:
		key = wParam;

		if (key == '\r' || key == '\n')
			gli_input_handle_key(keycode_Return);
		else if (key == '\b')
			gli_input_handle_key(keycode_Delete);
		else if (key == '\t')
			gli_input_handle_key(keycode_Tab);
		else if (key != 27) {
			/* translate from ANSI code page to Unicode */
			char ansich = (char)key;
			wchar_t widebuf[2];
			int res = MultiByteToWideChar(CP_ACP, 0, &ansich, 1, widebuf, 2);
			if (res) {
				if (Uni_IsSurrogate1(widebuf[0]))
					key = Uni_SurrogateToUTF32(widebuf[0], widebuf[1]);
				else
					key = widebuf[0];
				gli_input_handle_key(key);
			}
		}

		return 0;
    }

    /* Pass on unhandled events to Windows */
    return DefWindowProc(hwnd, message, wParam, lParam);
}