OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/common/win_util.h" | 5 #include "chrome/common/win_util.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlapp.h> | 8 #include <atlapp.h> |
9 #include <commdlg.h> | 9 #include <commdlg.h> |
10 #include <dwmapi.h> | 10 #include <dwmapi.h> |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 380 |
381 bool SaveFileAs(HWND owner, | 381 bool SaveFileAs(HWND owner, |
382 const std::wstring& suggested_name, | 382 const std::wstring& suggested_name, |
383 std::wstring* final_name) { | 383 std::wstring* final_name) { |
384 std::wstring filter = GetFileFilterFromPath(suggested_name); | 384 std::wstring filter = GetFileFilterFromPath(suggested_name); |
385 unsigned index = 1; | 385 unsigned index = 1; |
386 return SaveFileAsWithFilter(owner, | 386 return SaveFileAsWithFilter(owner, |
387 suggested_name, | 387 suggested_name, |
388 filter, | 388 filter, |
389 L"", | 389 L"", |
| 390 false, |
390 &index, | 391 &index, |
391 final_name); | 392 final_name); |
392 } | 393 } |
393 | 394 |
394 bool SaveFileAsWithFilter(HWND owner, | 395 bool SaveFileAsWithFilter(HWND owner, |
395 const std::wstring& suggested_name, | 396 const std::wstring& suggested_name, |
396 const std::wstring& filter, | 397 const std::wstring& filter, |
397 const std::wstring& def_ext, | 398 const std::wstring& def_ext, |
| 399 bool ignore_suggested_ext, |
398 unsigned* index, | 400 unsigned* index, |
399 std::wstring* final_name) { | 401 std::wstring* final_name) { |
400 DCHECK(final_name); | 402 DCHECK(final_name); |
401 // Having an empty filter makes for a bad user experience. We should always | 403 // Having an empty filter makes for a bad user experience. We should always |
402 // specify a filter when saving. | 404 // specify a filter when saving. |
403 DCHECK(!filter.empty()); | 405 DCHECK(!filter.empty()); |
404 std::wstring file_part = file_util::GetFilenameFromPath(suggested_name); | 406 std::wstring file_part = file_util::GetFilenameFromPath(suggested_name); |
405 | 407 |
406 // The size of the in/out buffer in number of characters we pass to win32 | 408 // The size of the in/out buffer in number of characters we pass to win32 |
407 // GetSaveFileName. From MSDN "The buffer must be large enough to store the | 409 // GetSaveFileName. From MSDN "The buffer must be large enough to store the |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 // the example above, if the first index was selected we need to skip 1 | 467 // the example above, if the first index was selected we need to skip 1 |
466 // instance of null to get to "*.jpg". | 468 // instance of null to get to "*.jpg". |
467 std::vector<std::wstring> filters; | 469 std::vector<std::wstring> filters; |
468 if (!filter.empty() && save_as.nFilterIndex > 0) | 470 if (!filter.empty() && save_as.nFilterIndex > 0) |
469 SplitString(filter, '\0', &filters); | 471 SplitString(filter, '\0', &filters); |
470 std::wstring filter_selected; | 472 std::wstring filter_selected; |
471 if (!filters.empty()) | 473 if (!filters.empty()) |
472 filter_selected = filters[(2 * (save_as.nFilterIndex - 1)) + 1]; | 474 filter_selected = filters[(2 * (save_as.nFilterIndex - 1)) + 1]; |
473 | 475 |
474 // Get the extension that was suggested to the user (when the Save As dialog | 476 // Get the extension that was suggested to the user (when the Save As dialog |
475 // was opened). | 477 // was opened). For saving web pages, we skip this step since there may be |
476 std::wstring suggested_ext = | 478 // 'extension characters' in the title of the web page. |
477 file_util::GetFileExtensionFromPath(suggested_name); | 479 std::wstring suggested_ext; |
| 480 if (!ignore_suggested_ext) |
| 481 suggested_ext = file_util::GetFileExtensionFromPath(suggested_name); |
| 482 |
478 // If we can't get the extension from the suggested_name, we use the default | 483 // If we can't get the extension from the suggested_name, we use the default |
479 // extension passed in. This is to cover cases like when saving a web page, | 484 // extension passed in. This is to cover cases like when saving a web page, |
480 // where we get passed in a name without an extension and a default extension | 485 // where we get passed in a name without an extension and a default extension |
481 // along with it. | 486 // along with it. |
482 if (suggested_ext.empty()) | 487 if (suggested_ext.empty()) |
483 suggested_ext = def_ext; | 488 suggested_ext = def_ext; |
484 | 489 |
485 *final_name = | 490 *final_name = |
486 AppendExtensionIfNeeded(*final_name, filter_selected, suggested_ext); | 491 AppendExtensionIfNeeded(*final_name, filter_selected, suggested_ext); |
487 return true; | 492 return true; |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 } | 897 } |
893 | 898 |
894 ChromeFont GetWindowTitleFont() { | 899 ChromeFont GetWindowTitleFont() { |
895 NONCLIENTMETRICS ncm; | 900 NONCLIENTMETRICS ncm; |
896 win_util::GetNonClientMetrics(&ncm); | 901 win_util::GetNonClientMetrics(&ncm); |
897 ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); | 902 ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); |
898 return ChromeFont::CreateFont(caption_font); | 903 return ChromeFont::CreateFont(caption_font); |
899 } | 904 } |
900 | 905 |
901 } // namespace win_util | 906 } // namespace win_util |
OLD | NEW |