Diff for /np2/win9x/dialog/dialogs.cpp between versions 1.2 and 1.14

version 1.2, 2003/10/29 21:35:58 version 1.14, 2007/12/16 14:58:25
Line 1 Line 1
 #include        "compiler.h"  #include        "compiler.h"
   #include        "resource.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        "dialogs.h"  #include        "dialogs.h"
   #include        "np2.h"
   #if defined(MT32SOUND_DLL)
   #include        "mt32snd.h"
   #endif
   
   
   const TCHAR str_nc[] = _T("N/C");
   
   
 static const char str_nc[] = "N/C";  // ---- enable
   
 // static       char    pathname[MAX_PATH];  void dlgs_enablebyautocheck(HWND hWnd, UINT uID, UINT uCheckID)
 // static       char    filename[MAX_PATH];  {
           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));
   
 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 select  // ---- file select
   
 BOOL dlgs_selectfile(HWND hWnd, const FILESEL *item,  static BOOL openFileParam(LPOPENFILENAME lpOFN, PCFSPARAM pcParam,
                                                                                         char *path, UINT size, int *ro) {                                                          OEMCHAR *pszPath, UINT uSize,
                                                           BOOL (WINAPI * fnAPI)(LPOPENFILENAME lpofn))
   {
           HINSTANCE       hInstance;
           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;
           }
   
           hInstance = g_hInstance;
   
           if (!HIWORD(pcParam->lpszTitle))
           {
                   lpszTitle = lockstringresource(hInstance, pcParam->lpszTitle);
                   lpOFN->lpstrTitle = lpszTitle;
           }
           else
           {
                   lpszTitle = NULL;
                   lpOFN->lpstrTitle = pcParam->lpszTitle;
           }
   
           if (!HIWORD(pcParam->lpszFilter))
           {
                   lpszFilter = lockstringresource(hInstance, pcParam->lpszFilter);
                   lpOFN->lpstrFilter = lpszFilter;
           }
           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++;
                   }
           }
   
         OPENFILENAME    ofn;  #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 ((item == NULL) || (path == NULL) || (size == 0)) {  #if defined(OSLANG_UTF8)
                 return(FALSE);          if (bResult)
           {
                   tchartooem(pszPath, uSize, szPath, -1);
         }          }
         ZeroMemory(&ofn, sizeof(OPENFILENAME));  #endif  // defined(OSLANG_UTF8)
         ofn.lStructSize = sizeof(OPENFILENAME);  
         ofn.hwndOwner = hWnd;          if (lpszTitle)
         ofn.lpstrFilter = item->filter;          {
         ofn.nFilterIndex = item->defindex;                  unlockstringresource(lpszTitle);
         ofn.lpstrFile = path;  
         ofn.nMaxFile = size;  
         ofn.Flags = OFN_FILEMUSTEXIST;  
         ofn.lpstrDefExt = item->ext;  
         ofn.lpstrTitle = item->title;  
         if (!GetOpenFileName(&ofn)) {  
                 return(FALSE);  
         }          }
         if (ro) {          if (lpszFilter)
                 *ro = ofn.Flags & OFN_READONLY;          {
                   unlockstringresource(lpszFilter);
           }
           if (lpszDefExt)
           {
                   unlockstringresource(lpszDefExt);
         }          }
         return(TRUE);  
 }  
   
 BOOL dlgs_selectwritefile(HWND hWnd, const FILESEL *item,          return bResult;
                                                                                         char *path, UINT size) {  }
   
   BOOL dlgs_openfile(HWND hWnd, PCFSPARAM pcParam,
                                                                           OEMCHAR *pszPath, UINT uSize, int *pnRO)
   {
         OPENFILENAME    ofn;          OPENFILENAME    ofn;
           BOOL                    bResult;
   
         if ((item == NULL) || (path == NULL) || (size == 0)) {          ZeroMemory(&ofn, sizeof(ofn));
                 return(FALSE);          ofn.lStructSize = sizeof(ofn);
         }  
         ZeroMemory(&ofn, sizeof(OPENFILENAME));  
         ofn.lStructSize = sizeof(OPENFILENAME);  
         ofn.hwndOwner = hWnd;          ofn.hwndOwner = hWnd;
         ofn.lpstrFilter = item->filter;          ofn.Flags = OFN_FILEMUSTEXIST;
         ofn.nFilterIndex = item->defindex;  
         ofn.lpstrFile = path;          if (pnRO == NULL)
         ofn.nMaxFile = size;          {
         ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;                  ofn.Flags |= OFN_HIDEREADONLY;
         ofn.lpstrDefExt = item->ext;  
         ofn.lpstrTitle = item->title;  
         if (!GetSaveFileName(&ofn)) {  
                 return(FALSE);  
         }          }
         return(TRUE);  
           bResult = openFileParam(&ofn, pcParam, pszPath, uSize, GetOpenFileName);
   
           if ((bResult) && (pnRO != NULL))
           {
                   *pnRO = ofn.Flags & OFN_READONLY;
           }
   
           return bResult;
 }  }
   
 BOOL dlgs_selectwritenum(HWND hWnd, const FILESEL *item,  BOOL dlgs_createfile(HWND hWnd, PCFSPARAM pcParam,
                                                                                         char *path, UINT size) {                                                                                                  OEMCHAR *pszPath, UINT uSize)
   {
           OPENFILENAME    ofn;
   
         char    *file;          ZeroMemory(&ofn, sizeof(ofn));
         char    *p;          ofn.lStructSize = sizeof(ofn);
         char    *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)
         }  {
         file = (char *)_MALLOC(size + 16, path);          OEMCHAR *pszNum[4];
         if (file == NULL) {          OEMCHAR *pszFile;
                 return(FALSE);          UINT uCount;
         }          UINT uPos;
         p = file_getname(path);  
         milstr_ncpy(file, path, size);          if (!pszPath)
         file_cutname(file);          {
         q = file + strlen(file);                  return FALSE;
           }
         for (i=0; i<10000; i++) {  
                 SPRINTF(q, p, i);          ZeroMemory(pszNum, sizeof(pszNum));
                 if (file_attr(file) == (short)-1) {          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;                          break;
                 }                  }
         }          }
         r = dlgs_selectwritefile(hWnd, item, file, size);          return dlgs_createfile(hWnd, pcParam, pszPath, uSize);
         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 FSPARAM fpMIMPI =
 static const char mimpi_ext[] = "def";  {
 static const char mimpi_filter[] = "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),
 void dlgs_browsemimpidef(HWND hWnd, WORD res) {          1
   };
         HWND    subwnd;  
         char    path[MAX_PATH];  void dlgs_browsemimpidef(HWND hWnd, UINT16 res) {
 const char      *p;  
           HWND            subwnd;
           OEMCHAR         path[MAX_PATH];
   const OEMCHAR   *p;
   
         subwnd = GetDlgItem(hWnd, res);          subwnd = GetDlgItem(hWnd, res);
         GetWindowText(subwnd, path, sizeof(path));          GetWindowText(subwnd, path, NELEMENTS(path));
         if (dlgs_selectfile(hWnd, &mimpi, path, sizeof(path), NULL)) {          if (dlgs_openfile(hWnd, &fpMIMPI, path, NELEMENTS(path), NULL)) {
                 p = path;                  p = path;
         }          }
         else {          else {
Line 134  const char *p; Line 265  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 145  void dlgs_setliststr(HWND hWnd, WORD res Line 276  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_setcbitem(HWND hWnd, UINT uID, PCCBPARAM pcItem, UINT uItems)
   {
           HWND    hItem;
           UINT    i;
           LPCTSTR lpcszStr;
           TCHAR   szString[128];
           int             nIndex;
   
           hItem = GetDlgItem(hWnd, uID);
           for (i=0; i<uItems; i++)
           {
                   lpcszStr = pcItem[i].lpcszString;
                   if (!HIWORD(lpcszStr))
                   {
                           if (!loadstringresource(g_hInstance, LOWORD(lpcszStr),
                                                                                           szString, NELEMENTS(szString)))
                           {
                                   continue;
                           }
                           lpcszStr = szString;
                   }
                   nIndex = SendMessage(hItem, CB_ADDSTRING, 0, (LPARAM)lpcszStr);
                   if (nIndex >= 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<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;
           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) == nItemData)
                   {
                           SendMessage(hItem, CB_SETCURSEL, (WPARAM)i, 0);
                           break;
                   }
           }
   }
   
   int dlgs_getcbcur(HWND hWnd, UINT uID, int nDefault)
   {
           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 nDefault;
   }
   
   
 // ---- 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 186  void dlgs_setlistmidiout(HWND hWnd, WORD Line 398  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 199  void dlgs_setlistmidiout(HWND hWnd, WORD Line 421  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 224  void dlgs_setlistmidiin(HWND hWnd, WORD  Line 446  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;  // ---- draw
         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  
   
 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;
 }  }
   

Removed from v.1.2  
changed lines
  Added in v.1.14


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