--- np2/win9x/dialog/dialogs.cpp 2003/10/16 17:59:04 1.1 +++ np2/win9x/dialog/dialogs.cpp 2011/03/07 09:54:11 1.18 @@ -1,143 +1,267 @@ -#include "compiler.h" -#include "strres.h" -#include "dosio.h" -#include "commng.h" -#include "sysmng.h" -#include "dialogs.h" - - -static const char str_nc[] = "N/C"; - -static char pathname[MAX_PATH]; -static char filename[MAX_PATH]; - -const char str_int0[] = "INT0"; -const char str_int1[] = "INT1"; -const char str_int2[] = "INT2"; -const char str_int4[] = "INT4"; -const char str_int5[] = "INT5"; -const char str_int6[] = "INT6"; +/** + * @file dialogs.cpp + * @brief Dialog subroutines + * + * @author $Author: yui $ + * @date $Date: 2011/03/07 09:54:11 $ + */ + +#include "compiler.h" +#include "resource.h" +#include "strres.h" +#include "bmpdata.h" +#include "oemtext.h" +#include "dosio.h" +#include "commng.h" +#include "dialogs.h" +#include "np2.h" +#if defined(MT32SOUND_DLL) +#include "mt32snd.h" +#endif +#if !defined(__GNUC__) +#pragma comment(lib, "winmm.lib") +#endif // !defined(__GNUC__) + +// ---- enable + +void dlgs_enablebyautocheck(HWND hWnd, UINT uID, UINT uCheckID) +{ + EnableWindow(GetDlgItem(hWnd, uID), + (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 +} -const char *dlgs_selectfile(HWND hWnd, const FILESEL *item, - const char *defname, char *folder, UINT size, int *ro) { - OPENFILENAME ofn; +// ---- file select - if ((defname) && (defname[0])) { - milstr_ncpy(pathname, defname, sizeof(pathname)); - } - else if (folder) { - milstr_ncpy(pathname, folder, sizeof(pathname)); +static BOOL openFileParam(LPOPENFILENAME lpOFN, PCFSPARAM pcParam, + OEMCHAR *pszPath, UINT uSize, + BOOL (WINAPI * fnAPI)(LPOPENFILENAME lpofn)) +{ + LPTSTR lpszTitle; + LPTSTR lpszFilter; + LPTSTR lpszDefExt; + LPTSTR p; +#if defined(OSLANG_UTF8) + TCHAR szPath[MAX_PATH]; +#endif // defined(OSLANG_UTF8) + BOOL bResult; + + if ((lpOFN == NULL) || (pcParam == NULL) || + (pszPath == NULL) || (uSize == 0) || (fnAPI == NULL)) + { + return FALSE; + } + + if (!HIWORD(pcParam->lpszTitle)) + { + lpszTitle = lockstringresource(pcParam->lpszTitle); + lpOFN->lpstrTitle = lpszTitle; + } + else + { + lpszTitle = NULL; + lpOFN->lpstrTitle = pcParam->lpszTitle; + } + + if (!HIWORD(pcParam->lpszFilter)) + { + lpszFilter = lockstringresource(pcParam->lpszFilter); + lpOFN->lpstrFilter = lpszFilter; + } + else + { + lpszFilter = NULL; + lpOFN->lpstrFilter = pcParam->lpszFilter; + } + + if (!HIWORD(pcParam->lpszDefExt)) + { + lpszDefExt = lockstringresource(pcParam->lpszDefExt); + lpOFN->lpstrDefExt = lpszDefExt; + } + else + { + lpszDefExt = NULL; + lpOFN->lpstrDefExt = pcParam->lpszDefExt; + } + + lpOFN->nFilterIndex = pcParam->nFilterIndex; + + + p = lpszFilter; + if (p) + { + while(*p != '\0') + { +#if !defined(_UNICODE) + if (IsDBCSLeadByte((BYTE)*p)) + { + p += 2; + continue; + } +#endif // !defined(_UNICODE) + if (*p == '|') + { + *p = '\0'; + } + p++; + } } - else { - pathname[0] = '\0'; + +#if defined(OSLANG_UTF8) + oemtotchar(szPath, NELEMENTS(szPath), pszPath, -1); + lpOFN->lpstrFile = szPath; + lpOFN->nMaxFile = NELEMENTS(szPath); +#else // defined(OSLANG_UTF8) + lpOFN->lpstrFile = pszPath; + lpOFN->nMaxFile = uSize; +#endif // defined(OSLANG_UTF8) + + bResult = (*fnAPI)(lpOFN); + +#if defined(OSLANG_UTF8) + if (bResult) + { + tchartooem(pszPath, uSize, szPath, -1); } - filename[0] = '\0'; +#endif // defined(OSLANG_UTF8) - ZeroMemory(&ofn, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = hWnd; - ofn.lpstrFilter = item->filter; - ofn.nFilterIndex = item->defindex; - ofn.lpstrFile = pathname; - ofn.lpstrFileTitle = filename; - ofn.nMaxFile = MAX_PATH; - ofn.Flags = OFN_FILEMUSTEXIST; - ofn.lpstrDefExt = item->ext; - ofn.lpstrTitle = item->title; - if (!GetOpenFileName(&ofn)) { - return(NULL); + if (lpszTitle) + { + unlockstringresource(lpszTitle); } - if (folder) { - milstr_ncpy(folder, pathname, size); - sysmng_update(SYS_UPDATEOSCFG); + if (lpszFilter) + { + unlockstringresource(lpszFilter); } - if (ro) { - *ro = ofn.Flags & OFN_READONLY; + if (lpszDefExt) + { + unlockstringresource(lpszDefExt); } - return(pathname); -} -const char *dlgs_selectwritefile(HWND hWnd, const FILESEL *item, - const char *defname, char *folder, UINT size) { + return bResult; +} +BOOL dlgs_openfile(HWND hWnd, PCFSPARAM pcParam, + OEMCHAR *pszPath, UINT uSize, int *pnRO) +{ OPENFILENAME ofn; + BOOL bResult; - if (defname) { - milstr_ncpy(pathname, defname, sizeof(pathname)); - } - else { - pathname[0] = '\0'; - } - filename[0] = '\0'; - - ZeroMemory(&ofn, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hWnd; - ofn.lpstrFilter = item->filter; - ofn.lpstrFile = pathname; - ofn.lpstrFileTitle = filename; - ofn.nFilterIndex = item->defindex; - ofn.nMaxFile = MAX_PATH; - ofn.nMaxFileTitle = sizeof(filename); - ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; - ofn.lpstrDefExt = item->ext; - ofn.lpstrTitle = item->title; - if (!GetSaveFileName(&ofn)) { - return(NULL); + ofn.Flags = OFN_FILEMUSTEXIST; + + if (pnRO == NULL) + { + ofn.Flags |= OFN_HIDEREADONLY; } - if (folder) { - milstr_ncpy(folder, pathname, size); - sysmng_update(SYS_UPDATEOSCFG); + + bResult = openFileParam(&ofn, pcParam, pszPath, uSize, GetOpenFileName); + + if ((bResult) && (pnRO != NULL)) + { + *pnRO = ofn.Flags & OFN_READONLY; } - return(pathname); + + return bResult; } -const char *dlgs_selectwritenum(HWND hWnd, const FILESEL *item, - const char *defname, char *folder, UINT size) { +BOOL dlgs_createfile(HWND hWnd, PCFSPARAM pcParam, + OEMCHAR *pszPath, UINT uSize) +{ + OPENFILENAME ofn; - char numfile[MAX_PATH]; - char *p; - int i; + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = hWnd; + ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; + return openFileParam(&ofn, pcParam, pszPath, uSize, GetSaveFileName); +} - if (folder) { - milstr_ncpy(numfile, folder, sizeof(numfile)); - } - else { - numfile[0] = '\0'; - } - file_cutname(numfile); - p = numfile + strlen(numfile); - for (i=0; i<10000; i++) { - wsprintf(p, defname, i); - if (file_attr(numfile) == -1) { +BOOL dlgs_createfilenum(HWND hWnd, PCFSPARAM pcParam, + OEMCHAR *pszPath, UINT uSize) +{ + OEMCHAR *pszNum[4]; + OEMCHAR *pszFile; + UINT uCount; + UINT uPos; + + if (!pszPath) + { + return FALSE; + } + + ZeroMemory(pszNum, sizeof(pszNum)); + pszFile = file_getname(pszPath); + uCount = 0; + while(1) + { + pszFile = milstr_chr(pszPath, '#'); + if (!pszFile) + { + break; + } + *pszFile = '0'; + pszNum[uCount] = pszFile; + uCount = (uCount + 1) % NELEMENTS(pszNum); + pszFile++; + } + + while(file_attr(pszPath) != (short)-1) + { + uPos = max(uCount, NELEMENTS(pszNum)); + while(uPos) + { + pszFile = pszNum[(uPos - 1) % NELEMENTS(pszNum)]; + *pszFile = *pszFile + 1; + if (*pszFile < ('0' + 10)) + { + break; + } + *pszFile = '0'; + uPos--; + } + if (!uPos) + { break; } } - return(dlgs_selectwritefile(hWnd, item, numfile, folder, size)); + return dlgs_createfile(hWnd, pcParam, pszPath, uSize); } // ---- mimpi def file -static const char mimpi_title[] = "Open MIMPI define file"; -static const char mimpi_ext[] = "def"; -static const char mimpi_filter[] = "MIMPI define file(*.def)\0*.def\0"; -static const FILESEL mimpi = {mimpi_title, mimpi_ext, mimpi_filter, 1}; - -void dlgs_browsemimpidef(HWND hWnd, WORD res) { - - HWND subwnd; - char path[MAX_PATH]; -const char *p; +static const FSPARAM fpMIMPI = +{ + MAKEINTRESOURCE(IDS_MIMPITITLE), + MAKEINTRESOURCE(IDS_MIMPIEXT), + MAKEINTRESOURCE(IDS_MIMPIFILTER), + 1 +}; + +void dlgs_browsemimpidef(HWND hWnd, UINT16 res) { + + HWND subwnd; + OEMCHAR path[MAX_PATH]; +const OEMCHAR *p; subwnd = GetDlgItem(hWnd, res); - GetWindowText(subwnd, path, sizeof(path)); - p = dlgs_selectfile(hWnd, &mimpi, path, NULL, 0, NULL); - if (p == NULL) { + GetWindowText(subwnd, path, NELEMENTS(path)); + if (dlgs_openfile(hWnd, &fpMIMPI, path, NELEMENTS(path), NULL)) { + p = path; + } + else { p = str_null; } SetWindowText(subwnd, p); @@ -146,7 +270,7 @@ const char *p; // ---- 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; UINT i; @@ -157,23 +281,112 @@ 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; UINT i; - char str[16]; + OEMCHAR str[16]; wnd = GetDlgItem(hWnd, res); for (i=0; i= 0) + { + SendMessage(hItem, CB_SETITEMDATA, + (WPARAM)nIndex, (LPARAM)pcItem[i].nItemData); + } + } +} + +void dlgs_setcbnumber(HWND hWnd, UINT uID, PCCBNPARAM pcItem, UINT uItems) +{ + HWND hItem; + UINT i; + TCHAR szValue[16]; + int nIndex; + + hItem = GetDlgItem(hWnd, uID); + for (i=0; i= 0) + { + SendMessage(hItem, CB_SETITEMDATA, + (WPARAM)nIndex, (LPARAM)pcItem[i].nItemData); + } + } +} + +void dlgs_setcbcur(HWND hWnd, UINT uID, int nItemData) +{ + HWND hItem; + int nItems; + int i; + + hItem = GetDlgItem(hWnd, uID); + nItems = (int)SendMessage(hItem, CB_GETCOUNT, 0, 0); + for (i=0; i= 0) + { + return (int)SendMessage(hItem, CB_GETITEMDATA, (WPARAM)nPos, 0); + } + return nDefault; +} + // ---- MIDIデバイスのリスト -void dlgs_setlistmidiout(HWND hWnd, WORD res, const char *defname) { +static void insertnc(HWND hWnd, int nPos) +{ + TCHAR szNC[128]; + + loadstringresource(LOWORD(IDS_NONCONNECT), szNC, NELEMENTS(szNC)); + SendMessage(hWnd, CB_INSERTSTRING, (WPARAM)nPos, (LPARAM)szNC); +} + +void dlgs_setlistmidiout(HWND hWnd, UINT16 res, const OEMCHAR *defname) { HWND wnd; UINT defcur; @@ -185,7 +398,7 @@ void dlgs_setlistmidiout(HWND hWnd, WORD wnd = GetDlgItem(hWnd, res); defcur = 0; devs = midiOutGetNumDevs(); - SendMessage(wnd, CB_INSERTSTRING, (WPARAM)0, (LPARAM)str_nc); + insertnc(wnd, 0); SendMessage(wnd, CB_INSERTSTRING, (WPARAM)1, (LPARAM)cmmidi_midimapper); if (!milstr_cmp(defname, cmmidi_midimapper)) { defcur = 1; @@ -198,6 +411,16 @@ void dlgs_setlistmidiout(HWND hWnd, WORD } num++; #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; ibfOffBits)), + 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; }