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.

168 lines
3.8 KiB

  1. //
  2. // fldoppsx - Folder Options Property Sheet Extension
  3. //
  4. #include "stdafx.h"
  5. #pragma hdrstop
  6. CFolderOptionsPsx::CFolderOptionsPsx() : m_cRef(1)
  7. {
  8. DllAddRef();
  9. }
  10. CFolderOptionsPsx::~CFolderOptionsPsx()
  11. {
  12. ATOMICRELEASE(m_pbs2);
  13. ATOMICRELEASE(m_pgfs);
  14. DllRelease();
  15. }
  16. ULONG CFolderOptionsPsx::AddRef()
  17. {
  18. return InterlockedIncrement(&m_cRef);
  19. }
  20. ULONG CFolderOptionsPsx::Release()
  21. {
  22. ULONG ulResult = InterlockedDecrement(&m_cRef);
  23. if (ulResult == 0) {
  24. delete this;
  25. }
  26. return ulResult;
  27. }
  28. HRESULT CFolderOptionsPsx::QueryInterface(REFIID riid, void **ppvObj)
  29. {
  30. static const QITAB qit[] = {
  31. QITABENT(CFolderOptionsPsx, IShellPropSheetExt),
  32. QITABENT(CFolderOptionsPsx, IShellExtInit),
  33. QITABENT(CFolderOptionsPsx, IObjectWithSite),
  34. { 0 },
  35. };
  36. return QISearch(this, qit, riid, ppvObj);
  37. }
  38. UINT CALLBACK CFolderOptionsPsx::PropCallback(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
  39. {
  40. CFolderOptionsPsx *pfolder = (CFolderOptionsPsx *)ppsp->lParam;
  41. switch (uMsg)
  42. {
  43. case PSPCB_RELEASE:
  44. pfolder->Release();
  45. break;
  46. }
  47. return TRUE;
  48. }
  49. //
  50. // We add two pages.
  51. //
  52. // 1. "General" - options.cpp
  53. // 2. "View" - advanced.cpp
  54. //
  55. // The rule for IShellPropSheetExt is that AddPages can be called
  56. // only once, so we don't have to worry about a second call accidentally
  57. // screwing up our IBrowserService pointer.
  58. //
  59. //
  60. HRESULT CFolderOptionsPsx::AddPages(LPFNADDPROPSHEETPAGE AddPage, LPARAM lParam)
  61. {
  62. if (!m_pgfs)
  63. {
  64. HRESULT hres = CoCreateInstance(CLSID_GlobalFolderSettings, NULL, CLSCTX_INPROC_SERVER,
  65. IID_IGlobalFolderSettings, (void **)&m_pgfs);
  66. if (FAILED(hres))
  67. return hres;
  68. }
  69. /*
  70. * We can limp along without an IBrowserService. It means that
  71. * we are only modifying global settings, not per-folder settings.
  72. */
  73. if (!m_pbs2)
  74. {
  75. IUnknown_QueryService(_punkSite, SID_SShellBrowser,
  76. IID_IBrowserService2, (void **)&m_pbs2);
  77. }
  78. PROPSHEETPAGE psp;
  79. /*
  80. * We used to do this only if we aren't a rooted Explorer,
  81. * but TOuzts says to do it always.
  82. *
  83. * The lParam is a pointer back to ourselves so the page
  84. * can figure out why it was created and so the two pages
  85. * can talk to each other.
  86. */
  87. psp.dwSize = SIZEOF(psp);
  88. psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK;
  89. psp.hInstance = HINST_THISDLL;
  90. psp.pfnCallback = CFolderOptionsPsx::PropCallback;
  91. psp.lParam = (LPARAM)this;
  92. // "General" page.
  93. psp.pszTemplate = MAKEINTRESOURCE(IDD_FOLDEROPTIONS);
  94. psp.pfnDlgProc = FolderOptionsDlgProc;
  95. HPROPSHEETPAGE hpage = CreatePropertySheetPage(&psp);
  96. if (hpage)
  97. {
  98. AddRef();
  99. if (!AddPage(hpage, lParam))
  100. {
  101. DestroyPropertySheetPage(hpage);
  102. Release();
  103. }
  104. }
  105. // "View" page.
  106. psp.pszTemplate = MAKEINTRESOURCE(IDD_ADVANCEDOPTIONS);
  107. psp.pfnDlgProc = AdvancedOptionsDlgProc;
  108. hpage = CreatePropertySheetPage(&psp);
  109. if (hpage)
  110. {
  111. AddRef();
  112. if (!AddPage(hpage, lParam))
  113. {
  114. DestroyPropertySheetPage(hpage);
  115. Release();
  116. }
  117. }
  118. return S_OK;
  119. }
  120. HRESULT CFolderOptionsPsx::ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE lpfnReplaceWith, LPARAM lParam)
  121. {
  122. return S_OK;
  123. }
  124. HRESULT CFolderOptionsPsx::Initialize(LPCITEMIDLIST pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID)
  125. {
  126. return S_OK;
  127. }
  128. STDAPI CFolderOptionsPsx_CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppvOut)
  129. {
  130. CFolderOptionsPsx *pfopt = new CFolderOptionsPsx();
  131. if (pfopt)
  132. {
  133. HRESULT hres = pfopt->QueryInterface(riid, ppvOut);
  134. pfopt->Release();
  135. return hres;
  136. }
  137. *ppvOut = NULL;
  138. return E_OUTOFMEMORY;
  139. }