| version 1.1.1.1, 2003/10/16 17:59:04 | version 1.11, 2007/10/26 14:38:34 | 
| Line 1 | Line 1 | 
 | #include        "compiler.h" | #include        "compiler.h" | 
 | #include        "strres.h" | #include        "strres.h" | 
 |  | #include        "bmpdata.h" | 
 |  | #include        "oemtext.h" | 
 | #include        "dosio.h" | #include        "dosio.h" | 
 | #include        "commng.h" | #include        "commng.h" | 
 | #include        "sysmng.h" |  | 
 | #include        "dialogs.h" | #include        "dialogs.h" | 
 |  | #if defined(MT32SOUND_DLL) | 
 |  | #include        "mt32snd.h" | 
 |  | #endif | 
 |  |  | 
 |  | extern HINSTANCE hInst; | 
 |  |  | 
 |  |  | 
 |  | const TCHAR str_nc[] = _T("N/C"); | 
 |  |  | 
| static const char str_nc[] = "N/C"; | const TCHAR str_int0[] = _T("INT0"); | 
|  | const TCHAR str_int1[] = _T("INT1"); | 
|  | const TCHAR str_int2[] = _T("INT2"); | 
|  | const TCHAR str_int4[] = _T("INT4"); | 
|  | const TCHAR str_int5[] = _T("INT5"); | 
|  | const TCHAR str_int6[] = _T("INT6"); | 
 |  |  | 
 | static  char    pathname[MAX_PATH]; |  | 
 | static  char    filename[MAX_PATH]; |  | 
 |  |  | 
| const char str_int0[] = "INT0"; | // ---- enable | 
| const char str_int1[] = "INT1"; |  | 
| const char str_int2[] = "INT2"; | void dlgs_enablebyautocheck(HWND hWnd, UINT uID, UINT uCheckID) | 
| const char str_int4[] = "INT4"; | { | 
| const char str_int5[] = "INT5"; | EnableWindow(GetDlgItem(hWnd, uID), | 
| const char str_int6[] = "INT6"; | (SendDlgItemMessage(hWnd, uCheckID, BM_GETCHECK, 0, 0) != 0)); | 
|  | } | 
|  |  | 
|  | void dlgs_disablebyautocheck(HWND hWnd, UINT uID, UINT uCheckID) | 
|  | { | 
|  | EnableWindow(GetDlgItem(hWnd, uID), | 
|  | (SendDlgItemMessage(hWnd, uCheckID, BM_GETCHECK, 0, 0) == 0)); | 
|  |  | 
|  | } | 
 |  |  | 
 |  |  | 
 | // ---- file select | // ---- file select | 
 |  |  | 
| const char *dlgs_selectfile(HWND hWnd, const FILESEL *item, | BOOL dlgs_selectfile(HWND hWnd, const FILESEL *item, | 
| const char *defname, char *folder, UINT size, int *ro) { | OEMCHAR *path, UINT size, int *ro) { | 
 |  |  | 
 |  | TCHAR                   *pszTitle; | 
 | OPENFILENAME    ofn; | OPENFILENAME    ofn; | 
 |  | #if defined(OSLANG_UTF8) | 
 |  | TCHAR                   _path[MAX_PATH]; | 
 |  | #endif | 
 |  | BOOL                    bResult; | 
 |  |  | 
| if ((defname) && (defname[0])) { | if ((item == NULL) || (path == NULL) || (size == 0)) { | 
| milstr_ncpy(pathname, defname, sizeof(pathname)); | return(FALSE); | 
| } |  | 
| else if (folder) { |  | 
| milstr_ncpy(pathname, folder, sizeof(pathname)); |  | 
| } |  | 
| else { |  | 
| pathname[0] = '\0'; |  | 
 | } | } | 
| filename[0] = '\0'; | pszTitle = lockstringresource(hInst, item->title); | 
 |  |  | 
 | ZeroMemory(&ofn, sizeof(OPENFILENAME)); | ZeroMemory(&ofn, sizeof(OPENFILENAME)); | 
 | ofn.lStructSize = sizeof(OPENFILENAME); | ofn.lStructSize = sizeof(OPENFILENAME); | 
 | ofn.hwndOwner = hWnd; | ofn.hwndOwner = hWnd; | 
 | ofn.lpstrFilter = item->filter; | ofn.lpstrFilter = item->filter; | 
 | ofn.nFilterIndex = item->defindex; | ofn.nFilterIndex = item->defindex; | 
| ofn.lpstrFile = pathname; | #if defined(OSLANG_UTF8) | 
| ofn.lpstrFileTitle = filename; | oemtotchar(_path, NELEMENTS(_path), path, -1); | 
| ofn.nMaxFile = MAX_PATH; | ofn.lpstrFile = _path; | 
|  | ofn.nMaxFile = NELEMENTS(_path); | 
|  | #else | 
|  | ofn.lpstrFile = path; | 
|  | ofn.nMaxFile = size; | 
|  | #endif | 
 | ofn.Flags = OFN_FILEMUSTEXIST; | ofn.Flags = OFN_FILEMUSTEXIST; | 
 | ofn.lpstrDefExt = item->ext; | ofn.lpstrDefExt = item->ext; | 
| ofn.lpstrTitle = item->title; | ofn.lpstrTitle = pszTitle; | 
| if (!GetOpenFileName(&ofn)) { |  | 
| return(NULL); | bResult = GetOpenFileName(&ofn); | 
| } | unlockstringresource(pszTitle); | 
| if (folder) { |  | 
| milstr_ncpy(folder, pathname, size); | if (bResult) { | 
| sysmng_update(SYS_UPDATEOSCFG); | #if defined(OSLANG_UTF8) | 
| } | tchartooem(path, NELEMENTS(path), _path, -1); | 
| if (ro) { | #endif | 
| *ro = ofn.Flags & OFN_READONLY; | if (ro) { | 
|  | *ro = ofn.Flags & OFN_READONLY; | 
|  | } | 
 | } | } | 
| return(pathname); | return(bResult); | 
 | } | } | 
 |  |  | 
| const char *dlgs_selectwritefile(HWND hWnd, const FILESEL *item, | BOOL dlgs_selectwritefile(HWND hWnd, const FILESEL *item, | 
| const char *defname, char *folder, UINT size) { | OEMCHAR *path, UINT size) { | 
 |  |  | 
 | OPENFILENAME    ofn; | OPENFILENAME    ofn; | 
 |  | TCHAR                   *pszTitle; | 
 |  | #if defined(OSLANG_UTF8) | 
 |  | TCHAR                   _path[MAX_PATH]; | 
 |  | #endif | 
 |  | BOOL                    bResult; | 
 |  |  | 
| if (defname) { | if ((item == NULL) || (path == NULL) || (size == 0)) { | 
| milstr_ncpy(pathname, defname, sizeof(pathname)); | return(FALSE); | 
| } |  | 
| else { |  | 
| pathname[0] = '\0'; |  | 
 | } | } | 
| filename[0] = '\0'; |  | 
|  | pszTitle = lockstringresource(hInst, item->title); | 
 |  |  | 
 | ZeroMemory(&ofn, sizeof(OPENFILENAME)); | ZeroMemory(&ofn, sizeof(OPENFILENAME)); | 
 | ofn.lStructSize = sizeof(OPENFILENAME); | ofn.lStructSize = sizeof(OPENFILENAME); | 
 | ofn.hwndOwner = hWnd; | ofn.hwndOwner = hWnd; | 
 | ofn.lpstrFilter = item->filter; | ofn.lpstrFilter = item->filter; | 
 | ofn.lpstrFile = pathname; |  | 
 | ofn.lpstrFileTitle = filename; |  | 
 | ofn.nFilterIndex = item->defindex; | ofn.nFilterIndex = item->defindex; | 
| ofn.nMaxFile = MAX_PATH; | #if defined(OSLANG_UTF8) | 
| ofn.nMaxFileTitle = sizeof(filename); | oemtotchar(_path, NELEMENTS(_path), path, -1); | 
|  | ofn.lpstrFile = _path; | 
|  | ofn.nMaxFile = NELEMENTS(_path); | 
|  | #else | 
|  | ofn.lpstrFile = path; | 
|  | ofn.nMaxFile = size; | 
|  | #endif | 
 | ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; | ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; | 
 | ofn.lpstrDefExt = item->ext; | ofn.lpstrDefExt = item->ext; | 
| ofn.lpstrTitle = item->title; | ofn.lpstrTitle = pszTitle; | 
| if (!GetSaveFileName(&ofn)) { |  | 
| return(NULL); | bResult = GetSaveFileName(&ofn); | 
| } |  | 
| if (folder) { | unlockstringresource(pszTitle); | 
| milstr_ncpy(folder, pathname, size); |  | 
| sysmng_update(SYS_UPDATEOSCFG); | #if defined(OSLANG_UTF8) | 
|  | if (bResult) { | 
|  | tchartooem(path, NELEMENTS(path), _path, -1); | 
 | } | } | 
| return(pathname); | #endif | 
|  | return(bResult); | 
 | } | } | 
 |  |  | 
| const char *dlgs_selectwritenum(HWND hWnd, const FILESEL *item, | BOOL dlgs_selectwritenum(HWND hWnd, const FILESEL *item, | 
| const char *defname, char *folder, UINT size) { | OEMCHAR *path, UINT size) { | 
 |  |  | 
| char    numfile[MAX_PATH]; | OEMCHAR *file; | 
| char    *p; | OEMCHAR *p; | 
| int             i; | OEMCHAR *q; | 
|  | UINT    i; | 
|  | BOOL    r; | 
 |  |  | 
| if (folder) { | if ((item == NULL) || (path == NULL) || (size == 0)) { | 
| milstr_ncpy(numfile, folder, sizeof(numfile)); | return(FALSE); | 
| } |  | 
| else { |  | 
| numfile[0] = '\0'; |  | 
 | } | } | 
| file_cutname(numfile); | file = (OEMCHAR *)_MALLOC((size + 16) * sizeof(OEMCHAR), path); | 
| p = numfile + strlen(numfile); | if (file == NULL) { | 
|  | return(FALSE); | 
|  | } | 
|  | p = file_getname(path); | 
|  | milstr_ncpy(file, path, size); | 
|  | file_cutname(file); | 
|  | q = file + OEMSTRLEN(file); | 
|  |  | 
 | for (i=0; i<10000; i++) { | for (i=0; i<10000; i++) { | 
| wsprintf(p, defname, i); | OEMSPRINTF(q, p, i); | 
| if (file_attr(numfile) == -1) { | if (file_attr(file) == (short)-1) { | 
 | break; | break; | 
 | } | } | 
 | } | } | 
| return(dlgs_selectwritefile(hWnd, item, numfile, folder, size)); | r = dlgs_selectwritefile(hWnd, item, file, size); | 
|  | if (r) { | 
|  | milstr_ncpy(path, file, size); | 
|  | } | 
|  | _MFREE(file); | 
|  | return(r); | 
 | } | } | 
 |  |  | 
 |  |  | 
 | // ---- mimpi def file | // ---- mimpi def file | 
 |  |  | 
| static const char mimpi_title[] = "Open MIMPI define file"; | static const TCHAR mimpi_title[] = _T("Open MIMPI define file"); | 
| static const char mimpi_ext[] = "def"; | static const TCHAR mimpi_ext[] = _T("def"); | 
| static const char mimpi_filter[] = "MIMPI define file(*.def)\0*.def\0"; | static const TCHAR mimpi_filter[] = _T("MIMPI define file(*.def)\0*.def\0"); | 
 | static const FILESEL mimpi = {mimpi_title, mimpi_ext, mimpi_filter, 1}; | static const FILESEL mimpi = {mimpi_title, mimpi_ext, mimpi_filter, 1}; | 
 |  |  | 
| void dlgs_browsemimpidef(HWND hWnd, WORD res) { | void dlgs_browsemimpidef(HWND hWnd, UINT16 res) { | 
 |  |  | 
| HWND    subwnd; | HWND            subwnd; | 
| char    path[MAX_PATH]; | OEMCHAR         path[MAX_PATH]; | 
| const char      *p; | const OEMCHAR   *p; | 
 |  |  | 
 | subwnd = GetDlgItem(hWnd, res); | subwnd = GetDlgItem(hWnd, res); | 
| GetWindowText(subwnd, path, sizeof(path)); | GetWindowText(subwnd, path, NELEMENTS(path)); | 
| p = dlgs_selectfile(hWnd, &mimpi, path, NULL, 0, NULL); | if (dlgs_selectfile(hWnd, &mimpi, path, NELEMENTS(path), NULL)) { | 
| if (p == NULL) { | p = path; | 
|  | } | 
|  | else { | 
 | p = str_null; | p = str_null; | 
 | } | } | 
 | SetWindowText(subwnd, p); | SetWindowText(subwnd, p); | 
| Line 146  const char *p; | Line 194  const char *p; | 
 |  |  | 
 | // ---- list | // ---- list | 
 |  |  | 
| void dlgs_setliststr(HWND hWnd, WORD res, const char **item, UINT items) { | void dlgs_setliststr(HWND hWnd, UINT16 res, const TCHAR **item, UINT items) { | 
 |  |  | 
 | HWND    wnd; | HWND    wnd; | 
 | UINT    i; | UINT    i; | 
| Line 157  void dlgs_setliststr(HWND hWnd, WORD res | Line 205  void dlgs_setliststr(HWND hWnd, WORD res | 
 | } | } | 
 | } | } | 
 |  |  | 
| void dlgs_setlistuint32(HWND hWnd, WORD res, const UINT32 *item, UINT items) { | void dlgs_setlistuint32(HWND hWnd, UINT16 res, const UINT32 *item, UINT items) { | 
|  |  | 
 | HWND    wnd; | HWND    wnd; | 
 | UINT    i; | UINT    i; | 
| char    str[16]; | OEMCHAR str[16]; | 
 |  |  | 
 | wnd = GetDlgItem(hWnd, res); | wnd = GetDlgItem(hWnd, res); | 
 | for (i=0; i<items; i++) { | for (i=0; i<items; i++) { | 
| wsprintf(str, str_u, item[i]); | OEMSPRINTF(str, str_u, item[i]); | 
 | SendMessage(wnd, CB_INSERTSTRING, (WPARAM)i, (LPARAM)str); | SendMessage(wnd, CB_INSERTSTRING, (WPARAM)i, (LPARAM)str); | 
 | } | } | 
 | } | } | 
 |  |  | 
 |  |  | 
 |  | void dlgs_setdroplistitem(HWND hWnd, UINT uID, | 
 |  | const TCHAR **ppszItem, UINT uItems) | 
 |  | { | 
 |  | HWND    hItem; | 
 |  | UINT    uPos; | 
 |  | UINT    i; | 
 |  | TCHAR   szString[128]; | 
 |  |  | 
 |  | hItem = GetDlgItem(hWnd, uID); | 
 |  | uPos = 0; | 
 |  | for (i=0; i<uItems; i++) { | 
 |  | LPCTSTR lpcszStr = ppszItem[i]; | 
 |  | if (!HIWORD(lpcszStr)) | 
 |  | { | 
 |  | if (!loadstringresource(hInst, LOWORD(lpcszStr), | 
 |  | szString, NELEMENTS(szString))) | 
 |  | { | 
 |  | continue; | 
 |  | } | 
 |  | lpcszStr = szString; | 
 |  | } | 
 |  | SendMessage(hItem, CB_INSERTSTRING, (WPARAM)uPos, (LPARAM)lpcszStr); | 
 |  | SendMessage(hItem, CB_SETITEMDATA, (WPARAM)uPos, (LPARAM)i); | 
 |  | uPos++; | 
 |  | } | 
 |  | } | 
 |  |  | 
 |  | void dlgs_setdroplistnumber(HWND hWnd, UINT uID, int nNumber) | 
 |  | { | 
 |  | HWND    hItem; | 
 |  | int             nItems; | 
 |  | int             i; | 
 |  |  | 
 |  | hItem = GetDlgItem(hWnd, uID); | 
 |  | nItems = SendMessage(hItem, CB_GETCOUNT, 0, 0); | 
 |  | for (i=0; i<nItems; i++) | 
 |  | { | 
 |  | if (SendMessage(hItem, CB_GETITEMDATA, (WPARAM)i, 0) == nNumber) | 
 |  | { | 
 |  | SendMessage(hItem, CB_SETCURSEL, (WPARAM)i, 0); | 
 |  | break; | 
 |  | } | 
 |  | } | 
 |  | } | 
 |  |  | 
 |  | int dlgs_getdroplistnumber(HWND hWnd, UINT uID) | 
 |  | { | 
 |  | HWND    hItem; | 
 |  | int             nPos; | 
 |  |  | 
 |  | hItem = GetDlgItem(hWnd, uID); | 
 |  | nPos = SendMessage(hItem, CB_GETCURSEL, 0, 0); | 
 |  | if (nPos >= 0) | 
 |  | { | 
 |  | return SendMessage(hItem, CB_GETITEMDATA, (WPARAM)nPos, 0); | 
 |  | } | 
 |  | return -1; | 
 |  | } | 
 |  |  | 
 |  |  | 
 | // ---- MIDIデバイスのリスト | // ---- MIDIデバイスのリスト | 
 |  |  | 
| void dlgs_setlistmidiout(HWND hWnd, WORD res, const char *defname) { | void dlgs_setlistmidiout(HWND hWnd, UINT16 res, const OEMCHAR *defname) { | 
 |  |  | 
 | HWND            wnd; | HWND            wnd; | 
 | UINT            defcur; | UINT            defcur; | 
| Line 198  void dlgs_setlistmidiout(HWND hWnd, WORD | Line 305  void dlgs_setlistmidiout(HWND hWnd, WORD | 
 | } | } | 
 | num++; | num++; | 
 | #endif | #endif | 
 |  | #if defined(MT32SOUND_DLL) | 
 |  | if (mt32sound_isenable()) { | 
 |  | SendMessage(wnd, CB_INSERTSTRING, (WPARAM)num, | 
 |  | (LPARAM)cmmidi_mt32sound); | 
 |  | if (!milstr_cmp(defname, cmmidi_mt32sound)) { | 
 |  | defcur = num; | 
 |  | } | 
 |  | num++; | 
 |  | } | 
 |  | #endif | 
 | for (i=0; i<devs; i++) { | for (i=0; i<devs; i++) { | 
 | if (midiOutGetDevCaps(i, &moc, sizeof(moc)) == MMSYSERR_NOERROR) { | if (midiOutGetDevCaps(i, &moc, sizeof(moc)) == MMSYSERR_NOERROR) { | 
 | SendMessage(wnd, CB_INSERTSTRING, | SendMessage(wnd, CB_INSERTSTRING, | 
| Line 211  void dlgs_setlistmidiout(HWND hWnd, WORD | Line 328  void dlgs_setlistmidiout(HWND hWnd, WORD | 
 | SendMessage(wnd, CB_SETCURSEL, (WPARAM)defcur, (LPARAM)0); | SendMessage(wnd, CB_SETCURSEL, (WPARAM)defcur, (LPARAM)0); | 
 | } | } | 
 |  |  | 
| void dlgs_setlistmidiin(HWND hWnd, WORD res, const char *defname) { | void dlgs_setlistmidiin(HWND hWnd, UINT16 res, const OEMCHAR *defname) { | 
 |  |  | 
 | HWND            wnd; | HWND            wnd; | 
 | UINT            defcur; | UINT            defcur; | 
| Line 236  void dlgs_setlistmidiin(HWND hWnd, WORD | Line 353  void dlgs_setlistmidiin(HWND hWnd, WORD | 
 | } | } | 
 |  |  | 
 |  |  | 
 | // ---- draw |  | 
 |  |  | 
 | void dlgs_linex(BYTE *image, int x, int y, int l, int align, BYTE c) { |  | 
 |  |  | 
 | image -= y * align; |  | 
 | while(l--) { |  | 
 | if (x & 1) { |  | 
 | image[x/2] &= 0xf0; |  | 
 | image[x/2] |= c; |  | 
 | } |  | 
 | else { |  | 
 | image[x/2] &= 0x0f; |  | 
 | image[x/2] |= (c << 4); |  | 
 | } |  | 
 | x++; |  | 
 | } |  | 
 | } |  | 
 |  |  | 
 | void dlgs_liney(BYTE *image, int x, int y, int l, int align, BYTE c) { |  | 
 |  |  | 
 | image += (x / 2) - y * align; |  | 
 | if (x & 1) { |  | 
 | while(l--) { |  | 
 | *image &= 0xf0; |  | 
 | *image |= c; |  | 
 | image -= align; |  | 
 | } |  | 
 | } |  | 
 | else { |  | 
 | c <<= 4; |  | 
 | while(l--) { |  | 
 | *image &= 0x0f; |  | 
 | *image |= c; |  | 
 | image -= align; |  | 
 | } |  | 
 | } |  | 
 | } |  | 
 |  |  | 
 |  |  | 
| // ---- jumper | // ---- draw | 
|  |  | 
| void dlgs_setjumperx(BYTE *image, int x, int y, int align) { |  | 
|  |  | 
| int             i; |  | 
|  |  | 
| x *= 9; |  | 
| y *= 9; |  | 
| for (i=0; i<2; i++) { |  | 
| dlgs_linex(image, x, y+0+i, 19, align, 0); |  | 
| dlgs_linex(image, x, y+8+i, 19, align, 0); |  | 
| dlgs_liney(image, x+ 0+i, y, 9, align, 0); |  | 
| dlgs_liney(image, x+17+i, y, 9, align, 0); |  | 
| } |  | 
| } |  | 
 |  |  | 
| void dlgs_setjumpery(BYTE *image, int x, int y, int align) { | void dlgs_drawbmp(HDC hdc, UINT8 *bmp) { | 
 |  |  | 
| int             i; | BMPFILE         *bf; | 
|  | BMPINFO         *bi; | 
| x *= 9; | BMPDATA         inf; | 
| y *= 9; | HBITMAP         hbmp; | 
| for (i=0; i<2; i++) { | UINT8           *image; | 
| dlgs_linex(image, x, y+ 0+i, 9, align, 0); | HDC                     hmdc; | 
| dlgs_linex(image, x, y+17+i, 9, align, 0); |  | 
| dlgs_liney(image, x+0+i, y, 19, align, 0); | if (bmp == NULL) { | 
| dlgs_liney(image, x+8+i, y, 19, align, 0); | return; | 
| } | } | 
|  | bf = (BMPFILE *)bmp; | 
|  | bi = (BMPINFO *)(bf + 1); | 
|  | if (bmpdata_getinfo(bi, &inf) != SUCCESS) { | 
|  | goto dsdb_err1; | 
|  | } | 
|  | hbmp = CreateDIBSection(hdc, (BITMAPINFO *)bi, DIB_RGB_COLORS, | 
|  | (void **)&image, NULL, 0); | 
|  | if (hbmp == NULL) { | 
|  | goto dsdb_err1; | 
|  | } | 
|  | CopyMemory(image, bmp + (LOADINTELDWORD(bf->bfOffBits)), | 
|  | bmpdata_getdatasize(bi)); | 
|  | hmdc = CreateCompatibleDC(hdc); | 
|  | SelectObject(hmdc, hbmp); | 
|  | if (inf.height < 0) { | 
|  | inf.height *= -1; | 
|  | } | 
|  | BitBlt(hdc, 0, 0, inf.width, inf.height, hmdc, 0, 0, SRCCOPY); | 
|  | DeleteDC(hmdc); | 
|  | DeleteObject(hbmp); | 
|  |  | 
|  | dsdb_err1: | 
|  | _MFREE(bmp); | 
|  | } | 
|  |  | 
|  |  | 
|  | // ---- | 
|  |  | 
|  | BOOL dlgs_getitemrect(HWND hWnd, UINT uID, RECT *pRect) | 
|  | { | 
|  | HWND    hItem; | 
|  | POINT   pt; | 
|  |  | 
|  | if (pRect == NULL) | 
|  | { | 
|  | return FALSE; | 
|  | } | 
|  | hItem = GetDlgItem(hWnd, uID); | 
|  | if (!GetWindowRect(hItem, pRect)) | 
|  | { | 
|  | return FALSE; | 
|  | } | 
|  | ZeroMemory(&pt, sizeof(pt)); | 
|  | if (!ClientToScreen(hWnd, &pt)) | 
|  | { | 
|  | return FALSE; | 
|  | } | 
|  | pRect->left -= pt.x; | 
|  | pRect->top -= pt.y; | 
|  | pRect->right -= pt.x; | 
|  | pRect->bottom -= pt.y; | 
|  | return TRUE; | 
 | } | } | 
 |  |  |