1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_BASE_WIN_OPEN_FILE_NAME_WIN_H_
6 #define UI_BASE_WIN_OPEN_FILE_NAME_WIN_H_
13 #include "base/macros.h"
14 #include "base/strings/string16.h"
15 #include "base/tuple.h"
16 #include "ui/base/ui_base_export.h"
25 // Encapsulates an OPENFILENAME struct and related buffers. Also provides static
26 // methods for interpreting the properties of an OPENFILENAME.
27 class UI_BASE_EXPORT OpenFileName
{
29 // Initializes the OPENFILENAME, which may be accessed using Get(). All fields
30 // will be NULL except for |lStructSize|, |lpstrFile|, and |nMaxFile|. The
31 // file buffer will initially contain a null-terminated empty string.
32 OpenFileName(HWND parent_window
, DWORD flags
);
35 // Initializes |lpstrFilter| from the label/pattern pairs in |filters|.
37 const std::vector
<Tuple
<base::string16
, base::string16
>>& filters
);
39 // Sets |lpstrInitialDir| and |lpstrFile|.
40 void SetInitialSelection(const base::FilePath
& initial_directory
,
41 const base::FilePath
& initial_filename
);
43 // The save as dialog on Windows XP remembers its last position, and if the
44 // screen resolution has changed it may be off screen. This method will check
45 // if we are running on XP and if so install a hook to reposition the dialog
47 void MaybeInstallWindowPositionHookForSaveAsOnXP();
49 // Returns the single selected file, or an empty path if there are more or
50 // less than one results.
51 base::FilePath
GetSingleResult();
53 // Returns the selected file or files.
54 void GetResult(base::FilePath
* directory
,
55 std::vector
<base::FilePath
>* filenames
);
57 // Returns the OPENFILENAME structure.
58 OPENFILENAME
* GetOPENFILENAME() { return &openfilename_
; }
60 // Returns the OPENFILENAME structure.
61 const OPENFILENAME
* GetOPENFILENAME() const { return &openfilename_
; }
63 // Stores directory and filenames in the buffer pointed to by
64 // |openfilename->lpstrFile| and sized |openfilename->nMaxFile|.
65 static void SetResult(const base::FilePath
& directory
,
66 const std::vector
<base::FilePath
>& filenames
,
67 OPENFILENAME
* openfilename
);
69 // Returns a vector of label/pattern pairs built from
70 // |openfilename->lpstrFilter|.
71 static std::vector
<Tuple
<base::string16
, base::string16
>> GetFilters(
72 const OPENFILENAME
* openfilename
);
75 OPENFILENAME openfilename_
;
76 base::string16 initial_directory_buffer_
;
77 wchar_t filename_buffer_
[UNICODE_STRING_MAX_CHARS
];
78 base::string16 filter_buffer_
;
80 DISALLOW_COPY_AND_ASSIGN(OpenFileName
);
86 #endif // UI_BASE_WIN_OPEN_FILE_NAME_WIN_H_