--- np2/win9x/toolwin.cpp 2003/10/28 18:21:05 1.1 +++ np2/win9x/toolwin.cpp 2003/10/29 14:02:35 1.4 @@ -3,7 +3,9 @@ #include "resource.h" #include "np2.h" #include "dosio.h" +#include "soundmng.h" #include "sysmng.h" +#include "menu.h" #include "toolwin.h" #include "ini.h" #include "dialog.h" @@ -18,18 +20,6 @@ #endif - NP2TOOL np2tool; - -static const char np2toolclass[] = "np2-toolwin"; -static const char np2tooltitle[] = "NP2 tool"; - -static const char str_deffont[] = "£Í£Ó £Ð¥´¥·¥Ã¥¯"; -static const char str_static[] = "STATIC"; -static const char str_combobox[] = "COMBOBOX"; -static const char str_button[] = "BUTTON"; -static const char str_browse[] = "..."; -static const char str_eject[] = "Eject"; - enum { IDC_TOOLHDDACC = 0, IDC_TOOLFDD1ACC, @@ -46,42 +36,30 @@ enum { }; typedef struct { + char main[MAX_PATH]; + char font[64]; + SINT32 fontsize; + UINT32 color1; + UINT32 color2; +} TOOLSKIN; + +typedef struct { const char *cname; const char *text; DWORD style; - DWORD exstyle; short posx; short posy; short width; short height; + BOOL tabstop; } SUBITEM; -static const BYTE fddlist[FDDLIST_DRV] = { - IDC_TOOLFDD1LIST, IDC_TOOLFDD2LIST}; - -static const SUBITEM subitem[IDC_MAXITEMS] = { - {str_static, NULL, WS_VISIBLE, 0, 47, 44, 8, 3}, - {str_static, NULL, WS_VISIBLE, 0, 93, 19, 8, 3}, - {str_combobox, NULL, - WS_VISIBLE | CBS_DROPDOWNLIST | WS_VSCROLL, 0, 104, 6, 248, 160}, - {str_button, str_browse, - WS_VISIBLE | BS_PUSHBUTTON, 0, 352, 7, 18, 17}, - {str_button, str_eject, - WS_VISIBLE | BS_PUSHBUTTON, 0, 370, 7, 34, 17}, - {str_static, NULL, WS_VISIBLE, 0, 93, 41, 8, 3}, - {str_combobox, NULL, - WS_VISIBLE | CBS_DROPDOWNLIST | WS_VSCROLL, 0, 104, 28, 248, 160}, - {str_button, str_browse, - WS_VISIBLE | BS_PUSHBUTTON, 0, 352, 29, 18, 17}, - {str_button, str_eject, - WS_VISIBLE | BS_PUSHBUTTON, 0, 370, 29, 34, 17}, -}; - -// static const DWORD mvccol[MVC_MAXCOLOR] = { -// 0xc0e8f8, 0xd8ecf4, 0x48a8c8, 0x000000}; - typedef struct { HWND hwnd; + HBITMAP hbmp; + BYTE fddaccess[2]; + BYTE hddaccess; + BYTE _padding; int winflg; int wingx; int wingy; @@ -92,24 +70,78 @@ typedef struct { int parenty; HFONT hfont; HDC hdcfont; + HBRUSH access[2]; HWND sub[IDC_MAXITEMS]; SCPROC subproc[IDC_MAXITEMS]; } TOOLWIN; + + NP2TOOL np2tool; +static TOOLSKIN toolskin; +static SUBITEM subitem[IDC_MAXITEMS]; static TOOLWIN toolwin; +#include "toolwin.res" + + +typedef struct { + WORD idc; + BYTE *counter; +} DISKACC; + +static const BYTE fddlist[FDDLIST_DRV] = { + IDC_TOOLFDD1LIST, IDC_TOOLFDD2LIST}; + +static const DISKACC diskacc[3] = { + {IDC_TOOLFDD1ACC, &toolwin.fddaccess[0]}, + {IDC_TOOLFDD2ACC, &toolwin.fddaccess[1]}, + {IDC_TOOLHDDACC, &toolwin.hddaccess}}; + + +// ---- + +static void skinsetdef(void) { + + ZeroMemory(&toolskin, sizeof(toolskin)); + toolskin.fontsize = 12; + milstr_ncpy(toolskin.font, str_deffont, sizeof(toolskin.font)); + toolskin.color1 = 0x600000; + toolskin.color2 = 0xff0000; + CopyMemory(subitem, defsubitem, sizeof(defsubitem)); +} + +static HBITMAP skinload(const char *path) { + + char fname[MAX_PATH]; + + if (path) { + ini_read(path, skintitle, skinini, sizeof(skinini)/sizeof(INITBL)); + } + if ((path) && (toolskin.main[0])) { + milstr_ncpy(fname, path, sizeof(fname)); + file_cutname(fname); + file_catname(fname, toolskin.main, sizeof(fname)); + return((HBITMAP)LoadImage(hInst, fname, IMAGE_BITMAP, + 0, 0, LR_LOADFROMFILE)); + } + else { + return(LoadBitmap(hInst, "NP2TOOL")); + } +} + + +// ---- + static void calctextsize(char *path, int leng, const char *p, int width) { HDC hdc; SIZE cur; char work[MAX_PATH]; -const char *q; int l; SIZE tail; int pos; int step; - // NetscapeÉ÷Ì£ milstr_ncpy(path, p, leng); hdc = toolwin.hdcfont; GetTextExtentPoint32(hdc, p, strlen(p), &cur); @@ -123,7 +155,7 @@ const char *q; l = strlen(path); if (l > 1) { l -= 1; - if (milstr_kanji2nd(p, l)) { + if (milstr_kanji2nd(p, l - 1)) { l--; } } @@ -213,9 +245,26 @@ static void sellist(UINT drv) { } } +static void accdraw(HWND hWnd, BYTE count) { + + HDC hdc; + PAINTSTRUCT ps; + RECT rc; + HBRUSH hbrush; + + hdc = BeginPaint(hWnd, &ps); + GetClientRect(hWnd, &rc); + hbrush = (HBRUSH)SelectObject(hdc, toolwin.access[(count)?1:0]); + PatBlt(hdc, rc.left, rc.top, rc.right, rc.bottom, PATCOPY); + SelectObject(hdc, hbrush); + EndPaint(hWnd, &ps); +} + static LRESULT CALLBACK twsub(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { UINT idc; + int dir; + UINT newidc; int files; char fname[MAX_PATH]; @@ -227,8 +276,30 @@ static LRESULT CALLBACK twsub(HWND hWnd, if (idc >= IDC_MAXITEMS) { return(0); } - if (msg == WM_DROPFILES) { - files = DragQueryFile((HDROP)wp, 0xFFFFFFFF, NULL, 0); + if (msg == WM_KEYDOWN) { + if ((TCHAR)wp == VK_TAB) { + dir = (GetKeyState(VK_SHIFT) >= 0)?1:-1; + newidc = idc; + do { + newidc += dir; + if (newidc >= IDC_MAXITEMS) { + newidc = (dir >= 0)?0:(IDC_MAXITEMS - 1); + } + if (subitem[newidc].tabstop) { + SetFocus(toolwin.sub[newidc]); + break; + } + } while(idc != newidc); + } + else if ((TCHAR)wp == VK_RETURN) { + if (subitem[idc].cname == str_button) { + return(CallWindowProc(toolwin.subproc[idc], + hWnd, WM_KEYDOWN, VK_SPACE, 0)); + } + } + } + else if (msg == WM_DROPFILES) { + files = DragQueryFile((HDROP)wp, (UINT)-1, NULL, 0); if (files == 1) { DragQueryFile((HDROP)wp, 0, fname, sizeof(fname)); if (idc == IDC_TOOLFDD1LIST) { @@ -243,6 +314,20 @@ static LRESULT CALLBACK twsub(HWND hWnd, DragFinish((HDROP)wp); return(FALSE); } + else if (msg == WM_PAINT) { + if (idc == IDC_TOOLHDDACC) { + accdraw(hWnd, toolwin.hddaccess); + return(FALSE); + } + else if (idc == IDC_TOOLFDD1ACC) { + accdraw(hWnd, toolwin.fddaccess[0]); + return(FALSE); + } + else if (idc == IDC_TOOLFDD2ACC) { + accdraw(hWnd, toolwin.fddaccess[1]); + return(FALSE); + } + } return(CallWindowProc(toolwin.subproc[idc], hWnd, msg, wp, lp)); } @@ -254,18 +339,21 @@ const SUBITEM *p; UINT i; HWND sub; - toolwin.hfont = CreateFont(12, 0, 0, 0, 0, 0, 0, 0, + toolwin.hfont = CreateFont(toolskin.fontsize, 0, 0, 0, 0, 0, 0, 0, SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, FIXED_PITCH, str_deffont); + DEFAULT_QUALITY, FIXED_PITCH, toolskin.font); hdc = GetDC(NULL); toolwin.hdcfont = CreateCompatibleDC(hdc); ReleaseDC(NULL, hdc); SelectObject(toolwin.hdcfont, toolwin.hfont); + toolwin.access[0] = CreateSolidBrush(0x000060); + toolwin.access[1] = CreateSolidBrush(0x0000ff); + hinstance = ((LPCREATESTRUCT)lp)->hInstance; p = subitem; for (i=0; iexstyle, p->cname, p->text, + sub = CreateWindow(p->cname, p->text, WS_CHILD | p->style, p->posx, p->posy, p->width, p->height, hWnd, (HMENU)(i + IDC_BASE), hinstance, NULL); toolwin.sub[i] = sub; @@ -288,8 +376,11 @@ static void toolwindestroy(void) { for (i=0; iright >= mainrc.left) && (rect->left <= mainrc.right)); - connecty = ((rect->bottom >= mainrc.top) && (rect->top <= mainrc.bottom)); - if ((toolwin.winflg & 3) && (!connectx) && (!connecty)) { - toolwin.winflg &= ~3; - rect->left += toolwin.wingx; - rect->top += toolwin.wingy; - toolwin.wingx = 0; - toolwin.wingy = 0; - } - - if (toolwin.winflg & 1) { - toolwin.wingx += rect->left - toolwin.wintx; - rect->left = toolwin.wintx; - } - else { - d = SNAPDOTPULL; - do { - if (connecty) { - d = rect->right - mainrc.left; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - d = rect->left - mainrc.right; - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - break; - } - if ((rect->bottom == mainrc.top) || - (rect->top == mainrc.bottom)) { - d = rect->left - mainrc.left; + changes = FALSE; + do { + if (toolwin.winflg & 1) { + toolwin.wingx += rect->left - toolwin.wintx; + rect->left = toolwin.wintx; + } + else { + d = SNAPDOTPULL; + do { + connecty = ((rect->bottom >= mainrc.top) && + (rect->top <= mainrc.bottom)); + if (connecty) { + d = rect->left - mainrc.right; if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { break; } - d = rect->right - mainrc.right; + 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 |= 1; - rect->left -= d; - toolwin.wingx = d; - toolwin.wintx = rect->left; - } - } - if ((toolwin.wingx >= SNAPDOTREL) || (toolwin.wingx <= -SNAPDOTREL)) { - toolwin.winflg &= ~1; - rect->left += toolwin.wingx; - toolwin.wingx = 0; - } - - if (toolwin.winflg & 2) { - toolwin.wingy += rect->top - toolwin.winty; - rect->top = toolwin.winty; - } - else { - d = SNAPDOTPULL; - do { - if (connectx) { - d = rect->bottom - mainrc.top; + d = rect->left - workrc.left; if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { break; } - d = rect->top - mainrc.bottom; + d = rect->right - workrc.right; if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { break; } - if ((rect->right == mainrc.left) || - (rect->left == mainrc.right)) { - d = rect->top - mainrc.top; + } while(0); + if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { + toolwin.winflg |= 1; + rect->left -= d; + toolwin.wingx = d; + toolwin.wintx = rect->left; + } + } + if ((toolwin.wingx >= SNAPDOTREL) || (toolwin.wingx <= -SNAPDOTREL)) { + toolwin.winflg &= ~1; + rect->left += toolwin.wingx; + toolwin.wingx = 0; + } + rect->right = rect->left + winlx; + + if (changes) { + break; + } + + if (toolwin.winflg & 2) { + toolwin.wingy += rect->top - toolwin.winty; + rect->top = toolwin.winty; + } + else { + d = SNAPDOTPULL; + do { + connectx = ((rect->right >= mainrc.left) && + (rect->left <= mainrc.right)); + if (connectx) { + d = rect->top - mainrc.bottom; if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { break; } - d = rect->bottom - mainrc.bottom; + 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; + } + } } + 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 |= 2; + rect->top -= d; + toolwin.wingy = d; + toolwin.winty = rect->top; + changes = TRUE; } - } while(0); - if ((d < SNAPDOTPULL) && (d > -SNAPDOTPULL)) { - toolwin.winflg |= 2; - rect->top -= d; - toolwin.wingy = d; - toolwin.winty = rect->top; } - } - if ((toolwin.wingy >= SNAPDOTREL) || (toolwin.wingy <= -SNAPDOTREL)) { - toolwin.winflg &= ~2; + if ((toolwin.wingy >= SNAPDOTREL) || (toolwin.wingy <= -SNAPDOTREL)) { + toolwin.winflg &= ~2; + rect->top += toolwin.wingy; + toolwin.wingy = 0; + changes = TRUE; + } + rect->bottom = rect->top + winly; + } while(changes); + + connectx = ((rect->right >= mainrc.left) && (rect->left <= mainrc.right)); + connecty = ((rect->bottom >= mainrc.top) && (rect->top <= mainrc.bottom)); + if ((toolwin.winflg & 3) && ((!connectx) || (!connecty))) { + toolwin.winflg &= ~3; + rect->left += toolwin.wingx; rect->top += toolwin.wingy; + rect->right = rect->left + winlx; + rect->bottom = rect->top + winly; + toolwin.wingx = 0; toolwin.wingy = 0; } - - rect->right = rect->left + winlx; - rect->bottom = rect->top + winly; } @@ -452,6 +572,10 @@ static LRESULT CALLBACK twproc(HWND hWnd switch(msg) { case WM_CREATE: + 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, lp); break; @@ -464,7 +588,9 @@ static LRESULT CALLBACK twproc(HWND hWnd break; case IDC_BASE + IDC_TOOLFDD1BROWSE: + soundmng_stop(); dialog_changefdd(hWnd, 0); + soundmng_play(); break; case IDC_BASE + IDC_TOOLFDD1EJECT: @@ -479,7 +605,9 @@ static LRESULT CALLBACK twproc(HWND hWnd break; case IDC_BASE + IDC_TOOLFDD2BROWSE: + soundmng_stop(); dialog_changefdd(hWnd, 1); + soundmng_play(); break; case IDC_BASE + IDC_TOOLFDD2EJECT: @@ -493,10 +621,23 @@ static LRESULT CALLBACK twproc(HWND hWnd toolwinpaint(hWnd); break; + case WM_ENTERMENULOOP: + soundmng_stop(); + break; + + case WM_EXITMENULOOP: + soundmng_play(); + break; + case WM_ENTERSIZEMOVE: + soundmng_stop(); movingstart(); break; + case WM_EXITSIZEMOVE: + soundmng_play(); + break; + case WM_MOVING: movingproc((RECT *)lp); break; @@ -513,6 +654,8 @@ static LRESULT CALLBACK twproc(HWND hWnd break; case WM_CLOSE: + xmenu_settoolwin(0); + sysmng_update(SYS_UPDATEOSCFG); DestroyWindow(hWnd); break; @@ -550,24 +693,44 @@ BOOL toolwin_initapp(HINSTANCE hInstance void toolwin_open(void) { + char path[MAX_PATH]; + HBITMAP hbmp; + BITMAP bmp; HWND hWnd; if (toolwin.hwnd) { return; } + ZeroMemory(&toolwin, sizeof(toolwin)); + skinsetdef(); + milstr_ncpy(path, modulefile, sizeof(path)); + file_cutname(path); + file_catname(path, np2skin, sizeof(path)); + hbmp = skinload(path); + if (hbmp == NULL) { + goto twope_err1; + } + GetObject(hbmp, sizeof(BITMAP), &bmp); + toolwin.hbmp = hbmp; hWnd = CreateWindowEx(0, np2toolclass, np2tooltitle, WS_SYSMENU, - np2tool.posx, np2tool.posy, 410, 52, + np2tool.posx, np2tool.posy, + bmp.bmWidth, bmp.bmHeight, NULL, NULL, hInst, NULL); toolwin.hwnd = hWnd; if (hWnd == NULL) { - return; + goto twope_err2; } UpdateWindow(hWnd); ShowWindow(hWnd, SW_SHOW); - 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); + return; + +twope_err2: + DeleteObject(hbmp); + +twope_err1: + xmenu_settoolwin(0); + sysmng_update(SYS_UPDATEOSCFG); + return; } void toolwin_close(void) { @@ -656,6 +819,66 @@ void toolwin_setfdd(BYTE drv, const char } +static void setdiskacc(UINT num, BYTE count) { + +const DISKACC *acc; + BYTE counter; + + if (toolwin.hwnd == NULL) { + return; + } + if (num < (sizeof(diskacc)/sizeof(DISKACC))) { + acc = diskacc + num; + counter = *(acc->counter); + *(acc->counter) = count; + if (counter) { + InvalidateRect(toolwin.sub[acc->idc], NULL, TRUE); + } + } +} + +void toolwin_fddaccess(BYTE drv) { + + if (drv < 2) { + setdiskacc(drv, 20); + } +} + +void toolwin_hddaccess(BYTE drv) { + + setdiskacc(2, 10); +} + +void toolwin_draw(BYTE frame) { + +const DISKACC *acc; +const DISKACC *accterm; + BYTE counter; + + if (toolwin.hwnd == NULL) { + return; + } + if (!frame) { + frame = 1; + } + acc = diskacc; + accterm = acc + (sizeof(diskacc)/sizeof(DISKACC)); + while(acc < accterm) { + counter = *acc->counter; + if (counter) { + if (counter <= frame) { + *(acc->counter) = 0; + InvalidateRect(toolwin.sub[acc->idc], NULL, TRUE); + } + else { + *(acc->counter) -= frame; + } + } + acc++; + } +} + + // ---- static const char np2toolini[] = "np2tool.ini";