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.

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