/* * Winefile * * Copyright 2000, 2003, 2004, 2005, 2008 Martin Fuchs * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #include "winefile.h" /* utility function to query the state of check boxes */ static inline BOOL get_check(HWND hwnd, INT id) { return BST_CHECKED&SendMessageW(GetDlgItem(hwnd, id), BM_GETSTATE, 0, 0); } /* utility funtion to set the state of check boxes */ static inline INT set_check(HWND hwnd, INT id, BOOL on) { return SendMessageW(GetDlgItem(hwnd, id), BM_SETCHECK, on?BST_CHECKED:BST_UNCHECKED, 0); } /* display dialog to choose the display font */ inline void choose_font(HWND hwnd) { WCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN]; CHOOSEFONTW chFont; LOGFONTW lFont; HDC hdc = GetDC(hwnd); chFont.lStructSize = sizeof(CHOOSEFONT); chFont.hwndOwner = hwnd; chFont.hDC = NULL; chFont.lpLogFont = &lFont; chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL; chFont.rgbColors = RGB(0,0,0); chFont.lCustData = 0; chFont.lpfnHook = NULL; chFont.lpTemplateName = NULL; chFont.hInstance = Globals.hInstance; chFont.lpszStyle = NULL; chFont.nFontType = SIMULATED_FONTTYPE; chFont.nSizeMin = 0; chFont.nSizeMax = 24; if (ChooseFontW(&chFont)) { HWND childWnd; HFONT hFontOld; DeleteObject(Globals.hfont); Globals.hfont = CreateFontIndirectW(&lFont); hFontOld = SelectObject(hdc, Globals.hfont); GetTextExtentPoint32(hdc, sSpace, 1, &Globals.spaceSize); /* change font in all open child windows */ for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) { ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(childWnd, GWLP_USERDATA); SendMessageW(child->left.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE); SendMessageW(child->right.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE); SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3)); SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3)); InvalidateRect(child->left.hwnd, NULL, TRUE); InvalidateRect(child->right.hwnd, NULL, TRUE); } SelectObject(hdc, hFontOld); } else if (CommDlgExtendedError()) { LoadStringW(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN); LoadStringW(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN); MessageBoxW(hwnd, dlg_info, dlg_name, MB_OK); } ReleaseDC(hwnd, hdc); } /* dialog box to edit the current filter settings */ INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam) { static struct FilterDialog* dlg; switch(nmsg) { case WM_INITDIALOG: dlg = (struct FilterDialog*) lparam; SetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern); set_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES, dlg->flags&TF_DIRECTORIES); set_check(hwnd, IDC_VIEW_TYPE_PROGRAMS, dlg->flags&TF_PROGRAMS); set_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS, dlg->flags&TF_DOCUMENTS); set_check(hwnd, IDC_VIEW_TYPE_OTHERS, dlg->flags&TF_OTHERS); set_check(hwnd, IDC_VIEW_TYPE_HIDDEN, dlg->flags&TF_HIDDEN); return 1; case WM_COMMAND: { int id = (int)wparam; if (id == IDOK) { int flags = 0; GetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH); flags |= get_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES) ? TF_DIRECTORIES : 0; flags |= get_check(hwnd, IDC_VIEW_TYPE_PROGRAMS) ? TF_PROGRAMS : 0; flags |= get_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS) ? TF_DOCUMENTS : 0; flags |= get_check(hwnd, IDC_VIEW_TYPE_OTHERS) ? TF_OTHERS : 0; flags |= get_check(hwnd, IDC_VIEW_TYPE_HIDDEN) ? TF_HIDDEN : 0; dlg->flags = flags; EndDialog(hwnd, id); } else if (id == IDCANCEL) EndDialog(hwnd, id); return 1;} } return 0; } /* "Execute ..." dialog box message handler */ INT_PTR CALLBACK ExecuteDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam) { static struct ExecuteDialog* dlg; switch(nmsg) { case WM_INITDIALOG: dlg = (struct ExecuteDialog*) lparam; return 1; case WM_COMMAND: { int id = (int)wparam; if (id == IDOK) { GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH); dlg->cmdshow = get_check(hwnd, 214) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL; EndDialog(hwnd, id); } else if (id == IDCANCEL) EndDialog(hwnd, id); return 1;} } return 0; } /* dialog box message handler to prompt for target paths */ INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam) { TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN]; switch(nmsg) { case WM_INITDIALOG: SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam); SetWindowText(GetDlgItem(hwnd, 201), (LPCTSTR)lparam); return 1; case WM_COMMAND: { int id = (int)wparam; switch(id) { case IDOK: { LPTSTR dest = (LPTSTR) GetWindowLongPtr(hwnd, GWLP_USERDATA); GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH); EndDialog(hwnd, id); break;} case IDCANCEL: EndDialog(hwnd, id); break; case 254: MessageBox(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK); break; } return 1; } } return 0; } struct PropertiesDialog { TCHAR path[MAX_PATH]; Entry entry; void* pVersionData; }; /* Structure used to store enumerated languages and code pages. */ struct LANGANDCODEPAGE { WORD wLanguage; WORD wCodePage; } *lpTranslate; static LPCSTR InfoStrings[] = { "Comments", "CompanyName", "FileDescription", "FileVersion", "InternalName", "LegalCopyright", "LegalTrademarks", "OriginalFilename", "PrivateBuild", "ProductName", "ProductVersion", "SpecialBuild", NULL }; /* callback function to enumerate resource languages */ static void PropDlg_DisplayValue(HWND hlbox, HWND hedit) { int idx = ListBox_GetCurSel(hlbox); if (idx != LB_ERR) { LPCTSTR pValue = (LPCTSTR) ListBox_GetItemData(hlbox, idx); if (pValue) SetWindowText(hedit, pValue); } } /* read version and language information from resources and display in the dialog */ static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCTSTR strFilename) { static TCHAR sBackSlash[] = {'\\','\0'}; static TCHAR sTranslation[] = {'\\','V','a','r','F','i','l','e','I','n','f','o','\\','T','r','a','n','s','l','a','t','i','o','n','\0'}; static TCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\', '%','0','4','x','%','0','4','x','\\','%','s','\0'}; DWORD dwVersionDataLen = GetFileVersionInfoSize((LPTSTR)strFilename, NULL); /* VC6 and MinGW headers use LPTSTR instead of LPCTSTR */ if (dwVersionDataLen) { dlg->pVersionData = heap_alloc(dwVersionDataLen); if (GetFileVersionInfo((LPTSTR)strFilename, 0, dwVersionDataLen, dlg->pVersionData)) { /* VC6 and MinGW headers use LPTSTR instead of LPCTSTR */ LPVOID pVal; UINT nValLen; if (VerQueryValue(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) { if (nValLen == sizeof(VS_FIXEDFILEINFO)) { VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal; char buffer[BUFFER_LEN]; sprintf(buffer, "%d.%d.%d.%d", HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS), HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS)); SetDlgItemTextA(hwnd, IDC_STATIC_PROP_VERSION, buffer); } } /* Read the list of languages and code pages. */ if (VerQueryValue(dlg->pVersionData, sTranslation, &pVal, &nValLen)) { struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal; struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen); HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES); /* Read the file description for each language and code page. */ for(; pTranslatewLanguage, pTranslate->wCodePage, infoStr); /* Retrieve file description for language and code page */ if (VerQueryValue(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) { int idx = ListBox_AddString(hlbox, infoStr); (void)ListBox_SetItemData(hlbox, idx, pTxt); } } } (void)ListBox_SetCurSel(hlbox, 0); PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES)); } } } } /* Properties dialog box message handler */ static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam) { static struct PropertiesDialog* dlg; switch(nmsg) { case WM_INITDIALOG: { static const TCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'}; TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN]; LPWIN32_FIND_DATA pWFD; ULONGLONG size; dlg = (struct PropertiesDialog*) lparam; pWFD = (LPWIN32_FIND_DATA) &dlg->entry.data; GetWindowText(hwnd, b1, MAX_PATH); wsprintf(b2, b1, pWFD->cFileName); SetWindowText(hwnd, b2); format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME); SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1); size = ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow; _stprintf(b1, sLongNumFmt, size); wsprintf(b2, sByteFmt, b1); SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2); SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName); SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path); set_check(hwnd, IDC_CHECK_READONLY, pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY); set_check(hwnd, IDC_CHECK_ARCHIVE, pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE); set_check(hwnd, IDC_CHECK_COMPRESSED, pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED); set_check(hwnd, IDC_CHECK_HIDDEN, pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN); set_check(hwnd, IDC_CHECK_SYSTEM, pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM); CheckForFileInfo(dlg, hwnd, dlg->path); return 1;} case WM_COMMAND: { int id = (int)wparam; switch(HIWORD(wparam)) { case LBN_SELCHANGE: { HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES); PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES)); break; } case BN_CLICKED: if (id==IDOK || id==IDCANCEL) EndDialog(hwnd, id); } return 1;} case WM_NCDESTROY: heap_free(dlg->pVersionData); dlg->pVersionData = NULL; break; } return 0; } /* Display the Properties dialog. */ void show_properties_dlg(Entry* entry, HWND hwnd) { struct PropertiesDialog dlg; memset(&dlg, 0, sizeof(struct PropertiesDialog)); get_path(entry, dlg.path); memcpy(&dlg.entry, entry, sizeof(Entry)); DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg); }