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.

577 lines
18 KiB

  1. /****************************************************************************
  2. *
  3. * Microsoft Confidential
  4. * Copyright (c) Microsoft Corporation 1994
  5. * All rights reserved
  6. *
  7. ***************************************************************************/
  8. #ifdef UNIX_FEATURE_ALIAS
  9. #undef UNICODE
  10. #include "inetcplp.h"
  11. #include "shalias.h"
  12. #include "mluisupp.h"
  13. STDAPI RefreshGlobalAliasList();
  14. #define GETALIASLIST(hDlg) ((LPALIASINFO )GetWindowLong(hDlg, DWL_USER))->aliasList
  15. #define GETALIASDELLIST(hDlg) ((LPALIASINFO )GetWindowLong(hDlg, DWL_USER))->aliasDelList
  16. BOOL CALLBACK AlEditDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  17. VOID WINAPI InitAliasListStyle(HWND hwndLV, DWORD dwView);
  18. static TCHAR g_szAliasKey[] = TEXT("Software\\Microsoft\\Internet Explorer\\Unix\\Alias");
  19. // InitListViewImageLists - creates image lists for a list view.
  20. // Returns TRUE if successful, or FALSE otherwise.
  21. // hwndLV - handle to the list view control.
  22. BOOL WINAPI InitAliasListImageLists(HWND hwndLV)
  23. {
  24. HICON hiconItem; // icon for list view items
  25. HIMAGELIST himlLarge; // image list for icon view
  26. HIMAGELIST himlSmall; // image list for other views
  27. // Create the full-sized and small icon image lists.
  28. himlLarge = ImageList_Create(GetSystemMetrics(SM_CXICON),
  29. GetSystemMetrics(SM_CYICON), TRUE, 1, 1);
  30. himlSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
  31. GetSystemMetrics(SM_CYSMICON), TRUE, 1, 1);
  32. // Add an icon to each image list.
  33. // note that IDI_WALLET has to live in inetcplc.rc because
  34. // it's used by a localizable dialog, hence the MLGetHinst()
  35. hiconItem = LoadIcon(MLGetHinst(), MAKEINTRESOURCE(IDI_WALLET));
  36. ImageList_AddIcon(himlLarge, hiconItem);
  37. ImageList_AddIcon(himlSmall, hiconItem);
  38. DeleteObject(hiconItem);
  39. // Assign the image lists to the list view control.
  40. ListView_SetImageList(hwndLV, himlLarge, LVSIL_NORMAL);
  41. ListView_SetImageList(hwndLV, himlSmall, LVSIL_SMALL);
  42. return TRUE;
  43. }
  44. // InitListViewItems - adds items and subitems to a list view.
  45. // Returns TRUE if successful, or FALSE otherwise.
  46. // hwndLV - handle to the list view control.
  47. // pfData - text file containing list view items with columns
  48. // separated by semicolons.
  49. BOOL WINAPI InitAliasListItems(HWND hwndLV, HDPA aliasList)
  50. {
  51. PSTR pszEnd;
  52. int iItem;
  53. int iSubItem;
  54. LVITEM lvi;
  55. // Initialize LVITEM members that are common to all items.
  56. lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  57. lvi.state = 0; lvi.stateMask = 0;
  58. lvi.pszText = LPSTR_TEXTCALLBACK; // app. maintains text
  59. lvi.iImage = 0; // image list index
  60. int aliasCount = DPA_GetPtrCount( aliasList );
  61. for (int i = 0; i< aliasCount; i++)
  62. {
  63. CAlias * ptr = (CAlias *)DPA_FastGetPtr( aliasList, i );
  64. // Initialize item-specific LVITEM members.
  65. lvi.iItem = i;
  66. lvi.iSubItem = 0;
  67. lvi.lParam = (LPARAM) NULL; // item data
  68. // Add the item.
  69. ListView_InsertItem(hwndLV, &lvi);
  70. // Initialize item-specific LVITEM members.
  71. ListView_SetItemText(hwndLV, i, 0, (TCHAR*)GetAliasName(ptr));
  72. ListView_SetItemText(hwndLV, i, 1, (TCHAR*)GetAliasUrl(ptr));
  73. }
  74. return TRUE;
  75. }
  76. // InitListViewColumns - adds columns to a list view control.
  77. // Returns TRUE if successful, or FALSE otherwise.
  78. // hwndLV - handle to the list view control.
  79. BOOL WINAPI InitAliasListColumns(HWND hwndLV)
  80. {
  81. TCHAR g_achTemp[256]; // temporary buffer
  82. LVCOLUMN lvc;
  83. int iCol;
  84. // Initialize the LVCOLUMN structure.
  85. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  86. lvc.fmt = LVCFMT_LEFT;
  87. lvc.pszText = g_achTemp;
  88. // Add the columns.
  89. for (iCol = 0; iCol < ALIASLIST_COLUMNS; iCol++)
  90. {
  91. lvc.iSubItem = iCol;
  92. lvc.cx = 100 + (iCol*150);
  93. MLLoadString(IDS_FIRSTCOLUMN + iCol,
  94. g_achTemp, sizeof(g_achTemp));
  95. if (ListView_InsertColumn(hwndLV, iCol, &lvc) == -1)
  96. return FALSE;
  97. }
  98. return TRUE;
  99. }
  100. // SetView - sets a list view's window style to change the view.
  101. // hwndLV - handle to the list view control.
  102. // dwView - value specifying a view style.
  103. VOID WINAPI InitAliasListStyle(HWND hwndLV, DWORD dwView)
  104. {
  105. // Get the current window style.
  106. DWORD dwStyle = ListView_GetExtendedListViewStyle(hwndLV);
  107. ListView_SetExtendedListViewStyle( hwndLV, (dwStyle|dwView) );
  108. // SetWindowLong(hwndLV, GWL_EXSTYLE, (dwStyle | dwView));
  109. }
  110. // AliasDel - deletes alias from active list and moves it to the
  111. // del list to be delete later.
  112. // hDlg - handle of the propertysheet dialog.
  113. BOOL WINAPI AliasDel( HWND hDlg )
  114. {
  115. int index = 0, iItem = 0;
  116. HWND lb = GetDlgItem( hDlg, IDC_ALIAS_LIST );
  117. HDPA aliasList = GETALIASLIST(hDlg);
  118. HDPA aliasDelList = GETALIASDELLIST(hDlg);
  119. BOOL fAsked = FALSE;
  120. BOOL fChanged = FALSE;
  121. int count = ListView_GetItemCount(lb);
  122. // Get the selection from the Listview and remove it from the
  123. // active alias list, add it to the aliaslist to be deleted.
  124. while( (iItem = ListView_GetNextItem( lb, -1, LVNI_SELECTED ) ) != -1 )
  125. {
  126. TCHAR str[MAX_URL_STRING]; *str = TEXT('\0');
  127. if( !fAsked )
  128. {
  129. TCHAR question[MAX_PATH];
  130. wsprintf( question, "Are you Sure you want to delete the selected items?");
  131. if( MessageBox( GetParent(hDlg), question, TEXT("Delete Alias"), MB_YESNO ) != IDYES )
  132. return FALSE;
  133. fAsked = TRUE;
  134. }
  135. // if( !ListView_GetCheckState(lb, iItem) ) continue;
  136. ListView_GetItemText(lb, iItem, 0, str, MAX_URL_STRING );
  137. if(*str)
  138. {
  139. if( (index = FindAliasIndex(aliasList, str) ) != -1 )
  140. {
  141. CAlias * ptr = (CAlias *)DPA_FastGetPtr( aliasList, index );
  142. if( ptr )
  143. {
  144. CAlias *pAlias = (CAlias *)DPA_DeletePtr( aliasList, index );
  145. // Add to List of deleted entries
  146. DPA_InsertPtr( aliasDelList, 0x7FFF, pAlias );
  147. ListView_DeleteItem(lb, iItem);
  148. fChanged = TRUE;
  149. LocalFree( str );
  150. }
  151. }
  152. }
  153. }
  154. if( fChanged )
  155. {
  156. InitAliasDialog( hDlg, NULL, FALSE );
  157. PropSheet_Changed(GetParent(hDlg),hDlg);
  158. }
  159. return TRUE;
  160. }
  161. // AliasEdit - Called in response to the Edit button pressed.
  162. // hDlg - Handle to the property sheet
  163. BOOL WINAPI AliasEdit( HWND hDlg )
  164. {
  165. CAlias * ptr = GetCurrentAlias( hDlg );
  166. HDPA aliasDelList = GETALIASDELLIST(hDlg);
  167. if( ptr )
  168. {
  169. CAlias *ptrOld = (CAlias *)CreateAlias( (LPTSTR)GetAliasName(ptr) );
  170. ALIASEDITINFO aliasEditInfo = { GETALIASLIST(hDlg), ptr, hDlg, EDIT_ALIAS };
  171. if(MLDialogBoxParamWrap( MLGetHinst(), MAKEINTRESOURCE(IDD_ALIAS_EDIT), hDlg, AlEditDlgProc, (LPARAM)&aliasEditInfo ) == 2 )
  172. {
  173. // Add old alias to del list if alias name changes.
  174. LPCTSTR aliasNew = GetAliasName(ptr);
  175. LPCTSTR aliasOld = GetAliasName(ptrOld);
  176. if( StrCmp( aliasNew, aliasOld) )
  177. DPA_InsertPtr( aliasDelList, 0x7FFF, ptrOld );
  178. else
  179. DestroyAlias( ptrOld );
  180. InitAliasDialog( hDlg, ptr, FALSE );
  181. PropSheet_Changed(GetParent(hDlg),hDlg);
  182. }
  183. }
  184. return TRUE;
  185. }
  186. // AliasEdit - Called in response to the Add button pressed.
  187. // hDlg - Handle to the property sheet
  188. BOOL WINAPI AliasAdd( HWND hDlg)
  189. {
  190. CAlias * ptr = (CAlias *)CreateAlias( TEXT("") );
  191. if ( ptr )
  192. {
  193. ALIASEDITINFO aliasEditInfo = { GETALIASLIST(hDlg), ptr, hDlg, ADD_ALIAS };
  194. if(MLDialogBoxParamWrap( MLGetHinst(), MAKEINTRESOURCE(IDD_ALIAS_EDIT), hDlg, AlEditDlgProc, (LPARAM)&aliasEditInfo ) == 2)
  195. {
  196. InitAliasDialog( hDlg, ptr, FALSE );
  197. PropSheet_Changed(GetParent(hDlg),hDlg);
  198. }
  199. DestroyAlias(ptr);
  200. }
  201. return TRUE;
  202. }
  203. // GetCurrentAlias - returns currently selected alis from the listview
  204. // Returns - Selected alias
  205. // hDlg - handle to the property sheet.
  206. CAlias * GetCurrentAlias( HWND hDlg )
  207. {
  208. int index = 0, iItem = 0;
  209. HDPA aliasList = GETALIASLIST( hDlg );
  210. HWND lb = GetDlgItem( hDlg, IDC_ALIAS_LIST );
  211. if( ListView_GetSelectedCount(lb) == 1 &&
  212. ( (iItem = ListView_GetNextItem( lb, -1, LVNI_SELECTED ) ) != -1 ) )
  213. {
  214. TCHAR str[MAX_URL_STRING]; *str = TEXT('\0');
  215. ListView_GetItemText(lb, iItem, 0, str, MAX_URL_STRING );
  216. if(*str)
  217. {
  218. if( (index = FindAliasIndex(aliasList, str) ) != -1 )
  219. {
  220. CAlias * ptr = (CAlias *)DPA_FastGetPtr( aliasList, index );
  221. return ptr;
  222. }
  223. }
  224. }
  225. return NULL;
  226. }
  227. // InitAliasDialog - Initalizes the aliases dialog
  228. // Returns - TRUE if succeeded/FALSE if failed.
  229. // hDlg - handle to the property sheet.
  230. // fFullInit - Init listview columns/styles/etc
  231. BOOL FAR PASCAL InitAliasDialog(HWND hDlg, CAlias * current, BOOL fFullInit)
  232. {
  233. HRESULT hr = E_FAIL;
  234. HKEY hKey;
  235. HWND listBox = GetDlgItem( hDlg, IDC_ALIAS_LIST );
  236. TCHAR * displayString;
  237. // Allocate memory for a structure which will hold all the info
  238. // gathered from this page
  239. //
  240. LPALIASINFO pgti = (LPALIASINFO)GetWindowLong(hDlg, DWL_USER);
  241. pgti->fInternalChange = FALSE;
  242. SendMessage( listBox, LVM_DELETEALLITEMS, 0, 0L );
  243. // Initailize ListView
  244. if( fFullInit )
  245. {
  246. SendDlgItemMessage( hDlg, IDC_ALIAS_EDIT, EM_LIMITTEXT, 255, 0 );
  247. SendDlgItemMessage( hDlg, IDC_URL_EDIT, EM_LIMITTEXT, MAX_URL_STRING-1, 0 );
  248. // InitAliasListStyle(listBox, LVS_EX_CHECKBOXES|LVS_EX_FULLROWSELECT );
  249. InitAliasListStyle(listBox, LVS_EX_FULLROWSELECT );
  250. InitAliasListImageLists(listBox);
  251. InitAliasListColumns(listBox);
  252. }
  253. InitAliasListItems(listBox, GETALIASLIST(hDlg));
  254. return TRUE;
  255. }
  256. // AliasApply - This function is called in response to pressing the apply/ok
  257. // button on the property sheet dialog.
  258. void AliasApply(HWND hDlg)
  259. {
  260. HDPA aliasDelList = GETALIASDELLIST(hDlg);
  261. HDPA aliasList = GETALIASLIST(hDlg);
  262. ASSERT(aliasList);
  263. if( aliasDelList )
  264. {
  265. int count = DPA_GetPtrCount( aliasDelList );
  266. for(int i=count-1; i>=0; i--)
  267. {
  268. CAlias * pAlias = (CAlias *)DPA_DeletePtr( aliasDelList, i );
  269. if(pAlias)
  270. {
  271. pAlias->Delete();
  272. DestroyAlias(pAlias);
  273. }
  274. }
  275. }
  276. // Save the currently changed aliases
  277. SaveAliases( aliasList );
  278. // Refresh Global Alias List.
  279. RefreshGlobalAliasList();
  280. }
  281. // AliasDlgProc - Alias PropertySheet dialog Proc
  282. // Returns BOOL
  283. // hDlg - Handle to the property sheet window
  284. // wParam, lParam - Word/Long param
  285. BOOL CALLBACK AliasDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  286. {
  287. // get our tab info structure
  288. LPALIASINFO pgti;
  289. if (uMsg == WM_INITDIALOG)
  290. {
  291. // Allocate memory for a structure which will hold all the info
  292. // gathered from this page
  293. //
  294. LPALIASINFO pgti = (LPALIASINFO)LocalAlloc(LPTR, sizeof(tagALIASINFO));
  295. if (!pgti)
  296. {
  297. EndDialog(hDlg, 0);
  298. return FALSE;
  299. }
  300. pgti->hDlg = hDlg;
  301. pgti->fInternalChange = FALSE;
  302. SetWindowLong(hDlg, DWL_USER, (LPARAM)pgti);
  303. if((pgti->aliasList = DPA_Create(4)) != (HDPA)NULL )
  304. {
  305. pgti->aliasDelList = DPA_Create(4);
  306. LoadAliases( pgti->aliasList );
  307. // Initailize dialog
  308. if( InitAliasDialog(hDlg, NULL, TRUE) )
  309. {
  310. return TRUE;
  311. }
  312. else
  313. {
  314. TCHAR szTitle[MAX_PATH];
  315. MLLoadString(IDS_ERROR_REGISTRY_TITLE, szTitle, sizeof(szTitle));
  316. MessageBox( GetParent(hDlg), TEXT("Cannot read aliases from registry."), szTitle, MB_OK );
  317. return FALSE;
  318. }
  319. }
  320. else
  321. return FALSE;
  322. }
  323. else
  324. pgti = (LPALIASINFO)GetWindowLong(hDlg, DWL_USER);
  325. if (!pgti)
  326. return FALSE;
  327. switch (uMsg)
  328. {
  329. case WM_NOTIFY:
  330. {
  331. NMHDR *lpnm = (NMHDR *) lParam;
  332. switch (lpnm->code)
  333. {
  334. case NM_DBLCLK:
  335. if(lpnm->idFrom == IDC_ALIAS_LIST)
  336. AliasEdit( pgti->hDlg );
  337. break;
  338. case PSN_QUERYCANCEL:
  339. case PSN_KILLACTIVE:
  340. case PSN_RESET:
  341. SetWindowLong( hDlg, DWL_MSGRESULT, FALSE );
  342. return TRUE;
  343. case PSN_APPLY:
  344. AliasApply(hDlg);
  345. break;
  346. }
  347. break;
  348. }
  349. case WM_COMMAND:
  350. {
  351. if(HIWORD(wParam) == BN_CLICKED)
  352. {
  353. switch (LOWORD(wParam))
  354. {
  355. case IDC_ALIAS_ADD:
  356. AliasAdd( pgti->hDlg ); break;
  357. case IDC_ALIAS_EDIT:
  358. AliasEdit( pgti->hDlg ); break;
  359. case IDC_ALIAS_DEL:
  360. AliasDel( pgti->hDlg ); break;
  361. }
  362. }
  363. }
  364. break;
  365. case WM_DESTROY:
  366. // Delete registry information
  367. if( pgti->aliasList )
  368. {
  369. FreeAliases(pgti->aliasList);
  370. DPA_Destroy(pgti->aliasList);
  371. }
  372. if( pgti->aliasDelList )
  373. {
  374. FreeAliases(pgti->aliasDelList);
  375. DPA_Destroy(pgti->aliasDelList);
  376. }
  377. if (pgti)
  378. LocalFree(pgti);
  379. SetWindowLong(hDlg, DWL_USER, (LONG)NULL); // make sure we don't re-enter
  380. break;
  381. }
  382. return FALSE;
  383. }
  384. BOOL CALLBACK AlEditDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  385. {
  386. CAlias * pAlias;
  387. LPALIASEDITINFO pAliasInfo;
  388. if (uMsg == WM_INITDIALOG)
  389. {
  390. TCHAR achTemp[256];
  391. pAliasInfo = (LPALIASEDITINFO)lParam;
  392. pAlias = pAliasInfo->alias;
  393. if( !lParam )
  394. {
  395. EndDialog(hDlg, 0);
  396. return FALSE;
  397. }
  398. SendDlgItemMessage( hDlg, IDC_ALIAS_EDIT, WM_SETTEXT, 0, (LPARAM)GetAliasName(pAlias));
  399. SendDlgItemMessage( hDlg, IDC_URL_EDIT, WM_SETTEXT, 0, (LPARAM)GetAliasUrl(pAlias));
  400. if( pAliasInfo->dwFlags & EDIT_ALIAS )
  401. {
  402. // EnableWindow( GetDlgItem(hDlg, IDC_ALIAS_EDIT ), FALSE );
  403. MLLoadString(IDS_TITLE_ALIASEDIT,
  404. achTemp, sizeof(achTemp));
  405. SendMessage( hDlg, WM_SETTEXT, 0, (LPARAM)achTemp);
  406. }
  407. else
  408. {
  409. MLLoadString(IDS_TITLE_ALIASADD,
  410. achTemp, sizeof(achTemp));
  411. SendMessage( hDlg, WM_SETTEXT, 0, (LPARAM)achTemp);
  412. }
  413. SetWindowLong(hDlg, DWL_USER, (LPARAM)pAliasInfo);
  414. EnableWindow( GetDlgItem(hDlg, IDOK), FALSE );
  415. }
  416. else
  417. pAliasInfo = (LPALIASEDITINFO)GetWindowLong(hDlg, DWL_USER);
  418. if (!pAlias)
  419. return FALSE;
  420. switch (uMsg)
  421. {
  422. case WM_COMMAND:
  423. switch (GET_WM_COMMAND_ID(wParam, lParam))
  424. {
  425. case IDC_ALIAS_EDIT:
  426. case IDC_URL_EDIT:
  427. if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_UPDATE)
  428. {
  429. EnableWindow( GetDlgItem(hDlg, IDOK), TRUE );
  430. }
  431. break;
  432. case IDOK:
  433. {
  434. if( pAliasInfo )
  435. {
  436. TCHAR alias[MAX_URL_STRING];
  437. TCHAR szurl[MAX_URL_STRING];
  438. SendDlgItemMessage( hDlg, IDC_ALIAS_EDIT, WM_GETTEXT, MAX_URL_STRING, (LPARAM)alias );
  439. SendDlgItemMessage( hDlg, IDC_URL_EDIT, WM_GETTEXT, MAX_URL_STRING, (LPARAM)szurl );
  440. EatSpaces( alias );
  441. if( !*alias )
  442. {
  443. EndDialog( hDlg, 1 );
  444. break;
  445. }
  446. if( pAliasInfo->dwFlags & ADD_ALIAS && *alias)
  447. {
  448. if(AddAliasToList( pAliasInfo->aliasList, alias, szurl, hDlg ))
  449. EndDialog( hDlg, 2);
  450. }
  451. else if( pAliasInfo->dwFlags & EDIT_ALIAS )
  452. {
  453. CAlias * ptr = pAliasInfo->alias;
  454. if( StrCmp(GetAliasName(ptr), alias) )
  455. if(FindAliasIndex( pAliasInfo->aliasList, alias ) != -1)
  456. {
  457. MessageBox( hDlg,
  458. TEXT("Alias with same name already exists"),
  459. TEXT("Edit Alias"),
  460. MB_OK|MB_ICONSTOP );
  461. break;
  462. }
  463. SetAliasInfo(ptr, alias, szurl);
  464. EndDialog( hDlg, 2);
  465. }
  466. break;
  467. }
  468. else
  469. EndDialog( hDlg, 1 );
  470. break;
  471. }
  472. case IDCANCEL:
  473. {
  474. EndDialog( hDlg, 1 );
  475. }
  476. }
  477. break;
  478. case WM_DESTROY:
  479. SetWindowLong(hDlg, DWL_USER, (LONG)NULL);
  480. break;
  481. }
  482. return FALSE;
  483. }
  484. #endif /* UNIX_FEATURE_ALIAS */