コード例 #1
0
ファイル: x11_main.c プロジェクト: DavidWiberg/sumatrapdf
int main(int argc, char **argv)
{
	int c;
	int len;
	char buf[128];
	KeySym keysym;
	int oldx = 0;
	int oldy = 0;
	int resolution = -1;
	int pageno = 1;
	fd_set fds;
	int width = -1;
	int height = -1;
	fz_context *ctx;
	struct timeval tmo_at;
	struct timeval now;
	struct timeval tmo;
	struct timeval *timeout;
	struct timeval tmo_advance_delay;

	ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT);
	if (!ctx)
	{
		fprintf(stderr, "cannot initialise context\n");
		exit(1);
	}

	while ((c = fz_getopt(argc, argv, "p:r:b:")) != -1)
	{
		switch (c)
		{
		case 'p': password = fz_optarg; break;
		case 'r': resolution = atoi(fz_optarg); break;
		case 'b': fz_set_aa_level(ctx, atoi(fz_optarg)); break;
		default: usage();
		}
	}

	if (argc - fz_optind == 0)
		usage();

	filename = argv[fz_optind++];

	if (argc - fz_optind == 1)
		pageno = atoi(argv[fz_optind++]);

	pdfapp_init(ctx, &gapp);

	winopen();

	if (resolution == -1)
		resolution = winresolution();
	if (resolution < MINRES)
		resolution = MINRES;
	if (resolution > MAXRES)
		resolution = MAXRES;

	gapp.transitions_enabled = 1;
	gapp.scrw = DisplayWidth(xdpy, xscr);
	gapp.scrh = DisplayHeight(xdpy, xscr);
	gapp.resolution = resolution;
	gapp.pageno = pageno;

	pdfapp_open(&gapp, filename, 0);

	FD_ZERO(&fds);

	signal(SIGHUP, signal_handler);

	tmo_at.tv_sec = 0;
	tmo_at.tv_usec = 0;

	while (!closing)
	{
		while (!closing && XPending(xdpy) && !transition_dirty)
		{
			XNextEvent(xdpy, &xevt);

			switch (xevt.type)
			{
			case Expose:
				dirty = 1;
				break;

			case ConfigureNotify:
				if (gapp.image)
				{
					if (xevt.xconfigure.width != reqw ||
						xevt.xconfigure.height != reqh)
						gapp.shrinkwrap = 0;
				}
				width = xevt.xconfigure.width;
				height = xevt.xconfigure.height;

				break;

			case KeyPress:
				len = XLookupString(&xevt.xkey, buf, sizeof buf, &keysym, NULL);

				if (!gapp.isediting)
					switch (keysym)
					{
					case XK_Escape:
						len = 1; buf[0] = '\033';
						break;

					case XK_Up:
						len = 1; buf[0] = 'k';
						break;
					case XK_Down:
						len = 1; buf[0] = 'j';
						break;

					case XK_Left:
						len = 1; buf[0] = 'b';
						break;
					case XK_Right:
						len = 1; buf[0] = ' ';
						break;

					case XK_Page_Up:
						len = 1; buf[0] = ',';
						break;
					case XK_Page_Down:
						len = 1; buf[0] = '.';
						break;
					}
				if (xevt.xkey.state & ControlMask && keysym == XK_c)
					docopy(&gapp, XA_CLIPBOARD);
				else if (len)
					onkey(buf[0]);

				onmouse(oldx, oldy, 0, 0, 0);

				break;

			case MotionNotify:
				oldx = xevt.xmotion.x;
				oldy = xevt.xmotion.y;
				onmouse(xevt.xmotion.x, xevt.xmotion.y, 0, xevt.xmotion.state, 0);
				break;

			case ButtonPress:
				onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 1);
				break;

			case ButtonRelease:
				copytime = xevt.xbutton.time;
				onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, -1);
				break;

			case SelectionRequest:
				onselreq(xevt.xselectionrequest.requestor,
					xevt.xselectionrequest.selection,
					xevt.xselectionrequest.target,
					xevt.xselectionrequest.property,
					xevt.xselectionrequest.time);
				break;

			case ClientMessage:
				if (xevt.xclient.format == 32 && xevt.xclient.data.l[0] == WM_DELETE_WINDOW)
					closing = 1;
				break;
			}
		}

		if (closing)
			continue;

		if (width != -1 || height != -1)
		{
			pdfapp_onresize(&gapp, width, height);
			width = -1;
			height = -1;
		}

		if (dirty || dirtysearch)
		{
			if (dirty)
				winblit(&gapp);
			else if (dirtysearch)
				winblitsearch(&gapp);
			dirty = 0;
			transition_dirty = 0;
			dirtysearch = 0;
			pdfapp_postblit(&gapp);
		}

		if (showingpage && !tmo_at.tv_sec && !tmo_at.tv_usec)
		{
			tmo.tv_sec = 2;
			tmo.tv_usec = 0;

			gettimeofday(&now, NULL);
			timeradd(&now, &tmo, &tmo_at);
		}

		if (XPending(xdpy) || transition_dirty)
			continue;

		timeout = NULL;

		if (tmo_at.tv_sec || tmo_at.tv_usec)
		{
			gettimeofday(&now, NULL);
			timersub(&tmo_at, &now, &tmo);
			if (tmo.tv_sec <= 0)
			{
				tmo_at.tv_sec = 0;
				tmo_at.tv_usec = 0;
				timeout = NULL;
				showingpage = 0;
				winrepaint(&gapp);
			}
			else
				timeout = &tmo;
		}

		if (advance_scheduled)
		{
			gettimeofday(&now, NULL);
			timersub(&tmo_advance, &now, &tmo_advance_delay);
			if (tmo_advance_delay.tv_sec <= 0)
			{
				/* Too late already */
				onkey(' ');
				onmouse(oldx, oldy, 0, 0, 0);
				advance_scheduled = 0;
			}
			else if (timeout == NULL)
			{
				timeout = &tmo_advance_delay;
			}
			else
			{
				struct timeval tmp;
				timersub(&tmo_advance_delay, timeout, &tmp);
				if (tmp.tv_sec < 0)
				{
					timeout = &tmo_advance_delay;
				}
			}
		}

		FD_SET(x11fd, &fds);
		if (select(x11fd + 1, &fds, NULL, NULL, timeout) < 0)
		{
			if (reloading)
			{
				winreloadfile(&gapp);
				reloading = 0;
			}
		}
		if (!FD_ISSET(x11fd, &fds))
		{
			if (timeout == &tmo_advance_delay)
			{
				onkey(' ');
				onmouse(oldx, oldy, 0, 0, 0);
				advance_scheduled = 0;
			}
			else
			{
				tmo_at.tv_sec = 0;
				tmo_at.tv_usec = 0;
				timeout = NULL;
				showingpage = 0;
				winrepaint(&gapp);
			}
		}
	}

	cleanup(&gapp);

	return 0;
}
コード例 #2
0
ファイル: win_main.c プロジェクト: AvinashKiran/mupdf
LRESULT CALLBACK
viewproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static int oldx = 0;
	static int oldy = 0;
	int x = (signed short) LOWORD(lParam);
	int y = (signed short) HIWORD(lParam);

	switch (message)
	{
	case WM_SIZE:
		if (wParam == SIZE_MINIMIZED)
			return 0;
		if (wParam == SIZE_MAXIMIZED)
			gapp.shrinkwrap = 0;
		pdfapp_onresize(&gapp, LOWORD(lParam), HIWORD(lParam));
		break;

	/* Paint events are low priority and automagically catenated
	 * so we don't need to do any fancy waiting to defer repainting.
	 */
	case WM_PAINT:
	{
		//puts("WM_PAINT");
		PAINTSTRUCT ps;
		hdc = BeginPaint(hwnd, &ps);
		winblit();
		hdc = NULL;
		EndPaint(hwnd, &ps);
		pdfapp_postblit(&gapp);
		return 0;
	}

	case WM_ERASEBKGND:
		return 1; // well, we don't need to erase to redraw cleanly

	/* Mouse events */

	case WM_LBUTTONDOWN:
		SetFocus(hwndview);
		oldx = x; oldy = y;
		handlemouse(x, y, 1, 1);
		return 0;
	case WM_MBUTTONDOWN:
		SetFocus(hwndview);
		oldx = x; oldy = y;
		handlemouse(x, y, 2, 1);
		return 0;
	case WM_RBUTTONDOWN:
		SetFocus(hwndview);
		oldx = x; oldy = y;
		handlemouse(x, y, 3, 1);
		return 0;

	case WM_LBUTTONUP:
		oldx = x; oldy = y;
		handlemouse(x, y, 1, -1);
		return 0;
	case WM_MBUTTONUP:
		oldx = x; oldy = y;
		handlemouse(x, y, 2, -1);
		return 0;
	case WM_RBUTTONUP:
		oldx = x; oldy = y;
		handlemouse(x, y, 3, -1);
		return 0;

	case WM_MOUSEMOVE:
		oldx = x; oldy = y;
		handlemouse(x, y, 0, 0);
		return 0;

	/* Mouse wheel */

	case WM_MOUSEWHEEL:
		if ((signed short)HIWORD(wParam) > 0)
			handlekey(LOWORD(wParam) & MK_SHIFT ? '+' : 'k');
		else
			handlekey(LOWORD(wParam) & MK_SHIFT ? '-' : 'j');
		return 0;

	/* Timer */
	case WM_TIMER:
		if (wParam == OUR_TIMER_ID && timer_pending && gapp.presentation_mode)
		{
			timer_pending = 0;
			handlekey(VK_RIGHT + 256);
			handlemouse(oldx, oldy, 0, 0); /* update cursor */
			return 0;
		}
		break;

	/* Keyboard events */

	case WM_KEYDOWN:
		/* only handle special keys */
		switch (wParam)
		{
		case VK_F1:
		case VK_LEFT:
		case VK_UP:
		case VK_PRIOR:
		case VK_RIGHT:
		case VK_DOWN:
		case VK_NEXT:
		case VK_ESCAPE:
			handlekey(wParam + 256);
			handlemouse(oldx, oldy, 0, 0);	/* update cursor */
			return 0;
		}
		return 1;

	/* unicode encoded chars, including escape, backspace etc... */
	case WM_CHAR:
		if (wParam < 256)
		{
			handlekey(wParam);
			handlemouse(oldx, oldy, 0, 0);	/* update cursor */
		}
		return 0;
	}

	fflush(stdout);

	/* Pass on unhandled events to Windows */
	return DefWindowProc(hwnd, message, wParam, lParam);
}
コード例 #3
0
ファイル: syswin.c プロジェクト: BPaden/garglk
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);
}
コード例 #4
0
int main(int argc, char **argv)
{
	char *filename;
	int c;
	int len;
	char buf[128];
	KeySym keysym;
	int oldx = 0;
	int oldy = 0;
	int zoom = 100;
	int pageno = 1;
	int wasshowingpage;
	struct timeval tmo, tmo_at;

	while ((c = fz_getopt(argc, argv, "d:z:p:")) != -1)
	{
		switch (c)
		{
		case 'd': password = fz_optarg; break;
		case 'z': zoom = atoi(fz_optarg); break;
		case 'p': pageno = atoi(fz_optarg); break;
		default: usage();
		}
	}

	if (zoom < 100)
		zoom = 100;
	if (zoom > 300)
		zoom = 300;

	if (argc - fz_optind == 0)
		usage();

	filename = argv[fz_optind++];

	fz_cpudetect();
	fz_accelerate();

	winopen();

	pdfapp_init(&gapp);
	gapp.scrw = DisplayWidth(xdpy, xscr);
	gapp.scrh = DisplayHeight(xdpy, xscr);
	gapp.zoom = zoom / 100.0;
	gapp.pageno = pageno;

	pdfapp_open(&gapp, filename);

	winresettmo(&tmo, &tmo_at);

	while (1)
	{
		do
		{
			winawaitevent(&tmo, &tmo_at);

			if (tmo_at.tv_sec != 0 && tmo_at.tv_usec != 0 &&
				tmo.tv_sec == 0 && tmo.tv_usec == 0)
			{
				/* redraw page */
				winblit(&gapp);
				isshowingpage = 0;
				winresettmo(&tmo, &tmo_at);
				continue;
			}

			switch (xevt.type)
			{
			case Expose:
				dirty = 1;
				break;

			case ConfigureNotify:
				if (gapp.image)
				{
					if (xevt.xconfigure.width != reqw ||
						xevt.xconfigure.height != reqh)
						gapp.shrinkwrap = 0;
				}
				pdfapp_onresize(&gapp,
						xevt.xconfigure.width,
						xevt.xconfigure.height);
				break;

			case KeyPress:
				wasshowingpage = isshowingpage;

				len = XLookupString(&xevt.xkey, buf, sizeof buf, &keysym, nil);
				if (len)
					onkey(buf[0]);
				onmouse(oldx, oldy, 0, 0, 0);

				if (dirty)
				{
					winblit(&gapp);
					dirty = 0;
					if (isshowingpage)
					{
						isshowingpage = 0;
						winresettmo(&tmo, &tmo_at);
					}
				}

				if (!wasshowingpage && isshowingpage)
					winsettmo(&tmo, &tmo_at);

				break;

			case MotionNotify:
				oldx = xevt.xbutton.x;
				oldy = xevt.xbutton.y;
				onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 0);
				break;

			case ButtonPress:
				onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 1);
				break;

			case ButtonRelease:
				copytime = xevt.xbutton.time;
				onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, -1);
				break;

			case SelectionRequest:
				onselreq(xevt.xselectionrequest.requestor,
						xevt.xselectionrequest.selection,
						xevt.xselectionrequest.target,
						xevt.xselectionrequest.property,
						xevt.xselectionrequest.time);
				break;
			}
		}
		while (XPending(xdpy));

		if (dirty)
		{
			winblit(&gapp);
			dirty = 0;
			if (isshowingpage)
			{
				isshowingpage = 0;
				winresettmo(&tmo, &tmo_at);
			}
		}
	}

	pdfapp_close(&gapp);

	return 0;
}
コード例 #5
0
int main(int argc, char **argv)
{
	char *filename;
	int c;
	int len;
	unsigned char buf[128];
	KeySym keysym;
	int oldx = 0;
	int oldy = 0;
	double zoom = 1.0;
	int pageno = 1;

	while ((c = getopt(argc, argv, "d:z:p:")) != -1)
	{
		switch (c)
		{
		case 'd': password = optarg; break;
		case 'z': zoom = atof(optarg); break;
		case 'p': pageno = atoi(optarg); break;
		default: usage();
		}
	}

	if (argc - optind == 0)
		usage();

	filename = argv[optind++];

	fz_cpudetect();
	fz_accelerate();

	winopen();

	pdfapp_init(&gapp);
	gapp.scrw = DisplayWidth(xdpy, xscr);
	gapp.scrh = DisplayHeight(xdpy, xscr);
	gapp.zoom = zoom;
	gapp.pageno = pageno;

	pdfapp_open(&gapp, filename);

	while (1)
	{
		do
		{
			XNextEvent(xdpy, &xevt);

			switch (xevt.type)
			{
			case Expose:
				dirty = 1;
				break;

			case ConfigureNotify:
				if (gapp.image)
				{
					if (xevt.xconfigure.width != reqw ||
						xevt.xconfigure.height != reqh)
						gapp.shrinkwrap = 0;
				}
				pdfapp_onresize(&gapp,
						xevt.xconfigure.width,
						xevt.xconfigure.height);
				break;

			case KeyPress:
				len = XLookupString(&xevt.xkey, buf, sizeof buf, &keysym, 0);
				if (len)
					onkey(buf[0]);
				onmouse(oldx, oldy, 0, 0, 0);

				if (dirty)
				{
					winblit(&gapp);
					dirty = 0;
				}

				break;

			case MotionNotify:
				oldx = xevt.xbutton.x;
				oldy = xevt.xbutton.y;
				onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 0);
				break;

			case ButtonPress:
				onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 1);
				break;

			case ButtonRelease:
				copytime = xevt.xbutton.time;
				onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, -1);
				break;

			case SelectionRequest:
				onselreq(xevt.xselectionrequest.requestor,
						xevt.xselectionrequest.selection,
						xevt.xselectionrequest.target,
						xevt.xselectionrequest.property,
						xevt.xselectionrequest.time);
				break;
			}
		}
		while (XPending(xdpy));

		if (dirty)
		{
			winblit(&gapp);
			dirty = 0;
		}
	}

	pdfapp_close(&gapp);

	return 0;
}
コード例 #6
0
ファイル: x11_main.c プロジェクト: Asido/MuPDF
int main(int argc, char **argv)
{
	int c;
	int len;
	char buf[128];
	KeySym keysym;
	int oldx = 0;
	int oldy = 0;
	int resolution = 72;
	int pageno = 1;
	int pagemark = 0;
	int accelerate = 1;
	int fd;
	fd_set fds;
	int width = -1;
	int height = -1;

	while ((c = fz_getopt(argc, argv, "p:r:b:A")) != -1)
	{
		switch (c)
		{
		case 'p': password = fz_optarg; break;
		case 'r': resolution = atoi(fz_optarg); break;
		case 'A': accelerate = 0; break;
		case 'b': fz_set_aa_level(atoi(fz_optarg)); break;
		default: usage();
		}
	}

	if (resolution < MINRES)
		resolution = MINRES;
	if (resolution > MAXRES)
		resolution = MAXRES;

	if (argc - fz_optind == 0)
		usage();

	if (accelerate)
		fz_accelerate();

	filename = argv[fz_optind++];

	winopen();

	pdfapp_init(&gapp);
	gapp.scrw = DisplayWidth(xdpy, xscr);
	gapp.scrh = DisplayHeight(xdpy, xscr);
	gapp.resolution = resolution;

	if (argc - fz_optind > 1)
		pageno = atoi(argv[fz_optind++]);

	gapp.pageno = pageno;

	fd = open(filename, O_BINARY | O_RDONLY, 0666);
	if (fd < 0)
		winerror(&gapp, fz_throw("cannot open file '%s'", filename));

	pdfapp_open(&gapp, filename, fd, 0);

	if (pdfapp_calcfilehash(&gapp, fd))
	{
		pdfapp_getmarkfile(&gapp);
		pagemark = pdfapp_getpgmark(&gapp);
		if (pagemark > 0)
		{
			if (pagemark <= gapp.pagecount)
			{
				gapp.pageno = pagemark;
				pdfapp_showpage(&gapp, 1, 1, 1);
			}
			else
				pdfapp_closemarkfile(&gapp);
		}
	}

	FD_ZERO(&fds);
	FD_SET(x11fd, &fds);

	signal(SIGHUP, signal_handler);
	atexit(exit_cb);

	while (!closing)
	{
		do
		{
			XNextEvent(xdpy, &xevt);

			switch (xevt.type)
			{
			case Expose:
				dirty = 1;
				break;

			case ConfigureNotify:
				if (gapp.image)
				{
					if (xevt.xconfigure.width != reqw ||
						xevt.xconfigure.height != reqh)
						gapp.shrinkwrap = 0;
				}
				width = xevt.xconfigure.width;
				height = xevt.xconfigure.height;

				break;

			case KeyPress:
				len = XLookupString(&xevt.xkey, buf, sizeof buf, &keysym, NULL);

				if (!gapp.isediting)
					switch (keysym)
					{
					case XK_Escape:
						len = 1; buf[0] = '\033';
						break;

					case XK_Up:
						len = 1; buf[0] = 'k';
						break;
					case XK_Down:
						len = 1; buf[0] = 'j';
						break;

					case XK_Left:
						len = 1; buf[0] = 'b';
						break;
					case XK_Right:
						len = 1; buf[0] = ' ';
						break;

					case XK_Page_Up:
						len = 1; buf[0] = ',';
						break;
					case XK_Page_Down:
						len = 1; buf[0] = '.';
						break;
					}
				if (len)
					onkey(buf[0]);

				onmouse(oldx, oldy, 0, 0, 0);

				break;

			case MotionNotify:
				oldx = xevt.xbutton.x;
				oldy = xevt.xbutton.y;
				onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 0);
				break;

			case ButtonPress:
				onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 1);
				break;

			case ButtonRelease:
				copytime = xevt.xbutton.time;
				onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, -1);
				break;

			case SelectionRequest:
				onselreq(xevt.xselectionrequest.requestor,
					xevt.xselectionrequest.selection,
					xevt.xselectionrequest.target,
					xevt.xselectionrequest.property,
					xevt.xselectionrequest.time);
				break;

			case ClientMessage:
				if (xevt.xclient.format == 32 && xevt.xclient.data.l[0] == WM_DELETE_WINDOW)
					closing = 1;
				break;
			}
		}
		while (!closing && XPending(xdpy));

		if (closing)
			continue;

		if (width != -1 || height != -1)
		{
			pdfapp_onresize(&gapp, width, height);
			width = -1;
			height = -1;
		}

		if (dirty || dirtysearch)
		{
			if (dirty)
				winblit(&gapp);
			else if (dirtysearch)
				winblitsearch(&gapp);
			dirty = 0;
			dirtysearch = 0;
		}

		if (XPending(xdpy))
			continue;

		if (select(x11fd + 1, &fds, NULL, NULL, NULL) < 0)
		{
			if (reloading)
			{
				winreloadfile(&gapp);
				reloading = 0;
			}
		}
	}

	pdfapp_close(&gapp);

	XDestroyWindow(xdpy, xwin);

	XFreePixmap(xdpy, xicon);

	XFreeCursor(xdpy, xcwait);
	XFreeCursor(xdpy, xchand);
	XFreeCursor(xdpy, xcarrow);

	XFreeGC(xdpy, xgc);

	XCloseDisplay(xdpy);

	return 0;
}
コード例 #7
0
ファイル: syswin.c プロジェクト: KeanW/zlr--git
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);
}