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

📄 gvpinit.c

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Copyright (C) 1993-1998, 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.
*/

/* gvpinit.c */
/* Initialisation routines for PM GSview */
#include "gvpm.h"

HELPINIT hi_help;
APIRET init1(void); 
APIRET init2(void); 
APIRET restore_window_position(SWP *pswp);
ULONG frame_flags = 
	    FCF_TITLEBAR |	/* have a title bar */
            FCF_SIZEBORDER |	/* have a sizeable window */
            FCF_MINMAX |	/* have a min and max button */
            FCF_SYSMENU | 	/* include a system menu */
            FCF_VERTSCROLL |	/* vertical scroll bar */
            FCF_HORZSCROLL |	/* horizontal scroll bar */
	    FCF_TASKLIST |	/* show it in window list */
	    FCF_ICON;		/* Load icon from resources */
#ifdef UNUSED
/* need to load these from a different module */
	    FCF_MENU |		/* Load menu from resources */
	    FCF_ACCELTABLE;	/* Load accelerator table from resources */
#endif

BOOL parse_args(GSVIEW_ARGS *pargs);


/* This code allows GSview to automatically find the language DLLs.
 * This allows languages to be added without having to alter the
 * source code of the GSview executable.
 */

/* At startup, we look for language DLLs in the GSview EXE directory
 * which have the following name.  The ?? is replaced by the two
 * letter Internet country code.
 */
const TCHAR lang_pattern[] = TEXT("gvpm??.dll");
const int lang_offset = 4;  /* offset to ?? */

/* We load each of these DLLs and if they contain a version
 * string that matches the GSview EXE, we consider them to
 * be a valid language DLL.  We store the details about each
 * in the following structure.  
 * The id is allocated automatically.
 * We refer to each language in the INI file using the twocc code, 
 * which matches the two letter Internet country code.
 * Each language DLL provides a string with the name of the language
 * in it's own language and also in English.  The latter is used 
 * on systems without that language installed.
 * The required ANSI codepage is in codepage.  If any code page is
 * acceptable (e.g. English) then this may be 0.
 */
typedef struct lang_s {
    int id;
    char twocc[3];
    char dllname[MAXSTR];
    char name[MAXSTR];	/* language name in it's language and codepage */
    char ename[MAXSTR];	/* language name in English */
    int codepage;
} lang_t;

/* The list of language DLLs available */
#define MAXLANG 19
lang_t lang[MAXLANG];
int nlang;

int
language_find(void)
{
ULONG cFilenames = 1;
    int i;
    FILEFINDBUF3 findbuf;
    HDIR hdir;
    CHAR dirname[MAXSTR];
    CHAR pattern[1024];
    CHAR buf[MAXSTR];
    int twocc_index;
    HMODULE hmodule;
    APIRET rc;

    for (i=0; i<MAXLANG; i++) {
	lang[i].id = 0;
	lang[i].twocc[0] = '\0';
	lang[i].dllname[0] = '\0';
    }

    /* First language is always English */
    nlang = 0;
    lang[nlang].id = IDM_LANGMENU + nlang + 1;
    lang[nlang].twocc[0] = 'e';
    lang[nlang].twocc[1] = 'n';
    lang[nlang].twocc[2] = '\0';
    lang[nlang].dllname[0] = '\0';
    strcpy(lang[nlang].name, "English");
    strcpy(lang[nlang].ename, "English");
    nlang++;

    /* Now search for language DLLs */
    strcpy(dirname, szExePath);
    strcpy(pattern, dirname);
    strcat(pattern, lang_pattern);
    twocc_index = strlen(pattern - 6);
    memset(&findbuf, 0, sizeof(findbuf));

    hdir = HDIR_CREATE;
    cFilenames = 1;
    rc = DosFindFirst((PBYTE)pattern, &hdir, FILE_NORMAL,
	    &findbuf, sizeof(findbuf), &cFilenames, FIL_STANDARD);
    while (!rc) {
        lang[nlang].id = IDM_LANGMENU + nlang + 1;
	lang[nlang].twocc[0] = findbuf.achName[lang_offset];
	lang[nlang].twocc[1] = findbuf.achName[lang_offset+1];
	lang[nlang].twocc[2] = '\0';
	if (strlen(dirname) + strlen(findbuf.achName) < 
	    sizeof(lang[nlang].dllname)-1) {
	    strcpy(lang[nlang].dllname, dirname); 
	    strcat(lang[nlang].dllname, findbuf.achName); 
 	}
	else
	    lang[nlang].id = 0;	/* can't do it */

	/* Try opening DLL */
	rc = DosLoadModule((PBYTE)buf, sizeof(buf), 
	    (PCSZ)lang[nlang].dllname, &hmodule);
	if (rc) {
	    gs_addmessf("Failed loading %s, rc=%d\n", lang[nlang].dllname, rc);
	    lang[nlang].id = 0;
	}
	else {
	    char vbuf[MAXSTR];
	    /* Make sure DLL version matches EXE */
	    memset(vbuf, 0, sizeof(vbuf));
	    WinLoadString(hab, hmodule, IDS_GSVIEWVERSION, sizeof(vbuf), 
		(unsigned char *)vbuf);
	    if (strcmp(TEXT(GSVIEW_DOT_VERSION), vbuf) != 0)
		lang[nlang].id = 0;
	    else  {
		/* Load string of language name */
		strncpy(lang[nlang].name, lang[nlang].twocc, sizeof(lang[nlang].name));
	        WinLoadString(hab, hmodule, IDS_LANGUAGE, 
		  sizeof(lang[nlang].name), (unsigned char *)lang[nlang].name);
	        WinLoadString(hab, hmodule, IDS_ELANGUAGE, 
		  sizeof(lang[nlang].ename), (unsigned char *)lang[nlang].ename);
		/* Get required code page */
	        WinLoadString(hab, hmodule, IDS_CODEPAGE, sizeof(vbuf), 
		    (unsigned char *)vbuf);
		lang[nlang].codepage = atoi(vbuf);
	    }
	    DosFreeModule(hmodule);
	}

	if (lang[nlang].id != 0) {
	    /* found a valid language */
	    nlang++;
	}

	cFilenames = 1;
	rc = DosFindNext(hdir, &findbuf, sizeof(findbuf), &cFilenames);
    }
    DosFindClose(hdir);

    return 0;
}

int language_free(void)
{
    int i;
    for (i=0; i<nlang; i++) {
	lang[i].id = 0;
	lang[i].twocc[0] = '\0';
	lang[i].dllname[0] = '\0';
    }
    return 0;
}

int language_id(const char *str)
{
    int i;
    for (i=0; i<nlang; i++) {
	if (strcmp(str, lang[i].twocc) == 0)
	    return lang[i].id;
    }
    return 0;
}

int language_lookup(int id)
{
    int i;
    for (i=0; i<nlang; i++) {
	if (id == lang[i].id)
	    return i;
    }
    return 0;
}

const char * language_twocc(int id)
{
    int i;
    for (i=0; i<nlang; i++) {
	if (id == lang[i].id)
	    return lang[i].twocc;
    }
    return "en";
}

const TCHAR * language_dllname(int id)
{
    int i;
    for (i=0; i<nlang; i++) {
	if (id == lang[i].id)
	    return lang[i].dllname;
    }
    return TEXT("");
}

/* load language dependent resources */
/* returns TRUE if language change successful */
BOOL
load_language(int language)
{
char langdll[MAXSTR];
char buf[MAXSTR];
HMODULE hmodule;
APIRET rc;

    if (language == IDM_LANGEN) {
	if (hlanguage)
	    DosFreeModule(hlanguage);
	/* Don't load a DLL - English is in main EXE resources */
	hlanguage = (HMODULE)NULL;
	/* English uses Western European code page */
	DosSetProcessCp(850);
	WinSetCp(hand_mq, 850);
	return TRUE;
    }

    strcpy(langdll, language_dllname(language));
    rc = DosLoadModule((PBYTE)buf, sizeof(buf), (PCSZ)langdll, &hmodule);
    if (!rc) {
	if (hlanguage)
	    DosFreeModule(hlanguage);
	hlanguage = hmodule;

	/* Set codepage for this language */
	DosSetProcessCp(lang[language_lookup(language)].codepage);
	WinSetCp(hand_mq, lang[language_lookup(language)].codepage);

	load_string(IDS_GSVIEWVERSION, langdll, sizeof(langdll));
	if (strcmp(GSVIEW_DOT_VERSION, langdll) != 0)
	    message_box("Language resources version doesn't match GSview EXE", 0);

	return TRUE;
    }

    return FALSE;
}

void
change_language(void)
{
char *p;
char helptitle[MAXSTR];
int i;
#define MAXCP 32
    ULONG aulCodepage[MAXCP];
    int ncp;

HWND hwndMenu;
MENUITEM mi;
MENUITEM mii;

    /* Get list of code pages supported by PM */
    ncp = WinQueryCpList(hab, MAXCP, (PULONG)aulCodepage);

    WinEnableWindowUpdate(hwnd_frame, FALSE);
    if (haccel)
	WinDestroyAccelTable(haccel);
    if (hwnd_menu)
	WinDestroyWindow(hwnd_menu);
    hwnd_menu = WinLoadMenu(hwnd_frame, hlanguage, ID_GSVIEW);

    /* User media */
    hwndMenu = WinWindowFromID(hwnd_frame, FID_MENU);
    WinSendMsg(hwndMenu, MM_QUERYITEM, 
	    MPFROM2SHORT(IDM_MEDIAMENU, TRUE), MPFROMP(&mi));
    mii.iPosition = MIT_END;
    mii.afStyle = MIS_TEXT;
    mii.afAttribute = 0;
    mii.hwndSubMenu = (HWND)NULL;
    mii.hItem = 0;
    for (i=0; i<(int)(sizeof(usermedia)/sizeof(USERMEDIA)-1); i++) {
	if (usermedia[i].name[0]) {
	    mii.id = usermedia[i].id;
	    WinSendMsg(mi.hwndSubMenu, MM_INSERTITEM, 
		(MPARAM)&mii, (MPARAM)usermedia[i].name);
	}
    }

    /* Add extra languages to menu */
    {   ULONG arCP[3];
	ULONG pcCP = 0;
	int codepage = 0;
	int i;
	char *language_name;

	if ((DosQueryCp(sizeof(arCP), arCP, &pcCP)==0) && pcCP)
	    codepage = (int)(arCP[0]);
	hwndMenu = WinWindowFromID(hwnd_frame, FID_MENU);
	WinSendMsg(hwndMenu, MM_QUERYITEM, 
		MPFROM2SHORT(IDM_LANGMENU, TRUE), MPFROMP(&mi));
	mii.iPosition = MIT_END;
	mii.afStyle = MIS_TEXT;
	mii.afAttribute = 0;
	mii.hwndSubMenu = (HWND)NULL;
	mii.hItem = 0;
	for (i=1; i<nlang; i++) {
	    mii.id = lang[i].id;
	    if (codepage && lang[i].codepage && (codepage != lang[i].codepage))
		language_name = lang[i].ename;	/* English version of name */
	    else
		language_name = lang[i].name;	/* Native name */
	    WinSendMsg(mi.hwndSubMenu, MM_INSERTITEM, 
		(MPARAM)&mii, (MPARAM)language_name);
	    if (codepage && lang[i].codepage) {
		int j;
		for (j=0; j<ncp; j++) {
		    if (aulCodepage[j] == (ULONG)(lang[i].codepage))
			break;	/* PM supports this codepage */
		}
		if (j == ncp)
		    enable_menu_item(IDM_LANGMENU, lang[i].id, FALSE);
	    }
	}
    }

    haccel = WinLoadAccelTable(hab, hlanguage, ID_GSVIEW);
    WinSetAccelTable(hab, haccel, hwnd_frame);
    frame_flags |= (FCF_MENU | FCF_ACCELTABLE);
    WinSendMsg(hwnd_frame, WM_UPDATEFRAME, (MPARAM)(frame_flags), (MPARAM)0);

    /* get path to help file */
    strcpy(szHelpName, szExePath);
    p = szHelpName + strlen(szHelpName);
    load_string(IDS_HELPFILE, p, sizeof(szHelpName) - (int)(p-szHelpName));
    load_string(IDS_HELPTITLE, helptitle, sizeof(helptitle));

    if (hwnd_help)
	WinDestroyHelpInstance(hwnd_help);
    /* create help window */
    hi_help.cb = sizeof(HELPINIT);
    hi_help.ulReturnCode = 0;
    hi_help.pszTutorialName = NULL;
    hi_help.phtHelpTable = NULL;
    hi_help.hmodAccelActionBarModule = 0;
    hi_help.idAccelTable = 0;
    hi_help.idActionBar = 0;
    hi_help.pszHelpWindowTitle=(PSZ)helptitle;
    hi_help.hmodHelpTableModule = 0;
    hi_help.fShowPanelId = 0;
    hi_help.pszHelpLibraryName = (PSZ)szHelpName;
    hwnd_help = WinCreateHelpInstance(hab, &hi_help);
    if (!hwnd_help || hi_help.ulReturnCode) {
	char buf[512];
	sprintf(buf, "WinCreateHelpInstance helpfile=%s handle=%ld, rc=%ld",  
	    szHelpName, hwnd_help, hi_help.ulReturnCode);
	message_box(buf, 0);
    }
    if (hwnd_help)
	WinAssociateHelpInstance(hwnd_help, hwnd_frame);

    nHelpTopic = IDS_TOPICROOT;
    init_check_menu();

    WinEnableWindowUpdate(hwnd_frame, TRUE);
    WinShowWindow(hwnd_frame, TRUE);
}

MRESULT EXPENTRY 
LanguageDlgProc(HWND hwnd, ULONG mess, MPARAM mp1, MPARAM mp2)
{
    switch(mess) {
	case WM_INITDLG:
	  {
	    ULONG arCP[3];
	    ULONG pcCP = 0;
	    int codepage = 0;
	    int i;
	    HWND hwndButton;
	    SWP swp;
	    char *language_name;
	    swp.fl = SWP_ACTIVATE | SWP_SIZE | SWP_SHOW;
	    if ((DosQueryCp(sizeof(arCP), arCP, &pcCP)==0) && pcCP)
		codepage = (int)(arCP[0]);
	    for (i=0; i<nlang; i++) {
		if (codepage && lang[i].codepage && (codepage != lang[i].codepage))
		    language_name = lang[i].ename;	/* English version of name */
		else
		    language_name = lang[i].name;	/* Native name */
		hwndButton = WinCreateWindow(hwnd, WC_BUTTON,
		    (PCSZ)(language_name),
		    WS_VISIBLE | WS_TABSTOP | WS_GROUP,
		    35, 16 + (nlang - 1 - i) * 32, 110, 26,
		    hwnd,
		    HWND_TOP,
		    lang[i].id,
		    NULL,
		    NULL);
		if (codepage && lang[i].codepage && 
		    (codepage != lang[i].codepage))
		    WinEnableWindow(hwndButton, FALSE);
	    }
	    swp.cx = 35 + 110 + 35 + 
		2 * WinQuerySysValue (HWND_DESKTOP, SV_CXSIZEBORDER);
	    swp.cy = 16 + nlang * 32 + 
		2 * WinQuerySysValue (HWND_DESKTOP, SV_CYSIZEBORDER) +
		WinQuerySysValue (HWND_DESKTOP, SV_CYTITLEBAR) ;
	    WinSetWindowPos(hwnd, HWND_TOP,
		0, 0, swp.cx, swp.cy, swp.fl);
	  }
	  break;
        case WM_COMMAND:
	    if ((SHORT1FROMMP(mp1) >  IDM_LANGMENU)
		&& (SHORT1FROMMP(mp1) <= IDM_LANGLAST)) {
		WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
		break;
	    }
            switch(SHORT1FROMMP(mp1)) {
		case DID_CANCEL:
                case DID_OK:
                    WinDismissDlg(hwnd, 0);
                    break;
            }
            break;
    }
    return WinDefDlgProc(hwnd, mess, mp1, mp2);
}

void 
check_language(void)
{
int language;
COUNTRYCODE pcc;
COUNTRYINFO pci;
ULONG pcbActual;
char buf[MAXSTR];
char *p;
    pcc.country = 0;	/* ask about default country */
    pcc.codepage = 0;
    if (DosQueryCtryInfo(sizeof(pci), &pcc, &pci, &pcbActual) != 0)
	return;	/* give up */

   if (pcbActual == 0)
	return;

    WinLoadString(hab, hlanguage, IDS_SLANGUAGE, sizeof(buf), 
	(unsigned char *)buf);
    p = strtok(buf, ",");
    while (p) {
	if (pci.country == (unsigned int)atoi(p))
	    return;	/* country matches GSview language */
        p = strtok(NULL, ",");
    }

    /* GSview language doesn't match country code */
    language = WinDlgBox(HWND_DESKTOP, hwnd_frame, LanguageDlgProc, 
	hlanguage, IDD_LANG, NULL);
    if (language) 
	gsview_language(language);
}

APIRET
gsview_init(int argc, char *argv[])
{
    unsigned char szClass[] = "gvBmpClass";  /* class name */
    unsigned char status_class[] = "gvStatusClass";
    unsigned char button_class[] = "gvButtonClass";
    APIRET rc = 0;

⌨️ 快捷键说明

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