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.

290 lines
7.0 KiB

  1. /*****************************************************************************
  2. *
  3. * diqvrang.c
  4. *
  5. * VList plug-in that does ranges.
  6. *
  7. *****************************************************************************/
  8. #include "diquick.h"
  9. #pragma BEGIN_CONST_DATA
  10. /*****************************************************************************
  11. *
  12. * VLISTRANGE
  13. *
  14. * range-specific goo.
  15. *
  16. *****************************************************************************/
  17. typedef struct VLISTRANGE {
  18. VLISTITEM item;
  19. DIPROPRANGE diprg;
  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. } VLISTRANGE, *PVLISTRANGE;
  28. /*****************************************************************************
  29. *
  30. * VRange_InitUD
  31. *
  32. * Common updown initialization goo.
  33. *
  34. *****************************************************************************/
  35. void INTERNAL
  36. VRange_InitUD(HWND hwndUD, PVLISTRANGE pvrg, int iValue)
  37. {
  38. ShowWindow(hwndUD, pvrg->Update ? SW_SHOW : SW_HIDE);
  39. UpDown_SetRange(hwndUD, 0x80000000, 0x7FFFFFFF);
  40. UpDown_SetPos(hwndUD, pvrg->iRadix, iValue);
  41. Edit_SetReadOnly(GetWindow(hwndUD, GW_HWNDPREV), !pvrg->Update);
  42. }
  43. /*****************************************************************************
  44. *
  45. * VRange_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. VRange_PreDisplay(HWND hdlg, PV pv)
  53. {
  54. PVLISTRANGE pvrg = pv;
  55. HWND hwndUD;
  56. hwndUD = GetDlgItem(hdlg, IDC_VRANGE_MINUD);
  57. VRange_InitUD(hwndUD, pvrg, pvrg->diprg.lMin);
  58. hwndUD = GetDlgItem(hdlg, IDC_VRANGE_MAXUD);
  59. VRange_InitUD(hwndUD, pvrg, pvrg->diprg.lMax);
  60. ShowWindow(GetDlgItem(hdlg, IDC_VRANGE_APPLY),
  61. pvrg->Update ? SW_SHOW : SW_HIDE);
  62. CheckRadioButton(hdlg, IDC_VRANGE_DEC, IDC_VRANGE_HEX,
  63. pvrg->iRadix == 10 ? IDC_VRANGE_DEC : IDC_VRANGE_HEX);
  64. SetDialogPtr(hdlg, pvrg);
  65. }
  66. /*****************************************************************************
  67. *
  68. * VRange_Destroy
  69. *
  70. * Nothing to clean up.
  71. *
  72. *****************************************************************************/
  73. void INTERNAL
  74. VRange_Destroy(PV pv)
  75. {
  76. PVLISTRANGE pvrg = pv;
  77. }
  78. /*****************************************************************************
  79. *
  80. * VRange_OnInitDialog
  81. *
  82. * Limit the strings to MAX_PATH characters.
  83. *
  84. *****************************************************************************/
  85. BOOL INTERNAL
  86. VRange_OnInitDialog(HWND hdlg)
  87. {
  88. HWND hwndEdit;
  89. hwndEdit = GetDlgItem(hdlg, IDC_VRANGE_MIN);
  90. Edit_LimitText(hwndEdit, CCHMAXINT);
  91. hwndEdit = GetDlgItem(hdlg, IDC_VRANGE_MAX);
  92. Edit_LimitText(hwndEdit, CCHMAXINT);
  93. return TRUE;
  94. }
  95. /*****************************************************************************
  96. *
  97. * VRange_OnApply
  98. *
  99. * Read the value (tricky if hex mode) and call the Update.
  100. *
  101. *****************************************************************************/
  102. void INLINE
  103. VRange_OnApply(HWND hdlg, PVLISTRANGE pvrg)
  104. {
  105. pvrg->Update(&pvrg->diprg.diph, pvrg->pvRef1, pvrg->pvRef2);
  106. }
  107. /*****************************************************************************
  108. *
  109. * VRange_GetValue
  110. *
  111. *****************************************************************************/
  112. void INTERNAL
  113. VRange_GetValue(HWND hdlg, PVLISTRANGE pvrg)
  114. {
  115. HWND hwndUD;
  116. hwndUD = GetDlgItem(hdlg, IDC_VRANGE_MINUD);
  117. UpDown_GetPos(hwndUD, &pvrg->diprg.lMin);
  118. hwndUD = GetDlgItem(hdlg, IDC_VRANGE_MAXUD);
  119. UpDown_GetPos(hwndUD, &pvrg->diprg.lMax);
  120. }
  121. /*****************************************************************************
  122. *
  123. * VRange_SetValue
  124. *
  125. *****************************************************************************/
  126. void INTERNAL
  127. VRange_SetValue(HWND hdlg, PVLISTRANGE pvrg)
  128. {
  129. HWND hwndUD;
  130. hwndUD = GetDlgItem(hdlg, IDC_VRANGE_MINUD);
  131. UpDown_SetPos(hwndUD, pvrg->iRadix, pvrg->diprg.lMin);
  132. hwndUD = GetDlgItem(hdlg, IDC_VRANGE_MAXUD);
  133. UpDown_SetPos(hwndUD, pvrg->iRadix, pvrg->diprg.lMax);
  134. }
  135. /*****************************************************************************
  136. *
  137. * VRange_SetRadix
  138. *
  139. * Set a new radix by reading the old value, changing the radix,
  140. * and writing out the new value.
  141. *
  142. *****************************************************************************/
  143. void INTERNAL
  144. VRange_SetRadix(HWND hdlg, PVLISTRANGE pvrg, int iRadix)
  145. {
  146. VRange_GetValue(hdlg, pvrg);
  147. pvrg->iRadix = iRadix;
  148. VRange_SetValue(hdlg, pvrg);
  149. }
  150. /*****************************************************************************
  151. *
  152. * VRange_OnCommand
  153. *
  154. * If they changed the radix, then change it.
  155. *
  156. * If they pressed Apply, then apply it.
  157. *
  158. *****************************************************************************/
  159. BOOL INTERNAL
  160. VRange_OnCommand(HWND hdlg, int id, UINT codeNotify)
  161. {
  162. PVLISTRANGE pvrg = GetDialogPtr(hdlg);
  163. switch (id) {
  164. case IDC_VRANGE_DEC:
  165. VRange_SetRadix(hdlg, pvrg, 10);
  166. return TRUE;
  167. case IDC_VRANGE_HEX:
  168. VRange_SetRadix(hdlg, pvrg, 16);
  169. return TRUE;
  170. case IDC_VRANGE_APPLY:
  171. VRange_GetValue(hdlg, pvrg);
  172. VRange_OnApply(hdlg, pvrg);
  173. return TRUE;
  174. }
  175. return FALSE;
  176. }
  177. /*****************************************************************************
  178. *
  179. * VRange_DlgProc
  180. *
  181. * Nothing really happens here. The real work is done externally.
  182. *
  183. *****************************************************************************/
  184. INT_PTR CALLBACK
  185. VRange_DlgProc(HWND hdlg, UINT wm, WPARAM wp, LPARAM lp)
  186. {
  187. switch (wm) {
  188. case WM_INITDIALOG:
  189. return VRange_OnInitDialog(hdlg);
  190. case WM_COMMAND:
  191. return VRange_OnCommand(hdlg,
  192. (int)GET_WM_COMMAND_ID(wp, lp),
  193. (UINT)GET_WM_COMMAND_CMD(wp, lp));
  194. }
  195. return FALSE;
  196. }
  197. /*****************************************************************************
  198. *
  199. * c_vvtblInt
  200. *
  201. * Our vtbl.
  202. *
  203. *****************************************************************************/
  204. const VLISTVTBL c_vvtblRange = {
  205. VRange_PreDisplay,
  206. VRange_Destroy,
  207. IDD_VAL_RANGE,
  208. VRange_DlgProc,
  209. };
  210. /*****************************************************************************
  211. *
  212. * VRange_Create
  213. *
  214. * Make a vlist item that tracks a string.
  215. *
  216. *****************************************************************************/
  217. PVLISTITEM EXTERNAL
  218. VRange_Create(LPDIPROPRANGE pdiprg, int iRadix,
  219. PROPUPDATEPROC Update, PV pvRef1, PV pvRef2)
  220. {
  221. PVLISTRANGE pvrg = LocalAlloc(LPTR, cbX(VLISTRANGE));
  222. if (pvrg) {
  223. pvrg->item.pvtbl = &c_vvtblRange;
  224. pvrg->diprg = *pdiprg;
  225. pvrg->iRadix = iRadix;
  226. pvrg->Update = Update;
  227. pvrg->pvRef1 = pvRef1;
  228. pvrg->pvRef2 = pvRef2;
  229. }
  230. return (PV)pvrg;
  231. }