⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gvwin.c

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 C
📖 第 1 页 / 共 5 页
字号:
			RECT rect;
			SYSTEMTIME t1, t2;
			int td;
			int tx1 = HIBYTE(HIWORD(wParam));
			int ty1 = LOBYTE(HIWORD(wParam));
			int tx2 = HIBYTE(LOWORD(wParam));
			int ty2 = LOBYTE(LOWORD(wParam));
			rect.left = (tx1 * image.tile_width) 
			    + display.offset.x - nHscrollPos;
			rect.right = rect.left + 
				(tx2 - tx1 + 1) * image.tile_width + 1;
			rect.top = 
			    (image.height - 1 - ((ty2+1) * image.tile_height)) 
			    + display.offset.y - nVscrollPos + 1;
			rect.bottom =  rect.top +
			    (ty2 - ty1 + 1) * image.tile_height + 1;
			GetSystemTime(&t1);
		        image_unlock(&image);
			InvalidateRect(hwnd, &rect, FALSE);
		        UpdateWindow(hwnd);
			GetSystemTime(&t2);
			/* make sure we don't spend too long doing updates */
			td = (t2.wHour - t1.wHour) * 3600000 + 
			    (t2.wMinute - t1.wMinute ) * 60000 +
			    (t2.wSecond - t1.wSecond ) * 1000 + 
			    (t2.wMilliseconds - t1.wMilliseconds);
			image_lock(&image);
			if (image.open && (td * 5 > image.tile_interval)) {
			    /* Backup off time and require to be done
			     * between updates.
			     */
			    image.tile_interval += td + 100;
			    image.tile_verydirty_threshold += 256;
			    image.tile_threshold += image.tile_threshold;
			}
		        image_unlock(&image);
		    }
		    else {
		        image_unlock(&image);
		    }
		    break;
	    case WM_PAINT:
		    if (quitnow) {
			hdc = BeginPaint(hwnd, &ps);
			rect = ps.rcPaint;
			FillRect(hdc, &rect, hbrush_window);
			EndPaint(hwnd, &ps);
			return 0;
		    }
		    image_lock(view.img);
		    request_mutex();
		    {
		    int wx,wy;
		    RECT source, dest, fillrect;
		    CDSC *dsc = psfile.dsc;
		    HBRUSH hbrush = hbrush_window;
		    hdc = BeginPaint(hwnd, &ps);
		    rect = ps.rcPaint;
		    SetMapMode(hdc, MM_TEXT);
		    SetBkMode(hdc,OPAQUE);
		    if (hwnd == hwnd_fullscreen)
			hbrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
		    if (image.open && 
			    (image.width > 1) && (image.height > 1)) {

			wx = rect.right-rect.left; /* width */
			wy = rect.bottom-rect.top;
			if (rect.left < display.offset.x)
				source.left = 0;
			else
				source.left = rect.left - display.offset.x + nHscrollPos;
			if (rect.top < display.offset.y)
				source.top = 0;
			else
				source.top = rect.top - display.offset.y + nVscrollPos;
			if (source.left > image.width)
				source.left = image.width;
			if (source.left + wx > image.width)
				wx = image.width - source.left;
			source.right = source.left + wx;
			if (source.top > image.height)
				source.top = image.height;
			if (source.top + wy > image.height)
				wy = image.height - source.top;
			source.bottom = source.top + wy;

			if (rect.left < display.offset.x)
				dest.left = display.offset.x;
			else
				dest.left = rect.left;
			if (rect.top < display.offset.y)
				dest.top = display.offset.y;
			else
				dest.top = rect.top;
			dest.right = dest.left + wx;
			dest.bottom = dest.top + wy;
			    
			if (wx && wy) {
			    image_draw(&image, hdc, dest.left, dest.top,
				wx, wy, source.left, source.top);
			}
			/* Fill areas around page */
			/* not sure if display.offset.y is from top or bottom */
			/* code here assumes top (opposite to OS/2) */
			if (rect.bottom > image.height + display.offset.y) {	/* bottom centre */
			    fillrect.bottom = rect.bottom; 
			    fillrect.top = image.height + display.offset.y;
			    fillrect.left = dest.left;
			    fillrect.right = dest.right;
			    FillRect(hdc, &fillrect, hbrush);
			}
			if (rect.top < display.offset.y) { /* top centre */
			    fillrect.bottom = display.offset.y;
			    fillrect.top = rect.top;
			    fillrect.left = dest.left;
			    fillrect.right = dest.right;
			    FillRect(hdc, &fillrect, hbrush);
			}
			if (rect.left < display.offset.x) { /* left */
			    fillrect.bottom = rect.bottom;
			    fillrect.top = rect.top;
			    fillrect.left = rect.left;
			    fillrect.right = display.offset.x;
			    FillRect(hdc, &fillrect, hbrush);
			}
			if (rect.right > image.width + display.offset.x) { /* right */
			    fillrect.bottom = rect.bottom;
			    fillrect.top = rect.top;
			    fillrect.left = image.width + display.offset.x;
			    fillrect.right = rect.right;
			    FillRect(hdc, &fillrect, hbrush);
			}
		    }
		    else {
			FillRect(hdc, &rect, hbrush);
		    }
		    /* draw bounding box */
		    if (image.open && (dsc != (CDSC *)NULL) &&
			(dsc->bbox != (CDSCBBOX *)NULL) &&
			option.show_bbox) {
			float x, y;
			HPEN hpen, hpen_old;
			/* map bounding box to device coordinates */
			x = (float)dsc->bbox->llx;
			y = (float)dsc->bbox->lly;
			map_pt_to_pixel(&x, &y);
			rect.left   = (int)x;
			rect.bottom = (int)y;
			x = (float)dsc->bbox->urx;
			y = (float)dsc->bbox->ury;
			map_pt_to_pixel(&x, &y);
			rect.right  = (int)x;
			rect.top    = (int)y;

			hpen = CreatePen(PS_DOT, 1, RGB(0,0,0));
			hpen_old = SelectPen(hdc, hpen);
			SelectPen(hdc, hpen);
			SetROP2(hdc, R2_XORPEN);
			MoveTo(hdc, rect.left, rect.bottom);
			LineTo(hdc, rect.right, rect.bottom);
			LineTo(hdc, rect.right, rect.top);
			LineTo(hdc, rect.left, rect.top);
			LineTo(hdc, rect.left, rect.bottom);
			SetROP2(hdc, R2_COPYPEN);
			SelectPen(hdc, hpen_old);
			DeletePen(hpen);
		    }
		    /* highlight found search word */
		    if (image.open && display.show_find) {
			float x, y;
			/* map bounding box to device coordinates */
			x = (float)psfile.text_bbox.llx;
			y = (float)psfile.text_bbox.lly;
			map_pt_to_pixel(&x, &y);
			rect.left   = (int)x;
			rect.bottom = (int)y;
			x = (float)psfile.text_bbox.urx;
			y = (float)psfile.text_bbox.ury;
			map_pt_to_pixel(&x, &y);
			rect.right  = (int)x;
			rect.top    = (int)y;
			if (rect.top > rect.bottom) {
			    int temp = rect.top;
			    rect.top = rect.bottom;
			    rect.bottom = temp;
			}

			/* invert text */
			InvertRect(hdc, &rect);

		    }

#ifndef VIEWONLY
		    /* highlight marked words */
		    highlight_words(hdc, text_mark_first, text_mark_last);
#endif

		    /* GS 6.50 highlights links itself for PDF files */
		    if ((option.gsversion < 650) || !psfile.ispdf)
			highlight_links(hdc);

		    EndPaint(hwnd, &ps);
		    release_mutex();
		    if (hwnd == hwnd_fullscreen)
			SetCursor(NULL);
		    image_unlock(view.img);
		    return 0;
		    }
    }

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

#ifndef WM_MOUSEWHEEL
#define WM_MOUSEWHEEL 0x020A
#define WHEEL_DELTA 120
#endif

/* parent overlapped window */
LRESULT CALLBACK _export
WndImgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT rect;

    if (message == help_message) {
#ifdef USE_HTMLHELP
/* should be able to do this with keyword lookup instead */
	TCHAR buf[MAXSTR];
	lstrcpy(buf, TEXT("html/"));
	load_string(nHelpTopic, buf+5, sizeof(buf)/sizeof(TCHAR)-6);
	int i;
	for (i=0; buf[i]; i++)
	    if (buf[i] == ' ')
		buf[i] = '_';
	lstrcat(buf, TEXT(".htm"));
	HtmlHelp(hwndimg,szHelpName,HH_DISPLAY_TOPIC,(DWORD)buf);
char strh[MAXSTR];
char strb[MAXSTR];
convert_widechar(strh, szHelpName, sizeof(strh)-1);
convert_widechar(strb, buf, sizeof(strh)-1);
gs_addmessf("HtmlHelp: %s HH_DISPLAY_TOPIC %s\n", strh, strb);
#else
	TCHAR buf[MAXSTR];
	load_string(nHelpTopic, buf, sizeof(buf)/sizeof(TCHAR)-1);
	WinHelp(hwndimg,szHelpName,HELP_KEY,(DWORD)buf);
#endif
	return 0;
    } else
    switch(message) {
	case WM_MOUSEWHEEL:
	    /* If Wheel Mice become available with a step size < WHEEL_DELTA,
	     * this code will need to be rewritten */
	    if (LOWORD(wParam) == MK_SHIFT) {
		/* change page */
		int numpages = 0;
		int skip = HIWORD(wParam);
		if (skip > 0x7fff)
		   skip = skip - 0x10000L;
		skip = -skip / WHEEL_DELTA;
		request_mutex();
		if (psfile.dsc != (CDSC *)NULL)
		    numpages = psfile.dsc->page_count;
		release_mutex();
	    
		if ( (skip < 0)  && 
		     (psfile.dsc != (CDSC *)NULL) && 
		     (psfile.pagenum != 1)) {
			PostMessage(hwnd ,WM_VSCROLL, SB_BOTTOM,0L);
			gs_page_skip(skip);
		}
		else if ( (skip > 0) && 
		    ((psfile.dsc == (CDSC *)NULL)
		    || (psfile.pagenum < numpages)) ) {
			PostMessage(hwnd ,WM_VSCROLL, SB_TOP,0L);
			if (psfile.dsc == (CDSC *)NULL)
			    skip = 1;
			gs_page_skip(skip);
		}
	    }
	    else if (LOWORD(wParam) ==  MK_CONTROL) {
		float scale = 1.0;
		int scroll_increment;
		scroll_increment = HIWORD(wParam);
		if (scroll_increment > 0x7fff)
		    scroll_increment -= 0x10000L;
		scroll_increment = -scroll_increment;
		if (scroll_increment > 0) {
		    while (scroll_increment > 0) {
			scale = (float)(scale * 1.20);
			scroll_increment -= WHEEL_DELTA;
		    }
		    gs_magnify(scale);
		}
		else if (scroll_increment < 0) {
		    while (scroll_increment < 0) {
			scale = (float)(scale/1.20);
			scroll_increment += WHEEL_DELTA;
		    }
		    gs_magnify(scale);
		}
	    }
	    else if (LOWORD(wParam) == MK_LBUTTON) {
		/* horizontal scroll */
		int scroll_increment;
		GetClientRect(hwnd, &rect);
		scroll_increment = HIWORD(wParam);
		if (scroll_increment > 0x7fff)
		    scroll_increment -= 0x10000L;
		scroll_increment = -scroll_increment 
		    * ((rect.right-rect.left)/16)
		    / WHEEL_DELTA;
		PostMessage(hwnd_image, WM_HSCROLL, 
		    MAKELONG(SB_FIND, scroll_increment), 0);
	    }
	    else {
		/* vertical scroll */
		int scroll_increment;
		GetClientRect(hwnd, &rect);
		scroll_increment = HIWORD(wParam);
		if (scroll_increment > 0x7fff)
		    scroll_increment -= 0x10000L;
		scroll_increment = -scroll_increment
		    * ((rect.bottom-rect.top)/16) 
		    / WHEEL_DELTA;
		PostMessage(hwnd_image, WM_VSCROLL, 
		    MAKELONG(SB_FIND, scroll_increment), 0);
	    }
	    return 0;
	case WM_GSV16SPL:
	    hwndspl = (HWND)lParam;	   /* gsv16spl.c window handle */
	    return 0;
	case WM_GSDEVICE:
	    if (fullscreen)	/* don't flash between pages */
		return 0;
	    /* hide window if closed */
	    if (!image.open) {
		ShowWindow(hwndimgchild, SW_HIDE);
		if (fullscreen) 
		    ShowWindow(hwnd_fullscreen, SW_HIDE);
	    }
	    bitmap.changed = TRUE;
	    return 0;
	case WM_GSSIZE:
	    if (image.open) {
		/* bitmap has changed */
		update_scroll_bars();
	    }
	    return 0;
	case WM_GSSYNC:
	    if (debug & DEBUG_GENERAL)
		gs_addmess("WM_GSSYNC\n");
	    hwnd_image = fullscreen ? hwnd_fullscreen : hwndimgchild;
	    if ( fullscreen &&
		(!IsWindowVisible(hwnd_fullscreen) || bitmap.changed) &&
		(image.width > 1) && (image.height > 1)) {
		SetFocus(hwndimg);
		ShowWindow(hwndimgchild, SW_HIDE);
		ShowWindow(hwnd_fullscreen, SW_SHOWNA);
		update_scroll_bars();
		bitmap.changed = FALSE;
	    }
	    else if ( (!IsWindowVisible(hwndimgchild) || bitmap.changed) &&
		(image.width > 1) && (image.height > 1)) {
		ShowWindow(hwndimgchild, SW_SHOWNA);
		update_scroll_bars();
		bitmap.changed = FALSE;
	    }
	    if ( !IsIconic(hwndimg) && !fullscreen) {  /* redraw child window */
		if (image.open) {
		    /* don't erase background - the bitmap will cover it anyway */
		    InvalidateRect(hwnd_image, (LPRECT)NULL, FALSE);
		    UpdateWindow(hwnd_image);
		}
	    }
	    return 0;
	case WM_GSPAGE:
	    if (debug & DEBUG_GENERAL)
		gs_addmess("WM_GSPAGE\n");
	    hwnd_image = fullscreen ? hwnd_fullscreen : hwndimgchild;
	    if ( fullscreen &&
		(!IsWindowVisible(hwnd_fullscreen) || bitmap.changed) &&
		(image.width > 1) && (image.height > 1)) {
		SetFocus(hwndimg);
		ShowWindow(hwndimgchild, SW_HIDE);
		ShowWindow(hwnd_fullscreen, SW_SHOWNA);
		update_scroll_bars();
		bitmap.changed = FALSE;
	    }
	    else if ( (!IsWindowVisible(hwndimgchild) || bitmap.changed) &&
		(image.width > 1) && (image.height > 1)) {
		ShowWindow(hwndimgchild, SW_SHOWNA);
		update_scroll_bars();
		bitmap.changed = FALSE;
	    }
	    /* showpage has just been called */
	    play_sound(SOUND_PAGE);
	    if (IsIconic(hwndimg))    /* useless as an Icon so fix it */
		ShowWindow(hwndimg, SW_SHOWNORMAL);
	    if ( !IsIconic(hwndimg) ) {  /* redraw child window */
		if (image.open) {
		    if (display.show_find) {
			scroll_to_find();
		    }
		    /* don't erase background - the bitmap will cover it anyway */
		    InvalidateRect(hwnd_image, (LPRECT)NULL, FALSE);
		    UpdateWindow(hwnd_image);
		}
	    }
	    info_link();
	    return 0;
	case WM_GSTILE:
	    /* Must post this to the image window, since only it has 
	     * the scroll position
	     */
	    if (debug & DEBUG_GENERAL)
		gs_addmess("WM_GSTILE\n");
	    hwnd_image = fullscreen ? hwnd_fullscreen : hwndimgchild;
	    if ( !IsIconic(hwndimg) && image.open && !fullscreen)
	    	    PostMessage(hwnd_image, WM_GSTILE, wParam, lParam);
	    return 0;
	case WM_GSMESSBOX:
	    /* delayed message box, usually from other thread */
	    {TCHAR buf[MAXSTR];
	    load_string((int)wParam, buf, sizeof(buf)/sizeof(TCHAR));
	    message_box(buf, (int)lParam);
	    }
	    return 0;
	case WM_GSSHOWMESS:
	    /* delayed message box, usually from other thread */
	    /* delayed show message, usually from other thread */
	    gs_showmess();
	    return 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -