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.

263 lines
7.2 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. /***************************************************************************/
  4. /****************** Basic Class Dialog Handlers ****************************/
  5. /***************************************************************************/
  6. #define cchpMax 511
  7. /*
  8. ** Purpose:
  9. ** Multi Edit Dialog procedure for templates with multiple edit controls.
  10. ** Control IDs:
  11. ** The Edit controls must have IDs of IDC_EDIT1 to IDC_EDIT10.
  12. ** Pushbuttons recognized are IDC_O, IDC_C, IDC_M, IDC_H, IDC_X, and IDC_B.
  13. ** Initialization:
  14. ** The symbol $(EditTextIn) is used to set the initial text in the Edit
  15. ** controls. The symbol $(EditTextLim) is used to set the limit of the
  16. ** text in the edit fields.
  17. ** Termination:
  18. ** The strings in the Edit controls are stored in the symbol $(EditTextOut)
  19. ** The id of the Pushbutton (eg IDC_C) which caused termination is
  20. ** converted to a string and stored in the symbol $(ButtonPressed).
  21. **
  22. *****************************************************************************/
  23. INT_PTR APIENTRY
  24. FGstMultiEditDlgProc(
  25. HWND hdlg,
  26. UINT wMsg,
  27. WPARAM wParam,
  28. LPARAM lParam
  29. )
  30. {
  31. CHP rgchNum[10];
  32. CHP rgchText[cchpMax + 1];
  33. RGSZ rgsz, rgszEditTextIn, rgszEditTextLim;
  34. PSZ pszEditTextIn, pszEditTextLim;
  35. SZ sz, szEditTextIn, szEditTextLim;
  36. INT i, nCount, idc;
  37. INT DefEditCtl;
  38. BOOL NeedToSetFocus = FALSE;
  39. Unused(lParam);
  40. switch (wMsg) {
  41. case STF_REINITDIALOG:
  42. if ((sz = SzFindSymbolValueInSymTab("ReInit")) == (SZ)NULL ||
  43. (CrcStringCompareI(sz, "YES") != crcEqual)) {
  44. return(fTrue);
  45. }
  46. //
  47. // See whether we are supposed to set the focus to a certain
  48. // edit control.
  49. //
  50. if((sz = SzFindSymbolValueInSymTab("DefEditCtl")) != NULL) {
  51. NeedToSetFocus = TRUE;
  52. DefEditCtl = atoi(sz);
  53. }
  54. case WM_INITDIALOG:
  55. AssertDataSeg();
  56. FRemoveSymbolFromSymTab("DefEditCtl");
  57. if( wMsg == WM_INITDIALOG ) {
  58. FCenterDialogOnDesktop(hdlg);
  59. }
  60. //
  61. // find the initalisers: EditTextIn, EditTextLim
  62. //
  63. szEditTextIn = SzFindSymbolValueInSymTab("EditTextIn");
  64. szEditTextLim = SzFindSymbolValueInSymTab("EditTextLim");
  65. if ( szEditTextIn == (SZ)NULL ||
  66. szEditTextLim == (SZ)NULL ) {
  67. Assert(fFalse);
  68. return(fTrue);
  69. }
  70. //
  71. // Convert initializers to rgsz structures
  72. //
  73. while ((pszEditTextIn = rgszEditTextIn = RgszFromSzListValue(szEditTextIn)) == (RGSZ)NULL) {
  74. if (!FHandleOOM(hdlg)) {
  75. DestroyWindow(GetParent(hdlg));
  76. return(fTrue);
  77. }
  78. }
  79. while ((pszEditTextLim = rgszEditTextLim = RgszFromSzListValue(szEditTextLim)) == (RGSZ)NULL) {
  80. if (!FHandleOOM(hdlg)) {
  81. DestroyWindow(GetParent(hdlg));
  82. return(fTrue);
  83. }
  84. }
  85. //
  86. // Circulate through the initialisers: EditTextIn, EditTextLim
  87. // in tandem, initialising the edit boxes that
  88. // are there in this dialog
  89. //
  90. idc = IDC_EDIT1;
  91. while ( (szEditTextIn = *pszEditTextIn++) != (SZ)NULL &&
  92. (szEditTextLim = *pszEditTextLim++) != (SZ)NULL ) {
  93. // First set the limit of the text in the edit field
  94. SendDlgItemMessage(
  95. hdlg,
  96. idc,
  97. EM_LIMITTEXT,
  98. atoi(szEditTextLim),
  99. 0L
  100. );
  101. // And then set the text in the edit field
  102. SetDlgItemText(hdlg, idc++, (LPSTR)szEditTextIn);
  103. }
  104. EvalAssert(FFreeRgsz(rgszEditTextIn));
  105. EvalAssert(FFreeRgsz(rgszEditTextLim));
  106. if(NeedToSetFocus) {
  107. SetFocus(GetDlgItem(hdlg,IDC_EDIT1+DefEditCtl));
  108. return(FALSE);
  109. }
  110. return(fTrue);
  111. case WM_CLOSE:
  112. PostMessage(
  113. hdlg,
  114. WM_COMMAND,
  115. MAKELONG(IDC_X, BN_CLICKED),
  116. 0L
  117. );
  118. return(fTrue);
  119. case WM_COMMAND:
  120. switch(LOWORD(wParam)) {
  121. case IDCANCEL:
  122. if (LOWORD(wParam) == IDCANCEL) {
  123. if (!GetDlgItem(hdlg, IDC_B) || HIWORD(GetKeyState(VK_CONTROL)) || HIWORD(GetKeyState(VK_SHIFT)) || HIWORD(GetKeyState(VK_MENU)))
  124. {
  125. break;
  126. }
  127. wParam = IDC_B;
  128. }
  129. case IDC_C:
  130. case IDC_B:
  131. case IDC_O:
  132. case IDC_M:
  133. case IDC_X:
  134. case IDC_BTN0:
  135. case IDC_BTN1: case IDC_BTN2: case IDC_BTN3:
  136. case IDC_BTN4: case IDC_BTN5: case IDC_BTN6:
  137. case IDC_BTN7: case IDC_BTN8: case IDC_BTN9:
  138. // Add the button pressed to the symbol table
  139. _itoa((INT)wParam, rgchNum, 10);
  140. while (!FAddSymbolValueToSymTab("ButtonPressed", rgchNum)) {
  141. if (!FHandleOOM(hdlg)) {
  142. DestroyWindow(GetParent(hdlg));
  143. return(fTrue);
  144. }
  145. }
  146. // Add EditTextOut list variable to the symbol table
  147. for (i = 0; i < 10; i++) {
  148. if (GetDlgItem(hdlg, IDC_EDIT1 + i) == (HWND)NULL) {
  149. break;
  150. }
  151. }
  152. // i has the number of edit fields, allocate an rgsz structure
  153. // with i+1 entries (last one NULL TERMINATOR)
  154. nCount = i;
  155. while ((rgsz = (RGSZ)SAlloc((CB)((nCount + 1) * sizeof(SZ))))
  156. == (RGSZ)NULL) {
  157. if (!FHandleOOM(hdlg)) {
  158. DestroyWindow(GetParent(hdlg));
  159. return(fTrue);
  160. }
  161. }
  162. rgsz[nCount] = (SZ)NULL;
  163. // Circulate through the edit fields in the dialog box, determining
  164. // the text in each and storing it in the
  165. for (i = 0; i < nCount; i++) {
  166. SendDlgItemMessage(
  167. hdlg,
  168. IDC_EDIT1 + i,
  169. (WORD)WM_GETTEXT,
  170. cchpMax + 1,
  171. (LPARAM)rgchText
  172. );
  173. rgsz[i] = SzDupl(rgchText);
  174. }
  175. // Form a list out of the rgsz structure
  176. while ((sz = SzListValueFromRgsz(rgsz)) == (SZ)NULL) {
  177. if (!FHandleOOM(hdlg)) {
  178. DestroyWindow(GetParent(hdlg));
  179. return(fTrue);
  180. }
  181. }
  182. // Set the EditTextOut symbol to this list
  183. while (!FAddSymbolValueToSymTab("EditTextOut", sz)) {
  184. if (!FHandleOOM(hdlg)) {
  185. DestroyWindow(GetParent(hdlg));
  186. return(fTrue);
  187. }
  188. }
  189. EvalAssert(FFreeRgsz(rgsz));
  190. SFree(sz);
  191. PostMessage(GetParent(hdlg), (WORD)STF_UI_EVENT, 0, 0L);
  192. break;
  193. }
  194. break;
  195. case STF_DESTROY_DLG:
  196. PostMessage(GetParent(hdlg), (WORD)STF_EDIT_DLG_DESTROYED, 0, 0L);
  197. DestroyWindow(hdlg);
  198. return(fTrue);
  199. }
  200. return(fFalse);
  201. }