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.

264 lines
6.6 KiB

  1. #include "priv.h"
  2. #ifndef UNIX
  3. #include "sccls.h"
  4. #include "explore2.h"
  5. #include <iethread.h>
  6. #include "resource.h"
  7. #include "itbar.h"
  8. #include "mluisupp.h"
  9. #define DM_FOCUS DM_TRACE
  10. #define SUPERCLASS CSHELLBROWSER
  11. TCHAR const c_szSettings[] = TEXT("Settings");
  12. TCHAR const c_szCabinetExpView[] = TEXT("ExpView");
  13. CExplorerBrowser::CExplorerBrowser()
  14. {
  15. // warning: can't call SUPERCLASS until _Initialize has been called
  16. // (since that's what does the aggregation)
  17. }
  18. CExplorerBrowser::~CExplorerBrowser()
  19. {
  20. if (GetUIVersion() < 5) {
  21. if (_hmenuTemplate)
  22. DestroyMenu(_hmenuTemplate);
  23. if (_hmenuFull)
  24. DestroyMenu(_hmenuFull);
  25. }
  26. }
  27. HRESULT CExplorerBrowser::_Initialize(HWND hwnd, IUnknown *pauto)
  28. {
  29. HRESULT hr;
  30. SHELLSTATE ss = {0};
  31. hr = SUPERCLASS::_Initialize(hwnd, pauto);
  32. if (SUCCEEDED(hr)) {
  33. _fSubclassed = TRUE;
  34. }
  35. return hr;
  36. }
  37. void CExplorerBrowser::v_InitMembers()
  38. {
  39. if (GetUIVersion() < 5) {
  40. _hmenuTemplate = _MenuTemplate(MENU_TEMPLATE, TRUE);
  41. _hmenuFull = _MenuTemplate(MENU_FULL, TRUE);
  42. _hmenuCur = _hmenuTemplate;
  43. } else {
  44. // explorer/non-explorer shell menus same on nt5
  45. SUPERCLASS::v_InitMembers();
  46. }
  47. }
  48. HRESULT CExplorerBrowser_CreateInstance(HWND hwnd, LPVOID* ppsb)
  49. {
  50. HRESULT hr;
  51. CExplorerBrowser *psb = new CExplorerBrowser();
  52. if (psb) {
  53. hr = psb->_Initialize(hwnd, NULL); // aggregation, etc.
  54. if (FAILED(hr)) {
  55. ASSERT(0); // shouldn't happen
  56. ATOMICRELEASE(psb);
  57. }
  58. } else {
  59. // low mem
  60. hr = E_OUTOFMEMORY;
  61. }
  62. *ppsb = (LPVOID)psb;
  63. return hr;
  64. }
  65. IStream* CExplorerBrowser::_GetITBarStream(BOOL fWebBrowser, DWORD grfMode)
  66. {
  67. return GetITBarStream(ITBS_EXPLORER, grfMode);
  68. }
  69. HRESULT CExplorerBrowser::OnCreate(LPCREATESTRUCT pcs)
  70. {
  71. HRESULT hres = SUPERCLASS::OnCreate(pcs);
  72. v_ShowControl(FCW_TREE, SBSC_SHOW);
  73. return hres;
  74. }
  75. DWORD CExplorerBrowser::v_ShowControl(UINT iControl, int iCmd)
  76. {
  77. int iShowing = -1;
  78. switch (iControl) {
  79. case FCW_TREE:
  80. {
  81. // get the current state
  82. iShowing = (IsControlWindowShown(FCW_TREE, NULL) == S_OK) ? SBSC_SHOW : SBSC_HIDE;
  83. if (iCmd != SBSC_QUERY) {
  84. // turn it on/off as requested
  85. VARIANTARG v = {0};
  86. v.vt = VT_I4;
  87. v.lVal = SBSC_SHOW ? 1 : 0;
  88. Exec(&CGID_Explorer, SBCMDID_EXPLORERBAR, 0, &v, NULL);
  89. }
  90. break;
  91. }
  92. default:
  93. return SUPERCLASS::v_ShowControl(iControl, iCmd);
  94. }
  95. return iShowing;
  96. }
  97. // FEATURE: should go to cshellbrowser
  98. void CExplorerBrowser::_EnableMenuItemsByAttribs(HMENU hmenu)
  99. {
  100. if (_pbbd->_pidlCur) {
  101. DWORD dwAttrib = SFGAO_CANDELETE | SFGAO_CANRENAME | SFGAO_HASPROPSHEET;
  102. IEGetAttributesOf(_pbbd->_pidlCur, &dwAttrib);
  103. _EnableMenuItem(hmenu, FCIDM_DELETE, (dwAttrib & SFGAO_CANDELETE));
  104. _EnableMenuItem(hmenu, FCIDM_RENAME, (dwAttrib & SFGAO_CANRENAME));
  105. _EnableMenuItem(hmenu, FCIDM_PROPERTIES, (dwAttrib & SFGAO_HASPROPSHEET));
  106. }
  107. }
  108. BOOL CExplorerBrowser::_ExplorerTreeHasFocus()
  109. {
  110. BOOL bRet = FALSE;
  111. IInputObject* pio;
  112. if (SUCCEEDED(_QIExplorerBand(IID_IInputObject, (void**)&pio)))
  113. {
  114. bRet = (pio->HasFocusIO() == S_OK);
  115. pio->Release();
  116. }
  117. return bRet;
  118. }
  119. LRESULT CExplorerBrowser::v_OnInitMenuPopup(HMENU hmenuPopup, int nIndex, BOOL fSystemMenu)
  120. {
  121. if (hmenuPopup == _GetMenuFromID(FCIDM_MENU_FILE))
  122. {
  123. if (_ExplorerTreeHasFocus())
  124. _EnableMenuItemsByAttribs(hmenuPopup);
  125. }
  126. return SUPERCLASS::v_OnInitMenuPopup(hmenuPopup, nIndex, fSystemMenu);
  127. }
  128. HRESULT CExplorerBrowser::InsertMenusSB(HMENU hmenuShared,
  129. LPOLEMENUGROUPWIDTHS lpMenuWidths)
  130. {
  131. SUPERCLASS::InsertMenusSB(hmenuShared, lpMenuWidths);
  132. if (GetUIVersion() < 5) {
  133. if (lpMenuWidths->width[4] == 1)
  134. lpMenuWidths->width[4] = 2; // we have tools AND help for explorer mode
  135. }
  136. return S_OK;
  137. }
  138. void CExplorerBrowser::v_GetDefaultSettings(IETHREADPARAM *piei)
  139. {
  140. if (GetUIVersion() < 5)
  141. {
  142. // set the flags
  143. piei->fs.fFlags = 0;
  144. piei->fs.ViewMode = FVM_LIST;
  145. ASSERT(DFS_VID_Default == VID_WebView);
  146. #if 0 // If DFS_VID_Default differs from VID_WebView, then turn these lines back on
  147. piei->m_vidRestore = VID_List;
  148. piei->m_dwViewPriority = VIEW_PRIORITY_NONE; // let anyone override the VID_List default
  149. #endif
  150. piei->wv.bStatusBar = g_dfs.bDefStatusBar;
  151. piei->wp.length = 0;
  152. piei->wHotkey = 0;
  153. }
  154. else
  155. SUPERCLASS::v_GetDefaultSettings(piei);
  156. }
  157. void CExplorerBrowser::v_ParentFolder()
  158. {
  159. if (_ShouldAllowNavigateParent()) {
  160. BrowseObject(NULL, SBSP_PARENT | SBSP_SAMEBROWSER);
  161. }
  162. }
  163. HRESULT CExplorerBrowser::BrowseObject(LPCITEMIDLIST pidl, UINT wFlags)
  164. {
  165. // turn non-explore to newbrowser
  166. if ((GetUIVersion() < 5) && (wFlags & SBSP_OPENMODE))
  167. {
  168. wFlags &= ~(SBSP_DEFBROWSER | SBSP_SAMEBROWSER);
  169. wFlags |= SBSP_NEWBROWSER;
  170. }
  171. return SUPERCLASS::BrowseObject(pidl, wFlags);
  172. }
  173. DWORD CExplorerBrowser::v_RestartFlags()
  174. {
  175. return COF_CREATENEWWINDOW | COF_EXPLORE;
  176. }
  177. void CExplorerBrowser::v_GetAppTitleTemplate(LPTSTR pszBuffer, LPTSTR szFullName)
  178. {
  179. if (GetUIVersion() < 5) {
  180. // "exploring - la de da"
  181. TCHAR szBuffer[80];
  182. MLLoadString(IDS_EXPLORING, szBuffer, ARRAYSIZE(szBuffer));
  183. wnsprintf(pszBuffer, ARRAYSIZE(szBuffer) /*Lack of something better*/, TEXT("%s - %%s"), szBuffer);
  184. } else {
  185. SUPERCLASS::v_GetAppTitleTemplate(pszBuffer, szFullName);
  186. }
  187. }
  188. void CExplorerBrowser::_UpdateFolderSettings(LPCITEMIDLIST pidl)
  189. {
  190. if (GetUIVersion() < 5)
  191. {
  192. // Explorer always inherits the view a la win95
  193. _pbbd->_psv->GetCurrentInfo(&_fsd._fs);
  194. }
  195. else
  196. SUPERCLASS::_UpdateFolderSettings(pidl);
  197. }
  198. LPSTREAM CExplorerBrowser::v_GetViewStream(LPCITEMIDLIST pidl, DWORD grfMode,
  199. LPCWSTR pwszName)
  200. {
  201. // if it's asking for general browser info, give it the one browser info.
  202. // otherwise give do what our superclass does
  203. if ((GetUIVersion() < 5) && (StrCmpW(pwszName, L"CabView") == 0))
  204. {
  205. HKEY hk = SHGetShellKey(SHELLKEY_HKCU_EXPLORER, NULL, FALSE);
  206. if (hk)
  207. {
  208. IStream *pstm = OpenRegStream(hk, c_szCabinetExpView, c_szSettings, grfMode);
  209. RegCloseKey(hk);
  210. return pstm;
  211. }
  212. }
  213. return SUPERCLASS::v_GetViewStream(pidl, grfMode, pwszName);
  214. }
  215. #endif