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.

461 lines
18 KiB

  1. /*++
  2. Copyright (c) 1990-1998, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. filenew.h
  5. Abstract:
  6. This module contains the header information for the new Win32 fileopen
  7. dialogs.
  8. Revision History:
  9. --*/
  10. #undef StrCpy
  11. #undef StrCat
  12. #include "d32tlog.h"
  13. ////////////////////////////////////////////////////////////////////////////
  14. //
  15. // TEMPMEM class
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. class TEMPMEM
  19. {
  20. public:
  21. TEMPMEM(UINT cb)
  22. {
  23. m_uSize = cb;
  24. m_pMem = cb ? LocalAlloc(LPTR, cb) : NULL;
  25. }
  26. ~TEMPMEM()
  27. {
  28. if (m_pMem)
  29. {
  30. LocalFree(m_pMem);
  31. }
  32. }
  33. operator LPBYTE() const
  34. {
  35. return ((LPBYTE)m_pMem);
  36. }
  37. BOOL Resize(UINT cb);
  38. private:
  39. LPVOID m_pMem;
  40. protected:
  41. UINT m_uSize;
  42. };
  43. ////////////////////////////////////////////////////////////////////////////
  44. //
  45. // TEMPSTR class
  46. //
  47. ////////////////////////////////////////////////////////////////////////////
  48. class TEMPSTR : public TEMPMEM
  49. {
  50. public:
  51. TEMPSTR(UINT cc = 0) : TEMPMEM(cc * sizeof(TCHAR))
  52. {
  53. }
  54. operator LPTSTR() const
  55. {
  56. return ((LPTSTR)(LPBYTE) * (TEMPMEM *)this);
  57. }
  58. BOOL StrCpy(LPCTSTR pszText);
  59. BOOL StrCat(LPCTSTR pszText);
  60. BOOL StrSize(UINT cb)
  61. {
  62. return (TEMPMEM::Resize(cb * sizeof(TCHAR)));
  63. }
  64. };
  65. ////////////////////////////////////////////////////////////////////////////
  66. //
  67. // MYLISTBOXITEM class
  68. //
  69. // One object of this class exists for each item in the location dropdown.
  70. //
  71. // Data members:
  72. // psfSub - instance of IShellFolder bound to this container
  73. // pidlThis - IDL of this container, relative to its parent
  74. // pidlFull - IDL of this container, relative to the desktop
  75. // cIndent - indent level (0-based)
  76. // dwFlags -
  77. // MLBI_PERMANENT - item is an "information source" and should
  78. // always remain
  79. // dwAttrs - attributes of this container as reported by GetAttributesOf()
  80. // iImage, iSelectedImage - indices into the system image list for this
  81. // object
  82. //
  83. // Member functions:
  84. // ShouldInclude() - returns whether item belongs in the location dropdown
  85. // IsShared() - returns whether an item is shared or not
  86. // SwitchCurrentDirectory() - changes the Win32 current directory to the
  87. // directory indicated by this item
  88. //
  89. ////////////////////////////////////////////////////////////////////////////
  90. class MYLISTBOXITEM
  91. {
  92. public:
  93. IShellFolder *psfSub;
  94. IShellFolder *psfParent;
  95. LPITEMIDLIST pidlThis;
  96. LPITEMIDLIST pidlFull;
  97. DWORD cIndent;
  98. DWORD dwFlags;
  99. DWORD dwAttrs;
  100. int iImage;
  101. int iSelectedImage;
  102. HWND _hwndCmb;
  103. MYLISTBOXITEM();
  104. ULONG AddRef();
  105. ULONG Release();
  106. BOOL Init( HWND hwndCmb,
  107. MYLISTBOXITEM *pParentItem,
  108. IShellFolder *psf,
  109. LPCITEMIDLIST pidl,
  110. DWORD c,
  111. DWORD f,
  112. IShellTaskScheduler* pScheduler);
  113. //This function is used to initialize all members directly.
  114. BOOL Init(HWND hwndCmb, IShellFolder *psf, LPCITEMIDLIST pidl, DWORD c, DWORD f, DWORD dwAttrs, int iImage,
  115. int iSelectedImage);
  116. inline BOOL ShouldInclude()
  117. {
  118. return (dwAttrs & (SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM));
  119. }
  120. inline BOOL IsShared()
  121. {
  122. return (dwAttrs & SFGAO_SHARE);
  123. }
  124. void SwitchCurrentDirectory(ICurrentWorkingDirectory * pcwd);
  125. IShellFolder* GetShellFolder();
  126. static void CALLBACK _AsyncIconTaskCallback(LPCITEMIDLIST pidl, LPVOID pvData, LPVOID pvHint, INT iIconIndex, INT iOpenIconIndex);
  127. private:
  128. ~MYLISTBOXITEM();
  129. LONG _cRef;
  130. };
  131. ////////////////////////////////////////////////////////////////////////////
  132. //
  133. // CFileOpenBrowser class
  134. //
  135. ////////////////////////////////////////////////////////////////////////////
  136. typedef BOOL (*EIOCALLBACK)(class CFileOpenBrowser*that, LPCITEMIDLIST pidl, LPARAM lParam);
  137. typedef enum
  138. {
  139. ECODE_S_OK = 0,
  140. ECODE_BADDRIVE = 1,
  141. ECODE_BADPATH = 2,
  142. } ECODE;
  143. typedef enum
  144. {
  145. OKBUTTON_NONE = 0x0000,
  146. OKBUTTON_NODEFEXT = 0x0001,
  147. OKBUTTON_QUOTED = 0x0002,
  148. } OKBUTTON_FLAGS;
  149. typedef UINT OKBUTTONFLAGS;
  150. typedef struct _SHTCUTINFO
  151. {
  152. BOOL fReSolve; //[IN] Should we resolve the shortcut
  153. DWORD dwAttr; //[IN/OUT] Attributes of the target pointed by shortcut
  154. LPTSTR pszLinkFile; //[OUT] Target file name
  155. UINT cchFile; //[IN] size of buffer pointed to by pszLinkFile
  156. LPITEMIDLIST * ppidl; //[OUT] pidl of the target pointed to by shortcut
  157. }SHTCUTINFO, *PSHTCUTINFO;
  158. typedef enum
  159. {
  160. LOCTYPE_RECENT_FOLDER = 1,
  161. LOCTYPE_MYPICTURES_FOLDER = 2,
  162. LOCTYPE_OTHERS = 3,
  163. LOCTYPE_WIA_FOLDER = 4
  164. }LOCTYPE;
  165. class CFileOpenBrowser
  166. : public IShellBrowser
  167. , public ICommDlgBrowser2
  168. , public IServiceProvider
  169. {
  170. public:
  171. // *** IUnknown methods ***
  172. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID *ppvObj);
  173. STDMETHOD_(ULONG,AddRef) (THIS);
  174. STDMETHOD_(ULONG,Release) (THIS);
  175. // *** IOleWindow methods ***
  176. STDMETHOD(GetWindow) (THIS_ HWND *lphwnd);
  177. STDMETHOD(ContextSensitiveHelp) (THIS_ BOOL fEnterMode);
  178. // *** IShellBrowser methods *** (same as IOleInPlaceFrame)
  179. STDMETHOD(InsertMenusSB) (THIS_ HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths);
  180. STDMETHOD(SetMenuSB) (THIS_ HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject);
  181. STDMETHOD(RemoveMenusSB) (THIS_ HMENU hmenuShared);
  182. STDMETHOD(SetStatusTextSB) (THIS_ LPCOLESTR lpszStatusText);
  183. STDMETHOD(EnableModelessSB) (THIS_ BOOL fEnable);
  184. STDMETHOD(TranslateAcceleratorSB) (THIS_ LPMSG lpmsg, WORD wID);
  185. // *** IShellBrowser methods ***
  186. STDMETHOD(BrowseObject)(THIS_ LPCITEMIDLIST pidl, UINT wFlags);
  187. STDMETHOD(GetViewStateStream)(THIS_ DWORD grfMode, LPSTREAM *pStrm);
  188. STDMETHOD(GetControlWindow)(THIS_ UINT id, HWND *lphwnd);
  189. STDMETHOD(SendControlMsg)(THIS_ UINT id, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pret);
  190. STDMETHOD(QueryActiveShellView)(THIS_ struct IShellView **ppshv);
  191. STDMETHOD(OnViewWindowActive)(THIS_ struct IShellView *pshv);
  192. STDMETHOD(SetToolbarItems)(THIS_ LPTBBUTTON lpButtons, UINT nButtons, UINT uFlags);
  193. // *** ICommDlgBrowser methods ***
  194. STDMETHOD(OnDefaultCommand) (THIS_ struct IShellView *ppshv);
  195. STDMETHOD(OnStateChange) (THIS_ struct IShellView *ppshv, ULONG uChange);
  196. STDMETHOD(IncludeObject) (THIS_ struct IShellView *ppshv, LPCITEMIDLIST lpItem);
  197. // *** ICommDlgBrowser2 methods ***
  198. STDMETHOD(Notify) (THIS_ struct IShellView *ppshv, DWORD dwNotifyType);
  199. STDMETHOD(GetDefaultMenuText) (THIS_ struct IShellView *ppshv, WCHAR *pszText, INT cchMax);
  200. STDMETHOD(GetViewFlags)(THIS_ DWORD *pdwFlags);
  201. // *** IServiceProvider methods ***
  202. STDMETHOD(QueryService)(THIS_ REFGUID guidService, REFIID riid, LPVOID* ppvObj);
  203. // *** Our own methods ***
  204. CFileOpenBrowser(HWND hDlg, BOOL fIsSaveAs);
  205. ~CFileOpenBrowser();
  206. HRESULT SwitchView(struct IShellFolder *psfNew, LPCITEMIDLIST pidlNew, FOLDERSETTINGS *pfs, SHELLVIEWID const *pvid, BOOL fUseDefultView);
  207. void OnDblClick(BOOL bFromOKButton);
  208. LRESULT OnNotify(LPNMHDR lpnmhdr);
  209. BOOL OnSetCursor(void);
  210. void ViewCommand(UINT uIndex);
  211. void PaintDriveLine(DRAWITEMSTRUCT *lpdis);
  212. void GetFullPath(LPTSTR pszBuf);
  213. BOOL OnSelChange(int iItem = -1, BOOL bForceUpdate = FALSE);
  214. void OnDotDot();
  215. void RefreshFilter(HWND hwndFilter);
  216. BOOL JumpToPath(LPCTSTR pszDirectory, BOOL bTranslate = FALSE);
  217. BOOL JumpToIDList(LPCITEMIDLIST pidlNew, BOOL bTranslate = FALSE, BOOL bAddToNavStack = TRUE);
  218. BOOL SetDirRetry(LPTSTR pszDir, BOOL bNoValidate = FALSE);
  219. BOOL MultiSelectOKButton(LPCTSTR pszFiles, OKBUTTONFLAGS Flags);
  220. BOOL OKButtonPressed(LPCTSTR pszFile, OKBUTTONFLAGS Flags);
  221. UINT GetDirectoryFromLB(LPTSTR szBuffer, int *pichRoot);
  222. void SetCurrentFilter(LPCTSTR pszFilter, OKBUTTONFLAGS Flags = OKBUTTON_QUOTED);
  223. UINT GetFullEditName(LPTSTR pszBuf, UINT cLen, TEMPSTR *pTempStr = NULL, BOOL *pbNoDefExt = NULL);
  224. void ProcessEdit();
  225. LRESULT OnCommandMessage(WPARAM wParam, LPARAM lParam);
  226. BOOL OnCDMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
  227. void RemoveOldPath(int *piNewSel);
  228. BOOL LinkMatchSpec(LPCITEMIDLIST pidl, LPCTSTR szSpec);
  229. BOOL GetLinkStatus(LPCITEMIDLIST pidl,PSHTCUTINFO pinfo);
  230. HRESULT ResolveLink(LPCITEMIDLIST pidl, PSHTCUTINFO pinfo, IShellFolder *psf = NULL);
  231. void SelFocusChange(BOOL bSelChange);
  232. void SelRename(void);
  233. void SetSaveButton(UINT idSaveButton);
  234. void RealSetSaveButton(UINT idSaveButton);
  235. void SetEditFile(LPCTSTR pszFile, LPCTSTR pszFileFriendly, BOOL bShowExt, BOOL bSaveNullExt = TRUE);
  236. BOOL EnumItemObjects(UINT uItem, EIOCALLBACK pfnCallBack, LPARAM lParam);
  237. BOOL IsKnownExtension(LPCTSTR pszExtension);
  238. UINT FindNameInView(LPTSTR pszFile, OKBUTTONFLAGS Flags, LPTSTR pszPathName,
  239. int nFileOffset, int nExtOffset, int *pnErrCode,
  240. BOOL bTryAsDir = TRUE);
  241. void UpdateLevel(HWND hwndLB, int iInsert, MYLISTBOXITEM *pParentItem);
  242. void InitializeDropDown(HWND hwndCtl);
  243. BOOL FSChange(LONG lNotification, LPCITEMIDLIST *ppidl);
  244. int GetNodeFromIDList(LPCITEMIDLIST pidl);
  245. void Timer(WPARAM wID);
  246. BOOL CreateHookDialog(POINT *pPtSize);
  247. void OnGetMinMax(LPMINMAXINFO pmmi);
  248. void OnSize(int, int);
  249. void VerifyListViewPosition(void);
  250. BOOL CreateToolbar(); // Creates the file open toolbar
  251. void EnableFileMRU(BOOL fEnable); // Enable/Disable File MRU based on the flag passed
  252. void UpdateNavigation(); // Updates the Navigation by adding the current pidl
  253. // to the navigation stack
  254. void UpdateUI(LPITEMIDLIST pidlNew); // Updates the back navigation button and the hot item on the places bar
  255. LPCTSTR JumpToInitialLocation(LPCTSTR pszDir, LPTSTR pszFile);
  256. BOOL InitLookIn(HWND hDlg); //Initializes the look in drop down.
  257. int _CopyFileNameToOFN(LPTSTR pszFile, DWORD *pdwError);
  258. void _CopyTitleToOFN(LPCTSTR pszTitle);
  259. BOOL _IsNoDereferenceLinks(LPCWSTR pszFile, IShellItem *psi);
  260. BOOL _OpenAsContainer(IShellItem *psi, SFGAOF sfgao);
  261. HRESULT _ParseName(LPCITEMIDLIST pidlParent, IShellFolder *psf, IBindCtx *pbc, LPCOLESTR psz, IShellItem **ppsi);
  262. HRESULT _ParseNameAndTest(LPCOLESTR pszIn, IBindCtx *pbc, IShellItem **ppsi, BOOL fAllowJump);
  263. HRESULT _ParseShellItem(LPCOLESTR pszIn, IShellItem **ppsi, BOOL fAllowJump);
  264. HRESULT _TestShellItem(IShellItem *psi, BOOL fAllowJump, IShellItem **ppsiReal);
  265. #ifdef RETURN_SHELLITEMS
  266. HRESULT _ItemOKButtonPressed(LPCTSTR pszFile, OKBUTTONFLAGS Flags);
  267. HRESULT _ProcessShellItem(IShellItem *psi);
  268. #endif RETURN_SHELLITEMS
  269. HRESULT _MakeFakeCopy(IShellItem *psi, LPWSTR *ppszPath);
  270. BOOL CheckForRestrictedFolder(LPCTSTR lpszPath, int nFileOffset); //Checks to see whether a file can be saved in the given path.
  271. void ResetDialogHeight(HWND hDlg, HWND hwndExclude, HWND hwndGrip, int nCtlsBottom);
  272. void ReAdjustDialog(); // if help and open as read only is hidden then this function readjusts the dialog
  273. // to reclaim the space occupied by these controls
  274. //Places Bar Related Functions
  275. HWND CreatePlacesbar(HWND hDlg); // Creates places bar
  276. void _RecreatePlacesbar();
  277. void _CleanupPlacesbar();
  278. void _FillPlacesbar(HWND hwndPlacesbar);
  279. BOOL _EnumPlacesBarItem(HKEY hkey, int i , SHFILEINFO *psfi, LPITEMIDLIST *ppidl);
  280. BOOL _GetPlacesBarItemToolTip(int idCmd, LPTSTR pText, DWORD dwSize);
  281. BOOL _GetPBItemFromTokenStrings(LPTSTR lpszPath, SHFILEINFO * psfi, LPITEMIDLIST *ppidl);
  282. BOOL _GetPBItemFromCSIDL(DWORD csidl, SHFILEINFO * psfi, LPITEMIDLIST *ppidl);
  283. BOOL _GetPBItemFromPath(LPTSTR lpszPath, SHFILEINFO * psfi, LPITEMIDLIST *ppidl);
  284. //Pidl Processing Functions
  285. BOOL _ProcessPidlSelection(); //Processes the selection pidl if any.
  286. HRESULT _ProcessItemAsFile(IShellItem *psi);
  287. //General Utility Functions
  288. BOOL _ValidateSelectedFile(LPCTSTR pszFile, int *pErrCode);
  289. BOOL _PostProcess(LPTSTR pszFile);
  290. BOOL _IsThumbnailFolder(LPCITEMIDLIST pidl);
  291. BOOL _IsWIAFolder(IShellFolder *psf);
  292. LOCTYPE _GetLocationType(MYLISTBOXITEM *pLocation);
  293. void _WaitCursor(BOOL fWait);
  294. BOOL CFileOpenBrowser::_IsRestrictedDrive(LPCTSTR pszPath, LPCITEMIDLIST pidl);
  295. void CFileOpenBrowser::JumpToLocationIfUnrestricted(LPCTSTR pszPath, LPCITEMIDLIST pidl, BOOL bTranslate);
  296. BOOL CFileOpenBrowser::_SaveAccessDenied(LPCTSTR pszFile);
  297. void _CleanupDialog(BOOL fRet);
  298. void OnThemeActive(HWND hwndDlg, BOOL bActive);
  299. //Member Variables
  300. LONG _cRef; // compobj refcount
  301. int _iCurrentLocation; // index of curr selection in location dropdown
  302. int _iVersion; // Which version of dialog are we showing
  303. MYLISTBOXITEM *_pCurrentLocation; // ptr to object for same
  304. HWND _hwndDlg; // handle of this dialog
  305. HWND _hSubDlg; // handle of the hook dialog
  306. IShellView *_psv; // current view object
  307. IShellFolder *_psfCurrent; // current shellfolder object
  308. TravelLog *_ptlog; // ptr to travel log
  309. HWND _hwndView; // current view window
  310. HWND _hwndToolbar; // toolbar window
  311. HWND _hwndPlacesbar; // places bar window
  312. HWND _hwndLastFocus; // ctrl that had focus before OK button
  313. HIMAGELIST _himl; // system imagelist (small images)
  314. TEMPSTR _pszHideExt; // saved file with extension
  315. TEMPSTR _tszDefSave; // saved file with extension
  316. TEMPSTR _pszDefExt; // writable version of the DefExt
  317. TEMPSTR _pszObjectPath; // full object path
  318. TEMPSTR _pszObjectCurDir; // object current directory (folder)
  319. UINT _uRegister;
  320. int _iComboIndex;
  321. int _iNodeDrives; // location of my computer in drop down
  322. int _iNodeDesktop; // location of Desktop in drop down
  323. int _iCommandID; // Next command id to use for a Placebar Item
  324. int _iCheckedButton; // if > 0 tells which places bar button is checked
  325. BOOL _bEnableSizing; // if sizing is enabled
  326. BOOL _bUseCombo; // Use the edit window instead of comboxex for app compatibility
  327. POINT _ptLastSize; // last known size of dialog
  328. POINT _ptMinTrack; // initial size of view
  329. SIZE _sizeView; // last known size of view
  330. HWND _hwndGrip; // window handle of sizing grip
  331. DWORD _dwPlacesbarPadding; // default placesbar toolbar padding
  332. LPOPENFILENAME _pOFN; // caller's OPENFILENAME struct
  333. BOOL _bSave : 1; // whether this is a save-as dialog
  334. BOOL _fShowExtensions : 1; // whether to show extensions
  335. BOOL _bUseHideExt : 1; // whether pszHideExt is valid
  336. BOOL _bDropped : 1;
  337. BOOL _bNoInferDefExt : 1; // don't get defext from combo
  338. BOOL _fSelChangedPending : 1; // we have a selchanging message pending
  339. BOOL _bSelIsObject : 1; // the last selected object is an object, not a file
  340. BOOL _bUseSizeView : 1; // only use cached size after failure to create view...
  341. BOOL _bAppRedrawn : 1; // Did app call RedrawWindow? - see ResetDialogHeight
  342. BOOL _bDestroyPlacesbarImageList : 1; // Free placesbar imagelist first time only
  343. HWND _hwndTips; // hWnd of tooltip control for this window
  344. LPOPENFILEINFO _pOFI; // info for thunking (ansi callers only)
  345. ICurrentWorkingDirectory * _pcwd; // Interface to AutoComplete COM Object that sets CurrentWorkingDir
  346. UINT _CachedViewMode; // we force Some folders into specific views. this caches the users choice
  347. UINT _fCachedViewFlags; // we also need to cache the view flags.
  348. // Apphack for Borland JBuilder Professional - see ResetDialogHeight
  349. int _topOrig; // original window top
  350. LPITEMIDLIST _pidlSelection; // This is currently selected items pidl.
  351. IShellTaskScheduler* _pScheduler; // This TaskScheduler is used to do delayed Icon extractions.
  352. int _cWaitCursor;
  353. LONG _cRefCannotNavigate;
  354. HWND _hwndModelessFocus;
  355. WNDPROC _lpOKProc;
  356. // Perf: Big structures go at the end
  357. TCHAR _szLastFilter[MAX_PATH + 1]; // last filter chosen by the user
  358. TCHAR _szStartDir[MAX_PATH + 1]; // saved starting directory
  359. TCHAR _szCurDir[MAX_PATH + 1]; // currently viewed dir (if FS)
  360. TCHAR _szBuf[MAX_PATH + 4]; // scratch buffer
  361. TCHAR _szTipBuf[MAX_PATH + 1]; // tool tip buffer
  362. ////////////////////////////////////////////////////////////////////////////
  363. //
  364. // WAIT_CURSOR class
  365. //
  366. ////////////////////////////////////////////////////////////////////////////
  367. class WAIT_CURSOR
  368. {
  369. private:
  370. CFileOpenBrowser *_that;
  371. public:
  372. WAIT_CURSOR(CFileOpenBrowser *that) : _that(that)
  373. {
  374. _that->_WaitCursor(TRUE);
  375. }
  376. ~WAIT_CURSOR()
  377. {
  378. _that->_WaitCursor(FALSE);
  379. }
  380. };
  381. };
  382. #define VIEW_JUMPDESKTOP (VIEW_NEWFOLDER + 1)