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.

941 lines
25 KiB

  1. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  2. //
  3. // proppgs.cpp
  4. //
  5. // IShellPropSheetExt for channel shortcuts.
  6. //
  7. // History:
  8. //
  9. // 6/12/97 edwardp Created.
  10. //
  11. // Note: The hotkey stuff is comment out, the shell/windows doesn't make it
  12. // possible to persist hotkey settings across sessions and it isn't
  13. // worth kicking off another thread at boot to enable this feature.
  14. //
  15. ////////////////////////////////////////////////////////////////////////////////
  16. //
  17. // Includes
  18. //
  19. #include "stdinc.h"
  20. #include "cdfidl.h"
  21. #include "persist.h"
  22. #include "cdfview.h"
  23. #include "proppgs.h"
  24. #include "xmlutil.h"
  25. #include "dll.h"
  26. #include "iconhand.h"
  27. #include "resource.h"
  28. #include "winineti.h"
  29. #include <iehelpid.h>
  30. #include <mluisupp.h>
  31. #pragma warning(disable:4800)
  32. //
  33. // Constructor and destructor.
  34. //
  35. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  36. //
  37. // *** CPropertyPages::CPropertyPages ***
  38. //
  39. // Constructor for CPropertyPages.
  40. //
  41. ////////////////////////////////////////////////////////////////////////////////
  42. CPropertyPages::CPropertyPages (
  43. void
  44. )
  45. : m_cRef(1)
  46. {
  47. ASSERT(NULL == m_pSubscriptionMgr2);
  48. ASSERT(NULL == m_pInitDataObject);
  49. TraceMsg(TF_OBJECTS, "+ IShellPropSheetExt");
  50. DllAddRef();
  51. return;
  52. }
  53. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  54. //
  55. // *** CPropertyPages::~CPropertyPages ***
  56. //
  57. // Destructor.
  58. //
  59. ////////////////////////////////////////////////////////////////////////////////
  60. CPropertyPages::~CPropertyPages (
  61. void
  62. )
  63. {
  64. if (m_pSubscriptionMgr2)
  65. m_pSubscriptionMgr2->Release();
  66. if (m_pInitDataObject)
  67. m_pInitDataObject->Release();
  68. ASSERT(0 == m_cRef);
  69. //
  70. // Matching Release for the constructor Addref.
  71. //
  72. TraceMsg(TF_OBJECTS, "- IShellPropSheetExt");
  73. DllRelease();
  74. return;
  75. }
  76. //
  77. // IUnknown methods.
  78. //
  79. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  80. //
  81. // *** CPropertyPages::QueryInterface ***
  82. //
  83. // CPropertyPages QI.
  84. //
  85. ////////////////////////////////////////////////////////////////////////////////
  86. STDMETHODIMP
  87. CPropertyPages::QueryInterface (
  88. REFIID riid,
  89. void **ppv
  90. )
  91. {
  92. ASSERT(ppv);
  93. HRESULT hr;
  94. *ppv = NULL;
  95. if (IID_IUnknown == riid || IID_IShellPropSheetExt == riid)
  96. {
  97. *ppv = (IShellPropSheetExt*)this;
  98. }
  99. else if (IID_IShellExtInit == riid)
  100. {
  101. *ppv = (IShellExtInit*)this;
  102. }
  103. if (*ppv)
  104. {
  105. ((IUnknown*)*ppv)->AddRef();
  106. hr = S_OK;
  107. }
  108. else
  109. {
  110. hr = E_NOINTERFACE;
  111. }
  112. ASSERT((SUCCEEDED(hr) && *ppv) || (FAILED(hr) && NULL == *ppv));
  113. return hr;
  114. }
  115. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  116. //
  117. // *** CPropertyPages::AddRef ***
  118. //
  119. // CPropertyPages AddRef.
  120. //
  121. ////////////////////////////////////////////////////////////////////////////////
  122. STDMETHODIMP_(ULONG)
  123. CPropertyPages::AddRef (
  124. void
  125. )
  126. {
  127. ASSERT(m_cRef != 0);
  128. ASSERT(m_cRef < (ULONG)-1);
  129. return ++m_cRef;
  130. }
  131. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  132. //
  133. // *** CPropertyPages::Release ***
  134. //
  135. // CContextMenu Release.
  136. //
  137. ////////////////////////////////////////////////////////////////////////////////
  138. STDMETHODIMP_(ULONG)
  139. CPropertyPages::Release (
  140. void
  141. )
  142. {
  143. ASSERT (m_cRef != 0);
  144. ULONG cRef = --m_cRef;
  145. if (0 == cRef)
  146. delete this;
  147. return cRef;
  148. }
  149. //
  150. // IShellPropSheetExt methods.
  151. //
  152. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  153. //
  154. // *** Name ***
  155. //
  156. //
  157. // Description:
  158. //
  159. //
  160. // Parameters:
  161. //
  162. //
  163. // Return:
  164. //
  165. //
  166. // Comments:
  167. //
  168. //
  169. ////////////////////////////////////////////////////////////////////////////////
  170. STDMETHODIMP
  171. CPropertyPages::AddPages(
  172. LPFNADDPROPSHEETPAGE lpfnAddPage,
  173. LPARAM lParam
  174. )
  175. {
  176. HRESULT hr = S_OK;
  177. PROPSHEETPAGE psp;
  178. psp.dwSize = sizeof(PROPSHEETPAGE);
  179. psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK;
  180. psp.hInstance = MLGetHinst();
  181. psp.pszTemplate = MAKEINTRESOURCE(IDD_CHANNEL_PROP);
  182. psp.hIcon = NULL;
  183. psp.pszTitle = NULL;
  184. psp.pfnDlgProc = PropSheetDlgProc;
  185. psp.lParam = (LPARAM)(CPropertyPages *)this;
  186. psp.pfnCallback = PropSheetCallback;
  187. HPROPSHEETPAGE hpage = CreatePropertySheetPage(&psp);
  188. if (hpage)
  189. {
  190. // Release() happens in PropSheetCallback.
  191. AddRef();
  192. // Assume the mess below doesn't work, we want the default page to be us.
  193. hr = 1;
  194. // HACKHACK: This code attempts to remove the Folder property pages such as
  195. // General and Sharing (it will also whack any 3rd party pages which were
  196. // unfortunate enough to have been loaded before use :)
  197. PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam;
  198. // First make sure we can safely access the memory as if it were a
  199. // PROPSHEETHEADER structure.
  200. if (!IsBadReadPtr(ppsh, PROPSHEETHEADER_V1_SIZE) &&
  201. !IsBadWritePtr(ppsh, PROPSHEETHEADER_V1_SIZE))
  202. {
  203. // Now see if the module matches shell32
  204. if (ppsh->hInstance == GetModuleHandle(TEXT("shell32.dll")))
  205. {
  206. // looks good so rip 'em out
  207. for (UINT i = 0; i < ppsh->nPages; i++)
  208. {
  209. // At least be a good citizen and delete their pages so we
  210. // don't leak
  211. DestroyPropertySheetPage(ppsh->phpage[i]);
  212. }
  213. ppsh->nPages = 0;
  214. // Now we shouldn't need to mess with the default page. If someone
  215. // loads after us, we may not win.
  216. hr = 0;
  217. }
  218. }
  219. if (lpfnAddPage(hpage, lParam))
  220. {
  221. WCHAR wszURL[INTERNET_MAX_URL_LENGTH];
  222. SHTCharToUnicode(m_szURL, wszURL, ARRAYSIZE(wszURL));
  223. if (SUCCEEDED(InitializeSubsMgr2()))
  224. {
  225. m_pSubscriptionMgr2->IsSubscribed(wszURL, &m_bStartSubscribed);
  226. if (m_bStartSubscribed)
  227. {
  228. IShellPropSheetExt *pspse;
  229. if (SUCCEEDED(m_pSubscriptionMgr2->QueryInterface(IID_IShellPropSheetExt,
  230. (void **)&pspse)))
  231. {
  232. pspse->AddPages(lpfnAddPage, lParam);
  233. pspse->Release();
  234. }
  235. }
  236. }
  237. }
  238. else
  239. {
  240. DestroyPropertySheetPage(hpage);
  241. hr = E_FAIL;
  242. }
  243. }
  244. else
  245. {
  246. hr = E_OUTOFMEMORY;
  247. }
  248. return hr;
  249. }
  250. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  251. //
  252. // *** Name ***
  253. //
  254. //
  255. // Description:
  256. //
  257. //
  258. // Parameters:
  259. //
  260. //
  261. // Return:
  262. //
  263. //
  264. // Comments:
  265. //
  266. //
  267. ////////////////////////////////////////////////////////////////////////////////
  268. STDMETHODIMP
  269. CPropertyPages::ReplacePage(
  270. UINT uPageID,
  271. LPFNADDPROPSHEETPAGE lpfnAddPage,
  272. LPARAM lParam
  273. )
  274. {
  275. return E_NOTIMPL;
  276. }
  277. //
  278. // IShellExtInit methods.
  279. //
  280. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  281. //
  282. // *** Name ***
  283. //
  284. //
  285. // Description:
  286. //
  287. //
  288. // Parameters:
  289. //
  290. //
  291. // Return:
  292. //
  293. //
  294. // Comments:
  295. //
  296. //
  297. ////////////////////////////////////////////////////////////////////////////////
  298. STDMETHODIMP
  299. CPropertyPages::Initialize(
  300. LPCITEMIDLIST pidl,
  301. LPDATAOBJECT pIDataObject,
  302. HKEY hkey
  303. )
  304. {
  305. HRESULT hr;
  306. STGMEDIUM stgmed;
  307. FORMATETC fmtetc = {CF_HDROP, NULL, DVASPECT_CONTENT, -1,
  308. TYMED_HGLOBAL};
  309. if (m_pInitDataObject)
  310. m_pInitDataObject->Release();
  311. m_pInitDataObject = pIDataObject;
  312. m_pInitDataObject->AddRef();
  313. hr = pIDataObject->GetData(&fmtetc, &stgmed);
  314. if (SUCCEEDED(hr))
  315. {
  316. if (DragQueryFile((HDROP)stgmed.hGlobal, 0, m_szPath,
  317. ARRAYSIZE(m_szPath)))
  318. {
  319. TCHAR szDesktopINI[MAX_PATH];
  320. if (PathCombine(szDesktopINI, m_szPath, c_szDesktopINI))
  321. {
  322. GetPrivateProfileString(c_szChannel, c_szCDFURL, TEXT(""), m_szURL,
  323. ARRAYSIZE(m_szURL), szDesktopINI);
  324. }
  325. else
  326. {
  327. hr = E_FAIL;
  328. }
  329. //m_wHotkey = GetPrivateProfileInt(c_szChannel, c_szHotkey, 0, szDesktopINI);
  330. }
  331. else
  332. {
  333. hr = E_FAIL;
  334. }
  335. ReleaseStgMedium(&stgmed);
  336. }
  337. return hr;
  338. }
  339. //
  340. // Helper functions
  341. //
  342. HRESULT CPropertyPages::InitializeSubsMgr2()
  343. {
  344. HRESULT hr = E_FAIL;
  345. #ifndef UNIX
  346. if (NULL != m_pSubscriptionMgr2)
  347. {
  348. hr = S_OK;
  349. }
  350. else
  351. {
  352. hr = CoInitialize(NULL);
  353. if (SUCCEEDED(hr))
  354. {
  355. DLL_ForcePreloadDlls(PRELOAD_WEBCHECK);
  356. hr = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  357. CLSCTX_INPROC_SERVER, IID_ISubscriptionMgr2,
  358. (void**)&m_pSubscriptionMgr2);
  359. if (SUCCEEDED(hr))
  360. {
  361. IShellExtInit* pIShellExtInit;
  362. hr = m_pSubscriptionMgr2->QueryInterface(IID_IShellExtInit,
  363. (void **)&pIShellExtInit);
  364. if (SUCCEEDED(hr))
  365. {
  366. hr = pIShellExtInit->Initialize(NULL, m_pInitDataObject, NULL);
  367. pIShellExtInit->Release();
  368. }
  369. }
  370. }
  371. CoUninitialize();
  372. }
  373. #endif /* !UNIX */
  374. return hr;
  375. }
  376. void CPropertyPages::ShowOfflineSummary(HWND hdlg, BOOL bShow)
  377. {
  378. static const int offSumIDs[] =
  379. {
  380. IDC_SUMMARY,
  381. IDC_LAST_SYNC_TEXT,
  382. IDC_LAST_SYNC,
  383. IDC_DOWNLOAD_SIZE_TEXT,
  384. IDC_DOWNLOAD_SIZE,
  385. IDC_DOWNLOAD_RESULT,
  386. IDC_DOWNLOAD_RESULT_TEXT,
  387. IDC_FREE_SPACE_TEXT
  388. };
  389. if (bShow)
  390. {
  391. TCHAR szLastSync[128];
  392. TCHAR szDownloadSize[128];
  393. TCHAR szDownloadResult[128];
  394. WCHAR wszURL[INTERNET_MAX_URL_LENGTH];
  395. MLLoadString(IDS_VALUE_UNKNOWN, szLastSync, ARRAYSIZE(szLastSync));
  396. StrCpyN(szDownloadSize, szLastSync, ARRAYSIZE(szDownloadSize));
  397. StrCpyN(szDownloadResult, szLastSync, ARRAYSIZE(szDownloadResult));
  398. SHTCharToUnicode(m_szURL, wszURL, ARRAYSIZE(wszURL));
  399. ASSERT(NULL != m_pSubscriptionMgr2);
  400. if (NULL != m_pSubscriptionMgr2)
  401. {
  402. ISubscriptionItem *psi;
  403. if (SUCCEEDED(m_pSubscriptionMgr2->GetItemFromURL(wszURL, &psi)))
  404. {
  405. enum { spLastSync, spDownloadSize, spDownloadResult };
  406. static const LPCWSTR pProps[] =
  407. {
  408. c_szPropCompletionTime,
  409. c_szPropCrawlActualSize,
  410. c_szPropStatusString
  411. };
  412. VARIANT vars[ARRAYSIZE(pProps)];
  413. if (SUCCEEDED(psi->ReadProperties(ARRAYSIZE(pProps), pProps, vars)))
  414. {
  415. if (VT_DATE == vars[spLastSync].vt)
  416. {
  417. FILETIME ft, ft2;
  418. DWORD dwFlags = FDTF_DEFAULT;
  419. SYSTEMTIME st;
  420. VariantTimeToSystemTime(vars[spLastSync].date, &st);
  421. SystemTimeToFileTime(&st, &ft);
  422. LocalFileTimeToFileTime(&ft, &ft2);
  423. SHFormatDateTime(&ft2, &dwFlags, szLastSync, ARRAYSIZE(szLastSync));
  424. }
  425. if (VT_I4 == vars[spDownloadSize].vt)
  426. {
  427. StrFormatByteSize(vars[spDownloadSize].lVal * 1024,
  428. szDownloadSize, ARRAYSIZE(szDownloadSize));
  429. }
  430. if (VT_BSTR == vars[spDownloadResult].vt)
  431. {
  432. #ifdef UNICODE
  433. wnsprintf(szDownloadResult, ARRAYSIZE(szDownloadResult),
  434. TEXT("%s"), vars[spDownloadResult].bstrVal);
  435. #else
  436. wnsprintf(szDownloadResult, ARRAYSIZE(szDownloadResult),
  437. TEXT("%S"), vars[spDownloadResult].bstrVal);
  438. #endif
  439. }
  440. for (int i = 0; i < ARRAYSIZE(pProps); i++)
  441. {
  442. VariantClear(&vars[i]);
  443. }
  444. }
  445. psi->Release();
  446. }
  447. }
  448. SetDlgItemText(hdlg, IDC_LAST_SYNC, szLastSync);
  449. SetDlgItemText(hdlg, IDC_DOWNLOAD_SIZE, szDownloadSize);
  450. SetDlgItemText(hdlg, IDC_DOWNLOAD_RESULT, szDownloadResult);
  451. }
  452. for (int i = 0; i < ARRAYSIZE(offSumIDs); i++)
  453. {
  454. ShowWindow(GetDlgItem(hdlg, offSumIDs[i]), bShow ? SW_SHOW : SW_HIDE);
  455. }
  456. }
  457. BOOL CPropertyPages::OnInitDialog(HWND hdlg)
  458. {
  459. TCHAR szName[MAX_PATH];
  460. HICON hicon = NULL;
  461. HRESULT hr;
  462. CIconHandler *pIconHandler = new CIconHandler;
  463. if (pIconHandler)
  464. {
  465. if (SUCCEEDED(pIconHandler->Load(m_szPath, 0)))
  466. {
  467. TCHAR szIconFile[MAX_PATH];
  468. int iIndex;
  469. UINT wFlags;
  470. if (SUCCEEDED(pIconHandler->GetIconLocation(0, szIconFile, ARRAYSIZE(szIconFile),
  471. &iIndex, &wFlags)))
  472. {
  473. HICON hiconScrap = NULL;
  474. hr = pIconHandler->Extract(szIconFile, iIndex, &hicon, &hiconScrap,
  475. MAKELONG(GetSystemMetrics(SM_CXICON),
  476. GetSystemMetrics(SM_CXSMICON)));
  477. if (S_FALSE == hr)
  478. {
  479. // Do it ourselves
  480. hicon = ExtractIcon(g_hinst, szIconFile, iIndex);
  481. }
  482. else if ((NULL != hiconScrap) && (hicon != hiconScrap))
  483. {
  484. // Otherwise cleanup unwanted little icon
  485. DestroyIcon(hiconScrap);
  486. }
  487. }
  488. }
  489. pIconHandler->Release();
  490. }
  491. if (NULL == hicon)
  492. {
  493. hicon = LoadIcon(g_hinst, MAKEINTRESOURCE(IDI_CHANNEL));
  494. }
  495. BOOL bEnableMakeOffline = TRUE;
  496. SendDlgItemMessage(hdlg, IDC_ICONEX2, STM_SETICON, (WPARAM)hicon, 0);
  497. StrCpyN(szName, m_szPath, ARRAYSIZE(szName));
  498. PathStripPath(szName);
  499. SetDlgItemText(hdlg, IDC_NAME, szName);
  500. SetDlgItemText(hdlg, IDC_URL, m_szURL);
  501. TCHAR szVisits[256];
  502. szVisits[0] = 0;
  503. CCdfView* pCCdfView = new CCdfView;
  504. if (pCCdfView)
  505. {
  506. hr = pCCdfView->Load(m_szURL, 0);
  507. if (SUCCEEDED(hr))
  508. {
  509. IXMLDocument* pIXMLDocument;
  510. hr = pCCdfView->ParseCdf(NULL, &pIXMLDocument, PARSE_LOCAL);
  511. if (SUCCEEDED(hr))
  512. {
  513. IXMLElement* pIXMLElement;
  514. LONG nIndex;
  515. hr = XML_GetFirstChannelElement(pIXMLDocument,
  516. &pIXMLElement, &nIndex);
  517. if (SUCCEEDED(hr))
  518. {
  519. BSTR bstrURL = XML_GetAttribute(pIXMLElement, XML_HREF);
  520. if (bstrURL && *bstrURL)
  521. {
  522. BYTE cei[MAX_CACHE_ENTRY_INFO_SIZE];
  523. LPINTERNET_CACHE_ENTRY_INFO pcei = (LPINTERNET_CACHE_ENTRY_INFO)cei;
  524. DWORD cbcei = MAX_CACHE_ENTRY_INFO_SIZE;
  525. if (GetUrlCacheEntryInfoW(bstrURL, pcei, &cbcei))
  526. {
  527. wnsprintf(szVisits, ARRAYSIZE(szVisits), TEXT("%d"),
  528. pcei->dwHitRate);
  529. }
  530. }
  531. SysFreeString(bstrURL);
  532. pIXMLElement->Release();
  533. }
  534. pIXMLDocument->Release();
  535. }
  536. }
  537. pCCdfView->Release();
  538. }
  539. if (0 == szVisits[0])
  540. {
  541. MLLoadString(IDS_VALUE_UNKNOWN, szVisits,
  542. ARRAYSIZE(szVisits));
  543. }
  544. SetDlgItemText(hdlg, IDC_VISITS, szVisits);
  545. /*
  546. SendDlgItemMessage(hdlg, IDC_HOTKEY, HKM_SETRULES,
  547. (HKCOMB_NONE | HKCOMB_A | HKCOMB_C | HKCOMB_S),
  548. (HOTKEYF_CONTROL | HOTKEYF_ALT));
  549. SendDlgItemMessage(hdlg, IDC_HOTKEY, HKM_SETHOTKEY, m_wHotkey, 0);
  550. */
  551. WCHAR wszURL[INTERNET_MAX_URL_LENGTH];
  552. SHTCharToUnicode(m_szURL, wszURL, ARRAYSIZE(wszURL));
  553. CheckDlgButton(hdlg, IDC_MAKE_OFFLINE, m_bStartSubscribed ? 1 : 0);
  554. if (m_bStartSubscribed)
  555. {
  556. if (SHRestricted2(REST_NoRemovingSubscriptions, m_szURL, 0))
  557. {
  558. bEnableMakeOffline = FALSE;
  559. }
  560. }
  561. else
  562. {
  563. if (SHRestricted2(REST_NoAddingSubscriptions, m_szURL, 0))
  564. {
  565. bEnableMakeOffline = FALSE;
  566. }
  567. }
  568. if (!CanSubscribe(wszURL))
  569. {
  570. bEnableMakeOffline = FALSE;
  571. }
  572. if (!bEnableMakeOffline)
  573. {
  574. EnableWindow(GetDlgItem(hdlg, IDC_MAKE_OFFLINE), FALSE);
  575. }
  576. ShowOfflineSummary(hdlg, m_bStartSubscribed);
  577. return TRUE;
  578. }
  579. BOOL AddSubsPropsCallback(HPROPSHEETPAGE hpage, LPARAM lParam)
  580. {
  581. return (bool) PropSheet_AddPage((HWND)lParam, hpage);
  582. }
  583. void CPropertyPages::AddRemoveSubsPages(HWND hdlg, BOOL bAdd)
  584. {
  585. ASSERT(NULL != m_pSubscriptionMgr2);
  586. if (NULL != m_pSubscriptionMgr2)
  587. {
  588. if (bAdd)
  589. {
  590. IShellPropSheetExt *pspse;
  591. if (SUCCEEDED(m_pSubscriptionMgr2->QueryInterface(IID_IShellPropSheetExt,
  592. (void **)&pspse)))
  593. {
  594. pspse->AddPages(AddSubsPropsCallback, (LPARAM)GetParent(hdlg));
  595. pspse->Release();
  596. }
  597. }
  598. else
  599. {
  600. ISubscriptionMgrPriv *psmp;
  601. if (SUCCEEDED(m_pSubscriptionMgr2->QueryInterface(IID_ISubscriptionMgrPriv,
  602. (void **)&psmp)))
  603. {
  604. psmp->RemovePages(GetParent(hdlg));
  605. psmp->Release();
  606. }
  607. }
  608. ShowOfflineSummary(hdlg, bAdd);
  609. }
  610. }
  611. BOOL CPropertyPages::OnCommand(HWND hdlg, WORD wNotifyCode, WORD wID, HWND hwndCtl)
  612. {
  613. BOOL bHandled = TRUE;
  614. switch (wID)
  615. {
  616. case IDC_MAKE_OFFLINE:
  617. if (wNotifyCode == BN_CLICKED)
  618. {
  619. AddRemoveSubsPages(hdlg, IsDlgButtonChecked(hdlg, IDC_MAKE_OFFLINE));
  620. PropSheet_Changed(GetParent(hdlg), hdlg);
  621. }
  622. break;
  623. /*
  624. case IDC_HOTKEY:
  625. if (wNotifyCode == EN_CHANGE)
  626. {
  627. PropSheet_Changed(GetParent(hdlg), hdlg);
  628. }
  629. break;
  630. */
  631. default:
  632. bHandled = FALSE;
  633. break;
  634. }
  635. return bHandled;
  636. }
  637. BOOL CPropertyPages::OnNotify(HWND hdlg, WPARAM idCtrl, LPNMHDR pnmh)
  638. {
  639. BOOL bHandled = FALSE;
  640. switch (pnmh->code)
  641. {
  642. case PSN_APPLY:
  643. {
  644. /*
  645. TCHAR szHotkey[32];
  646. TCHAR szDesktopINI[MAX_PATH];
  647. WORD wOldHotkey = m_wHotkey;
  648. m_wHotkey = (WORD)SendDlgItemMessage(hdlg, IDC_HOTKEY, HKM_GETHOTKEY, 0, 0);
  649. wnsprintf(szHotkey, ARRAYSIZE(szHotkey), TEXT("%d"), m_wHotkey);
  650. PathCombine(szDesktopINI, m_szPath, c_szDesktopINI);
  651. WritePrivateProfileString(c_szChannel, c_szHotkey, szHotkey, szDesktopINI);
  652. RegisterGlobalHotkey(wOldHotkey, m_wHotkey, m_szPath);
  653. */
  654. BOOL bIsSubscribed = IsDlgButtonChecked(hdlg, IDC_MAKE_OFFLINE);
  655. if (!bIsSubscribed)
  656. {
  657. WCHAR wszURL[INTERNET_MAX_URL_LENGTH];
  658. SHTCharToUnicode(m_szURL, wszURL, ARRAYSIZE(wszURL));
  659. if (NULL != m_pSubscriptionMgr2)
  660. {
  661. m_pSubscriptionMgr2->DeleteSubscription(wszURL, NULL);
  662. }
  663. }
  664. else
  665. {
  666. ISubscriptionMgrPriv *psmp;
  667. if ((NULL != m_pSubscriptionMgr2) &&
  668. SUCCEEDED(m_pSubscriptionMgr2->QueryInterface(IID_ISubscriptionMgrPriv,
  669. (void **)&psmp)))
  670. {
  671. psmp->SaveSubscription();
  672. psmp->Release();
  673. }
  674. }
  675. bHandled = TRUE;
  676. break;
  677. }
  678. }
  679. return bHandled;
  680. }
  681. void CPropertyPages::OnDestroy(HWND hdlg)
  682. {
  683. if (!m_bStartSubscribed &&
  684. IsDlgButtonChecked(hdlg, IDC_MAKE_OFFLINE) &&
  685. (NULL != m_pSubscriptionMgr2))
  686. {
  687. WCHAR wszURL[INTERNET_MAX_URL_LENGTH];
  688. SHTCharToUnicode(m_szURL, wszURL, ARRAYSIZE(wszURL));
  689. m_pSubscriptionMgr2->UpdateSubscription(wszURL);
  690. }
  691. // Ensure sys bit is still set
  692. SetFileAttributes(m_szPath, FILE_ATTRIBUTE_SYSTEM);
  693. }
  694. UINT CPropertyPages::PropSheetCallback(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
  695. {
  696. switch (uMsg)
  697. {
  698. case PSPCB_RELEASE:
  699. if (NULL != ppsp->lParam)
  700. {
  701. ((CPropertyPages *)ppsp->lParam)->Release();
  702. }
  703. break;
  704. }
  705. return 1;
  706. }
  707. TCHAR c_szHelpFile[] = TEXT("iexplore.hlp");
  708. DWORD aHelpIDs[] = {
  709. IDC_NAME, IDH_SUBPROPS_SUBTAB_SUBSCRIBED_NAME,
  710. IDC_URL_TEXT, IDH_SUBPROPS_SUBTAB_SUBSCRIBED_URL,
  711. IDC_URL, IDH_SUBPROPS_SUBTAB_SUBSCRIBED_URL,
  712. // IDC_HOTKEY_TEXT, IDH_WEBDOC_HOTKEY,
  713. // IDC_HOTKEY, IDH_WEBDOC_HOTKEY,
  714. IDC_VISITS_TEXT, IDH_WEBDOC_VISITS,
  715. IDC_VISITS, IDH_WEBDOC_VISITS,
  716. IDC_MAKE_OFFLINE, IDH_MAKE_AVAIL_OFFLINE,
  717. IDC_SUMMARY, IDH_GROUPBOX,
  718. IDC_LAST_SYNC_TEXT, IDH_SUBPROPS_SUBTAB_LAST,
  719. IDC_LAST_SYNC, IDH_SUBPROPS_SUBTAB_LAST,
  720. IDC_DOWNLOAD_SIZE_TEXT, IDH_SUBPROPS_DLSIZE,
  721. IDC_DOWNLOAD_SIZE, IDH_SUBPROPS_DLSIZE,
  722. IDC_DOWNLOAD_RESULT_TEXT, IDH_SUBPROPS_SUBTAB_RESULT,
  723. IDC_DOWNLOAD_RESULT, IDH_SUBPROPS_SUBTAB_RESULT,
  724. 0, 0
  725. };
  726. INT_PTR CPropertyPages::PropSheetDlgProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
  727. {
  728. INT_PTR lrHandled = FALSE;
  729. CPropertyPages *pThis;
  730. switch (msg)
  731. {
  732. case WM_INITDIALOG:
  733. {
  734. LPPROPSHEETPAGE pPropSheetPage = (LPPROPSHEETPAGE)lParam;
  735. ASSERT(NULL != pPropSheetPage);
  736. if (NULL != pPropSheetPage)
  737. {
  738. SetWindowLongPtr(hdlg, DWLP_USER, pPropSheetPage->lParam);
  739. }
  740. pThis = GetThis(hdlg);
  741. if (NULL != pThis)
  742. {
  743. lrHandled = pThis->OnInitDialog(hdlg);
  744. }
  745. break;
  746. }
  747. case WM_COMMAND:
  748. pThis = GetThis(hdlg);
  749. if (NULL != pThis)
  750. {
  751. lrHandled = pThis->OnCommand(hdlg, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
  752. }
  753. break;
  754. case WM_NOTIFY:
  755. pThis = GetThis(hdlg);
  756. if (NULL != pThis)
  757. {
  758. lrHandled = pThis->OnNotify(hdlg, wParam, (LPNMHDR)lParam);
  759. }
  760. break;
  761. case WM_DESTROY:
  762. pThis = GetThis(hdlg);
  763. if (NULL != pThis)
  764. {
  765. pThis->OnDestroy(hdlg);
  766. }
  767. break;
  768. case WM_HELP:
  769. SHWinHelpOnDemandWrap((HWND)((LPHELPINFO) lParam)->hItemHandle, c_szHelpFile,
  770. HELP_WM_HELP, (DWORD_PTR) aHelpIDs);
  771. lrHandled = TRUE;
  772. break;
  773. case WM_CONTEXTMENU:
  774. SHWinHelpOnDemandWrap((HWND)wParam, c_szHelpFile, HELP_CONTEXTMENU, (DWORD_PTR)aHelpIDs);
  775. lrHandled = TRUE;
  776. break;
  777. }
  778. return lrHandled;
  779. }