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.

185 lines
4.4 KiB

  1. /*****************************************************************************
  2. *
  3. * diqvedit.c
  4. *
  5. * VList plug-in that does strings.
  6. *
  7. *****************************************************************************/
  8. #include "diquick.h"
  9. #pragma BEGIN_CONST_DATA
  10. /*****************************************************************************
  11. *
  12. * VLISTEDIT
  13. *
  14. * BOOL-specific goo.
  15. *
  16. *****************************************************************************/
  17. typedef struct VLISTEDIT {
  18. VLISTITEM item;
  19. PTSTR ptszValue;
  20. /*
  21. * If non-NULL, then this is a read/write control.
  22. */
  23. EDITUPDATEPROC Update;
  24. PV pvRef1;
  25. PV pvRef2;
  26. } VLISTEDIT, *PVLISTEDIT;
  27. /*****************************************************************************
  28. *
  29. * VEdit_PreDisplay
  30. *
  31. * Set the edit control text and let the dialog know who it is in
  32. * charge of.
  33. *
  34. *****************************************************************************/
  35. void INTERNAL
  36. VEdit_PreDisplay(HWND hdlg, PV pv)
  37. {
  38. PVLISTEDIT pvedit = pv;
  39. HWND hwndEdit = GetDlgItem(hdlg, IDC_VEDIT_EDIT);
  40. SetWindowText(hwndEdit, pvedit->ptszValue);
  41. Edit_SetReadOnly(hwndEdit, !pvedit->Update);
  42. ShowWindow(GetDlgItem(hdlg, IDC_VEDIT_APPLY),
  43. pvedit->Update ? SW_SHOW : SW_HIDE);
  44. SetDialogPtr(hdlg, pvedit);
  45. }
  46. /*****************************************************************************
  47. *
  48. * VEdit_Destroy
  49. *
  50. * Gotta free the string.
  51. *
  52. *****************************************************************************/
  53. void INTERNAL
  54. VEdit_Destroy(PV pv)
  55. {
  56. PVLISTEDIT pvedit = pv;
  57. LocalFree(pvedit->ptszValue);
  58. }
  59. /*****************************************************************************
  60. *
  61. * VEdit_OnInitDialog
  62. *
  63. * Limit the strings to MAX_PATH characters.
  64. *
  65. *****************************************************************************/
  66. BOOL INTERNAL
  67. VEdit_OnInitDialog(HWND hdlg)
  68. {
  69. HWND hwndEdit = GetDlgItem(hdlg, IDC_VEDIT_EDIT);
  70. Edit_LimitText(hwndEdit, MAX_PATH);
  71. return TRUE;
  72. }
  73. /*****************************************************************************
  74. *
  75. * VEdit_OnCommand
  76. *
  77. * If they pressed Apply, then apply it.
  78. *
  79. *****************************************************************************/
  80. BOOL INTERNAL
  81. VEdit_OnCommand(HWND hdlg, int id, UINT codeNotify)
  82. {
  83. if (id == IDC_VEDIT_APPLY) {
  84. PVLISTEDIT pvedit = GetDialogPtr(hdlg);
  85. TCHAR tsz[MAX_PATH];
  86. GetDlgItemText(hdlg, IDC_VEDIT_EDIT, tsz, cA(tsz));
  87. pvedit->Update(tsz, pvedit->pvRef1, pvedit->pvRef2);
  88. return TRUE;
  89. }
  90. return FALSE;
  91. }
  92. /*****************************************************************************
  93. *
  94. * VEdit_DlgProc
  95. *
  96. * Nothing really happens here. The real work is done externally.
  97. *
  98. *****************************************************************************/
  99. INT_PTR CALLBACK
  100. VEdit_DlgProc(HWND hdlg, UINT wm, WPARAM wp, LPARAM lp)
  101. {
  102. switch (wm) {
  103. case WM_INITDIALOG:
  104. return VEdit_OnInitDialog(hdlg);
  105. case WM_COMMAND:
  106. return VEdit_OnCommand(hdlg,
  107. (int)GET_WM_COMMAND_ID(wp, lp),
  108. (UINT)GET_WM_COMMAND_CMD(wp, lp));
  109. }
  110. return FALSE;
  111. }
  112. /*****************************************************************************
  113. *
  114. * c_vvtblEdit
  115. *
  116. * Our vtbl.
  117. *
  118. *****************************************************************************/
  119. const VLISTVTBL c_vvtblEdit = {
  120. VEdit_PreDisplay,
  121. VEdit_Destroy,
  122. IDD_VAL_EDIT,
  123. VEdit_DlgProc,
  124. };
  125. /*****************************************************************************
  126. *
  127. * VEdit_Create
  128. *
  129. * Make a vlist item that tracks a string.
  130. *
  131. *****************************************************************************/
  132. PVLISTITEM EXTERNAL
  133. VEdit_Create(LPCTSTR ptszValue, EDITUPDATEPROC Update, PV pvRef1, PV pvRef2)
  134. {
  135. PVLISTEDIT pvedit = LocalAlloc(LPTR, cbX(VLISTEDIT));
  136. if (pvedit) {
  137. pvedit->item.pvtbl = &c_vvtblEdit;
  138. pvedit->ptszValue = LocalAlloc(LPTR,
  139. cbX(TCHAR) * (lstrlen(ptszValue) + 1));
  140. if (pvedit->ptszValue) {
  141. lstrcpy(pvedit->ptszValue, ptszValue);
  142. pvedit->Update = Update;
  143. pvedit->pvRef1 = pvRef1;
  144. pvedit->pvRef2 = pvRef2;
  145. } else {
  146. LocalFree(pvedit);
  147. pvedit = 0;
  148. }
  149. }
  150. return (PV)pvedit;
  151. }