2000-03-22 10:43:43 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-03-22 10:43:43 +03:00
|
|
|
|
|
|
|
#ifndef nsFilePicker_h__
|
|
|
|
#define nsFilePicker_h__
|
|
|
|
|
2011-12-15 01:22:28 +04:00
|
|
|
#include <windows.h>
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2002-09-07 09:23:45 +04:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2009-03-30 22:08:06 +04:00
|
|
|
#include "nsCOMArray.h"
|
2000-03-22 10:43:43 +03:00
|
|
|
#include "nsBaseFilePicker.h"
|
|
|
|
#include "nsString.h"
|
2000-03-22 13:19:48 +03:00
|
|
|
#include "nsdefs.h"
|
2011-12-07 23:01:48 +04:00
|
|
|
#include <commdlg.h>
|
2011-12-15 01:22:28 +04:00
|
|
|
#include <shobjidl.h>
|
2013-12-16 04:00:54 +04:00
|
|
|
#undef LogSeverity // SetupAPI.h #defines this as DWORD
|
2011-12-15 01:22:28 +04:00
|
|
|
|
2012-04-09 23:53:46 +04:00
|
|
|
class nsILoadContext;
|
|
|
|
|
2012-09-03 19:25:08 +04:00
|
|
|
class nsBaseWinFilePicker : public nsBaseFilePicker {
|
|
|
|
public:
|
2017-11-06 06:37:28 +03:00
|
|
|
NS_IMETHOD GetDefaultString(nsAString& aDefaultString) override;
|
|
|
|
NS_IMETHOD SetDefaultString(const nsAString& aDefaultString) override;
|
|
|
|
NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension) override;
|
|
|
|
NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension) override;
|
2012-09-03 19:25:08 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsString mDefaultFilePath;
|
|
|
|
nsString mDefaultFilename;
|
|
|
|
nsString mDefaultExtension;
|
|
|
|
};
|
|
|
|
|
2000-03-22 10:43:43 +03:00
|
|
|
/**
|
|
|
|
* Native Windows FileSelector wrapper
|
|
|
|
*/
|
|
|
|
|
2020-11-16 22:37:09 +03:00
|
|
|
class nsFilePicker : public nsBaseWinFilePicker {
|
|
|
|
virtual ~nsFilePicker() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2000-03-22 10:43:43 +03:00
|
|
|
public:
|
2016-07-22 11:56:13 +03:00
|
|
|
nsFilePicker();
|
2000-03-22 10:43:43 +03:00
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
NS_IMETHOD Init(mozIDOMWindowProxy* aParent, const nsAString& aTitle,
|
|
|
|
int16_t aMode) override;
|
2016-07-22 11:56:13 +03:00
|
|
|
|
2000-03-22 10:43:43 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
2016-07-22 11:56:13 +03:00
|
|
|
|
2012-09-03 19:25:08 +04:00
|
|
|
// nsIFilePicker (less what's in nsBaseFilePicker and nsBaseWinFilePicker)
|
2017-11-06 06:37:28 +03:00
|
|
|
NS_IMETHOD GetFilterIndex(int32_t* aFilterIndex) override;
|
|
|
|
NS_IMETHOD SetFilterIndex(int32_t aFilterIndex) override;
|
|
|
|
NS_IMETHOD GetFile(nsIFile** aFile) override;
|
|
|
|
NS_IMETHOD GetFileURL(nsIURI** aFileURL) override;
|
|
|
|
NS_IMETHOD GetFiles(nsISimpleEnumerator** aFiles) override;
|
|
|
|
NS_IMETHOD AppendFilter(const nsAString& aTitle,
|
|
|
|
const nsAString& aFilter) override;
|
2000-03-22 10:43:43 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/* method from nsBaseFilePicker */
|
2004-04-22 03:38:22 +04:00
|
|
|
virtual void InitNative(nsIWidget* aParent, const nsAString& aTitle) override;
|
2017-08-06 07:15:31 +03:00
|
|
|
nsresult Show(int16_t* aReturnVal) override;
|
|
|
|
nsresult ShowW(int16_t* aReturnVal);
|
2000-03-22 13:19:48 +03:00
|
|
|
void GetFilterListArray(nsString& aFilterList);
|
2016-12-23 05:13:31 +03:00
|
|
|
bool ShowFolderPicker(const nsString& aInitialDir);
|
|
|
|
bool ShowFilePicker(const nsString& aInitialDir);
|
2011-12-15 01:22:16 +04:00
|
|
|
void RememberLastUsedDirectory();
|
|
|
|
bool IsPrivacyModeEnabled();
|
|
|
|
bool IsDefaultPathLink();
|
|
|
|
bool IsDefaultPathHtml();
|
2000-03-22 10:43:43 +03:00
|
|
|
|
2012-04-09 23:53:46 +04:00
|
|
|
nsCOMPtr<nsILoadContext> mLoadContext;
|
2004-04-22 03:38:22 +04:00
|
|
|
nsCOMPtr<nsIWidget> mParentWidget;
|
2000-03-22 10:43:43 +03:00
|
|
|
nsString mTitle;
|
2000-04-19 03:49:17 +04:00
|
|
|
nsCString mFile;
|
2000-08-25 06:17:53 +04:00
|
|
|
nsString mFilterList;
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t mSelectedType;
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMArray<nsIFile> mFiles;
|
2002-07-03 04:55:47 +04:00
|
|
|
nsString mUnicodeFile;
|
2020-11-16 22:37:09 +03:00
|
|
|
|
|
|
|
struct FreeDeleter {
|
|
|
|
void operator()(void* aPtr) { ::free(aPtr); }
|
|
|
|
};
|
|
|
|
static mozilla::UniquePtr<char16_t[], FreeDeleter> sLastUsedUnicodeDirectory;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-15 01:22:28 +04:00
|
|
|
class ComDlgFilterSpec {
|
|
|
|
public:
|
2012-01-05 00:30:57 +04:00
|
|
|
ComDlgFilterSpec() {}
|
|
|
|
~ComDlgFilterSpec() {}
|
2016-07-22 11:56:13 +03:00
|
|
|
|
2022-04-29 01:03:05 +03:00
|
|
|
uint32_t Length() { return mSpecList.Length(); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2022-04-29 01:03:05 +03:00
|
|
|
bool IsEmpty() { return (mSpecList.Length() == 0); }
|
2011-12-15 01:22:28 +04:00
|
|
|
|
2012-01-05 00:30:57 +04:00
|
|
|
const COMDLG_FILTERSPEC* get() { return mSpecList.Elements(); }
|
2011-12-15 01:22:28 +04:00
|
|
|
|
|
|
|
void Append(const nsAString& aTitle, const nsAString& aFilter);
|
2016-07-22 11:56:13 +03:00
|
|
|
|
2011-12-15 01:22:28 +04:00
|
|
|
private:
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<COMDLG_FILTERSPEC, 1> mSpecList;
|
|
|
|
AutoTArray<nsString, 2> mStrings;
|
2011-12-15 01:22:28 +04:00
|
|
|
};
|
|
|
|
|
2011-12-15 01:22:28 +04:00
|
|
|
ComDlgFilterSpec mComFilterList;
|
2000-03-22 10:43:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsFilePicker_h__
|