Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfontdlg.c
Go to the documentation of this file.
00001 /* 00002 * COMMDLG - Font Dialog 00003 * 00004 * Copyright 1994 Martin Ayotte 00005 * Copyright 1996 Albrecht Kleine 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 #include <ctype.h> 00023 #include <stdlib.h> 00024 #include <stdarg.h> 00025 #include <stdio.h> 00026 #include <string.h> 00027 #include "windef.h" 00028 #include "winbase.h" 00029 #include "winnls.h" 00030 #include "wingdi.h" 00031 #include "winuser.h" 00032 #include "commdlg.h" 00033 #include "dlgs.h" 00034 #include "wine/debug.h" 00035 #include "cderr.h" 00036 #include "cdlg.h" 00037 00038 WINE_DEFAULT_DEBUG_CHANNEL(commdlg); 00039 00040 typedef struct 00041 { 00042 HWND hWnd1; 00043 HWND hWnd2; 00044 LPCHOOSEFONTW lpcf32w; 00045 int added; 00046 } CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT; 00047 00048 00049 static const WCHAR strWineFontData[] = {'_','_','W','I','N','E','_','F','O','N','T','D','L','G','D','A','T','A',0}; 00050 static const WCHAR strWineFontData_a[] = 00051 {'_','_','W','I','N','E','_','F','O','N','T','D','L','G','D','A','T','A','_','A',0}; 00052 static const WCHAR chooseFontW[] = {'C','H','O','O','S','E','_','F','O','N','T',0}; 00053 00054 /* image list with TrueType bitmaps and more */ 00055 static HIMAGELIST himlTT = 0; 00056 #define TTBITMAP_XSIZE 20 /* x-size of the bitmaps */ 00057 00058 static INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 00059 static INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 00060 00061 /* There is a table here of all charsets, and the sample text for each. 00062 * There is a second table that translates a charset into an index into 00063 * the first table. 00064 */ 00065 00066 #define CI(cs) ((IDS_CHARSET_##cs)-IDS_CHARSET_ANSI) 00067 00068 00069 static const WCHAR stWestern[]={'A','a','B','b','Y','y','Z','z',0}; /* Western and default */ 00070 static const WCHAR stSymbol[]={'S','y','m','b','o','l',0}; /* Symbol */ 00071 static const WCHAR stShiftJis[]={'A','a',0x3042,0x3041,0x30a2,0x30a1,0x4e9c,0x5b87,0}; /* Shift JIS */ 00072 static const WCHAR stHangul[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Hangul */ 00073 static const WCHAR stGB2312[]={0x5fae,0x8f6f,0x4e2d,0x6587,0x8f6f,0x4ef6,0}; /* GB2312 */ 00074 static const WCHAR stBIG5[]={0x4e2d,0x6587,0x5b57,0x578b,0x7bc4,0x4f8b,0}; /* BIG5 */ 00075 static const WCHAR stGreek[]={'A','a','B','b',0x0391,0x03b1,0x0392,0x03b2,0}; /* Greek */ 00076 static const WCHAR stTurkish[]={'A','a','B','b',0x011e,0x011f,0x015e,0x015f,0}; /* Turkish */ 00077 static const WCHAR stHebrew[]={'A','a','B','b',0x05e0,0x05e1,0x05e9,0x05ea,0}; /* Hebrew */ 00078 static const WCHAR stArabic[]={'A','a','B','b',0x0627,0x0628,0x062c,0x062f,0x0647,0x0648,0x0632,0};/* Arabic */ 00079 static const WCHAR stBaltic[]={'A','a','B','b','Y','y','Z','z',0}; /* Baltic */ 00080 static const WCHAR stVietname[]={'A','a','B','b',0x01a0,0x01a1,0x01af,0x01b0,0}; /* Vietnamese */ 00081 static const WCHAR stCyrillic[]={'A','a','B','b',0x0411,0x0431,0x0424,0x0444,0}; /* Cyrillic */ 00082 static const WCHAR stEastEur[]={'A','a','B','b',0xc1,0xe1,0xd4,0xf4,0}; /* East European */ 00083 static const WCHAR stThai[]={'A','a','B','b',0x0e2d,0x0e31,0x0e01,0x0e29,0x0e23,0x0e44,0x0e17,0x0e22,0}; /* Thai */ 00084 static const WCHAR stJohab[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Johab */ 00085 static const WCHAR stMac[]={'A','a','B','b','Y','y','Z','z',0}; /* Mac */ 00086 static const WCHAR stOEM[]={'A','a','B','b',0xf8,0xf1,0xfd,0}; /* OEM */ 00087 /* the following character sets actually behave different (Win2K observation): 00088 * the sample string is 'sticky': it uses the sample string of the previous 00089 * selected character set. That behaviour looks like some default, which is 00090 * not (yet) implemented. */ 00091 static const WCHAR stVISCII[]={'A','a','B','b',0}; /* VISCII */ 00092 static const WCHAR stTCVN[]={'A','a','B','b',0}; /* TCVN */ 00093 static const WCHAR stKOI8[]={'A','a','B','b',0}; /* KOI-8 */ 00094 static const WCHAR stIso88593[]={'A','a','B','b',0}; /* ISO-8859-3 */ 00095 static const WCHAR stIso88594[]={'A','a','B','b',0}; /* ISO-8859-4 */ 00096 static const WCHAR stIso885910[]={'A','a','B','b',0}; /* ISO-8859-10 */ 00097 static const WCHAR stCeltic[]={'A','a','B','b',0};/* Celtic */ 00098 00099 static const WCHAR * const sample_lang_text[]={ 00100 stWestern,stSymbol,stShiftJis,stHangul,stGB2312, 00101 stBIG5,stGreek,stTurkish,stHebrew,stArabic, 00102 stBaltic,stVietname,stCyrillic,stEastEur,stThai, 00103 stJohab,stMac,stOEM,stVISCII,stTCVN, 00104 stKOI8,stIso88593,stIso88594,stIso885910,stCeltic}; 00105 00106 00107 static const BYTE CHARSET_ORDER[256]={ 00108 CI(ANSI), 0, CI(SYMBOL), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(MAC), 0, 0, 00113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00116 CI(JIS), CI(HANGUL), CI(JOHAB), 0, 0, 0, CI(GB2312), 0, CI(BIG5), 0, 0, 0, 0, 0, 0, 0, 00117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00118 0, CI(GREEK), CI(TURKISH), CI(VIETNAMESE), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00119 0, CI(HEBREW), CI(ARABIC), 0, 0, 0, 0, 0, 0, 0, CI(BALTIC), 0, 0, 0, 0, 0, 00120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(RUSSIAN), 0, 0, 0, 00121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(THAI), 0, 00122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(EE), 0, 00123 CI(VISCII), CI(TCVN), CI(KOI8), CI(ISO3), CI(ISO4), CI(ISO10), CI(CELTIC), 0, 0, 0, 0, 0, 0, 0, 0, CI(OEM), 00124 }; 00125 00126 static const struct { 00127 DWORD mask; 00128 const char *name; 00129 } cfflags[] = { 00130 #define XX(x) { x, #x }, 00131 XX(CF_SCREENFONTS) 00132 XX(CF_PRINTERFONTS) 00133 XX(CF_SHOWHELP) 00134 XX(CF_ENABLEHOOK) 00135 XX(CF_ENABLETEMPLATE) 00136 XX(CF_ENABLETEMPLATEHANDLE) 00137 XX(CF_INITTOLOGFONTSTRUCT) 00138 XX(CF_USESTYLE) 00139 XX(CF_EFFECTS) 00140 XX(CF_APPLY) 00141 XX(CF_ANSIONLY) 00142 XX(CF_NOVECTORFONTS) 00143 XX(CF_NOSIMULATIONS) 00144 XX(CF_LIMITSIZE) 00145 XX(CF_FIXEDPITCHONLY) 00146 XX(CF_WYSIWYG) 00147 XX(CF_FORCEFONTEXIST) 00148 XX(CF_SCALABLEONLY) 00149 XX(CF_TTONLY) 00150 XX(CF_NOFACESEL) 00151 XX(CF_NOSTYLESEL) 00152 XX(CF_NOSIZESEL) 00153 XX(CF_SELECTSCRIPT) 00154 XX(CF_NOSCRIPTSEL) 00155 XX(CF_NOVERTFONTS) 00156 #undef XX 00157 }; 00158 00159 static void _dump_cf_flags(DWORD cflags) 00160 { 00161 unsigned int i; 00162 00163 for (i = 0; i < sizeof(cfflags)/sizeof(cfflags[0]); i++) 00164 if (cfflags[i].mask & cflags) 00165 TRACE("%s|",cfflags[i].name); 00166 TRACE("\n"); 00167 } 00168 00169 /*********************************************************************** 00170 * ChooseFontW (COMDLG32.@) 00171 * 00172 * Create a font dialog box. 00173 * 00174 * PARAMS 00175 * lpChFont [I/O] in: information to initialize the dialog box. 00176 * out: User's color selection 00177 * 00178 * RETURNS 00179 * TRUE: Ok button clicked. 00180 * FALSE: Cancel button clicked, or error. 00181 */ 00182 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont) 00183 { 00184 LPCVOID template; 00185 HRSRC hResInfo; 00186 HINSTANCE hDlginst; 00187 HGLOBAL hDlgTmpl; 00188 00189 TRACE("(%p)\n", lpChFont); 00190 00191 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 ) 00192 { 00193 template=lpChFont->hInstance; 00194 } else 00195 { 00196 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 ) 00197 { 00198 hDlginst=lpChFont->hInstance; 00199 if( !(hResInfo = FindResourceW(hDlginst, lpChFont->lpTemplateName, 00200 (LPWSTR)RT_DIALOG))) 00201 { 00202 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); 00203 return FALSE; 00204 } 00205 } else 00206 { 00207 hDlginst=COMDLG32_hInstance; 00208 if (!(hResInfo = FindResourceW(hDlginst, chooseFontW, (LPWSTR)RT_DIALOG))) 00209 { 00210 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); 00211 return FALSE; 00212 } 00213 } 00214 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) || 00215 !(template = LockResource( hDlgTmpl ))) 00216 { 00217 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); 00218 return FALSE; 00219 } 00220 } 00221 if (TRACE_ON(commdlg)) 00222 _dump_cf_flags(lpChFont->Flags); 00223 00224 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS )) 00225 FIXME(": unimplemented flag (ignored)\n"); 00226 00227 return DialogBoxIndirectParamW(COMDLG32_hInstance, template, 00228 lpChFont->hwndOwner, FormatCharDlgProcW, (LPARAM)lpChFont ); 00229 } 00230 00231 /*********************************************************************** 00232 * ChooseFontA (COMDLG32.@) 00233 * 00234 * See ChooseFontW. 00235 */ 00236 BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont) 00237 { 00238 LPCVOID template; 00239 HRSRC hResInfo; 00240 HINSTANCE hDlginst; 00241 HGLOBAL hDlgTmpl; 00242 00243 TRACE("(%p)\n", lpChFont); 00244 00245 if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 ) 00246 { 00247 template=lpChFont->hInstance; 00248 } else 00249 { 00250 if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 ) 00251 { 00252 hDlginst=lpChFont->hInstance; 00253 if( !(hResInfo = FindResourceA(hDlginst, lpChFont->lpTemplateName, 00254 (LPSTR)RT_DIALOG))) 00255 { 00256 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); 00257 return FALSE; 00258 } 00259 } else 00260 { 00261 hDlginst=COMDLG32_hInstance; 00262 if (!(hResInfo = FindResourceW(hDlginst, chooseFontW, (LPWSTR)RT_DIALOG))) 00263 { 00264 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); 00265 return FALSE; 00266 } 00267 } 00268 if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) || 00269 !(template = LockResource( hDlgTmpl ))) 00270 { 00271 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); 00272 return FALSE; 00273 } 00274 } 00275 if (TRACE_ON(commdlg)) 00276 _dump_cf_flags(lpChFont->Flags); 00277 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS )) 00278 FIXME(": unimplemented flag (ignored)\n"); 00279 00280 return DialogBoxIndirectParamA(COMDLG32_hInstance, template, 00281 lpChFont->hwndOwner, FormatCharDlgProcA, (LPARAM)lpChFont ); 00282 } 00283 00284 #define TEXT_EXTRAS 4 00285 #define TEXT_COLORS 16 00286 00287 static const COLORREF textcolors[TEXT_COLORS]= 00288 { 00289 0x00000000L,0x00000080L,0x00008000L,0x00008080L, 00290 0x00800000L,0x00800080L,0x00808000L,0x00808080L, 00291 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL, 00292 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL 00293 }; 00294 00295 /*********************************************************************** 00296 * CFn_HookCallChk32 [internal] 00297 */ 00298 static BOOL CFn_HookCallChk32(const CHOOSEFONTW *lpcf) 00299 { 00300 if (lpcf) 00301 if(lpcf->Flags & CF_ENABLEHOOK) 00302 if (lpcf->lpfnHook) 00303 return TRUE; 00304 return FALSE; 00305 } 00306 00307 /************************************************************************* 00308 * AddFontFamily [internal] 00309 */ 00310 static INT AddFontFamily(const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM, 00311 UINT nFontType, const CHOOSEFONTW *lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e) 00312 { 00313 int i; 00314 WORD w; 00315 const LOGFONTW *lplf = &(lpElfex->elfLogFont); 00316 00317 TRACE("font=%s (nFontType=%d)\n", debugstr_w(lplf->lfFaceName), nFontType); 00318 00319 if (lpcf->Flags & CF_FIXEDPITCHONLY) 00320 if (!(lplf->lfPitchAndFamily & FIXED_PITCH)) 00321 return 1; 00322 if (lpcf->Flags & CF_ANSIONLY) 00323 if (lplf->lfCharSet != ANSI_CHARSET) 00324 return 1; 00325 if (lpcf->Flags & CF_TTONLY) 00326 if (!(nFontType & TRUETYPE_FONTTYPE)) 00327 return 1; 00328 00329 if (e) e->added++; 00330 00331 i=SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)lplf->lfFaceName); 00332 if (i == CB_ERR) { 00333 i = SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName); 00334 if( i != CB_ERR) { 00335 /* store some important font information */ 00336 w = (lplf->lfPitchAndFamily) << 8 | 00337 (HIWORD(lpNTM->ntmTm.ntmFlags) & 0xff); 00338 SendMessageW(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w)); 00339 } 00340 } 00341 return 1; 00342 } 00343 00344 /************************************************************************* 00345 * FontFamilyEnumProc32 [internal] 00346 */ 00347 static INT WINAPI FontFamilyEnumProc(const ENUMLOGFONTEXW *lpElfex, 00348 const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam) 00349 { 00350 LPCFn_ENUMSTRUCT e; 00351 e=(LPCFn_ENUMSTRUCT)lParam; 00352 return AddFontFamily( lpElfex, (const NEWTEXTMETRICEXW *) metrics, 00353 dwFontType, e->lpcf32w, e->hWnd1, e); 00354 } 00355 00356 /************************************************************************* 00357 * SetFontStylesToCombo2 [internal] 00358 * 00359 * Fill font style information into combobox (without using font.c directly) 00360 */ 00361 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTW *lplf) 00362 { 00363 #define FSTYLES 4 00364 struct FONTSTYLE 00365 { 00366 int italic; 00367 int weight; 00368 UINT resId; 00369 }; 00370 static const struct FONTSTYLE fontstyles[FSTYLES]={ 00371 { 0, FW_NORMAL, IDS_FONT_REGULAR }, 00372 { 1, FW_NORMAL, IDS_FONT_ITALIC }, 00373 { 0, FW_BOLD, IDS_FONT_BOLD }, 00374 { 1, FW_BOLD, IDS_FONT_BOLD_ITALIC } 00375 }; 00376 HFONT hf; 00377 TEXTMETRICW tm; 00378 int i,j; 00379 LOGFONTW lf; 00380 00381 lf = *lplf; 00382 00383 for (i=0;i<FSTYLES;i++) 00384 { 00385 lf.lfItalic=fontstyles[i].italic; 00386 lf.lfWeight=fontstyles[i].weight; 00387 hf=CreateFontIndirectW(&lf); 00388 hf=SelectObject(hdc,hf); 00389 GetTextMetricsW(hdc,&tm); 00390 hf=SelectObject(hdc,hf); 00391 DeleteObject(hf); 00392 /* font successful created ? */ 00393 if (((fontstyles[i].weight == FW_NORMAL && tm.tmWeight <= FW_MEDIUM) || 00394 (fontstyles[i].weight == FW_BOLD && tm.tmWeight > FW_MEDIUM)) && 00395 ((tm.tmItalic != 0)==fontstyles[i].italic)) 00396 { 00397 WCHAR name[64]; 00398 LoadStringW(COMDLG32_hInstance, fontstyles[i].resId, name, 64); 00399 j=SendMessageW(hwnd,CB_ADDSTRING,0,(LPARAM)name ); 00400 if (j==CB_ERR) return 1; 00401 j=SendMessageW(hwnd, CB_SETITEMDATA, j, 00402 MAKELONG(tm.tmWeight,fontstyles[i].italic)); 00403 if (j==CB_ERR) return 1; 00404 } 00405 } 00406 return 0; 00407 } 00408 00409 /************************************************************************* 00410 * AddFontSizeToCombo3 [internal] 00411 */ 00412 static int AddFontSizeToCombo3(HWND hwnd, UINT h, const CHOOSEFONTW *lpcf) 00413 { 00414 int j; 00415 WCHAR buffer[20]; 00416 static const WCHAR strFormat[] = {'%','2','d',0}; 00417 00418 if ( (!(lpcf->Flags & CF_LIMITSIZE)) || 00419 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax))) 00420 { 00421 wsprintfW(buffer, strFormat, h); 00422 j=SendMessageW(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer); 00423 if (j==CB_ERR) 00424 { 00425 j=SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer); 00426 if (j!=CB_ERR) j = SendMessageW(hwnd, CB_SETITEMDATA, j, h); 00427 if (j==CB_ERR) return 1; 00428 } 00429 } 00430 return 0; 00431 } 00432 00433 /************************************************************************* 00434 * SetFontSizesToCombo3 [internal] 00435 */ 00436 static int SetFontSizesToCombo3(HWND hwnd, const CHOOSEFONTW *lpcf) 00437 { 00438 static const BYTE sizes[]={6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72}; 00439 unsigned int i; 00440 00441 for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++) 00442 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1; 00443 return 0; 00444 } 00445 00446 /************************************************************************* 00447 * CFn_GetDC [internal] 00448 */ 00449 static inline HDC CFn_GetDC(const CHOOSEFONTW *lpcf) 00450 { 00451 HDC ret = ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? 00452 lpcf->hDC : 00453 GetDC(0); 00454 if(!ret) ERR("HDC failure!!!\n"); 00455 return ret; 00456 } 00457 00458 /************************************************************************* 00459 * GetScreenDPI [internal] 00460 */ 00461 static inline int GetScreenDPI(void) 00462 { 00463 HDC hdc; 00464 int result; 00465 00466 hdc = GetDC(0); 00467 result = GetDeviceCaps(hdc, LOGPIXELSY); 00468 ReleaseDC(0, hdc); 00469 00470 return result; 00471 } 00472 00473 /************************************************************************* 00474 * CFn_ReleaseDC [internal] 00475 */ 00476 static inline void CFn_ReleaseDC(const CHOOSEFONTW *lpcf, HDC hdc) 00477 { 00478 if(!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC)) 00479 ReleaseDC(0, hdc); 00480 } 00481 00482 /*********************************************************************** 00483 * AddFontStyle [internal] 00484 */ 00485 static INT AddFontStyle( const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM, 00486 UINT nFontType, const CHOOSEFONTW *lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg) 00487 { 00488 int i; 00489 const LOGFONTW *lplf = &(lpElfex->elfLogFont); 00490 HWND hcmb5; 00491 HDC hdc; 00492 00493 TRACE("(nFontType=%d)\n",nFontType); 00494 TRACE(" %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d" 00495 " ch=%d op=%d cp=%d q=%d pf=%xh\n", 00496 debugstr_w(lplf->lfFaceName),lplf->lfHeight,lplf->lfWidth, 00497 lplf->lfEscapement,lplf->lfOrientation, 00498 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline, 00499 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision, 00500 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily); 00501 if (nFontType & RASTER_FONTTYPE) 00502 { 00503 INT points; 00504 points = MulDiv( lpNTM->ntmTm.tmHeight - lpNTM->ntmTm.tmInternalLeading, 00505 72, GetScreenDPI()); 00506 i = AddFontSizeToCombo3(hcmb3, points, lpcf); 00507 if(i) return 0; 00508 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0; 00509 00510 if (!SendMessageW(hcmb2, CB_GETCOUNT, 0, 0)) 00511 { 00512 if(!(hdc = CFn_GetDC(lpcf))) return 0; 00513 i=SetFontStylesToCombo2(hcmb2,hdc,lplf); 00514 CFn_ReleaseDC(lpcf, hdc); 00515 if (i) 00516 return 0; 00517 } 00518 if (!( hcmb5 = GetDlgItem(hDlg, cmb5))) return 1; 00519 i = SendMessageW( hcmb5, CB_FINDSTRINGEXACT, 0, 00520 (LPARAM)lpElfex->elfScript); 00521 if( i == CB_ERR) { 00522 i = SendMessageW( hcmb5, CB_ADDSTRING, 0, 00523 (LPARAM)lpElfex->elfScript); 00524 if( i != CB_ERR) 00525 SendMessageW( hcmb5, CB_SETITEMDATA, i, lplf->lfCharSet); 00526 } 00527 return 1 ; 00528 } 00529 00530 static INT CFn_FitFontSize( HWND hDlg, int points) 00531 { 00532 int i,n; 00533 int ret = 0; 00534 /* look for fitting font size in combobox3 */ 00535 n=SendDlgItemMessageW(hDlg, cmb3, CB_GETCOUNT, 0, 0); 00536 for (i=0;i<n;i++) 00537 { 00538 if (points == (int)SendDlgItemMessageW 00539 (hDlg,cmb3, CB_GETITEMDATA,i,0)) 00540 { 00541 SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,i,0); 00542 SendMessageW(hDlg, WM_COMMAND, 00543 MAKEWPARAM(cmb3, CBN_SELCHANGE), 00544 (LPARAM)GetDlgItem(hDlg,cmb3)); 00545 ret = 1; 00546 break; 00547 } 00548 } 00549 return ret; 00550 } 00551 00552 static INT CFn_FitFontStyle( HWND hDlg, LONG packedstyle ) 00553 { 00554 LONG id; 00555 int i, ret = 0; 00556 /* look for fitting font style in combobox2 */ 00557 for (i=0;i<TEXT_EXTRAS;i++) 00558 { 00559 id = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0); 00560 if (packedstyle == id) 00561 { 00562 SendDlgItemMessageW(hDlg, cmb2, CB_SETCURSEL, i, 0); 00563 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE), 00564 (LPARAM)GetDlgItem(hDlg,cmb2)); 00565 ret = 1; 00566 break; 00567 } 00568 } 00569 return ret; 00570 } 00571 00572 00573 static INT CFn_FitCharSet( HWND hDlg, int charset ) 00574 { 00575 int i,n,cs; 00576 /* look for fitting char set in combobox5 */ 00577 n=SendDlgItemMessageW(hDlg, cmb5, CB_GETCOUNT, 0, 0); 00578 for (i=0;i<n;i++) 00579 { 00580 cs =SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0); 00581 if (charset == cs) 00582 { 00583 SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, i, 0); 00584 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE), 00585 (LPARAM)GetDlgItem(hDlg,cmb2)); 00586 return 1; 00587 } 00588 } 00589 /* no charset fits: select the first one in the list */ 00590 SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, 0, 0); 00591 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE), 00592 (LPARAM)GetDlgItem(hDlg,cmb2)); 00593 return 0; 00594 } 00595 00596 /*********************************************************************** 00597 * FontStyleEnumProc32 [internal] 00598 */ 00599 static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXW *lpElfex, 00600 const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam ) 00601 { 00602 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam; 00603 HWND hcmb2=s->hWnd1; 00604 HWND hcmb3=s->hWnd2; 00605 HWND hDlg=GetParent(hcmb3); 00606 return AddFontStyle( lpElfex, (const NEWTEXTMETRICEXW *) metrics, 00607 dwFontType, s->lpcf32w, hcmb2, hcmb3, hDlg); 00608 } 00609 00610 /*********************************************************************** 00611 * CFn_WMInitDialog [internal] 00612 */ 00613 static LRESULT CFn_WMInitDialog(HWND hDlg, LPARAM lParam, LPCHOOSEFONTW lpcf) 00614 { 00615 HDC hdc; 00616 int i,j,init=0; 00617 long pstyle; 00618 CFn_ENUMSTRUCT s; 00619 LPLOGFONTW lpxx; 00620 HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT)); 00621 static const WCHAR strColorName[] = {'[','c','o','l','o','r',' ','n','a','m','e',']',0}; 00622 00623 SetPropW(hDlg, strWineFontData, lpcf); 00624 lpxx=lpcf->lpLogFont; 00625 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam); 00626 00627 if (lpcf->lStructSize != sizeof(CHOOSEFONTW)) 00628 { 00629 ERR("structure size failure !!!\n"); 00630 EndDialog (hDlg, 0); 00631 return FALSE; 00632 } 00633 if (!himlTT) 00634 himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38), 00635 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0); 00636 00637 /* Set effect flags */ 00638 if((lpcf->Flags & CF_EFFECTS) && (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)) 00639 { 00640 if(lpxx->lfUnderline) 00641 CheckDlgButton(hDlg, chx2, TRUE); 00642 if(lpxx->lfStrikeOut) 00643 CheckDlgButton(hDlg, chx1, TRUE); 00644 } 00645 00646 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner)) 00647 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE); 00648 if (!(lpcf->Flags & CF_APPLY)) 00649 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE); 00650 if (lpcf->Flags & CF_NOSCRIPTSEL) 00651 EnableWindow(GetDlgItem(hDlg,cmb5),FALSE); 00652 if (lpcf->Flags & CF_EFFECTS) 00653 { 00654 for (i=0;i<TEXT_COLORS;i++) 00655 { 00656 WCHAR name[30]; 00657 00658 if( LoadStringW(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name, 00659 sizeof(name)/sizeof(*name) )==0 ) 00660 { 00661 memcpy(name, strColorName, sizeof(strColorName)); 00662 } 00663 j=SendDlgItemMessageW(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name); 00664 SendDlgItemMessageW(hDlg, cmb4, CB_SETITEMDATA, j, textcolors[i]); 00665 /* look for a fitting value in color combobox */ 00666 if (textcolors[i]==lpcf->rgbColors) 00667 SendDlgItemMessageW(hDlg,cmb4, CB_SETCURSEL,j,0); 00668 } 00669 } 00670 else 00671 { 00672 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE); 00673 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE); 00674 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE); 00675 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE); 00676 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE); 00677 } 00678 if(!(hdc = CFn_GetDC(lpcf))) 00679 { 00680 EndDialog (hDlg, 0); 00681 return FALSE; 00682 } 00683 s.hWnd1=GetDlgItem(hDlg,cmb1); 00684 s.lpcf32w=lpcf; 00685 do { 00686 LOGFONTW elf; 00687 s.added = 0; 00688 elf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */ 00689 elf.lfPitchAndFamily = 0; 00690 elf.lfFaceName[0] = '\0'; /* enum all fonts */ 00691 if (!EnumFontFamiliesExW(hdc, &elf, (FONTENUMPROCW)FontFamilyEnumProc, (LPARAM)&s, 0)) 00692 { 00693 TRACE("EnumFontFamiliesEx returns 0\n"); 00694 break; 00695 } 00696 if (s.added) break; 00697 if (lpcf->Flags & CF_FIXEDPITCHONLY) { 00698 FIXME("No font found with fixed pitch only, dropping flag.\n"); 00699 lpcf->Flags &= ~CF_FIXEDPITCHONLY; 00700 continue; 00701 } 00702 if (lpcf->Flags & CF_TTONLY) { 00703 FIXME("No font found with truetype only, dropping flag.\n"); 00704 lpcf->Flags &= ~CF_TTONLY; 00705 continue; 00706 } 00707 break; 00708 } while (1); 00709 00710 00711 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT) 00712 { 00713 /* look for fitting font name in combobox1 */ 00714 j=SendDlgItemMessageW(hDlg,cmb1,CB_FINDSTRING,-1,(LPARAM)lpxx->lfFaceName); 00715 if (j!=CB_ERR) 00716 { 00717 INT height = lpxx->lfHeight < 0 ? -lpxx->lfHeight : 00718 lpxx->lfHeight; 00719 INT points; 00720 int charset = lpxx->lfCharSet; 00721 points = MulDiv( height, 72, GetScreenDPI()); 00722 pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD: 00723 FW_NORMAL,lpxx->lfItalic !=0); 00724 SendDlgItemMessageW(hDlg, cmb1, CB_SETCURSEL, j, 0); 00725 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE), 00726 (LPARAM)GetDlgItem(hDlg,cmb1)); 00727 init=1; 00728 /* look for fitting font style in combobox2 */ 00729 CFn_FitFontStyle(hDlg, pstyle); 00730 /* look for fitting font size in combobox3 */ 00731 CFn_FitFontSize(hDlg, points); 00732 CFn_FitCharSet( hDlg, charset ); 00733 } 00734 } 00735 if (!init) 00736 { 00737 SendDlgItemMessageW(hDlg,cmb1,CB_SETCURSEL,0,0); 00738 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE), 00739 (LPARAM)GetDlgItem(hDlg,cmb1)); 00740 SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,0,0); 00741 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE), 00742 (LPARAM)GetDlgItem(hDlg,cmb1)); 00743 SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,0,0); 00744 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb3, CBN_SELCHANGE), 00745 (LPARAM)GetDlgItem(hDlg,cmb3)); 00746 SendDlgItemMessageW(hDlg,cmb5,CB_SETCURSEL,0,0); 00747 SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE), 00748 (LPARAM)GetDlgItem(hDlg,cmb5)); 00749 } 00750 if ((lpcf->Flags & CF_USESTYLE) && lpcf->lpszStyle) 00751 { 00752 j=SendDlgItemMessageW(hDlg,cmb2,CB_FINDSTRING,-1,(LPARAM)lpcf->lpszStyle); 00753 if (j!=CB_ERR) 00754 { 00755 j=SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,j,0); 00756 SendMessageW(hDlg,WM_COMMAND,cmb2, 00757 MAKELONG(LOWORD(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE)); 00758 } 00759 } 00760 CFn_ReleaseDC(lpcf, hdc); 00761 SetCursor(hcursor); 00762 return TRUE; 00763 } 00764 00765 00766 /*********************************************************************** 00767 * CFn_WMMeasureItem [internal] 00768 */ 00769 static LRESULT CFn_WMMeasureItem(HWND hDlg, LPARAM lParam) 00770 { 00771 HDC hdc; 00772 HFONT hfontprev; 00773 TEXTMETRICW tm; 00774 LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam; 00775 INT height = 0, cx; 00776 00777 if (!himlTT) 00778 himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38), 00779 TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0); 00780 ImageList_GetIconSize( himlTT, &cx, &height); 00781 lpmi->itemHeight = height + 2; 00782 /* use MAX of bitmap height and tm.tmHeight .*/ 00783 hdc=GetDC(hDlg); 00784 if(!hdc) return 0; 00785 hfontprev = SelectObject( hdc, GetStockObject( DEFAULT_GUI_FONT ) ); 00786 GetTextMetricsW(hdc, &tm); 00787 if( tm.tmHeight > lpmi->itemHeight) lpmi->itemHeight = tm.tmHeight; 00788 SelectObject(hdc, hfontprev); 00789 ReleaseDC(hDlg, hdc); 00790 return 0; 00791 } 00792 00793 00794 /*********************************************************************** 00795 * CFn_WMDrawItem [internal] 00796 */ 00797 static LRESULT CFn_WMDrawItem(LPARAM lParam) 00798 { 00799 HBRUSH hBrush; 00800 WCHAR buffer[40]; 00801 COLORREF cr, oldText=0, oldBk=0; 00802 RECT rect; 00803 int nFontType; 00804 int idx; 00805 LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam; 00806 00807 if (lpdi->itemID == (UINT)-1) /* got no items */ 00808 DrawFocusRect(lpdi->hDC, &lpdi->rcItem); 00809 else 00810 { 00811 if (lpdi->CtlType == ODT_COMBOBOX) 00812 { 00813 if (lpdi->itemState & ODS_SELECTED) 00814 { 00815 hBrush=GetSysColorBrush(COLOR_HIGHLIGHT); 00816 oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); 00817 oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT)); 00818 } else 00819 { 00820 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH)); 00821 SelectObject(lpdi->hDC, hBrush); 00822 } 00823 FillRect(lpdi->hDC, &lpdi->rcItem, hBrush); 00824 } 00825 else 00826 return TRUE; /* this should never happen */ 00827 00828 rect=lpdi->rcItem; 00829 switch (lpdi->CtlID) 00830 { 00831 case cmb1: 00832 /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */ 00833 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID, 00834 (LPARAM)buffer); 00835 TextOutW(lpdi->hDC, lpdi->rcItem.left + TTBITMAP_XSIZE + 10, 00836 lpdi->rcItem.top, buffer, lstrlenW(buffer)); 00837 nFontType = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L); 00838 idx = -1; 00839 if (nFontType & TRUETYPE_FONTTYPE) { 00840 idx = 0; /* picture: TT */ 00841 if( nFontType & NTM_TT_OPENTYPE) 00842 idx = 2; /* picture: O */ 00843 } else if( nFontType & NTM_PS_OPENTYPE) 00844 idx = 3; /* picture: O+ps */ 00845 else if( nFontType & NTM_TYPE1) 00846 idx = 4; /* picture: a */ 00847 else if( nFontType & DEVICE_FONTTYPE) 00848 idx = 1; /* picture: printer */ 00849 if( idx >= 0) 00850 ImageList_Draw( himlTT, idx, lpdi->hDC, lpdi->rcItem.left, 00851 lpdi->rcItem.top, ILD_TRANSPARENT); 00852 break; 00853 case cmb2: 00854 case cmb3: 00855 /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */ 00856 case cmb5: 00857 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID, 00858 (LPARAM)buffer); 00859 TextOutW(lpdi->hDC, lpdi->rcItem.left, 00860 lpdi->rcItem.top, buffer, lstrlenW(buffer)); 00861 break; 00862 00863 case cmb4: 00864 /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */ 00865 SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID, 00866 (LPARAM)buffer); 00867 TextOutW(lpdi->hDC, lpdi->rcItem.left + 25+5, 00868 lpdi->rcItem.top, buffer, lstrlenW(buffer)); 00869 cr = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L); 00870 hBrush = CreateSolidBrush(cr); 00871 if (hBrush) 00872 { 00873 hBrush = SelectObject (lpdi->hDC, hBrush) ; 00874 rect.right=rect.left+25; 00875 rect.top++; 00876 rect.left+=5; 00877 rect.bottom--; 00878 Rectangle( lpdi->hDC, rect.left, rect.top, 00879 rect.right, rect.bottom ); 00880 DeleteObject( SelectObject (lpdi->hDC, hBrush)) ; 00881 } 00882 rect=lpdi->rcItem; 00883 rect.left+=25+5; 00884 break; 00885 00886 default: 00887 return TRUE; /* this should never happen */ 00888 } 00889 if (lpdi->itemState & ODS_SELECTED) 00890 { 00891 SetTextColor(lpdi->hDC, oldText); 00892 SetBkColor(lpdi->hDC, oldBk); 00893 } 00894 } 00895 return TRUE; 00896 } 00897 00898 /*********************************************************************** 00899 * CFn_WMCommand [internal] 00900 */ 00901 static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFONTW lpcf) 00902 { 00903 int i; 00904 long l; 00905 HDC hdc; 00906 00907 if (!lpcf) return FALSE; 00908 00909 TRACE("WM_COMMAND wParam=%08X lParam=%08lX\n", (LONG)wParam, lParam); 00910 switch (LOWORD(wParam)) 00911 { 00912 case cmb1: 00913 if (HIWORD(wParam)==CBN_SELCHANGE) 00914 { 00915 INT pointsize; /* save current pointsize */ 00916 LONG pstyle; /* save current style */ 00917 int charset; 00918 int idx; 00919 if(!(hdc = CFn_GetDC(lpcf))) 00920 { 00921 EndDialog (hDlg, 0); 00922 return TRUE; 00923 } 00924 idx = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0); 00925 pointsize = (int)SendDlgItemMessageW( hDlg, cmb3, CB_GETITEMDATA, 00926 idx, 0); 00927 idx = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0); 00928 pstyle = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, idx, 0); 00929 idx = SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0); 00930 charset = SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, idx, 0); 00931 00932 SendDlgItemMessageW(hDlg, cmb2, CB_RESETCONTENT, 0, 0); 00933 SendDlgItemMessageW(hDlg, cmb3, CB_RESETCONTENT, 0, 0); 00934 SendDlgItemMessageW(hDlg, cmb5, CB_RESETCONTENT, 0, 0); 00935 i=SendDlgItemMessageW(hDlg, cmb1, CB_GETCURSEL, 0, 0); 00936 if (i!=CB_ERR) 00937 { 00938 HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT)); 00939 CFn_ENUMSTRUCT s; 00940 LOGFONTW enumlf; 00941 SendDlgItemMessageW(hDlg, cmb1, CB_GETLBTEXT, i, 00942 (LPARAM)enumlf.lfFaceName); 00943 TRACE("WM_COMMAND/cmb1 =>%s\n", debugstr_w(enumlf.lfFaceName)); 00944 s.hWnd1=GetDlgItem(hDlg, cmb2); 00945 s.hWnd2=GetDlgItem(hDlg, cmb3); 00946 s.lpcf32w=lpcf; 00947 enumlf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */ 00948 enumlf.lfPitchAndFamily = 0; 00949 EnumFontFamiliesExW(hdc, &enumlf, 00950 (FONTENUMPROCW)FontStyleEnumProc, (LPARAM)&s, 0); 00951 CFn_FitFontStyle(hDlg, pstyle); 00952 if( pointsize != CB_ERR) CFn_FitFontSize(hDlg, pointsize); 00953 if( charset != CB_ERR) CFn_FitCharSet( hDlg, charset ); 00954 SetCursor(hcursor); 00955 } 00956 CFn_ReleaseDC(lpcf, hdc); 00957 } 00958 break; 00959 case chx1: 00960 case chx2: 00961 case cmb2: 00962 case cmb3: 00963 case cmb5: 00964 if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED ) 00965 { 00966 WCHAR str[256]; 00967 WINDOWINFO wininfo; 00968 LPLOGFONTW lpxx=lpcf->lpLogFont; 00969 00970 TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam); 00971 i=SendDlgItemMessageW(hDlg,cmb1,CB_GETCURSEL,0,0); 00972 if (i==CB_ERR) 00973 i=GetDlgItemTextW( hDlg, cmb1, str, 256 ); 00974 else 00975 { 00976 SendDlgItemMessageW(hDlg,cmb1,CB_GETLBTEXT,i, 00977 (LPARAM)str); 00978 l=SendDlgItemMessageW(hDlg,cmb1,CB_GETITEMDATA,i,0); 00979 lpcf->nFontType = LOWORD(l); 00980 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */ 00981 /* same value reported to the EnumFonts 00982 call back with the extra FONTTYPE_... bits added */ 00983 lpxx->lfPitchAndFamily = HIWORD(l) >> 8; 00984 } 00985 lstrcpynW(lpxx->lfFaceName, str, sizeof(lpxx->lfFaceName)/sizeof(lpxx->lfFaceName[0])); 00986 i=SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0); 00987 if (i!=CB_ERR) 00988 { 00989 l=SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0); 00990 if (0!=(lpxx->lfItalic=HIWORD(l))) 00991 lpcf->nFontType |= ITALIC_FONTTYPE; 00992 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM) 00993 lpcf->nFontType |= BOLD_FONTTYPE; 00994 } 00995 i=SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0); 00996 if( i != CB_ERR) 00997 lpcf->iPointSize = 10 * LOWORD(SendDlgItemMessageW(hDlg, cmb3, 00998 CB_GETITEMDATA , i, 0)); 00999 else 01000 lpcf->iPointSize = 100; 01001 lpxx->lfHeight = - MulDiv( lpcf->iPointSize , 01002 GetScreenDPI(), 720); 01003 i=SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0); 01004 if (i!=CB_ERR) 01005 lpxx->lfCharSet=SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0); 01006 else 01007 lpxx->lfCharSet = DEFAULT_CHARSET; 01008 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1); 01009 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2); 01010 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0; 01011 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS; 01012 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS; 01013 lpxx->lfQuality=DEFAULT_QUALITY; 01014 01015 wininfo.cbSize=sizeof(wininfo); 01016 01017 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) ) 01018 { 01019 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2); 01020 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE ); 01021 } 01022 } 01023 break; 01024 01025 case cmb4: 01026 i=SendDlgItemMessageW(hDlg, cmb4, CB_GETCURSEL, 0, 0); 01027 if (i!=CB_ERR) 01028 { 01029 WINDOWINFO wininfo; 01030 01031 lpcf->rgbColors = SendDlgItemMessageW(hDlg, cmb4, CB_GETITEMDATA, i, 0); 01032 wininfo.cbSize=sizeof(wininfo); 01033 01034 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) ) 01035 { 01036 MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2); 01037 InvalidateRect( hDlg, &wininfo.rcWindow, TRUE ); 01038 } 01039 } 01040 break; 01041 01042 case psh15: 01043 i=RegisterWindowMessageW( HELPMSGSTRINGW ); 01044 if (lpcf->hwndOwner) 01045 SendMessageW(lpcf->hwndOwner, i, 0, (LPARAM)GetPropW(hDlg, strWineFontData)); 01046 break; 01047 01048 case IDOK: 01049 if ( (!(lpcf->Flags & CF_LIMITSIZE)) || 01050 ( (lpcf->Flags & CF_LIMITSIZE) && 01051 (lpcf->iPointSize >= 10 * lpcf->nSizeMin) && 01052 (lpcf->iPointSize <= 10 * lpcf->nSizeMax))) 01053 EndDialog(hDlg, TRUE); 01054 else 01055 { 01056 WCHAR buffer[80]; 01057 WCHAR format[80]; 01058 DWORD_PTR args[2]; 01059 LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE, format, sizeof(format)/sizeof(WCHAR)); 01060 args[0] = lpcf->nSizeMin; 01061 args[1] = lpcf->nSizeMax; 01062 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY, 01063 format, 0, 0, buffer, sizeof(buffer)/sizeof(*buffer), 01064 (__ms_va_list*)args); 01065 MessageBoxW(hDlg, buffer, NULL, MB_OK); 01066 } 01067 return(TRUE); 01068 case IDCANCEL: 01069 EndDialog(hDlg, FALSE); 01070 return(TRUE); 01071 } 01072 return(FALSE); 01073 } 01074 01075 static LRESULT CFn_WMDestroy(HWND hwnd, LPCHOOSEFONTW lpcfw) 01076 { 01077 LPCHOOSEFONTA lpcfa; 01078 LPSTR lpszStyle; 01079 LPLOGFONTA lpLogFonta; 01080 int len; 01081 01082 if (!lpcfw) return FALSE; 01083 01084 lpcfa = GetPropW(hwnd, strWineFontData_a); 01085 lpLogFonta = lpcfa->lpLogFont; 01086 lpszStyle = lpcfa->lpszStyle; 01087 memcpy(lpcfa, lpcfw, sizeof(CHOOSEFONTA)); 01088 lpcfa->lpLogFont = lpLogFonta; 01089 lpcfa->lpszStyle = lpszStyle; 01090 memcpy(lpcfa->lpLogFont, lpcfw->lpLogFont, sizeof(LOGFONTA)); 01091 WideCharToMultiByte(CP_ACP, 0, lpcfw->lpLogFont->lfFaceName, 01092 LF_FACESIZE, lpcfa->lpLogFont->lfFaceName, LF_FACESIZE, 0, 0); 01093 01094 if((lpcfw->Flags & CF_USESTYLE) && lpcfw->lpszStyle) { 01095 len = WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, NULL, 0, 0, 0); 01096 WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, lpcfa->lpszStyle, len, 0, 0); 01097 HeapFree(GetProcessHeap(), 0, lpcfw->lpszStyle); 01098 } 01099 01100 HeapFree(GetProcessHeap(), 0, lpcfw->lpLogFont); 01101 HeapFree(GetProcessHeap(), 0, lpcfw); 01102 SetPropW(hwnd, strWineFontData, 0); 01103 01104 return TRUE; 01105 } 01106 01107 static LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam, const CHOOSEFONTW *lpcf) 01108 { 01109 WINDOWINFO info; 01110 01111 if (!lpcf) return FALSE; 01112 01113 info.cbSize=sizeof(info); 01114 if( GetWindowInfo( GetDlgItem( hDlg, stc5), &info ) ) 01115 { 01116 PAINTSTRUCT ps; 01117 HDC hdc; 01118 HPEN hOrigPen; 01119 HFONT hOrigFont; 01120 LOGFONTW lf = *(lpcf->lpLogFont); 01121 01122 MapWindowPoints( 0, hDlg, (LPPOINT) &info.rcWindow, 2); 01123 hdc = BeginPaint( hDlg, &ps ); 01124 01125 TRACE("erase %d, rect=(%d,%d)-(%d,%d)\n", ps.fErase, 01126 ps.rcPaint.left, ps.rcPaint.top, 01127 ps.rcPaint.right, ps.rcPaint.bottom); 01128 01129 /* Paint frame */ 01130 MoveToEx( hdc, info.rcWindow.left, info.rcWindow.bottom, NULL ); 01131 hOrigPen=SelectObject( hdc, CreatePen( PS_SOLID, 2, 01132 GetSysColor( COLOR_3DSHADOW ) )); 01133 LineTo( hdc, info.rcWindow.left, info.rcWindow.top ); 01134 LineTo( hdc, info.rcWindow.right, info.rcWindow.top ); 01135 DeleteObject(SelectObject( hdc, CreatePen( PS_SOLID, 2, 01136 GetSysColor( COLOR_3DLIGHT ) ))); 01137 LineTo( hdc, info.rcWindow.right, info.rcWindow.bottom ); 01138 LineTo( hdc, info.rcWindow.left, info.rcWindow.bottom ); 01139 DeleteObject(SelectObject( hdc, hOrigPen )); 01140 01141 /* Draw the sample text itself */ 01142 info.rcWindow.right--; 01143 info.rcWindow.bottom--; 01144 info.rcWindow.top++; 01145 info.rcWindow.left++; 01146 hOrigFont = SelectObject( hdc, CreateFontIndirectW( &lf ) ); 01147 SetTextColor( hdc, lpcf->rgbColors ); 01148 01149 DrawTextW( hdc, 01150 sample_lang_text[CHARSET_ORDER[lpcf->lpLogFont->lfCharSet]], 01151 -1, &info.rcWindow, DT_CENTER|DT_VCENTER|DT_SINGLELINE ); 01152 01153 DeleteObject(SelectObject( hdc, hOrigFont )); 01154 EndPaint( hDlg, &ps ); 01155 } 01156 return FALSE; 01157 } 01158 01159 /*********************************************************************** 01160 * FormatCharDlgProcA [internal] 01161 */ 01162 static INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 01163 { 01164 LPCHOOSEFONTW lpcfw; 01165 LPCHOOSEFONTA lpcfa; 01166 INT_PTR res = FALSE; 01167 int len; 01168 01169 if (uMsg!=WM_INITDIALOG) { 01170 lpcfw = GetPropW(hDlg, strWineFontData); 01171 if (lpcfw && CFn_HookCallChk32(lpcfw)) 01172 res=CallWindowProcA((WNDPROC)lpcfw->lpfnHook, hDlg, uMsg, wParam, lParam); 01173 if (res) 01174 return res; 01175 } else { 01176 lpcfa=(LPCHOOSEFONTA)lParam; 01177 SetPropW(hDlg, strWineFontData_a, (HANDLE)lParam); 01178 01179 lpcfw = HeapAlloc(GetProcessHeap(), 0, sizeof(CHOOSEFONTW)); 01180 memcpy(lpcfw, lpcfa, sizeof(CHOOSEFONTA)); 01181 lpcfw->lpLogFont = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGFONTW)); 01182 memcpy(lpcfw->lpLogFont, lpcfa->lpLogFont, sizeof(LOGFONTA)); 01183 MultiByteToWideChar(CP_ACP, 0, lpcfa->lpLogFont->lfFaceName, 01184 LF_FACESIZE, lpcfw->lpLogFont->lfFaceName, LF_FACESIZE); 01185 01186 if((lpcfa->Flags & CF_USESTYLE) && lpcfa->lpszStyle) { 01187 len = MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, NULL, 0); 01188 lpcfw->lpszStyle = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); 01189 MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, lpcfw->lpszStyle, len); 01190 } 01191 01192 if (!CFn_WMInitDialog(hDlg, lParam, lpcfw)) 01193 { 01194 TRACE("CFn_WMInitDialog returned FALSE\n"); 01195 return FALSE; 01196 } 01197 if (CFn_HookCallChk32(lpcfw)) 01198 return CallWindowProcA((WNDPROC)lpcfa->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam); 01199 } 01200 switch (uMsg) 01201 { 01202 case WM_MEASUREITEM: 01203 return CFn_WMMeasureItem(hDlg,lParam); 01204 case WM_DRAWITEM: 01205 return CFn_WMDrawItem(lParam); 01206 case WM_COMMAND: 01207 return CFn_WMCommand(hDlg, wParam, lParam, lpcfw); 01208 case WM_DESTROY: 01209 return CFn_WMDestroy(hDlg, lpcfw); 01210 case WM_CHOOSEFONT_GETLOGFONT: 01211 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam); 01212 FIXME("current logfont back to caller\n"); 01213 break; 01214 case WM_PAINT: 01215 return CFn_WMPaint(hDlg, wParam, lParam, lpcfw); 01216 } 01217 return res; 01218 } 01219 01220 /*********************************************************************** 01221 * FormatCharDlgProcW [internal] 01222 */ 01223 static INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 01224 { 01225 LPCHOOSEFONTW lpcf; 01226 INT_PTR res = FALSE; 01227 01228 if (uMsg!=WM_INITDIALOG) 01229 { 01230 lpcf= GetPropW(hDlg, strWineFontData); 01231 if (lpcf && CFn_HookCallChk32(lpcf)) 01232 res=CallWindowProcW((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam); 01233 if (res) 01234 return res; 01235 } 01236 else 01237 { 01238 lpcf=(LPCHOOSEFONTW)lParam; 01239 if (!CFn_WMInitDialog(hDlg, lParam, lpcf)) 01240 { 01241 TRACE("CFn_WMInitDialog returned FALSE\n"); 01242 return FALSE; 01243 } 01244 if (CFn_HookCallChk32(lpcf)) 01245 return CallWindowProcW((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam); 01246 } 01247 switch (uMsg) 01248 { 01249 case WM_MEASUREITEM: 01250 return CFn_WMMeasureItem(hDlg, lParam); 01251 case WM_DRAWITEM: 01252 return CFn_WMDrawItem(lParam); 01253 case WM_COMMAND: 01254 return CFn_WMCommand(hDlg, wParam, lParam, lpcf); 01255 case WM_DESTROY: 01256 return TRUE; 01257 case WM_CHOOSEFONT_GETLOGFONT: 01258 TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam); 01259 FIXME("current logfont back to caller\n"); 01260 break; 01261 case WM_PAINT: 01262 return CFn_WMPaint(hDlg, wParam, lParam, lpcf); 01263 } 01264 return res; 01265 } Generated on Sat May 26 2012 04:21:43 for ReactOS by
1.7.6.1
|