📄 gvwdlg.c
字号:
/* 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.
*/
/* gvwdlg.c */
/* Dialog boxes for Windows GSview */
#include "gvwin.h"
void
centre_dialog(HWND hwnd)
{
/* centre dialog on screen */
int left = 0;
int top = 0;
int width = GetSystemMetrics(SM_CXFULLSCREEN);
int height = GetSystemMetrics(SM_CYFULLSCREEN);
RECT rect;
if (number_of_displays > 1) {
/* Put it on the first display */
left = first_display.left;
top = first_display.top;
width = first_display.width;
height = first_display.height;
}
GetWindowRect(hwnd, &rect);
MoveWindow(hwnd, left+(width - (rect.right - rect.left))/2,
top+(height - (rect.bottom - rect.top))/2,
(rect.right - rect.left),
(rect.bottom - rect.top), FALSE);
}
BOOL
get_filename(char *filename, BOOL save, int filter, int title, int help)
{
LPTSTR old_lpstrFile;
LPCTSTR old_lpstrTitle;
TCHAR szFileName[MAXSTR];
TCHAR szTitle[MAXSTR];
BOOL flag;
LPCTSTR old_lpstrFilter;
TCHAR szFilter[1024]; /* filter for OFN */
int i;
TCHAR cReplace;
#if defined(VIEWONLY)
save = FALSE;
#endif
if (help)
nHelpTopic = help;
old_lpstrTitle = ofn.lpstrTitle;
if (title) {
load_string(title, szTitle, sizeof(szTitle));
ofn.lpstrTitle = szTitle;
}
old_lpstrFile = ofn.lpstrFile;
if (filename != (LPSTR)NULL) {
convert_multibyte(szFileName, filename,
sizeof(szFileName)/sizeof(TCHAR));
ofn.lpstrFile = szFileName;
}
/* Get filter types */
old_lpstrFilter = ofn.lpstrFilter;
ofn.nFilterIndex = 0;
if (load_string(IDS_FILTER_BASE+filter, szFilter, sizeof(szFilter)-1)) {
cReplace = szFilter[lstrlen(szFilter)-1];
for (i=0; szFilter[i] != '\0'; i++)
if (szFilter[i] == cReplace)
szFilter[i] = '\0';
ofn.lpstrFilter = szFilter;
ofn.nFilterIndex = 0;
}
/* call the common dialog box */
#ifdef UNICODE
if (save)
flag = GetSaveFileName(&ofn);
else
flag = GetOpenFileName(&ofn);
#else
flag = GetOpenSaveFileNameL(&ofn, save);
#endif
if (flag)
convert_widechar(filename, ofn.lpstrFile, MAXSTR-1);
ofn.lpstrTitle = old_lpstrTitle;
ofn.lpstrFile = old_lpstrFile;
ofn.lpstrFilter = old_lpstrFilter;
ofn.nFilterIndex = 0;
if ( save && flag &&
(psfile.name[0]!='\0') && (strcmp(filename, psfile.name) == 0) ) {
gserror(IDS_NOTDFNAME, NULL, MB_ICONEXCLAMATION, SOUND_ERROR);
flag = FALSE;
}
/* GetOpenFileName() should change current directory */
/* Deal with broken Win32 that doesn't do this */
if (flag)
make_cwd(filename);
return flag;
}
/* Input Dialog Box structures */
LPCTSTR input_prop = TEXT("input_prop");
struct input_param {
LPCTSTR prompt;
TCHAR answer[MAXSTR];
};
/* input string dialog box */
BOOL CALLBACK _export
InputDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_INITDIALOG:
{
HLOCAL hlocal;
LPTSTR *panswer;
struct input_param *pparam = (struct input_param *)lParam;
SetDlgItemText(hDlg, ID_PROMPT, pparam->prompt);
SetDlgItemText(hDlg, ID_ANSWER, pparam->answer);
/* save address of answer string in property list */
hlocal = LocalAlloc(LHND, sizeof(pparam->answer));
panswer = (LPTSTR *)LocalLock(hlocal);
if (panswer != (LPTSTR *)NULL) {
*panswer = pparam->answer;
LocalUnlock(hlocal);
SetProp(hDlg, input_prop, (HANDLE)hlocal);
}
}
return( TRUE);
case WM_COMMAND:
switch(LOWORD(wParam)) {
case ID_HELP:
get_help();
return(FALSE);
case ID_ANSWER:
return(TRUE);
case IDOK:
{
HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop);
LPTSTR *panswer;
panswer = (LPTSTR *)LocalLock(hlocal);
if (panswer != (LPTSTR *)NULL) {
GetDlgItemText(hDlg, ID_ANSWER, *panswer, MAXSTR);
LocalUnlock(hlocal);
}
LocalFree(hlocal);
RemoveProp(hDlg, input_prop);
}
EndDialog(hDlg, TRUE);
return(TRUE);
case IDCANCEL:
{
HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop);
LocalFree(hlocal);
RemoveProp(hDlg, input_prop);
}
EndDialog(hDlg, FALSE);
return(TRUE);
default:
return(FALSE);
}
default:
return(FALSE);
}
}
BOOL
query_string(LPCTSTR prompt, char *answer)
{
struct input_param param;
BOOL flag;
convert_multibyte(param.answer, answer,
sizeof(param.answer)/sizeof(TCHAR));
param.prompt = prompt;
flag = DialogBoxParamL(hlanguage, MAKEINTRESOURCE(IDD_INPUT),
hwndimg, InputDlgProc, (LPARAM)¶m);
if (flag)
convert_widechar(answer, param.answer, MAXSTR-1);
return flag;
}
void
wwait(void)
{
MSG msg;
DWORD start = GetTickCount();
DWORD end = start + 70;
while ( (GetTickCount() <= end) && (GetTickCount() >= start) ) {
while (PeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
/* copyright dialog box */
BOOL CALLBACK _export
AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_INITDIALOG:
SetDlgItemText(hDlg, ABOUT_VERSION, TEXT(GSVIEW_DOT_VERSION));
SetDlgItemText(hDlg, NAG_NAME, registration_name);
if (registration_receipt != 0) {
TCHAR buf[16];
wsprintf(buf, TEXT("%u"), registration_receipt);
SetDlgItemText(hDlg, NAG_RECEIPT, buf);
}
return( TRUE);
case WM_LBUTTONDOWN:
{
HWND hwicon = GetDlgItem(hDlg, ABOUT_ICON);
HICON hicon1 = LoadIcon(phInstance, MAKEINTRESOURCE(ID_GSVIEW));
HICON hicon2 = LoadIcon(phInstance, MAKEINTRESOURCE(ID_GSVIEW2));
HICON hicon3 = LoadIcon(phInstance, MAKEINTRESOURCE(ID_GSVIEW3));
HDC hdc = GetDC(hwicon);
RECT rect; POINT pt;
pt.x = LOWORD(lParam); pt.y = HIWORD(lParam);
ClientToScreen(hDlg, &pt);
GetWindowRect(hwicon, &rect);
if (PtInRect(&rect,pt)) {
DrawIcon(hdc, 0, 0, hicon2);
wwait();
DrawIcon(hdc, 0, 0, hicon3);
wwait();
wwait();
DrawIcon(hdc, 0, 0, hicon2);
wwait();
DrawIcon(hdc, 0, 0, hicon1);
}
DestroyIcon(hicon1);
DestroyIcon(hicon2);
DestroyIcon(hicon3);
ReleaseDC(hwicon, hdc);
}
return FALSE;
case WM_LBUTTONDBLCLK:
{DWORD dwUnit = GetDialogBaseUnits();
RECT rect; POINT pt;
pt.x = LOWORD(lParam); pt.y = HIWORD(lParam);
/* this is for 8pt dialog fonts */
rect.left = 8 * LOWORD(dwUnit) / 5;
rect.top = 166 * HIWORD(dwUnit) / 10;
rect.right = 240 * LOWORD(dwUnit) / 5 + rect.left;
rect.bottom = 10 * HIWORD(dwUnit) / 10 + rect.top;
#ifdef NOTUSED
/* this is for 10pt dialog fonts */
rect.left = 8 * LOWORD(dwUnit) / 4;
rect.top = 166 * HIWORD(dwUnit) / 8;
rect.right = 240 * LOWORD(dwUnit) / 4 + rect.left;
rect.bottom = 8 * HIWORD(dwUnit) / 8 + rect.top;
#endif
if (PtInRect(&rect,pt)) {
BITMAP bm;
HBITMAP hbitmap_old;
HBITMAP hbitmap = LoadBitmap(phInstance,TEXT("gsview_bitmap"));
HDC hdc = GetDC(hDlg);
HDC hdcsrc = CreateCompatibleDC(hdc);
hbitmap_old = (HBITMAP)SelectObject(hdcsrc,hbitmap);
GetObject(hbitmap, sizeof(BITMAP),&bm);
BitBlt(hdc, rect.right-bm.bmWidth,rect.bottom-bm.bmHeight,
bm.bmWidth,bm.bmHeight,hdcsrc,0,0,SRCCOPY);
SelectObject(hdcsrc,hbitmap_old);
DeleteObject(hbitmap);
DeleteDC(hdcsrc);
ReleaseDC(hDlg,hdc);
}
}
return FALSE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDCANCEL:
case IDOK:
EndDialog(hDlg, TRUE);
return(TRUE);
default:
return(FALSE);
}
default:
return(FALSE);
}
}
void
show_about()
{
DialogBoxParamL(hlanguage, MAKEINTRESOURCE(IDD_ABOUT), hwndimg,
AboutDlgProc, (LPARAM)NULL);
}
#ifdef __BORLANDC__
#pragma argsused
#endif
/* information about document dialog box */
BOOL CALLBACK _export
InfoDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_INITDIALOG:
SendDlgItemMessage(hDlg, INFO_FILE, WM_SETFONT, (WPARAM)info_font, 1);
info_init(hDlg);
SendDlgItemMessage(hDlg, INFO_FILE, WM_SETFONT, (WPARAM)info_font, 1);
return( TRUE);
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK:
EndDialog(hDlg, TRUE);
return(TRUE);
case IDCANCEL:
EndDialog(hDlg, FALSE);
return(TRUE);
default:
return(FALSE);
}
default:
return(FALSE);
}
}
/* show info about ps file */
void
show_info()
{
DialogBoxParamL(hlanguage, MAKEINTRESOURCE(IDD_INFO),
hwndimg, InfoDlgProc, (LPARAM)NULL);
}
#define MAX_SYSTEM_SOUND 16
TCHAR *system_sounds;
TCHAR *sound_entry[MAX_SYSTEM_SOUND];
TCHAR szNone[32];
TCHAR szSpeaker[32];
int system_num;
BOOL CALLBACK _export SoundDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam);
int
load_sounds(void)
{
/* add our two sounds */
sound_entry[0] = TEXT("");
sound_entry[1] = TEXT(BEEP);
load_string(IDS_NONE, szNone, sizeof(szNone));
load_string(IDS_SPKR, szSpeaker, sizeof(szSpeaker));
#ifndef UNICODE
if (is_win32s) {
/* get list of system sounds */
char *p;
int j;
system_sounds = (char *)malloc(PROFILE_SIZE);
if (system_sounds != (char *)NULL) {
GetProfileString("sounds", NULL, "", system_sounds,
PROFILE_SIZE);
}
p = system_sounds;
for (j=2; p!=(char *)NULL && j<MAX_SYSTEM_SOUND && strlen(p)!=0;
j++) {
/* Windows NT uses "Enable=1" in the sounds section */
/* We need to prevent this from appearing in the */
/* list of sounds */
if (strcmp(p, "Enable") == 0)
j--;
else
sound_entry[j] = p;
p += strlen(p) + 1;
}
system_num = j;
}
else
#endif
{
/* It is difficult to get the names of Windows system sounds */
/* for Windows 4 and later */
system_num = 2;
}
return system_num;
}
TCHAR *
get_sound_entry(int index)
{
return (sound_entry[index]);
}
TCHAR *
get_sound_name(int index)
{
static char buf[64];
TCHAR *p;
if (index==0)
return szNone;
if (index==1)
return szSpeaker;
#ifndef UNICODE
if (is_win32s) {
GetProfileString("sounds", sound_entry[index], ",",
buf, sizeof(buf));
p = strchr(buf,',');
if (p != (char *)NULL)
return p+1;
}
#endif
return (TCHAR *)NULL;
}
int
find_sound_name(TCHAR *entry)
{
int i;
for (i=0; i<system_num; i++) {
if (lstrcmp(entry, sound_entry[i])==0)
return i;
}
return -1; /* no find */
}
void
add_sounds(HWND hDlg)
{
int ifile;
TCHAR *p;
for (ifile=system_num-1; ifile>=0; ifile--) {
p = get_sound_name(ifile);
if (p != (TCHAR *)NULL)
SendDlgItemMessageL(hDlg, SOUND_FILE, LB_INSERTSTRING, 0,
(LPARAM)(LPTSTR)p);
}
}
void
free_sounds(void)
{
if (system_sounds != (TCHAR *)NULL)
free(system_sounds);
}
void
change_sounds(void)
{
nHelpTopic = IDS_TOPICSOUND;
DialogBoxParamL(hlanguage, MAKEINTRESOURCE(IDD_SOUND), hwndimg,
SoundDlgProc, (LPARAM)NULL);
}
#ifdef __BORLANDC__
#pragma argsused
#endif
BOOL CALLBACK _export
SoundDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
{
TCHAR buf[MAXSTR];
int ievent, ifile;
static struct sound_s dsound[NUMSOUND]; /* copy of sound[] */
WORD notify_message;
const TCHAR *szWaveFilter = TEXT("*.wav");
static TCHAR szPath[MAXSTR];
static int file_start;
TCHAR *p;
switch (wmsg) {
case WM_INITDIALOG:
file_start = load_sounds();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -