Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Side by Side Diff: ui/base/win/open_file_name_win.cc

Issue 821453003: Update legacy Tuple-using code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/win/open_file_name_win.h ('k') | ui/base/win/open_file_name_win_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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<Tuple2<base::string16, base::string16> >& filters) { 88 const std::vector<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 (std::vector<Tuple2<base::string16, base::string16> >::const_iterator 93 for (const auto& filter : filters) {
94 it = filters.begin(); 94 filter_buffer_.append(get<0>(filter));
95 it != filters.end();
96 ++it) {
97 filter_buffer_.append(it->a);
98 filter_buffer_.push_back(0); 95 filter_buffer_.push_back(0);
99 filter_buffer_.append(it->b); 96 filter_buffer_.append(get<1>(filter));
100 filter_buffer_.push_back(0); 97 filter_buffer_.push_back(0);
101 } 98 }
102 filter_buffer_.push_back(0); 99 filter_buffer_.push_back(0);
103 openfilename_.lpstrFilter = filter_buffer_.c_str(); 100 openfilename_.lpstrFilter = filter_buffer_.c_str();
104 } 101 }
105 102
106 void OpenFileName::SetInitialSelection(const base::FilePath& initial_directory, 103 void OpenFileName::SetInitialSelection(const base::FilePath& initial_directory,
107 const base::FilePath& initial_filename) { 104 const base::FilePath& initial_filename) {
108 // First reset to the default case. 105 // First reset to the default case.
109 // 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
198 // Because the result has embedded nulls, we must memcpy. 195 // Because the result has embedded nulls, we must memcpy.
199 memcpy(openfilename->lpstrFile, 196 memcpy(openfilename->lpstrFile,
200 filename_value.c_str(), 197 filename_value.c_str(),
201 (filename_value.size() + 1) * sizeof(filename_value[0])); 198 (filename_value.size() + 1) * sizeof(filename_value[0]));
202 } else if (openfilename->nMaxFile) { 199 } else if (openfilename->nMaxFile) {
203 openfilename->lpstrFile[0] = 0; 200 openfilename->lpstrFile[0] = 0;
204 } 201 }
205 } 202 }
206 203
207 // static 204 // static
208 std::vector<Tuple2<base::string16, base::string16> > OpenFileName::GetFilters( 205 std::vector<Tuple<base::string16, base::string16>>
209 const OPENFILENAME* openfilename) { 206 OpenFileName::GetFilters(const OPENFILENAME* openfilename) {
210 std::vector<Tuple2<base::string16, base::string16> > filters; 207 std::vector<Tuple<base::string16, base::string16>> filters;
211 208
212 const base::char16* display_string = openfilename->lpstrFilter; 209 const base::char16* display_string = openfilename->lpstrFilter;
213 if (!display_string) 210 if (!display_string)
214 return filters; 211 return filters;
215 212
216 while (*display_string) { 213 while (*display_string) {
217 const base::char16* display_string_end = display_string; 214 const base::char16* display_string_end = display_string;
218 while (*display_string_end) 215 while (*display_string_end)
219 ++display_string_end; 216 ++display_string_end;
220 const base::char16* pattern = display_string_end + 1; 217 const base::char16* pattern = display_string_end + 1;
221 const base::char16* pattern_end = pattern; 218 const base::char16* pattern_end = pattern;
222 while (*pattern_end) 219 while (*pattern_end)
223 ++pattern_end; 220 ++pattern_end;
224 filters.push_back( 221 filters.push_back(
225 MakeTuple(base::string16(display_string, display_string_end), 222 MakeTuple(base::string16(display_string, display_string_end),
226 base::string16(pattern, pattern_end))); 223 base::string16(pattern, pattern_end)));
227 display_string = pattern_end + 1; 224 display_string = pattern_end + 1;
228 } 225 }
229 226
230 return filters; 227 return filters;
231 } 228 }
232 229
233 } // namespace win 230 } // namespace win
234 } // namespace ui 231 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/win/open_file_name_win.h ('k') | ui/base/win/open_file_name_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698