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

📄 gvpdlg.c

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 C
📖 第 1 页 / 共 4 页
字号:
	if (WinDlgBox(HWND_DESKTOP, hwnd_frame, InstallDlgProc, hlanguage, IDD_INSTALL, NULL)
	   == DID_OK) {
		option.configured = TRUE;
		return TRUE;
	}
	return FALSE;
}

char *depthlist[] =    {"Default", "1", "4", "8", "24"};
int index_to_depth[] = { 0,         1,   4,   8,   24};
int depth_to_index(int depth)
{
int i;
    for (i=0; i<(int)(sizeof(index_to_depth)/sizeof(int)); i++)
	if (index_to_depth[i] == depth)
	    return i;
    return 0;
}

char *alphalist[] =    {"1", "2", "4"};
int index_to_alpha[] = { 1,   2,   4};
int alpha_to_index(int alpha)
{
unsigned int i;
    for (i=0; i<sizeof(index_to_alpha)/sizeof(int); i++)
	if (index_to_alpha[i] == alpha)
	    return i;
    return 0;
}

char *drawlist[] =    {"Default", "GpiDrawBits", "WinDrawBitmap"};
int index_to_draw[] = { IDM_DRAWDEF,  IDM_DRAWGPI, IDM_DRAWWIN };
int draw_to_index(int draw)
{
unsigned int i;
    for (i=0; i<sizeof(index_to_draw)/sizeof(int); i++)
	if (index_to_draw[i] == draw)
	    return i;
    return 0;
}

void
enable_alpha(HWND hwnd)
{
    int i;
    i = (int)WinSendMsg( WinWindowFromID(hwnd, DSET_DEPTH),
	    	LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), MPFROMLONG(0) );
    if (i == LIT_NONE)
	return;
    i = real_depth(index_to_depth[i]);
    i = (i >= 8);
    WinEnableWindow(WinWindowFromID(hwnd, DSET_TALPHA), i);
    WinEnableWindow(WinWindowFromID(hwnd, DSET_GALPHA), i);
}


MRESULT EXPENTRY 
DisplaySettingsDlgProc(HWND hwnd, ULONG mess, MPARAM mp1, MPARAM mp2)
{
    char buf[128];
    unsigned int i;
    switch(mess) {
	case WM_INITDLG:
	    WinSendMsg( WinWindowFromID(hwnd, DSET_RES),
	    	EM_SETTEXTLIMIT, MPFROM2SHORT(sizeof(buf)-1, 0), MPFROMLONG(0) );
	    if (option.xdpi == option.ydpi)
		sprintf(buf,"%g", option.xdpi);
	    else 
		sprintf(buf,"%g %g", option.xdpi, option.ydpi);
	    SetDlgItemText(hwnd, DSET_RES, buf);
	    WinSendMsg( WinWindowFromID(hwnd, DSET_ZOOMRES),
	    	EM_SETTEXTLIMIT, MPFROM2SHORT(sizeof(buf)-1, 0), MPFROMLONG(0) );
	    if (option.zoom_xdpi == option.zoom_ydpi)
		sprintf(buf,"%g", option.zoom_xdpi);
	    else 
		sprintf(buf,"%g %g", option.zoom_xdpi, option.zoom_ydpi);
	    SetDlgItemText(hwnd, DSET_ZOOMRES, buf);
	    WinSendMsg( WinWindowFromID(hwnd, DSET_DEPTH),
	    	LM_DELETEALL, MPFROMLONG(0), MPFROMLONG(0) );
	    for (i=0; i<sizeof(depthlist)/sizeof(char *); i++) {
		strcpy(buf, depthlist[i]);
		if (strcmp(buf, "Default")==0)
		    load_string(IDS_DEFAULT, buf, sizeof(buf)-1);
	        WinSendMsg( WinWindowFromID(hwnd, DSET_DEPTH),
	    	    LM_INSERTITEM, MPFROMSHORT(LIT_END), MPFROMP(buf) );
	    }
	    WinSendMsg( WinWindowFromID(hwnd, DSET_DEPTH),
		LM_SELECTITEM, MPFROMSHORT(depth_to_index(option.depth)), MPFROMSHORT(TRUE));
	    WinSendMsg( WinWindowFromID(hwnd, DSET_TALPHA),
	    	LM_DELETEALL, MPFROMLONG(0), MPFROMLONG(0) );
	    WinSendMsg( WinWindowFromID(hwnd, DSET_TALPHA),
	    	LM_DELETEALL, MPFROMLONG(0), MPFROMLONG(0) );
	    for (i=0; i<sizeof(alphalist)/sizeof(char *); i++) {
	        WinSendMsg( WinWindowFromID(hwnd, DSET_TALPHA),
	    	    LM_INSERTITEM, MPFROMSHORT(LIT_END), MPFROMP(alphalist[i]) );
	        WinSendMsg( WinWindowFromID(hwnd, DSET_GALPHA),
	    	    LM_INSERTITEM, MPFROMSHORT(LIT_END), MPFROMP(alphalist[i]) );
	    }
	    WinSendMsg( WinWindowFromID(hwnd, DSET_TALPHA),
		LM_SELECTITEM, MPFROMSHORT(alpha_to_index(option.alpha_text)), MPFROMSHORT(TRUE));
	    WinSendMsg( WinWindowFromID(hwnd, DSET_GALPHA),
		LM_SELECTITEM, MPFROMSHORT(alpha_to_index(option.alpha_graphics)), MPFROMSHORT(TRUE));
	    enable_alpha(hwnd);
	    WinSendMsg( WinWindowFromID(hwnd, DSET_DRAWMETHOD),
	    	LM_DELETEALL, MPFROMLONG(0), MPFROMLONG(0) );
	    for (i=0; i<sizeof(drawlist)/sizeof(char *); i++) {
		strcpy(buf, drawlist[i]);
		if (strcmp(buf, "Default")==0)
		    load_string(IDS_DEFAULT, buf, sizeof(buf)-1);
	        WinSendMsg( WinWindowFromID(hwnd, DSET_DRAWMETHOD),
	    	    LM_INSERTITEM, MPFROMSHORT(LIT_END), MPFROMP(buf) );
	    }
	    WinSendMsg( WinWindowFromID(hwnd, DSET_DRAWMETHOD),
		LM_SELECTITEM, MPFROMSHORT(draw_to_index(option.drawmethod)), MPFROMSHORT(TRUE));
    	    break;
	case WM_CONTROL:
	    if (SHORT2FROMMP(mp1) == LN_SELECT)
		enable_alpha(hwnd);
	    break;
        case WM_COMMAND:
            switch(SHORT1FROMMP(mp1)) {
                case DID_OK:
		    {
		    BOOL unzoom = FALSE;
		    BOOL resize = FALSE;
	            BOOL restart = FALSE;
		    float x, y;
                    WinQueryWindowText(WinWindowFromID(hwnd, DSET_RES),
                    	sizeof(buf)-2, (PBYTE)buf);
		    switch (sscanf(buf,"%f %f", &x, &y)) {
		      case EOF:
		      case 0:
			break;
		      case 1:
			y = x;
		      case 2:
			if (x==0.0)
			    x= DEFAULT_RESOLUTION;
			if (y==0.0)
			    y= DEFAULT_RESOLUTION;
			if ( (x != option.xdpi) || (y != option.ydpi) ) {
			    option.xdpi = x;
			    option.ydpi = y;
			    resize = TRUE; 
			    unzoom = TRUE;
			}
		    }
                    WinQueryWindowText(WinWindowFromID(hwnd, DSET_ZOOMRES),
                    	sizeof(buf)-2, (PBYTE)buf);
		    switch (sscanf(buf,"%f %f", &x, &y)) {
		      case EOF:
		      case 0:
			break;
		      case 1:
			y = x;
		      case 2:
			if (x==0.0)
			    x= DEFAULT_RESOLUTION;
			if (y==0.0)
			    y= DEFAULT_RESOLUTION;
			if ( (x != option.zoom_xdpi) || (y != option.zoom_ydpi) ) {
			    option.zoom_xdpi = x;
			    option.zoom_ydpi = y;
			    resize = TRUE; 
			    unzoom = TRUE;
			}
		    }
		    i = (unsigned int)WinSendMsg( WinWindowFromID(hwnd, DSET_DEPTH),
			LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), MPFROMLONG(0) );
		    i = index_to_depth[i];
		    if (i != (unsigned int)option.depth) {
			option.depth = i;
			restart = TRUE;
			resize = TRUE; 
			unzoom = TRUE;
		    }
		    i = (unsigned int)WinSendMsg( WinWindowFromID(hwnd, DSET_TALPHA),
			LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), MPFROMLONG(0) );
		    i = index_to_alpha[i];
		    if (i != (unsigned int)option.alpha_text) {
			option.alpha_text = i;
			restart = TRUE;
			resize = TRUE; 
			unzoom = TRUE;
		    }
		    i = (unsigned int)WinSendMsg( WinWindowFromID(hwnd, DSET_GALPHA),
			LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), MPFROMLONG(0) );
		    i = index_to_alpha[i];
		    if (i != (unsigned int)option.alpha_graphics) {
			option.alpha_graphics = i;
			/* restart = TRUE; */
			resize = TRUE; 
			unzoom = TRUE;
		    }
		    i = (unsigned int)WinSendMsg( WinWindowFromID(hwnd, DSET_DRAWMETHOD),
			LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), MPFROMLONG(0) );
		    i = index_to_draw[i];
		    if (i != (unsigned int)option.drawmethod) {
			option.drawmethod = i;
			/* strictly all we need to do is redraw the screen */
			/* but we force this making GS redraw */
			resize = TRUE; 	
		    }
		    if (resize) {
			if (unzoom)
			    gsview_unzoom();
			if (gsdll.state != GS_UNINIT) {
/* gs_resize has this check
			    if (option.redisplay && (gsdll.state == GS_PAGE) && (psfile.doc != (CDSC *)NULL))
*/
				gs_resize();
			    /* for those that can't be changed with a */
			    /* postscript command so must close gs */
			    if (restart)
				pending.restart = TRUE;
			}
		    }
		    }
                    WinDismissDlg(hwnd, DID_OK);
		    return (MRESULT)TRUE;
		case DID_CANCEL:
		    WinDismissDlg(hwnd, DID_CANCEL);
		    return (MRESULT)TRUE;
		case ID_HELP:
		    nHelpTopic = IDS_TOPICDSET;
		    get_help();
		    return (MRESULT)TRUE;
            }
            break;
    }
    return WinDefDlgProc(hwnd, mess, mp1, mp2);
}


void
display_settings(void)
{
	WinDlgBox(HWND_DESKTOP, hwnd_frame, DisplaySettingsDlgProc, hlanguage, IDD_DSET, NULL);
}


/* Text Window for Ghostscript Messages */
/* uses OS/2 MLE control */


#define TWLENGTH 16384
#define TWSCROLL 1024
char twbuf[TWLENGTH];
int twend;

MRESULT EXPENTRY 
TextDlgProc(HWND hwnd, ULONG mess, MPARAM mp1, MPARAM mp2)
{
    switch(mess) {
	case WM_INITDLG:
	    {IPT ipt = 0;
	    int len = strlen(twbuf);
	    WinSendMsg( WinWindowFromID(hwnd, TEXTWIN_MLE),
	    	MLM_SETIMPORTEXPORT, (MPARAM)twbuf, (MPARAM)len);
	    WinSendMsg( WinWindowFromID(hwnd, TEXTWIN_MLE),
	    	MLM_IMPORT, (MPARAM)&ipt, (MPARAM)len);
	    WinSendMsg( WinWindowFromID(hwnd, TEXTWIN_MLE),
	    	MLM_SETSEL, (MPARAM)len, (MPARAM)len);
	    }
    	    break;
        case WM_COMMAND:
            switch(SHORT1FROMMP(mp1)) {
                case DID_OK:
                    WinEnableWindow(WinWindowFromID(hwnd, DID_OK), FALSE);
                    WinDismissDlg(hwnd, DID_OK);
		    return (MRESULT)TRUE;
		case ID_HELP:
		    get_help();
		    return (MRESULT)TRUE;
		case TEXTWIN_COPY:
		    {MRESULT mr; 
	    	    mr = WinSendMsg( WinWindowFromID(hwnd, TEXTWIN_MLE),
	    		MLM_QUERYSEL, (MPARAM)MLFQS_MINMAXSEL, (MPARAM)0);
		    if (SHORT1FROMMP(mr) == SHORT2FROMMP(mr)) /* no selection so select all */
	    		WinSendMsg( WinWindowFromID(hwnd, TEXTWIN_MLE),
	    		    MLM_SETSEL, 0, (MPARAM)strlen(twbuf));
	    	    WinSendMsg( WinWindowFromID(hwnd, TEXTWIN_MLE),
	    		MLM_COPY, (MPARAM)0, (MPARAM)0);
		    WinSendMsg( WinWindowFromID(hwnd, TEXTWIN_MLE),
		        MLM_SETSEL, (MPARAM)strlen(twbuf), (MPARAM)strlen(twbuf));
		    }
		    return (MRESULT)TRUE;
            }
            break;
    }
    return WinDefDlgProc(hwnd, mess, mp1, mp2);
}

/* Show Ghostscript messages window */
void
gs_showmess(void)
{
        nHelpTopic = IDS_TOPICMESS;
	WinDlgBox(HWND_DESKTOP, hwnd_frame, TextDlgProc, hlanguage, IDD_TEXTWIN, NULL);
}

/* Add string for Ghostscript message window */
void
gs_addmess_count(const char *str, int count)
{
    /* if debugging, write to a log file */
    if (debug & DEBUG_LOG) {
	FILE *f = fopen("c:\\gsview.txt", "a");
	if (f != (FILE *)NULL) {
	    fwrite(str, 1, count, f);
	    fclose(f);
	}
    }

    if (count >= TWSCROLL)
	return;		/* too large */
    if (count + twend >= TWLENGTH-1) {
	/* scroll buffer */
	twend -= TWSCROLL;
	memmove(twbuf, twbuf+TWSCROLL, twend);
    }
    memmove(twbuf+twend, str, count);
    twend += count;
    *(twbuf+twend) = '\0';
}

void
gs_addmess(const char *str)
{
    gs_addmess_count(str, strlen(str));
}


MRESULT EXPENTRY 
DSCErrorDlgProc(HWND hwnd, ULONG mess, MPARAM mp1, MPARAM mp2)
{
    switch(mess) {
	case WM_INITDLG:
	    {BYTE buf[MAXSTR];
	    unsigned int i;
	    unsigned int j = 0;
	    PBYTE mess = (PBYTE)mp2;
	    /* place one line per control */
	    while (*mess) {
		for (i=0; i<sizeof(buf)-1; i++) {
		    buf[i] = *mess++;
		    if (buf[i] == '\n') {
			buf[i] = '\0';
			break;
		    }
		}
		WinSetWindowText(WinWindowFromID(hwnd, DSC_STATIC_TEXT+j), buf);
		j++;
	    }
	    }
    	    break;
        case WM_COMMAND:
            switch(SHORT1FROMMP(mp1)) {
                case DID_OK:
                    WinDismissDlg(hwnd, CDSC_RESPONSE_OK);
		    return (MRESULT)TRUE;
                case DID_CANCEL:
                    WinDismissDlg(hwnd, CDSC_RESPONSE_CANCEL);
		    return (MRESULT)TRUE;
                case DSC_IGNORE_ALL:
                    WinDismissDlg(hwnd, CDSC_RESPONSE_IGNORE_ALL);
		    return (MRESULT)TRUE;
		case ID_HELP:
		    get_help();
		    return (MRESULT)TRUE;
            }
            break;
    }
    return WinDefDlgProc(hwnd, mess, mp1, mp2);
}


int 
get_dsc_response(char *message)
{
    nHelpTopic = IDS_TOPICDSCWARN;
    return WinDlgBox(HWND_DESKTOP, hwnd_frame, DSCErrorDlgProc, 
	hlanguage, IDD_DSCERROR, message);
}

⌨️ 快捷键说明

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