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.

302 lines
7.3 KiB

  1. /*****************************************************************************
  2. *
  3. * diqvcal.c
  4. *
  5. * VList plug-in that does calibrations.
  6. *
  7. *****************************************************************************/
  8. #include "diquick.h"
  9. #pragma BEGIN_CONST_DATA
  10. /*****************************************************************************
  11. *
  12. * VLISTCAL
  13. *
  14. * range-specific goo.
  15. *
  16. *****************************************************************************/
  17. typedef struct VLISTCAL {
  18. VLISTITEM item;
  19. DIPROPCAL dical;
  20. int iRadix;
  21. /*
  22. * If non-NULL, then this is a read/write control.
  23. */
  24. PROPUPDATEPROC Update;
  25. PV pvRef1;
  26. PV pvRef2;
  27. } VLISTCAL, *PVLISTCAL;
  28. /*****************************************************************************
  29. *
  30. * VCal_InitUD
  31. *
  32. * Common updown initialization goo.
  33. *
  34. *****************************************************************************/
  35. void INTERNAL
  36. VCal_InitUD(HWND hwndUD, PVLISTCAL pvcal, int iValue)
  37. {
  38. ShowWindow(hwndUD, pvcal->Update ? SW_SHOW : SW_HIDE);
  39. UpDown_SetRange(hwndUD, 0x80000000, 0x7FFFFFFF);
  40. UpDown_SetPos(hwndUD, pvcal->iRadix, iValue);
  41. Edit_SetReadOnly(GetWindow(hwndUD, GW_HWNDPREV), !pvcal->Update);
  42. }
  43. /*****************************************************************************
  44. *
  45. * VCal_PreDisplay
  46. *
  47. * Set the edit control text and let the dialog know who it is in
  48. * charge of.
  49. *
  50. *****************************************************************************/
  51. void INTERNAL
  52. VCal_PreDisplay(HWND hdlg, PV pv)
  53. {
  54. PVLISTCAL pvcal = pv;
  55. HWND hwndUD;
  56. hwndUD = GetDlgItem(hdlg, IDC_VCAL_MINUD);
  57. VCal_InitUD(hwndUD, pvcal, pvcal->dical.lMin);
  58. hwndUD = GetDlgItem(hdlg, IDC_VCAL_CTRUD);
  59. VCal_InitUD(hwndUD, pvcal, pvcal->dical.lCenter);
  60. hwndUD = GetDlgItem(hdlg, IDC_VCAL_MAXUD);
  61. VCal_InitUD(hwndUD, pvcal, pvcal->dical.lMax);
  62. ShowWindow(GetDlgItem(hdlg, IDC_VCAL_APPLY),
  63. pvcal->Update ? SW_SHOW : SW_HIDE);
  64. CheckRadioButton(hdlg, IDC_VCAL_DEC, IDC_VCAL_HEX,
  65. pvcal->iRadix == 10 ? IDC_VCAL_DEC : IDC_VCAL_HEX);
  66. SetDialogPtr(hdlg, pvcal);
  67. }
  68. /*****************************************************************************
  69. *
  70. * VCal_Destroy
  71. *
  72. * Nothing to clean up.
  73. *
  74. *****************************************************************************/
  75. void INTERNAL
  76. VCal_Destroy(PV pv)
  77. {
  78. PVLISTCAL pvcal = pv;
  79. }
  80. /*****************************************************************************
  81. *
  82. * VCal_OnInitDialog
  83. *
  84. * Limit the strings to MAX_PATH characters.
  85. *
  86. *****************************************************************************/
  87. BOOL INTERNAL
  88. VCal_OnInitDialog(HWND hdlg)
  89. {
  90. HWND hwndEdit;
  91. hwndEdit = GetDlgItem(hdlg, IDC_VCAL_MIN);
  92. Edit_LimitText(hwndEdit, CCHMAXINT);
  93. hwndEdit = GetDlgItem(hdlg, IDC_VCAL_CTR);
  94. Edit_LimitText(hwndEdit, CCHMAXINT);
  95. hwndEdit = GetDlgItem(hdlg, IDC_VCAL_MAX);
  96. Edit_LimitText(hwndEdit, CCHMAXINT);
  97. return TRUE;
  98. }
  99. /*****************************************************************************
  100. *
  101. * VCal_OnApply
  102. *
  103. * Read the value (tricky if hex mode) and call the Update.
  104. *
  105. *****************************************************************************/
  106. void INLINE
  107. VCal_OnApply(HWND hdlg, PVLISTCAL pvcal)
  108. {
  109. pvcal->Update(&pvcal->dical.diph, pvcal->pvRef1, pvcal->pvRef2);
  110. }
  111. /*****************************************************************************
  112. *
  113. * VCal_GetValue
  114. *
  115. *****************************************************************************/
  116. void INTERNAL
  117. VCal_GetValue(HWND hdlg, PVLISTCAL pvcal)
  118. {
  119. HWND hwndUD;
  120. hwndUD = GetDlgItem(hdlg, IDC_VCAL_MINUD);
  121. UpDown_GetPos(hwndUD, &pvcal->dical.lMin);
  122. hwndUD = GetDlgItem(hdlg, IDC_VCAL_CTRUD);
  123. UpDown_GetPos(hwndUD, &pvcal->dical.lCenter);
  124. hwndUD = GetDlgItem(hdlg, IDC_VCAL_MAXUD);
  125. UpDown_GetPos(hwndUD, &pvcal->dical.lMax);
  126. }
  127. /*****************************************************************************
  128. *
  129. * VCal_SetValue
  130. *
  131. *****************************************************************************/
  132. void INTERNAL
  133. VCal_SetValue(HWND hdlg, PVLISTCAL pvcal)
  134. {
  135. HWND hwndUD;
  136. hwndUD = GetDlgItem(hdlg, IDC_VCAL_MINUD);
  137. UpDown_SetPos(hwndUD, pvcal->iRadix, pvcal->dical.lMin);
  138. hwndUD = GetDlgItem(hdlg, IDC_VCAL_CTRUD);
  139. UpDown_SetPos(hwndUD, pvcal->iRadix, pvcal->dical.lCenter);
  140. hwndUD = GetDlgItem(hdlg, IDC_VCAL_MAXUD);
  141. UpDown_SetPos(hwndUD, pvcal->iRadix, pvcal->dical.lMax);
  142. }
  143. /*****************************************************************************
  144. *
  145. * VCal_SetRadix
  146. *
  147. * Set a new radix by reading the old value, changing the radix,
  148. * and writing out the new value.
  149. *
  150. *****************************************************************************/
  151. void INTERNAL
  152. VCal_SetRadix(HWND hdlg, PVLISTCAL pvcal, int iRadix)
  153. {
  154. VCal_GetValue(hdlg, pvcal);
  155. pvcal->iRadix = iRadix;
  156. VCal_SetValue(hdlg, pvcal);
  157. }
  158. /*****************************************************************************
  159. *
  160. * VCal_OnCommand
  161. *
  162. * If they changed the radix, then change it.
  163. *
  164. * If they pressed Apply, then apply it.
  165. *
  166. *****************************************************************************/
  167. BOOL INTERNAL
  168. VCal_OnCommand(HWND hdlg, int id, UINT codeNotify)
  169. {
  170. PVLISTCAL pvcal = GetDialogPtr(hdlg);
  171. switch (id) {
  172. case IDC_VCAL_DEC:
  173. VCal_SetRadix(hdlg, pvcal, 10);
  174. return TRUE;
  175. case IDC_VCAL_HEX:
  176. VCal_SetRadix(hdlg, pvcal, 16);
  177. return TRUE;
  178. case IDC_VCAL_APPLY:
  179. VCal_GetValue(hdlg, pvcal);
  180. VCal_OnApply(hdlg, pvcal);
  181. return TRUE;
  182. }
  183. return FALSE;
  184. }
  185. /*****************************************************************************
  186. *
  187. * VCal_DlgProc
  188. *
  189. * Nothing really happens here. The real work is done externally.
  190. *
  191. *****************************************************************************/
  192. INT_PTR CALLBACK
  193. VCal_DlgProc(HWND hdlg, UINT wm, WPARAM wp, LPARAM lp)
  194. {
  195. switch (wm) {
  196. case WM_INITDIALOG:
  197. return VCal_OnInitDialog(hdlg);
  198. case WM_COMMAND:
  199. return VCal_OnCommand(hdlg,
  200. (int)GET_WM_COMMAND_ID(wp, lp),
  201. (UINT)GET_WM_COMMAND_CMD(wp, lp));
  202. }
  203. return FALSE;
  204. }
  205. /*****************************************************************************
  206. *
  207. * c_vvtblInt
  208. *
  209. * Our vtbl.
  210. *
  211. *****************************************************************************/
  212. const VLISTVTBL c_vvtblCal = {
  213. VCal_PreDisplay,
  214. VCal_Destroy,
  215. IDD_VAL_CAL,
  216. VCal_DlgProc,
  217. };
  218. /*****************************************************************************
  219. *
  220. * VCal_Create
  221. *
  222. * Make a vlist item that tracks a DIPROPCAL.
  223. *
  224. *****************************************************************************/
  225. PVLISTITEM EXTERNAL
  226. VCal_Create(LPDIPROPCAL pdical, int iRadix,
  227. PROPUPDATEPROC Update, PV pvRef1, PV pvRef2)
  228. {
  229. PVLISTCAL pvcal = LocalAlloc(LPTR, cbX(VLISTCAL));
  230. if (pvcal) {
  231. pvcal->item.pvtbl = &c_vvtblCal;
  232. pvcal->dical = *pdical;
  233. pvcal->iRadix = iRadix;
  234. pvcal->Update = Update;
  235. pvcal->pvRef1 = pvRef1;
  236. pvcal->pvRef2 = pvRef2;
  237. }
  238. return (PV)pvcal;
  239. }