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

📄 gvwin.c

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

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

TCHAR szAppName[MAXSTR] = TEXT(GSVIEW_PRODUCT);  /* application name - for title bar */
TCHAR szExePath[MAXSTR];
char szIniFile[MAXSTR];
TCHAR szWait[MAXSTR];
char szFindText[MAXSTR];
char previous_filename[MAXSTR];
char selectname[MAXSTR];
const TCHAR szClassName[] = TEXT("gsview_class");
const TCHAR szImgClassName[] = TEXT("gsview_img_class");
const char szScratch[] = "gsview";	/* temporary filename prefix */
char *szSpoolPrefix = "\\\\spool\\";

HWND hwndimg;			/* gsview main window */
HWND hDlgModeless;		/* any modeless dialog box */
HWND hwnd_measure;		/* measure modelss dialog box */
HWND hwnd_fullscreen;		/* full screen popup of child window */
HWND hwnd_image;		/* full screen or image child window */	
HWND hwndimgchild;		/* gswin image child window */
HWND hwndspl;			/* window handle of gsv16spl.exe */
HINSTANCE phInstance;		/* instance of gsview */
HINSTANCE hlanguage;		/* instance of language resources */
UINT nCodePageLanguage;		/* Code page of the GSview language */
UINT nCodePageSystem;		/* Code page of the system */

#define MAXARGS 64
int nargc;
char *nargv[MAXARGS];
GSVIEW_ARGS args;		/* Parsed arguments */
PSFILE psfile;		/* Postscript file structure */
PRINTER printer;	/* Ghostscript printer structure */
BOOL win32s_printer_pending = FALSE;
BMAP bitmap;		/* information about display bitmap */
OPTIONS option;		/* GSview options (saved in INI file) */
DISPLAY display;	/* Display parameters */
char last_files[4][MAXSTR];	/* last 4 files used */
int last_files_count;		/* number of files known */
HISTORY history;		/* history of pages displayed */
BOOL fullscreen = FALSE;
HCURSOR hCursorArrow;
HPEN hpen_btnshadow;		/* button shadow */
HPEN hpen_btnhighlight;		/* button highlight */
HBRUSH hbrush_window;		/* Window background */
HBRUSH hbrush_menu;		/* menu background */

struct sound_s sound[NUMSOUND] = {
	{"SoundOutputPage", IDS_SNDPAGE, TEXT("")},
	{"SoundNoPage", IDS_SNDNOPAGE, TEXT(BEEP)},
	{"SoundNoNumbering", IDS_SNDNONUMBER, TEXT("")},
	{"SoundNotOpen", IDS_SNDNOTOPEN, TEXT("")},
	{"SoundError", IDS_SNDERROR, TEXT(BEEP)},
	{"SoundStart", IDS_SNDSTART, TEXT("")},
	{"SoundExit", IDS_SNDEXIT, TEXT("")},
	{"SoundBusy", IDS_SNDBUSY, TEXT(BEEP)},
};
USERMEDIA usermedia[IDM_USERSIZE13 - IDM_USERSIZE1 + 1];

/* initialised in init.c */
BOOL is_winnt = FALSE;		/* To allow selective use of Windows NT features */
BOOL is_win95 = FALSE;		/* To allow selective use of Windows 95 features */
BOOL is_win98 = FALSE;		/* To allow selective use of Windows 98 features */
BOOL is_win32s = FALSE;		/* To allow selective use of Win32s misfeatures */
BOOL is_win4;			/* To allow selective use of Windows 4.0 features */
BOOL multithread = FALSE;
CRITICAL_SECTION crit_sec;	/* for thread synchronization */
HANDLE hmutex_ps;		/* for protecting psfile and pending */
TCHAR szHelpName[MAXSTR];	/* buffer for building help filename */
int nHelpTopic;			/* topic for OFN_SHOWHELP */
UINT help_message;		/* message sent by OFN_SHOWHELP */
HMENU hmenu;			/* main menu */
HACCEL haccel;			/* menu accelerators */
HCURSOR hcWait;
HCURSOR hcCrossHair;
HCURSOR hcHand;
POINT img_offset;		/* offset to gswin child window */
HFONT info_font;		/* font for info line */
HFONT hFontAnsi;		/* ANSI (Western European) font */
HFONT hFontGreek;		/* cp 1253 / Greek font */
HFONT hFontEastEurope;		/* ISO-Latin2 / cp1250 font */
HFONT hFontCyrillic;		/* Windows Cyrillic / cp1251 font */
POINT info_file;		/* position of file information */
POINT info_page;		/* position of page information */
RECT  info_rect;		/* position and size of brief info area */
RECT  info_coord;		/* position and size of coordinate information */
RECT  button_rect;		/* position and size of button area */
int on_link;			/* TRUE if we were or are over link */
int on_link_page;		/* page number of link target */
const char *on_link_action;	/* action of link target */
long gsbytes_size;		/* number of bytes for this page */
long gsbytes_done;		/* number of byte written */
BOOL fit_page_enabled = FALSE;	/* next WM_SIZE is allowed to resize window */

BOOL prev_in_child;		/* true if cursor previously in gswin child window */
int page_skip = 5;		/* number of pages to skip in IDM_NEXTSKIP or IDM_PREVSKIP */
BOOL zoom = FALSE;		/* true if display zoomed */
int debug = 0;			/* /D command line option used */
BOOL print_silent = FALSE;	/* /P or /F command line option used */
BOOL print_exit = FALSE;	/* exit on completion of printing */
int print_count = 0;		/* number of current print jobs */
				/* It is safe to exit GSview when this is 0 */
HINSTANCE hlib_mmsystem;	/* DLL containing sndPlaySound function */
FPSPS lpfnSndPlaySound;		/* pointer to sndPlaySound function if loaded */
BOOL quitnow = FALSE;		/* Used to cause exit from nested message loops */

int percent_done;		/* percentage of document processed */
int percent_pending;		/* TRUE if WM_GSPERCENT is pending */

int number_of_displays = 1; /* number of active displays */
DISPLAY_INFO first_display;
DISPLAY_INFO last_display;

#if (WINVER < 0x0400)
/* Windows 4.0 scroll bar extras */
#define SIF_RANGE           0x01
#define SIF_PAGE            0x02
#define SIF_POS             0x04
#define SIF_DISABLENOSCROLL 0x08
#define SIF_TRACKPOS        0x10
#define SIF_ALL             (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS)
#define SBM_SETSCROLLINFO 0x00E9
#define SBM_GETSCROLLINFO 0x00EA

typedef struct tagSCROLLINFO {
    UINT cbSize;
    UINT fMask;
    int nMin;
    int nMax;
    UINT nPage;
    int nPos;
    int nTrackPos;
} SCROLLINFO;
typedef SCROLLINFO FAR *LPSCROLLINFO;
/*
WINUSERAPI int WINAPI SetScrollInfo(HWND, int, LPSCROLLINFO, BOOL);
WINUSERAPI int WINAPI GetScrollInfo(HWND, int, LPSCROLLINFO);
*/
#endif

typedef int (WINAPI *PFN_SetScrollInfo)(HWND, int, LPSCROLLINFO, BOOL);
PFN_SetScrollInfo pSetScrollInfo;
HMODULE hmodule_user32;

BOOL
load_SetScrollInfo(void)
{
    /* Instead of linking to SetScrollInfo at load time,
     * we instead do it at run time.
     * This allows us to produce an EXE that will run under
     * Windows 3.1 and Windows 4.0
     */
    if (!is_win4)
	return FALSE;
    hmodule_user32 = LoadLibrary(TEXT("USER32.DLL"));
    if (hmodule_user32 < (HINSTANCE)HINSTANCE_ERROR) {
	hmodule_user32 = (HINSTANCE)NULL;
        return FALSE;
    }
    pSetScrollInfo = (PFN_SetScrollInfo) GetProcAddress(hmodule_user32, "SetScrollInfo");
    if (!pSetScrollInfo)
        return FALSE;
    return TRUE;
}

void
free_SetScrollInfo(void) 
{
    if (!hmodule_user32)
	return;
    pSetScrollInfo = (PFN_SetScrollInfo)NULL;
    FreeLibrary(hmodule_user32);
    hmodule_user32 = (HINSTANCE)NULL;
}


/* local functions */
BOOL draw_button(DRAWITEMSTRUCT FAR *lpdis);
BOOL in_child_client_area(void);
BOOL in_client_area(void);
BOOL in_info_area(void);
void info_paint(HWND, HDC);
void cursorpos_paint(HDC hdc);
void gsview_close(void);
BOOL query_close(void);
void update_scroll_bars(void);
void gs_thread(void *arg);
void map_pt_to_pixel(float *x, float *y);
void enable_menu_item(int menuid, int itemid, BOOL enabled);
void end_button_help(void);

#ifndef VIEWONLY
void highlight_words(HDC hdc, int first, int last);
BOOL text_marking = FALSE;
int text_mark_first = -1;
int text_mark_last = -1;
#endif

void highlight_links(HDC hdc);
void info_link(void);
int win_get_args(int *argc, char **argv, int maxarg, char *cmdline);

#ifndef MEMORYFILE
int PASCAL 
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int cmdShow)
{
    LPSTR pcmdline = GetCommandLineA();
    return gsview_main(hInstance, pcmdline);
}
#endif

int gsview_main(HINSTANCE hInstance, LPSTR lpszCmdLine)
{
    MSG msg;
    DWORD dwHelpCookie = 0;
    char *cmdline;

    /* copy the hInstance into a variable so it can be used */
    phInstance = hInstance;

    dde_initialise();
    cmdline = (char *)malloc(strlen(lpszCmdLine)+1);
    if (cmdline == NULL)
	return 0;
    strcpy(cmdline, lpszCmdLine);
    win_get_args(&nargc, nargv, MAXARGS, cmdline);

    if (!gsview_init1(nargc, nargv)) {
	dde_uninitialise();
	return FALSE;
    }

    /* don't start the DDE server until after we have parsed the 
     * command line, otherwise we could end up talking to ourselves
     * instead of a separate copy of GSview
     */
    dde_enable_server(TRUE);

    load_SetScrollInfo();
    if (print_silent) {
	ShowWindow(hwndimg, SW_SHOWMINNOACTIVE);
    }
    else
    {   STARTUPINFO sti;
	GetStartupInfo(&sti);
	ShowWindow(hwndimg, option.img_max && (sti.wShowWindow == SW_SHOWNORMAL) 
	    ? SW_SHOWMAXIMIZED : SW_SHOWDEFAULT);
    }
    info_wait(IDS_NOWAIT);
    if (gsview_changed())
	PostQuitMessage(0);
    else if (!print_silent)
	// before changing following line, please see gvcreg.cpp
	registration_check();

    if (multithread) {
	/* start thread for displaying */
	display.tid = _beginthread(gs_thread, 131072, NULL);
    }
#ifdef USE_HTMLHELP
    HtmlHelp(hwndimg, NULL, HH_INITIALIZE, (DWORD)&dwHelpCookie);
#endif
    
    while (!(!multithread && quitnow)
	     && GetMessage(&msg, (HWND)NULL, 0, 0)) {
	if ( ((hDlgModeless == 0) || !IsDialogMessage(hDlgModeless, &msg)) 
	  && ((hwnd_measure == 0) || !IsDialogMessage(hwnd_measure, &msg)) 
	   ) {
#ifdef USE_HTMLHELP
	    if (!HtmlHelp(NULL, NULL, HH_PRETRANSLATEMESSAGE, (DWORD)(&msg))) { 
#endif
		if (!TranslateAccelerator(hwndimg, haccel, &msg)) {
		    TranslateMessage(&msg);
		    DispatchMessage(&msg);
		}
#ifdef USE_HTMLHELP
	    }
#endif
	}
	if (multithread) {
	    /* release other thread if needed */
	    if (pending.unload || pending.now || pending.next || quitnow)
		SetEvent(display.event);
	}
	else 
	{
	    if (pending.now) {
		if (is_win95 || is_winnt)
		    gs_process();	/* start Ghostscript */
		else {
		    /* Win32s can't start gs_process while printing */
		    /* Check if gvwgs.exe is running */
		    HWND hwndprn = FindWindow(NULL, TEXT("GSview Print"));
		    if (IsWindow(hwndprn)) {
			pending.now = FALSE;
			gserror(0, "Busy printing.  Win32s can't use Ghostscript for displaying while it is being used for printing. Try again when 'GSview Print' has finished.", MB_ICONEXCLAMATION, SOUND_ERROR);
		    }
		    if (pending.now)
			gs_process();	/* start Ghostscript */
		}
		update_scroll_bars();
	    }
	}
#ifndef VIEWONLY
	if (
	    is_win32s && 
	    win32s_printer_pending) {
	    /* Win32s can't load GS DLL twice */
	    /* so we must run it while display GS DLL is unloaded */
	    start_gvwgs();
	    win32s_printer_pending = FALSE;
	    /* We can't stop the user attempting to display while */
	    /* printing since we don't know when printer finished */
	    /* We'll see how much of a problem this causes */
	}
#endif
    }

    dde_uninitialise();

    play_sound(SOUND_EXIT);
    gsview_close();
    DestroyWindow(hwndimg);
    hwndimg = HWND_DESKTOP;
#ifndef VIEWONLY
    printer_cleanup();
#endif
    delete_buttons();
    free_SetScrollInfo();
#ifdef USE_HTMLHELP
    HtmlHelp(hwndimg,szHelpName, HH_UNINITIALIZE, (DWORD)dwHelpCookie);
    gs_addmessf("HtmlHelp: %s HH_CLOSE_ALL\n", szHelpName);
#else
    WinHelp(hwndimg,szHelpName,HELP_QUIT,(DWORD)NULL);
#endif
    if (hlib_mmsystem != (HINSTANCE)NULL)
	FreeLibrary(hlib_mmsystem);
    if ((hlanguage != (HINSTANCE)NULL) && (hlanguage != phInstance))
	FreeLibrary(hlanguage);

#ifdef DEBUG_MALLOC
    if (malloc_file)
	fclose(malloc_file);
#endif

    if (debug & DEBUG_MEM) {
	while (PeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE))
	    /* clear quit message */;
	debug_memory_report();
    }
    return 0;
}



/* child image window */
LRESULT CALLBACK _export
WndImgChildProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{	
    HDC hdc;
    PAINTSTRUCT ps;
    RECT rect;
    int nVscrollInc, nHscrollInc;
    static int cxAdjust, cyAdjust;
    static int cxClient, cyClient;
    static int nHscrollPos, nHscrollMax;
    static int nVscrollPos, nVscrollMax;

    switch(message) {
	    case WM_CREATE:
		    cxClient = cyClient = 0;
		    nHscrollPos = nHscrollMax = 0;
		    nVscrollPos = nVscrollMax = 0;
		    break;
	    case WM_DESTROY:
		    hwnd_image = hwndimgchild;
		    fullscreen = FALSE;
		    if ((hwnd == hwnd_fullscreen) && image.open) {
			ShowWindow(hwnd_image, SW_SHOWNA);
			update_scroll_bars();
			InvalidateRect(hwnd_image, (LPRECT)NULL, FALSE);
			UpdateWindow(hwnd_image);
			if (debug)
			    gs_addmess("Full Screen finished\r\n");
		    }
		    hwnd_fullscreen = (HWND)NULL;
		    break;
	    case WM_SIZE:
		    if (wParam == SIZE_MINIMIZED)
			    return(0);
		    cyClient = HIWORD(lParam);
		    cxClient = LOWORD(lParam);

#ifdef OLD
		    cyAdjust = min(image.height, cyClient) - cyClient;
		    cyClient += cyAdjust;
#else
		    if (image.height < cyClient) {
			/* shrink window */
			cyAdjust = image.height - cyClient;
		    }
		    else {
			if (!fullscreen && fit_page_enabled) {
			    /* We just got a GSDLL_SIZE and option.fitpage 
			     * was TRUE enlarge window to smaller of bitmap 
			     * height and height if client extended to 
			     * bottom of screen
			     */
			    GetWindowRect(GetParent(hwnd),&rect);
			    cyAdjust = min(image.height, 
				cyClient + GetSystemMetrics(SM_CYFULLSCREEN) + 
				GetSystemMetrics(SM_CYCAPTION) - rect.bottom)
				- cyClient;
			}

⌨️ 快捷键说明

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