示例#1
0
void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int state)
{
	pdf_link *link;
	fz_matrix ctm;
	fz_point p;

	p.x = x - app->panx + app->image->x;
	p.y = y - app->pany + app->image->y;

	ctm = pdfapp_viewctm(app);
	ctm = fz_invertmatrix(ctm);

	p = fz_transformpoint(ctm, p);

	for (link = app->page->links; link; link = link->next)
	{
		if (p.x >= link->rect.x0 && p.x <= link->rect.x1)
			if (p.y >= link->rect.y0 && p.y <= link->rect.y1)
				break;
	}

	if (link)
	{
		wincursor(app, HAND);
		if (btn == 1 && state == 1)
		{
			if (fz_isstring(link->dest))
				pdfapp_gotouri(app, link->dest);
			if (fz_isindirect(link->dest))
				pdfapp_gotopage(app, link->dest);
			return;
		}
	}
	else
	{
		wincursor(app, ARROW);
	}

	if (state == 1)
	{
		if (btn == 1 && !app->iscopying)
		{
			app->ispanning = 1;
			app->selx = x;
			app->sely = y;
		}
		if (btn == 3 && !app->ispanning)
		{
			app->iscopying = 1;
			app->selx = x;
			app->sely = y;
			app->selr.x0 = x;
			app->selr.x1 = x;
			app->selr.y0 = y;
			app->selr.y1 = y;
		}
		if (btn == 4 || btn == 5) /* scroll wheel */
		{
			int dir = btn == 4 ? 1 : -1;
			app->ispanning = app->iscopying = 0;
			if (modifiers & (1<<2))
			{
				/* zoom in/out if ctrl is pressed */
				app->zoom += 0.1 * dir;
				if (app->zoom > 3.0)
					app->zoom = 3.0;
				if (app->zoom < 0.1)
					app->zoom = 0.1;
				pdfapp_showpage(app, 0, 1);
			}
			else
			{
				/* scroll up/down, or left/right if
				   shift is pressed */
				int isx = (modifiers & (1<<0));
				int xstep = isx ? 20 * dir : 0;
				int ystep = !isx ? 20 * dir : 0;
				pdfapp_panview(app, app->panx + xstep, app->pany + ystep);
			}
		}
	}

	else if (state == -1)
	{
		if (app->iscopying)
		{
			app->iscopying = 0;
			app->selr.x0 = MIN(app->selx, x);
			app->selr.x1 = MAX(app->selx, x);
			app->selr.y0 = MIN(app->sely, y);
			app->selr.y1 = MAX(app->sely, y);
			winrepaint(app);
			if (app->selr.x0 < app->selr.x1 && app->selr.y0 < app->selr.y1)
				windocopy(app);
		}
		if (app->ispanning)
			app->ispanning = 0;
	}

	else if (app->ispanning)
	{
		int newx = app->panx + x - app->selx;
		int newy = app->pany + y - app->sely;
		pdfapp_panview(app, newx, newy);
		app->selx = x;
		app->sely = y;
	}

	else if (app->iscopying)
	{
		app->selr.x0 = MIN(app->selx, x);
		app->selr.x1 = MAX(app->selx, x);
		app->selr.y0 = MIN(app->sely, y);
		app->selr.y1 = MAX(app->sely, y);
		winrepaint(app);
	}

}
示例#2
0
void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int state)
{
	pdf_link *link;
	fz_matrix ctm;
	fz_point p;

	p.x = x - app->panx + app->image->x;
	p.y = y - app->pany + app->image->y;

	ctm = pdfapp_viewctm(app);
	ctm = fz_invert_matrix(ctm);

	p = fz_transform_point(ctm, p);

	for (link = app->page_links; link; link = link->next)
	{
		if (p.x >= link->rect.x0 && p.x <= link->rect.x1)
			if (p.y >= link->rect.y0 && p.y <= link->rect.y1)
				break;
	}

	if (link)
	{
		wincursor(app, HAND);
		if (btn == 1 && state == 1)
		{
			if (link->kind == PDF_LINK_URI)
				pdfapp_gotouri(app, link->dest);
			else if (link->kind == PDF_LINK_GOTO)
				pdfapp_gotopage(app, fz_array_get(link->dest, 0)); /* [ pageobj ... ] */
			return;
		}
	}
	else
	{
		wincursor(app, ARROW);
	}

	if (state == 1)
	{
		if (btn == 1 && !app->iscopying)
		{
			app->ispanning = 1;
			app->selx = x;
			app->sely = y;
			app->beyondy = 0;
		}
		if (btn == 3 && !app->ispanning)
		{
			app->iscopying = 1;
			app->selx = x;
			app->sely = y;
			app->selr.x0 = x;
			app->selr.x1 = x;
			app->selr.y0 = y;
			app->selr.y1 = y;
		}
		if (btn == 4 || btn == 5) /* scroll wheel */
		{
			int dir = btn == 4 ? 1 : -1;
			app->ispanning = app->iscopying = 0;
			if (modifiers & (1<<2))
			{
				/* zoom in/out if ctrl is pressed */
				if (dir > 0)
					app->resolution *= ZOOMSTEP;
				else
					app->resolution /= ZOOMSTEP;
				if (app->resolution > MAXRES)
					app->resolution = MAXRES;
				if (app->resolution < MINRES)
					app->resolution = MINRES;
				pdfapp_showpage(app, 0, 1, 1);
			}
			else
			{
				/* scroll up/down, or left/right if
				shift is pressed */
				int isx = (modifiers & (1<<0));
				int xstep = isx ? 20 * dir : 0;
				int ystep = !isx ? 20 * dir : 0;
				pdfapp_panview(app, app->panx + xstep, app->pany + ystep);
			}
		}
	}

	else if (state == -1)
	{
		if (app->iscopying)
		{
			app->iscopying = 0;
			app->selr.x0 = MIN(app->selx, x) - app->panx + app->image->x;
			app->selr.x1 = MAX(app->selx, x) - app->panx + app->image->x;
			app->selr.y0 = MIN(app->sely, y) - app->pany + app->image->y;
			app->selr.y1 = MAX(app->sely, y) - app->pany + app->image->y;
			winrepaint(app);
			if (app->selr.x0 < app->selr.x1 && app->selr.y0 < app->selr.y1)
				windocopy(app);
		}
		if (app->ispanning)
			app->ispanning = 0;
	}

	else if (app->ispanning)
	{
		int newx = app->panx + x - app->selx;
		int newy = app->pany + y - app->sely;
		/* Scrolling beyond limits implies flipping pages */
		/* Are we requested to scroll beyond limits? */
		if (newy + app->image->h < app->winh || newy > 0)
		{
			/* Yes. We can assume that deltay != 0 */
			int deltay = y - app->sely;
			/* Check whether the panning has occured in the
			 * direction that we are already crossing the
			 * limit it. If not, we can conclude that we
			 * have switched ends of the page and will thus
			 * start over counting.
			 */
			if( app->beyondy == 0 || (app->beyondy ^ deltay) >= 0 )
			{
				/* Updating how far we are beyond and
				 * flipping pages if beyond threshhold
				 */
				app->beyondy += deltay;
				if (app->beyondy > BEYOND_THRESHHOLD)
				{
					if( app->pageno > 1 )
					{
						app->pageno--;
						pdfapp_showpage(app, 1, 1, 1);
						newy = -app->image->h;
					}
					app->beyondy = 0;
				}
				else if (app->beyondy < -BEYOND_THRESHHOLD)
				{
					if( app->pageno < app->pagecount )
					{
						app->pageno++;
						pdfapp_showpage(app, 1, 1, 1);
						newy = 0;
					}
					app->beyondy = 0;
				}
			}
			else
				app->beyondy = 0;
		}
		/* Although at this point we've already determined that
		 * or that no scrolling will be performed in
		 * y-direction, the x-direction has not yet been taken
		 * care off. Therefore
		 */
		pdfapp_panview(app, newx, newy);

		app->selx = x;
		app->sely = y;
	}

	else if (app->iscopying)
	{
		app->selr.x0 = MIN(app->selx, x) - app->panx + app->image->x;
		app->selr.x1 = MAX(app->selx, x) - app->panx + app->image->x;
		app->selr.y0 = MIN(app->sely, y) - app->pany + app->image->y;
		app->selr.y1 = MAX(app->sely, y) - app->pany + app->image->y;
		winrepaint(app);
	}

}
示例#3
0
void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int state)
{
    pdf_link *link;
    fz_matrix ctm;
    fz_point p;

    p.x = x - app->panx + app->image->x;
    p.y = y - app->pany + app->image->y;

    ctm = pdfapp_viewctm(app);
    ctm = fz_invertmatrix(ctm);

    p = fz_transformpoint(ctm, p);

    for (link = app->page->links; link; link = link->next)
    {
        if (p.x >= link->rect.x0 && p.x <= link->rect.x1)
            if (p.y >= link->rect.y0 && p.y <= link->rect.y1)
                break;
    }

    if (link)
    {
        wincursor(app, HAND);
        if (btn == 1 && state == 1)
        {
            if (link->kind == PDF_LURI)
                pdfapp_gotouri(app, link->dest);
            else if (link->kind == PDF_LGOTO)
                pdfapp_gotopage(app, link->dest);
            return;
        }
    }
    else
    {
        wincursor(app, ARROW);
    }

    if (state == 1)
    {
        if (btn == 1 && !app->iscopying)
        {
            app->ispanning = 1;
            app->selx = x;
            app->sely = y;
        }
        if (btn == 3 && !app->ispanning)
        {
            kno_clearselect(app); //code change by kakai
            app->iscopying = 1;
            app->selx = x;
            app->sely = y;
            app->selr.x0 = x;
            app->selr.x1 = x;
            app->selr.y0 = y;
            app->selr.y1 = y;
        }
        if (btn == 4 || btn == 5) /* scroll wheel */
        {
            int dir = btn == 4 ? 1 : -1;
            app->ispanning = app->iscopying = 0;
            if (modifiers & (1<<2))
            {
                /* zoom in/out if ctrl is pressed */
                app->zoom += 0.1 * dir;
                if (app->zoom > 3.0)
                    app->zoom = 3.0;
                if (app->zoom < 0.1)
                    app->zoom = 0.1;
                pdfapp_showpage(app, 0, 1);
            }
            else
            {
                /* scroll up/down, or left/right if
                shift is pressed */
                int isx = (modifiers & (1<<0));
                int xstep = isx ? 20 * dir : 0;
                int ystep = !isx ? 20 * dir : 0;
                pdfapp_panview(app, app->panx + xstep, app->pany + ystep);
            }
        }
    }

    else if (state == -1)
    {
        //Code change by Kakai
        //Hit testing
        kno_hitdata *hitdata = kno_gethitdata(app, x, y);
        printf("hit test char is: %c\n", hitdata->ucs);
        //Code change by Kakai
        if (app->iscopying)
        {
            app->iscopying = 0;
            app->selr.x0 = MIN(app->selx, x);
            app->selr.x1 = MAX(app->selx, x);
            app->selr.y0 = MIN(app->sely, y);
            app->selr.y1 = MAX(app->sely, y);
            winrepaint(app);
            if (app->selr.x0 < app->selr.x1 && app->selr.y0 < app->selr.y1)
                windocopy(app);
        }
        if (app->ispanning)
            app->ispanning = 0;
    }

    else if (app->ispanning)
    {
        int newx = app->panx + x - app->selx;
        int newy = app->pany + y - app->sely;
        pdfapp_panview(app, newx, newy);
        app->selx = x;
        app->sely = y;
    }

    else if (app->iscopying)
    {
        app->selr.x0 = MIN(app->selx, x);
        app->selr.x1 = MAX(app->selx, x);
        app->selr.y0 = MIN(app->sely, y);
        app->selr.y1 = MAX(app->sely, y);
        //code change by kakai
        //IsHighlightable and selection testing
        int closestx, closesty;
        closestx = closesty = 0;
        if (kno_ishighlightable(app, x, y, &closestx, &closesty) == 1)
            kno_onselect(app); //code change by kakai
        else
        {
            printf("x is %d\n", closestx);
            printf("y is %d\n", closesty);
        }
        //code change by kakai
        winrepaint(app);
    }

}