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.

652 lines
15 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // iebrowse.c
  8. //
  9. // Description:
  10. // This file contains the dialog procedures for the IE browser settings
  11. // pop-ups.
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "pch.h"
  15. #include "resource.h"
  16. #define MAX_FAVORITE_LEN 1024
  17. static TCHAR *StrFriendlyName;
  18. static TCHAR *StrUrl;
  19. //----------------------------------------------------------------------------
  20. //
  21. // Function: InsertEntryIntoFavorites
  22. //
  23. // Purpose:
  24. //
  25. // Arguments:
  26. //
  27. // Returns: TRUE if the item was added,
  28. // FALSE if it was not
  29. //
  30. //----------------------------------------------------------------------------
  31. static BOOL
  32. InsertEntryIntoFavorites( IN HWND hwnd, TCHAR *pszFriendlyName, TCHAR *pszURL )
  33. {
  34. LVITEM LvItem;
  35. HWND hFavorites;
  36. INT iPosition;
  37. BOOL bSuccess = TRUE;
  38. hFavorites = GetDlgItem( hwnd, IDC_LV_FAVORITES );
  39. iPosition = ListView_GetItemCount( hFavorites );
  40. ZeroMemory( &LvItem, sizeof(LVITEM) );
  41. LvItem.mask = LVIF_TEXT;
  42. LvItem.iItem = iPosition;
  43. LvItem.iSubItem = 0;
  44. LvItem.pszText = pszFriendlyName;
  45. LvItem.cchTextMax = MAX_FAVORITE_LEN;
  46. //
  47. // if ListView_InsertItem returns a non-negative value then it succeeded
  48. //
  49. if( ListView_InsertItem( hFavorites, &LvItem ) < 0 )
  50. {
  51. bSuccess = FALSE;
  52. }
  53. ListView_SetItemText( hFavorites, iPosition, 1, pszURL );
  54. return( bSuccess );
  55. }
  56. //----------------------------------------------------------------------------
  57. //
  58. // Function: OnInitFavoritesDialog
  59. //
  60. // Purpose:
  61. //
  62. // Arguments: IN HWND hwnd - handle to the dialog box
  63. //
  64. // Returns: VOID
  65. //
  66. //----------------------------------------------------------------------------
  67. static VOID
  68. OnInitFavoritesDialog( IN HWND hwnd )
  69. {
  70. RECT rect;
  71. INT iColWidth;
  72. INT iRetVal;
  73. INT iIndex;
  74. INT iEntries;
  75. LV_COLUMN lvCol;
  76. TCHAR *pFriendlyName;
  77. TCHAR *pUrl;
  78. HWND hFavoritesListView;
  79. INT iCount = 0;
  80. //
  81. // Set the text limit on the edit boxes
  82. //
  83. SendDlgItemMessage( hwnd,
  84. IDC_EB_FRIENDLYNAME,
  85. EM_LIMITTEXT,
  86. (WPARAM) MAX_FAVORITE_LEN,
  87. (LPARAM) 0 );
  88. SendDlgItemMessage( hwnd,
  89. IDC_EB_URL,
  90. EM_LIMITTEXT,
  91. (WPARAM) MAX_FAVORITE_LEN,
  92. (LPARAM) 0 );
  93. //
  94. // Initialize the list box
  95. //
  96. StrFriendlyName = MyLoadString( IDS_FRIENDLY_NAME );
  97. StrUrl = MyLoadString( IDS_URL );
  98. hFavoritesListView = GetDlgItem( hwnd, IDC_LV_FAVORITES );
  99. GetClientRect( hFavoritesListView, &rect );
  100. iColWidth = ( rect.right / 2 );
  101. ListView_SetColumnWidth( hFavoritesListView, 0, iColWidth );
  102. ListView_SetColumnWidth( hFavoritesListView, 1, iColWidth );
  103. lvCol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
  104. lvCol.fmt = LVCFMT_LEFT;
  105. lvCol.cx = iColWidth;
  106. //
  107. // Add the two columns and header text
  108. //
  109. for( iIndex = 0; iIndex < 2; iIndex++ ) {
  110. if ( iIndex == 0 )
  111. lvCol.pszText = (LPTSTR) StrFriendlyName;
  112. else
  113. lvCol.pszText = (LPTSTR) StrUrl;
  114. iRetVal = ListView_InsertColumn( hFavoritesListView, iIndex, &lvCol );
  115. if( iRetVal == -1 )
  116. {
  117. // ISSUE-2002/02/28-stelo- we got a problem if we get here, can't make the column headers
  118. }
  119. }
  120. //
  121. // Populate the favorites dialog
  122. //
  123. iEntries = GetNameListSize( &GenSettings.Favorites );
  124. for( iIndex = 0; iIndex < iEntries; iIndex = iIndex + 2 )
  125. {
  126. pFriendlyName = GetNameListName( &GenSettings.Favorites, iIndex );
  127. pUrl = GetNameListName( &GenSettings.Favorites, iIndex + 1 );
  128. if( *pFriendlyName != _T('\0') && *pUrl != _T('\0') )
  129. {
  130. InsertEntryIntoFavorites( hwnd, pFriendlyName, pUrl );
  131. }
  132. }
  133. iCount = ListView_GetItemCount( hFavoritesListView );
  134. if( iCount > 0 )
  135. {
  136. EnableWindow( GetDlgItem( hwnd, IDC_BUT_REMOVE ), TRUE );
  137. }
  138. else
  139. {
  140. EnableWindow( GetDlgItem( hwnd, IDC_BUT_REMOVE ), FALSE );
  141. }
  142. }
  143. //----------------------------------------------------------------------------
  144. //
  145. // Function: OnAddFavorites
  146. //
  147. // Purpose:
  148. //
  149. // Arguments: IN HWND hwnd - handle to the dialog box
  150. //
  151. // Returns: VOID
  152. //
  153. //----------------------------------------------------------------------------
  154. static VOID
  155. OnAddFavorites( IN HWND hwnd )
  156. {
  157. TCHAR szFriendlyName[MAX_FAVORITE_LEN + 1];
  158. TCHAR szURL[MAX_FAVORITE_LEN + 1];
  159. GetWindowText( GetDlgItem( hwnd, IDC_EB_FRIENDLYNAME ),
  160. szFriendlyName,
  161. MAX_FAVORITE_LEN + 1 );
  162. GetWindowText( GetDlgItem( hwnd, IDC_EB_URL ),
  163. szURL,
  164. MAX_FAVORITE_LEN + 1 );
  165. if( lstrcmp( szFriendlyName, _T("") ) == 0)
  166. {
  167. ReportErrorId( hwnd,
  168. MSGTYPE_ERR,
  169. IDS_ERR_FRIENDLY_NAME_BLANK );
  170. return;
  171. }
  172. else if( lstrcmp( szURL, _T("") ) == 0)
  173. {
  174. ReportErrorId( hwnd,
  175. MSGTYPE_ERR,
  176. IDS_ERR_URL_BLANK );
  177. return;
  178. }
  179. if( InsertEntryIntoFavorites( hwnd, szFriendlyName, szURL ) )
  180. {
  181. SetWindowText( GetDlgItem( hwnd, IDC_EB_FRIENDLYNAME ),
  182. _T("") );
  183. SetWindowText( GetDlgItem( hwnd, IDC_EB_URL ),
  184. _T("") );
  185. EnableWindow( GetDlgItem( hwnd, IDC_BUT_REMOVE ), TRUE );
  186. }
  187. }
  188. //----------------------------------------------------------------------------
  189. //
  190. // Function: OnRemoveFavorites
  191. //
  192. // Purpose:
  193. //
  194. // Arguments: IN HWND hwnd - handle to the dialog box
  195. //
  196. // Returns: VOID
  197. //
  198. //----------------------------------------------------------------------------
  199. static VOID
  200. OnRemoveFavorites( IN HWND hwnd )
  201. {
  202. HWND hFavorites;
  203. INT iSelectedItem;
  204. INT iCount;
  205. hFavorites = GetDlgItem( hwnd, IDC_LV_FAVORITES );
  206. iSelectedItem = ListView_GetSelectionMark( hFavorites );
  207. //
  208. // see if nothing was selected
  209. //
  210. if( iSelectedItem == -1 )
  211. {
  212. return;
  213. }
  214. ListView_DeleteItem( hFavorites, iSelectedItem );
  215. //
  216. // Set the state of the remove button appropriately
  217. //
  218. iCount = ListView_GetItemCount( hFavorites );
  219. if( iCount > 0 )
  220. {
  221. EnableWindow( GetDlgItem( hwnd, IDC_BUT_REMOVE ), TRUE );
  222. }
  223. else
  224. {
  225. EnableWindow( GetDlgItem( hwnd, IDC_BUT_REMOVE ), FALSE );
  226. }
  227. }
  228. //----------------------------------------------------------------------------
  229. //
  230. // Function: StoreFavorites
  231. //
  232. // Purpose:
  233. //
  234. // Arguments: IN HWND hwnd - handle to the dialog box
  235. //
  236. // Returns: VOID
  237. //
  238. //----------------------------------------------------------------------------
  239. static VOID
  240. StoreFavorites( IN HWND hwnd )
  241. {
  242. INT i;
  243. INT iEntries;
  244. LVITEM FriendlyNameItem;
  245. LVITEM UrlItem;
  246. HWND hFavorites;
  247. TCHAR szFriendlyName[MAX_FAVORITE_LEN + 1];
  248. TCHAR szURL[MAX_FAVORITE_LEN + 1];
  249. hFavorites = GetDlgItem( hwnd, IDC_LV_FAVORITES );
  250. ZeroMemory( &FriendlyNameItem, sizeof(LVITEM) );
  251. ZeroMemory( &UrlItem, sizeof(LVITEM) );
  252. ResetNameList( &GenSettings.Favorites );
  253. FriendlyNameItem.mask = LVIF_TEXT;
  254. FriendlyNameItem.pszText = szFriendlyName;
  255. FriendlyNameItem.cchTextMax = MAX_FAVORITE_LEN;
  256. FriendlyNameItem.iSubItem = 0;
  257. UrlItem.mask = LVIF_TEXT;
  258. UrlItem.pszText = szURL;
  259. UrlItem.cchTextMax = MAX_FAVORITE_LEN;
  260. UrlItem.iSubItem = 1;
  261. iEntries = ListView_GetItemCount( hFavorites );
  262. for( i = 0; i < iEntries; i++ )
  263. {
  264. FriendlyNameItem.iItem = i;
  265. UrlItem.iItem = i;
  266. if( ListView_GetItem( hFavorites, &FriendlyNameItem ) &&
  267. ListView_GetItem( hFavorites, &UrlItem ) )
  268. {
  269. if( szFriendlyName[0] != _T('\0') && szURL[0] != _T('\0') )
  270. {
  271. AddNameToNameList( &GenSettings.Favorites,
  272. szFriendlyName );
  273. AddNameToNameList( &GenSettings.Favorites,
  274. szURL );
  275. }
  276. }
  277. }
  278. }
  279. //----------------------------------------------------------------------------
  280. //
  281. // Function: FavoritesDlg
  282. //
  283. // Purpose:
  284. //
  285. // Arguments: standard Win32 dialog proc arguments
  286. //
  287. // Returns: standard Win32 dialog proc return value -- whether the message
  288. // was handled or not
  289. //
  290. //----------------------------------------------------------------------------
  291. INT_PTR CALLBACK FavoritesDlg(
  292. IN HWND hwnd,
  293. IN UINT uMsg,
  294. IN WPARAM wParam,
  295. IN LPARAM lParam )
  296. {
  297. BOOL bStatus = TRUE;
  298. switch (uMsg) {
  299. case WM_INITDIALOG:
  300. OnInitFavoritesDialog( hwnd );
  301. break;
  302. case WM_COMMAND:
  303. {
  304. int nButtonId;
  305. switch ( nButtonId = LOWORD(wParam) )
  306. {
  307. case IDOK:
  308. // ISSUE-2002/02/28-stelo- do I need to validate proxy addresses?
  309. if( HIWORD( wParam ) == BN_CLICKED ) {
  310. StoreFavorites( hwnd );
  311. EndDialog( hwnd, TRUE );
  312. }
  313. break;
  314. case IDCANCEL:
  315. if( HIWORD( wParam ) == BN_CLICKED ) {
  316. EndDialog( hwnd, FALSE );
  317. }
  318. break;
  319. case IDC_BUT_ADD:
  320. if( HIWORD( wParam ) == BN_CLICKED ) {
  321. OnAddFavorites( hwnd );
  322. }
  323. break;
  324. case IDC_BUT_REMOVE:
  325. if( HIWORD( wParam ) == BN_CLICKED ) {
  326. OnRemoveFavorites( hwnd );
  327. }
  328. break;
  329. default:
  330. bStatus = FALSE;
  331. break;
  332. }
  333. }
  334. break;
  335. default:
  336. bStatus = FALSE;
  337. break;
  338. }
  339. return( bStatus );
  340. }
  341. //----------------------------------------------------------------------------
  342. //
  343. // Function: OnInitBrowserSettingsDialog
  344. //
  345. // Purpose:
  346. //
  347. // Arguments: IN HWND hwnd - handle to the dialog box
  348. //
  349. // Returns: VOID
  350. //
  351. //----------------------------------------------------------------------------
  352. static VOID
  353. OnInitBrowserSettingsDialog( IN HWND hwnd )
  354. {
  355. //
  356. // Set the text limit on the edit boxes
  357. //
  358. SendDlgItemMessage( hwnd,
  359. IDC_EB_HOMEPAGE,
  360. EM_LIMITTEXT,
  361. (WPARAM) MAX_HOMEPAGE_LEN,
  362. (LPARAM) 0 );
  363. SendDlgItemMessage( hwnd,
  364. IDC_EB_HELPPAGE,
  365. EM_LIMITTEXT,
  366. (WPARAM) MAX_HELPPAGE_LEN,
  367. (LPARAM) 0 );
  368. SendDlgItemMessage( hwnd,
  369. IDC_EB_SEARCHPAGE,
  370. EM_LIMITTEXT,
  371. (WPARAM) MAX_SEARCHPAGE_LEN,
  372. (LPARAM) 0 );
  373. //
  374. // Set the initial values
  375. //
  376. SetWindowText( GetDlgItem( hwnd, IDC_EB_HOMEPAGE ),
  377. GenSettings.szHomePage );
  378. SetWindowText( GetDlgItem( hwnd, IDC_EB_HELPPAGE ),
  379. GenSettings.szHelpPage );
  380. SetWindowText( GetDlgItem( hwnd, IDC_EB_SEARCHPAGE ),
  381. GenSettings.szSearchPage );
  382. }
  383. //----------------------------------------------------------------------------
  384. //
  385. // Function: OnDestroyBrowserSettings
  386. //
  387. // Purpose:
  388. //
  389. // Arguments: IN HWND hwnd - handle to the dialog box
  390. //
  391. // Returns: VOID
  392. //
  393. //----------------------------------------------------------------------------
  394. static VOID
  395. OnDestroyBrowserSettings( IN HWND hwnd )
  396. {
  397. //
  398. // Free the strings that were allocated for this page
  399. //
  400. free( StrFriendlyName );
  401. free( StrUrl );
  402. }
  403. //----------------------------------------------------------------------------
  404. //
  405. // Function: StoreBrowserSettings
  406. //
  407. // Purpose:
  408. //
  409. // Arguments: IN HWND hwnd - handle to the dialog box
  410. //
  411. // Returns: VOID
  412. //
  413. //----------------------------------------------------------------------------
  414. static VOID
  415. StoreBrowserSettings( IN HWND hwnd )
  416. {
  417. GetWindowText( GetDlgItem( hwnd, IDC_EB_HOMEPAGE ),
  418. GenSettings.szHomePage,
  419. MAX_HOMEPAGE_LEN + 1 );
  420. GetWindowText( GetDlgItem( hwnd, IDC_EB_HELPPAGE ),
  421. GenSettings.szHelpPage,
  422. MAX_HELPPAGE_LEN + 1 );
  423. GetWindowText( GetDlgItem( hwnd, IDC_EB_SEARCHPAGE ),
  424. GenSettings.szSearchPage,
  425. MAX_SEARCHPAGE_LEN + 1 );
  426. }
  427. //----------------------------------------------------------------------------
  428. //
  429. // Function: OnAddFavoritesClicked
  430. //
  431. // Purpose:
  432. //
  433. // Arguments: IN HWND hwnd - handle to the dialog box
  434. //
  435. // Returns: VOID
  436. //
  437. //----------------------------------------------------------------------------
  438. static VOID
  439. OnAddFavoritesClicked( IN HWND hwnd )
  440. {
  441. DialogBox( FixedGlobals.hInstance,
  442. MAKEINTRESOURCE(IDD_IE_FAVORITES),
  443. hwnd,
  444. FavoritesDlg );
  445. }
  446. //----------------------------------------------------------------------------
  447. //
  448. // Function: BrowserSettingsDlg
  449. //
  450. // Purpose:
  451. //
  452. // Arguments: standard Win32 dialog proc arguments
  453. //
  454. // Returns: standard Win32 dialog proc return value -- whether the message
  455. // was handled or not
  456. //
  457. //----------------------------------------------------------------------------
  458. INT_PTR CALLBACK BrowserSettingsDlg(
  459. IN HWND hwnd,
  460. IN UINT uMsg,
  461. IN WPARAM wParam,
  462. IN LPARAM lParam )
  463. {
  464. BOOL bStatus = TRUE;
  465. switch (uMsg) {
  466. case WM_INITDIALOG:
  467. OnInitBrowserSettingsDialog( hwnd );
  468. break;
  469. case WM_DESTROY:
  470. OnDestroyBrowserSettings( hwnd );
  471. break;
  472. case WM_COMMAND:
  473. {
  474. int nButtonId;
  475. switch ( nButtonId = LOWORD(wParam) )
  476. {
  477. case IDOK:
  478. // ISSUE-2002/02/28-stelo- do I need to validate proxy addresses?
  479. if( HIWORD( wParam ) == BN_CLICKED ) {
  480. StoreBrowserSettings( hwnd );
  481. EndDialog( hwnd, TRUE );
  482. }
  483. break;
  484. case IDCANCEL:
  485. if( HIWORD( wParam ) == BN_CLICKED ) {
  486. EndDialog( hwnd, FALSE );
  487. }
  488. break;
  489. case IDC_BUT_FAVORITES:
  490. if( HIWORD(wParam) == BN_CLICKED )
  491. OnAddFavoritesClicked( hwnd );
  492. break;
  493. default:
  494. bStatus = FALSE;
  495. break;
  496. }
  497. }
  498. break;
  499. default:
  500. bStatus = FALSE;
  501. break;
  502. }
  503. return( bStatus );
  504. }