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 | 10 |
10 namespace ui { | 11 namespace ui { |
11 namespace win { | 12 namespace win { |
12 | 13 |
14 namespace { | |
15 | |
16 // Ensures that the Save As dialog is on-screen. | |
17 UINT_PTR CALLBACK SaveAsDialogHook(HWND dialog, UINT message, | |
18 WPARAM wparam, LPARAM lparam) { | |
19 static const UINT kPrivateMessage = 0x2F3F; | |
20 switch (message) { | |
21 case WM_INITDIALOG: { | |
22 // Do nothing here. Just post a message to defer actual processing. | |
23 ::PostMessage(dialog, kPrivateMessage, 0, 0); | |
24 return TRUE; | |
25 } | |
26 case kPrivateMessage: { | |
27 // The dialog box is the parent of the current handle. | |
28 HWND real_dialog = ::GetParent(dialog); | |
29 | |
30 // Retrieve the final size. | |
31 RECT dialog_rect; | |
32 ::GetWindowRect(real_dialog, &dialog_rect); | |
33 | |
34 // Verify that the upper left corner is visible. | |
35 POINT point = { dialog_rect.left, dialog_rect.top }; | |
36 HMONITOR monitor1 = ::MonitorFromPoint(point, MONITOR_DEFAULTTONULL); | |
sky
2014/08/19 17:02:51
Why not MonitorFromWindow, get the work area and c
erikwright (departed)
2014/08/19 17:09:15
I have no idea. This code is moved verbatim from i
| |
37 point.x = dialog_rect.right; | |
38 point.y = dialog_rect.bottom; | |
39 | |
40 // Verify that the lower right corner is visible. | |
41 HMONITOR monitor2 = ::MonitorFromPoint(point, MONITOR_DEFAULTTONULL); | |
42 if (monitor1 && monitor2) | |
43 return 0; | |
44 | |
45 // Some part of the dialog box is not visible, fix it by moving is to the | |
46 // client rect position of the browser window. | |
47 HWND parent_window = ::GetParent(real_dialog); | |
48 if (!parent_window) | |
49 return 0; | |
50 WINDOWINFO parent_info; | |
51 parent_info.cbSize = sizeof(WINDOWINFO); | |
52 ::GetWindowInfo(parent_window, &parent_info); | |
53 ::SetWindowPos( | |
54 real_dialog, | |
55 NULL, | |
56 parent_info.rcClient.left, | |
57 parent_info.rcClient.top, | |
58 0, | |
59 0, // Size. | |
60 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER); | |
61 | |
62 return 0; | |
63 } | |
64 } | |
65 return 0; | |
66 } | |
67 | |
68 } // namespace | |
69 | |
13 OpenFileName::OpenFileName(HWND parent_window, DWORD flags) { | 70 OpenFileName::OpenFileName(HWND parent_window, DWORD flags) { |
14 ::ZeroMemory(&openfilename_, sizeof(openfilename_)); | 71 ::ZeroMemory(&openfilename_, sizeof(openfilename_)); |
15 openfilename_.lStructSize = sizeof(openfilename_); | 72 openfilename_.lStructSize = sizeof(openfilename_); |
16 | 73 |
17 // According to http://support.microsoft.com/?scid=kb;en-us;222003&x=8&y=12, | 74 // According to http://support.microsoft.com/?scid=kb;en-us;222003&x=8&y=12, |
18 // The lpstrFile Buffer MUST be NULL Terminated. | 75 // The lpstrFile Buffer MUST be NULL Terminated. |
19 filename_buffer_[0] = 0; | 76 filename_buffer_[0] = 0; |
20 openfilename_.lpstrFile = filename_buffer_; | 77 openfilename_.lpstrFile = filename_buffer_; |
21 openfilename_.nMaxFile = arraysize(filename_buffer_); | 78 openfilename_.nMaxFile = arraysize(filename_buffer_); |
22 | 79 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 | 122 |
66 if (initial_filename.empty()) | 123 if (initial_filename.empty()) |
67 return; | 124 return; |
68 | 125 |
69 // The filename is ignored if no initial directory is supplied. | 126 // The filename is ignored if no initial directory is supplied. |
70 base::wcslcpy(filename_buffer_, | 127 base::wcslcpy(filename_buffer_, |
71 initial_filename.value().c_str(), | 128 initial_filename.value().c_str(), |
72 arraysize(filename_buffer_)); | 129 arraysize(filename_buffer_)); |
73 } | 130 } |
74 | 131 |
132 void OpenFileName::MaybeInstallWindowPositionHookForSaveAsOnXP() { | |
133 if (base::win::GetVersion() >= base::win::VERSION_VISTA) | |
134 return; | |
135 | |
136 openfilename_.Flags |= OFN_ENABLEHOOK; | |
137 DCHECK(!openfilename_.lpfnHook); | |
138 openfilename_.lpfnHook = &SaveAsDialogHook; | |
139 } | |
140 | |
75 base::FilePath OpenFileName::GetSingleResult() { | 141 base::FilePath OpenFileName::GetSingleResult() { |
76 base::FilePath directory; | 142 base::FilePath directory; |
77 std::vector<base::FilePath> filenames; | 143 std::vector<base::FilePath> filenames; |
78 GetResult(&directory, &filenames); | 144 GetResult(&directory, &filenames); |
79 if (filenames.size() != 1) | 145 if (filenames.size() != 1) |
80 return base::FilePath(); | 146 return base::FilePath(); |
81 return directory.Append(filenames[0]); | 147 return directory.Append(filenames[0]); |
82 } | 148 } |
83 | 149 |
84 void OpenFileName::GetResult(base::FilePath* directory, | 150 void OpenFileName::GetResult(base::FilePath* directory, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 MakeTuple(base::string16(display_string, display_string_end), | 216 MakeTuple(base::string16(display_string, display_string_end), |
151 base::string16(pattern, pattern_end))); | 217 base::string16(pattern, pattern_end))); |
152 display_string = pattern_end + 1; | 218 display_string = pattern_end + 1; |
153 } | 219 } |
154 | 220 |
155 return filters; | 221 return filters; |
156 } | 222 } |
157 | 223 |
158 } // namespace win | 224 } // namespace win |
159 } // namespace ui | 225 } // namespace ui |
OLD | NEW |