#include "compiler.h"
#include <windowsx.h>
#include <shlobj.h>
#include "resource.h"
#include "dialog.h"
#include "dosio.h"
#include "mkfnt.h"
static const char fonttype_pc98[] = "PC-98 Bitmap";
static const char fonttype_v98[] = "Virtual98 (font.rom)";
static const char fonttype_pc286[] = "EPSON PC-286 Bitmap";
static const char fonttype_x1[] = "X1 (fnt*.x1)";
static const char fonttype_x68k[] = "X68000 (cgrom.dat)";
static const char *makefonttype[] = {
fonttype_pc98,
fonttype_v98,
fonttype_pc286,
fonttype_x1,
fonttype_x68k};
static int CALLBACK enumfontface(LPLOGFONT lplogfont,
LPTEXTMETRIC lptextmetric, DWORD dwtype, LPARAM lp) {
HWND hWnd;
HDC hdc;
ATOM atom;
hWnd = (HWND)lp;
hdc = GetDC(hWnd);
atom = GlobalFindAtom((LPSTR)lplogfont->lfFaceName);
if (!atom) {
atom = GlobalAddAtom(lplogfont->lfFaceName);
}
if ((lplogfont->lfCharSet & SHIFTJIS_CHARSET) &&
(lplogfont->lfPitchAndFamily & FIXED_PITCH) &&
(lplogfont->lfFaceName[0] != '@')) {
SendMessage(GetDlgItem(hWnd, IDC_FONTFACE),
CB_ADDSTRING, (WPARAM)0, (LPARAM)lplogfont->lfFaceName);
}
ReleaseDC(hWnd, hdc);
return(TRUE);
}
void init_fontface(HWND hWnd) {
HDC hdc;
HINSTANCE hinst;
FARPROC lpenumfontface;
hdc = GetDC(hWnd);
hinst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
lpenumfontface = MakeProcInstance((FARPROC)enumfontface, hinst);
EnumFonts(hdc, NULL, (FONTENUMPROC)lpenumfontface, (LPARAM)hWnd);
FreeProcInstance(lpenumfontface);
ReleaseDC(hWnd, hdc);
}
// --------------------------------------------------------------------------
static char filework[MAX_PATH + 16];
static char filework2[MAX_PATH + 16];
static int CALLBACK selectfolderproc(HWND hWnd, UINT msg,
WPARAM wp, LPARAM lp) {
switch(msg) {
case BFFM_INITIALIZED:
if (lp) {
SendMessage(hWnd, BFFM_SETSELECTION, TRUE, lp);
}
break;
}
return(FALSE);
}
static LPSTR selectfolder(HWND hWnd, LPSTR deffolder) {
char *ret;
BROWSEINFO bi;
ITEMIDLIST *idl;
LPMALLOC pMalloc;
ret = NULL;
if (SUCCEEDED(SHGetMalloc(&pMalloc))) {
bi.hwndOwner = hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = filework;
bi.lpszTitle = "フォルダを選択して下さい";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = (BFFCALLBACK)selectfolderproc;
bi.lParam = (LPARAM)deffolder;
bi.iImage = 0;
idl = SHBrowseForFolder(&bi);
if (idl != NULL) {
if (SHGetPathFromIDList(idl, filework) != FALSE) {
file_setseparator(filework, MAX_PATH);
ret = filework;
}
pMalloc->Free(idl);
}
pMalloc->Release();
}
return(ret);
}
typedef struct {
LPSTR title;
LPSTR ext;
LPSTR filter;
int defindex;
} WINUI_T;
static WINUI_T bmpsel = {
"フォントファイルの選択", "bmp",
"bitmat files (*.BMP)\0*.bmp\0", 1};
static LPSTR selectsavefile(HWND hWnd, WINUI_T *item, LPSTR defname) {
OPENFILENAME ofn;
if (defname) {
strcpy(filework, defname);
}
else {
filework[0] = '\0';
}
filework2[0] = '\0';
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = item->filter;
ofn.lpstrFile = filework;
ofn.lpstrFileTitle = filework2;
ofn.nFilterIndex = item->defindex;
ofn.nMaxFile = MAX_PATH;
ofn.nMaxFileTitle = sizeof(filework2);
ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
ofn.lpstrDefExt = item->ext;
ofn.lpstrTitle = item->title;
if (!GetSaveFileName(&ofn)) {
return(NULL);
}
return(filework);
}
// ---- init
static const char none[] = "(none)";
static const char deffont[] = "MS ゴシック";
static LRESULT init(HWND hWnd) {
int pos;
int i;
init_fontface(hWnd);
if ((int)SendDlgItemMessage(hWnd, IDC_FONTFACE, CB_GETCOUNT, 0, 0) == 0) {
SendDlgItemMessage(hWnd, IDC_FONTFACE,
CB_ADDSTRING, (WPARAM)0, (LPARAM)none);
}
pos = (int)SendDlgItemMessage(hWnd, IDC_FONTFACE,
CB_FINDSTRING, (UINT)-1, (LPARAM)deffont);
if (pos == CB_ERR) {
pos = 0;
}
ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_FONTFACE), pos);
for (i=0; i<(sizeof(makefonttype)/sizeof(char *)); i++) {
SendDlgItemMessage(hWnd, IDC_OUTDATA,
CB_INSERTSTRING, (WPARAM)i, (LPARAM)makefonttype[i]);
}
ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_OUTDATA), 0);
Edit_SetText(GetDlgItem(hWnd, IDC_DIREDIT), file_getcd(""));
return(0);
}
// ---- command
static void cmd_ok(HWND hWnd) {
char *p;
char fontpath[MAX_PATH];
char fontface[128];
UINT sel;
HCURSOR hcur;
HCURSOR hcurbak;
Edit_GetText(GetDlgItem(hWnd, IDC_DIREDIT), fontpath, MAX_PATH);
Edit_GetText(GetDlgItem(hWnd, IDC_FONTFACE), fontface, sizeof(fontface));
sel = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_OUTDATA));
hcurbak = GetCursor();
hcur = LoadCursor(NULL, IDC_WAIT);
SetCursor(hcur);
switch(sel) {
case 0: // 98bmp
strcat(fontpath, "font.bmp");
p = selectsavefile(hWnd, &bmpsel, fontpath);
if (p) {
makepc98bmp(p, fontface, FALSE);
}
break;
case 1: // virtual98
// makev98fontrom(fontpath, fontface);
makev98font(fontpath, fontface);
break;
case 2: // epson
strcat(fontpath, "font286.bmp");
p = selectsavefile(hWnd, &bmpsel, fontpath);
if (p) {
makepc98bmp(p, fontface, TRUE);
}
break;
case 3: // x1
makex1font(fontpath, fontface);
break;
case 4: // x68000
// makecgromdat(fontpath, fontface);
makex68kfont(fontpath, fontface);
break;
}
SetCursor(hcurbak);
}
static void cmd_dirbrowse(HWND hWnd) {
char *p;
char fontpath[MAX_PATH];
Edit_GetText(GetDlgItem(hWnd, IDC_DIREDIT), fontpath, MAX_PATH);
file_cutseparator(fontpath);
p = selectfolder(hWnd, fontpath);
if (p) {
Edit_SetText(GetDlgItem(hWnd, IDC_DIREDIT), p);
}
}
LRESULT CALLBACK mkfontproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_INITDIALOG:
return(init(hWnd));
case WM_COMMAND:
switch (LOWORD(wp)) {
case IDOK:
cmd_ok(hWnd);
EndDialog(hWnd, IDOK);
break;
case IDCANCEL:
EndDialog(hWnd, IDCANCEL);
break;
case IDC_DIRBROWSE:
cmd_dirbrowse(hWnd);
return(FALSE);
}
break;
case WM_CLOSE:
PostMessage(hWnd, WM_COMMAND, IDCANCEL, 0);
break;
default:
return(FALSE);
}
return(TRUE);
}
RetroPC.NET-CVS <cvs@retropc.net>