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

📄 gvpprn.c

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 C
📖 第 1 页 / 共 4 页
字号:
	if (mp1 == MPFROM2SHORT(DEVICE_NAME, CBN_LBSELECT)) {
	    idevice = (int)WinSendMsg(WinWindowFromID(hwnd, DEVICE_NAME), 
		LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), (MPARAM)0);
	    if (idevice == LIT_NONE)
		return FALSE;
	    WinSendMsg(WinWindowFromID(hwnd, DEVICE_NAME), LM_QUERYITEMTEXT,  
		MPFROM2SHORT(idevice, sizeof(entry)), MPFROMP(entry));
	    if ( (proplist = get_properties(entry)) 
		!= (struct prop_item_s *)NULL ) {
		free((char *)proplist);
		WinEnableWindow(WinWindowFromID(hwnd, DEVICE_PROP), TRUE);
	    }
	    else
		WinEnableWindow(WinWindowFromID(hwnd, DEVICE_PROP), FALSE);
	    /* now look up entry in gvpm.ini */
	    /* and update DEVICE_RES list box */
	    {PROFILE *prf;
	     char section[MAXSTR];
/* need to reopen profile file - this is wasteful */
	      if ( (prf = profile_open(szIniFile)) != (PROFILE *)NULL ) {
		/* update printer options */
		strcpy(section, entry);
		strcat(section, " Options");
		profile_read_string(prf, section, "Options", "", 
			buf, sizeof(buf)-2);
		WinSetWindowText(WinWindowFromID(hwnd, DEVICE_OPTIONS), 
			(PCSZ)buf);
		/* now look up resolutions */
		profile_read_string(prf, 
		    bConvert ? CONVERTSECTION : DEVSECTION, 
		    entry, "", buf, sizeof(buf)-2);
		profile_close(prf);
	      }
	      else
		buf[0] = '\0';
	    }
	    while ((*buf) && (buf[strlen(buf)-1]==' '))
	    buf[strlen(buf)-1] = '\0';    /* remove trailing spaces */
	    buf[strlen(buf)+1] = '\0';	/* double NULL at end */
	    WinSendMsg(WinWindowFromID(hwnd, DEVICE_RES), LM_DELETEALL, 
		(MPARAM)0, (MPARAM)0);
	    p = buf;
	    if (p==(char *)NULL || *p == '\0') {
		/* no resolutions can be set */
		WinEnableWindow(WinWindowFromID(hwnd, DEVICE_RES), FALSE);
		WinEnableWindow(WinWindowFromID(hwnd, DEVICE_RESTEXT), FALSE);
	    }
	    else {
	      WinEnableWindow(WinWindowFromID(hwnd, DEVICE_RES), TRUE);
	      WinEnableWindow(WinWindowFromID(hwnd, DEVICE_RESTEXT), TRUE);
	      while (p && *p!='\0') {
		res = p;
		while ((*p!='\0') && (*p!=','))
		    p++;
		*p++ = '\0';
		WinSendMsg( WinWindowFromID(hwnd, DEVICE_RES),
		    LM_INSERTITEM, MPFROMLONG(LIT_END), MPFROMP(res) );
	      }
	    }
	    WinSendMsg( WinWindowFromID(hwnd, DEVICE_RES),
		LM_SELECTITEM, MPFROMLONG(0), MPFROMLONG(TRUE) );
	    if ((int)WinSendMsg(WinWindowFromID(hwnd, DEVICE_RES), 
		LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), (MPARAM)0)
		    != LIT_NONE)
		WinSetWindowText(WinWindowFromID(hwnd, DEVICE_RES), (PCSZ)buf);
	}
	switch (SHORT2FROMMP(mp1)) {
	    case LN_ENTER:
		if (SHORT1FROMMP(mp1) == PAGE_LIST)
		    WinPostMsg(hwnd, WM_COMMAND, (MPARAM)DID_OK, 
			MPFROM2SHORT(CMDSRC_OTHER, TRUE));
		if (SHORT1FROMMP(mp1) == SPOOL_PORT)
		    WinPostMsg(hwnd, WM_COMMAND, (MPARAM)DID_OK, 
			MPFROM2SHORT(CMDSRC_OTHER, TRUE));
		break;
	    case BN_CLICKED:
	       if (SHORT1FROMMP(mp1) == SPOOL_TOFILE) {
		    i = (int)WinSendMsg( WinWindowFromID(hwnd, SPOOL_TOFILE),
		    BM_QUERYCHECK, MPFROMLONG(0), MPFROMLONG(0));
		    /* toggle state */
		    i = (i == 0) ? 1 : 0;
		    WinSendMsg( WinWindowFromID(hwnd, SPOOL_TOFILE),
			BM_SETCHECK, MPFROMLONG(i), MPFROMLONG(0));
		    if (i) {  /* save selection */
			device_queue_index = (int)WinSendMsg(WinWindowFromID(
			   hwnd, SPOOL_PORT), LM_QUERYSELECTION, 
			    MPFROMSHORT(LIT_FIRST), (MPARAM)0);
		    }
		    WinSendMsg( WinWindowFromID(hwnd, SPOOL_PORT),
			LM_SELECTITEM, MPFROMLONG(device_queue_index), 
			MPFROMLONG(i ? FALSE : TRUE));
		    WinEnableWindow(WinWindowFromID(hwnd, SPOOL_PORTTEXT), 
			(i ? FALSE : TRUE) );
		    WinEnableWindow(WinWindowFromID(hwnd, SPOOL_PORT), 
			(i ? FALSE : TRUE) );
		    
	       }
	       else if (SHORT1FROMMP(mp1) == DEVICE_PSPRINT) {
		    i = (int)WinSendMsg( WinWindowFromID(hwnd, DEVICE_PSPRINT),
		    BM_QUERYCHECK, MPFROMLONG(0), MPFROMLONG(0));
		    /* toggle state */
		    i = (i == 0) ? 1 : 0;
		    WinSendMsg( WinWindowFromID(hwnd, DEVICE_PSPRINT),
			BM_SETCHECK, MPFROMLONG(i), MPFROMLONG(0));
		    i = !i;
		    WinEnableWindow(WinWindowFromID(hwnd, DEVICE_NAMETEXT), i);
		    WinEnableWindow(WinWindowFromID(hwnd, DEVICE_NAME), i);
		    WinEnableWindow(WinWindowFromID(hwnd, DEVICE_OPTIONSTEXT), i);
		    WinEnableWindow(WinWindowFromID(hwnd, DEVICE_OPTIONS), i);
		    WinEnableWindow(WinWindowFromID(hwnd, DEVICE_UNIPRINT), i);
		    WinEnableWindow(WinWindowFromID(hwnd, DEVICE_ADVPS), !i);
		    if (i)
			WinSendMsg(hwnd, WM_CONTROL, 
			    MPFROM2SHORT(DEVICE_NAME, CBN_LBSELECT),
			    MPFROMLONG(WinWindowFromID(hwnd, DEVICE_NAME)));
		    else 
			WinEnableWindow(WinWindowFromID(hwnd, DEVICE_RESTEXT), 
				i);
			WinEnableWindow(WinWindowFromID(hwnd, DEVICE_RES), i);
		    WinEnableWindow(WinWindowFromID(hwnd, DEVICE_PROP), i);
		    if (!i && (int)WinSendMsg( 
			WinWindowFromID(hwnd, SPOOL_TOFILE),
			BM_QUERYCHECK, MPFROMLONG(0), MPFROMLONG(0)) )
			WinSendMsg(hwnd, WM_CONTROL, MPFROM2SHORT(SPOOL_TOFILE,
			    BN_CLICKED), MPFROMLONG(0));
		    WinEnableWindow(WinWindowFromID(hwnd, SPOOL_TOFILE), i);
		}
	    }
	    return FALSE;
      case WM_COMMAND:
	switch(LOUSHORT(mp1)) {
	    case DID_OK:
		/* save device name and resolution */
		if (bConvert) {
		    WinQueryWindowText(WinWindowFromID(hwnd, DEVICE_NAME), 
			 sizeof(option.convert_device)-1, 
			(PBYTE)(option.convert_device));
		    WinQueryWindowText(WinWindowFromID(hwnd, DEVICE_RES), 
			sizeof(option.convert_resolution)-1, 
			(PBYTE)(option.convert_resolution));
		}
		else {
		    WinQueryWindowText(WinWindowFromID(hwnd, DEVICE_NAME), 
			 sizeof(option.printer_device)-1, 
			(PBYTE)(option.printer_device));
		    WinQueryWindowText(WinWindowFromID(hwnd, DEVICE_RES), 
			sizeof(option.printer_resolution)-1, 
			(PBYTE)(option.printer_resolution));
		    /* get PostScript Printer state */
		    option.print_method = (int)WinSendMsg( 
			WinWindowFromID(hwnd, DEVICE_PSPRINT),
			BM_QUERYCHECK, MPFROMLONG(0), MPFROMLONG(0))
			? PRINT_PS : PRINT_GS;
		    /* get Print to File state */
		    option.print_to_file = (int)WinSendMsg( 
			WinWindowFromID(hwnd, SPOOL_TOFILE),
			BM_QUERYCHECK, MPFROMLONG(0), MPFROMLONG(0));
		    if (!option.print_to_file) {
			/* save queue name */
			device_queue_index = 1+(int)WinSendMsg(
			    WinWindowFromID(hwnd, SPOOL_PORT), 
			    LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), 
			    (MPARAM)0);
			p = device_queue_list;
			for (i=2; i<device_queue_index+device_queue_index && 
				  strlen(p)!=0; i++)
			    p += strlen(p)+1;
			strcpy(option.printer_queue, p);
		    }
		}
		/* Fixed Media */
		option.print_fixed_media = (int)WinSendMsg( 
		    WinWindowFromID(hwnd, DEVICE_FIXEDMEDIA),
		    LM_QUERYSELECTION, MPFROMLONG(LIT_FIRST), MPFROMLONG(0));
		/* save pages numbers */
		if ( (psfile.dsc != (CDSC *)NULL) 
		    && (psfile.dsc->page_count != 0)) {
		    PageMultiDlgProc(hwnd, msg, mp1, mp2);
		    option.print_reverse = psfile.page_list.reverse;
		}

		/* get options */
		{PROFILE *prf;
		  char section[MAXSTR];
		  if ( (prf = profile_open(szIniFile)) != (PROFILE *)NULL ) {
/* need to reopen profile file - this is wasteful */
		    /* update printer options */
		    strcpy(section, bConvert ? option.convert_device :
				option.printer_device);
		    strcat(section, " Options");
		    WinQueryWindowText(WinWindowFromID(hwnd, DEVICE_OPTIONS), 
			sizeof(buf), (PBYTE)buf);
		    profile_write_string(prf, section, "Options", buf);
		    profile_close(prf);
		  }
		}
		WinDismissDlg(hwnd, DID_OK);
		return (MRESULT)TRUE;
	    case ID_HELP:
		get_help();
		return (MRESULT)TRUE;
	    case DEVICE_UNIPRINT:
		WinQueryWindowText(WinWindowFromID(hwnd, DEVICE_NAME), 
		     sizeof(buf), (PBYTE)buf);
		if (strcmp(buf, "uniprint") != 0) {
		  /* select uniprint device */
		    i = (int)WinSendMsg( WinWindowFromID(hwnd, DEVICE_NAME),
			LM_SEARCHSTRING, 
			MPFROM2SHORT(LSS_CASESENSITIVE, LIT_FIRST),
			MPFROMP("uniprint") );
		    if ((i == LIT_ERROR) || (i == LIT_NONE)) {
			play_sound(SOUND_ERROR);
			return FALSE;	/* can't select uniprint */
		    }
		    WinSendMsg( WinWindowFromID(hwnd, DEVICE_NAME),
			LM_SELECTITEM, 
			MPFROMLONG(i), MPFROMLONG(TRUE) );
		    /* force update of DEVICE_RES */
		    WinSendMsg(hwnd, WM_CONTROL, 
			MPFROM2SHORT(DEVICE_NAME, CBN_LBSELECT),
			MPFROMLONG(WinWindowFromID(hwnd, DEVICE_NAME)));
		}
		nHelpTopic = IDS_TOPICPRINT;
		WinDlgBox(HWND_DESKTOP, hwnd, UniDlgProc, hlanguage, 
		    IDD_UNIPRINT, NULL);
		return (MRESULT)TRUE;
	    case DEVICE_ADVPS:
		nHelpTopic = IDS_TOPICPRINT;
		WinDlgBox(HWND_DESKTOP, hwnd, AdvPSDlgProc, hlanguage, 
		    IDD_ADVPS, NULL);
		return (MRESULT)TRUE;
	    case PAGE_ALL:
	    case PAGE_EVEN:
	    case PAGE_ODD:
		return (MRESULT)PageMultiDlgProc(hwnd, msg, mp1, mp2);
	    case DEVICE_PROP:
		idevice = (int)WinSendMsg(WinWindowFromID(hwnd, DEVICE_NAME), 
		    LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), (MPARAM)0);
		if (idevice == LIT_NONE)
		    return (MRESULT)TRUE;
		WinSendMsg(WinWindowFromID(hwnd, DEVICE_NAME), 
		    LM_QUERYITEMTEXT,  MPFROM2SHORT(idevice, sizeof(entry)), 
		    MPFROMP(entry));
		if ( (proplist = get_properties(entry)) != (struct prop_item_s *)NULL ) {
			free((char *)proplist);
			nHelpTopic = IDS_TOPICPROP;
			WinDlgBox(HWND_DESKTOP, hwnd, PropDlgProc, hlanguage, IDD_PROP, entry);
			nHelpTopic = IDS_TOPICPRINT;
		}
		else
		    play_sound(SOUND_ERROR);
		return (MRESULT)TRUE;
	}
	break;
    }
    return WinDefDlgProc(hwnd, msg, mp1, mp2);
}

BOOL
get_device(void)
{
int result;
    if ((device_queue_list=(char *)malloc(PRINT_BUF_SIZE)) == (char *)NULL)
	return FALSE;
    get_ports(device_queue_list, PRINT_BUF_SIZE);
    nHelpTopic = IDS_TOPICPRINT;
    result = WinDlgBox(HWND_DESKTOP, hwnd_frame, DeviceDlgProc, 
	hlanguage, IDD_DEVICE, (MPARAM)FALSE);
    free(device_queue_list);
    if (result != DID_OK)
	return FALSE;
    return TRUE;
}

/* print a range of pages using a Ghostscript device */
void
gsview_print(BOOL convert)
{
    /* silent printing not yet implemented */
    int i;
    int flag;
    char command[MAXSTR+MAXSTR];
    char progname[MAXSTR];
    
    if (psfile.name[0] == '\0') {
	gserror(IDS_NOTOPEN, NULL, MB_ICONEXCLAMATION, SOUND_NOTOPEN);
	return;
    }
    

    if (convert) {
	if (print_silent) {
	    if (psfile.dsc != (CDSC *)NULL)
		for (i=0; i< (int)psfile.dsc->page_count; i++)
		    psfile.page_list.select[i] = TRUE;
	}
	else {
	    nHelpTopic = IDS_TOPICCONVERT;
	    if (WinDlgBox(HWND_DESKTOP, hwnd_frame, DeviceDlgProc, 
		    hlanguage, IDD_CONVERT, (MPARAM)TRUE) != DID_OK)
		return;
	}
    }
    else {
	if (print_silent) {
	    /* don't prompt */
	    int i;
	    psfile.print_copies = 1;
	    psfile.print_ignoredsc = FALSE;
	    if ( (psfile.dsc != (CDSC *)NULL) && 
		 (psfile.dsc->page_count != 0)) {
		psfile.page_list.current = 0;
		psfile.page_list.multiple = TRUE;
		for (i=0; i< (int)psfile.dsc->page_count; i++)
		    psfile.page_list.select[i] = TRUE;
		psfile.page_list.reverse = option.print_reverse;
	    }
	}
	else if (!get_device())
	    return;
    }

// PRINT_GDI not yet implemented
    if (option.print_method == PRINT_GDI)
	option.print_method = PRINT_GS;

    if (!gsview_cprint(printer.psname, printer.optname, convert)) {
	if (print_exit && (print_count==0) && !(debug & DEBUG_GDI))
	    gsview_command(IDM_EXIT);
	return;
    }

    info_wait(IDS_WAITPRINT);

    strcpy(progname, "gvpgs.exe");

    sprintf(command,"%s \042%s\042 \042%s\042 \042%s\042", debug ? "/d" : "", 
       option.gsdll, printer.optname, printer.psname);

    if (strlen(command) > MAXSTR-1) {
	    /* command line too long */
	    gserror(IDS_TOOLONG, command, MB_ICONHAND, SOUND_ERROR);
	    if (!debug)
		unlink(printer.psname);
	    printer.psname[0] = '\0';
	    if (!debug)
		unlink(printer.optname);
	    printer.optname[0] = '\0';
	    return;
    }

    flag = exec_pgm(progname, command, &printer.prog);
    if (!flag || !printer.prog.valid) {
	    cleanup_pgm(&printer.prog);
	    gserror(IDS_CANNOTRUN, command, MB_ICONHAND, SOUND_ERROR);
	    if (!debug)
		unlink(printer.psname);
	    printer.psname[0] = '\0';
	    if (!debug)
		unlink(printer.optname);
	    printer.optname[0] = '\0';
	    info_wait(IDS_NOWAIT);
	    return;
    }

    info_wait(IDS_NOWAIT);
    
    if (print_exit && (print_count==0) && !(debug & DEBUG_GDI))
	gsview_command(IDM_EXIT);

    return;
}

⌨️ 快捷键说明

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