OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/base/win/open_file_name_win.h" | 5 #include "ui/base/win/open_file_name_win.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 openfilename_.nMaxFile = arraysize(filename_buffer_); | 78 openfilename_.nMaxFile = arraysize(filename_buffer_); |
79 | 79 |
80 openfilename_.Flags = flags; | 80 openfilename_.Flags = flags; |
81 openfilename_.hwndOwner = parent_window; | 81 openfilename_.hwndOwner = parent_window; |
82 } | 82 } |
83 | 83 |
84 OpenFileName::~OpenFileName() { | 84 OpenFileName::~OpenFileName() { |
85 } | 85 } |
86 | 86 |
87 void OpenFileName::SetFilters( | 87 void OpenFileName::SetFilters( |
88 const std::vector<Tuple<base::string16, base::string16>>& filters) { | 88 const std::vector<base::Tuple<base::string16, base::string16>>& filters) { |
89 openfilename_.lpstrFilter = NULL; | 89 openfilename_.lpstrFilter = NULL; |
90 filter_buffer_.clear(); | 90 filter_buffer_.clear(); |
91 if (filters.empty()) | 91 if (filters.empty()) |
92 return; | 92 return; |
93 for (const auto& filter : filters) { | 93 for (const auto& filter : filters) { |
94 filter_buffer_.append(get<0>(filter)); | 94 filter_buffer_.append(base::get<0>(filter)); |
95 filter_buffer_.push_back(0); | 95 filter_buffer_.push_back(0); |
96 filter_buffer_.append(get<1>(filter)); | 96 filter_buffer_.append(base::get<1>(filter)); |
97 filter_buffer_.push_back(0); | 97 filter_buffer_.push_back(0); |
98 } | 98 } |
99 filter_buffer_.push_back(0); | 99 filter_buffer_.push_back(0); |
100 openfilename_.lpstrFilter = filter_buffer_.c_str(); | 100 openfilename_.lpstrFilter = filter_buffer_.c_str(); |
101 } | 101 } |
102 | 102 |
103 void OpenFileName::SetInitialSelection(const base::FilePath& initial_directory, | 103 void OpenFileName::SetInitialSelection(const base::FilePath& initial_directory, |
104 const base::FilePath& initial_filename) { | 104 const base::FilePath& initial_filename) { |
105 // First reset to the default case. | 105 // First reset to the default case. |
106 // According to http://support.microsoft.com/?scid=kb;en-us;222003&x=8&y=12, | 106 // According to http://support.microsoft.com/?scid=kb;en-us;222003&x=8&y=12, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // Because the result has embedded nulls, we must memcpy. | 195 // Because the result has embedded nulls, we must memcpy. |
196 memcpy(openfilename->lpstrFile, | 196 memcpy(openfilename->lpstrFile, |
197 filename_value.c_str(), | 197 filename_value.c_str(), |
198 (filename_value.size() + 1) * sizeof(filename_value[0])); | 198 (filename_value.size() + 1) * sizeof(filename_value[0])); |
199 } else if (openfilename->nMaxFile) { | 199 } else if (openfilename->nMaxFile) { |
200 openfilename->lpstrFile[0] = 0; | 200 openfilename->lpstrFile[0] = 0; |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 // static | 204 // static |
205 std::vector<Tuple<base::string16, base::string16>> | 205 std::vector<base::Tuple<base::string16, base::string16>> |
206 OpenFileName::GetFilters(const OPENFILENAME* openfilename) { | 206 OpenFileName::GetFilters(const OPENFILENAME* openfilename) { |
207 std::vector<Tuple<base::string16, base::string16>> filters; | 207 std::vector<base::Tuple<base::string16, base::string16>> filters; |
208 | 208 |
209 const base::char16* display_string = openfilename->lpstrFilter; | 209 const base::char16* display_string = openfilename->lpstrFilter; |
210 if (!display_string) | 210 if (!display_string) |
211 return filters; | 211 return filters; |
212 | 212 |
213 while (*display_string) { | 213 while (*display_string) { |
214 const base::char16* display_string_end = display_string; | 214 const base::char16* display_string_end = display_string; |
215 while (*display_string_end) | 215 while (*display_string_end) |
216 ++display_string_end; | 216 ++display_string_end; |
217 const base::char16* pattern = display_string_end + 1; | 217 const base::char16* pattern = display_string_end + 1; |
218 const base::char16* pattern_end = pattern; | 218 const base::char16* pattern_end = pattern; |
219 while (*pattern_end) | 219 while (*pattern_end) |
220 ++pattern_end; | 220 ++pattern_end; |
221 filters.push_back( | 221 filters.push_back( |
222 MakeTuple(base::string16(display_string, display_string_end), | 222 base::MakeTuple(base::string16(display_string, display_string_end), |
223 base::string16(pattern, pattern_end))); | 223 base::string16(pattern, pattern_end))); |
224 display_string = pattern_end + 1; | 224 display_string = pattern_end + 1; |
225 } | 225 } |
226 | 226 |
227 return filters; | 227 return filters; |
228 } | 228 } |
229 | 229 |
230 } // namespace win | 230 } // namespace win |
231 } // namespace ui | 231 } // namespace ui |
OLD | NEW |