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.

282 lines
7.8 KiB

  1. /*
  2. * common - Common user interface services
  3. */
  4. #include "tweakui.h"
  5. /*****************************************************************************
  6. *
  7. * Common_SetDirty
  8. *
  9. * Make a property sheet dirty.
  10. *
  11. *****************************************************************************/
  12. void NEAR PASCAL
  13. Common_SetDirty(HWND hdlg)
  14. {
  15. PropSheet_Changed(GetParent(hdlg), hdlg);
  16. }
  17. /*****************************************************************************
  18. *
  19. * Common_NeedLogoff
  20. *
  21. * Indicate that you need to log off for the changes to take effect.
  22. *
  23. *****************************************************************************/
  24. void NEAR PASCAL
  25. Common_NeedLogoff(HWND hdlg)
  26. {
  27. PropSheet_RestartWindows(GetParent(hdlg));
  28. }
  29. /*****************************************************************************
  30. *
  31. * Common_OnHelp
  32. *
  33. * Respond to the F1 key.
  34. *
  35. *****************************************************************************/
  36. void PASCAL
  37. Common_OnHelp(LPARAM lp, const DWORD CODESEG *pdwHelp)
  38. {
  39. WinHelp((HWND) ((LPHELPINFO) lp)->hItemHandle, c_tszMyHelp,
  40. HELP_WM_HELP, (DWORD_PTR) pdwHelp);
  41. }
  42. /*****************************************************************************
  43. *
  44. * Common_OnContextMenu
  45. *
  46. * Respond to a right-click.
  47. *
  48. *****************************************************************************/
  49. void PASCAL
  50. Common_OnContextMenu(WPARAM wp, const DWORD CODESEG *pdwHelp)
  51. {
  52. WinHelp((HWND) wp, c_tszMyHelp, HELP_CONTEXTMENU, (DWORD_PTR) pdwHelp);
  53. }
  54. /*****************************************************************************
  55. *
  56. * Common_OnLvContextMenu
  57. *
  58. * The context menu shall appear in the listview.
  59. *
  60. * Have the callback generate the menu, then pop it up and let the
  61. * window procedure's WM_COMMAND do the rest.
  62. *
  63. *****************************************************************************/
  64. void PASCAL
  65. Common_OnLvContextMenu(HWND hwnd, POINT pt, CMCALLBACK pfn)
  66. {
  67. int iItem = Misc_LV_GetCurSel(hwnd);
  68. if (iItem != -1) {
  69. ClientToScreen(hwnd, &pt); /* Make it screen coordinates */
  70. TrackPopupMenuEx(pfn(hwnd, iItem),
  71. TPM_RIGHTBUTTON | TPM_VERTICAL |
  72. TPM_LEFTALIGN | TPM_TOPALIGN, pt.x, pt.y,
  73. GetParent(hwnd), 0);
  74. }
  75. }
  76. /*****************************************************************************
  77. *
  78. * Common_LV_OnContextMenu
  79. *
  80. * If the context menu came from the listview, figure out which
  81. * item got clicked on. If we find an item, pop up its context
  82. * menu. Otherwise, just do the standard help thing.
  83. *
  84. * NOTE! We don't use LVHT_ONITEM because ListView is broken!
  85. * Watch:
  86. *
  87. * #define LVHT_ONITEMSTATEICON 0x0008
  88. * #define LVHT_ABOVE 0x0008
  89. *
  90. * Oops. This means that clicks above the item are treated as
  91. * clicks on the state icon.
  92. *
  93. * Fortunately, we reside completely in report view, so you can't
  94. * legally click above the item. The only way it can happen is
  95. * if the coordinates to OnContextMenu are out of range, so we
  96. * catch that up front and munge it accordingly.
  97. *
  98. *****************************************************************************/
  99. void PASCAL
  100. Common_LV_OnContextMenu(HWND hdlg, HWND hwnd, LPARAM lp,
  101. CMCALLBACK pfn, const DWORD CODESEG *pdwHelp)
  102. {
  103. if (GetDlgCtrlID(hwnd) == IDC_LISTVIEW) {
  104. LV_HITTESTINFO hti;
  105. if (lp == (LPARAM)0xFFFFFFFF) {
  106. /* Pretend it was on the center of the small icon */
  107. ListView_GetItemPosition(hwnd, Misc_LV_GetCurSel(hwnd),
  108. &hti.pt);
  109. hti.pt.x += GetSystemMetrics(SM_CXSMICON) / 2;
  110. hti.pt.y += GetSystemMetrics(SM_CYSMICON) / 2;
  111. Common_OnLvContextMenu(hwnd, hti.pt, pfn);
  112. } else {
  113. Misc_LV_HitTest(hwnd, &hti, lp);
  114. if ((hti.flags & LVHT_ONITEM)) {
  115. /* Because LV sometimes forgets to move the focus... */
  116. Misc_LV_SetCurSel(hwnd, hti.iItem);
  117. Common_OnLvContextMenu(hwnd, hti.pt, pfn);
  118. } else {
  119. Common_OnContextMenu((WPARAM)hwnd, pdwHelp);
  120. }
  121. }
  122. } else {
  123. Common_OnContextMenu((WPARAM)hwnd, pdwHelp);
  124. }
  125. }
  126. /*****************************************************************************
  127. *
  128. * Common_OnLvCommand
  129. *
  130. * Handle a WM_COMMAND that might be for the listview.
  131. *
  132. *****************************************************************************/
  133. void PASCAL
  134. Common_OnLvCommand(HWND hdlg, int idCmd, PLVCI rglvci, int clvci)
  135. {
  136. do {
  137. if (idCmd == rglvci[0].id) {
  138. HWND hwnd = GetDlgItem(hdlg, IDC_LISTVIEW);
  139. int iItem = Misc_LV_GetCurSel(hwnd);
  140. if (iItem != -1) {
  141. rglvci[0].pfn(hwnd, iItem);
  142. }
  143. break;
  144. }
  145. rglvci++;
  146. } while (--clvci);
  147. }
  148. /*****************************************************************************
  149. *
  150. * EnableDlgItem
  151. *
  152. * A simple wrapper.
  153. *
  154. *****************************************************************************/
  155. void NEAR PASCAL
  156. EnableDlgItem(HWND hdlg, UINT idc, BOOL f)
  157. {
  158. EnableWindow(GetDlgItem(hdlg, idc), f);
  159. }
  160. /*****************************************************************************
  161. *
  162. * EnableDlgItems
  163. *
  164. *****************************************************************************/
  165. void NEAR PASCAL
  166. EnableDlgItems(HWND hdlg, UINT idcFirst, UINT idcLast, BOOL f)
  167. {
  168. for (; idcFirst <= idcLast; idcFirst++) {
  169. EnableWindow(GetDlgItem(hdlg, idcFirst), f);
  170. }
  171. }
  172. /*****************************************************************************
  173. *
  174. * AdjustDlgItems
  175. *
  176. *****************************************************************************/
  177. void NEAR PASCAL
  178. AdjustDlgItems(HWND hdlg, UINT idcFirst, UINT idcLast, UINT adi)
  179. {
  180. for (UINT idc = idcFirst; idc <= idcLast; idc++) {
  181. HWND hwnd = GetDlgItem(hdlg, idc);
  182. if (adi & (ADI_DISABLE | ADI_ENABLE)) {
  183. EnableWindow(hwnd, (adi & ADI_ENABLE) ? TRUE : FALSE);
  184. }
  185. if (adi & (ADI_HIDE | ADI_SHOW)) {
  186. ShowWindow(hwnd, (adi & ADI_SHOW) ? SW_SHOW : SW_HIDE);
  187. }
  188. }
  189. }
  190. /*****************************************************************************
  191. *
  192. * SetDlgItemTextLimit
  193. *
  194. * Set the dialog item text as well as limiting its size.
  195. *
  196. *****************************************************************************/
  197. void NEAR PASCAL
  198. SetDlgItemTextLimit(HWND hdlg, UINT id, LPCTSTR ptsz, UINT ctch)
  199. {
  200. HWND hwnd = GetDlgItem(hdlg, id);
  201. SetWindowText(hwnd, ptsz);
  202. Edit_LimitText(hwnd, ctch - 1);
  203. }
  204. /*****************************************************************************
  205. *
  206. * DestroyDlgItems
  207. *
  208. *****************************************************************************/
  209. void NEAR PASCAL
  210. DestroyDlgItems(HWND hdlg, UINT idcFirst, UINT idcLast)
  211. {
  212. UINT idc;
  213. for (idc = idcFirst; idc <= idcLast; idc++) {
  214. DestroyWindow(GetDlgItem(hdlg, idc));
  215. }
  216. }
  217. /*****************************************************************************
  218. *
  219. * GetDlgItemRect
  220. *
  221. * Get the rect of a dialog item in client coordinates.
  222. *
  223. *****************************************************************************/
  224. void PASCAL
  225. GetDlgItemRect(HWND hdlg, UINT idc, LPRECT prc)
  226. {
  227. GetWindowRect(GetDlgItem(hdlg, idc), prc);
  228. MapWindowRect(NULL, hdlg, prc);
  229. }
  230. /*****************************************************************************
  231. *
  232. * MoveDlgItems
  233. *
  234. *****************************************************************************/
  235. void PASCAL
  236. MoveDlgItems(HWND hdlg, UINT idcTarget, UINT idcFirst, UINT idcLast)
  237. {
  238. RECT rcFrom, rcTo;
  239. GetDlgItemRect(hdlg, idcTarget, &rcTo);
  240. GetDlgItemRect(hdlg, idcFirst, &rcFrom);
  241. int dy = rcTo.top - rcFrom.top;
  242. HDWP hdwp = BeginDeferWindowPos(idcLast - idcFirst + 1);
  243. for (UINT idc = idcFirst; idc <= idcLast; idc++) {
  244. GetDlgItemRect(hdlg, idc, &rcFrom);
  245. HWND hwnd = GetDlgItem(hdlg, idc);
  246. hdwp = DeferWindowPos(hdwp, hwnd, NULL,
  247. rcFrom.left, rcFrom.top + dy, 0, 0,
  248. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
  249. }
  250. EndDeferWindowPos(hdwp);
  251. }