📄 gvwinit.c
字号:
return rc;
}
/***************************/
HINSTANCE zlib_hinstance;
PFN_gzopen gzopen;
PFN_gzread gzread;
PFN_gzclose gzclose;
void
unload_zlib(void)
{
if (zlib_hinstance == (HINSTANCE)NULL)
return;
FreeLibrary(zlib_hinstance);
zlib_hinstance = NULL;
gzopen = NULL;
gzread = NULL;
gzclose = NULL;
}
/* load zlib DLL for gunzip */
BOOL
load_zlib(void)
{
char buf[MAXSTR];
char exepath[MAXSTR];
#ifdef DECALPHA
char zlibname[] = "zlibda.dll";
#else
char zlibname[] = "zlib32.dll";
#endif
convert_widechar(exepath, szExePath, sizeof(exepath)-1);
if (zlib_hinstance != (HINSTANCE)NULL)
return TRUE; /* already loaded */
/* first look in GSview directory */
strcpy(buf, exepath);
strcat(buf, zlibname);
gs_addmess("Attempting to load ");
gs_addmess(buf);
gs_addmess("\n");
zlib_hinstance = LoadLibraryA(buf);
if (zlib_hinstance < (HINSTANCE)HINSTANCE_ERROR) {
/* if that fails, use the system search path */
strcpy(buf, zlibname);
gs_addmess("Attempting to load ");
gs_addmess(buf);
gs_addmess("\n");
zlib_hinstance = LoadLibraryA(buf);
}
if (zlib_hinstance >= (HINSTANCE)HINSTANCE_ERROR) {
gzopen = (PFN_gzopen) GetProcAddress(zlib_hinstance, "gzopen");
if (gzopen == NULL) {
unload_zlib();
}
else {
gzread = (PFN_gzread) GetProcAddress(zlib_hinstance, "gzread");
if (gzread == NULL) {
unload_zlib();
}
else {
gzclose = (PFN_gzclose) GetProcAddress(zlib_hinstance, "gzclose");
if (gzclose == NULL) {
unload_zlib();
}
}
}
}
else
zlib_hinstance = NULL;
if (zlib_hinstance == NULL) {
TCHAR wbuf[MAXSTR];
load_string(IDS_ZLIB_FAIL, wbuf, sizeof(wbuf)/sizeof(TCHAR)-1);
if (message_box(wbuf, MB_OKCANCEL) == IDOK) {
nHelpTopic = IDS_TOPICZLIB;
get_help();
}
return FALSE;
}
return TRUE;
}
/***************************/
HINSTANCE bzip2_hinstance;
PFN_bzopen bzopen;
PFN_bzread bzread;
PFN_bzclose bzclose;
void
unload_bzip2(void)
{
if (bzip2_hinstance == (HINSTANCE)NULL)
return;
FreeLibrary(bzip2_hinstance);
bzip2_hinstance = NULL;
bzopen = NULL;
bzread = NULL;
bzclose = NULL;
}
/* load bzip2 DLL for gunzip */
BOOL
load_bzip2(void)
{
char buf[MAXSTR];
char exepath[MAXSTR];
char bzip2name[] = "libbz2.dll";
convert_widechar(exepath, szExePath, sizeof(exepath)-1);
if (bzip2_hinstance != (HINSTANCE)NULL)
return TRUE; /* already loaded */
/* first look in GSview directory */
strcpy(buf, exepath);
strcat(buf, bzip2name);
gs_addmess("Attempting to load ");
gs_addmess(buf);
gs_addmess("\n");
bzip2_hinstance = LoadLibraryA(buf);
if (bzip2_hinstance < (HINSTANCE)HINSTANCE_ERROR) {
/* if that fails, use the system search path */
strcpy(buf, bzip2name);
bzip2_hinstance = LoadLibraryA(buf);
gs_addmess("Attempting to load ");
gs_addmess(buf);
gs_addmess("\n");
}
if (bzip2_hinstance >= (HINSTANCE)HINSTANCE_ERROR) {
bzopen = (PFN_bzopen) GetProcAddress(bzip2_hinstance, "BZ2_bzopen");
if (bzopen == NULL) {
unload_bzip2();
}
else {
bzread = (PFN_bzread) GetProcAddress(bzip2_hinstance, "BZ2_bzread");
if (bzread == NULL) {
unload_bzip2();
}
else {
bzclose = (PFN_bzclose) GetProcAddress(bzip2_hinstance, "BZ2_bzclose");
if (bzclose == NULL) {
unload_bzip2();
}
}
}
}
else
bzip2_hinstance = NULL;
if (bzip2_hinstance == NULL) {
TCHAR wbuf[MAXSTR];
load_string(IDS_BZIP2_FAIL, wbuf, sizeof(wbuf)/sizeof(TCHAR)-1);
if (message_box(wbuf, MB_OKCANCEL) == IDOK) {
nHelpTopic = IDS_TOPICBZIP2;
get_help();
}
return FALSE;
}
return TRUE;
}
/****************************************************/
/* Easy Configure */
#ifdef __BORLANDC__
#pragma argsused
#endif
/* easy configure dialog box */
BOOL CALLBACK _export
EasyConfigureDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
WORD notify_message;
switch(message) {
case WM_INITDIALOG:
{
int *gsver = (int *)lParam;
int i;
int n=0;
char buf[16];
for (i=1; i<=gsver[0]; i++) {
if ((gsver[i] >= GS_REVISION_MIN) &&
(gsver[i] <= GS_REVISION_MAX)) {
n++;
gsver_string(gsver[i], buf);
/* put string in list box */
SendDlgItemMessageA(hDlg, IDC_GSVER, LB_ADDSTRING,
0, (LPARAM)((LPSTR)buf));
}
}
SendDlgItemMessage(hDlg, IDC_GSVER, LB_SETCURSEL,
n-1, 0L);
}
return TRUE;
case WM_COMMAND:
notify_message = GetNotification(wParam,lParam);
switch(LOWORD(wParam)) {
case IDOK:
{
char buf[16];
int i = (int)SendDlgItemMessage(hDlg, IDC_GSVER,
LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, IDC_GSVER, LB_GETTEXT,
i, (LPARAM)(LPSTR)buf);
EndDialog(hDlg, gsver_int(buf));
}
return(TRUE);
case IDCANCEL:
EndDialog(hDlg, 0);
return(TRUE);
case ID_HELP:
get_help();
return(FALSE);
case IDC_GSVER:
if (notify_message == LBN_DBLCLK)
PostMessage(hDlg, WM_COMMAND, IDOK, 0);
return(FALSE);
default:
return(FALSE);
}
}
return(FALSE);
}
int
config_easy(BOOL bVerbose)
{
#ifndef __WIN32__
#error Win16 is no longer supported
#endif
int result;
int *gsver;
int gs_count = 0;
get_gs_versions(&gs_count);
if (gs_count == 0)
return 1;
gsver = (int *)malloc(sizeof(int) * (gs_count + 1));
if (gsver == (int *)NULL)
return 1;
gsver[0] = gs_count+1;
nHelpTopic = IDS_TOPICEASYCFG;
if (get_gs_versions(gsver)) {
if (!bVerbose && (gsver[0] == 1)) {
/* Only one copy of Ghostscript installed */
/* Don't prompt user */
result = gsver[1];
}
else {
/* Multiple copies of Ghostscript installed */
/* Ask user to choose one */
result = DialogBoxParamL(hlanguage,
MAKEINTRESOURCE(IDD_EASYCFG), hwndimg,
EasyConfigureDlgProc, (LPARAM)gsver);
}
}
free(gsver);
if (result == 0)
return 0; /* don't configure and don't warn */
option.gsversion= result;
get_gs_string(option.gsversion, "GS_DLL", option.gsdll,
sizeof(option.gsdll));
get_gs_string(option.gsversion, "GS_LIB", option.gsinclude,
sizeof(option.gsinclude));
strcpy(option.gsother, "-dNOPLATFONTS -sFONTPATH=\042c:\\psfonts\042");
/* copy printer.ini */
gsview_printer_profiles();
option.configured = TRUE;
write_profile();
if (gsdll.open)
pending.unload = TRUE;
return 0; /* success */
}
/***************************/
/* configure dialog wizard */
HWND hWiz = HWND_DESKTOP;
int gsver = GS_REVISION;
int wiz_exit(HWND hwnd);
int check_gsver(HWND hwnd);
int config_finish(HWND hwnd);
BOOL CALLBACK _export CfgChildDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK _export CfgMainDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
/* hDlgModeless */
typedef struct tagWIZPAGE {
int id; /* resource ID */
int prev; /* resource id of previous page */
int next; /* resource id of next page */
int (*func)(HWND); /* function to run on exit from page */
HWND hwnd; /* window handle of dialog */
} WIZPAGE;
WIZPAGE pages[]={
{IDD_CFG1, IDD_CFG1, IDD_CFG2, NULL, 0},
{IDD_CFG2, IDD_CFG1, IDD_CFG3, check_gsver, 0},
{IDD_CFG3, IDD_CFG2, IDD_CFG4, NULL, 0},
{IDD_CFG4, IDD_CFG3, IDD_CFG5, NULL, 0},
{IDD_CFG5, IDD_CFG4, IDD_CFG6, NULL, 0},
{IDD_CFG6, IDD_CFG5, IDD_CFG7, config_finish, 0},
{IDD_CFG7, IDD_CFG7, IDD_CFG7, wiz_exit, 0},
{0, 0, 0, NULL, 0}
};
#ifdef __BORLANDC__
#pragma argsused
#endif
int wiz_exit(HWND hwnd)
{
PostMessage(hWiz, WM_COMMAND, (WPARAM)IDOK, (LPARAM)0);
return 0;
}
WIZPAGE *
find_page_from_id(int id)
{
WIZPAGE *page;
for (page=pages; page->id; page++) {
if (page->id == id)
return page;
}
return NULL;
}
void
goto_page(HWND hwnd, int id)
{
WIZPAGE *page;
HWND hbutton;
page = find_page_from_id(id);
if (page) {
ShowWindow(hwnd, SW_HIDE);
ShowWindow(page->hwnd, SW_SHOW);
hDlgModeless = page->hwnd;
if (IsWindowEnabled(GetDlgItem(page->hwnd, IDNEXT)) )
hbutton = GetDlgItem(page->hwnd, IDNEXT);
else
hbutton = GetDlgItem(page->hwnd, IDCANCEL);
SetFocus(hbutton);
SendMessage(hbutton, BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, TRUE);
return;
}
}
void
next_page(HWND hwnd)
{
WIZPAGE *page;
int id;
for (page=pages; page->id; page++) {
if (page->hwnd == hwnd) {
if (page->func) {
/* need to execute a function before continuing */
if ( (id = page->func(hwnd)) != 0) {
goto_page(hwnd, id);
return;
}
}
goto_page(hwnd, page->next);
return;
}
}
}
void
prev_page(HWND hwnd)
{
WIZPAGE *page;
for (page=pages; page->id; page++) {
if (page->hwnd == hwnd) {
goto_page(hwnd, page->prev);
}
}
}
int
add_gsver(HWND hwnd, int offset)
{
char buf[MAXSTR];
int ver;
GetDlgItemTextA(hwnd, IDC_CFG20, buf, sizeof(buf));
if (strlen(buf) == 4)
ver = (buf[0]-'0')*100 + (buf[2]-'0')*10 + (buf[3]-'0');
else if (strlen(buf) == 3)
ver = (buf[0]-'0')*100 + (buf[2]-'0')*10;
else
return GS_REVISION;
ver += offset;
if (ver > GS_REVISION_MAX)
ver = GS_REVISION_MAX;
if (ver < GS_REVISION_MIN)
ver = GS_REVISION_MIN;
return ver;
}
int
check_gsver(HWND hwnd)
{
char buf[MAXSTR];
int ver = GS_REVISION;
BOOL fixit = FALSE;
/* should allow edit field to be changed */
/* then make sure it is within range */
GetDlgItemTextA(hwnd, IDC_CFG20, buf, sizeof(buf));
if (strlen(buf) == 4) {
ver = (buf[0]-'0')*100 + (buf[2]-'0')*10 + (buf[3]-'0');
if ( (ver > GS_REVISION_MAX) || (ver < GS_REVISION_MIN) )
fixit = TRUE;
}
else
fixit = TRUE;
if (fixit) {
ver = GS_REVISION;
sprintf(buf, "%d.%02d", ver / 100, ver % 100);
SetDlgItemTextA(hwnd, IDC_CFG20, buf);
/* don't move until it is valid */
return IDD_CFG2;
}
gsver = ver;
return 0;
}
/* update GS directory edit field when version number changes */
void
gsdir_fix(HWND hwnd, char *verstr)
{
char buf[MAXSTR];
char *p;
GetDlgItemTextA(hwnd, IDC_CFG22, buf, sizeof(buf));
if (strlen(buf) < 6)
return;
p = buf + strlen(buf) - 4;
if (isdigit((int)(p[0])) && (p[1]=='.') &&
isdigit((int)(p[2])) && isdigit((int)(p[3]))) {
strcpy(p, verstr);
SetDlgItemTextA(hwnd, IDC_CFG22, buf);
}
else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -