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.

245 lines
6.0 KiB

  1. /*****************************************************************************
  2. *
  3. * diqvbool.c
  4. *
  5. * VList plug-in that does BOOLs.
  6. *
  7. *****************************************************************************/
  8. #include "diquick.h"
  9. #pragma BEGIN_CONST_DATA
  10. /*****************************************************************************
  11. *
  12. * VLISTBOOL
  13. *
  14. * BOOL-specific goo.
  15. *
  16. * When we PreDisplay a control, we stash the VLISTBOOL into the
  17. * DWL_USER. We can't use the GWLP_USERDATA, because the vlist
  18. * manager uses that.
  19. *
  20. *****************************************************************************/
  21. typedef struct VLISTBOOL {
  22. VLISTITEM item;
  23. DIPROPDWORD dipdw;
  24. /*
  25. * If non-NULL, then this is a read/write control.
  26. */
  27. PROPUPDATEPROC Update;
  28. PV pvRef1;
  29. PV pvRef2;
  30. } VLISTBOOL, *PVLISTBOOL;
  31. /*****************************************************************************
  32. *
  33. * VBool_PreDisplay
  34. *
  35. * Check the Yes or No, accordingly.
  36. *
  37. * Note that there is no such thing as a read-only radio button.
  38. * We have to disable it.
  39. *
  40. *****************************************************************************/
  41. void INTERNAL
  42. VBool_PreDisplay(HWND hdlg, PV pv)
  43. {
  44. PVLISTBOOL pvbool = pv;
  45. /*
  46. * Need to do this early so our subclass procedure knows who
  47. * we're talking about.
  48. */
  49. SetDialogPtr(hdlg, pvbool);
  50. CheckRadioButton(hdlg, IDC_VBOOL_YES, IDC_VBOOL_NO,
  51. pvbool->dipdw.dwData ? IDC_VBOOL_YES
  52. : IDC_VBOOL_NO);
  53. ShowWindow(GetDlgItem(hdlg, IDC_VBOOL_APPLY),
  54. pvbool->Update ? SW_SHOW : SW_HIDE);
  55. }
  56. /*****************************************************************************
  57. *
  58. * VBool_Destroy
  59. *
  60. * Nothing to clean up.
  61. *
  62. *****************************************************************************/
  63. void INTERNAL
  64. VBool_Destroy(PV pv)
  65. {
  66. PVLISTBOOL pvbool = pv;
  67. }
  68. /*****************************************************************************
  69. *
  70. * VBool_Button_SubclassProc
  71. *
  72. * Procedure we install that subclasses our radio buttons.
  73. *
  74. * If we are in R/O mode, then we return DLGC_STATIC so the
  75. * dialog manager won't include us in the TAB order.
  76. *
  77. *****************************************************************************/
  78. LRESULT CALLBACK
  79. VBool_Button_SubclassProc(HWND hwnd, UINT wm, WPARAM wp, LPARAM lp)
  80. {
  81. switch (wm) {
  82. case WM_GETDLGCODE:
  83. {
  84. PVLISTBOOL pvbool = GetDialogPtr(GetParent(hwnd));
  85. if (pvbool && !pvbool->Update) {
  86. return DLGC_STATIC;
  87. }
  88. }
  89. break;
  90. }
  91. return CallWindowProc((WNDPROC)GetWindowLongPtr(hwnd, GWLP_USERDATA),
  92. hwnd, wm, wp, lp);
  93. }
  94. /*****************************************************************************
  95. *
  96. * VBool_OnInitDialog
  97. *
  98. * Subclas our buttons so they act "dumb".
  99. *
  100. *****************************************************************************/
  101. BOOL INTERNAL
  102. VBool_OnInitDialog(HWND hdlg)
  103. {
  104. WNDPROC wp;
  105. HWND hwnd;
  106. hwnd = GetDlgItem(hdlg, IDC_VBOOL_YES);
  107. wp = SubclassWindow(hwnd, VBool_Button_SubclassProc);
  108. SetWindowLongPtr(hwnd, GWLP_USERDATA, (INT_PTR)wp);
  109. hwnd = GetDlgItem(hdlg, IDC_VBOOL_NO);
  110. wp = SubclassWindow(hwnd, VBool_Button_SubclassProc);
  111. SetWindowLongPtr(hwnd, GWLP_USERDATA, (INT_PTR)wp);
  112. return TRUE;
  113. }
  114. /*****************************************************************************
  115. *
  116. * VBool_OnApply
  117. *
  118. * Let the owner know.
  119. *
  120. *****************************************************************************/
  121. void INTERNAL
  122. VBool_OnApply(HWND hdlg)
  123. {
  124. HRESULT hres;
  125. PVLISTBOOL pvbool = GetDialogPtr(hdlg);
  126. pvbool->dipdw.dwData = IsDlgButtonChecked(hdlg, IDC_VBOOL_YES);
  127. hres = pvbool->Update(&pvbool->dipdw.diph, pvbool->pvRef1, pvbool->pvRef2);
  128. if (FAILED(hres)) {
  129. MessageBoxV(hdlg, IDS_ERR_HRESULT, hres);
  130. }
  131. }
  132. /*****************************************************************************
  133. *
  134. * VBool_OnCommand
  135. *
  136. * If they clicked one of the options, change it back if we are R/O.
  137. *
  138. * If they pressed Apply, then apply it.
  139. *
  140. *****************************************************************************/
  141. BOOL INLINE
  142. VBool_OnCommand(HWND hdlg, int id, UINT codeNotify)
  143. {
  144. switch (id) {
  145. case IDC_VBOOL_APPLY:
  146. VBool_OnApply(hdlg);
  147. return TRUE;
  148. }
  149. return FALSE;
  150. }
  151. /*****************************************************************************
  152. *
  153. * VBool_DlgProc
  154. *
  155. * Nothing really happens here. The real work is done externally.
  156. *
  157. *****************************************************************************/
  158. INT_PTR CALLBACK
  159. VBool_DlgProc(HWND hdlg, UINT wm, WPARAM wp, LPARAM lp)
  160. {
  161. switch (wm) {
  162. case WM_INITDIALOG: return VBool_OnInitDialog(hdlg);
  163. case WM_COMMAND:
  164. return VBool_OnCommand(hdlg,
  165. (int)GET_WM_COMMAND_ID(wp, lp),
  166. (UINT)GET_WM_COMMAND_CMD(wp, lp));
  167. }
  168. return FALSE;
  169. }
  170. /*****************************************************************************
  171. *
  172. * c_vvtblBool
  173. *
  174. * Our vtbl.
  175. *
  176. *****************************************************************************/
  177. const VLISTVTBL c_vvtblBool = {
  178. VBool_PreDisplay,
  179. VBool_Destroy,
  180. IDD_VAL_BOOL,
  181. VBool_DlgProc,
  182. };
  183. /*****************************************************************************
  184. *
  185. * VBool_Create
  186. *
  187. * Make a vlist item that tracks a BOOL.
  188. *
  189. *****************************************************************************/
  190. PVLISTITEM EXTERNAL
  191. VBool_Create(LPDIPROPDWORD pdipdw, PROPUPDATEPROC Update, PV pvRef1, PV pvRef2)
  192. {
  193. PVLISTBOOL pvbool = LocalAlloc(LPTR, cbX(VLISTBOOL));
  194. if (pvbool) {
  195. pvbool->item.pvtbl = &c_vvtblBool;
  196. pvbool->dipdw = *pdipdw;
  197. pvbool->Update = Update;
  198. pvbool->pvRef1 = pvRef1;
  199. pvbool->pvRef2 = pvRef2;
  200. }
  201. return (PV)pvbool;
  202. }