Diff for /np2/win9x/dialog/dialogs.cpp between versions 1.11 and 1.15

version 1.11, 2007/10/26 14:38:34 version 1.15, 2007/12/17 14:52:56
Line 1 Line 1
 #include        "compiler.h"  #include        "compiler.h"
   #include        "resource.h"
 #include        "strres.h"  #include        "strres.h"
 #include        "bmpdata.h"  #include        "bmpdata.h"
 #include        "oemtext.h"  #include        "oemtext.h"
 #include        "dosio.h"  #include        "dosio.h"
 #include        "commng.h"  #include        "commng.h"
 #include        "dialogs.h"  #include        "dialogs.h"
   #include        "np2.h"
 #if defined(MT32SOUND_DLL)  #if defined(MT32SOUND_DLL)
 #include        "mt32snd.h"  #include        "mt32snd.h"
 #endif  #endif
   
 extern HINSTANCE hInst;  
   
   
 const TCHAR str_nc[] = _T("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");  
   
   
 // ---- enable  // ---- enable
Line 40  void dlgs_disablebyautocheck(HWND hWnd,  Line 31  void dlgs_disablebyautocheck(HWND hWnd, 
   
 // ---- file select  // ---- file select
   
 BOOL dlgs_selectfile(HWND hWnd, const FILESEL *item,  static BOOL openFileParam(LPOPENFILENAME lpOFN, PCFSPARAM pcParam,
                                                                                 OEMCHAR *path, UINT size, int *ro) {                                                          OEMCHAR *pszPath, UINT uSize,
                                                           BOOL (WINAPI * fnAPI)(LPOPENFILENAME lpofn))
         TCHAR                   *pszTitle;  {
         OPENFILENAME    ofn;          HINSTANCE       hInstance;
           LPTSTR          lpszTitle;
           LPTSTR          lpszFilter;
           LPTSTR          lpszDefExt;
           LPTSTR          p;
 #if defined(OSLANG_UTF8)  #if defined(OSLANG_UTF8)
         TCHAR                   _path[MAX_PATH];          TCHAR           szPath[MAX_PATH];
 #endif  #endif  // defined(OSLANG_UTF8)
         BOOL                    bResult;          BOOL            bResult;
   
         if ((item == NULL) || (path == NULL) || (size == 0)) {          if ((lpOFN == NULL) || (pcParam == NULL) ||
                 return(FALSE);                  (pszPath == NULL) || (uSize == 0) || (fnAPI == NULL))
           {
                   return FALSE;
         }          }
         pszTitle = lockstringresource(hInst, item->title);  
   
         ZeroMemory(&ofn, sizeof(OPENFILENAME));          hInstance = g_hInstance;
         ofn.lStructSize = sizeof(OPENFILENAME);  
         ofn.hwndOwner = hWnd;  
         ofn.lpstrFilter = item->filter;  
         ofn.nFilterIndex = item->defindex;  
 #if defined(OSLANG_UTF8)  
         oemtotchar(_path, NELEMENTS(_path), path, -1);  
         ofn.lpstrFile = _path;  
         ofn.nMaxFile = NELEMENTS(_path);  
 #else  
         ofn.lpstrFile = path;  
         ofn.nMaxFile = size;  
 #endif  
         ofn.Flags = OFN_FILEMUSTEXIST;  
         ofn.lpstrDefExt = item->ext;  
         ofn.lpstrTitle = pszTitle;  
   
         bResult = GetOpenFileName(&ofn);          if (!HIWORD(pcParam->lpszTitle))
         unlockstringresource(pszTitle);          {
                   lpszTitle = lockstringresource(hInstance, pcParam->lpszTitle);
                   lpOFN->lpstrTitle = lpszTitle;
           }
           else
           {
                   lpszTitle = NULL;
                   lpOFN->lpstrTitle = pcParam->lpszTitle;
           }
   
         if (bResult) {          if (!HIWORD(pcParam->lpszFilter))
 #if defined(OSLANG_UTF8)          {
                 tchartooem(path, NELEMENTS(path), _path, -1);                  lpszFilter = lockstringresource(hInstance, pcParam->lpszFilter);
 #endif                  lpOFN->lpstrFilter = lpszFilter;
                 if (ro) {          }
                         *ro = ofn.Flags & OFN_READONLY;          else
           {
                   lpszFilter = NULL;
                   lpOFN->lpstrFilter = pcParam->lpszFilter;
           }
   
           if (!HIWORD(pcParam->lpszDefExt))
           {
                   lpszDefExt = lockstringresource(hInstance, 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++;
                 }                  }
         }          }
         return(bResult);  
 }  
   
 BOOL dlgs_selectwritefile(HWND hWnd, const FILESEL *item,  #if defined(OSLANG_UTF8)
                                                                                         OEMCHAR *path, UINT size) {          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);
   
         OPENFILENAME    ofn;  
         TCHAR                   *pszTitle;  
 #if defined(OSLANG_UTF8)  #if defined(OSLANG_UTF8)
         TCHAR                   _path[MAX_PATH];          if (bResult)
 #endif          {
         BOOL                    bResult;                  tchartooem(pszPath, uSize, szPath, -1);
           }
   #endif  // defined(OSLANG_UTF8)
   
         if ((item == NULL) || (path == NULL) || (size == 0)) {          if (lpszTitle)
                 return(FALSE);          {
                   unlockstringresource(lpszTitle);
           }
           if (lpszFilter)
           {
                   unlockstringresource(lpszFilter);
           }
           if (lpszDefExt)
           {
                   unlockstringresource(lpszDefExt);
         }          }
   
         pszTitle = lockstringresource(hInst, item->title);          return bResult;
   }
   
         ZeroMemory(&ofn, sizeof(OPENFILENAME));  BOOL dlgs_openfile(HWND hWnd, PCFSPARAM pcParam,
         ofn.lStructSize = sizeof(OPENFILENAME);                                                                          OEMCHAR *pszPath, UINT uSize, int *pnRO)
   {
           OPENFILENAME    ofn;
           BOOL                    bResult;
   
           ZeroMemory(&ofn, sizeof(ofn));
           ofn.lStructSize = sizeof(ofn);
         ofn.hwndOwner = hWnd;          ofn.hwndOwner = hWnd;
         ofn.lpstrFilter = item->filter;          ofn.Flags = OFN_FILEMUSTEXIST;
         ofn.nFilterIndex = item->defindex;  
 #if defined(OSLANG_UTF8)  
         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.lpstrDefExt = item->ext;  
         ofn.lpstrTitle = pszTitle;  
   
         bResult = GetSaveFileName(&ofn);          if (pnRO == NULL)
           {
                   ofn.Flags |= OFN_HIDEREADONLY;
           }
   
         unlockstringresource(pszTitle);          bResult = openFileParam(&ofn, pcParam, pszPath, uSize, GetOpenFileName);
   
 #if defined(OSLANG_UTF8)          if ((bResult) && (pnRO != NULL))
         if (bResult) {          {
                 tchartooem(path, NELEMENTS(path), _path, -1);                  *pnRO = ofn.Flags & OFN_READONLY;
         }          }
 #endif  
         return(bResult);          return bResult;
 }  }
   
 BOOL dlgs_selectwritenum(HWND hWnd, const FILESEL *item,  BOOL dlgs_createfile(HWND hWnd, PCFSPARAM pcParam,
                                                                                         OEMCHAR *path, UINT size) {                                                                                                  OEMCHAR *pszPath, UINT uSize)
   {
           OPENFILENAME    ofn;
   
         OEMCHAR *file;          ZeroMemory(&ofn, sizeof(ofn));
         OEMCHAR *p;          ofn.lStructSize = sizeof(ofn);
         OEMCHAR *q;          ofn.hwndOwner = hWnd;
         UINT    i;          ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
         BOOL    r;          return openFileParam(&ofn, pcParam, pszPath, uSize, GetSaveFileName);
   }
   
         if ((item == NULL) || (path == NULL) || (size == 0)) {  BOOL dlgs_createfilenum(HWND hWnd, PCFSPARAM pcParam,
                 return(FALSE);                                                                                                  OEMCHAR *pszPath, UINT uSize)
   {
           OEMCHAR *pszNum[4];
           OEMCHAR *pszFile;
           UINT uCount;
           UINT uPos;
   
           if (!pszPath)
           {
                   return FALSE;
         }          }
         file = (OEMCHAR *)_MALLOC((size + 16) * sizeof(OEMCHAR), path);  
         if (file == NULL) {          ZeroMemory(pszNum, sizeof(pszNum));
                 return(FALSE);          pszFile = file_getname(pszPath);
         }          uCount = 0;
         p = file_getname(path);          while(1)
         milstr_ncpy(file, path, size);          {
         file_cutname(file);                  pszFile = milstr_chr(pszPath, '#');
         q = file + OEMSTRLEN(file);                  if (!pszFile)
                   {
         for (i=0; i<10000; i++) {  
                 OEMSPRINTF(q, p, i);  
                 if (file_attr(file) == (short)-1) {  
                         break;                          break;
                 }                  }
                   *pszFile = '0';
                   pszNum[uCount] = pszFile;
                   uCount = (uCount + 1) % NELEMENTS(pszNum);
                   pszFile++;
         }          }
         r = dlgs_selectwritefile(hWnd, item, file, size);  
         if (r) {          while(file_attr(pszPath) != (short)-1)
                 milstr_ncpy(path, file, size);          {
                   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;
                   }
         }          }
         _MFREE(file);          return dlgs_createfile(hWnd, pcParam, pszPath, uSize);
         return(r);  
 }  }
   
   
 // ---- mimpi def file  // ---- mimpi def file
   
 static const TCHAR mimpi_title[] = _T("Open MIMPI define file");  static const FSPARAM fpMIMPI =
 static const TCHAR mimpi_ext[] = _T("def");  {
 static const TCHAR mimpi_filter[] = _T("MIMPI define file(*.def)\0*.def\0");          MAKEINTRESOURCE(IDS_MIMPITITLE),
 static const FILESEL mimpi = {mimpi_title, mimpi_ext, mimpi_filter, 1};          MAKEINTRESOURCE(IDS_MIMPIEXT),
           MAKEINTRESOURCE(IDS_MIMPIFILTER),
           1
   };
   
 void dlgs_browsemimpidef(HWND hWnd, UINT16 res) {  void dlgs_browsemimpidef(HWND hWnd, UINT16 res) {
   
Line 182  const OEMCHAR *p; Line 251  const OEMCHAR *p;
   
         subwnd = GetDlgItem(hWnd, res);          subwnd = GetDlgItem(hWnd, res);
         GetWindowText(subwnd, path, NELEMENTS(path));          GetWindowText(subwnd, path, NELEMENTS(path));
         if (dlgs_selectfile(hWnd, &mimpi, path, NELEMENTS(path), NULL)) {          if (dlgs_openfile(hWnd, &fpMIMPI, path, NELEMENTS(path), NULL)) {
                 p = path;                  p = path;
         }          }
         else {          else {
Line 217  void dlgs_setlistuint32(HWND hWnd, UINT1 Line 286  void dlgs_setlistuint32(HWND hWnd, UINT1
         }          }
 }  }
   
   void dlgs_setcbitem(HWND hWnd, UINT uID, PCCBPARAM pcItem, UINT uItems)
 void dlgs_setdroplistitem(HWND hWnd, UINT uID,  
                                                                                 const TCHAR **ppszItem, UINT uItems)  
 {  {
         HWND    hItem;          HWND    hItem;
         UINT    uPos;  
         UINT    i;          UINT    i;
           LPCTSTR lpcszStr;
         TCHAR   szString[128];          TCHAR   szString[128];
           int             nIndex;
   
         hItem = GetDlgItem(hWnd, uID);          hItem = GetDlgItem(hWnd, uID);
         uPos = 0;          for (i=0; i<uItems; i++)
         for (i=0; i<uItems; i++) {          {
                 LPCTSTR lpcszStr = ppszItem[i];                  lpcszStr = pcItem[i].lpcszString;
                 if (!HIWORD(lpcszStr))                  if (!HIWORD(lpcszStr))
                 {                  {
                         if (!loadstringresource(hInst, LOWORD(lpcszStr),                          if (!loadstringresource(g_hInstance, LOWORD(lpcszStr),
                                                                                         szString, NELEMENTS(szString)))                                                                                          szString, NELEMENTS(szString)))
                         {                          {
                                 continue;                                  continue;
                         }                          }
                         lpcszStr = szString;                          lpcszStr = szString;
                 }                  }
                 SendMessage(hItem, CB_INSERTSTRING, (WPARAM)uPos, (LPARAM)lpcszStr);                  nIndex = SendMessage(hItem, CB_ADDSTRING, 0, (LPARAM)lpcszStr);
                 SendMessage(hItem, CB_SETITEMDATA, (WPARAM)uPos, (LPARAM)i);                  if (nIndex >= 0)
                 uPos++;                  {
                           SendMessage(hItem, CB_SETITEMDATA,
                                                                   (WPARAM)nIndex, (LPARAM)pcItem[i].nItemData);
                   }
         }          }
 }  }
   
 void dlgs_setdroplistnumber(HWND hWnd, UINT uID, int nNumber)  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<uItems; i++)
           {
                   wsprintf(szValue, str_u, pcItem[i].uValue);
                   nIndex = SendMessage(hItem, CB_ADDSTRING, 0, (LPARAM)szValue);
                   if (nIndex >= 0)
                   {
                           SendMessage(hItem, CB_SETITEMDATA,
                                                                   (WPARAM)nIndex, (LPARAM)pcItem[i].nItemData);
                   }
           }
   }
   
   void dlgs_setcbcur(HWND hWnd, UINT uID, int nItemData)
 {  {
         HWND    hItem;          HWND    hItem;
         int             nItems;          int             nItems;
Line 255  void dlgs_setdroplistnumber(HWND hWnd, U Line 346  void dlgs_setdroplistnumber(HWND hWnd, U
         nItems = SendMessage(hItem, CB_GETCOUNT, 0, 0);          nItems = SendMessage(hItem, CB_GETCOUNT, 0, 0);
         for (i=0; i<nItems; i++)          for (i=0; i<nItems; i++)
         {          {
                 if (SendMessage(hItem, CB_GETITEMDATA, (WPARAM)i, 0) == nNumber)                  if (SendMessage(hItem, CB_GETITEMDATA, (WPARAM)i, 0) == nItemData)
                 {                  {
                         SendMessage(hItem, CB_SETCURSEL, (WPARAM)i, 0);                          SendMessage(hItem, CB_SETCURSEL, (WPARAM)i, 0);
                         break;                          break;
Line 263  void dlgs_setdroplistnumber(HWND hWnd, U Line 354  void dlgs_setdroplistnumber(HWND hWnd, U
         }          }
 }  }
   
 int dlgs_getdroplistnumber(HWND hWnd, UINT uID)  int dlgs_getcbcur(HWND hWnd, UINT uID, int nDefault)
 {  {
         HWND    hItem;          HWND    hItem;
         int             nPos;          int             nPos;
Line 274  int dlgs_getdroplistnumber(HWND hWnd, UI Line 365  int dlgs_getdroplistnumber(HWND hWnd, UI
         {          {
                 return SendMessage(hItem, CB_GETITEMDATA, (WPARAM)nPos, 0);                  return SendMessage(hItem, CB_GETITEMDATA, (WPARAM)nPos, 0);
         }          }
         return -1;          return nDefault;
 }  }
   
   
 // ---- MIDIデバイスのリスト  // ---- MIDIデバイスのリスト
   
   static void insertnc(HWND hWnd, int nPos)
   {
           TCHAR   szNC[128];
   
           loadstringresource(g_hInstance, LOWORD(IDS_NONCONNECT),
                                                                                                           szNC, NELEMENTS(szNC));
           SendMessage(hWnd, CB_INSERTSTRING, (WPARAM)nPos, (LPARAM)szNC);
   }
   
 void dlgs_setlistmidiout(HWND hWnd, UINT16 res, const OEMCHAR *defname) {  void dlgs_setlistmidiout(HWND hWnd, UINT16 res, const OEMCHAR *defname) {
   
         HWND            wnd;          HWND            wnd;
Line 292  void dlgs_setlistmidiout(HWND hWnd, UINT Line 392  void dlgs_setlistmidiout(HWND hWnd, UINT
         wnd = GetDlgItem(hWnd, res);          wnd = GetDlgItem(hWnd, res);
         defcur = 0;          defcur = 0;
         devs = midiOutGetNumDevs();          devs = midiOutGetNumDevs();
         SendMessage(wnd, CB_INSERTSTRING, (WPARAM)0, (LPARAM)str_nc);          insertnc(wnd, 0);
         SendMessage(wnd, CB_INSERTSTRING, (WPARAM)1, (LPARAM)cmmidi_midimapper);          SendMessage(wnd, CB_INSERTSTRING, (WPARAM)1, (LPARAM)cmmidi_midimapper);
         if (!milstr_cmp(defname, cmmidi_midimapper)) {          if (!milstr_cmp(defname, cmmidi_midimapper)) {
                 defcur = 1;                  defcur = 1;
Line 339  void dlgs_setlistmidiin(HWND hWnd, UINT1 Line 439  void dlgs_setlistmidiin(HWND hWnd, UINT1
         wnd = GetDlgItem(hWnd, res);          wnd = GetDlgItem(hWnd, res);
         defcur = 0;          defcur = 0;
         num = midiInGetNumDevs();          num = midiInGetNumDevs();
         SendMessage(wnd, CB_INSERTSTRING, (WPARAM)0, (LPARAM)str_nc);          insertnc(wnd, 0);
         for (i=0; i<num; i++) {          for (i=0; i<num; i++) {
                 if (midiInGetDevCaps(i, &mic, sizeof(mic)) == MMSYSERR_NOERROR) {                  if (midiInGetDevCaps(i, &mic, sizeof(mic)) == MMSYSERR_NOERROR) {
                         SendMessage(wnd, CB_INSERTSTRING,                          SendMessage(wnd, CB_INSERTSTRING,

Removed from v.1.11  
changed lines
  Added in v.1.15


RetroPC.NET-CVS <cvs@retropc.net>