dialogs.c

Go to the documentation of this file.
00001 /*
00002  * Winefile
00003  *
00004  * Copyright 2000, 2003, 2004, 2005, 2008 Martin Fuchs
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 "winefile.h"
00022 
00023 
00024 /* utility function to query the state of check boxes */
00025 static inline BOOL get_check(HWND hwnd, INT id)
00026 {
00027     return BST_CHECKED&SendMessageW(GetDlgItem(hwnd, id), BM_GETSTATE, 0, 0);
00028 }
00029 
00030 /* utility funtion to set the state of check boxes */
00031 static inline INT set_check(HWND hwnd, INT id, BOOL on)
00032 {
00033     return SendMessageW(GetDlgItem(hwnd, id), BM_SETCHECK, on?BST_CHECKED:BST_UNCHECKED, 0);
00034 }
00035 
00036 
00037 /* display dialog to choose the display font */
00038 inline void choose_font(HWND hwnd)
00039 {
00040     WCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN];
00041     CHOOSEFONTW chFont;
00042     LOGFONTW lFont;
00043 
00044     HDC hdc = GetDC(hwnd);
00045     chFont.lStructSize = sizeof(CHOOSEFONT);
00046     chFont.hwndOwner = hwnd;
00047     chFont.hDC = NULL;
00048     chFont.lpLogFont = &lFont;
00049     chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL;
00050     chFont.rgbColors = RGB(0,0,0);
00051     chFont.lCustData = 0;
00052     chFont.lpfnHook = NULL;
00053     chFont.lpTemplateName = NULL;
00054     chFont.hInstance = Globals.hInstance;
00055     chFont.lpszStyle = NULL;
00056     chFont.nFontType = SIMULATED_FONTTYPE;
00057     chFont.nSizeMin = 0;
00058     chFont.nSizeMax = 24;
00059 
00060     if (ChooseFontW(&chFont)) {
00061         HWND childWnd;
00062         HFONT hFontOld;
00063 
00064         DeleteObject(Globals.hfont);
00065         Globals.hfont = CreateFontIndirectW(&lFont);
00066         hFontOld = SelectObject(hdc, Globals.hfont);
00067         GetTextExtentPoint32(hdc, sSpace, 1, &Globals.spaceSize);
00068 
00069         /* change font in all open child windows */
00070         for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
00071             ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(childWnd, GWLP_USERDATA);
00072             SendMessageW(child->left.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
00073             SendMessageW(child->right.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
00074             SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
00075             SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
00076             InvalidateRect(child->left.hwnd, NULL, TRUE);
00077             InvalidateRect(child->right.hwnd, NULL, TRUE);
00078         }
00079 
00080         SelectObject(hdc, hFontOld);
00081     }
00082     else if (CommDlgExtendedError()) {
00083         LoadStringW(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
00084         LoadStringW(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
00085         MessageBoxW(hwnd, dlg_info, dlg_name, MB_OK);
00086     }
00087 
00088     ReleaseDC(hwnd, hdc);
00089 }
00090 
00091 
00092 /* dialog box to edit the current filter settings */
00093 
00094 INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
00095 {
00096     static struct FilterDialog* dlg;
00097 
00098     switch(nmsg) {
00099         case WM_INITDIALOG:
00100             dlg = (struct FilterDialog*) lparam;
00101             SetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
00102             set_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES, dlg->flags&TF_DIRECTORIES);
00103             set_check(hwnd, IDC_VIEW_TYPE_PROGRAMS, dlg->flags&TF_PROGRAMS);
00104             set_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS, dlg->flags&TF_DOCUMENTS);
00105             set_check(hwnd, IDC_VIEW_TYPE_OTHERS, dlg->flags&TF_OTHERS);
00106             set_check(hwnd, IDC_VIEW_TYPE_HIDDEN, dlg->flags&TF_HIDDEN);
00107             return 1;
00108 
00109         case WM_COMMAND: {
00110             int id = (int)wparam;
00111 
00112             if (id == IDOK) {
00113                 int flags = 0;
00114 
00115                 GetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
00116 
00117                 flags |= get_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES) ? TF_DIRECTORIES : 0;
00118                 flags |= get_check(hwnd, IDC_VIEW_TYPE_PROGRAMS) ? TF_PROGRAMS : 0;
00119                 flags |= get_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS) ? TF_DOCUMENTS : 0;
00120                 flags |= get_check(hwnd, IDC_VIEW_TYPE_OTHERS) ? TF_OTHERS : 0;
00121                 flags |= get_check(hwnd, IDC_VIEW_TYPE_HIDDEN) ? TF_HIDDEN : 0;
00122 
00123                 dlg->flags = flags;
00124 
00125                 EndDialog(hwnd, id);
00126             } else if (id == IDCANCEL)
00127                 EndDialog(hwnd, id);
00128 
00129             return 1;}
00130     }
00131 
00132     return 0;
00133 }
00134 
00135 
00136 /* "Execute ..." dialog box message handler */
00137 
00138 INT_PTR CALLBACK ExecuteDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
00139 {
00140     static struct ExecuteDialog* dlg;
00141 
00142     switch(nmsg) {
00143         case WM_INITDIALOG:
00144             dlg = (struct ExecuteDialog*) lparam;
00145             return 1;
00146 
00147         case WM_COMMAND: {
00148             int id = (int)wparam;
00149 
00150             if (id == IDOK) {
00151                 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
00152                 dlg->cmdshow = get_check(hwnd, 214) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL;
00153                 EndDialog(hwnd, id);
00154             } else if (id == IDCANCEL)
00155                 EndDialog(hwnd, id);
00156 
00157             return 1;}
00158     }
00159 
00160     return 0;
00161 }
00162 
00163 
00164 /* dialog box message handler to prompt for target paths */
00165 
00166 INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
00167 {
00168     TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
00169 
00170     switch(nmsg) {
00171         case WM_INITDIALOG:
00172             SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
00173             SetWindowText(GetDlgItem(hwnd, 201), (LPCTSTR)lparam);
00174             return 1;
00175 
00176         case WM_COMMAND: {
00177             int id = (int)wparam;
00178 
00179             switch(id) {
00180               case IDOK: {
00181                 LPTSTR dest = (LPTSTR) GetWindowLongPtr(hwnd, GWLP_USERDATA);
00182                 GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
00183                 EndDialog(hwnd, id);
00184                 break;}
00185 
00186               case IDCANCEL:
00187                 EndDialog(hwnd, id);
00188                 break;
00189 
00190               case 254:
00191                 MessageBox(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
00192                 break;
00193             }
00194 
00195             return 1;
00196         }
00197     }
00198 
00199     return 0;
00200 }
00201 
00202 
00203 struct PropertiesDialog {
00204     TCHAR   path[MAX_PATH];
00205     Entry   entry;
00206     void*   pVersionData;
00207 };
00208 
00209 /* Structure used to store enumerated languages and code pages. */
00210 struct LANGANDCODEPAGE {
00211     WORD wLanguage;
00212     WORD wCodePage;
00213 } *lpTranslate;
00214 
00215 static LPCSTR InfoStrings[] = {
00216     "Comments",
00217     "CompanyName",
00218     "FileDescription",
00219     "FileVersion",
00220     "InternalName",
00221     "LegalCopyright",
00222     "LegalTrademarks",
00223     "OriginalFilename",
00224     "PrivateBuild",
00225     "ProductName",
00226     "ProductVersion",
00227     "SpecialBuild",
00228     NULL
00229 };
00230 
00231 /* callback function to enumerate resource languages */
00232 static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
00233 {
00234     int idx = ListBox_GetCurSel(hlbox);
00235 
00236     if (idx != LB_ERR) {
00237         LPCTSTR pValue = (LPCTSTR) ListBox_GetItemData(hlbox, idx);
00238 
00239         if (pValue)
00240             SetWindowText(hedit, pValue);
00241     }
00242 }
00243 
00244 /* read version and language information from resources and display in the dialog */
00245 static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCTSTR strFilename)
00246 {
00247     static TCHAR sBackSlash[] = {'\\','\0'};
00248     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'};
00249     static TCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
00250                                         '%','0','4','x','%','0','4','x','\\','%','s','\0'};
00251     DWORD dwVersionDataLen = GetFileVersionInfoSize((LPTSTR)strFilename, NULL); /* VC6 and MinGW headers use LPTSTR instead of LPCTSTR */
00252 
00253     if (dwVersionDataLen) {
00254         dlg->pVersionData = heap_alloc(dwVersionDataLen);
00255 
00256         if (GetFileVersionInfo((LPTSTR)strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {  /* VC6 and MinGW headers use LPTSTR instead of LPCTSTR */
00257             LPVOID pVal;
00258             UINT nValLen;
00259 
00260             if (VerQueryValue(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
00261                 if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
00262                     VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
00263                     char buffer[BUFFER_LEN];
00264 
00265                     sprintf(buffer, "%d.%d.%d.%d",
00266                         HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
00267                         HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
00268 
00269                     SetDlgItemTextA(hwnd, IDC_STATIC_PROP_VERSION, buffer);
00270                 }
00271             }
00272 
00273             /* Read the list of languages and code pages. */
00274             if (VerQueryValue(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
00275                 struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
00276                 struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
00277 
00278                 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
00279 
00280                 /* Read the file description for each language and code page. */
00281                 for(; pTranslate<pEnd; ++pTranslate) {
00282                     LPCSTR* p;
00283 
00284                     for(p=InfoStrings; *p; ++p) {
00285                         TCHAR subblock[200];
00286 #ifdef UNICODE
00287                         TCHAR infoStr[100];
00288 #endif
00289                         LPCTSTR pTxt;
00290                         UINT nValLen;
00291 
00292                         LPCSTR pInfoString = *p;
00293 #ifdef UNICODE
00294                         MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
00295 #else
00296 #define infoStr pInfoString
00297 #endif
00298                         wsprintf(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
00299 
00300                         /* Retrieve file description for language and code page */
00301                         if (VerQueryValue(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
00302                             int idx = ListBox_AddString(hlbox, infoStr);
00303                             (void)ListBox_SetItemData(hlbox, idx, pTxt);
00304                         }
00305                     }
00306                 }
00307 
00308                 (void)ListBox_SetCurSel(hlbox, 0);
00309 
00310                 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
00311             }
00312         }
00313     }
00314 }
00315 
00316 /* Properties dialog box message handler */
00317 static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
00318 {
00319     static struct PropertiesDialog* dlg;
00320 
00321     switch(nmsg) {
00322         case WM_INITDIALOG: {
00323             static const TCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
00324             TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
00325             LPWIN32_FIND_DATA pWFD;
00326             ULONGLONG size;
00327 
00328             dlg = (struct PropertiesDialog*) lparam;
00329             pWFD = (LPWIN32_FIND_DATA) &dlg->entry.data;
00330 
00331             GetWindowText(hwnd, b1, MAX_PATH);
00332             wsprintf(b2, b1, pWFD->cFileName);
00333             SetWindowText(hwnd, b2);
00334 
00335             format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
00336             SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
00337 
00338             size = ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow;
00339             _stprintf(b1, sLongNumFmt, size);
00340             wsprintf(b2, sByteFmt, b1);
00341             SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
00342 
00343             SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
00344             SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
00345 
00346             set_check(hwnd, IDC_CHECK_READONLY, pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY);
00347             set_check(hwnd, IDC_CHECK_ARCHIVE, pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE);
00348             set_check(hwnd, IDC_CHECK_COMPRESSED, pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED);
00349             set_check(hwnd, IDC_CHECK_HIDDEN, pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN);
00350             set_check(hwnd, IDC_CHECK_SYSTEM, pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM);
00351 
00352             CheckForFileInfo(dlg, hwnd, dlg->path);
00353             return 1;}
00354 
00355         case WM_COMMAND: {
00356             int id = (int)wparam;
00357 
00358             switch(HIWORD(wparam)) {
00359               case LBN_SELCHANGE: {
00360                 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
00361                 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
00362                 break;
00363               }
00364 
00365               case BN_CLICKED:
00366                 if (id==IDOK || id==IDCANCEL)
00367                     EndDialog(hwnd, id);
00368             }
00369 
00370             return 1;}
00371 
00372         case WM_NCDESTROY:
00373             heap_free(dlg->pVersionData);
00374             dlg->pVersionData = NULL;
00375             break;
00376     }
00377 
00378     return 0;
00379 }
00380 
00381 /* Display the Properties dialog. */
00382 void show_properties_dlg(Entry* entry, HWND hwnd)
00383 {
00384     struct PropertiesDialog dlg;
00385 
00386     memset(&dlg, 0, sizeof(struct PropertiesDialog));
00387     get_path(entry, dlg.path);
00388     memcpy(&dlg.entry, entry, sizeof(Entry));
00389 
00390     DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
00391 }

Winefile Source Code Documentation
generated on 15.09.2008 by doxygen

Winefile Homepage