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.

256 lines
7.1 KiB

  1. /****************************************************************************\
  2. OPTCOMP.C / Setup Manager
  3. Microsoft Confidential
  4. Copyright (c) Microsoft Corporation 2001-2002
  5. All rights reserved
  6. Source file for the OPK Wizard that contains the external and internal
  7. functions used by the "Optional Component" wizard page.
  8. 01/2002 - Stephen Lodwick (STELO)
  9. Initial creation
  10. \****************************************************************************/
  11. //
  12. // Include File(s):
  13. //
  14. #include "pch.h"
  15. #include "wizard.h"
  16. #include "resource.h"
  17. #include "optcomp.h"
  18. //
  19. // Internal Defined Value(s):
  20. //
  21. //
  22. // Internal Function Prototype(s):
  23. //
  24. static BOOL OnInit(HWND, HWND, LPARAM);
  25. static void SaveData(HWND);
  26. static void OnListViewNotify(HWND, UINT, WPARAM, NMLVDISPINFO*);
  27. //
  28. // External Function(s):
  29. //
  30. INT_PTR CALLBACK OptionalCompDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  31. {
  32. switch (uMsg)
  33. {
  34. HANDLE_MSG(hwnd, WM_INITDIALOG, OnInit);
  35. case WM_NOTIFY:
  36. switch ( wParam )
  37. {
  38. case IDC_OPTCOMP:
  39. // Notification to list view, lets handle below
  40. //
  41. OnListViewNotify(hwnd, uMsg, wParam, (NMLVDISPINFO*) lParam);
  42. break;
  43. default:
  44. switch ( ((NMHDR FAR *) lParam)->code )
  45. {
  46. case PSN_KILLACTIVE:
  47. case PSN_RESET:
  48. case PSN_WIZBACK:
  49. case PSN_WIZFINISH:
  50. break;
  51. case PSN_WIZNEXT:
  52. SaveData(hwnd);
  53. break;
  54. case PSN_QUERYCANCEL:
  55. WIZ_CANCEL(hwnd);
  56. break;
  57. case PSN_HELP:
  58. WIZ_HELP();
  59. break;
  60. case PSN_SETACTIVE:
  61. WIZ_BUTTONS(hwnd, PSWIZB_BACK | PSWIZB_NEXT);
  62. break;
  63. }
  64. break;
  65. }
  66. default:
  67. return FALSE;
  68. }
  69. return TRUE;
  70. }
  71. //
  72. // Internal Function(s):
  73. //
  74. static BOOL OnInit(HWND hwnd, HWND hwndFocus, LPARAM lParam)
  75. {
  76. LVITEM lvItem;
  77. LPTSTR lpItemText = NULL;
  78. LVCOLUMN lvCol;
  79. DWORD dwPosition = ListView_GetItemCount( GetDlgItem(hwnd, IDC_OPTCOMP) );
  80. RECT rect;
  81. INT index;
  82. DWORD64 dwComponents;
  83. HWND lvHandle = GetDlgItem(hwnd, IDC_OPTCOMP);
  84. // Add check boxes to each of the items
  85. //
  86. ListView_SetExtendedListViewStyle(lvHandle, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);
  87. // Believe it or not we must add the column (even though it's hidden)
  88. //
  89. GetClientRect( lvHandle, &rect );
  90. lvCol.mask = LVCF_FMT | LVCF_WIDTH;
  91. lvCol.fmt = LVCFMT_LEFT;
  92. lvCol.cx = rect.right;
  93. ListView_InsertColumn(lvHandle, 0, &lvCol);
  94. ListView_SetColumnWidth(lvHandle, 0, rect.right);
  95. // Go through all of the known components and add them to the list box
  96. //
  97. for (index=0;index<AS(s_cgComponentNames);index++)
  98. {
  99. // Is this platform allowed to have this component
  100. //
  101. if ( s_cgComponentNames[index].dwValidSkus & WizGlobals.iPlatform)
  102. {
  103. DWORD dwItem = ListView_GetItemCount(lvHandle);
  104. BOOL bReturn = FALSE;
  105. // We are allowed to add this string
  106. //
  107. lpItemText = AllocateString(NULL, s_cgComponentNames[index].uId);
  108. ZeroMemory(&lvItem, sizeof(LVITEM));
  109. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  110. lvItem.state = 0;
  111. lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  112. lvItem.iItem = dwItem;
  113. lvItem.lParam = s_cgComponentNames[index].dwComponentsIndex;
  114. lvItem.iSubItem = 0;
  115. lvItem.pszText = lpItemText;
  116. ListView_InsertItem(lvHandle, &lvItem);
  117. // Determine if all of the necessary components are installed
  118. //
  119. bReturn = ((GenSettings.dwWindowsComponents & s_cgComponentNames[index].dwComponents) == s_cgComponentNames[index].dwComponents) ? TRUE : FALSE;
  120. // Check the item depending on the default value set in the platform page
  121. //
  122. ListView_SetCheckState(lvHandle, dwItem, bReturn)
  123. FREE(lpItemText);
  124. }
  125. }
  126. // Always return false to WM_INITDIALOG.
  127. //
  128. return FALSE;
  129. }
  130. static void SaveData(HWND hwnd)
  131. {
  132. DWORD dwItemCount = 0,
  133. dwIndex = 0;
  134. HWND lvHandle = GetDlgItem(hwnd, IDC_OPTCOMP);
  135. BOOL bChecked = FALSE;
  136. LVITEM lvItem;
  137. DWORD64 dwComponents = 0;
  138. BOOL bAddComponent = FALSE;
  139. // Check to make sure we have a valid handle and that there's atleast one item in the list
  140. //
  141. if ( ( lvHandle ) &&
  142. (dwItemCount = ListView_GetItemCount(lvHandle))
  143. )
  144. {
  145. // Zero this out as we're going to rescan the components to install
  146. //
  147. GenSettings.dwWindowsComponents = 0;
  148. // Iterate through each of the items in the list
  149. //
  150. for (dwIndex=0;dwIndex < dwItemCount;dwIndex++)
  151. {
  152. ZeroMemory(&lvItem, sizeof(LVITEM));
  153. lvItem.mask = LVIF_PARAM;
  154. lvItem.iItem = dwIndex;
  155. lvItem.iSubItem = 0;
  156. ListView_GetItem(lvHandle, &lvItem);
  157. // Determine if this is a component group to install
  158. //
  159. if ( ListView_GetCheckState(lvHandle, dwIndex) )
  160. {
  161. // We would like to install this component group
  162. //
  163. GenSettings.dwWindowsComponents |= s_cgComponentNames[lvItem.lParam].dwComponents;
  164. }
  165. }
  166. }
  167. }
  168. static void OnListViewNotify(HWND hwnd, UINT uMsg, WPARAM wParam, NMLVDISPINFO * lpnmlvdi)
  169. {
  170. HWND lvHandle = GetDlgItem(hwnd, IDC_OPTCOMP);
  171. POINT ptScreen,
  172. ptClient;
  173. LVHITTESTINFO lvHitInfo;
  174. LVITEM lvItem;
  175. // See what the notification message that was sent to the list view.
  176. //
  177. switch ( lpnmlvdi->hdr.code )
  178. {
  179. case NM_DBLCLK:
  180. // Get cursor position, translate to client coordinates and
  181. // do a listview hittest.
  182. //
  183. GetCursorPos(&ptScreen);
  184. ptClient.x = ptScreen.x;
  185. ptClient.y = ptScreen.y;
  186. MapWindowPoints(NULL, lvHandle, &ptClient, 1);
  187. lvHitInfo.pt.x = ptClient.x;
  188. lvHitInfo.pt.y = ptClient.y;
  189. ListView_HitTest(lvHandle, &lvHitInfo);
  190. // Test if item was clicked.
  191. //
  192. if ( lvHitInfo.flags & LVHT_ONITEM )
  193. {
  194. // Set the check button on/off depending on prior value
  195. //
  196. ListView_SetCheckState(lvHandle, lvHitInfo.iItem, !ListView_GetCheckState(lvHandle, lvHitInfo.iItem));
  197. }
  198. break;
  199. }
  200. return;
  201. }