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.

443 lines
12 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1993-1995
  4. * TITLE: PROPPAGE.CPP
  5. * VERSION: 1.0
  6. * AUTHOR: jsenior
  7. * DATE: 10/28/1998
  8. *
  9. ********************************************************************************
  10. *
  11. * CHANGE LOG:
  12. *
  13. * DATE REV DESCRIPTION
  14. * ---------- ------- ----------------------------------------------------------
  15. * 10/28/1998 jsenior Original implementation.
  16. *
  17. *******************************************************************************/
  18. #include "BandPage.h"
  19. #include "PowrPage.h"
  20. #include "debug.h"
  21. HANDLE UsbPropertyPage::hInst = (HANDLE) 0;
  22. UsbPropertyPage::UsbPropertyPage(HDEVINFO DeviceInfoSet,
  23. PSP_DEVINFO_DATA DeviceInfoData) :
  24. deviceInfoSet(DeviceInfoSet), deviceInfoData(DeviceInfoData), imageList()
  25. {
  26. preItem = 0;
  27. hWndParent = NULL;
  28. rootItem = NULL;
  29. }
  30. UsbPropertyPage::UsbPropertyPage(HWND HWndParent, LPCSTR DeviceName) :
  31. deviceInfoSet(0), deviceInfoData(0), imageList()
  32. {
  33. WCHAR realName[MAX_PATH];
  34. if (MultiByteToWideChar(CP_ACP,
  35. MB_PRECOMPOSED,
  36. DeviceName,
  37. -1,
  38. realName,
  39. MAX_PATH)) {
  40. deviceName = realName;
  41. }
  42. preItem = 0;
  43. hWndParent = HWndParent;
  44. rootItem = NULL;
  45. }
  46. UsbPropertyPage::UsbPropertyPage(UsbItem *item) :
  47. deviceInfoSet(0), deviceInfoData(0), imageList()
  48. {
  49. preItem = item;
  50. hWndParent = NULL;
  51. rootItem = NULL;
  52. }
  53. HPROPSHEETPAGE UsbPropertyPage::Create()
  54. {
  55. //
  56. // Add the Port Settings property page
  57. //
  58. psp.dwSize = sizeof(PROPSHEETPAGE);
  59. psp.dwFlags = PSP_USECALLBACK; // | PSP_HASHELP;
  60. psp.hInstance = (HINSTANCE) hInst;
  61. psp.pszTemplate = MAKEINTRESOURCE(dlgResource);
  62. //
  63. // following points to the dlg window proc
  64. //
  65. psp.pfnDlgProc = StaticDialogProc;
  66. psp.lParam = (LPARAM) this;
  67. //
  68. // Following points to the control callback of the dlg window proc.
  69. // The callback gets called before creation/after destruction of the page
  70. //
  71. psp.pfnCallback = StaticDialogCallback;
  72. //
  73. // Allocate the actual page
  74. //
  75. return CreatePropertySheetPage(&psp);
  76. }
  77. UINT CALLBACK
  78. UsbPropertyPage::StaticDialogCallback(HWND Hwnd,
  79. UINT Msg,
  80. LPPROPSHEETPAGE Page)
  81. {
  82. UsbPropertyPage *that;
  83. that = (UsbPropertyPage*) Page->lParam;
  84. switch (Msg) {
  85. case PSPCB_CREATE:
  86. return TRUE; // return TRUE to continue with creation of page
  87. case PSPCB_RELEASE:
  88. DeleteChunk(that);
  89. delete that;
  90. CheckMemory();
  91. return 0; // return value ignored
  92. default:
  93. break;
  94. }
  95. return TRUE;
  96. }
  97. BOOL
  98. UsbPropertyPage::OnContextMenu(HWND HwndControl,
  99. WORD Xpos,
  100. WORD Ypos)
  101. {
  102. WinHelp(HwndControl,
  103. TEXT(HELPFILE),
  104. HELP_CONTEXTMENU,
  105. (USBULONG_PTR) HelpIds);
  106. return FALSE;
  107. }
  108. void
  109. UsbPropertyPage::OnHelp(HWND ParentHwnd,
  110. LPHELPINFO HelpInfo)
  111. {
  112. if (HelpInfo->iContextType == HELPINFO_WINDOW) {
  113. WinHelp((HWND) HelpInfo->hItemHandle,
  114. TEXT(HELPFILE),
  115. HELP_WM_HELP,
  116. (USBULONG_PTR) HelpIds);
  117. }
  118. }
  119. USBINT_PTR APIENTRY UsbPropertyPage::StaticDialogProc(IN HWND hDlg,
  120. IN UINT uMessage,
  121. IN WPARAM wParam,
  122. IN LPARAM lParam)
  123. {
  124. UsbPropertyPage *that;
  125. that = (UsbPropertyPage *) UsbGetWindowLongPtr(hDlg, USBDWLP_USER);
  126. if (!that && uMessage != WM_INITDIALOG)
  127. return FALSE; //DefDlgProc(hDlg, uMessage, wParam, lParam);
  128. switch (uMessage) {
  129. case WM_COMMAND:
  130. return that->OnCommand(HIWORD(wParam),
  131. LOWORD(wParam),
  132. (HWND) lParam);
  133. case WM_INITDIALOG:
  134. that = (UsbPropertyPage *) ((LPPROPSHEETPAGE)lParam)->lParam;
  135. UsbSetWindowLongPtr(hDlg, USBDWLP_USER, (USBLONG_PTR) that);
  136. that->hwnd = hDlg;
  137. return that->OnInitDialog();
  138. case WM_NOTIFY:
  139. return that->OnNotify(hDlg, (int) wParam, (LPNMHDR) lParam);
  140. case WM_CONTEXTMENU:
  141. return that->OnContextMenu((HWND)wParam, LOWORD(lParam), HIWORD(lParam));
  142. case WM_HELP:
  143. that->OnHelp(hDlg, (LPHELPINFO) lParam);
  144. break;
  145. default:
  146. break;
  147. }
  148. return that->ActualDialogProc(hDlg, uMessage, wParam, lParam);
  149. }
  150. BOOL UsbPropertyPage::OnNotify(HWND hDlg, int nID, LPNMHDR pnmh)
  151. {
  152. switch (pnmh->code) {
  153. //
  154. // Sent when the user clicks on Apply OR OK !!
  155. //
  156. case PSN_APPLY:
  157. //
  158. // Do what ever action is necessary
  159. //
  160. UsbSetWindowLongPtr(hwnd, USBDWLP_MSGRESULT, PSNRET_NOERROR);
  161. return TRUE;
  162. default:
  163. break;
  164. }
  165. return TRUE;
  166. }
  167. BOOL
  168. UsbPropertyPage::GetDeviceName()
  169. {
  170. HKEY hDeviceKey;
  171. DWORD dwBufferSize, dwError;
  172. WCHAR szBuffer[MAX_PATH];
  173. //
  174. // Open the device key for the source device instance, and retrieve its
  175. // "SymbolicName" value.
  176. //
  177. hDeviceKey = SetupDiOpenDevRegKey(deviceInfoSet,
  178. deviceInfoData,
  179. DICS_FLAG_GLOBAL,
  180. 0,
  181. DIREG_DEV,
  182. KEY_ALL_ACCESS);
  183. if (INVALID_HANDLE_VALUE == hDeviceKey) {
  184. goto GetDeviceNameError;
  185. }
  186. dwBufferSize = sizeof(szBuffer);
  187. dwError = RegQueryValueEx(hDeviceKey,
  188. _T("SymbolicName"),
  189. NULL,
  190. NULL,
  191. (PBYTE)szBuffer,
  192. &dwBufferSize);
  193. if(ERROR_SUCCESS != dwError) {
  194. goto GetDeviceNameError;
  195. }
  196. deviceName = szBuffer;
  197. RegCloseKey(hDeviceKey);
  198. return TRUE;
  199. GetDeviceNameError:
  200. if (hDeviceKey != INVALID_HANDLE_VALUE) {
  201. RegCloseKey(hDeviceKey);
  202. }
  203. return FALSE;
  204. }
  205. void
  206. UsbPropertyPage::DisplayPPSelectedListItem(HWND main, HWND hList)
  207. {
  208. LVITEM item;
  209. BOOL b;
  210. int itemIndex = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
  211. ZeroMemory(&item, sizeof(LVITEM));
  212. item.mask = LVIF_PARAM;
  213. item.iItem = itemIndex;
  214. b = ListView_GetItem(hList, &item);
  215. if (!b) {
  216. return;
  217. }
  218. ShowPropertyPage(main, (UsbItem*) item.lParam);
  219. }
  220. void
  221. UsbPropertyPage::DisplayPPSelectedTreeItem(HWND main, HWND hList)
  222. {
  223. TVITEM item;
  224. BOOL b;
  225. ZeroMemory(&item, sizeof(TVITEM));
  226. if (NULL == (item.hItem = TreeView_GetSelection(hList))) {
  227. return;
  228. }
  229. item.mask = TVIF_PARAM;
  230. b = TreeView_GetItem(hList, &item);
  231. if (!b) {
  232. return;
  233. }
  234. ShowPropertyPage(main, (UsbItem*) item.lParam);
  235. }
  236. #ifdef WINNT
  237. typedef USBINT_PTR (FAR *DeviceProp)(HWND, LPCTSTR, LPCTSTR, BOOL);
  238. void
  239. UsbPropertyPage::ShowPropertyPage(HWND parent, UsbItem *usbItem)
  240. {
  241. HINSTANCE h;
  242. DeviceProp p;
  243. TCHAR buf[MAX_PATH];
  244. if (usbItem != NULL) {
  245. CM_Get_Device_ID(usbItem->configInfo->devInst,
  246. buf,
  247. MAX_PATH,
  248. NULL);
  249. h = LoadLibrary(TEXT("devmgr.dll"));
  250. if (h) {
  251. p = (DeviceProp) GetProcAddress(h, "DevicePropertiesW");
  252. if (p) {
  253. p (parent, NULL, buf, FALSE);
  254. }
  255. FreeLibrary(h);
  256. }
  257. }
  258. }
  259. #else
  260. void
  261. UsbPropertyPage::ShowPropertyPage(HWND HWndParent, UsbItem *usbItem)
  262. {
  263. CHAR buf[MAX_PATH];
  264. ULONG len = MAX_PATH;
  265. CONFIGRET cfgRet;
  266. HKEY hDevKey;
  267. if (usbItem != NULL) {
  268. if (CR_SUCCESS != (cfgRet =
  269. CM_Open_DevNode_Key(usbItem->configInfo->devInst,
  270. KEY_QUERY_VALUE,
  271. CM_REGISTRY_HARDWARE,
  272. RegDisposition_OpenExisting,
  273. &hDevKey,
  274. 0))) {
  275. return;
  276. }
  277. len = MAX_PATH;
  278. if (ERROR_SUCCESS != RegQueryValueEx(hDevKey,
  279. _T("SymbolicName"),
  280. NULL,
  281. NULL,
  282. (LPBYTE) &buf,
  283. &len)) {
  284. RegCloseKey(hDevKey);
  285. return;
  286. }
  287. if (usbItem->itemType == UsbItem::UsbItemType::HCD) {
  288. BandwidthPage *band;
  289. band = new BandwidthPage(HWndParent, buf);
  290. AddChunk(band);
  291. if (!band) {
  292. return;
  293. }
  294. band->CreateIndependent();
  295. DeleteChunk(band);
  296. delete band;
  297. } else if (usbItem->itemType == UsbItem::UsbItemType::RootHub ||
  298. usbItem->itemType == UsbItem::UsbItemType::Hub) {
  299. PowerPage *power;
  300. power = new PowerPage(HWndParent, buf);
  301. AddChunk(power);
  302. if (!power) {
  303. return;
  304. }
  305. power->CreateIndependent();
  306. DeleteChunk(power);
  307. delete power;
  308. } /*else {
  309. GenericPage *generic;
  310. generic = new GenericPage(HWndParent, buf);
  311. AddChunk(generic);
  312. if (!generic) {
  313. return;
  314. }
  315. generic->CreateIndependent();
  316. DeleteChunk(generic);
  317. delete generic;
  318. } */
  319. }
  320. }
  321. #endif
  322. VOID
  323. UsbPropertyPage::CreateAsChild(HWND HWndParent,
  324. HWND hCreateOn,
  325. UsbItem *item)
  326. {
  327. RECT rc;
  328. POINT *p = (POINT*) &rc;
  329. GetWindowRect(hCreateOn, &rc);
  330. ScreenToClient(HWndParent, p++);
  331. ScreenToClient(HWndParent, p);
  332. if (NULL != (hwnd = CreateDialogParam(gHInst,
  333. MAKEINTRESOURCE(dlgResource),
  334. HWndParent,
  335. AppletDialogProc,
  336. (LPARAM) this))) {
  337. SetWindowPos(hwnd,
  338. hCreateOn,
  339. rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
  340. SWP_SHOWWINDOW);
  341. }
  342. }
  343. VOID
  344. UsbPropertyPage::CreateIndependent()
  345. {
  346. int error;
  347. if (-1 == DialogBoxParam(gHInst,
  348. MAKEINTRESOURCE(dlgResource),
  349. hWndParent,
  350. AppletDialogProc,
  351. (LPARAM) this)) {
  352. error = GetLastError();
  353. }
  354. }
  355. BOOL UsbPropertyPage::DestroyChild()
  356. {
  357. if (hwnd) {
  358. return DestroyWindow(hwnd);
  359. }
  360. //
  361. // If there's nothing to destroy, then in a way we've been successful
  362. //
  363. return TRUE;
  364. }
  365. USBINT_PTR APIENTRY UsbPropertyPage::AppletDialogProc(IN HWND hDlg,
  366. IN UINT uMessage,
  367. IN WPARAM wParam,
  368. IN LPARAM lParam)
  369. {
  370. UsbPropertyPage *that;
  371. switch (uMessage) {
  372. case WM_INITDIALOG:
  373. that = (UsbPropertyPage *) lParam;
  374. UsbSetWindowLongPtr(hDlg, USBDWLP_USER, (USBLONG_PTR) that);
  375. that->hwnd = hDlg;
  376. return that->OnInitDialog();
  377. default:
  378. break;
  379. }
  380. return StaticDialogProc(hDlg, uMessage, wParam, lParam);
  381. }