Bug 1799258 - Fix constexpr issue on base toolchain builds. r=gfx-reviewers,lsalzman
[gecko.git] / widget / windows / nsFilePicker.h
blob81545c5380f050f705b83030ee9e2b184365187b
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsFilePicker_h__
8 #define nsFilePicker_h__
10 #include <windows.h>
12 #include "nsIFile.h"
13 #include "nsISimpleEnumerator.h"
14 #include "nsCOMArray.h"
15 #include "nsBaseFilePicker.h"
16 #include "nsString.h"
17 #include "nsdefs.h"
18 #include <commdlg.h>
19 #include <shobjidl.h>
20 #undef LogSeverity // SetupAPI.h #defines this as DWORD
22 class nsILoadContext;
24 class nsBaseWinFilePicker : public nsBaseFilePicker {
25 public:
26 NS_IMETHOD GetDefaultString(nsAString& aDefaultString) override;
27 NS_IMETHOD SetDefaultString(const nsAString& aDefaultString) override;
28 NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension) override;
29 NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension) override;
31 protected:
32 nsString mDefaultFilePath;
33 nsString mDefaultFilename;
34 nsString mDefaultExtension;
37 /**
38 * Native Windows FileSelector wrapper
41 class nsFilePicker : public nsBaseWinFilePicker {
42 virtual ~nsFilePicker() = default;
44 public:
45 nsFilePicker();
47 NS_IMETHOD Init(mozIDOMWindowProxy* aParent, const nsAString& aTitle,
48 nsIFilePicker::Mode aMode) override;
50 NS_DECL_ISUPPORTS
52 // nsIFilePicker (less what's in nsBaseFilePicker and nsBaseWinFilePicker)
53 NS_IMETHOD GetFilterIndex(int32_t* aFilterIndex) override;
54 NS_IMETHOD SetFilterIndex(int32_t aFilterIndex) override;
55 NS_IMETHOD GetFile(nsIFile** aFile) override;
56 NS_IMETHOD GetFileURL(nsIURI** aFileURL) override;
57 NS_IMETHOD GetFiles(nsISimpleEnumerator** aFiles) override;
58 NS_IMETHOD AppendFilter(const nsAString& aTitle,
59 const nsAString& aFilter) override;
61 protected:
62 /* method from nsBaseFilePicker */
63 virtual void InitNative(nsIWidget* aParent, const nsAString& aTitle) override;
64 nsresult Show(nsIFilePicker::ResultCode* aReturnVal) override;
65 nsresult ShowW(nsIFilePicker::ResultCode* aReturnVal);
66 void GetFilterListArray(nsString& aFilterList);
67 bool ShowFolderPicker(const nsString& aInitialDir);
68 bool ShowFilePicker(const nsString& aInitialDir);
69 void RememberLastUsedDirectory();
70 bool IsPrivacyModeEnabled();
71 bool IsDefaultPathLink();
72 bool IsDefaultPathHtml();
74 nsCOMPtr<nsILoadContext> mLoadContext;
75 nsCOMPtr<nsIWidget> mParentWidget;
76 nsString mTitle;
77 nsCString mFile;
78 nsString mFilterList;
79 int16_t mSelectedType;
80 nsCOMArray<nsIFile> mFiles;
81 nsString mUnicodeFile;
83 struct FreeDeleter {
84 void operator()(void* aPtr) { ::free(aPtr); }
86 static mozilla::UniquePtr<char16_t[], FreeDeleter> sLastUsedUnicodeDirectory;
88 class ComDlgFilterSpec {
89 public:
90 ComDlgFilterSpec() {}
91 ~ComDlgFilterSpec() {}
93 uint32_t Length() { return mSpecList.Length(); }
95 bool IsEmpty() { return (mSpecList.Length() == 0); }
97 const COMDLG_FILTERSPEC* get() { return mSpecList.Elements(); }
99 void Append(const nsAString& aTitle, const nsAString& aFilter);
101 private:
102 AutoTArray<COMDLG_FILTERSPEC, 1> mSpecList;
103 AutoTArray<nsString, 2> mStrings;
106 ComDlgFilterSpec mComFilterList;
109 #endif // nsFilePicker_h__