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.

405 lines
11 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // addevice.c
  8. //
  9. // Description:
  10. // This file contains the dialog proc for the add network component pop-up,
  11. // "Select Network Component Type" (IDD_LAN_COMPONENT_ADD).
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "pch.h"
  15. #include "resource.h"
  16. #define NUMBER_OF_TYPES_OF_COMPONENTS 3
  17. //
  18. // prototypes
  19. //
  20. INT_PTR CALLBACK
  21. SelectNetworkClientDlgProc( IN HWND hwnd,
  22. IN UINT uMsg,
  23. IN WPARAM wParam,
  24. IN LPARAM lParam );
  25. INT_PTR CALLBACK
  26. SelectNetworkServiceDlgProc( IN HWND hwnd,
  27. IN UINT uMsg,
  28. IN WPARAM wParam,
  29. IN LPARAM lParam );
  30. INT_PTR CALLBACK
  31. SelectNetworkProtocolDlgProc( IN HWND hwnd,
  32. IN UINT uMsg,
  33. IN WPARAM wParam,
  34. IN LPARAM lParam );
  35. static COMPONENT_TYPE CurrentSelection; // holds the current selection in the list view
  36. static NETWORK_COMPONENT rgListViewAddEntries[NUMBER_OF_TYPES_OF_COMPONENTS];
  37. //----------------------------------------------------------------------------
  38. //
  39. // Function: InitAddListView
  40. //
  41. // Purpose:
  42. //
  43. // Arguments:
  44. //
  45. // Returns:
  46. //
  47. //----------------------------------------------------------------------------
  48. BOOL
  49. InitAddListView( HWND hDlg, HINSTANCE hInst )
  50. {
  51. LV_ITEM lvI; // list view item structure
  52. HICON hIcon1, hIcon2, hIcon3; // handles to icons
  53. HIMAGELIST hSmall; // handle to image list for small icons
  54. HWND hListViewWnd; // handle to list view window
  55. int index;
  56. hListViewWnd = GetDlgItem( hDlg, IDC_LVW_LAN_COMPONENTS );
  57. // Initialize the list view window
  58. // First initialize the image lists you will need:
  59. // create image list for the small icons
  60. hSmall = ImageList_Create(BITMAP_WIDTH, BITMAP_HEIGHT, ILC_MASK, 3, 0 );
  61. // Load the icons and add them to the image list
  62. hIcon1 = LoadIcon(hInst, MAKEINTRESOURCE(IDI_CLIENT));
  63. hIcon2 = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SERVICE));
  64. hIcon3 = LoadIcon(hInst, MAKEINTRESOURCE(IDI_PROTOCOL));
  65. if (ImageList_AddIcon(hSmall, hIcon1) == -1)
  66. return FALSE ;
  67. if (ImageList_AddIcon(hSmall, hIcon2) == -1)
  68. return FALSE ;
  69. if (ImageList_AddIcon(hSmall, hIcon3) == -1)
  70. return FALSE ;
  71. // Be sure that all the icons were added
  72. if (ImageList_GetImageCount(hSmall) < 3)
  73. return FALSE ;
  74. // Associate the image list with the list view control
  75. ListView_SetImageList(hListViewWnd, hSmall, LVSIL_SMALL);
  76. // Finally, add the actual items to the control
  77. // Fill out the LV_ITEM structure for each of the items to add to the list
  78. // The mask specifies the the pszText, iImage, lParam and state
  79. // members of the LV_ITEM structure are valid
  80. lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  81. for (index = 0; index < 3; index++) {
  82. lvI.iItem = index;
  83. lvI.iSubItem = 0;
  84. lvI.iImage = index;
  85. // The parent window is responsible for storing the text
  86. // The list view control will send an LVN_GETDISPINFO
  87. // when it needs the text to display
  88. lvI.pszText = LPSTR_TEXTCALLBACK;
  89. lvI.cchTextMax = MAX_ITEMLEN;
  90. lvI.lParam = (LPARAM)&rgListViewAddEntries[index];
  91. // Select the first item
  92. if (index == 0)
  93. {
  94. lvI.state = lvI.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  95. }
  96. else // leave the others unselected
  97. {
  98. lvI.state = lvI.stateMask = 0;
  99. }
  100. if (ListView_InsertItem(hListViewWnd, &lvI) == -1)
  101. return FALSE ;
  102. }
  103. return( TRUE );
  104. }
  105. //----------------------------------------------------------------------------
  106. //
  107. // Function: OnAddDeviceInitDialog
  108. //
  109. // Purpose:
  110. //
  111. // Arguments: IN HWND hwnd - handle to the dialog
  112. //
  113. // Returns: VOID
  114. //
  115. //----------------------------------------------------------------------------
  116. VOID
  117. OnAddDeviceInitDialog( IN HWND hwnd )
  118. {
  119. //
  120. // Initialize the array for the list view by loading the string
  121. // resources the properties field nor the installed flag is valid
  122. // for this screen so just set it to a value
  123. //
  124. rgListViewAddEntries[0].StrComponentName = MyLoadString( IDS_CLIENT );
  125. rgListViewAddEntries[0].StrComponentDescription = MyLoadString( IDS_CLIENT_DESCRIPTION );
  126. rgListViewAddEntries[0].ComponentType = CLIENT;
  127. rgListViewAddEntries[0].bHasPropertiesTab = FALSE;
  128. rgListViewAddEntries[0].bInstalled = FALSE;
  129. rgListViewAddEntries[1].StrComponentName = MyLoadString( IDS_SERVICE );
  130. rgListViewAddEntries[1].StrComponentDescription = MyLoadString( IDS_SERVICE_DESCRIPTION );
  131. rgListViewAddEntries[1].ComponentType = SERVICE;
  132. rgListViewAddEntries[1].bHasPropertiesTab = FALSE;
  133. rgListViewAddEntries[1].bInstalled = FALSE;
  134. rgListViewAddEntries[2].StrComponentName = MyLoadString( IDS_PROTOCOL );
  135. rgListViewAddEntries[2].StrComponentDescription = MyLoadString( IDS_PROTOCOL_DESCRIPTION );
  136. rgListViewAddEntries[2].ComponentType = PROTOCOL;
  137. rgListViewAddEntries[2].bHasPropertiesTab = FALSE;
  138. rgListViewAddEntries[2].bInstalled = FALSE;
  139. InitAddListView(hwnd, FixedGlobals.hInstance);
  140. CurrentSelection = CLIENT; // initialize the list view to the first one being selected
  141. // TODO: design issue, should there be a default description and if there is, should
  142. // the corresponding list view entry already be selected
  143. // Set the default description
  144. SetWindowText( GetDlgItem( hwnd, IDC_TXT_COMPONENT_DESC ),
  145. rgListViewAddEntries[0].StrComponentDescription);
  146. }
  147. //----------------------------------------------------------------------------
  148. //
  149. // Function: OnAddButtonClicked
  150. //
  151. // Purpose:
  152. //
  153. // Arguments: IN HWND hwnd - handle to the dialog
  154. //
  155. // Returns: VOID
  156. //
  157. //----------------------------------------------------------------------------
  158. static VOID
  159. OnAddButtonClicked( IN HWND hwnd )
  160. {
  161. switch( CurrentSelection ) {
  162. INT_PTR iReturnValue;
  163. //
  164. // for each case it pops-up the appropriate dialog box and then passes
  165. // the return value back to the main LAN wizard page
  166. //
  167. case CLIENT: {
  168. iReturnValue = DialogBox( FixedGlobals.hInstance,
  169. (LPCTSTR)IDD_SELECT_CLIENT,
  170. hwnd,
  171. SelectNetworkClientDlgProc );
  172. EndDialog( hwnd, iReturnValue );
  173. break;
  174. }
  175. case SERVICE: {
  176. iReturnValue = DialogBox( FixedGlobals.hInstance,
  177. (LPCTSTR)IDD_SELECT_SERVICE,
  178. hwnd,
  179. SelectNetworkServiceDlgProc );
  180. EndDialog( hwnd, iReturnValue );
  181. break;
  182. }
  183. case PROTOCOL: {
  184. iReturnValue = DialogBox( FixedGlobals.hInstance,
  185. (LPCTSTR)IDD_SELECT_PROTOCOL,
  186. hwnd,
  187. SelectNetworkProtocolDlgProc );
  188. EndDialog( hwnd, iReturnValue );
  189. break;
  190. }
  191. }
  192. }
  193. //----------------------------------------------------------------------------
  194. //
  195. // Function: NotifyHandler
  196. //
  197. // Purpose:
  198. //
  199. // Arguments: IN HWND hwnd - handle to the dialog
  200. // IN WPARAM wParam -
  201. // IN LPARAM lParam -
  202. //
  203. // Returns: BOOL - whether the message was handled or not
  204. //
  205. //----------------------------------------------------------------------------
  206. static BOOL
  207. NotifyHandler( IN HWND hwnd, IN WPARAM wParam, IN LPARAM lParam )
  208. {
  209. LPNMHDR pnmh = (LPNMHDR)lParam;
  210. LV_DISPINFO *pLvdi = (LV_DISPINFO *)lParam;
  211. NM_LISTVIEW *pNm = (NM_LISTVIEW *)lParam;
  212. NETWORK_COMPONENT *pListViewString = (NETWORK_COMPONENT *)(pLvdi->item.lParam);
  213. HWND hwndComponentDescription;
  214. HWND hButton;
  215. BOOL bStatus = TRUE;
  216. if( wParam == IDC_LVW_LAN_COMPONENTS )
  217. {
  218. switch(pLvdi->hdr.code)
  219. {
  220. case LVN_GETDISPINFO:
  221. pLvdi->item.pszText = pListViewString->StrComponentName;
  222. break;
  223. }
  224. switch(pNm->hdr.code)
  225. {
  226. case LVN_ITEMCHANGED:
  227. if( pNm->uNewState == SELECTED ) // test to see if a new item in the list has been selected
  228. {
  229. CurrentSelection = pNm->iItem;
  230. hwndComponentDescription = GetDlgItem( hwnd, IDC_TXT_COMPONENT_DESC );
  231. SetWindowText( hwndComponentDescription,
  232. rgListViewAddEntries[CurrentSelection].StrComponentDescription );
  233. }
  234. break;
  235. case NM_DBLCLK:
  236. {
  237. NMITEMACTIVATE *pNmItemActivate = (NMITEMACTIVATE *) lParam;
  238. //
  239. // see if the user has double clicked inside the list view
  240. //
  241. if( pNm->hdr.idFrom == IDC_LVW_LAN_COMPONENTS )
  242. {
  243. //
  244. // Make sure they actually clicked on an item and not just
  245. // empty space
  246. //
  247. if( pNmItemActivate->iItem != -1 )
  248. {
  249. OnAddButtonClicked( hwnd );
  250. }
  251. }
  252. break;
  253. }
  254. default:
  255. bStatus = FALSE;
  256. break;
  257. }
  258. }
  259. return( bStatus );
  260. }
  261. //----------------------------------------------------------------------------
  262. //
  263. // Function: AddDeviceDlgProc
  264. //
  265. // Purpose:
  266. //
  267. // Arguments:
  268. //
  269. // Returns:
  270. //
  271. //----------------------------------------------------------------------------
  272. INT_PTR CALLBACK
  273. AddDeviceDlgProc( IN HWND hwnd,
  274. IN UINT uMsg,
  275. IN WPARAM wParam,
  276. IN LPARAM lParam)
  277. {
  278. BOOL bStatus = TRUE;
  279. switch( uMsg ) {
  280. case WM_INITDIALOG: {
  281. OnAddDeviceInitDialog( hwnd );
  282. break;
  283. }
  284. case WM_COMMAND:
  285. {
  286. int nButtonId;
  287. switch ( nButtonId = LOWORD(wParam) ) {
  288. case IDC_PSB_COMPONENT_ADD:
  289. OnAddButtonClicked( hwnd );
  290. break;
  291. case IDCANCEL:
  292. EndDialog(hwnd, 0);
  293. break;
  294. default:
  295. bStatus = FALSE;
  296. break;
  297. }
  298. break;
  299. }
  300. case WM_NOTIFY:
  301. bStatus = NotifyHandler( hwnd, wParam, lParam );
  302. break;
  303. default:
  304. bStatus = FALSE;
  305. break;
  306. }
  307. return( bStatus );
  308. }