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

📄 gvwprn.c

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Copyright (C) 1993-2001, Ghostgum Software Pty Ltd.  All rights reserved.
  
  This file is part of GSview.
  
  This program is distributed with NO WARRANTY OF ANY KIND.  No author
  or distributor accepts any responsibility for the consequences of using it,
  or for whether it serves any particular purpose or works at all, unless he
  or she says so in writing.  Refer to the GSview Free Public Licence 
  (the "Licence") for full details.
  
  Every copy of GSview must include a copy of the Licence, normally in a 
  plain ASCII text file named LICENCE.  The Licence grants you the right 
  to copy, modify and redistribute GSview, but only under certain conditions 
  described in the Licence.  Among other things, the Licence requires that 
  the copyright notice and this notice be preserved on all copies.
*/

/* gvwprn.c */
/* Printer routines for Windows GSview */
#include "gvwin.h"

#ifndef DS_FIXEDSYS
/* as defined in Windows 2000 April SDK */
#define DS_FIXEDSYS 0x0008L
#endif
#ifndef DS_SHELLFONT
/* as defined in Windows 2000 April SDK */
#define DS_SHELLFONT (DS_SETFONT | DS_FIXEDSYS)
#endif


/* documented in Device Driver Adaptation Guide */
/* Prototypes taken from print.h */
DECLARE_HANDLE(HPJOB);

HPJOB   WINAPI OpenJob(LPSTR, LPSTR, HPJOB);
int     WINAPI StartSpoolPage(HPJOB);
int     WINAPI EndSpoolPage(HPJOB);
int     WINAPI WriteSpool(HPJOB, LPSTR, int);
int     WINAPI CloseJob(HPJOB);
int     WINAPI DeleteJob(HPJOB, int);
int     WINAPI WriteDialog(HPJOB, LPSTR, int);
int     WINAPI DeleteSpoolPage(HPJOB);

char not_defined[] = "[Not defined]";
char * get_ports(void);
char * get_queues(void);
#define PORT_BUF_SIZE 4096

PRINTDLG pd;	/* global */

BOOL CALLBACK _export
NewDeviceDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam);

void
strip_spaces(char *s)
{
char *d = s;
   while (*s) {
	if (*s != ' ')
	    *d++ = *s;
	s++;
   }
   *d = '\0';
}

char editpropname[MAXSTR];

/* dialog for adding or editing properties */
BOOL CALLBACK _export
EditPropDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
{
static char device[MAXSTR];	/* contains printer device name */
PROFILE *prf;
    switch (wmsg) {
	case WM_INITDIALOG:
	    /* initialise device name */
	    strncpy(device, (LPSTR)lParam, sizeof(device)-1);	
	    if ( (prf = profile_open(szIniFile)) != (PROFILE *)NULL ) {
	      if (*editpropname) {
		  char section[MAXSTR];
		  char buf[MAXSTR];
		  if (*editpropname == 's')
		      SendDlgItemMessage(hDlg, EDITPROP_STRING, BM_SETCHECK, 
			      (WPARAM)1, 0L);
		  else
		      SendDlgItemMessage(hDlg, EDITPROP_NUMBER, BM_SETCHECK, 
			      (WPARAM)1, 0L);
		  SetDlgItemTextA(hDlg, EDITPROP_NAME, editpropname+1);
		  strncpy(section, device, sizeof(section)-1);
		  strncat(section, " values", sizeof(section)-strlen(section)-1);
		  profile_read_string(prf, section, editpropname, "", 
			buf, sizeof(buf)-2);
		  SetDlgItemTextA(hDlg, EDITPROP_VALUE, buf);
	      }
	      profile_close(prf);
	    }
	    else
	        SendDlgItemMessage(hDlg, EDITPROP_NUMBER, BM_SETCHECK, (WPARAM)1, 0L);
	    return TRUE;
	case WM_COMMAND:
	  switch (LOWORD(wParam)) {
	    case EDITPROP_DEL:
		{
		char name[MAXSTR];
		char section[MAXSTR];
		if ( SendDlgItemMessage(hDlg, EDITPROP_STRING, 
		    BM_GETCHECK, (WPARAM)1, 0L) > 0) {
		    strcpy(name, "s");
		}
		else
		    strcpy(name, "d");
		GetDlgItemTextA(hDlg, EDITPROP_NAME, name+1, sizeof(name)-2);
		strip_spaces(name);
		if (strlen(name)>1) {
		    strcpy(section, device);
		    strcat(section, " values");
		    if ( (prf = profile_open(szIniFile)) != (PROFILE *)NULL ) {
		      profile_write_string(prf, section, name, NULL);
		      profile_write_string(prf, device, name, NULL);
		      profile_close(prf);
		    }
		}
		EndDialog(hDlg, TRUE);
		}
		return TRUE;
	    case ID_HELP:
		get_help();
		return(FALSE);
	    case IDOK:
		{
		char name[MAXSTR];
		char value[MAXSTR];
		char section[MAXSTR];
		if ( SendDlgItemMessage(hDlg, EDITPROP_STRING, 
		    BM_GETCHECK, (WPARAM)1, 0L) > 0) {
		    strcpy(name, "s");
		}
		else
		    strcpy(name, "d");
		GetDlgItemTextA(hDlg, EDITPROP_NAME, name+1, sizeof(name)-2);
		GetDlgItemTextA(hDlg, EDITPROP_VALUE, value, sizeof(value)-1);
		strip_spaces(name);
		strip_spaces(value);
		if ((strlen(name)>1) && strlen(value)) {
		    strcpy(section, device);
		    strcat(section, " values");
		    if ( (prf = profile_open(szIniFile)) != (PROFILE *)NULL ) {
			profile_write_string(prf, section, name, value);
			strtok(value, ",");
			profile_write_string(prf, device, name, value);
			profile_close(prf);
		    }
		}
		EndDialog(hDlg, TRUE);
		}
		return TRUE;
	    case IDCANCEL:
		EndDialog(hDlg, FALSE);
		return TRUE;
	  }
	  break;
	}
	return FALSE;
}

/* dialog box for selecting printer properties */
BOOL CALLBACK _export
PropDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
{
    char buf[128];
    TCHAR wbuf[128];
    int iprop;
    int ivalue;
    WORD notify_message;
    char *p;
    char *value;
    static TCHAR notdef[128];
    static char device[MAXSTR];	/* contains printer device name */
    static struct prop_item_s* propitem;
    char section[MAXSTR];
    PROFILE *prf;

    switch (wmsg) {
	case WM_INITDIALOG:
	    strcpy(device, (LPSTR)lParam);	/* initialise device name */
	    load_string(IDS_NOTDEFTAG, notdef, sizeof(notdef));
	    propitem = get_properties(device);
	    SendDlgItemMessage(hDlg, PROP_NAME, CB_RESETCONTENT, (WPARAM)0, (LPARAM)0);
	    SendDlgItemMessage(hDlg, PROP_VALUE, CB_RESETCONTENT, (WPARAM)0, (LPARAM)0);
	    for (iprop=0; propitem[iprop].name[0]; iprop++) {
		SendDlgItemMessageA(hDlg, PROP_NAME, CB_ADDSTRING, 0, 
		    (LPARAM)((LPSTR)propitem[iprop].name+1));
	    }
	    SendDlgItemMessage(hDlg, PROP_NAME, CB_SETCURSEL, 0, 0L);
	    /* force update of PROP_VALUE */
	    SendDlgNotification(hDlg, PROP_NAME, CBN_SELCHANGE);
	    EnableWindow(GetDlgItem(hDlg, PROP_NAME), (iprop != 0));
	    EnableWindow(GetDlgItem(hDlg, PROP_VALUE), (iprop != 0));
	    EnableWindow(GetDlgItem(hDlg, PROP_EDIT), (iprop != 0));

	    if ( (prf = profile_open(szIniFile)) != (PROFILE *)NULL ) {
		strcpy(section, device);
		strcat(section, " Options");
		profile_read_string(prf, section, "Xoffset", "0", 
		    buf, sizeof(buf)-2);
		SetDlgItemTextA(hDlg, PROP_XOFFSET, buf);
		profile_read_string(prf, section, "Yoffset", "0", 
		    buf, sizeof(buf)-2);
		SetDlgItemTextA(hDlg, PROP_YOFFSET, buf);
		profile_close(prf);
	    }

	    SetFocus(GetDlgItem(hDlg, IDOK));
	    return TRUE;
	case WM_COMMAND:
	    notify_message = GetNotification(wParam,lParam);
	    switch (LOWORD(wParam)) {
		case ID_HELP:
		    nHelpTopic = IDS_TOPICPROP;
		    get_help();
		    return(FALSE);
		case PROP_NAME:
		    if (notify_message != CBN_SELCHANGE) {
			    return FALSE;
		    }
		    iprop = (int)SendDlgItemMessage(hDlg, PROP_NAME, CB_GETCURSEL, 0, 0L);
		    if (iprop == CB_ERR) {
			return FALSE;
		    }
		    /* now look up entry in gsview.ini */
		    /* and update PROP_VALUE list box */
		    SendDlgItemMessage(hDlg, PROP_VALUE, CB_RESETCONTENT, 0, 0L);
		    SendDlgItemMessageL(hDlg, PROP_VALUE, CB_ADDSTRING, 0, 
			(LPARAM)((LPSTR)notdef));
		    strcpy(section, device);
		    strcat(section, " values");
		    if ( (prf = profile_open(szIniFile)) != (PROFILE *)NULL ) {
		      profile_read_string(prf, section, propitem[iprop].name, 
			"", buf, sizeof(buf)-2);
		      profile_close(prf);
		    }
		    buf[strlen(buf)+1] = '\0';	/* put double NULL at end */
		    p = buf;
		    if (*p != '\0') {
		      EnableWindow(GetDlgItem(hDlg, PROP_VALUE), TRUE);
		      while (*p!='\0') {
			value = p;
			while ((*p!='\0') && (*p!=','))
			    p++;
			*p++ = '\0';
			SendDlgItemMessageA(hDlg, PROP_VALUE, CB_ADDSTRING, 0, 
			    (LPARAM)((LPSTR)value));
		      }
		    }

		    strcpy(buf, propitem[iprop].value);
		    if (strcmp(buf, not_defined)==0) {
			lstrcpy(wbuf, notdef);
		    }
		    else {
			convert_multibyte(wbuf, buf, 
			    sizeof(wbuf)/sizeof(TCHAR));
		    }
		    SendDlgItemMessageL(hDlg, PROP_VALUE, CB_SELECTSTRING, -1, 
			(LPARAM)(LPTSTR)wbuf);
		    SetDlgItemTextL(hDlg, PROP_VALUE, wbuf);
		    return FALSE;
		case PROP_VALUE:
		    if (notify_message == CBN_SELCHANGE) {
			iprop = (int)SendDlgItemMessage(hDlg, PROP_NAME, CB_GETCURSEL, 0, 0L);
			if (iprop == CB_ERR)
			    return FALSE;
			ivalue = (int)SendDlgItemMessage(hDlg, PROP_VALUE, CB_GETCURSEL, 0, 0L);
			if (ivalue == CB_ERR)
			    return FALSE;
			SendDlgItemMessageLGetString(hDlg, 
			    PROP_VALUE, CB_GETLBTEXT, 
			    ivalue, (LPARAM)(LPTSTR)wbuf);
			if (lstrcmp(wbuf, notdef)==0)
			    strcpy(propitem[iprop].value, not_defined);
			else
			    convert_widechar(propitem[iprop].value, wbuf,
				sizeof(propitem[iprop].value)/sizeof(TCHAR)-1);
		    }
		    if (notify_message == CBN_EDITCHANGE) {
			iprop = (int)SendDlgItemMessage(hDlg, PROP_NAME, CB_GETCURSEL, 0, 0L);
			if (iprop == CB_ERR)
			    return FALSE;
			GetDlgItemTextL(hDlg, PROP_VALUE, 
			    wbuf, sizeof(wbuf)/sizeof(TCHAR)-1);
			if (lstrcmp(wbuf, notdef)==0)
			    strcpy(propitem[iprop].value, not_defined);
			else
			    convert_widechar(propitem[iprop].value, wbuf,
				sizeof(propitem[iprop].value)/sizeof(TCHAR)-1);
		    }
		    return FALSE;
		case PROP_EDIT:
		    nHelpTopic = IDS_TOPICEDITPROP;
		    iprop = (int)SendDlgItemMessage(hDlg, PROP_NAME, CB_GETCURSEL, 0, 0L);
		    editpropname[0] = '\0';
		    if (iprop != CB_ERR)
			strcpy(editpropname, propitem[iprop].name);
		    DialogBoxParamL(hlanguage, MAKEINTRESOURCE(IDD_EDITPROP), 
			hDlg, EditPropDlgProc, (LPARAM)device);
		    free((char *)propitem);
		    SendMessage(hDlg, WM_INITDIALOG, (WPARAM)hDlg, (LPARAM)device);
		    SendDlgItemMessage(hDlg, IDOK, BM_SETSTYLE, 
			    (WPARAM)BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
		    SendDlgItemMessage(hDlg, PROP_EDIT, BM_SETSTYLE, 
			    (WPARAM)BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
		    nHelpTopic = IDS_TOPICPROP;
		    return FALSE;
		case PROP_NEW:
		    nHelpTopic = IDS_TOPICEDITPROP;
		    editpropname[0] = '\0';
		    DialogBoxParamL(hlanguage, MAKEINTRESOURCE(IDD_EDITPROP), 
			hDlg, EditPropDlgProc, (LPARAM)device);
		    free((char *)propitem);
		    SendMessage(hDlg, WM_INITDIALOG, (WPARAM)hDlg, (LPARAM)device);
		    SendDlgItemMessage(hDlg, IDOK, BM_SETSTYLE, 
			    (WPARAM)BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
		    SendDlgItemMessage(hDlg, PROP_NEW, BM_SETSTYLE, 
			    (WPARAM)BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
		    nHelpTopic = IDS_TOPICPROP;
		    return FALSE;
		case IDOK:
		    if ( (prf = profile_open(szIniFile)) != (PROFILE *)NULL ) {
			for (iprop=0; propitem[iprop].name[0]; iprop++) {
			    profile_write_string(prf, device, 
				propitem[iprop].name, propitem[iprop].value);
		      }
		      strcpy(section, device);
		      strcat(section, " Options");
		      GetDlgItemTextA(hDlg, PROP_XOFFSET, buf, sizeof(buf)-2);
		      profile_write_string(prf, section, "Xoffset", buf);
		      GetDlgItemTextA(hDlg, PROP_YOFFSET, buf, sizeof(buf)-2);
		      profile_write_string(prf, section, "Yoffset", buf);
		      profile_close(prf);
		    }
		    free((char *)propitem);
		    EndDialog(hDlg, TRUE);
		    return TRUE;
		case IDCANCEL:
		    free((char *)propitem);
		    EndDialog(hDlg, FALSE);
		    return TRUE;
	    }
	    break;
    }
    return FALSE;
}


LPSTR
GetUPPname(HWND hwnd, LPSTR uppname, int upplen)
{
    LPSTR p, q;
    uppname[0] = '\0';
    GetDlgItemTextA(GetParent(hwnd), 
	    DEVICE_OPTIONS, (LPSTR)uppname, upplen);
    p = uppname;
    if (p[0] == '"') {
	/* remove quotes around configuration file */
	p++;
	q = strchr(p, '"');
	if (q != (LPSTR)NULL)
	    *q = '\0';
    }
    if (p[0] == '@')
	p++;
    if (strlen(p))
        memmove(uppname, p, strlen(p)+1);
    return uppname;
}

/* dialog box for selecting uniprint configuration file */
#ifdef __BORLANDC__
#pragma argsused
#endif
BOOL CALLBACK _export
UniDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
{
    WORD notify_message;
    LPSTR p, q;
    char uppname[MAXSTR];	/* contains printer device name */
    static LPSTR ubuf;
    LPSTR desc;
    int i;

    switch (wmsg) {
	case WM_INITDIALOG:
	    ubuf = NULL;
	    /* Delay initialization of the list box until 
	     * after it is displayed, because searching for 
	     * configuration files takes several seconds.
	     */
	    SendDlgItemMessage(hDlg, UPP_LIST, LB_RESETCONTENT, 0, (LPARAM)0);
	    { TCHAR wbuf[MAXSTR];
	      load_string(IDS_WAIT, wbuf, sizeof(wbuf));
	      SendDlgItemMessageL(hDlg, UPP_LIST, LB_ADDSTRING, 0, 
		(LPARAM)wbuf);
	    }
	    EnableWindow(GetDlgItem(hDlg, UPP_LIST), FALSE);
	    uppname[0] = uppname[1] = '\0';
	    GetUPPname(hDlg, uppname, sizeof(uppname));
	    SetDlgItemTextA(hDlg, UPP_NAME, uppname);
	    PostMessage(hDlg, WM_COMMAND, WM_USER, 0L);
	    return TRUE;
	case WM_COMMAND:
	    notify_message = GetNotification(wParam,lParam);
	    switch (LOWORD(wParam)) {
		case WM_USER:
		    /* time consuming initialization */
		    ShowWindow(hDlg, SW_SHOW);
		    InvalidateRect(hDlg, NULL, FALSE);
		    UpdateWindow(hDlg);
		    desc = NULL;
		    uppname[0] = uppname[1] = '\0';
		    i = enum_upp_path(option.gsinclude, NULL, 0);
		    if ((ubuf = (LPSTR)malloc(i)) == (char *)NULL) {
			play_sound(SOUND_ERROR);
			PostMessage(hDlg, WM_COMMAND, IDCANCEL, 0L);
			return TRUE;	/* no memory */
		    }
		    enum_upp_path(option.gsinclude, ubuf, i);
		    GetUPPname(hDlg, uppname, sizeof(uppname));
		    SendDlgItemMessage(hDlg, UPP_LIST, LB_RESETCONTENT, 
			0, (LPARAM)0);
		    for (p = ubuf; *p; p += strlen(p) + 1) {
			q = p + strlen(p) + 1;
			if (strcmp(p, uppname) == 0)
			    desc = q;
			SendDlgItemMessageA(hDlg, UPP_LIST, LB_ADDSTRING, 
				0, (LPARAM)q);

⌨️ 快捷键说明

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