Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
7.3 KiB

  1. /*
  2. * PROPBOX.C
  3. *
  4. * Copyright (C) 1990 Microsoft Corporation.
  5. *
  6. * Dialog box for creating a new map.
  7. */
  8. /* Revision history:
  9. March 92 Ported to 16/32 common code by Laurie Griffiths (LaurieGr)
  10. */
  11. #include "preclude.h"
  12. #include <windows.h>
  13. #include <mmsystem.h>
  14. #if defined(WIN32)
  15. #include <port1632.h>
  16. #endif
  17. #include <string.h>
  18. #include "hack.h"
  19. #include "midimap.h"
  20. #include "cphelp.h"
  21. #include "midi.h"
  22. #include "extern.h"
  23. /* How about a f***ing comment ??? */
  24. static UINT PackString(LPSTR szStr)
  25. {
  26. UINT i;
  27. LPSTR lpstrBegin,lpstrPtr;
  28. // remove leading whitespace
  29. for (lpstrBegin=lpstrPtr=szStr; ISSPACE(*lpstrPtr) ; lpstrPtr++);
  30. // move backwards from the end
  31. for(i = lstrlen(szStr)-1; i > 0 && ISSPACE(szStr[i]);i--);
  32. if (lpstrPtr > szStr+i )
  33. return 0;
  34. szStr[i+1] = '\0';
  35. // while(*szStr++ = *lpstrPtr++); // Was coded like this - I wonder why?
  36. strcpy(szStr, lpstrPtr);
  37. return lstrlen(lpstrBegin);
  38. }
  39. BOOL FAR PASCAL _loadds PropBox(
  40. HWND hdlg,
  41. UINT uMessage,
  42. WPARAM wParam,
  43. LPARAM lParam)
  44. {
  45. static BOOL fEnabled;
  46. DWORD dwExists;
  47. int idName = 0;
  48. int idHelp = 0;
  49. char szName [24],
  50. szCaption[80],
  51. szTextBuf [256],
  52. szRsrc [256],
  53. szBuf [MMAP_MAXNAME];
  54. switch (uMessage)
  55. {
  56. case WM_INITDIALOG:
  57. switch (iMap)
  58. {
  59. case MMAP_SETUP:
  60. LoadString(hLibInst, IDS_NEW_SETUP, szCaption, sizeof(szCaption));
  61. break;
  62. case MMAP_PATCH:
  63. LoadString(hLibInst, IDS_NEW_PATCH, szCaption, sizeof(szCaption));
  64. break;
  65. case MMAP_KEY:
  66. LoadString(hLibInst, IDS_NEW_KEY, szCaption, sizeof(szCaption));
  67. break;
  68. }
  69. SetWindowText(hdlg, szCaption);
  70. #ifdef FSAVEAS
  71. if (fSaveAs) {
  72. SetDlgItemText(hdlg, ID_PROPNAME, szCurrent);
  73. SetDlgItemText(hdlg, ID_PROPDESC, szCurDesc);
  74. fEnabled = TRUE;
  75. } else
  76. #endif
  77. EnableWindow(GetDlgItem(hdlg, IDOK), FALSE);
  78. SendDlgItemMessage(hdlg, ID_PROPNAME, EM_LIMITTEXT,
  79. (WPARAM)(MMAP_MAXNAME - 1), (LPARAM)0);
  80. SendDlgItemMessage(hdlg, ID_PROPDESC, EM_LIMITTEXT,
  81. (WPARAM)(MMAP_MAXDESC - 1), (LPARAM)0);
  82. fEnabled = FALSE;
  83. break;
  84. case WM_COMMAND:
  85. switch (LOWORD(wParam)) {
  86. case IDH_DLG_MIDI_NEW:
  87. goto DoHelp;
  88. case IDOK:
  89. GetDlgItemText(hdlg, ID_PROPNAME, szBuf,
  90. MMAP_MAXNAME);
  91. if (PackString(szBuf) == 0)
  92. return FALSE;
  93. //fSaveAs is never set
  94. //!! if (/* !fSaveAs || */ lstrcmpi(szBuf, szCurrent)) {
  95. dwExists = mapExists(iMap, szBuf);
  96. if (LOWORD(dwExists) != MMAPERR_SUCCESS) {
  97. VShowError(hdlg, LOWORD(dwExists));
  98. EndDialog(hdlg, FALSE);
  99. return TRUE;
  100. }
  101. if (HIWORD(dwExists)) {
  102. switch (iMap)
  103. {
  104. case MMAP_SETUP:
  105. idName = IDS_SETUP;
  106. break;
  107. case MMAP_PATCH:
  108. idName = IDS_PATCH;
  109. break;
  110. case MMAP_KEY:
  111. idName = IDS_KEY;
  112. break;
  113. }
  114. LoadString(hLibInst, idName, szName,
  115. sizeof(szName));
  116. // AnsiUpperBuff(szName, 1);
  117. LoadString(hLibInst, IDS_DUPLICATE,
  118. szRsrc, sizeof(szRsrc));
  119. wsprintf(szTextBuf, szRsrc, (LPSTR)
  120. szName);
  121. if (IDNO == MessageBox(hdlg,
  122. szTextBuf, szBuf,
  123. MB_YESNO |
  124. MB_ICONEXCLAMATION))
  125. break;
  126. fNew = FALSE;
  127. }
  128. lstrcpy(szCurrent, szBuf);
  129. //!! }
  130. GetDlgItemText(hdlg, ID_PROPDESC, szCurDesc,
  131. MMAP_MAXDESC);
  132. EndDialog(hdlg, TRUE);
  133. break;
  134. case IDCANCEL:
  135. EndDialog(hdlg, FALSE);
  136. break;
  137. case ID_PROPNAME:
  138. if (!GetDlgItemText(hdlg, ID_PROPNAME, szBuf,
  139. MMAP_MAXNAME))
  140. {
  141. if (fEnabled)
  142. {
  143. EnableWindow(GetDlgItem(hdlg, IDOK),
  144. FALSE);
  145. fEnabled = FALSE;
  146. }
  147. } else
  148. if (!fEnabled)
  149. {
  150. EnableWindow(GetDlgItem(hdlg, IDOK), TRUE);
  151. fEnabled = TRUE;
  152. }
  153. break;
  154. default:
  155. return FALSE;
  156. }
  157. break;
  158. default:
  159. if (uMessage == uHelpMessage)
  160. {
  161. DoHelp:
  162. switch (iMap)
  163. {
  164. case MMAP_SETUP:
  165. idHelp = IDH_DLG_MIDI_SETUPNEW;
  166. break;
  167. case MMAP_PATCH:
  168. idHelp = IDH_DLG_MIDI_PATCHNEW;
  169. break;
  170. case MMAP_KEY:
  171. idHelp = IDH_DLG_MIDI_KEYNEW;
  172. break;
  173. }
  174. WinHelp(hWnd, szMidiHlp, HELP_CONTEXT, idHelp);
  175. return TRUE;
  176. }
  177. else
  178. return FALSE;
  179. break;
  180. }
  181. return TRUE;
  182. } /* PropBox */