--- np2/win9x/toolwin.cpp 2003/10/30 22:33:34 1.10 +++ np2/win9x/toolwin.cpp 2007/12/28 20:36:40 1.25 @@ -2,18 +2,24 @@ #include "strres.h" #include "resource.h" #include "np2.h" +#include "winloc.h" +#include "oemtext.h" #include "dosio.h" #include "soundmng.h" #include "sysmng.h" #include "menu.h" #include "toolwin.h" #include "ini.h" +#include "np2class.h" #include "dialog.h" #include "dialogs.h" #include "pccore.h" #include "diskdrv.h" +extern WINLOCEX np2_winlocexallwin(HWND base); + + enum { IDC_TOOLHDDACC = 0, IDC_TOOLFDD1ACC, @@ -28,12 +34,7 @@ enum { IDC_TOOLPOWER, IDC_MAXITEMS, - IDC_BASE = 3000, - - IDC_SKINSEL = 3100, - IDC_SKINDEF = 3101, - IDC_SKINMRU = 3102, - IDC_TOOLCLOSE = IDC_SKINMRU + SKINMRU_MAX + IDC_BASE = 3000 }; enum { @@ -43,30 +44,31 @@ 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 { HWND hwnd; + WINLOCEX wlex; HBITMAP hbmp; - BYTE fddaccess[2]; - BYTE hddaccess; - BYTE _padding; + UINT8 fddaccess[2]; + UINT8 hddaccess; + UINT8 _padding; int winflg; int wingx; int wingy; @@ -82,10 +84,8 @@ typedef struct { SUBCLASSPROC subproc[IDC_MAXITEMS]; } TOOLWIN; -enum { - GTWL_FOCUS = 0, - GTWL_SIZE = 4 -}; +#define GTWLP_FOCUS (NP2GWLP_SIZE + (0 * sizeof(LONG_PTR))) +#define GTWLP_SIZE (NP2GWLP_SIZE + (1 * sizeof(LONG_PTR))) NP2TOOL np2tool; static TOOLSKIN toolskin; @@ -96,11 +96,11 @@ static TOOLWIN toolwin; typedef struct { - WORD idc; - BYTE *counter; + UINT16 idc; + UINT8 *counter; } DISKACC; -static const BYTE fddlist[FDDLIST_DRV] = { +static const UINT8 fddlist[FDDLIST_DRV] = { IDC_TOOLFDD1LIST, IDC_TOOLFDD2LIST}; static const DISKACC diskacc[3] = { @@ -111,19 +111,19 @@ 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) { - ini_read(path, skintitle, skinini1, sizeof(skinini1)/sizeof(INITBL)); + ini_read(path, skintitle, skinini1, NELEMENTS(skinini1)); } if (toolskin.main[0]) { ZeroMemory(subitem, sizeof(defsubitem)); @@ -136,29 +136,35 @@ static HBITMAP skinload(const char *path CopyMemory(subitem, defsubitem, sizeof(defsubitem)); } if (path) { - ini_read(path, skintitle, skinini2, sizeof(skinini2)/sizeof(INITBL)); + 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(g_hInstance, tchr, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (ret != NULL) { return(ret); } } - return(LoadBitmap(hInst, "NP2TOOL")); + return(LoadBitmap(g_hInstance, _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; @@ -166,7 +172,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; } @@ -174,22 +180,21 @@ static void calctextsize(char *path, int file_cutname(path); file_cutseparator(path); file_cutname(path); - l = strlen(path); - if (l > 1) { - l -= 1; - if (milstr_kanji2nd(p, l - 1)) { - l--; - } - } - else { - l = 0; + file_cutseparator(path); + l = OEMSTRLEN(path); + work[0] = '\0'; + if (l) { + milstr_ncpy(work, str_browse, NELEMENTS(work)); } - milstr_ncpy(work, str_browse, sizeof(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; @@ -204,35 +209,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); @@ -260,10 +265,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; @@ -284,7 +289,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; @@ -299,7 +304,7 @@ static void remakefddlist(HWND hwnd, TOO setlist(hwnd, fdd, sel); } -static void accdraw(HWND hWnd, BYTE count) { +static void accdraw(HWND hWnd, UINT8 count) { HDC hdc; PAINTSTRUCT ps; @@ -320,7 +325,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) { @@ -352,7 +357,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); @@ -380,29 +391,23 @@ static LRESULT CALLBACK twsub(HWND hWnd, } } else if (msg == WM_SETFOCUS) { - SetWindowLong(GetParent(hWnd), GTWL_FOCUS, idc); - } - else if (msg == WM_SYSKEYDOWN) { - if (((short)wp == VK_SPACE) && (lp & 0x20000000)) { - return(SendMessage(GetParent(hWnd), msg, wp, lp)); - } + SetWindowLongPtr(GetParent(hWnd), GTWLP_FOCUS, idc); } return(CallWindowProc(toolwin.subproc[idc], hWnd, msg, wp, lp)); } 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); @@ -410,10 +415,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; @@ -437,22 +444,29 @@ 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); + hWnd, (HMENU)(i + IDC_BASE), g_hInstance, 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] = (SUBCLASSPROC)GetWindowLongPtr(sub, + GWLP_WNDPROC); + SetWindowLongPtr(sub, GWLP_WNDPROC, (LONG_PTR)twsub); SendMessage(sub, WM_SETFONT, (WPARAM)toolwin.hfont, MAKELPARAM(TRUE, 0)); } p++; } for (i=0; ii; j--) { - id[j] = id[j-1]; - } - id[i] = cnt; - file[cnt] = p; - } - for (i=0; ii; j--) + { + uID[j] = uID[j-1]; + } + uID[i] = uCount; + pcszMruList[uCount] = pszMru; + } + + for (i=0; ii; j--) + { + uID[j] = uID[j-1]; + } + uID[i] = uCount; + pcszMruList[uCount] = pszMru; + } + for (i=0; iright - rect->left; - winly = rect->bottom - rect->top; - - if ((winlx > (workrc.right - workrc.left)) || - (winly > (workrc.bottom - workrc.top))) { - return; - } - - if (toolwin.winflg & 0x03) { - toolwin.wingx += rect->left - toolwin.wintx; - rect->left = toolwin.wintx; - if ((toolwin.wingx >= SNAPDOTREL) || (toolwin.wingx <= -SNAPDOTREL)) { - toolwin.winflg &= ~0x03; - rect->left += toolwin.wingx; - toolwin.wingx = 0; - } - rect->right = rect->left + winlx; - } - if (toolwin.winflg & 0x0c) { - toolwin.wingy += rect->top - toolwin.winty; - rect->top = toolwin.winty; - if ((toolwin.wingy >= SNAPDOTREL) || (toolwin.wingy <= -SNAPDOTREL)) { - toolwin.winflg &= ~0x0c; - rect->top += toolwin.wingy; - toolwin.wingy = 0; - } - rect->bottom = rect->top + winly; - } - - connectx = ((rect->right >= mainrc.left) && (rect->left <= mainrc.right)); - connecty = ((rect->bottom >= mainrc.top) && (rect->top <= mainrc.bottom)); - if ((!connectx) || (!connecty)) { - if (toolwin.winflg & 0x01) { - toolwin.winflg &= ~0x01; - rect->left += toolwin.wingx; - rect->right = rect->left + winlx; - toolwin.wingx = 0; - } - if (toolwin.winflg & 0x04) { - toolwin.winflg &= ~0x04; - rect->top += toolwin.wingy; - rect->bottom = rect->top + winly; - toolwin.wingy = 0; - } - } - - do { - changes = FALSE; - if ((!(toolwin.winflg & 0x01)) && - (rect->bottom >= mainrc.top) && (rect->top <= mainrc.bottom)) { - do { - d = rect->left - mainrc.right; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - d = rect->right - mainrc.left; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - if ((rect->bottom == mainrc.top) || - (rect->top == mainrc.bottom)) { - d = rect->left - mainrc.left; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - d = rect->right - mainrc.right; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - } - } while(0); - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - toolwin.winflg |= 0x01; - rect->left -= d; - rect->right = rect->left + winlx; - toolwin.wingx = d; - toolwin.wintx = rect->left; - changes = TRUE; - } - } - if (!(toolwin.winflg & 0x03)) { - do { - d = rect->left - workrc.left; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - d = rect->right - workrc.right; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - } while(0); - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - toolwin.winflg |= 0x02; - rect->left -= d; - rect->right = rect->left + winlx; - toolwin.wingx = d; - toolwin.wintx = rect->left; - changes = TRUE; - } - } - - if ((!(toolwin.winflg & 0x04)) && - (rect->right >= mainrc.left) && (rect->left <= mainrc.right)) { - do { - d = rect->top - mainrc.bottom; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - d = rect->bottom - mainrc.top; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - if ((rect->right == mainrc.left) || - (rect->left == mainrc.right)) { - d = rect->top - mainrc.top; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - d = rect->bottom - mainrc.bottom; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - } - } while(0); - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - toolwin.winflg |= 0x04; - rect->top -= d; - rect->bottom = rect->top + winly; - toolwin.wingy = d; - toolwin.winty = rect->top; - changes = TRUE; - } - } - if (!(toolwin.winflg & 0x0c)) { - do { - d = rect->top - workrc.top; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - d = rect->bottom - workrc.bottom; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - } while(0); - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - toolwin.winflg |= 0x08; - rect->top -= d; - rect->bottom = rect->top + winly; - toolwin.wingy = d; - toolwin.winty = rect->top; - changes = TRUE; - } - } - } while(changes); + winlocex_move(wlex); + winlocex_destroy(wlex); } // ---- -static void openpopup(HWND hWnd, LPARAM lp) { - +static void openpopup(HWND hWnd, LPARAM lp) +{ HMENU hMenu; POINT pt; hMenu = CreatePopupMenu(); - AppendMenu(hMenu, MF_POPUP, (UINT)createskinmenu(), str_toolskin); - AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); - AppendMenu(hMenu, MF_STRING, IDC_TOOLCLOSE, str_toolclose); + if (!winui_en) + { + menu_addmenu(hMenu, 0, np2class_gethmenu(g_hWndMain), FALSE); + } + menu_addmenures(hMenu, -1, IDR_TOOLWIN, FALSE); + menu_addmenures(hMenu, -1, IDR_CLOSE, TRUE); + setSkinMruMenu(hMenu); pt.x = LOWORD(lp); pt.y = HIWORD(lp); ClientToScreen(hWnd, &pt); TrackPopupMenu(hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hWnd, NULL); - ModifyMenu(hMenu, 0, MF_BYPOSITION | MF_POPUP, (UINT)0, str_toolskin); DestroyMenu(hMenu); } -static LRESULT CALLBACK twproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { - +static void toolwin_oncreate(HWND hWnd) +{ HMENU hMenu; - BOOL r; - UINT idc; + int nCount; + + np2class_wmcreate(hWnd); + setSkinMruMenu(np2class_gethmenu(hWnd)); + + hMenu = GetSystemMenu(hWnd, FALSE); + nCount = menu_addmenures(hMenu, 0, IDR_TOOLWIN, FALSE); + if (nCount) + { + InsertMenu(hMenu, nCount, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); + setSkinMruMenu(hMenu); + } + + np2class_windowtype(hWnd, (np2tool.type & 1) << 1); + toolwincreate(hWnd); +} + +static LRESULT CALLBACK twproc(HWND hWnd, UINT uMsg, WPARAM wp, LPARAM lp) +{ + BOOL r; + UINT idc; + WINLOCEX wlex; - switch(msg) { + switch(uMsg) { case WM_CREATE: - hMenu = GetSystemMenu(hWnd, FALSE); - InsertMenu(hMenu, 0, MF_BYPOSITION | MF_POPUP, - (UINT)createskinmenu(), str_toolskin); - InsertMenu(hMenu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); - - SetWindowLong(hWnd, GWL_STYLE, - GetWindowLong(hWnd, GWL_STYLE) & (~WS_CAPTION)); - SetWindowPos(hWnd, 0, 0, 0, 0, 0, - SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER); - toolwincreate(hWnd); + toolwin_oncreate(hWnd); break; case WM_SYSCOMMAND: switch(wp) { - case IDC_SKINSEL: - case IDC_SKINDEF: - case IDC_SKINMRU + 0: - case IDC_SKINMRU + 1: - case IDC_SKINMRU + 2: - case IDC_SKINMRU + 3: + case IDM_TOOL_SKINSEL: + case IDM_TOOL_SKINDEF: + case IDM_TOOL_SKINMRU + 0: + case IDM_TOOL_SKINMRU + 1: + case IDM_TOOL_SKINMRU + 2: + case IDM_TOOL_SKINMRU + 3: return(SendMessage(hWnd, WM_COMMAND, wp, lp)); default: - return(DefWindowProc(hWnd, msg, wp, lp)); + return(DefWindowProc(hWnd, uMsg, wp, lp)); } break; @@ -876,9 +797,9 @@ static LRESULT CALLBACK twproc(HWND hWnd break; case IDC_BASE + IDC_TOOLFDD1BROWSE: - soundmng_disable(SNDPROC_TOOL); - dialog_changefdd(hWnd, 0); - soundmng_enable(SNDPROC_TOOL); + if (!winui_en) { + SendMessage(g_hWndMain, WM_COMMAND, IDM_FDD1OPEN, 0); + } break; case IDC_BASE + IDC_TOOLFDD1EJECT: @@ -893,9 +814,9 @@ static LRESULT CALLBACK twproc(HWND hWnd break; case IDC_BASE + IDC_TOOLFDD2BROWSE: - soundmng_disable(SNDPROC_TOOL); - dialog_changefdd(hWnd, 1); - soundmng_enable(SNDPROC_TOOL); + if (!winui_en) { + SendMessage(g_hWndMain, WM_COMMAND, IDM_FDD2OPEN, 0); + } break; case IDC_BASE + IDC_TOOLFDD2EJECT: @@ -904,71 +825,77 @@ static LRESULT CALLBACK twproc(HWND hWnd break; case IDC_BASE + IDC_TOOLRESET: - SendMessage(hWndMain, WM_COMMAND, IDM_RESET, 0); - SetForegroundWindow(hWndMain); + if (!winui_en) { + SendMessage(g_hWndMain, WM_COMMAND, IDM_RESET, 0); + SetForegroundWindow(g_hWndMain); + } break; case IDC_BASE + IDC_TOOLPOWER: - SendMessage(hWndMain, WM_CLOSE, 0, 0L); + if (!winui_en) { + SendMessage(g_hWndMain, WM_CLOSE, 0, 0L); + } break; - case IDC_SKINSEL: + case IDM_TOOL_SKINSEL: soundmng_disable(SNDPROC_TOOL); - r = dlgs_selectfile(hWnd, &skinui, np2tool.skin, - sizeof(np2tool.skin), NULL); + r = dlgs_openfile(hWnd, &fpSkin, np2tool.skin, + NELEMENTS(np2tool.skin), NULL); soundmng_enable(SNDPROC_TOOL); if (r) { skinchange(hWnd); } break; - case IDC_SKINDEF: + case IDM_TOOL_SKINDEF: np2tool.skin[0] = '\0'; skinchange(hWnd); break; - case IDC_SKINMRU + 0: - case IDC_SKINMRU + 1: - case IDC_SKINMRU + 2: - case IDC_SKINMRU + 3: + case IDM_TOOL_SKINMRU + 0: + case IDM_TOOL_SKINMRU + 1: + case IDM_TOOL_SKINMRU + 2: + case IDM_TOOL_SKINMRU + 3: file_cpyname(np2tool.skin, - np2tool.skinmru[LOWORD(wp) - IDC_SKINMRU], - sizeof(np2tool.skin)); + np2tool.skinmru[LOWORD(wp) - IDM_TOOL_SKINMRU], + NELEMENTS(np2tool.skin)); skinchange(hWnd); break; - case IDC_TOOLCLOSE: + case IDM_CLOSE: SendMessage(hWnd, WM_CLOSE, 0, 0); break; + + default: + if (!winui_en) { + return(SendMessage(g_hWndMain, uMsg, wp, lp)); + } + break; } break; case WM_KEYDOWN: // TABを押した時に復帰 if ((short)wp == VK_TAB) { - idc = GetWindowLong(hWnd, GTWL_FOCUS); + idc = (UINT)GetWindowLongPtr(hWnd, GTWLP_FOCUS); if (idc < IDC_MAXITEMS) { SetFocus(toolwin.sub[idc]); } return(0); } - break; + return(SendMessage(g_hWndMain, uMsg, wp, lp)); - case WM_SYSKEYDOWN: // ALT+SPACEを自前処理 - if (((short)wp == VK_SPACE) && (lp & 0x20000000)) { - POINT pt; - pt.x = 0; - pt.y = 0; - ClientToScreen(hWnd, &pt); - return(SendMessage(hWnd, 0x313, 0, MAKELPARAM(pt.x, pt.y))); + case WM_KEYUP: + if ((short)wp == VK_TAB) { + return(0); } - break; + return(SendMessage(g_hWndMain, uMsg, wp, lp)); case WM_PAINT: toolwinpaint(hWnd); break; case WM_DRAWITEM: - tooldrawbutton(hWnd, wp, (LPDRAWITEMSTRUCT)lp); + tooldrawbutton(hWnd, (UINT)wp, (LPDRAWITEMSTRUCT)lp); break; case WM_ENTERMENULOOP: @@ -981,15 +908,18 @@ static LRESULT CALLBACK twproc(HWND hWnd case WM_ENTERSIZEMOVE: soundmng_disable(SNDPROC_TOOL); - movingstart(); + winlocex_destroy(toolwin.wlex); + toolwin.wlex = np2_winlocexallwin(hWnd); break; - case WM_EXITSIZEMOVE: - soundmng_enable(SNDPROC_TOOL); + case WM_MOVING: + winlocex_moving(toolwin.wlex, (RECT *)lp); break; - case WM_MOVING: - movingproc((RECT *)lp); + case WM_EXITSIZEMOVE: + winlocex_destroy(toolwin.wlex); + toolwin.wlex = NULL; + soundmng_enable(SNDPROC_TOOL); break; case WM_MOVE: @@ -1004,26 +934,39 @@ static LRESULT CALLBACK twproc(HWND hWnd break; case WM_CLOSE: - xmenu_settoolwin(0); + sysmenu_settoolwin(0); sysmng_update(SYS_UPDATEOSCFG); DestroyWindow(hWnd); break; case WM_DESTROY: + np2class_wmdestroy(hWnd); toolwindestroy(); toolwin.hwnd = NULL; break; case WM_LBUTTONDOWN: - SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0L); + if (np2tool.type & 1) { + return(SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0L)); + } break; case WM_RBUTTONDOWN: openpopup(hWnd, lp); break; + case WM_LBUTTONDBLCLK: + np2tool.type ^= 1; + wlex = np2_winlocexallwin(g_hWndMain); + winlocex_setholdwnd(wlex, hWnd); + np2class_windowtype(hWnd, (np2tool.type & 1) << 1); + winlocex_move(wlex); + winlocex_destroy(wlex); + sysmng_update(SYS_UPDATEOSCFG); + break; + default: - return(DefWindowProc(hWnd, msg, wp, lp)); + return(DefWindowProc(hWnd, uMsg, wp, lp)); } return(0); } @@ -1032,23 +975,24 @@ BOOL toolwin_initapp(HINSTANCE hInstance WNDCLASS wc; - wc.style = CS_HREDRAW | CS_VREDRAW; + wc.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = twproc; wc.cbClsExtra = 0; - wc.cbWndExtra = GTWL_SIZE; + wc.cbWndExtra = GTWLP_SIZE; wc.hInstance = hInstance; wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON2)); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH); - wc.lpszMenuName = NULL; + wc.lpszMenuName = MAKEINTRESOURCE(IDR_TOOLWIN); wc.lpszClassName = np2toolclass; return(RegisterClass(&wc)); } -void toolwin_open(void) { +void toolwin_create(HINSTANCE hInstance) { HBITMAP hbmp; BITMAP bmp; + TCHAR szCaption[128]; HWND hWnd; if (toolwin.hwnd) { @@ -1061,141 +1005,50 @@ void toolwin_open(void) { } GetObject(hbmp, sizeof(BITMAP), &bmp); toolwin.hbmp = hbmp; - hWnd = CreateWindow(np2toolclass, np2tooltitle, WS_SYSMENU, + + loadstringresource(LOWORD(IDS_CAPTION_TOOL), + szCaption, NELEMENTS(szCaption)); + hWnd = CreateWindow(np2toolclass, szCaption, + WS_SYSMENU | WS_MINIMIZEBOX, np2tool.posx, np2tool.posy, bmp.bmWidth, bmp.bmHeight, - NULL, NULL, hInst, NULL); + NULL, NULL, hInstance, NULL); + winloc_setclientsize(hWnd, bmp.bmWidth, bmp.bmHeight); toolwin.hwnd = hWnd; if (hWnd == NULL) { goto twope_err2; } UpdateWindow(hWnd); - ShowWindow(hWnd, SW_SHOW); - SetForegroundWindow(hWndMain); + ShowWindow(hWnd, SW_SHOWNOACTIVATE); + SetForegroundWindow(g_hWndMain); return; twope_err2: DeleteObject(hbmp); twope_err1: - xmenu_settoolwin(0); + sysmenu_settoolwin(0); sysmng_update(SYS_UPDATEOSCFG); return; } -void toolwin_close(void) { +void toolwin_destroy(void) { if (toolwin.hwnd) { DestroyWindow(toolwin.hwnd); } } -void toolwin_movingstart(void) { - - RECT mainrc; - RECT toolrc; - UINT connect; - - if (toolwin.hwnd == NULL) { - return; - } - GetWindowRect(hWndMain, &mainrc); - GetWindowRect(toolwin.hwnd, &toolrc); - connect = 0; - if ((toolrc.bottom >= mainrc.top) && (toolrc.top <= mainrc.bottom)) { - if (toolrc.right == mainrc.left) { - connect += 0x01; - } - else if (toolrc.left == mainrc.right) { - connect += 0x02; - } - else if (toolrc.left == mainrc.left) { - connect += 0x03; - } - else if (toolrc.right == mainrc.right) { - connect += 0x04; - } - } - if ((toolrc.right >= mainrc.left) && (toolrc.left <= mainrc.right)) { - if (toolrc.bottom == mainrc.top) { - connect += 1 << 4; - } - else if (toolrc.top == mainrc.bottom) { - connect += 2 << 4; - } - else if (toolrc.top == mainrc.top) { - connect += 3 << 4; - } - else if (toolrc.bottom == mainrc.bottom) { - connect += 4 << 4; - } - } - toolwin.parentcn = connect; - toolwin.parentx = mainrc.left; - toolwin.parenty = mainrc.top; -} - -void toolwin_movingend(void) { - - UINT connect; - RECT mainrc; - RECT toolrc; - int cx; - int cy; - - connect = toolwin.parentcn; - toolwin.parentcn = 0; - if ((toolwin.hwnd == NULL) || (!connect)) { - return; - } - GetWindowRect(hWndMain, &mainrc); - GetWindowRect(toolwin.hwnd, &toolrc); - cx = toolrc.right - toolrc.left; - cy = toolrc.bottom - toolrc.top; - toolrc.left += mainrc.left - toolwin.parentx; - toolrc.top += mainrc.top - toolwin.parenty; - switch(connect & 0x0f) { - case 1: - toolrc.left = mainrc.left - cx; - break; - - case 2: - toolrc.left = mainrc.right; - break; - - case 3: - toolrc.left = mainrc.left; - break; +HWND toolwin_gethwnd(void) { - case 4: - toolrc.left = mainrc.right - cx; - break; - } - switch((connect >> 4) & 0x0f) { - case 1: - toolrc.top = mainrc.top - cy; - break; - - case 2: - toolrc.top = mainrc.bottom; - break; - - case 3: - toolrc.top = mainrc.top; - break; - - case 4: - toolrc.top = mainrc.bottom - cy; - break; - } - MoveWindow(toolwin.hwnd, toolrc.left, toolrc.top, cx, cy, TRUE); + return(toolwin.hwnd); } -void toolwin_setfdd(BYTE drv, const char *name) { +void toolwin_setfdd(UINT8 drv, const OEMCHAR *name) { TOOLFDD *fdd; - char *q; - char *p; + OEMCHAR *q; + OEMCHAR *p; UINT i; HWND sub; @@ -1213,28 +1066,28 @@ void toolwin_setfdd(BYTE drv, const char if (!file_cmpname(q, name)) { break; } - q += sizeof(fdd->name[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) { sub = toolwin.sub[fddlist[drv]]; if (sub) { remakefddlist(sub, fdd); - SetForegroundWindow(hWndMain); + SetForegroundWindow(g_hWndMain); } } } -static void setdiskacc(UINT num, BYTE count) { +static void setdiskacc(UINT num, UINT8 count) { const DISKACC *acc; HWND sub; @@ -1242,7 +1095,7 @@ const DISKACC *acc; if (toolwin.hwnd == NULL) { return; } - if (num < (sizeof(diskacc)/sizeof(DISKACC))) { + if (num < NELEMENTS(diskacc)) { acc = diskacc + num; sub = NULL; if (*(acc->counter) == 0) { @@ -1255,23 +1108,23 @@ const DISKACC *acc; } } -void toolwin_fddaccess(BYTE drv) { +void toolwin_fddaccess(UINT8 drv) { if (drv < 2) { setdiskacc(drv, 20); } } -void toolwin_hddaccess(BYTE drv) { +void toolwin_hddaccess(UINT8 drv) { setdiskacc(2, 10); } -void toolwin_draw(BYTE frame) { +void toolwin_draw(UINT8 frame) { const DISKACC *acc; const DISKACC *accterm; - BYTE counter; + UINT8 counter; HWND sub; if (toolwin.hwnd == NULL) { @@ -1281,7 +1134,7 @@ const DISKACC *accterm; frame = 1; } acc = diskacc; - accterm = acc + (sizeof(diskacc)/sizeof(DISKACC)); + accterm = acc + NELEMENTS(diskacc); while(acc < accterm) { counter = *acc->counter; if (counter) { @@ -1303,49 +1156,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}, - {"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; - initgetfile(path, sizeof(path)); - ini_read(path, ini_title, iniitem, sizeof(iniitem)/sizeof(INITBL)); + np2tool.type = 1; + 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)); - ini_write(path, ini_title, iniitem, sizeof(iniitem)/sizeof(INITBL)); + initgetfile(path, NELEMENTS(path)); + ini_write(path, ini_title, iniitem, NELEMENTS(iniitem)); }