widget/windows/nsFilePicker.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/windows/nsFilePicker.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,164 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef nsFilePicker_h__
    1.11 +#define nsFilePicker_h__
    1.12 +
    1.13 +#include <windows.h>
    1.14 +
    1.15 +// For Vista IFileDialog interfaces which aren't exposed
    1.16 +// unless _WIN32_WINNT >= _WIN32_WINNT_LONGHORN.
    1.17 +#if _WIN32_WINNT < _WIN32_WINNT_LONGHORN
    1.18 +#define _WIN32_WINNT_bak _WIN32_WINNT
    1.19 +#undef _WIN32_WINNT
    1.20 +#define _WIN32_WINNT _WIN32_WINNT_LONGHORN
    1.21 +#define _WIN32_IE_bak _WIN32_IE
    1.22 +#undef _WIN32_IE
    1.23 +#define _WIN32_IE _WIN32_IE_IE70
    1.24 +#endif
    1.25 +
    1.26 +#include "nsIFile.h"
    1.27 +#include "nsITimer.h"
    1.28 +#include "nsISimpleEnumerator.h"
    1.29 +#include "nsCOMArray.h"
    1.30 +#include "nsAutoPtr.h"
    1.31 +#include "nsBaseFilePicker.h"
    1.32 +#include "nsString.h"
    1.33 +#include "nsdefs.h"
    1.34 +#include <commdlg.h>
    1.35 +#include <shobjidl.h>
    1.36 +#undef LogSeverity // SetupAPI.h #defines this as DWORD
    1.37 +
    1.38 +class nsILoadContext;
    1.39 +
    1.40 +class nsBaseWinFilePicker :
    1.41 +  public nsBaseFilePicker
    1.42 +{
    1.43 +public:
    1.44 +  NS_IMETHOD GetDefaultString(nsAString& aDefaultString);
    1.45 +  NS_IMETHOD SetDefaultString(const nsAString& aDefaultString);
    1.46 +  NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension);
    1.47 +  NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
    1.48 +
    1.49 +protected:
    1.50 +  nsString mDefaultFilePath;
    1.51 +  nsString mDefaultFilename;
    1.52 +  nsString mDefaultExtension;
    1.53 +};
    1.54 +
    1.55 +/**
    1.56 + * Native Windows FileSelector wrapper
    1.57 + */
    1.58 +
    1.59 +class nsFilePicker :
    1.60 +  public IFileDialogEvents,
    1.61 +  public nsBaseWinFilePicker
    1.62 +{
    1.63 +public:
    1.64 +  nsFilePicker(); 
    1.65 +  virtual ~nsFilePicker();
    1.66 +
    1.67 +  NS_IMETHOD Init(nsIDOMWindow *aParent, const nsAString& aTitle, int16_t aMode);
    1.68 +                  
    1.69 +  NS_DECL_ISUPPORTS
    1.70 +  
    1.71 +  // IUnknown's QueryInterface
    1.72 +  STDMETHODIMP QueryInterface(REFIID refiid, void** ppvResult);
    1.73 +
    1.74 +  // nsIFilePicker (less what's in nsBaseFilePicker and nsBaseWinFilePicker)
    1.75 +  NS_IMETHOD GetFilterIndex(int32_t *aFilterIndex);
    1.76 +  NS_IMETHOD SetFilterIndex(int32_t aFilterIndex);
    1.77 +  NS_IMETHOD GetFile(nsIFile * *aFile);
    1.78 +  NS_IMETHOD GetFileURL(nsIURI * *aFileURL);
    1.79 +  NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
    1.80 +  NS_IMETHOD Show(int16_t *aReturnVal); 
    1.81 +  NS_IMETHOD ShowW(int16_t *aReturnVal); 
    1.82 +  NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
    1.83 +
    1.84 +  // IFileDialogEvents
    1.85 +  HRESULT STDMETHODCALLTYPE OnFileOk(IFileDialog *pfd);
    1.86 +  HRESULT STDMETHODCALLTYPE OnFolderChanging(IFileDialog *pfd, IShellItem *psiFolder);
    1.87 +  HRESULT STDMETHODCALLTYPE OnFolderChange(IFileDialog *pfd);
    1.88 +  HRESULT STDMETHODCALLTYPE OnSelectionChange(IFileDialog *pfd);
    1.89 +  HRESULT STDMETHODCALLTYPE OnShareViolation(IFileDialog *pfd, IShellItem *psi, FDE_SHAREVIOLATION_RESPONSE *pResponse);
    1.90 +  HRESULT STDMETHODCALLTYPE OnTypeChange(IFileDialog *pfd);
    1.91 +  HRESULT STDMETHODCALLTYPE OnOverwrite(IFileDialog *pfd, IShellItem *psi, FDE_OVERWRITE_RESPONSE *pResponse);
    1.92 +
    1.93 +protected:
    1.94 +  enum PickerType {
    1.95 +    PICKER_TYPE_OPEN,
    1.96 +    PICKER_TYPE_SAVE,
    1.97 +  };
    1.98 +
    1.99 +  /* method from nsBaseFilePicker */
   1.100 +  virtual void InitNative(nsIWidget *aParent,
   1.101 +                          const nsAString& aTitle);
   1.102 +  static void GetQualifiedPath(const wchar_t *aInPath, nsString &aOutPath);
   1.103 +  void GetFilterListArray(nsString& aFilterList);
   1.104 +  bool FilePickerWrapper(OPENFILENAMEW* ofn, PickerType aType);
   1.105 +  bool ShowXPFolderPicker(const nsString& aInitialDir);
   1.106 +  bool ShowXPFilePicker(const nsString& aInitialDir);
   1.107 +  bool ShowFolderPicker(const nsString& aInitialDir, bool &aWasInitError);
   1.108 +  bool ShowFilePicker(const nsString& aInitialDir, bool &aWasInitError);
   1.109 +  void AppendXPFilter(const nsAString& aTitle, const nsAString& aFilter);
   1.110 +  void RememberLastUsedDirectory();
   1.111 +  bool IsPrivacyModeEnabled();
   1.112 +  bool IsDefaultPathLink();
   1.113 +  bool IsDefaultPathHtml();
   1.114 +  void SetDialogHandle(HWND aWnd);
   1.115 +  bool ClosePickerIfNeeded(bool aIsXPDialog);
   1.116 +  static void PickerCallbackTimerFunc(nsITimer *aTimer, void *aPicker);
   1.117 +  static UINT_PTR CALLBACK MultiFilePickerHook(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
   1.118 +  static UINT_PTR CALLBACK FilePickerHook(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
   1.119 +
   1.120 +  nsCOMPtr<nsILoadContext> mLoadContext;
   1.121 +  nsCOMPtr<nsIWidget>    mParentWidget;
   1.122 +  nsString               mTitle;
   1.123 +  nsCString              mFile;
   1.124 +  nsString               mFilterList;
   1.125 +  int16_t                mSelectedType;
   1.126 +  nsCOMArray<nsIFile>    mFiles;
   1.127 +  static char            mLastUsedDirectory[];
   1.128 +  nsString               mUnicodeFile;
   1.129 +  static char16_t      *mLastUsedUnicodeDirectory;
   1.130 +  HWND                   mDlgWnd;
   1.131 +
   1.132 +  class ComDlgFilterSpec
   1.133 +  {
   1.134 +  public:
   1.135 +    ComDlgFilterSpec() {}
   1.136 +    ~ComDlgFilterSpec() {}
   1.137 +    
   1.138 +    const uint32_t Length() {
   1.139 +      return mSpecList.Length();
   1.140 +    }
   1.141 +
   1.142 +    const bool IsEmpty() {
   1.143 +      return (mSpecList.Length() == 0);
   1.144 +    }
   1.145 +
   1.146 +    const COMDLG_FILTERSPEC* get() {
   1.147 +      return mSpecList.Elements();
   1.148 +    }
   1.149 +    
   1.150 +    void Append(const nsAString& aTitle, const nsAString& aFilter);
   1.151 +  private:
   1.152 +    nsAutoTArray<COMDLG_FILTERSPEC, 1> mSpecList;
   1.153 +    nsAutoTArray<nsString, 2> mStrings;
   1.154 +  };
   1.155 +
   1.156 +  ComDlgFilterSpec       mComFilterList;
   1.157 +  DWORD                  mFDECookie;
   1.158 +};
   1.159 +
   1.160 +#if defined(_WIN32_WINNT_bak)
   1.161 +#undef _WIN32_WINNT
   1.162 +#define _WIN32_WINNT _WIN32_WINNT_bak
   1.163 +#undef _WIN32_IE
   1.164 +#define _WIN32_IE _WIN32_IE_bak
   1.165 +#endif
   1.166 +
   1.167 +#endif // nsFilePicker_h__

mercurial