--- np2/win9x/toolwin.cpp 2005/02/07 14:46:14 1.16 +++ np2/win9x/toolwin.cpp 2006/12/24 00:52:30 1.21 @@ -3,6 +3,7 @@ #include "resource.h" #include "np2.h" #include "winloc.h" +#include "oemtext.h" #include "dosio.h" #include "soundmng.h" #include "sysmng.h" @@ -48,22 +49,22 @@ enum { }; typedef struct { - char main[MAX_PATH]; - char font[64]; + OEMCHAR main[MAX_PATH]; + OEMCHAR font[64]; SINT32 fontsize; UINT32 color1; UINT32 color2; } TOOLSKIN; typedef struct { - UINT tctl; -const char *text; - short posx; - short posy; - short width; - short height; - short extend; - short padding; + UINT tctl; +const OEMCHAR *text; + short posx; + short posy; + short width; + short height; + short extend; + short padding; } SUBITEM; typedef struct { @@ -102,7 +103,7 @@ static TOOLWIN toolwin; typedef struct { - WORD idc; + UINT16 idc; UINT8 *counter; } DISKACC; @@ -117,15 +118,15 @@ static const DISKACC diskacc[3] = { // ---- -static HBITMAP skinload(const char *path) { +static HBITMAP skinload(const OEMCHAR *path) { - char fname[MAX_PATH]; + OEMCHAR fname[MAX_PATH]; UINT i; HBITMAP ret; ZeroMemory(&toolskin, sizeof(toolskin)); toolskin.fontsize = 12; - milstr_ncpy(toolskin.font, str_deffont, sizeof(toolskin.font)); + milstr_ncpy(toolskin.font, str_deffont, NELEMENTS(toolskin.font)); toolskin.color1 = 0x600000; toolskin.color2 = 0xff0000; if (path) { @@ -145,26 +146,32 @@ static HBITMAP skinload(const char *path ini_read(path, skintitle, skinini2, NELEMENTS(skinini2)); } if (toolskin.main[0]) { - milstr_ncpy(fname, path, sizeof(fname)); + milstr_ncpy(fname, path, NELEMENTS(fname)); file_cutname(fname); - file_catname(fname, toolskin.main, sizeof(fname)); - ret = (HBITMAP)LoadImage(hInst, fname, IMAGE_BITMAP, + file_catname(fname, toolskin.main, NELEMENTS(fname)); +#if defined(OSLANG_UTF8) + TCHAR tchr[MAX_PATH]; + oemtotchar(tchr, NELEMENTS(tchr), fname, -1); +#else + const TCHAR *tchr = fname; +#endif + ret = (HBITMAP)LoadImage(hInst, tchr, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (ret != NULL) { return(ret); } } - return(LoadBitmap(hInst, "NP2TOOL")); + return(LoadBitmap(hInst, _T("NP2TOOL"))); } // ---- -static void calctextsize(char *path, int leng, const char *p, int width) { +static void calctextsize(OEMCHAR *path, int leng, const OEMCHAR *p, int width) { HDC hdc; SIZE cur; - char work[MAX_PATH]; + OEMCHAR work[MAX_PATH]; int l; SIZE tail; int pos; @@ -172,7 +179,7 @@ static void calctextsize(char *path, int milstr_ncpy(path, p, leng); hdc = toolwin.hdcfont; - GetTextExtentPoint32(hdc, p, strlen(p), &cur); + GetTextExtentPoint32(hdc, p, OEMSTRLEN(p), &cur); if (cur.cx < width) { return; } @@ -181,16 +188,20 @@ static void calctextsize(char *path, int file_cutseparator(path); file_cutname(path); file_cutseparator(path); - l = strlen(path); + l = OEMSTRLEN(path); work[0] = '\0'; if (l) { - milstr_ncpy(work, str_browse, sizeof(work)); + milstr_ncpy(work, str_browse, NELEMENTS(work)); } - milstr_ncat(work, p + l, sizeof(work)); - GetTextExtentPoint32(hdc, work, strlen(work), &tail); + milstr_ncat(work, p + l, NELEMENTS(work)); + GetTextExtentPoint32(hdc, work, OEMSTRLEN(work), &tail); pos = 0; while(pos < l) { - step = ((((p[pos] ^ 0x20) - 0xa1) & 0xff) < 0x3c)?2:1; +#if defined(_UNICODE) + step = 1; +#else + step = (IsDBCSLeadByte((BYTE)p[pos]))?2:1; +#endif GetTextExtentPoint32(hdc, p, pos + step, &cur); if (cur.cx + tail.cx >= width) { break; @@ -205,35 +216,35 @@ static void calctextsize(char *path, int static void setlist(HWND hwnd, const TOOLFDD *fdd, UINT sel) { - RECT rc; - int width; - char basedir[MAX_PATH]; - UINT i; -const char *p; - char dir[MAX_PATH]; -const char *q; + RECT rc; + int width; + OEMCHAR basedir[MAX_PATH]; + UINT i; +const OEMCHAR *p; + OEMCHAR dir[MAX_PATH]; +const OEMCHAR *q; SendMessage(hwnd, CB_RESETCONTENT, (WPARAM)0, (LPARAM)0); GetClientRect(hwnd, &rc); width = rc.right - rc.left - 6; // border size? basedir[0] = '\0'; if (sel < fdd->cnt) { - milstr_ncpy(basedir, fdd->name[fdd->pos[sel]], sizeof(basedir)); + milstr_ncpy(basedir, fdd->name[fdd->pos[sel]], NELEMENTS(basedir)); file_cutname(basedir); } for (i=0; icnt; i++) { p = fdd->name[fdd->pos[i]]; - milstr_ncpy(dir, p, sizeof(dir)); + milstr_ncpy(dir, p, NELEMENTS(dir)); file_cutname(dir); if (!file_cmpname(basedir, dir)) { - q = file_getname((char *)p); + q = file_getname(p); } else { - calctextsize(dir, sizeof(dir), p, width); + calctextsize(dir, NELEMENTS(dir), p, width); q = dir; } SendMessage(hwnd, CB_INSERTSTRING, (WPARAM)i, (LPARAM)q); - p += sizeof(fdd->name[0]); + p += NELEMENTS(fdd->name[0]); } if (sel < fdd->cnt) { SendMessage(hwnd, CB_SETCURSEL, (WPARAM)sel, (LPARAM)0); @@ -261,10 +272,10 @@ static void sellist(UINT drv) { static void remakefddlist(HWND hwnd, TOOLFDD *fdd) { - char *p; + OEMCHAR *p; UINT cnt; - char *q; - char *fname[FDDLIST_MAX]; + OEMCHAR *q; + OEMCHAR *fname[FDDLIST_MAX]; UINT i; UINT j; UINT sel; @@ -285,7 +296,7 @@ static void remakefddlist(HWND hwnd, TOO fdd->pos[j] = fdd->pos[j-1]; } fdd->pos[i] = cnt; - p += sizeof(fdd->name[0]); + p += NELEMENTS(fdd->name[0]); } fdd->cnt = cnt; sel = (UINT)-1; @@ -321,7 +332,7 @@ static LRESULT CALLBACK twsub(HWND hWnd, int dir; UINT newidc; int files; - char fname[MAX_PATH]; + OEMCHAR fname[MAX_PATH]; idc = GetWindowLong(hWnd, GWL_ID) - IDC_BASE; if (idc >= IDC_MAXITEMS) { @@ -353,7 +364,13 @@ static LRESULT CALLBACK twsub(HWND hWnd, else if (msg == WM_DROPFILES) { files = DragQueryFile((HDROP)wp, (UINT)-1, NULL, 0); if (files == 1) { - DragQueryFile((HDROP)wp, 0, fname, sizeof(fname)); +#if defined(OSLANG_UTF8) + TCHAR tchr[MAX_PATH]; + DragQueryFile((HDROP)wp, 0, tchr, NELEMENTS(tchr)); + tchartooem(fname, NELEMENTS(fname), tchr, -1); +#else + DragQueryFile((HDROP)wp, 0, fname, NELEMENTS(fname)); +#endif if (idc == IDC_TOOLFDD1LIST) { diskdrv_setfdd(0, fname, 0); toolwin_setfdd(0, fname); @@ -388,17 +405,16 @@ static LRESULT CALLBACK twsub(HWND hWnd, static void toolwincreate(HWND hWnd) { - HDC hdc; -const SUBITEM *p; - UINT i; - HWND sub; -const char *cls; - DWORD style; - +#if defined(OSLANG_UTF8) + TCHAR fontface[64]; + oemtotchar(fontface, NELEMENTS(fontface), toolskin.font, -1); +#else + const TCHAR *fontface = toolskin.font; +#endif toolwin.hfont = CreateFont(toolskin.fontsize, 0, 0, 0, 0, 0, 0, 0, SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, FIXED_PITCH, toolskin.font); - hdc = GetDC(NULL); + DEFAULT_QUALITY, FIXED_PITCH, fontface); + HDC hdc = GetDC(NULL); toolwin.hdcfont = CreateCompatibleDC(hdc); ReleaseDC(NULL, hdc); SelectObject(toolwin.hdcfont, toolwin.hfont); @@ -406,10 +422,12 @@ const char *cls; toolwin.access[0] = CreateSolidBrush(0x000060); toolwin.access[1] = CreateSolidBrush(0x0000ff); - p = subitem; + const SUBITEM *p = subitem; + UINT i; for (i=0; itctl) { case TCTL_STATIC: cls = str_static; @@ -433,22 +451,28 @@ const char *cls; break; } if ((cls) && (p->width > 0) && (p->height > 0)) { - sub = CreateWindow(cls, p->text, WS_CHILD | WS_VISIBLE | style, +#if defined(OSLANG_UTF8) + TCHAR ptext[64]; + oemtotchar(ptext, NELEMENTS(ptext), p->text, -1); +#else + const TCHAR *ptext = p->text; +#endif + sub = CreateWindow(cls, ptext, WS_CHILD | WS_VISIBLE | style, p->posx, p->posy, p->width, p->height, hWnd, (HMENU)(i + IDC_BASE), hInst, NULL); } toolwin.sub[i] = sub; toolwin.subproc[i] = NULL; if (sub) { - toolwin.subproc[i] = (SUBCLASSPROC)GetWindowLong(sub, GWL_WNDPROC); - SetWindowLong(sub, GWL_WNDPROC, (LONG)twsub); + toolwin.subproc[i] = GetWindowProc(sub); + SetWindowProc(sub, twsub); SendMessage(sub, WM_SETFONT, (WPARAM)toolwin.hfont, MAKELPARAM(TRUE, 0)); } p++; } for (i=0; iname[0]); + q += NELEMENTS(fdd->name[0]); } - p = q - sizeof(fdd->name[0]); + p = q - NELEMENTS(fdd->name[0]); while(i > 0) { i--; CopyMemory(q, p, sizeof(fdd->name[0])); - p -= sizeof(fdd->name[0]); - q -= sizeof(fdd->name[0]); + p -= NELEMENTS(fdd->name[0]); + q -= NELEMENTS(fdd->name[0]); } - file_cpyname(fdd->name[0], name, sizeof(fdd->name[0])); + file_cpyname(fdd->name[0], name, NELEMENTS(fdd->name[0])); } sysmng_update(SYS_UPDATEOSCFG); if (toolwin.hwnd != NULL) { @@ -1052,51 +1082,51 @@ const DISKACC *accterm; // ---- -static const char ini_title[] = "NP2 tool"; +static const OEMCHAR ini_title[] = OEMTEXT("NP2 tool"); -static const INITBL iniitem[] = { - {"WindposX", INITYPE_SINT32, &np2tool.posx, 0}, - {"WindposY", INITYPE_SINT32, &np2tool.posy, 0}, - {"WindType", INITYPE_BOOL, &np2tool.type, 0}, - {"SkinFile", INITYPE_STR, np2tool.skin, MAX_PATH}, - {"SkinMRU0", INITYPE_STR, np2tool.skinmru[0], MAX_PATH}, - {"SkinMRU1", INITYPE_STR, np2tool.skinmru[1], MAX_PATH}, - {"SkinMRU2", INITYPE_STR, np2tool.skinmru[2], MAX_PATH}, - {"SkinMRU3", INITYPE_STR, np2tool.skinmru[3], MAX_PATH}, - {"FD1NAME0", INITYPE_STR, np2tool.fdd[0].name[0], MAX_PATH}, - {"FD1NAME1", INITYPE_STR, np2tool.fdd[0].name[1], MAX_PATH}, - {"FD1NAME2", INITYPE_STR, np2tool.fdd[0].name[2], MAX_PATH}, - {"FD1NAME3", INITYPE_STR, np2tool.fdd[0].name[3], MAX_PATH}, - {"FD1NAME4", INITYPE_STR, np2tool.fdd[0].name[4], MAX_PATH}, - {"FD1NAME5", INITYPE_STR, np2tool.fdd[0].name[5], MAX_PATH}, - {"FD1NAME6", INITYPE_STR, np2tool.fdd[0].name[6], MAX_PATH}, - {"FD1NAME7", INITYPE_STR, np2tool.fdd[0].name[7], MAX_PATH}, - {"FD2NAME0", INITYPE_STR, np2tool.fdd[1].name[0], MAX_PATH}, - {"FD2NAME1", INITYPE_STR, np2tool.fdd[1].name[1], MAX_PATH}, - {"FD2NAME2", INITYPE_STR, np2tool.fdd[1].name[2], MAX_PATH}, - {"FD2NAME3", INITYPE_STR, np2tool.fdd[1].name[3], MAX_PATH}, - {"FD2NAME4", INITYPE_STR, np2tool.fdd[1].name[4], MAX_PATH}, - {"FD2NAME5", INITYPE_STR, np2tool.fdd[1].name[5], MAX_PATH}, - {"FD2NAME6", INITYPE_STR, np2tool.fdd[1].name[6], MAX_PATH}, - {"FD2NAME7", INITYPE_STR, np2tool.fdd[1].name[7], MAX_PATH}}; +static const PFTBL iniitem[] = { + PFVAL("WindposX", PFTYPE_SINT32, &np2tool.posx), + PFVAL("WindposY", PFTYPE_SINT32, &np2tool.posy), + PFVAL("WindType", PFTYPE_BOOL, &np2tool.type), + PFSTR("SkinFile", PFTYPE_STR, np2tool.skin), + PFSTR("SkinMRU0", PFTYPE_STR, np2tool.skinmru[0]), + PFSTR("SkinMRU1", PFTYPE_STR, np2tool.skinmru[1]), + PFSTR("SkinMRU2", PFTYPE_STR, np2tool.skinmru[2]), + PFSTR("SkinMRU3", PFTYPE_STR, np2tool.skinmru[3]), + PFSTR("FD1NAME0", PFTYPE_STR, np2tool.fdd[0].name[0]), + PFSTR("FD1NAME1", PFTYPE_STR, np2tool.fdd[0].name[1]), + PFSTR("FD1NAME2", PFTYPE_STR, np2tool.fdd[0].name[2]), + PFSTR("FD1NAME3", PFTYPE_STR, np2tool.fdd[0].name[3]), + PFSTR("FD1NAME4", PFTYPE_STR, np2tool.fdd[0].name[4]), + PFSTR("FD1NAME5", PFTYPE_STR, np2tool.fdd[0].name[5]), + PFSTR("FD1NAME6", PFTYPE_STR, np2tool.fdd[0].name[6]), + PFSTR("FD1NAME7", PFTYPE_STR, np2tool.fdd[0].name[7]), + PFSTR("FD2NAME0", PFTYPE_STR, np2tool.fdd[1].name[0]), + PFSTR("FD2NAME1", PFTYPE_STR, np2tool.fdd[1].name[1]), + PFSTR("FD2NAME2", PFTYPE_STR, np2tool.fdd[1].name[2]), + PFSTR("FD2NAME3", PFTYPE_STR, np2tool.fdd[1].name[3]), + PFSTR("FD2NAME4", PFTYPE_STR, np2tool.fdd[1].name[4]), + PFSTR("FD2NAME5", PFTYPE_STR, np2tool.fdd[1].name[5]), + PFSTR("FD2NAME6", PFTYPE_STR, np2tool.fdd[1].name[6]), + PFSTR("FD2NAME7", PFTYPE_STR, np2tool.fdd[1].name[7])}; void toolwin_readini(void) { - char path[MAX_PATH]; + OEMCHAR path[MAX_PATH]; ZeroMemory(&np2tool, sizeof(np2tool)); np2tool.posx = CW_USEDEFAULT; np2tool.posy = CW_USEDEFAULT; np2tool.type = 1; - initgetfile(path, sizeof(path)); + initgetfile(path, NELEMENTS(path)); ini_read(path, ini_title, iniitem, NELEMENTS(iniitem)); } void toolwin_writeini(void) { - char path[MAX_PATH]; + OEMCHAR path[MAX_PATH]; - initgetfile(path, sizeof(path)); + initgetfile(path, NELEMENTS(path)); ini_write(path, ini_title, iniitem, NELEMENTS(iniitem)); }