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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 bool ShouldUseVistaFrame() { | 153 bool ShouldUseVistaFrame() { |
154 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) | 154 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) |
155 return false; | 155 return false; |
156 // If composition is not enabled, we behave like on XP. | 156 // If composition is not enabled, we behave like on XP. |
157 BOOL f; | 157 BOOL f; |
158 DwmIsCompositionEnabled(&f); | 158 DwmIsCompositionEnabled(&f); |
159 return !!f; | 159 return !!f; |
160 } | 160 } |
161 | 161 |
162 void ShowItemInFolder(const std::wstring& full_path) { | |
163 std::wstring dir = file_util::GetDirectoryFromPath(full_path); | |
164 if (dir == L"" || !file_util::PathExists(full_path)) | |
165 return; | |
166 | |
167 // ParseDisplayName will fail if the directory is "C:", it must be "C:\\". | |
168 FilePath dir_path(dir); | |
169 file_util::EnsureEndsWithSeparator(&dir_path); | |
170 dir = dir_path.value(); | |
171 | |
172 typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)( | |
173 PCIDLIST_ABSOLUTE pidl_Folder, | |
174 UINT cidl, | |
175 PCUITEMID_CHILD_ARRAY pidls, | |
176 DWORD flags); | |
177 | |
178 static SHOpenFolderAndSelectItemsFuncPtr open_folder_and_select_itemsPtr = | |
179 NULL; | |
180 static bool initialize_open_folder_proc = true; | |
181 if (initialize_open_folder_proc) { | |
182 initialize_open_folder_proc = false; | |
183 // The SHOpenFolderAndSelectItems API is exposed by shell32 version 6 | |
184 // and does not exist in Win2K. We attempt to retrieve this function export | |
185 // from shell32 and if it does not exist, we just invoke ShellExecute to | |
186 // open the folder thus losing the functionality to select the item in | |
187 // the process. | |
188 HMODULE shell32_base = GetModuleHandle(L"shell32.dll"); | |
189 if (!shell32_base) { | |
190 NOTREACHED(); | |
191 return; | |
192 } | |
193 open_folder_and_select_itemsPtr = | |
194 reinterpret_cast<SHOpenFolderAndSelectItemsFuncPtr> | |
195 (GetProcAddress(shell32_base, "SHOpenFolderAndSelectItems")); | |
196 } | |
197 if (!open_folder_and_select_itemsPtr) { | |
198 ShellExecute(NULL, _T("open"), dir.c_str(), NULL, NULL, SW_SHOW); | |
199 return; | |
200 } | |
201 | |
202 CComPtr<IShellFolder> desktop; | |
203 HRESULT hr = SHGetDesktopFolder(&desktop); | |
204 if (FAILED(hr)) | |
205 return; | |
206 | |
207 CoMemReleaser<ITEMIDLIST> dir_item; | |
208 hr = desktop->ParseDisplayName(NULL, NULL, | |
209 const_cast<wchar_t *>(dir.c_str()), | |
210 NULL, &dir_item, NULL); | |
211 if (FAILED(hr)) | |
212 return; | |
213 | |
214 CoMemReleaser<ITEMIDLIST> file_item; | |
215 hr = desktop->ParseDisplayName(NULL, NULL, | |
216 const_cast<wchar_t *>(full_path.c_str()), | |
217 NULL, &file_item, NULL); | |
218 if (FAILED(hr)) | |
219 return; | |
220 | |
221 const ITEMIDLIST* highlight[] = { | |
222 {file_item}, | |
223 }; | |
224 (*open_folder_and_select_itemsPtr)(dir_item, arraysize(highlight), | |
225 highlight, NULL); | |
226 } | |
227 | |
228 // Open an item via a shell execute command. Error code checking and casting | 162 // Open an item via a shell execute command. Error code checking and casting |
229 // explanation: http://msdn2.microsoft.com/en-us/library/ms647732.aspx | 163 // explanation: http://msdn2.microsoft.com/en-us/library/ms647732.aspx |
230 bool OpenItemViaShell(const FilePath& full_path, bool ask_for_app) { | 164 bool OpenItemViaShell(const FilePath& full_path, bool ask_for_app) { |
231 HINSTANCE h = ::ShellExecuteW( | 165 HINSTANCE h = ::ShellExecuteW( |
232 NULL, NULL, full_path.value().c_str(), NULL, | 166 NULL, NULL, full_path.value().c_str(), NULL, |
233 full_path.DirName().value().c_str(), SW_SHOWNORMAL); | 167 full_path.DirName().value().c_str(), SW_SHOWNORMAL); |
234 | 168 |
235 LONG_PTR error = reinterpret_cast<LONG_PTR>(h); | 169 LONG_PTR error = reinterpret_cast<LONG_PTR>(h); |
236 if (error > 32) | 170 if (error > 32) |
237 return true; | 171 return true; |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 } | 845 } |
912 | 846 |
913 ChromeFont GetWindowTitleFont() { | 847 ChromeFont GetWindowTitleFont() { |
914 NONCLIENTMETRICS ncm; | 848 NONCLIENTMETRICS ncm; |
915 win_util::GetNonClientMetrics(&ncm); | 849 win_util::GetNonClientMetrics(&ncm); |
916 ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); | 850 ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); |
917 return ChromeFont::CreateFont(caption_font); | 851 return ChromeFont::CreateFont(caption_font); |
918 } | 852 } |
919 | 853 |
920 } // namespace win_util | 854 } // namespace win_util |
OLD | NEW |