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__
13 #include "nsISimpleEnumerator.h"
14 #include "nsCOMArray.h"
15 #include "nsBaseFilePicker.h"
20 #undef LogSeverity // SetupAPI.h #defines this as DWORD
24 class nsBaseWinFilePicker
: public nsBaseFilePicker
{
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
;
32 nsString mDefaultFilePath
;
33 nsString mDefaultFilename
;
34 nsString mDefaultExtension
;
38 * Native Windows FileSelector wrapper
41 class nsFilePicker
: public nsBaseWinFilePicker
{
42 virtual ~nsFilePicker() = default;
47 NS_IMETHOD
Init(mozIDOMWindowProxy
* aParent
, const nsAString
& aTitle
,
48 nsIFilePicker::Mode aMode
) override
;
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
;
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
;
79 int16_t mSelectedType
;
80 nsCOMArray
<nsIFile
> mFiles
;
81 nsString mUnicodeFile
;
84 void operator()(void* aPtr
) { ::free(aPtr
); }
86 static mozilla::UniquePtr
<char16_t
[], FreeDeleter
> sLastUsedUnicodeDirectory
;
88 class 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
);
102 AutoTArray
<COMDLG_FILTERSPEC
, 1> mSpecList
;
103 AutoTArray
<nsString
, 2> mStrings
;
106 ComDlgFilterSpec mComFilterList
;
109 #endif // nsFilePicker_h__