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

📄 gvwin.c

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 C
📖 第 1 页 / 共 5 页
字号:
	case WM_GSREDISPLAY:
	    PostMessage(hwnd, WM_COMMAND, IDM_REDISPLAY, 0);
	    return 0;
	case WM_GSTITLE:
	    /* update title */
	    request_mutex();
	    if (psfile.name[0] != '\0') {
		TCHAR buf[256];
		TCHAR fname[MAXSTR];
		convert_multibyte(fname, psfile.name, 
		    sizeof(fname)/sizeof(TCHAR));
		GetFileTitle(fname, buf, (WORD)(sizeof(buf)/sizeof(TCHAR)));
		wsprintf(buf+lstrlen(buf), TEXT(" - %s"), szAppName);
		SetWindowText(hwnd, buf);
	    }
	    else
		SetWindowText(hwnd, szAppName);
	    release_mutex();
	    return 0;
	case WM_GSPERCENT:
	    percent_pending = FALSE;
	    InvalidateRect(hwndimg, (LPRECT)&info_rect, FALSE);
	    UpdateWindow(hwndimg);
	    return 0;
	case WM_GSTEXTINDEX:
#ifndef VIEWONLY
	    make_text_index();
	    text_marking = FALSE;
	    text_mark_first = text_mark_last = -1;
#endif
	    return 0;
	case WM_GSWAIT:
	    info_wait(wParam);
	    return 0;
	case WM_ACTIVATE:
	    {
#ifdef WIN32
	     HWND hwnd_activate = (HWND)lParam;
#else
	     HWND hwnd_activate = (HWND)LOWORD(lParam);
#endif
	    /* We seem to be activated whenever fActive is non-zero
	     * and hwnd_activate == NULL
	     */
	    if ( (LOWORD(wParam) != WA_INACTIVE) &&
		 ( (hwnd_activate == (HWND)NULL) || 
		   (hwnd_activate == hwndimg) ||
		   (hwnd_activate == hwndimgchild) ||
		   (hwnd_activate == hwnd_image)
		 )
               )
	        if (dfchanged() != 0)
		    PostMessage(hwnd, WM_COMMAND, IDM_REDISPLAY, 0);
	    }
	    break;
	case WM_CREATE:
	    hwndimg = hwnd;
	    gsview_create();
	    /* Enable Drag Drop */
	    DragAcceptFiles(hwnd, TRUE);
	    break;
	case WM_CLOSE:
	    quitnow = TRUE;		 	/* exit from nested message loops */
	    pending.unload = TRUE;
	    pending.abort = TRUE;
	    if (multithread)
		SetEvent(display.event);	/* unblock display thread */
	    if (gsdll.state != GS_UNINIT)
		return 0;			/* don't close yet */
	    PostQuitMessage(0);
	    break;
	case WM_DESTROY:
	    /* tell GS DLL to unload */
	    quitnow = TRUE;
	    pending.unload = TRUE;

	    /* disable Drag Drop */
	    DragAcceptFiles(hwnd, FALSE);
	    PostQuitMessage(0);			/* redundant */
	    break;
/*
	case WM_ENDSESSION:
	    if (wParam)
		gsview_close();
	    return 0;
*/
	case WM_DROPFILES:
	    {
		LPSTR szFile;
		HGLOBAL hglobal;
		int i, cFiles, length;
		HDROP hdrop = (HDROP)wParam;
		cFiles = DragQueryFileA(hdrop, 0xffffffff, (LPSTR)NULL, 0);
		for (i=0; i<cFiles; i++) {
		    length = DragQueryFileA(hdrop, i, (LPSTR)NULL, 0);
		    hglobal = GlobalAlloc(GHND | GMEM_SHARE, length+1);
		    if (hglobal) {
			    szFile = (LPSTR)GlobalLock(hglobal);
			    DragQueryFileA(hdrop, i, szFile, MAXSTR);
			    GlobalUnlock(hglobal);
			    /* it doesn't work if we call gsview_display directly */
			    PostMessage(hwnd, WM_COMMAND, IDM_DROP, (LPARAM)hglobal);
		    }
		}
		DragFinish(hdrop);
	    }
	    break;
	case WM_INITMENU:
	    if (hmenu == (HMENU)wParam) {
		HMENU hmenuedit = GetSubMenu(hmenu,1);
		BOOL idle;
		BOOL addeps;
	        idle = (gsdll.state != GS_BUSY);
#ifndef VIEWONLY
		enable_menu_item(IDM_EDITMENU, IDM_COPYCLIP, image.open);
		if (OpenClipboard(hwnd)) {
		    enable_menu_item(IDM_EDITMENU, IDM_PASTETO, IsClipboardFormatAvailable(CF_DIB));
		    enable_menu_item(IDM_EDITMENU, IDM_CONVERT, 
			IsClipboardFormatAvailable(CF_DIB) || 
			IsClipboardFormatAvailable(CF_BITMAP));
		    CloseClipboard();
		}

		/* IDM_ADDEPSMENU */
		addeps =  (psfile.dsc != (CDSC *)NULL) && psfile.dsc->epsf && idle;
		if (addeps) {
		    EnableMenuItem(hmenuedit, 5, MF_BYPOSITION | MF_ENABLED);
		}
		else {
		    EnableMenuItem(hmenuedit, 5, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
		}
		/* Extract EPS sub menu */
		if ( (psfile.preview == IDS_EPST) || (psfile.preview == IDS_EPSW) && idle)
		    EnableMenuItem(hmenuedit, 6, MF_BYPOSITION | MF_ENABLED);
		else
		    EnableMenuItem(hmenuedit, 6, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
		enable_menu_item(IDM_ADDEPSMENU, IDM_MAKEEPSU, addeps);
		addeps =  addeps && image.open;
		enable_menu_item(IDM_ADDEPSMENU, IDM_MAKEEPSI, addeps);
		enable_menu_item(IDM_ADDEPSMENU, IDM_MAKEEPST4, addeps);
		enable_menu_item(IDM_ADDEPSMENU, IDM_MAKEEPST6U, addeps);
		enable_menu_item(IDM_ADDEPSMENU, IDM_MAKEEPST6P, addeps);

		enable_menu_item(IDM_EDITMENU, IDM_PSTOEDIT, idle);
		enable_menu_item(IDM_EDITMENU, IDM_TEXTEXTRACT, idle);
		enable_menu_item(IDM_EDITMENU, IDM_TEXTFIND, idle);
		enable_menu_item(IDM_EDITMENU, IDM_TEXTFINDNEXT, idle);
#endif


#ifndef MEMORYFILE
		/* Recent files */
		{   char buf[MAXSTR];
		    int i;
#ifndef VIEWONLY
		    int offset = 15;
#else
		    int offset = 7;
#endif
		    HMENU hmenufile = GetSubMenu(hmenu,0);
		    RemoveMenu(hmenufile, IDM_LASTFILE1, MF_BYCOMMAND);
		    RemoveMenu(hmenufile, IDM_LASTFILE2, MF_BYCOMMAND);
		    RemoveMenu(hmenufile, IDM_LASTFILE3, MF_BYCOMMAND);
		    RemoveMenu(hmenufile, IDM_LASTFILE4, MF_BYCOMMAND);
		    for (i=last_files_count; i>0; i--) {
		        sprintf(buf, "&%d %s", i, last_files[i-1]);
			if (strlen(buf)>64) {
			    int j;
			    for (j=strlen(buf); j>0; j--)
				if ((buf[j] == '/') || (buf[j] == '\\'))
				    break;
			    if (strlen(buf) - j > 28)
				memmove(buf+3, buf+strlen(buf)+1-30, 30);
			    else {
				buf[5] = buf[6] = buf[7] = '.';
				memmove(buf+8, buf+j, strlen(buf)+1-j);
			    }
			}
			InsertMenuA(hmenufile, offset, MF_BYPOSITION | MF_STRING, IDM_LASTFILE1+i-1, buf);
		    }
		}
#endif /* !MEMORYFILE */
		return 0;
	    }
	    break;
	case WM_COMMAND:
	    request_mutex();
	    if (LOWORD(wParam) == IDM_ARGS) {
		GSVIEW_ARGS *pargs = (GSVIEW_ARGS *)lParam;
#ifndef VIEWONLY
		/* delayed processing of command line arguments */
		if (pargs->print || pargs->convert) {
		    make_cwd(pargs->filename);
		    gsview_selectfile(pargs->filename);
		    if (pargs->device[0]) {
			if (pargs->print)
			    strcpy(option.printer_device, pargs->device);
			else
			    strcpy(option.convert_device, pargs->device);
		    }
		    if ((pargs->queue[0]) && pargs->print)
			strcpy(option.printer_queue, pargs->queue);
		    if (dfreopen() != 0) {
			release_mutex();
		        return 0;
		    }
		    if (psfile.name[0] != '\0') {
		        option.print_to_file = FALSE;
		        gsview_print(!pargs->print);
		    }
		    dfclose();
		}
		else if (pargs->spool) {
		    if (*pargs->filename) {
			gs_addmess("Spooling \042");
			gs_addmess(pargs->filename);
			gs_addmess("\042 to printer \042");
			if (pargs->queue)
			    gs_addmess(pargs->queue);
			gs_addmess("\042\n");
			gsview_spool(pargs->filename, pargs->queue);
			gsview_command(IDM_EXIT);
			break;
		    }
		}
		else  
#endif
		if (pargs->filename[0]) {
		    make_cwd(pargs->filename);
		    gsview_displayfile(pargs->filename);
		}
	    }
	    else if (LOWORD(wParam) == IDM_DROP) {
		LPSTR szFile = (LPSTR)GlobalLock((HGLOBAL)lParam);
		make_cwd(szFile);
		gsview_displayfile(szFile);
		GlobalUnlock((HGLOBAL)lParam);
		GlobalFree((HGLOBAL)lParam);
	    }
	    else {
		if (GetNotification(wParam,lParam) != BN_DOUBLECLICKED) {
		    if (hDlgModeless) {
			play_sound(SOUND_ERROR);
			release_mutex();
			return 0;	/* obtaining Bounding Box so ignore commands */
		    }
#ifdef NOTUSED
		    if (gsdll.state == GS_BUSY) {
			/* With DLL, more than the following will be safe */
			switch(LOWORD(wParam)) {
			    case IDM_INFO:
			    case IDM_CLOSE_DONE:
			    case IDM_SAVEDIR:
			    case IDM_SETTINGS:
			    case IDM_SAVESETTINGS:
			    case IDM_SOUNDS:
			    case IDM_HELPCONTENT:
			    case IDM_HELPSEARCH:
			    case IDM_ABOUT:
			    case IDM_GSMESS:
			    case IDM_EXIT:
				/* these are safe to use when busy */
				break;
			    default:
				play_sound(SOUND_ERROR);
				release_mutex();
				return 0;	/* Command not permitted now */
			}
		    }
#endif
		    gsview_command(LOWORD(wParam));
		}
	    }
	    release_mutex();
	    return 0;
	case WM_KEYDOWN:
	case WM_KEYUP:
	    end_button_help();
	    /* pass on key presses so that child window scroll bars work */
	    SendMessage(hwnd_image, message, wParam, lParam);
	    return 0;
	case WM_SIZE:
	    /* make child window fill client area */
	    {
	    int cx, cy;
	    calc_info_button_areas(LOWORD(lParam), HIWORD(lParam));
	    cx = LOWORD(lParam)-img_offset.x;
	    cy = info_rect.top - img_offset.y;
	    if ((wParam != SIZE_MINIMIZED) && hwndimgchild !=(HWND)NULL)
		SetWindowPos(hwndimgchild, (HWND)NULL, 
		    img_offset.x, img_offset.y, cx, cy, 
		    SWP_NOZORDER | SWP_NOACTIVATE);
	    /* save window size for INIFILE */
	    if (wParam == SIZE_RESTORED) {
		    GetWindowRect(hwnd,&rect);
		    option.img_size.x = rect.right-rect.left;
		    option.img_size.y = rect.bottom-rect.top;
	    }
	    if (IsWindowVisible(hwnd))
		option.img_max = (wParam == SIZE_MAXIMIZED);
	    }
	    return 0;
	case WM_MOVE:
	    /* save window position for INIFILE */
	    if (!IsIconic(hwnd) && !IsZoomed(hwnd)) {
		    GetWindowRect(hwnd,&rect);
		    option.img_origin.x = rect.left;
		    option.img_origin.y = rect.top;
	    }
	    return 0;
	case WM_SETCURSOR:
	    /* if waiting, display hourglass cursor over our window */
	    if (szWait[0] != '\0') {
		if (in_child_client_area()) {
		    SetCursor(hcWait);
		    return TRUE;
		}
	    }
	    /* track cursor and display coordinates if in child window */
	    if (image.open) {
		float x, y;
		if (in_child_client_area() || prev_in_child) {
		    /* update coordinate info */
		    HFONT old_hfont;
		    HDC hdc = GetDC(hwnd);
		    if (info_font)
			old_hfont = (HFONT)SelectObject(hdc, info_font);
		    cursorpos_paint(hdc);
		    if (info_font)
			SelectObject(hdc, old_hfont);
		    ReleaseDC(hwnd, hdc);
		}
		prev_in_child = in_child_client_area();
		if (get_cursorpos(&x, &y)) {
		    PDFLINK link;
		    info_link();
		    if (is_link(x, y, &link)) {
			SetCursor(hcHand);
		        return TRUE;
		    }
		}
	    }
	    break;
	case WM_PARENTNOTIFY:
/*
	    if (wParam == WM_LBUTTONDOWN) {
		if (hDlgModeless && in_child_client_area())
		    SendMessage(hDlgModeless, WM_COMMAND, BB_CLICK, lParam);
		return 0;
	    }
*/
	    if (wParam == WM_RBUTTONDOWN) {
		float x, y;
		RECT rect;
		int zwidth, zheight;
		if (hDlgModeless) {
		    play_sound(SOUND_BUSY);
		    break;
		}
		request_mutex();
		GetWindowRect(hwnd_image,&rect);
		if (get_cursorpos(&x, &y)) {
		    int scrollx, scrolly;
		    zoom = !zoom;
		    display.zoom_xoffset = (int)x;
		    display.zoom_yoffset = (int)y;
		    scrollx = bitmap.scrollx;
		    scrolly = bitmap.scrolly;
		    if (rect.right - rect.left > image.width)
		        zwidth = image.width;
		    else
		        zwidth = rect.right - rect.left;
		    if (rect.bottom - rect.top > image.height)
		        zheight = image.height;
		    else
		        zheight = rect.bottom - rect.top;
		    x = (float)((scrollx + zwidth/2)*72.0/option.xdpi);
		    y = (float)(((image.height-1) - 
			(scrolly + zheight/2))*72.0/option.ydpi);
		    transform_point(&x, &y);
		    x = (float)(x * option.xdpi/72.0);
		    y = (float)(y * option.ydpi/72.0);
		    display.zoom_xoffset -= (int)(x*72.0/option.zoom_xdpi);
		    display.zoom_yoffset -= (int)(y*72.0/option.zoom_ydpi);
		}
		else {
		    zoom = FALSE;
		}
		release_mutex();
		PostMessage(hwndimg, WM_COMMAND, IDM_ZOOM, (LPARAM)0);
	    }
	    break;
	case WM_SYSCOLORCHANGE:
	    system_colours();
	    break;
	case WM_PAINT:
	    {
	    HDC hdc;
	    PAINTSTRUCT ps;
	    hdc = BeginPaint(hwnd, &ps);
	    /* draw info area at bottom */
	    info_paint(hwnd, hdc);
	    /* buttons at top */
	    /* draw button background */
	    GetClientRect(hwnd, &rect);
	    rect.top = button_rect.top;
	    rect.left = button_rect.left;
	    rect.bottom = button_rect.bottom;
	    if (rect.bottom - rect.top > 2)
		FillRect(hdc, &rect, hbrush_menu);
	    SelectPen(hdc, hpen_btnshadow);
	    MoveTo(hdc, rect.left, rect.top);
	    LineTo(hdc, rect.right, rect.top);

	    if (rect.bottom - rect.top > 2) {
		MoveTo(hdc, rect.left, rect.bottom);
		LineTo(hdc, rect.right, rect.bottom);
		SelectPen(hdc, hpen_btnhighlight);
		MoveTo(hdc, rect.left, rect.top+1);
		LineTo(hdc, rect.right, rect.top+1);
	    }
	    EndPaint(hwnd, &ps);
	    }
	    return 0;
	case WM_MEASUREITEM:
	    return 1;
	case WM_DRAWITEM:
	    return draw_button((DRAWITEMSTRUCT FAR *)lParam);
    }
    return DefWindowProc(hwnd, message, wParam, lParam);
}

⌨️ 快捷键说明

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