Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef nsFilePicker_h__ |
michael@0 | 8 | #define nsFilePicker_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include <windows.h> |
michael@0 | 11 | |
michael@0 | 12 | // For Vista IFileDialog interfaces which aren't exposed |
michael@0 | 13 | // unless _WIN32_WINNT >= _WIN32_WINNT_LONGHORN. |
michael@0 | 14 | #if _WIN32_WINNT < _WIN32_WINNT_LONGHORN |
michael@0 | 15 | #define _WIN32_WINNT_bak _WIN32_WINNT |
michael@0 | 16 | #undef _WIN32_WINNT |
michael@0 | 17 | #define _WIN32_WINNT _WIN32_WINNT_LONGHORN |
michael@0 | 18 | #define _WIN32_IE_bak _WIN32_IE |
michael@0 | 19 | #undef _WIN32_IE |
michael@0 | 20 | #define _WIN32_IE _WIN32_IE_IE70 |
michael@0 | 21 | #endif |
michael@0 | 22 | |
michael@0 | 23 | #include "nsIFile.h" |
michael@0 | 24 | #include "nsITimer.h" |
michael@0 | 25 | #include "nsISimpleEnumerator.h" |
michael@0 | 26 | #include "nsCOMArray.h" |
michael@0 | 27 | #include "nsAutoPtr.h" |
michael@0 | 28 | #include "nsBaseFilePicker.h" |
michael@0 | 29 | #include "nsString.h" |
michael@0 | 30 | #include "nsdefs.h" |
michael@0 | 31 | #include <commdlg.h> |
michael@0 | 32 | #include <shobjidl.h> |
michael@0 | 33 | #undef LogSeverity // SetupAPI.h #defines this as DWORD |
michael@0 | 34 | |
michael@0 | 35 | class nsILoadContext; |
michael@0 | 36 | |
michael@0 | 37 | class nsBaseWinFilePicker : |
michael@0 | 38 | public nsBaseFilePicker |
michael@0 | 39 | { |
michael@0 | 40 | public: |
michael@0 | 41 | NS_IMETHOD GetDefaultString(nsAString& aDefaultString); |
michael@0 | 42 | NS_IMETHOD SetDefaultString(const nsAString& aDefaultString); |
michael@0 | 43 | NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension); |
michael@0 | 44 | NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension); |
michael@0 | 45 | |
michael@0 | 46 | protected: |
michael@0 | 47 | nsString mDefaultFilePath; |
michael@0 | 48 | nsString mDefaultFilename; |
michael@0 | 49 | nsString mDefaultExtension; |
michael@0 | 50 | }; |
michael@0 | 51 | |
michael@0 | 52 | /** |
michael@0 | 53 | * Native Windows FileSelector wrapper |
michael@0 | 54 | */ |
michael@0 | 55 | |
michael@0 | 56 | class nsFilePicker : |
michael@0 | 57 | public IFileDialogEvents, |
michael@0 | 58 | public nsBaseWinFilePicker |
michael@0 | 59 | { |
michael@0 | 60 | public: |
michael@0 | 61 | nsFilePicker(); |
michael@0 | 62 | virtual ~nsFilePicker(); |
michael@0 | 63 | |
michael@0 | 64 | NS_IMETHOD Init(nsIDOMWindow *aParent, const nsAString& aTitle, int16_t aMode); |
michael@0 | 65 | |
michael@0 | 66 | NS_DECL_ISUPPORTS |
michael@0 | 67 | |
michael@0 | 68 | // IUnknown's QueryInterface |
michael@0 | 69 | STDMETHODIMP QueryInterface(REFIID refiid, void** ppvResult); |
michael@0 | 70 | |
michael@0 | 71 | // nsIFilePicker (less what's in nsBaseFilePicker and nsBaseWinFilePicker) |
michael@0 | 72 | NS_IMETHOD GetFilterIndex(int32_t *aFilterIndex); |
michael@0 | 73 | NS_IMETHOD SetFilterIndex(int32_t aFilterIndex); |
michael@0 | 74 | NS_IMETHOD GetFile(nsIFile * *aFile); |
michael@0 | 75 | NS_IMETHOD GetFileURL(nsIURI * *aFileURL); |
michael@0 | 76 | NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles); |
michael@0 | 77 | NS_IMETHOD Show(int16_t *aReturnVal); |
michael@0 | 78 | NS_IMETHOD ShowW(int16_t *aReturnVal); |
michael@0 | 79 | NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter); |
michael@0 | 80 | |
michael@0 | 81 | // IFileDialogEvents |
michael@0 | 82 | HRESULT STDMETHODCALLTYPE OnFileOk(IFileDialog *pfd); |
michael@0 | 83 | HRESULT STDMETHODCALLTYPE OnFolderChanging(IFileDialog *pfd, IShellItem *psiFolder); |
michael@0 | 84 | HRESULT STDMETHODCALLTYPE OnFolderChange(IFileDialog *pfd); |
michael@0 | 85 | HRESULT STDMETHODCALLTYPE OnSelectionChange(IFileDialog *pfd); |
michael@0 | 86 | HRESULT STDMETHODCALLTYPE OnShareViolation(IFileDialog *pfd, IShellItem *psi, FDE_SHAREVIOLATION_RESPONSE *pResponse); |
michael@0 | 87 | HRESULT STDMETHODCALLTYPE OnTypeChange(IFileDialog *pfd); |
michael@0 | 88 | HRESULT STDMETHODCALLTYPE OnOverwrite(IFileDialog *pfd, IShellItem *psi, FDE_OVERWRITE_RESPONSE *pResponse); |
michael@0 | 89 | |
michael@0 | 90 | protected: |
michael@0 | 91 | enum PickerType { |
michael@0 | 92 | PICKER_TYPE_OPEN, |
michael@0 | 93 | PICKER_TYPE_SAVE, |
michael@0 | 94 | }; |
michael@0 | 95 | |
michael@0 | 96 | /* method from nsBaseFilePicker */ |
michael@0 | 97 | virtual void InitNative(nsIWidget *aParent, |
michael@0 | 98 | const nsAString& aTitle); |
michael@0 | 99 | static void GetQualifiedPath(const wchar_t *aInPath, nsString &aOutPath); |
michael@0 | 100 | void GetFilterListArray(nsString& aFilterList); |
michael@0 | 101 | bool FilePickerWrapper(OPENFILENAMEW* ofn, PickerType aType); |
michael@0 | 102 | bool ShowXPFolderPicker(const nsString& aInitialDir); |
michael@0 | 103 | bool ShowXPFilePicker(const nsString& aInitialDir); |
michael@0 | 104 | bool ShowFolderPicker(const nsString& aInitialDir, bool &aWasInitError); |
michael@0 | 105 | bool ShowFilePicker(const nsString& aInitialDir, bool &aWasInitError); |
michael@0 | 106 | void AppendXPFilter(const nsAString& aTitle, const nsAString& aFilter); |
michael@0 | 107 | void RememberLastUsedDirectory(); |
michael@0 | 108 | bool IsPrivacyModeEnabled(); |
michael@0 | 109 | bool IsDefaultPathLink(); |
michael@0 | 110 | bool IsDefaultPathHtml(); |
michael@0 | 111 | void SetDialogHandle(HWND aWnd); |
michael@0 | 112 | bool ClosePickerIfNeeded(bool aIsXPDialog); |
michael@0 | 113 | static void PickerCallbackTimerFunc(nsITimer *aTimer, void *aPicker); |
michael@0 | 114 | static UINT_PTR CALLBACK MultiFilePickerHook(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); |
michael@0 | 115 | static UINT_PTR CALLBACK FilePickerHook(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); |
michael@0 | 116 | |
michael@0 | 117 | nsCOMPtr<nsILoadContext> mLoadContext; |
michael@0 | 118 | nsCOMPtr<nsIWidget> mParentWidget; |
michael@0 | 119 | nsString mTitle; |
michael@0 | 120 | nsCString mFile; |
michael@0 | 121 | nsString mFilterList; |
michael@0 | 122 | int16_t mSelectedType; |
michael@0 | 123 | nsCOMArray<nsIFile> mFiles; |
michael@0 | 124 | static char mLastUsedDirectory[]; |
michael@0 | 125 | nsString mUnicodeFile; |
michael@0 | 126 | static char16_t *mLastUsedUnicodeDirectory; |
michael@0 | 127 | HWND mDlgWnd; |
michael@0 | 128 | |
michael@0 | 129 | class ComDlgFilterSpec |
michael@0 | 130 | { |
michael@0 | 131 | public: |
michael@0 | 132 | ComDlgFilterSpec() {} |
michael@0 | 133 | ~ComDlgFilterSpec() {} |
michael@0 | 134 | |
michael@0 | 135 | const uint32_t Length() { |
michael@0 | 136 | return mSpecList.Length(); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | const bool IsEmpty() { |
michael@0 | 140 | return (mSpecList.Length() == 0); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | const COMDLG_FILTERSPEC* get() { |
michael@0 | 144 | return mSpecList.Elements(); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | void Append(const nsAString& aTitle, const nsAString& aFilter); |
michael@0 | 148 | private: |
michael@0 | 149 | nsAutoTArray<COMDLG_FILTERSPEC, 1> mSpecList; |
michael@0 | 150 | nsAutoTArray<nsString, 2> mStrings; |
michael@0 | 151 | }; |
michael@0 | 152 | |
michael@0 | 153 | ComDlgFilterSpec mComFilterList; |
michael@0 | 154 | DWORD mFDECookie; |
michael@0 | 155 | }; |
michael@0 | 156 | |
michael@0 | 157 | #if defined(_WIN32_WINNT_bak) |
michael@0 | 158 | #undef _WIN32_WINNT |
michael@0 | 159 | #define _WIN32_WINNT _WIN32_WINNT_bak |
michael@0 | 160 | #undef _WIN32_IE |
michael@0 | 161 | #define _WIN32_IE _WIN32_IE_bak |
michael@0 | 162 | #endif |
michael@0 | 163 | |
michael@0 | 164 | #endif // nsFilePicker_h__ |