Leaked source code of windows server 2003
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.

625 lines
19 KiB

  1. /*-------------------------------------------------------------------
  2. | dripick.c - Driver Device Pick(main screen).
  3. |--------------------------------------------------------------------*/
  4. #include "precomp.h"
  5. static BOOL FAR PASCAL on_command(HWND hDlg, UINT message,
  6. WPARAM wParam, LPARAM lParam);
  7. static int setup_buttons(HWND hDlg);
  8. static void set_main_dlg_info(HWND hDlg);
  9. static int do_tv_notify(HWND hDlg, UINT message,
  10. WPARAM wParam, LPARAM lParam);
  11. HIMAGELIST hTreeImage = NULL;
  12. HBITMAP hbmBoard;
  13. HBITMAP hbmPort;
  14. HBITMAP hbmBoardMask;
  15. HBITMAP hbmPortMask;
  16. /*----------------------------------------------------------
  17. DevicePickSheet - Dlg window procedure for add on Advanced sheet.
  18. |-------------------------------------------------------------*/
  19. BOOL WINAPI DevicePickSheet(
  20. IN HWND hDlg,
  21. IN UINT uMessage,
  22. IN WPARAM wParam,
  23. IN LPARAM lParam)
  24. {
  25. OUR_INFO * OurProps = (OUR_INFO *)GetWindowLong(hDlg, DWL_USER);
  26. UINT stat;
  27. static int first_time = 1;
  28. Port_Config *ps;
  29. switch(uMessage)
  30. {
  31. case WM_INITDIALOG :
  32. OurProps = (OUR_INFO *)((LPPROPSHEETPAGE)lParam)->lParam;
  33. SetWindowLong(hDlg, DWL_USER, (LONG)OurProps);
  34. DbgPrintf(D_Init, ("Dripick:Init 9\n"))
  35. if (glob_hwnd == NULL)
  36. glob_hwnd = hDlg;
  37. if (wi->NumDevices == 0)
  38. {
  39. EnableWindow(GetDlgItem(hDlg, IDB_REMOVE),0);
  40. EnableWindow(GetDlgItem(hDlg, IDB_PROPERTIES),0);
  41. }
  42. set_main_dlg_info(hDlg);
  43. SetFocus(GetDlgItem(hDlg, IDC_LBOX_DEVICE));
  44. #if (defined(NT50))
  45. // if nt50 then get rid of <add> and <remove>
  46. // buttons
  47. ShowWindow(GetDlgItem(hDlg, IDB_ADD), SW_HIDE);
  48. ShowWindow(GetDlgItem(hDlg, IDB_REMOVE), SW_HIDE);
  49. #endif
  50. return TRUE; // No need for us to set the focus.
  51. case PSM_QUERYSIBLINGS :
  52. {
  53. switch (HIWORD(wParam))
  54. {
  55. case QUERYSIB_GET_OUR_PROPS :
  56. // grab updated info from controls(don't have any)
  57. SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
  58. return TRUE;
  59. break;
  60. default :
  61. return FALSE;
  62. }
  63. }
  64. case WM_COMMAND :
  65. on_command(hDlg, uMessage, wParam, lParam);
  66. return FALSE;
  67. case WM_PAINT:
  68. if (first_time)
  69. {
  70. first_time = 0;
  71. if (wi->NumDevices == 0) // bring up wizard
  72. {
  73. PostMessage(hDlg, WM_COMMAND, IDB_ADD, 0); // bring up add wiz
  74. }
  75. #if (defined(NT50) && defined(S_VS))
  76. // they need to configure the mac-address...
  77. if (mac_match(wi->dev[0].MacAddr, mac_zero_addr))
  78. PostMessage(hDlg, WM_COMMAND, IDB_PROPERTIES, 0); // bring up VS device sheet
  79. #endif
  80. }
  81. return FALSE;
  82. case WM_HELP:
  83. our_context_help(lParam);
  84. return FALSE;
  85. case WM_NOTIFY :
  86. switch (((NMHDR *)lParam)->code)
  87. {
  88. //case TVN_STARTLABELEDIT: no such thing
  89. // DgbPrint(D_Test, ("start label edit"))
  90. //return FALSE;
  91. case TVN_ENDLABELEDIT:
  92. {
  93. TV_ITEM *item;
  94. item = &((TV_DISPINFO *)lParam)->item;
  95. // 80H bit used to mark tree item as a Device(not port)
  96. glob_info->device_selected = (item->lParam & 0x7f);
  97. glob_info->port_selected = (item->lParam >> 8);
  98. if (item->lParam & 0x80) // a board is selected
  99. glob_info->selected = BOARD_SELECTED;
  100. else glob_info->selected = PORT_SELECTED;
  101. if (item->pszText != NULL)
  102. {
  103. int bad_label = 0;
  104. // on a board(we should trap start-of-edit!)
  105. if (glob_info->selected == BOARD_SELECTED)
  106. {
  107. if (strlen(item->pszText) > 59) // limit to 59 chars
  108. item->pszText[60] = 0;
  109. strcpy(wi->dev[glob_info->device_selected].Name, item->pszText);
  110. DbgPrintf(D_Error,(TEXT("device label:%s\n"), item->pszText));
  111. }
  112. else
  113. {
  114. // copy over new name
  115. if ((strlen(item->pszText) > 10) ||
  116. (strlen(item->pszText) == 0))
  117. {
  118. bad_label = 1; // don't keep the text, to long
  119. }
  120. _tcsupr(item->pszText);
  121. if (_tcsncmp(item->pszText, "COM", 3) != 0)
  122. bad_label = 2;
  123. else if (strlen(item->pszText) < 4)
  124. bad_label = 3;
  125. else if (!isdigit(item->pszText[3]))
  126. bad_label = 4;
  127. if (bad_label)
  128. {
  129. DbgPrintf(D_Error, (TEXT("Bad COM name, err%d"), bad_label))
  130. stat = our_message(&wi->ip,RcStr((MSGSTR+2)),MB_OK);
  131. return 0; // don't keep the text, to long
  132. }
  133. ps = &wi->dev[glob_info->device_selected].ports[glob_info->port_selected];
  134. strcpy(ps->Name, item->pszText);
  135. #if 0
  136. validate_port_name(ps, 1); // if not valid, make it so
  137. DbgPrintf(D_Error,(TEXT("port label:%s\n"), item->pszText));
  138. if (wi->dev[glob_info->device_selected].NumPorts >
  139. (glob_info->port_selected+1))
  140. {
  141. set_main_dlg_info(hDlg);
  142. stat = our_message(&wi->ip,
  143. "Rename in ascending order all remaining ports on this device?",MB_YESNO);
  144. if (stat == IDYES)
  145. {
  146. rename_ascending(glob_info->device_selected,
  147. glob_info->port_selected);
  148. }
  149. }
  150. #endif
  151. }
  152. set_main_dlg_info(hDlg);
  153. return 1; // keep the text
  154. }
  155. }
  156. break;
  157. case TVN_SELCHANGED :
  158. {
  159. // selection change in the tree view, update buttons accordingly
  160. NM_TREEVIEW *nmtv;
  161. TV_ITEM *item;
  162. nmtv = (NM_TREEVIEW *) lParam;
  163. item = &nmtv->itemNew;
  164. // 80H bit used to mark tree item as a Device(not port)
  165. glob_info->device_selected = (item->lParam & 0x7f);
  166. glob_info->port_selected = (item->lParam >> 8);
  167. if (item->lParam & 0x80) // a board is selected
  168. glob_info->selected = BOARD_SELECTED;
  169. else glob_info->selected = PORT_SELECTED;
  170. setup_buttons(hDlg);
  171. }
  172. break;
  173. case PSN_HELP :
  174. our_help(&wi->ip, IDD_MAIN_DLG);
  175. break;
  176. case PSN_QUERYCANCEL :
  177. // request that the other sheets gather up any changes.
  178. PropSheet_QuerySiblings(GetParent(hDlg),
  179. (WPARAM) (QUERYSIB_GET_OUR_PROPS << 16),
  180. 0);
  181. if (allow_exit(1)) // request cancel
  182. {
  183. // the DWL_MSGRESULT field must be *FALSE* to tell QueryCancel
  184. // that an exit is acceptable. The function result must be
  185. // *TRUE* to acknowledge that we handled the message.
  186. SetWindowLong(hDlg, DWL_MSGRESULT, FALSE); // allow cancel
  187. return TRUE;
  188. }
  189. else
  190. {
  191. // the DWL_MSGRESULT field must be *TRUE* to tell QueryCancel
  192. // that we don't want an exit. The function result must be
  193. // *TRUE* to acknowledge that we handled the message.
  194. SetWindowLong(hDlg, DWL_MSGRESULT, TRUE); // don't allow cancel
  195. return TRUE;
  196. }
  197. break;
  198. case PSN_APPLY :
  199. // request that the other sheets gather up any changes.
  200. PropSheet_QuerySiblings(GetParent(hDlg),
  201. (WPARAM) (QUERYSIB_GET_OUR_PROPS << 16),
  202. 0);
  203. if (!wi->DriverExitDone)
  204. {
  205. // now see if anything changed that needs saving
  206. if (allow_exit(0)) // request ok to save and exit
  207. {
  208. wi->DriverExitDone = 1; // prevents other pages doing this
  209. // do the install/save of config params if not canceling..
  210. #ifdef NT50
  211. our_nt50_exit(); // ok, quit
  212. #else
  213. our_exit(); // nt40 exit
  214. #endif
  215. SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
  216. //wi->SaveOnExit = 1;
  217. }
  218. else
  219. {
  220. SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  221. }
  222. }
  223. return TRUE;
  224. default :
  225. return FALSE;
  226. }
  227. default :
  228. return FALSE;
  229. }
  230. }
  231. #define YBITMAP 16
  232. #define XBITMAP 16
  233. //#define XBITMAP 24
  234. /*-------------------------------------------------------------------
  235. | set_main_dlg_info - Run to setup the various field selections.
  236. ran at start and when any changes are made. Smart IO-selections
  237. which exclude themselves from double choose.
  238. |--------------------------------------------------------------------*/
  239. static void set_main_dlg_info(HWND hDlg)
  240. {
  241. int i,j,bd;
  242. HWND hwnd;
  243. char tmpstr[80];
  244. Device_Config *dev;
  245. int first_time = 0;
  246. int dev_select = glob_info->device_selected;
  247. int port_select = glob_info->port_selected;
  248. int selected = glob_info->selected;
  249. //------------------ fill in the device selection window
  250. hwnd = GetDlgItem(hDlg, IDC_LBOX_DEVICE);
  251. {
  252. TV_ITEM tvItem;
  253. HTREEITEM tvSelectHandle;
  254. TV_INSERTSTRUCT tvIns;
  255. if (hTreeImage == NULL)
  256. {
  257. hTreeImage = ImageList_Create(XBITMAP,YBITMAP, TRUE, 2, 2);
  258. #ifdef S_VS
  259. i = ImageList_AddMasked (hTreeImage, LoadBitmap(glob_hinst,
  260. // MAKEINTRESOURCE(BMP_VS_BOX)), RGB(128,128,128));
  261. MAKEINTRESOURCE(BMP_VS_BOX)), RGB(255,255,255));
  262. #else
  263. i = ImageList_AddMasked (hTreeImage, LoadBitmap(glob_hinst,
  264. MAKEINTRESOURCE(BMP_BOARDS)), RGB(0,128,128));
  265. #endif
  266. ImageList_AddMasked (hTreeImage, LoadBitmap(glob_hinst,
  267. MAKEINTRESOURCE(BMP_PORTSM)), RGB(0,128,128));
  268. glob_info->device_selected = 0;
  269. glob_info->port_selected = 0;
  270. glob_info->selected = BOARD_SELECTED;
  271. dev_select = glob_info->device_selected;
  272. port_select = glob_info->port_selected;
  273. selected = glob_info->selected;
  274. first_time = 1;
  275. }
  276. TreeView_DeleteAllItems(hwnd);
  277. TreeView_SetImageList(hwnd, hTreeImage, TVSIL_NORMAL);
  278. for (bd=0; bd< wi->NumDevices; bd++)
  279. {
  280. dev = &wi->dev[bd];
  281. tvItem.pszText = dev->Name;
  282. tvItem.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
  283. tvItem.iImage = 0;
  284. tvItem.iSelectedImage = 0;
  285. tvItem.lParam = bd | 0x80;
  286. tvIns.hParent = TVGN_ROOT;
  287. tvIns.hInsertAfter = TVGN_ROOT;
  288. tvIns.item = tvItem;
  289. // And insert the item, returning its handle
  290. dev->tvHandle = TreeView_InsertItem ( hwnd, &tvIns );
  291. if ((selected == BOARD_SELECTED) && (dev_select == bd))
  292. tvSelectHandle = dev->tvHandle;
  293. if (tvSelectHandle == NULL) // make sure it selects something
  294. tvSelectHandle = dev->tvHandle;
  295. for (j=0; j< wi->dev[bd].NumPorts; j++)
  296. {
  297. #ifdef INDEXED_PORT_NAMES
  298. // generate the port name based on StartComIndex
  299. wsprintf(dev->ports[j].Name, "COM%d", dev->StartComIndex + j);
  300. #endif
  301. tvItem.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
  302. tvItem.iImage = 1;
  303. tvItem.iSelectedImage = 1;
  304. tvItem.pszText = dev->ports[j].Name;
  305. tvItem.lParam = bd | (j<<8);
  306. // Fill out the TV_INSERTSTRUCT
  307. tvIns.hInsertAfter = NULL;
  308. tvIns.hParent = dev->tvHandle;
  309. tvIns.item = tvItem;
  310. // And insert the item, returning its handle
  311. dev->ports[j].tvHandle = TreeView_InsertItem ( hwnd, &tvIns );
  312. if ((selected == PORT_SELECTED) && (port_select == j) &&
  313. (dev_select == bd))
  314. tvSelectHandle = dev->ports[j].tvHandle;
  315. }
  316. }
  317. // make sure all devices are expanded, showing their ports.
  318. for (bd=0; bd< wi->NumDevices; bd++)
  319. {
  320. dev = &wi->dev[bd];
  321. TreeView_Expand ( hwnd, dev->tvHandle, TVE_EXPAND);
  322. }
  323. if (wi->NumDevices > 0)
  324. {
  325. if (!first_time)
  326. TreeView_SelectItem(hwnd, tvSelectHandle);
  327. }
  328. }
  329. setup_buttons(hwnd);
  330. }
  331. /*-----------------------------------------------------------------------------
  332. | on_command -
  333. |-----------------------------------------------------------------------------*/
  334. BOOL FAR PASCAL on_command(HWND hDlg, UINT message,
  335. WPARAM wParam, LPARAM lParam)
  336. {
  337. WORD uCmd;
  338. int i,j, stat;
  339. #ifdef WIN32
  340. uCmd = HIWORD(wParam);
  341. #else
  342. uCmd = HIWORD(lParam);
  343. #endif
  344. switch (LOWORD(wParam))
  345. {
  346. case IDC_LBOX_DEVICE:
  347. if (uCmd == CBN_DBLCLK)
  348. {
  349. // this doesn't work
  350. if (glob_info->selected == BOARD_SELECTED)
  351. DoDevicePropPages(hDlg);
  352. else DoPortPropPages(hDlg, glob_info->device_selected, glob_info->port_selected);
  353. break;
  354. }
  355. //if (uCmd != CBN_SELCHANGE) break;
  356. break;
  357. // for nt50 we don't have a remove or add button
  358. #if ( (!defined(NT50)) )
  359. case IDB_REMOVE:
  360. if (wi->NumDevices < 1)
  361. {
  362. MessageBox(hDlg,"Use the Network Control Panel applet to remove this software.",
  363. "Error",MB_OK|MB_ICONSTOP);
  364. break;
  365. }
  366. #ifdef S_RK
  367. // force them to remove ISA boards in order
  368. i = glob_info->device_selected;
  369. if (wi->dev[i].IoAddress >= 0x100) // isa board
  370. {
  371. ++i;
  372. for (; i<wi->NumDevices; i++)
  373. {
  374. if (wi->dev[i].IoAddress >= 0x100) // isa board
  375. {
  376. MessageBox(hDlg,"You have to remove the last ISA board in the list first.",
  377. "Error",MB_OK|MB_ICONSTOP);
  378. i = 100; // don't let them remove
  379. }
  380. }
  381. if (i>=100) // don't let them remove
  382. break;
  383. }
  384. #endif
  385. // delete the device node
  386. j = 0;
  387. for (i=0; i<wi->NumDevices; i++)
  388. {
  389. if (i != glob_info->device_selected)
  390. {
  391. if (i != j)
  392. memcpy(&wi->dev[j], &wi->dev[i], sizeof(Device_Config));
  393. ++j;
  394. }
  395. }
  396. if (wi->NumDevices > 0)
  397. --wi->NumDevices;
  398. if (glob_info->device_selected > 0)
  399. --glob_info->device_selected;
  400. glob_info->selected = BOARD_SELECTED;
  401. if (wi->NumDevices == 0)
  402. {
  403. EnableWindow(GetDlgItem(hDlg, IDB_REMOVE),0);
  404. EnableWindow(GetDlgItem(hDlg, IDB_PROPERTIES),0);
  405. }
  406. set_main_dlg_info(hDlg);
  407. break;
  408. case IDB_ADD:
  409. {
  410. Device_Config *dev;
  411. /////////char tmpstr[80];
  412. if (wi->NumDevices == MAX_NUM_DEVICES)
  413. {
  414. wi->NumDevices = MAX_NUM_DEVICES;
  415. our_message(&wi->ip,RcStr((MSGSTR+3)),MB_OK);
  416. break; // bail
  417. }
  418. dev = &wi->dev[wi->NumDevices];
  419. glob_info->device_selected = wi->NumDevices; // point to new one
  420. // clear out all ports config
  421. memset(dev->ports, 0, sizeof(Port_Config) * MAX_NUM_PORTS_PER_DEVICE); // clear our structure
  422. ++wi->NumDevices;
  423. stat = DoAddWizPropPages(hDlg); // add wizard sheet
  424. if (stat != 0) // they canceled or didn't finish
  425. {
  426. if (wi->NumDevices > 0) // error, so remove
  427. --wi->NumDevices;
  428. break; // cancelled, so bail
  429. }
  430. if (wi->NumDevices == 0) // shouldn't happen, but just in case
  431. break;
  432. if (glob_info->device_selected >= wi->NumDevices)
  433. glob_info->device_selected = wi->NumDevices - 1;
  434. // transfer the data from the wizard buffer to the new device buffer
  435. strncpy(dev->ModelName, glob_add_wiz->BoardType, sizeof(dev->ModelName));
  436. dev->ModemDevice = glob_add_wiz->IsModemDev;
  437. wi->ModemCountry = glob_add_wiz->CountryCode;
  438. dev->NumPorts = glob_add_wiz->NumPorts;
  439. #ifdef S_RK
  440. dev->IoAddress = glob_add_wiz->IoAddress;
  441. if (!glob_add_wiz->IsIsa)
  442. dev->IoAddress = 1;
  443. wsprintf(dev->Name, "Rocket #%d", wi->NumDevices);
  444. #else
  445. dev->HubDevice = glob_add_wiz->IsHub;
  446. dev->BackupServer = glob_add_wiz->BackupServer;
  447. dev->BackupTimer = glob_add_wiz->BackupTimer;
  448. memcpy(&dev->MacAddr, &glob_add_wiz->MacAddr, sizeof(dev->MacAddr));
  449. if (dev->HubDevice)
  450. wsprintf(dev->Name, "Rocket Serial Hub #%d", wi->NumDevices);
  451. else if (dev->ModemDevice)
  452. wsprintf(dev->Name, "VS2000 #%d", wi->NumDevices);
  453. else
  454. wsprintf(dev->Name, "VS1000 #%d", wi->NumDevices);
  455. #endif
  456. {
  457. char tmpstr[20];
  458. // pick com-port names
  459. FormANewComPortName(tmpstr, NULL);
  460. for (i=0; i<dev->NumPorts; i++)
  461. {
  462. strcpy(dev->ports[i].Name, tmpstr);
  463. BumpPortName(tmpstr);
  464. }
  465. }
  466. //validate_device(dev, 1);
  467. if (dev->ModemDevice)
  468. {
  469. // lets turn on the RING emulation option on the ports
  470. for (i=0; i<dev->NumPorts; i++)
  471. dev->ports[i].RingEmulate = 1;
  472. }
  473. // now show it.
  474. if (DoDevicePropPages(hDlg) != 0) // if they cancel out
  475. {
  476. if (wi->NumDevices > 0) // error, so remove
  477. --wi->NumDevices;
  478. }
  479. if (wi->NumDevices != 0)
  480. {
  481. EnableWindow(GetDlgItem(hDlg, IDB_REMOVE),1);
  482. EnableWindow(GetDlgItem(hDlg, IDB_PROPERTIES),1);
  483. }
  484. set_main_dlg_info(hDlg);
  485. }
  486. break;
  487. #endif
  488. case IDB_PROPERTIES:
  489. if (wi->NumDevices == 0)
  490. break;
  491. if (glob_info->device_selected >= wi->NumDevices)
  492. glob_info->device_selected = wi->NumDevices - 1;
  493. if (glob_info->selected == BOARD_SELECTED)
  494. DoDevicePropPages(hDlg);
  495. else
  496. DoPortPropPages(hDlg, glob_info->device_selected, glob_info->port_selected);
  497. set_main_dlg_info(hDlg);
  498. SetFocus(GetDlgItem(hDlg, IDC_LBOX_DEVICE));
  499. break;
  500. }
  501. return TRUE;
  502. }
  503. /*---------------------------------------------------------------------------
  504. setup_buttons - Enable or Disable buttons depending on circumstances.
  505. |---------------------------------------------------------------------------*/
  506. static int setup_buttons(HWND hDlg)
  507. {
  508. if (glob_info->selected == BOARD_SELECTED) // on a board
  509. {
  510. EnableWindow(GetDlgItem(hDlg, IDB_PROPERTIES),1);
  511. EnableWindow(GetDlgItem(hDlg, IDB_REMOVE),1); // enable remove
  512. if (wi->NumDevices < MAX_NUM_DEVICES)
  513. EnableWindow(GetDlgItem(hDlg, IDB_ADD),1);
  514. else EnableWindow(GetDlgItem(hDlg, IDB_ADD),0);
  515. }
  516. else // on a port
  517. {
  518. EnableWindow(GetDlgItem(hDlg, IDB_PROPERTIES),1);
  519. EnableWindow(GetDlgItem(hDlg, IDB_REMOVE),0); // disable remove
  520. EnableWindow(GetDlgItem(hDlg, IDB_ADD),0); // disable add
  521. }
  522. if (wi->NumDevices == 0) // special case
  523. {
  524. EnableWindow(GetDlgItem(hDlg, IDB_REMOVE),0);
  525. EnableWindow(GetDlgItem(hDlg, IDB_PROPERTIES),0);
  526. EnableWindow(GetDlgItem(hDlg, IDB_ADD),1); // enable add
  527. }
  528. return 0;
  529. }