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.

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