Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfolder_options.cpp
Go to the documentation of this file.
00001 /* 00002 * Open With Context Menu extension 00003 * 00004 * Copyright 2007 Johannes Anderwald <janderwald@reactos.org> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00019 */ 00020 00021 #include <precomp.h> 00022 00023 00024 WINE_DEFAULT_DEBUG_CHANNEL (fprop); 00025 #define MAX_PROPERTY_SHEET_PAGE (32) 00026 00032 00034 00035 typedef struct 00036 { 00037 WCHAR FileExtension[30]; 00038 WCHAR FileDescription[100]; 00039 WCHAR ClassKey[MAX_PATH]; 00040 } FOLDER_FILE_TYPE_ENTRY, *PFOLDER_FILE_TYPE_ENTRY; 00041 00042 typedef struct 00043 { 00044 LPCWSTR szKeyName; 00045 UINT ResourceID; 00046 } FOLDER_VIEW_ENTRY, PFOLDER_VIEW_ENTRY; 00047 /* 00048 static FOLDER_VIEW_ENTRY s_Options[] = 00049 { 00050 { L"AlwaysShowMenus", IDS_ALWAYSSHOWMENUS }, 00051 { L"AutoCheckSelect", -1 }, 00052 { L"ClassicViewState", -1 }, 00053 { L"DontPrettyPath", -1 }, 00054 { L"Filter", -1 }, 00055 { L"FolderContentsInfoTip", IDS_FOLDERCONTENTSTIP }, 00056 { L"FriendlyTree", -1 }, 00057 { L"Hidden", -1, }, 00058 { L"HideFileExt", IDS_HIDEFILEEXT }, 00059 { L"HideIcons", -1}, 00060 { L"IconsOnly", -1}, 00061 { L"ListviewAlphaSelect", -1}, 00062 { L"ListviewShadow", -1}, 00063 { L"ListviewWatermark", -1}, 00064 { L"MapNetDrvBtn", -1}, 00065 { L"PersistBrowsers", -1}, 00066 { L"SeperateProcess", IDS_SEPERATEPROCESS}, 00067 { L"ServerAdminUI", -1}, 00068 { L"SharingWizardOn", IDS_USESHAREWIZARD}, 00069 { L"ShowCompColor", IDS_COMPCOLOR}, 00070 { L"ShowInfoTip", IDS_SHOWINFOTIP}, 00071 { L"ShowPreviewHandlers", -1}, 00072 { L"ShowSuperHidden", IDS_HIDEOSFILES}, 00073 { L"ShowTypeOverlay", -1}, 00074 { L"Start_ShowMyGames", -1}, 00075 { L"StartMenuInit", -1}, 00076 { L"SuperHidden", -1}, 00077 { L"TypeAhead", -1}, 00078 { L"Webview", -1}, 00079 { NULL, -1} 00080 00081 }; 00082 */ 00083 00084 EXTERN_C HPSXA WINAPI SHCreatePropSheetExtArrayEx(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface, IDataObject *pDataObj); 00085 00086 static 00087 INT_PTR 00088 CALLBACK 00089 FolderOptionsGeneralDlg( 00090 HWND hwndDlg, 00091 UINT uMsg, 00092 WPARAM wParam, 00093 LPARAM lParam 00094 ) 00095 { 00096 return FALSE; 00097 } 00098 00099 static 00100 VOID 00101 InitializeFolderOptionsListCtrl(HWND hwndDlg) 00102 { 00103 RECT clientRect; 00104 LVCOLUMNW col; 00105 WCHAR szName[50]; 00106 HWND hDlgCtrl; 00107 00108 hDlgCtrl = GetDlgItem(hwndDlg, 14003); 00109 00110 if (!LoadStringW(shell32_hInstance, IDS_COLUMN_EXTENSION, szName, sizeof(szName) / sizeof(WCHAR))) 00111 szName[0] = 0; 00112 szName[(sizeof(szName)/sizeof(WCHAR))-1] = 0; 00113 00114 GetClientRect(hDlgCtrl, &clientRect); 00115 ZeroMemory(&col, sizeof(LV_COLUMN)); 00116 col.mask = LVCF_SUBITEM | LVCF_WIDTH | LVCF_FMT; 00117 col.iSubItem = 0; 00118 col.pszText = szName; 00119 col.fmt = LVCFMT_LEFT; 00120 col.cx = (clientRect.right - clientRect.left) - GetSystemMetrics(SM_CXVSCROLL); 00121 (void)SendMessageW(hDlgCtrl, LVM_INSERTCOLUMN, 0, (LPARAM)&col); 00122 00123 00124 00125 } 00126 00127 static 00128 INT_PTR 00129 CALLBACK 00130 FolderOptionsViewDlg( 00131 HWND hwndDlg, 00132 UINT uMsg, 00133 WPARAM wParam, 00134 LPARAM lParam 00135 ) 00136 { 00137 switch(uMsg) 00138 { 00139 case WM_INITDIALOG: 00140 InitializeFolderOptionsListCtrl(hwndDlg); 00141 return TRUE; 00142 } 00143 00144 return FALSE; 00145 00146 } 00147 00148 static 00149 VOID 00150 InitializeFileTypesListCtrlColumns(HWND hDlgCtrl) 00151 { 00152 RECT clientRect; 00153 LVCOLUMNW col; 00154 WCHAR szName[50]; 00155 DWORD dwStyle; 00156 int columnSize = 140; 00157 00158 00159 if (!LoadStringW(shell32_hInstance, IDS_COLUMN_EXTENSION, szName, sizeof(szName) / sizeof(WCHAR))) 00160 { 00161 /* default to english */ 00162 wcscpy(szName, L"Extensions"); 00163 } 00164 00165 /* make sure its null terminated */ 00166 szName[(sizeof(szName)/sizeof(WCHAR))-1] = 0; 00167 00168 GetClientRect(hDlgCtrl, &clientRect); 00169 ZeroMemory(&col, sizeof(LV_COLUMN)); 00170 columnSize = 140; //FIXME 00171 col.iSubItem = 0; 00172 col.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM | LVCF_FMT; 00173 col.fmt = LVCFMT_FIXED_WIDTH; 00174 col.cx = columnSize | LVCFMT_LEFT; 00175 col.cchTextMax = wcslen(szName); 00176 col.pszText = szName; 00177 (void)SendMessageW(hDlgCtrl, LVM_INSERTCOLUMNW, 0, (LPARAM)&col); 00178 00179 if (!LoadStringW(shell32_hInstance, IDS_FILE_TYPES, szName, sizeof(szName) / sizeof(WCHAR))) 00180 { 00181 /* default to english */ 00182 wcscpy(szName, L"FileTypes"); 00183 } 00184 00185 col.iSubItem = 1; 00186 col.cx = clientRect.right - clientRect.left - columnSize; 00187 col.cchTextMax = wcslen(szName); 00188 col.pszText = szName; 00189 (void)SendMessageW(hDlgCtrl, LVM_INSERTCOLUMNW, 1, (LPARAM)&col); 00190 00191 /* set full select style */ 00192 dwStyle = (DWORD) SendMessage(hDlgCtrl, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); 00193 dwStyle = dwStyle | LVS_EX_FULLROWSELECT; 00194 SendMessage(hDlgCtrl, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle); 00195 } 00196 00197 INT 00198 FindItem(HWND hDlgCtrl, WCHAR * ItemName) 00199 { 00200 LVFINDINFOW findInfo; 00201 ZeroMemory(&findInfo, sizeof(LVFINDINFOW)); 00202 00203 findInfo.flags = LVFI_STRING; 00204 findInfo.psz = ItemName; 00205 return ListView_FindItem(hDlgCtrl, 0, &findInfo); 00206 } 00207 00208 static 00209 VOID 00210 InsertFileType(HWND hDlgCtrl, WCHAR * szName, PINT iItem, WCHAR * szFile) 00211 { 00212 PFOLDER_FILE_TYPE_ENTRY Entry; 00213 HKEY hKey; 00214 LVITEMW lvItem; 00215 DWORD dwSize; 00216 00217 if (szName[0] != L'.') 00218 { 00219 /* FIXME handle URL protocol handlers */ 00220 return; 00221 } 00222 00223 /* allocate file type entry */ 00224 Entry = (PFOLDER_FILE_TYPE_ENTRY)HeapAlloc(GetProcessHeap(), 0, sizeof(FOLDER_FILE_TYPE_ENTRY)); 00225 00226 if (!Entry) 00227 return; 00228 00229 /* open key */ 00230 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, szName, 0, KEY_READ, &hKey) != ERROR_SUCCESS) 00231 { 00232 HeapFree(GetProcessHeap(), 0, Entry); 00233 return; 00234 } 00235 00236 /* FIXME check for duplicates */ 00237 00238 /* query for the default key */ 00239 dwSize = sizeof(Entry->ClassKey); 00240 if (RegQueryValueExW(hKey, NULL, NULL, NULL, (LPBYTE)Entry->ClassKey, &dwSize) != ERROR_SUCCESS) 00241 { 00242 /* no link available */ 00243 Entry->ClassKey[0] = 0; 00244 } 00245 00246 if (Entry->ClassKey[0]) 00247 { 00248 HKEY hTemp; 00249 /* try open linked key */ 00250 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, Entry->ClassKey, 0, KEY_READ, &hTemp) == ERROR_SUCCESS) 00251 { 00252 /* use linked key */ 00253 RegCloseKey(hKey); 00254 hKey = hTemp; 00255 } 00256 } 00257 00258 /* read friendly type name */ 00259 if (RegLoadMUIStringW(hKey, L"FriendlyTypeName", Entry->FileDescription, sizeof(Entry->FileDescription), NULL, 0, NULL) != ERROR_SUCCESS) 00260 { 00261 /* read file description */ 00262 dwSize = sizeof(Entry->FileDescription); 00263 Entry->FileDescription[0] = 0; 00264 00265 /* read default key */ 00266 RegQueryValueExW(hKey, NULL, NULL, NULL, (LPBYTE)Entry->FileDescription, &dwSize); 00267 } 00268 00269 /* close key */ 00270 RegCloseKey(hKey); 00271 00272 /* convert extension to upper case */ 00273 wcscpy(Entry->FileExtension, szName); 00274 _wcsupr(Entry->FileExtension); 00275 00276 if (!Entry->FileDescription[0]) 00277 { 00278 /* construct default 'FileExtensionFile' */ 00279 wcscpy(Entry->FileDescription, &Entry->FileExtension[1]); 00280 wcscat(Entry->FileDescription, L" "); 00281 wcscat(Entry->FileDescription, szFile); 00282 } 00283 00284 ZeroMemory(&lvItem, sizeof(LVITEMW)); 00285 lvItem.mask = LVIF_TEXT | LVIF_PARAM; 00286 lvItem.iSubItem = 0; 00287 lvItem.pszText = &Entry->FileExtension[1]; 00288 lvItem.iItem = *iItem; 00289 lvItem.lParam = (LPARAM)Entry; 00290 (void)SendMessageW(hDlgCtrl, LVM_INSERTITEMW, 0, (LPARAM)&lvItem); 00291 00292 ZeroMemory(&lvItem, sizeof(LVITEMW)); 00293 lvItem.mask = LVIF_TEXT; 00294 lvItem.pszText = Entry->FileDescription; 00295 lvItem.iItem = *iItem; 00296 lvItem.iSubItem = 1; 00297 00298 (void)SendMessageW(hDlgCtrl, LVM_SETITEMW, 0, (LPARAM)&lvItem); 00299 (*iItem)++; 00300 } 00301 00302 static 00303 int 00304 CALLBACK 00305 ListViewCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) 00306 { 00307 PFOLDER_FILE_TYPE_ENTRY Entry1, Entry2; 00308 00309 Entry1 = (PFOLDER_FILE_TYPE_ENTRY)lParam1; 00310 Entry2 = (PFOLDER_FILE_TYPE_ENTRY)lParam2; 00311 00312 return wcsicmp(Entry1->FileExtension, Entry2->FileExtension); 00313 } 00314 00315 static 00316 BOOL 00317 InitializeFileTypesListCtrl(HWND hwndDlg) 00318 { 00319 HWND hDlgCtrl; 00320 DWORD dwIndex = 0; 00321 WCHAR szName[50]; 00322 WCHAR szFile[100]; 00323 DWORD dwName; 00324 LVITEMW lvItem; 00325 INT iItem = 0; 00326 00327 hDlgCtrl = GetDlgItem(hwndDlg, 14000); 00328 InitializeFileTypesListCtrlColumns(hDlgCtrl); 00329 00330 szFile[0] = 0; 00331 if (!LoadStringW(shell32_hInstance, IDS_SHV_COLUMN1, szFile, sizeof(szFile) / sizeof(WCHAR))) 00332 { 00333 /* default to english */ 00334 wcscpy(szFile, L"File"); 00335 } 00336 szFile[(sizeof(szFile)/sizeof(WCHAR))-1] = 0; 00337 00338 dwName = sizeof(szName) / sizeof(WCHAR); 00339 00340 while(RegEnumKeyExW(HKEY_CLASSES_ROOT, dwIndex++, szName, &dwName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) 00341 { 00342 InsertFileType(hDlgCtrl, szName, &iItem, szFile); 00343 dwName = sizeof(szName) / sizeof(WCHAR); 00344 } 00345 00346 /* sort list */ 00347 ListView_SortItems(hDlgCtrl, ListViewCompareProc, NULL); 00348 00349 /* select first item */ 00350 ZeroMemory(&lvItem, sizeof(LVITEMW)); 00351 lvItem.mask = LVIF_STATE; 00352 lvItem.stateMask = (UINT) - 1; 00353 lvItem.state = LVIS_FOCUSED | LVIS_SELECTED; 00354 lvItem.iItem = 0; 00355 (void)SendMessageW(hDlgCtrl, LVM_SETITEMW, 0, (LPARAM)&lvItem); 00356 00357 return TRUE; 00358 } 00359 00360 static 00361 PFOLDER_FILE_TYPE_ENTRY 00362 FindSelectedItem( 00363 HWND hDlgCtrl) 00364 { 00365 UINT Count, Index; 00366 LVITEMW lvItem; 00367 00368 Count = ListView_GetItemCount(hDlgCtrl); 00369 00370 for (Index = 0; Index < Count; Index++) 00371 { 00372 ZeroMemory(&lvItem, sizeof(LVITEM)); 00373 lvItem.mask = LVIF_PARAM | LVIF_STATE; 00374 lvItem.iItem = Index; 00375 lvItem.stateMask = (UINT) - 1; 00376 00377 if (ListView_GetItem(hDlgCtrl, &lvItem)) 00378 { 00379 if (lvItem.state & LVIS_SELECTED) 00380 return (PFOLDER_FILE_TYPE_ENTRY)lvItem.lParam; 00381 } 00382 } 00383 00384 return NULL; 00385 } 00386 00387 static 00388 INT_PTR 00389 CALLBACK 00390 FolderOptionsFileTypesDlg( 00391 HWND hwndDlg, 00392 UINT uMsg, 00393 WPARAM wParam, 00394 LPARAM lParam 00395 ) 00396 { 00397 LPNMLISTVIEW lppl; 00398 LVITEMW lvItem; 00399 WCHAR Buffer[255], FormatBuffer[255]; 00400 PFOLDER_FILE_TYPE_ENTRY pItem; 00401 OPENASINFO Info; 00402 00403 switch(uMsg) 00404 { 00405 case WM_INITDIALOG: 00406 InitializeFileTypesListCtrl(hwndDlg); 00407 return TRUE; 00408 case WM_COMMAND: 00409 switch(LOWORD(wParam)) 00410 { 00411 case 14006: 00412 pItem = FindSelectedItem(GetDlgItem(hwndDlg, 14000)); 00413 if (pItem) 00414 { 00415 Info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_REGISTER_EXT; 00416 Info.pcszClass = pItem->FileExtension; 00417 SHOpenWithDialog(hwndDlg, &Info); 00418 } 00419 break; 00420 } 00421 00422 break; 00423 case WM_NOTIFY: 00424 lppl = (LPNMLISTVIEW) lParam; 00425 00426 if (lppl->hdr.code == LVN_ITEMCHANGING) 00427 { 00428 ZeroMemory(&lvItem, sizeof(LVITEM)); 00429 lvItem.mask = LVIF_PARAM; 00430 lvItem.iItem = lppl->iItem; 00431 if (!SendMessageW(lppl->hdr.hwndFrom, LVM_GETITEMW, 0, (LPARAM)&lvItem)) 00432 return TRUE; 00433 00434 pItem = (PFOLDER_FILE_TYPE_ENTRY)lvItem.lParam; 00435 if (!pItem) 00436 return TRUE; 00437 00438 if (!(lppl->uOldState & LVIS_FOCUSED) && (lppl->uNewState & LVIS_FOCUSED)) 00439 { 00440 /* new focused item */ 00441 if (!LoadStringW(shell32_hInstance, IDS_FILE_DETAILS, FormatBuffer, sizeof(FormatBuffer) / sizeof(WCHAR))) 00442 { 00443 /* use default english format string */ 00444 wcscpy(FormatBuffer, L"Details for '%s' extension"); 00445 } 00446 00447 /* format buffer */ 00448 swprintf(Buffer, FormatBuffer, &pItem->FileExtension[1]); 00449 /* update dialog */ 00450 SetDlgItemTextW(hwndDlg, 14003, Buffer); 00451 00452 if (!LoadStringW(shell32_hInstance, IDS_FILE_DETAILSADV, FormatBuffer, sizeof(FormatBuffer) / sizeof(WCHAR))) 00453 { 00454 /* use default english format string */ 00455 wcscpy(FormatBuffer, L"Files with extension '%s' are of type '%s'. To change settings that affect all '%s' files, click Advanced."); 00456 } 00457 /* format buffer */ 00458 swprintf(Buffer, FormatBuffer, &pItem->FileExtension[1], &pItem->FileDescription[0], &pItem->FileDescription[0]); 00459 /* update dialog */ 00460 SetDlgItemTextW(hwndDlg, 14007, Buffer); 00461 } 00462 } 00463 break; 00464 } 00465 00466 return FALSE; 00467 } 00468 00469 static 00470 VOID 00471 ShowFolderOptionsDialog(HWND hWnd, HINSTANCE hInst) 00472 { 00473 PROPSHEETHEADERW pinfo; 00474 HPROPSHEETPAGE hppages[3]; 00475 HPROPSHEETPAGE hpage; 00476 UINT num_pages = 0; 00477 WCHAR szOptions[100]; 00478 00479 hpage = SH_CreatePropertySheetPage(IDD_FOLDER_OPTIONS_GENERAL, FolderOptionsGeneralDlg, 0, NULL); 00480 if (hpage) 00481 hppages[num_pages++] = hpage; 00482 00483 hpage = SH_CreatePropertySheetPage(IDD_FOLDER_OPTIONS_VIEW, FolderOptionsViewDlg, 0, NULL); 00484 if (hpage) 00485 hppages[num_pages++] = hpage; 00486 00487 hpage = SH_CreatePropertySheetPage(IDD_FOLDER_OPTIONS_FILETYPES, FolderOptionsFileTypesDlg, 0, NULL); 00488 if (hpage) 00489 hppages[num_pages++] = hpage; 00490 00491 szOptions[0] = L'\0'; 00492 LoadStringW(shell32_hInstance, IDS_FOLDER_OPTIONS, szOptions, sizeof(szOptions) / sizeof(WCHAR)); 00493 szOptions[(sizeof(szOptions)/sizeof(WCHAR))-1] = L'\0'; 00494 00495 memset(&pinfo, 0x0, sizeof(PROPSHEETHEADERW)); 00496 pinfo.dwSize = sizeof(PROPSHEETHEADERW); 00497 pinfo.dwFlags = PSH_NOCONTEXTHELP; 00498 pinfo.nPages = num_pages; 00499 pinfo.phpage = hppages; 00500 pinfo.pszCaption = szOptions; 00501 00502 PropertySheetW(&pinfo); 00503 } 00504 00505 static 00506 VOID 00507 Options_RunDLLCommon(HWND hWnd, HINSTANCE hInst, int fOptions, DWORD nCmdShow) 00508 { 00509 switch(fOptions) 00510 { 00511 case 0: 00512 ShowFolderOptionsDialog(hWnd, hInst); 00513 break; 00514 case 1: 00515 // show taskbar options dialog 00516 FIXME("notify explorer to show taskbar options dialog"); 00517 //PostMessage(GetShellWindow(), WM_USER+22, fOptions, 0); 00518 break; 00519 default: 00520 FIXME("unrecognized options id %d\n", fOptions); 00521 } 00522 } 00523 00524 /************************************************************************* 00525 * Options_RunDLL (SHELL32.@) 00526 */ 00527 EXTERN_C VOID WINAPI Options_RunDLL(HWND hWnd, HINSTANCE hInst, LPCSTR cmd, DWORD nCmdShow) 00528 { 00529 Options_RunDLLCommon(hWnd, hInst, StrToIntA(cmd), nCmdShow); 00530 } 00531 00532 /************************************************************************* 00533 * Options_RunDLLA (SHELL32.@) 00534 */ 00535 EXTERN_C VOID WINAPI Options_RunDLLA(HWND hWnd, HINSTANCE hInst, LPCSTR cmd, DWORD nCmdShow) 00536 { 00537 Options_RunDLLCommon(hWnd, hInst, StrToIntA(cmd), nCmdShow); 00538 } 00539 00540 /************************************************************************* 00541 * Options_RunDLLW (SHELL32.@) 00542 */ 00543 EXTERN_C VOID WINAPI Options_RunDLLW(HWND hWnd, HINSTANCE hInst, LPCWSTR cmd, DWORD nCmdShow) 00544 { 00545 Options_RunDLLCommon(hWnd, hInst, StrToIntW(cmd), nCmdShow); 00546 } Generated on Sat May 26 2012 04:24:55 for ReactOS by
1.7.6.1
|