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.

240 lines
6.3 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. /***************************************************************************/
  4. /****************** Basic Class Dialog Handlers ****************************/
  5. /***************************************************************************/
  6. /*
  7. ** Purpose:
  8. ** Multiple Choice Listbox Dialog procedure for templates with exactly one
  9. ** listbox control.
  10. ** Control IDs:
  11. ** The Listbox control must have the id IDC_LIST1. Pushbuttons
  12. ** recognized are IDC_O, IDC_C, IDC_M, IDC_H, IDC_X, and IDC_B.
  13. ** Initialization:
  14. ** The symbol $(ListItemsIn) is a list of strings to insert into the
  15. ** listbox. The symbol $(ListItemOut) is a list of strings which for
  16. ** each that matches a string in $(ListItemsIn) it sets that item as
  17. ** selected.
  18. ** Termination:
  19. ** The selected items (if any) are stored as a list in the symbol
  20. ** $(ListItemsOut). The id of the Pushbutton (eg IDC_C) which caused
  21. ** termination is converted to a string and stored in the symbol
  22. ** $(ButtonPressed).
  23. **
  24. *****************************************************************************/
  25. INT_PTR APIENTRY FGstMultiDlgProc(HWND hdlg,
  26. UINT wMsg,
  27. WPARAM wParam,
  28. LPARAM lParam)
  29. {
  30. CHP rgchNum[10];
  31. INT i, nCount;
  32. RGSZ rgsz, rgszSel;
  33. PSZ psz, pszSel;
  34. SZ szList;
  35. CHP szItemCur[256];
  36. UINT iItemTop;
  37. Unused(lParam);
  38. switch (wMsg) {
  39. case WM_INITDIALOG:
  40. AssertDataSeg();
  41. if( wMsg == WM_INITDIALOG ) {
  42. FCenterDialogOnDesktop(hdlg);
  43. }
  44. if ((szList = SzFindSymbolValueInSymTab("ListItemsIn")) == (SZ)NULL)
  45. {
  46. Assert(fFalse);
  47. return(fTrue);
  48. }
  49. while ((psz = rgsz = RgszFromSzListValue(szList)) == (RGSZ)NULL)
  50. if (!FHandleOOM(hdlg))
  51. {
  52. DestroyWindow(GetParent(hdlg));
  53. return(fTrue);
  54. }
  55. nCount = 0;
  56. while (*psz)
  57. {
  58. SendDlgItemMessage(hdlg, IDC_LIST1, LB_ADDSTRING, 0,
  59. (LPARAM)*psz++);
  60. nCount++;
  61. }
  62. Assert(nCount == (INT)SendDlgItemMessage(hdlg, IDC_LIST1, LB_GETCOUNT,
  63. 0, 0L));
  64. //
  65. // Find out the items in the multi list box to select
  66. //
  67. if ((szList = SzFindSymbolValueInSymTab("ListItemsOut")) == (SZ)NULL)
  68. {
  69. EvalAssert(FFreeRgsz(rgsz));
  70. return(fTrue);
  71. }
  72. while ((pszSel = rgszSel = RgszFromSzListValue(szList)) == (RGSZ)NULL)
  73. if (!FHandleOOM(hdlg))
  74. {
  75. EvalAssert(FFreeRgsz(rgsz));
  76. DestroyWindow(GetParent(hdlg));
  77. return(fTrue);
  78. }
  79. iItemTop = 0;
  80. for (i = 0; i < nCount; i++) {
  81. CHP szItemCur[256];
  82. if ( (SendDlgItemMessage(
  83. hdlg,
  84. IDC_LIST1,
  85. LB_GETTEXT,
  86. (WPARAM)i,
  87. (LPARAM)szItemCur
  88. ) != LB_ERR)
  89. ) {
  90. psz = pszSel;
  91. while ( *psz ) {
  92. if (CrcStringCompareI(*psz++, szItemCur) == crcEqual) {
  93. EvalAssert(SendDlgItemMessage(hdlg, IDC_LIST1, LB_SETSEL, 1,
  94. MAKELONG(i, 0)) != LB_ERR);
  95. if (iItemTop == 0 || i < (INT)iItemTop) {
  96. iItemTop = i;
  97. }
  98. break;
  99. }
  100. }
  101. }
  102. }
  103. EvalAssert(FFreeRgsz(rgsz));
  104. EvalAssert(FFreeRgsz(rgszSel));
  105. /* REVIEW KLUDGE no way to find out how many lines in the listbox? */
  106. if (iItemTop < 4)
  107. iItemTop = 0;
  108. SendDlgItemMessage(hdlg, IDC_LIST1, LB_SETTOPINDEX, iItemTop, 0L);
  109. return(fTrue);
  110. case STF_REINITDIALOG:
  111. return(fTrue);
  112. case WM_CLOSE:
  113. PostMessage(
  114. hdlg,
  115. WM_COMMAND,
  116. MAKELONG(IDC_X, BN_CLICKED),
  117. 0L
  118. );
  119. return(fTrue);
  120. case WM_COMMAND:
  121. switch(LOWORD(wParam))
  122. {
  123. case IDC_S:
  124. case IDC_L:
  125. SendDlgItemMessage(hdlg,
  126. IDC_LIST1,
  127. LB_SETSEL,
  128. (LOWORD(wParam) == IDC_S),
  129. -1L);
  130. break;
  131. case IDCANCEL:
  132. if (LOWORD(wParam) == IDCANCEL) {
  133. if (!GetDlgItem(hdlg, IDC_B) || HIWORD(GetKeyState(VK_CONTROL)) || HIWORD(GetKeyState(VK_SHIFT)) || HIWORD(GetKeyState(VK_MENU)))
  134. {
  135. break;
  136. }
  137. wParam = IDC_B;
  138. }
  139. case IDC_O:
  140. case IDC_C:
  141. case IDC_M:
  142. case IDC_X:
  143. case IDC_B:
  144. case IDC_BTN0:
  145. case IDC_BTN1: case IDC_BTN2: case IDC_BTN3:
  146. case IDC_BTN4: case IDC_BTN5: case IDC_BTN6:
  147. case IDC_BTN7: case IDC_BTN8: case IDC_BTN9:
  148. _itoa((INT)wParam, rgchNum, 10);
  149. while (!FAddSymbolValueToSymTab("ButtonPressed", rgchNum))
  150. if (!FHandleOOM(hdlg))
  151. {
  152. DestroyWindow(GetParent(hdlg));
  153. return(fTrue);
  154. }
  155. nCount = (INT)SendDlgItemMessage(hdlg, IDC_LIST1, LB_GETSELCOUNT, 0,
  156. 0L);
  157. while ((psz = rgsz = (RGSZ)SAlloc((CB)((nCount + 1) * sizeof(SZ))))
  158. == (RGSZ)NULL)
  159. if (!FHandleOOM(hdlg))
  160. {
  161. DestroyWindow(GetParent(hdlg));
  162. return(fTrue);
  163. }
  164. rgsz[nCount] = (SZ)NULL;
  165. /* REVIEW would be faster to use LB_GETSELITEMS */
  166. nCount = (INT)SendDlgItemMessage(hdlg, IDC_LIST1, LB_GETCOUNT, 0,
  167. 0L);
  168. for (i = 0; i < nCount; i++)
  169. {
  170. if (SendDlgItemMessage(hdlg, IDC_LIST1, LB_GETSEL, (WORD)i, 0L))
  171. {
  172. EvalAssert(SendDlgItemMessage(hdlg, IDC_LIST1, LB_GETTEXT,
  173. (WPARAM)i, (LPARAM)szItemCur) != LB_ERR);
  174. while ((*psz = SzDupl(szItemCur)) == (SZ)NULL)
  175. if (!FHandleOOM(hdlg))
  176. {
  177. DestroyWindow(GetParent(hdlg));
  178. return(fTrue);
  179. }
  180. psz++;
  181. }
  182. }
  183. while ((szList = SzListValueFromRgsz(rgsz)) == (SZ)NULL)
  184. if (!FHandleOOM(hdlg))
  185. {
  186. DestroyWindow(GetParent(hdlg));
  187. return(fTrue);
  188. }
  189. while (!FAddSymbolValueToSymTab("ListItemsOut", szList))
  190. if (!FHandleOOM(hdlg))
  191. {
  192. DestroyWindow(GetParent(hdlg));
  193. return(fTrue);
  194. }
  195. SFree(szList);
  196. FFreeRgsz(rgsz);
  197. PostMessage(GetParent(hdlg), (WORD)STF_UI_EVENT, 0, 0L);
  198. break;
  199. }
  200. break;
  201. case STF_DESTROY_DLG:
  202. PostMessage(GetParent(hdlg), (WORD)STF_MULTI_DLG_DESTROYED, 0, 0L);
  203. DestroyWindow(hdlg);
  204. return(fTrue);
  205. }
  206. return(fFalse);
  207. }