--- np2/win9x/toolwin.cpp 2003/10/29 14:02:35 1.4 +++ np2/win9x/toolwin.cpp 2003/10/29 21:35:58 1.5 @@ -9,17 +9,11 @@ #include "toolwin.h" #include "ini.h" #include "dialog.h" +#include "dialogs.h" #include "pccore.h" #include "diskdrv.h" -#ifdef STRICT -#define SCPROC WNDPROC -#else -#define SCPROC FARPROC -#endif - - enum { IDC_TOOLHDDACC = 0, IDC_TOOLFDD1ACC, @@ -32,7 +26,11 @@ enum { IDC_TOOLFDD2EJECT, IDC_MAXITEMS, - IDC_BASE = 3000 + IDC_BASE = 3000, + + IDC_SKINDEF = 3100, + IDC_SKINSEL = 3101, + IDC_TOOLCLOSE = 3102 }; typedef struct { @@ -55,24 +53,24 @@ const char *text; } SUBITEM; typedef struct { - HWND hwnd; - HBITMAP hbmp; - BYTE fddaccess[2]; - BYTE hddaccess; - BYTE _padding; - int winflg; - int wingx; - int wingy; - int wintx; - int winty; - int parentcn; - int parentx; - int parenty; - HFONT hfont; - HDC hdcfont; - HBRUSH access[2]; - HWND sub[IDC_MAXITEMS]; - SCPROC subproc[IDC_MAXITEMS]; + HWND hwnd; + HBITMAP hbmp; + BYTE fddaccess[2]; + BYTE hddaccess; + BYTE _padding; + int winflg; + int wingx; + int wingy; + int wintx; + int winty; + UINT parentcn; + int parentx; + int parenty; + HFONT hfont; + HDC hdcfont; + HBRUSH access[2]; + HWND sub[IDC_MAXITEMS]; + SUBCLASSPROC subproc[IDC_MAXITEMS]; } TOOLWIN; @@ -100,7 +98,10 @@ static const DISKACC diskacc[3] = { // ---- -static void skinsetdef(void) { +static HBITMAP skinload(const char *path) { + + char fname[MAX_PATH]; + HBITMAP ret; ZeroMemory(&toolskin, sizeof(toolskin)); toolskin.fontsize = 12; @@ -108,11 +109,6 @@ static void skinsetdef(void) { 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)); @@ -121,12 +117,13 @@ static HBITMAP skinload(const char *path 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")); + ret = (HBITMAP)LoadImage(hInst, fname, IMAGE_BITMAP, + 0, 0, LR_LOADFROMFILE); + if (ret != NULL) { + return(ret); + } } + return(LoadBitmap(hInst, "NP2TOOL")); } @@ -180,40 +177,30 @@ static void calctextsize(char *path, int milstr_ncat(path, work, leng); } -static void setlist(UINT drv) { +static void setlist(HWND hwnd, const TOOLFDD *fdd, UINT sel) { - HWND hwnd; RECT rc; int width; - TOOLFDD *fdd; - char *p; - UINT i; char basedir[MAX_PATH]; + UINT i; +const char *p; char dir[MAX_PATH]; - char *q; +const char *q; - if (drv >= FDDLIST_DRV) { - return; - } - hwnd = toolwin.sub[fddlist[drv]]; + SendMessage(hwnd, CB_RESETCONTENT, (WPARAM)0, (LPARAM)0); GetClientRect(hwnd, &rc); width = rc.right - rc.left - 6; // border size? - SendMessage(hwnd, CB_RESETCONTENT, (WPARAM)0, (LPARAM)0); - fdd = np2tool.fdd + drv; - p = fdd->name[0]; basedir[0] = '\0'; - if (fdd->insert) { - milstr_ncpy(basedir, p, sizeof(basedir)); + if (sel < fdd->cnt) { + milstr_ncpy(basedir, fdd->name[fdd->pos[sel]], sizeof(basedir)); file_cutname(basedir); } - for (i=0; icnt; i++) { + p = fdd->name[fdd->pos[i]]; milstr_ncpy(dir, p, sizeof(dir)); file_cutname(dir); if (!file_cmpname(basedir, dir)) { - q = file_getname(p); + q = file_getname((char *)p); } else { calctextsize(dir, sizeof(dir), p, width); @@ -222,29 +209,76 @@ static void setlist(UINT drv) { SendMessage(hwnd, CB_INSERTSTRING, (WPARAM)i, (LPARAM)q); p += sizeof(fdd->name[0]); } - if (fdd->insert) { - SendMessage(hwnd, CB_SETCURSEL, (WPARAM)0, (LPARAM)0); + if (sel < fdd->cnt) { + SendMessage(hwnd, CB_SETCURSEL, (WPARAM)sel, (LPARAM)0); } } static void sellist(UINT drv) { HWND hwnd; + TOOLFDD *fdd; UINT sel; - char path[MAX_PATH]; if (drv >= FDDLIST_DRV) { return; } hwnd = toolwin.sub[fddlist[drv]]; + fdd = np2tool.fdd + drv; sel = (UINT)SendMessage(hwnd, CB_GETCURSEL, 0, 0); - if (sel < FDDLIST_MAX) { - milstr_ncpy(path, np2tool.fdd[drv].name[sel], sizeof(path)); - diskdrv_setfdd(drv, path, 0); - toolwin_setfdd(drv, path); + if (sel < fdd->cnt) { + diskdrv_setfdd(drv, fdd->name[fdd->pos[sel]], 0); + fdd->insert = 1; + setlist(hwnd, fdd, sel); } } +static void remakefddlist(UINT drv) { + + TOOLFDD *fdd; + char *p; + UINT cnt; + char *q; + char *fname[FDDLIST_MAX]; + UINT i; + UINT j; + UINT sel; + + if (drv >= FDDLIST_DRV) { + return; + } + fdd = np2tool.fdd + drv; + p = fdd->name[0]; + for (cnt=0; cntpos[i]]) < 0) { + break; + } + } + for (j=cnt; j>i; j--) { + fdd->pos[j] = fdd->pos[j-1]; + } + fdd->pos[i] = cnt; + p += sizeof(fdd->name[0]); + } + fdd->cnt = cnt; + sel = (UINT)-1; + if (fdd->insert) { + for (i=0; ipos[i] == 0) { + sel = i; + break; + } + } + } + setlist(toolwin.sub[fddlist[drv]], fdd, sel); +} + static void accdraw(HWND hWnd, BYTE count) { HDC hdc; @@ -331,10 +365,9 @@ static LRESULT CALLBACK twsub(HWND hWnd, return(CallWindowProc(toolwin.subproc[idc], hWnd, msg, wp, lp)); } -static void toolwincreate(HWND hWnd, LPARAM lp) { +static void toolwincreate(HWND hWnd) { HDC hdc; - HINSTANCE hinstance; const SUBITEM *p; UINT i; HWND sub; @@ -350,14 +383,13 @@ const SUBITEM *p; toolwin.access[0] = CreateSolidBrush(0x000060); toolwin.access[1] = CreateSolidBrush(0x0000ff); - hinstance = ((LPCREATESTRUCT)lp)->hInstance; p = subitem; for (i=0; icname, p->text, WS_CHILD | p->style, p->posx, p->posy, p->width, p->height, - hWnd, (HMENU)(i + IDC_BASE), hinstance, NULL); + hWnd, (HMENU)(i + IDC_BASE), hInst, NULL); toolwin.sub[i] = sub; - toolwin.subproc[i] = (SCPROC)GetWindowLong(sub, GWL_WNDPROC); + toolwin.subproc[i] = (SUBCLASSPROC)GetWindowLong(sub, GWL_WNDPROC); SetWindowLong(sub, GWL_WNDPROC, (LONG)twsub); SendMessage(sub, WM_SETFONT, (WPARAM)toolwin.hfont, MAKELPARAM(TRUE, 0)); @@ -365,7 +397,7 @@ const SUBITEM *p; } for (i=0; i= 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; + + 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); +} +#else void toolwin_movingstart(void) { RECT mainrc; @@ -778,6 +993,7 @@ void toolwin_movingend(void) { } toolwin.parentcn = 0; } +#endif void toolwin_setfdd(BYTE drv, const char *name) { @@ -813,12 +1029,11 @@ void toolwin_setfdd(BYTE drv, const char } sysmng_update(SYS_UPDATEOSCFG); if (toolwin.hwnd != NULL) { - setlist(drv); + remakefddlist(drv); SetForegroundWindow(hWndMain); } } - static void setdiskacc(UINT num, BYTE count) { const DISKACC *acc; @@ -887,6 +1102,7 @@ static const char ini_title[] = "NP2 too static const INITBL iniitem[] = { {"WindposX", INITYPE_SINT32, &np2tool.posx, 0}, {"WindposY", INITYPE_SINT32, &np2tool.posy, 0}, + {"SkinFile", INITYPE_STR, np2tool.skin, 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},