Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/comdlg32/fontdlg.c
8841 views
1
/*
2
* COMMDLG - Font Dialog
3
*
4
* Copyright 1994 Martin Ayotte
5
* Copyright 1996 Albrecht Kleine
6
*
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
11
*
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
16
*
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20
*/
21
22
#include <ctype.h>
23
#include <stdlib.h>
24
#include <stdarg.h>
25
#include <stdio.h>
26
#include <string.h>
27
#include "windef.h"
28
#include "winbase.h"
29
#include "winnls.h"
30
#include "wingdi.h"
31
#include "winuser.h"
32
#include "commdlg.h"
33
#include "dlgs.h"
34
#include "wine/debug.h"
35
#include "cderr.h"
36
#include "cdlg.h"
37
38
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
39
40
typedef struct
41
{
42
HWND hWnd1;
43
HWND hWnd2;
44
LPCHOOSEFONTW lpcf32w;
45
int added;
46
} CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;
47
48
49
static const WCHAR strWineFontData[] = L"__WINE_FONTDLGDATA";
50
static const WCHAR strWineFontData_a[] = L"__WINE_FONTDLGDATA_A";
51
52
/* image list with TrueType bitmaps and more */
53
static HIMAGELIST himlTT = 0;
54
#define TTBITMAP_XSIZE 20 /* x-size of the bitmaps */
55
56
static INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
57
static INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
58
59
/* There is a table here of all charsets, and the sample text for each.
60
* There is a second table that translates a charset into an index into
61
* the first table.
62
*/
63
64
#define CI(cs) ((IDS_CHARSET_##cs)-IDS_CHARSET_ANSI)
65
66
static const WCHAR * const sample_lang_text[]={
67
L"AaBbYyZz", /* Western and default */
68
L"Symbol", /* Symbol */
69
L"Aa\x3042\x3041\x30a2\x30a1\x4e9c\x5b87", /* Shift JIS */
70
L"\xac00\xb098\xb2e4" "AaBYyZz", /* Hangul */
71
L"\x5fae\x8f6f\x4e2d\x6587\x8f6f\x4ef6", /* GB2312 */
72
L"\x4e2d\x6587\x5b57\x578b\x7bc4\x4f8b", /* BIG5 */
73
L"AaBb\x0391\x03b1\x0392\x03b2", /* Greek */
74
L"AaBb\x011e\x011f\x015e\x015f", /* Turkish */
75
L"AaBb\x05e0\x05e1\x05e9\x05ea", /* Hebrew */
76
L"AaBb\x0627\x0628\x062c\x062f\x0647\x0648\x0632", /* Arabic */
77
L"AaBbYyZz", /* Baltic */
78
L"AaBb\x01a0\x01a1\x01af\x01b0", /* Vietnamese */
79
L"AaBb\x0411\x0431\x0424\x0444", /* Cyrillic */
80
L"AaBb\x00c1\x00e1\x00d4\x00f4", /* East European */
81
L"AaBb\x0e2d\x0e31\x0e01\x0e29\x0e23\x0e44\x0e17\x0e22", /* Thai */
82
L"\xac00\xb098\xb2e4" "AaBYyZz", /* Johab */
83
L"AaBbYyZz", /* Mac */
84
L"AaBb\x00f8\x00f1\x00fd", /* OEM */
85
/* the following character sets actually behave different (Win2K observation):
86
* the sample string is 'sticky': it uses the sample string of the previous
87
* selected character set. That behaviour looks like some default, which is
88
* not (yet) implemented. */
89
L"AaBb", /* VISCII */
90
L"AaBb", /* TCVN */
91
L"AaBb", /* KOI-8 */
92
L"AaBb", /* ISO-8859-3 */
93
L"AaBb", /* ISO-8859-4 */
94
L"AaBb", /* ISO-8859-10 */
95
L"AaBb" /* Celtic */
96
};
97
98
99
static const BYTE CHARSET_ORDER[256]={
100
CI(ANSI), 0, CI(SYMBOL), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(MAC), 0, 0,
105
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
106
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
107
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
108
CI(JIS), CI(HANGUL), CI(JOHAB), 0, 0, 0, CI(GB2312), 0, CI(BIG5), 0, 0, 0, 0, 0, 0, 0,
109
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110
0, CI(GREEK), CI(TURKISH), CI(VIETNAMESE), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
111
0, CI(HEBREW), CI(ARABIC), 0, 0, 0, 0, 0, 0, 0, CI(BALTIC), 0, 0, 0, 0, 0,
112
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(RUSSIAN), 0, 0, 0,
113
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(THAI), 0,
114
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(EE), 0,
115
CI(VISCII), CI(TCVN), CI(KOI8), CI(ISO3), CI(ISO4), CI(ISO10), CI(CELTIC), 0, 0, 0, 0, 0, 0, 0, 0, CI(OEM),
116
};
117
118
static const struct {
119
DWORD mask;
120
const char *name;
121
} cfflags[] = {
122
#define XX(x) { x, #x },
123
XX(CF_SCREENFONTS)
124
XX(CF_PRINTERFONTS)
125
XX(CF_SHOWHELP)
126
XX(CF_ENABLEHOOK)
127
XX(CF_ENABLETEMPLATE)
128
XX(CF_ENABLETEMPLATEHANDLE)
129
XX(CF_INITTOLOGFONTSTRUCT)
130
XX(CF_USESTYLE)
131
XX(CF_EFFECTS)
132
XX(CF_APPLY)
133
XX(CF_ANSIONLY)
134
XX(CF_NOVECTORFONTS)
135
XX(CF_NOSIMULATIONS)
136
XX(CF_LIMITSIZE)
137
XX(CF_FIXEDPITCHONLY)
138
XX(CF_WYSIWYG)
139
XX(CF_FORCEFONTEXIST)
140
XX(CF_SCALABLEONLY)
141
XX(CF_TTONLY)
142
XX(CF_NOFACESEL)
143
XX(CF_NOSTYLESEL)
144
XX(CF_NOSIZESEL)
145
XX(CF_SELECTSCRIPT)
146
XX(CF_NOSCRIPTSEL)
147
XX(CF_NOVERTFONTS)
148
#undef XX
149
};
150
151
static void _dump_cf_flags(DWORD cflags)
152
{
153
unsigned int i;
154
155
for (i = 0; i < ARRAY_SIZE(cfflags); i++)
156
if (cfflags[i].mask & cflags)
157
TRACE("%s|",cfflags[i].name);
158
TRACE("\n");
159
}
160
161
/***********************************************************************
162
* ChooseFontW (COMDLG32.@)
163
*
164
* Create a font dialog box.
165
*
166
* PARAMS
167
* lpChFont [I/O] in: information to initialize the dialog box.
168
* out: User's color selection
169
*
170
* RETURNS
171
* TRUE: Ok button clicked.
172
* FALSE: Cancel button clicked, or error.
173
*/
174
BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
175
{
176
LPCVOID template;
177
HRSRC hResInfo;
178
HINSTANCE hDlginst;
179
HGLOBAL hDlgTmpl;
180
181
TRACE("(%p)\n", lpChFont);
182
183
if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
184
{
185
template=lpChFont->hInstance;
186
} else
187
{
188
if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
189
{
190
hDlginst=lpChFont->hInstance;
191
if( !(hResInfo = FindResourceW(hDlginst, lpChFont->lpTemplateName,
192
(LPWSTR)RT_DIALOG)))
193
{
194
COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
195
return FALSE;
196
}
197
} else
198
{
199
hDlginst=COMDLG32_hInstance;
200
if (!(hResInfo = FindResourceW(hDlginst, L"CHOOSE_FONT", (LPWSTR)RT_DIALOG)))
201
{
202
COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
203
return FALSE;
204
}
205
}
206
if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
207
!(template = LockResource( hDlgTmpl )))
208
{
209
COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
210
return FALSE;
211
}
212
}
213
if (TRACE_ON(commdlg))
214
_dump_cf_flags(lpChFont->Flags);
215
216
if (lpChFont->Flags & CF_SELECTSCRIPT)
217
FIXME(": unimplemented flag (ignored)\n");
218
219
return DialogBoxIndirectParamW(COMDLG32_hInstance, template,
220
lpChFont->hwndOwner, FormatCharDlgProcW, (LPARAM)lpChFont );
221
}
222
223
/***********************************************************************
224
* ChooseFontA (COMDLG32.@)
225
*
226
* See ChooseFontW.
227
*/
228
BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
229
{
230
LPCVOID template;
231
HRSRC hResInfo;
232
HINSTANCE hDlginst;
233
HGLOBAL hDlgTmpl;
234
235
TRACE("(%p)\n", lpChFont);
236
237
if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
238
{
239
template=lpChFont->hInstance;
240
} else
241
{
242
if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
243
{
244
hDlginst=lpChFont->hInstance;
245
if( !(hResInfo = FindResourceA(hDlginst, lpChFont->lpTemplateName,
246
(LPSTR)RT_DIALOG)))
247
{
248
COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
249
return FALSE;
250
}
251
} else
252
{
253
hDlginst=COMDLG32_hInstance;
254
if (!(hResInfo = FindResourceW(hDlginst, L"CHOOSE_FONT", (LPWSTR)RT_DIALOG)))
255
{
256
COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
257
return FALSE;
258
}
259
}
260
if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
261
!(template = LockResource( hDlgTmpl )))
262
{
263
COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
264
return FALSE;
265
}
266
}
267
if (TRACE_ON(commdlg))
268
_dump_cf_flags(lpChFont->Flags);
269
if (lpChFont->Flags & CF_SELECTSCRIPT)
270
FIXME(": unimplemented flag (ignored)\n");
271
272
return DialogBoxIndirectParamA(COMDLG32_hInstance, template,
273
lpChFont->hwndOwner, FormatCharDlgProcA, (LPARAM)lpChFont );
274
}
275
276
#define TEXT_EXTRAS 4
277
#define TEXT_COLORS 16
278
279
static const COLORREF textcolors[TEXT_COLORS]=
280
{
281
0x00000000L,0x00000080L,0x00008000L,0x00008080L,
282
0x00800000L,0x00800080L,0x00808000L,0x00808080L,
283
0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
284
0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
285
};
286
287
/***********************************************************************
288
* CFn_HookCallChk32 [internal]
289
*/
290
static BOOL CFn_HookCallChk32(const CHOOSEFONTW *lpcf)
291
{
292
if (lpcf)
293
if(lpcf->Flags & CF_ENABLEHOOK)
294
if (lpcf->lpfnHook)
295
return TRUE;
296
return FALSE;
297
}
298
299
/*************************************************************************
300
* AddFontFamily [internal]
301
*/
302
static INT AddFontFamily(const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM,
303
UINT nFontType, const CHOOSEFONTW *lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e)
304
{
305
int i;
306
WORD w;
307
const LOGFONTW *lplf = &(lpElfex->elfLogFont);
308
309
TRACE("font=%s (nFontType=%d)\n", debugstr_w(lplf->lfFaceName), nFontType);
310
311
if (lpcf->Flags & CF_FIXEDPITCHONLY)
312
if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
313
return 1;
314
if (lpcf->Flags & CF_ANSIONLY)
315
if (lplf->lfCharSet != ANSI_CHARSET)
316
return 1;
317
if (lpcf->Flags & CF_TTONLY)
318
if (!(nFontType & TRUETYPE_FONTTYPE))
319
return 1;
320
if (lpcf->Flags & CF_NOVERTFONTS)
321
if (lplf->lfFaceName[0] == '@')
322
return 1;
323
324
if (e) e->added++;
325
326
i=SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)lplf->lfFaceName);
327
if (i == CB_ERR) {
328
i = SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
329
if( i != CB_ERR) {
330
/* store some important font information */
331
w = (lplf->lfPitchAndFamily) << 8 |
332
(HIWORD(lpNTM->ntmTm.ntmFlags) & 0xff);
333
SendMessageW(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
334
}
335
}
336
return 1;
337
}
338
339
/*************************************************************************
340
* FontFamilyEnumProc32 [internal]
341
*/
342
static INT WINAPI FontFamilyEnumProc(const ENUMLOGFONTEXW *lpElfex,
343
const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam)
344
{
345
LPCFn_ENUMSTRUCT e;
346
e=(LPCFn_ENUMSTRUCT)lParam;
347
return AddFontFamily( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
348
dwFontType, e->lpcf32w, e->hWnd1, e);
349
}
350
351
/*************************************************************************
352
* SetFontStylesToCombo2 [internal]
353
*
354
* Fill font style information into combobox (without using font.c directly)
355
*/
356
static BOOL SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTW *lplf)
357
{
358
#define FSTYLES 4
359
struct FONTSTYLE
360
{
361
int italic;
362
int weight;
363
UINT resId;
364
};
365
static const struct FONTSTYLE fontstyles[FSTYLES]={
366
{ 0, FW_NORMAL, IDS_FONT_REGULAR },
367
{ 1, FW_NORMAL, IDS_FONT_ITALIC },
368
{ 0, FW_BOLD, IDS_FONT_BOLD },
369
{ 1, FW_BOLD, IDS_FONT_BOLD_ITALIC }
370
};
371
HFONT hf;
372
TEXTMETRICW tm;
373
int i,j;
374
LOGFONTW lf;
375
376
lf = *lplf;
377
378
for (i=0;i<FSTYLES;i++)
379
{
380
lf.lfItalic=fontstyles[i].italic;
381
lf.lfWeight=fontstyles[i].weight;
382
hf=CreateFontIndirectW(&lf);
383
hf=SelectObject(hdc,hf);
384
GetTextMetricsW(hdc,&tm);
385
hf=SelectObject(hdc,hf);
386
DeleteObject(hf);
387
/* font successful created ? */
388
if (((fontstyles[i].weight == FW_NORMAL && tm.tmWeight <= FW_MEDIUM) ||
389
(fontstyles[i].weight == FW_BOLD && tm.tmWeight > FW_MEDIUM)) &&
390
((tm.tmItalic != 0)==fontstyles[i].italic))
391
{
392
WCHAR name[64];
393
LoadStringW(COMDLG32_hInstance, fontstyles[i].resId, name, 64);
394
j=SendMessageW(hwnd,CB_ADDSTRING,0,(LPARAM)name );
395
if (j==CB_ERR) return TRUE;
396
j=SendMessageW(hwnd, CB_SETITEMDATA, j,
397
MAKELONG(tm.tmWeight,fontstyles[i].italic));
398
if (j==CB_ERR) return TRUE;
399
}
400
}
401
return FALSE;
402
}
403
404
/*************************************************************************
405
* AddFontSizeToCombo3 [internal]
406
*/
407
static BOOL AddFontSizeToCombo3(HWND hwnd, UINT h, const CHOOSEFONTW *lpcf)
408
{
409
int j;
410
WCHAR buffer[20];
411
412
if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
413
((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
414
{
415
swprintf(buffer, ARRAY_SIZE(buffer), L"%d", h);
416
j=SendMessageW(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
417
if (j==CB_ERR)
418
{
419
j=SendMessageW(hwnd, CB_INSERTSTRING, -1, (LPARAM)buffer);
420
if (j!=CB_ERR) j = SendMessageW(hwnd, CB_SETITEMDATA, j, h);
421
if (j==CB_ERR) return TRUE;
422
}
423
}
424
return FALSE;
425
}
426
427
/*************************************************************************
428
* SetFontSizesToCombo3 [internal]
429
*/
430
static BOOL SetFontSizesToCombo3(HWND hwnd, const CHOOSEFONTW *lpcf)
431
{
432
static const BYTE sizes[]={6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
433
unsigned int i;
434
435
for (i = 0; i < ARRAY_SIZE(sizes); i++)
436
if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return TRUE;
437
return FALSE;
438
}
439
440
/*************************************************************************
441
* CFn_GetDC [internal]
442
*/
443
static inline HDC CFn_GetDC(const CHOOSEFONTW *lpcf)
444
{
445
HDC ret = ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ?
446
lpcf->hDC :
447
GetDC(0);
448
if(!ret) ERR("HDC failure!!!\n");
449
return ret;
450
}
451
452
/*************************************************************************
453
* GetScreenDPI [internal]
454
*/
455
static inline int GetScreenDPI(void)
456
{
457
HDC hdc;
458
int result;
459
460
hdc = GetDC(0);
461
result = GetDeviceCaps(hdc, LOGPIXELSY);
462
ReleaseDC(0, hdc);
463
464
return result;
465
}
466
467
/*************************************************************************
468
* CFn_ReleaseDC [internal]
469
*/
470
static inline void CFn_ReleaseDC(const CHOOSEFONTW *lpcf, HDC hdc)
471
{
472
if(!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
473
ReleaseDC(0, hdc);
474
}
475
476
/*************************************************************************
477
* select_combo_item [internal]
478
*/
479
static void select_combo_item( HWND dialog, int id, int sel )
480
{
481
HWND combo = GetDlgItem( dialog, id );
482
SendMessageW( combo, CB_SETCURSEL, sel, 0 );
483
SendMessageW( dialog, WM_COMMAND, MAKEWPARAM( id, CBN_SELCHANGE ), (LPARAM)combo );
484
}
485
486
/***********************************************************************
487
* AddFontStyle [internal]
488
*/
489
static INT AddFontStyle( const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM,
490
UINT nFontType, const CHOOSEFONTW *lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg)
491
{
492
int i;
493
const LOGFONTW *lplf = &(lpElfex->elfLogFont);
494
HWND hcmb5;
495
HDC hdc;
496
497
TRACE("(nFontType=%d)\n",nFontType);
498
TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
499
" ch=%d op=%d cp=%d q=%d pf=%xh\n",
500
debugstr_w(lplf->lfFaceName),lplf->lfHeight,lplf->lfWidth,
501
lplf->lfEscapement,lplf->lfOrientation,
502
lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
503
lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
504
lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
505
if (nFontType & RASTER_FONTTYPE)
506
{
507
INT points;
508
points = MulDiv( lpNTM->ntmTm.tmHeight - lpNTM->ntmTm.tmInternalLeading,
509
72, GetScreenDPI());
510
if (AddFontSizeToCombo3(hcmb3, points, lpcf))
511
return 0;
512
} else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
513
514
if (!SendMessageW(hcmb2, CB_GETCOUNT, 0, 0))
515
{
516
BOOL res;
517
if(!(hdc = CFn_GetDC(lpcf))) return 0;
518
res = SetFontStylesToCombo2(hcmb2,hdc,lplf);
519
CFn_ReleaseDC(lpcf, hdc);
520
if (res)
521
return 0;
522
}
523
if (!( hcmb5 = GetDlgItem(hDlg, cmb5))) return 1;
524
i = SendMessageW( hcmb5, CB_FINDSTRINGEXACT, 0,
525
(LPARAM)lpElfex->elfScript);
526
if( i == CB_ERR) {
527
i = SendMessageW( hcmb5, CB_ADDSTRING, 0,
528
(LPARAM)lpElfex->elfScript);
529
if( i != CB_ERR)
530
SendMessageW( hcmb5, CB_SETITEMDATA, i, lplf->lfCharSet);
531
}
532
return 1 ;
533
}
534
535
static void CFn_FitFontSize( HWND hDlg, int points)
536
{
537
int i,n;
538
539
/* look for fitting font size in combobox3 */
540
n=SendDlgItemMessageW(hDlg, cmb3, CB_GETCOUNT, 0, 0);
541
for (i=0;i<n;i++)
542
{
543
if (points == (int)SendDlgItemMessageW
544
(hDlg,cmb3, CB_GETITEMDATA,i,0))
545
{
546
select_combo_item( hDlg, cmb3, i );
547
return;
548
}
549
}
550
551
/* no default matching size, set text manually */
552
SetDlgItemInt(hDlg, cmb3, points, TRUE);
553
}
554
555
static BOOL CFn_FitFontStyle( HWND hDlg, LONG packedstyle )
556
{
557
LONG id;
558
int i;
559
/* look for fitting font style in combobox2 */
560
for (i=0;i<TEXT_EXTRAS;i++)
561
{
562
id = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
563
if (packedstyle == id)
564
{
565
select_combo_item( hDlg, cmb2, i );
566
return TRUE;
567
}
568
}
569
return FALSE;
570
}
571
572
573
static BOOL CFn_FitCharSet( HWND hDlg, int charset )
574
{
575
int i,n,cs;
576
/* look for fitting char set in combobox5 */
577
n=SendDlgItemMessageW(hDlg, cmb5, CB_GETCOUNT, 0, 0);
578
for (i=0;i<n;i++)
579
{
580
cs =SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
581
if (charset == cs)
582
{
583
select_combo_item( hDlg, cmb5, i );
584
return TRUE;
585
}
586
}
587
/* no charset fits: select the first one in the list */
588
select_combo_item( hDlg, cmb5, 0 );
589
return FALSE;
590
}
591
592
/***********************************************************************
593
* FontStyleEnumProc32 [internal]
594
*/
595
static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXW *lpElfex,
596
const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam )
597
{
598
LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
599
HWND hcmb2=s->hWnd1;
600
HWND hcmb3=s->hWnd2;
601
HWND hDlg=GetParent(hcmb3);
602
return AddFontStyle( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
603
dwFontType, s->lpcf32w, hcmb2, hcmb3, hDlg);
604
}
605
606
/***********************************************************************
607
* CFn_WMInitDialog [internal]
608
*/
609
static LRESULT CFn_WMInitDialog(HWND hDlg, LPARAM lParam, LPCHOOSEFONTW lpcf)
610
{
611
HDC hdc;
612
int i,j;
613
BOOL init = FALSE;
614
long pstyle;
615
CFn_ENUMSTRUCT s;
616
LPLOGFONTW lpxx;
617
HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
618
619
SetPropW(hDlg, strWineFontData, lpcf);
620
lpxx=lpcf->lpLogFont;
621
TRACE("WM_INITDIALOG lParam=%08IX\n", lParam);
622
623
if (lpcf->lStructSize != sizeof(CHOOSEFONTW))
624
{
625
ERR("structure size failure!!!\n");
626
EndDialog (hDlg, 0);
627
return FALSE;
628
}
629
if (!himlTT)
630
himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
631
TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
632
633
/* Set effect flags */
634
if((lpcf->Flags & CF_EFFECTS) && (lpcf->Flags & CF_INITTOLOGFONTSTRUCT))
635
{
636
if(lpxx->lfUnderline)
637
CheckDlgButton(hDlg, chx2, TRUE);
638
if(lpxx->lfStrikeOut)
639
CheckDlgButton(hDlg, chx1, TRUE);
640
}
641
642
if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
643
ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
644
if (!(lpcf->Flags & CF_APPLY))
645
ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
646
if (lpcf->Flags & CF_NOSCRIPTSEL)
647
EnableWindow(GetDlgItem(hDlg,cmb5),FALSE);
648
if (lpcf->Flags & CF_EFFECTS)
649
{
650
for (i=0;i<TEXT_COLORS;i++)
651
{
652
WCHAR name[30];
653
654
if (LoadStringW(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name, ARRAY_SIZE(name)) == 0)
655
lstrcpyW(name, L"[color name]");
656
j=SendDlgItemMessageW(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
657
SendDlgItemMessageW(hDlg, cmb4, CB_SETITEMDATA, j, textcolors[i]);
658
/* look for a fitting value in color combobox */
659
if (textcolors[i]==lpcf->rgbColors)
660
SendDlgItemMessageW(hDlg,cmb4, CB_SETCURSEL,j,0);
661
}
662
}
663
else
664
{
665
ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
666
ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
667
ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
668
ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
669
ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
670
}
671
if(!(hdc = CFn_GetDC(lpcf)))
672
{
673
EndDialog (hDlg, 0);
674
return FALSE;
675
}
676
s.hWnd1=GetDlgItem(hDlg,cmb1);
677
s.lpcf32w=lpcf;
678
do {
679
LOGFONTW elf;
680
s.added = 0;
681
elf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
682
elf.lfPitchAndFamily = 0;
683
elf.lfFaceName[0] = '\0'; /* enum all fonts */
684
if (!EnumFontFamiliesExW(hdc, &elf, (FONTENUMPROCW)FontFamilyEnumProc, (LPARAM)&s, 0))
685
{
686
TRACE("EnumFontFamiliesEx returns 0\n");
687
break;
688
}
689
if (s.added) break;
690
if (lpcf->Flags & CF_FIXEDPITCHONLY) {
691
FIXME("No font found with fixed pitch only, dropping flag.\n");
692
lpcf->Flags &= ~CF_FIXEDPITCHONLY;
693
continue;
694
}
695
if (lpcf->Flags & CF_TTONLY) {
696
FIXME("No font found with truetype only, dropping flag.\n");
697
lpcf->Flags &= ~CF_TTONLY;
698
continue;
699
}
700
break;
701
} while (1);
702
703
704
if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
705
{
706
/* look for fitting font name in combobox1 */
707
j=SendDlgItemMessageW(hDlg,cmb1,CB_FINDSTRING,-1,(LPARAM)lpxx->lfFaceName);
708
if (j!=CB_ERR)
709
{
710
INT height = lpxx->lfHeight < 0 ? -lpxx->lfHeight :
711
lpxx->lfHeight;
712
INT points;
713
int charset = lpxx->lfCharSet;
714
points = MulDiv( height, 72, GetScreenDPI());
715
pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:
716
FW_NORMAL,lpxx->lfItalic !=0);
717
select_combo_item( hDlg, cmb1, j );
718
init = TRUE;
719
/* look for fitting font style in combobox2 */
720
CFn_FitFontStyle(hDlg, pstyle);
721
/* look for fitting font size in combobox3 */
722
CFn_FitFontSize(hDlg, points);
723
CFn_FitCharSet( hDlg, charset );
724
}
725
}
726
if (!init)
727
{
728
select_combo_item( hDlg, cmb1, 0 );
729
select_combo_item( hDlg, cmb2, 0 );
730
select_combo_item( hDlg, cmb3, 0 );
731
select_combo_item( hDlg, cmb5, 0 );
732
}
733
/* limit text length user can type in as font size */
734
SendDlgItemMessageW(hDlg, cmb3, CB_LIMITTEXT, 5, 0);
735
736
if ((lpcf->Flags & CF_USESTYLE) && lpcf->lpszStyle)
737
{
738
j=SendDlgItemMessageW(hDlg,cmb2,CB_FINDSTRING,-1,(LPARAM)lpcf->lpszStyle);
739
if (j!=CB_ERR) select_combo_item( hDlg, cmb2, j );
740
}
741
CFn_ReleaseDC(lpcf, hdc);
742
SetCursor(hcursor);
743
return TRUE;
744
}
745
746
747
/***********************************************************************
748
* CFn_WMMeasureItem [internal]
749
*/
750
static LRESULT CFn_WMMeasureItem(HWND hDlg, LPARAM lParam)
751
{
752
HDC hdc;
753
HFONT hfontprev;
754
TEXTMETRICW tm;
755
LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
756
INT height = 0, cx;
757
758
if (!himlTT)
759
himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
760
TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
761
ImageList_GetIconSize( himlTT, &cx, &height);
762
lpmi->itemHeight = height + 2;
763
/* use MAX of bitmap height and tm.tmHeight .*/
764
hdc=GetDC(hDlg);
765
if(!hdc) return 0;
766
hfontprev = SelectObject( hdc, (HFONT)SendMessageW( hDlg, WM_GETFONT, 0, 0 ));
767
GetTextMetricsW(hdc, &tm);
768
if( tm.tmHeight > lpmi->itemHeight) lpmi->itemHeight = tm.tmHeight;
769
SelectObject(hdc, hfontprev);
770
ReleaseDC(hDlg, hdc);
771
return 0;
772
}
773
774
775
/***********************************************************************
776
* CFn_WMDrawItem [internal]
777
*/
778
static LRESULT CFn_WMDrawItem(LPARAM lParam)
779
{
780
HBRUSH hBrush;
781
WCHAR buffer[40];
782
COLORREF cr, oldText=0, oldBk=0;
783
RECT rect;
784
int nFontType;
785
int cx, cy, idx;
786
LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
787
788
if (lpdi->itemID == (UINT)-1) /* got no items */
789
DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
790
else
791
{
792
if (lpdi->CtlType == ODT_COMBOBOX)
793
{
794
if (lpdi->itemState & ODS_SELECTED)
795
{
796
hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
797
oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
798
oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
799
} else
800
{
801
hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
802
SelectObject(lpdi->hDC, hBrush);
803
}
804
FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
805
}
806
else
807
return TRUE; /* this should never happen */
808
809
rect=lpdi->rcItem;
810
switch (lpdi->CtlID)
811
{
812
case cmb1:
813
/* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
814
ImageList_GetIconSize( himlTT, &cx, &cy);
815
SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
816
(LPARAM)buffer);
817
TextOutW(lpdi->hDC, lpdi->rcItem.left + cx + 4,
818
lpdi->rcItem.top, buffer, lstrlenW(buffer));
819
nFontType = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
820
idx = -1;
821
if (nFontType & TRUETYPE_FONTTYPE) {
822
idx = 0; /* picture: TT */
823
if( nFontType & NTM_TT_OPENTYPE)
824
idx = 2; /* picture: O */
825
} else if( nFontType & NTM_PS_OPENTYPE)
826
idx = 3; /* picture: O+ps */
827
else if( nFontType & NTM_TYPE1)
828
idx = 4; /* picture: a */
829
else if( nFontType & DEVICE_FONTTYPE)
830
idx = 1; /* picture: printer */
831
if( idx >= 0)
832
ImageList_Draw( himlTT, idx, lpdi->hDC, lpdi->rcItem.left,
833
(lpdi->rcItem.top + lpdi->rcItem.bottom - cy) / 2, ILD_TRANSPARENT);
834
break;
835
case cmb2:
836
case cmb3:
837
/* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
838
case cmb5:
839
SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
840
(LPARAM)buffer);
841
TextOutW(lpdi->hDC, lpdi->rcItem.left,
842
lpdi->rcItem.top, buffer, lstrlenW(buffer));
843
break;
844
845
case cmb4:
846
/* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
847
SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
848
(LPARAM)buffer);
849
TextOutW(lpdi->hDC, lpdi->rcItem.left + 25+5,
850
lpdi->rcItem.top, buffer, lstrlenW(buffer));
851
cr = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
852
hBrush = CreateSolidBrush(cr);
853
if (hBrush)
854
{
855
hBrush = SelectObject (lpdi->hDC, hBrush) ;
856
rect.right=rect.left+25;
857
rect.top++;
858
rect.left+=5;
859
rect.bottom--;
860
Rectangle( lpdi->hDC, rect.left, rect.top,
861
rect.right, rect.bottom );
862
DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
863
}
864
rect=lpdi->rcItem;
865
rect.left+=25+5;
866
break;
867
868
default:
869
return TRUE; /* this should never happen */
870
}
871
if (lpdi->itemState & ODS_SELECTED)
872
{
873
SetTextColor(lpdi->hDC, oldText);
874
SetBkColor(lpdi->hDC, oldBk);
875
}
876
}
877
return TRUE;
878
}
879
880
static INT get_dialog_font_point_size(HWND hDlg, CHOOSEFONTW *cf)
881
{
882
BOOL invalid_size = FALSE;
883
INT i, size;
884
885
i = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
886
if (i != CB_ERR)
887
size = LOWORD(SendDlgItemMessageW(hDlg, cmb3, CB_GETITEMDATA , i, 0));
888
else
889
{
890
WCHAR buffW[8], *endptrW;
891
892
GetDlgItemTextW(hDlg, cmb3, buffW, ARRAY_SIZE(buffW));
893
size = wcstol(buffW, &endptrW, 10);
894
invalid_size = size == 0 && *endptrW;
895
896
if (size == 0)
897
size = 10;
898
}
899
900
cf->iPointSize = 10 * size;
901
cf->lpLogFont->lfHeight = -MulDiv(cf->iPointSize, GetScreenDPI(), 720);
902
return invalid_size ? -1 : size;
903
}
904
905
/***********************************************************************
906
* CFn_WMCommand [internal]
907
*/
908
static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFONTW lpcf)
909
{
910
int i;
911
long l;
912
HDC hdc;
913
BOOL cmb_selected_by_edit = FALSE;
914
915
if (!lpcf) return FALSE;
916
917
if(HIWORD(wParam) == CBN_EDITCHANGE)
918
{
919
int idx;
920
WCHAR str_edit[256], str_cmb[256];
921
int cmb = LOWORD(wParam);
922
923
GetDlgItemTextW(hDlg, cmb, str_edit, ARRAY_SIZE(str_edit));
924
idx = SendDlgItemMessageW(hDlg, cmb, CB_FINDSTRING, -1, (LPARAM)str_edit);
925
if(idx != -1)
926
{
927
SendDlgItemMessageW(hDlg, cmb, CB_GETLBTEXT, idx, (LPARAM)str_cmb);
928
929
/* Select listbox entry only if we have an exact match */
930
if(lstrcmpiW(str_edit, str_cmb) == 0)
931
{
932
SendDlgItemMessageW(hDlg, cmb, CB_SETCURSEL, idx, 0);
933
SendDlgItemMessageW(hDlg, cmb, CB_SETEDITSEL, 0, -1); /* Remove edit field selection */
934
cmb_selected_by_edit = TRUE;
935
}
936
}
937
}
938
939
TRACE("WM_COMMAND wParam=%08IX lParam=%08IX\n", wParam, lParam);
940
switch (LOWORD(wParam))
941
{
942
case cmb1:
943
if (HIWORD(wParam) == CBN_SELCHANGE || cmb_selected_by_edit)
944
{
945
INT pointsize; /* save current pointsize */
946
LONG pstyle; /* save current style */
947
int charset;
948
int idx;
949
if(!(hdc = CFn_GetDC(lpcf)))
950
{
951
EndDialog (hDlg, 0);
952
return TRUE;
953
}
954
idx = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
955
pointsize = (int)SendDlgItemMessageW( hDlg, cmb3, CB_GETITEMDATA,
956
idx, 0);
957
idx = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
958
pstyle = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, idx, 0);
959
idx = SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
960
charset = SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, idx, 0);
961
962
SendDlgItemMessageW(hDlg, cmb2, CB_RESETCONTENT, 0, 0);
963
SendDlgItemMessageW(hDlg, cmb3, CB_RESETCONTENT, 0, 0);
964
SendDlgItemMessageW(hDlg, cmb5, CB_RESETCONTENT, 0, 0);
965
i=SendDlgItemMessageW(hDlg, cmb1, CB_GETCURSEL, 0, 0);
966
if (i!=CB_ERR)
967
{
968
HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
969
CFn_ENUMSTRUCT s;
970
LOGFONTW enumlf;
971
SendDlgItemMessageW(hDlg, cmb1, CB_GETLBTEXT, i,
972
(LPARAM)enumlf.lfFaceName);
973
TRACE("WM_COMMAND/cmb1 =>%s\n", debugstr_w(enumlf.lfFaceName));
974
s.hWnd1=GetDlgItem(hDlg, cmb2);
975
s.hWnd2=GetDlgItem(hDlg, cmb3);
976
s.lpcf32w=lpcf;
977
enumlf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
978
enumlf.lfPitchAndFamily = 0;
979
EnumFontFamiliesExW(hdc, &enumlf,
980
(FONTENUMPROCW)FontStyleEnumProc, (LPARAM)&s, 0);
981
CFn_FitFontStyle(hDlg, pstyle);
982
if( pointsize != CB_ERR) CFn_FitFontSize(hDlg, pointsize);
983
if( charset != CB_ERR) CFn_FitCharSet( hDlg, charset );
984
SetCursor(hcursor);
985
}
986
CFn_ReleaseDC(lpcf, hdc);
987
}
988
break;
989
case chx1:
990
case chx2:
991
case cmb2:
992
case cmb3:
993
case cmb5:
994
if (HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == BN_CLICKED || cmb_selected_by_edit)
995
{
996
WCHAR str[256];
997
WINDOWINFO wininfo;
998
LPLOGFONTW lpxx=lpcf->lpLogFont;
999
1000
TRACE("WM_COMMAND/cmb2,3 =%08IX\n", lParam);
1001
1002
/* face name */
1003
i=SendDlgItemMessageW(hDlg,cmb1,CB_GETCURSEL,0,0);
1004
if (i==CB_ERR)
1005
GetDlgItemTextW( hDlg, cmb1, str, ARRAY_SIZE(str));
1006
else
1007
{
1008
SendDlgItemMessageW(hDlg,cmb1,CB_GETLBTEXT,i,
1009
(LPARAM)str);
1010
l=SendDlgItemMessageW(hDlg,cmb1,CB_GETITEMDATA,i,0);
1011
lpcf->nFontType = LOWORD(l);
1012
/* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
1013
/* same value reported to the EnumFonts
1014
call back with the extra FONTTYPE_... bits added */
1015
lpxx->lfPitchAndFamily = HIWORD(l) >> 8;
1016
}
1017
lstrcpynW(lpxx->lfFaceName, str, ARRAY_SIZE(lpxx->lfFaceName));
1018
1019
/* style */
1020
i=SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1021
if (i!=CB_ERR)
1022
{
1023
l=SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
1024
if (0!=(lpxx->lfItalic=HIWORD(l)))
1025
lpcf->nFontType |= ITALIC_FONTTYPE;
1026
if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
1027
lpcf->nFontType |= BOLD_FONTTYPE;
1028
}
1029
1030
/* size */
1031
get_dialog_font_point_size(hDlg, lpcf);
1032
1033
/* charset */
1034
if (lpcf->Flags & CF_NOSCRIPTSEL)
1035
lpxx->lfCharSet = DEFAULT_CHARSET;
1036
else
1037
{
1038
i=SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
1039
if (i!=CB_ERR)
1040
lpxx->lfCharSet=SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
1041
else
1042
lpxx->lfCharSet = DEFAULT_CHARSET;
1043
}
1044
lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
1045
lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
1046
lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
1047
lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
1048
lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
1049
lpxx->lfQuality=DEFAULT_QUALITY;
1050
1051
wininfo.cbSize=sizeof(wininfo);
1052
1053
if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
1054
{
1055
MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
1056
InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
1057
}
1058
}
1059
break;
1060
1061
case cmb4:
1062
i=SendDlgItemMessageW(hDlg, cmb4, CB_GETCURSEL, 0, 0);
1063
if (i!=CB_ERR)
1064
{
1065
WINDOWINFO wininfo;
1066
1067
lpcf->rgbColors = SendDlgItemMessageW(hDlg, cmb4, CB_GETITEMDATA, i, 0);
1068
wininfo.cbSize=sizeof(wininfo);
1069
1070
if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
1071
{
1072
MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
1073
InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
1074
}
1075
}
1076
break;
1077
1078
case psh15:
1079
i=RegisterWindowMessageW( HELPMSGSTRINGW );
1080
if (lpcf->hwndOwner)
1081
SendMessageW(lpcf->hwndOwner, i, 0, (LPARAM)GetPropW(hDlg, strWineFontData));
1082
break;
1083
1084
case IDOK:
1085
{
1086
WCHAR msgW[80];
1087
INT pointsize;
1088
1089
pointsize = get_dialog_font_point_size(hDlg, lpcf);
1090
if (pointsize == -1)
1091
{
1092
LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE_INPUT, msgW, ARRAY_SIZE(msgW));
1093
MessageBoxW(hDlg, msgW, NULL, MB_OK | MB_ICONINFORMATION);
1094
return TRUE;
1095
}
1096
1097
if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
1098
( (lpcf->Flags & CF_LIMITSIZE) &&
1099
(lpcf->iPointSize >= 10 * lpcf->nSizeMin) &&
1100
(lpcf->iPointSize <= 10 * lpcf->nSizeMax)))
1101
EndDialog(hDlg, TRUE);
1102
else
1103
{
1104
WCHAR format[80];
1105
DWORD_PTR args[2];
1106
LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE, format, ARRAY_SIZE(format));
1107
args[0] = lpcf->nSizeMin;
1108
args[1] = lpcf->nSizeMax;
1109
FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
1110
format, 0, 0, msgW, ARRAY_SIZE(msgW), (va_list *)args);
1111
MessageBoxW(hDlg, msgW, NULL, MB_OK);
1112
}
1113
return(TRUE);
1114
}
1115
case IDCANCEL:
1116
EndDialog(hDlg, FALSE);
1117
return(TRUE);
1118
}
1119
return(FALSE);
1120
}
1121
1122
static LRESULT CFn_WMDestroy(HWND hwnd, LPCHOOSEFONTW lpcfw)
1123
{
1124
LPCHOOSEFONTA lpcfa;
1125
LPSTR lpszStyle;
1126
LPLOGFONTA lpLogFonta;
1127
int len;
1128
1129
if (!lpcfw) return FALSE;
1130
1131
lpcfa = GetPropW(hwnd, strWineFontData_a);
1132
lpLogFonta = lpcfa->lpLogFont;
1133
lpszStyle = lpcfa->lpszStyle;
1134
memcpy(lpcfa, lpcfw, sizeof(CHOOSEFONTA));
1135
lpcfa->lpLogFont = lpLogFonta;
1136
lpcfa->lpszStyle = lpszStyle;
1137
memcpy(lpcfa->lpLogFont, lpcfw->lpLogFont, sizeof(LOGFONTA));
1138
WideCharToMultiByte(CP_ACP, 0, lpcfw->lpLogFont->lfFaceName,
1139
LF_FACESIZE, lpcfa->lpLogFont->lfFaceName, LF_FACESIZE, 0, 0);
1140
1141
if((lpcfw->Flags & CF_USESTYLE) && lpcfw->lpszStyle) {
1142
len = WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, NULL, 0, 0, 0);
1143
WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, lpcfa->lpszStyle, len, 0, 0);
1144
free(lpcfw->lpszStyle);
1145
}
1146
1147
free(lpcfw->lpLogFont);
1148
free(lpcfw);
1149
SetPropW(hwnd, strWineFontData, 0);
1150
1151
return TRUE;
1152
}
1153
1154
static LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam, const CHOOSEFONTW *lpcf)
1155
{
1156
WINDOWINFO info;
1157
1158
if (!lpcf) return FALSE;
1159
1160
info.cbSize=sizeof(info);
1161
if( GetWindowInfo( GetDlgItem( hDlg, stc5), &info ) )
1162
{
1163
PAINTSTRUCT ps;
1164
HDC hdc;
1165
HFONT hOrigFont;
1166
LOGFONTW lf = *(lpcf->lpLogFont);
1167
1168
MapWindowPoints( 0, hDlg, (LPPOINT) &info.rcWindow, 2);
1169
hdc = BeginPaint( hDlg, &ps );
1170
1171
TRACE("erase %d, rect=%s\n", ps.fErase, wine_dbgstr_rect(&ps.rcPaint));
1172
1173
/* Paint frame */
1174
DrawEdge( hdc, &info.rcWindow, EDGE_SUNKEN, BF_RECT|BF_ADJUST );
1175
1176
/* Draw the sample text itself */
1177
hOrigFont = SelectObject( hdc, CreateFontIndirectW( &lf ) );
1178
SetTextColor( hdc, lpcf->rgbColors );
1179
SetBkMode( hdc, TRANSPARENT );
1180
1181
DrawTextW( hdc,
1182
sample_lang_text[CHARSET_ORDER[lpcf->lpLogFont->lfCharSet]],
1183
-1, &info.rcWindow, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
1184
1185
DeleteObject(SelectObject( hdc, hOrigFont ));
1186
EndPaint( hDlg, &ps );
1187
}
1188
return FALSE;
1189
}
1190
1191
/***********************************************************************
1192
* FormatCharDlgProcA [internal]
1193
*/
1194
static INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1195
{
1196
LPCHOOSEFONTW lpcfw;
1197
LPCHOOSEFONTA lpcfa;
1198
INT_PTR res = FALSE;
1199
int len;
1200
1201
if (uMsg!=WM_INITDIALOG) {
1202
lpcfw = GetPropW(hDlg, strWineFontData);
1203
if (lpcfw && CFn_HookCallChk32(lpcfw))
1204
res=CallWindowProcA((WNDPROC)lpcfw->lpfnHook, hDlg, uMsg, wParam, lParam);
1205
if (res)
1206
return res;
1207
} else {
1208
lpcfa=(LPCHOOSEFONTA)lParam;
1209
SetPropW(hDlg, strWineFontData_a, (HANDLE)lParam);
1210
1211
lpcfw = malloc(sizeof(*lpcfw));
1212
memcpy(lpcfw, lpcfa, sizeof(CHOOSEFONTA));
1213
lpcfw->lpLogFont = malloc(sizeof(*lpcfw->lpLogFont));
1214
memcpy(lpcfw->lpLogFont, lpcfa->lpLogFont, sizeof(LOGFONTA));
1215
MultiByteToWideChar(CP_ACP, 0, lpcfa->lpLogFont->lfFaceName,
1216
LF_FACESIZE, lpcfw->lpLogFont->lfFaceName, LF_FACESIZE);
1217
1218
if((lpcfa->Flags & CF_USESTYLE) && lpcfa->lpszStyle) {
1219
len = MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, NULL, 0);
1220
lpcfw->lpszStyle = malloc(len * sizeof(WCHAR));
1221
MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, lpcfw->lpszStyle, len);
1222
}
1223
1224
if (!CFn_WMInitDialog(hDlg, lParam, lpcfw))
1225
{
1226
TRACE("CFn_WMInitDialog returned FALSE\n");
1227
return FALSE;
1228
}
1229
if (CFn_HookCallChk32(lpcfw))
1230
return CallWindowProcA((WNDPROC)lpcfa->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1231
}
1232
switch (uMsg)
1233
{
1234
case WM_MEASUREITEM:
1235
return CFn_WMMeasureItem(hDlg,lParam);
1236
case WM_DRAWITEM:
1237
return CFn_WMDrawItem(lParam);
1238
case WM_COMMAND:
1239
return CFn_WMCommand(hDlg, wParam, lParam, lpcfw);
1240
case WM_DESTROY:
1241
return CFn_WMDestroy(hDlg, lpcfw);
1242
case WM_CHOOSEFONT_GETLOGFONT:
1243
{
1244
LOGFONTA *logfont = (LOGFONTA *)lParam;
1245
TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08IX\n", lParam);
1246
memcpy( logfont, lpcfw->lpLogFont, FIELD_OFFSET( LOGFONTA, lfFaceName ));
1247
WideCharToMultiByte( CP_ACP, 0, lpcfw->lpLogFont->lfFaceName, LF_FACESIZE,
1248
logfont->lfFaceName, LF_FACESIZE, NULL, NULL );
1249
break;
1250
}
1251
case WM_PAINT:
1252
return CFn_WMPaint(hDlg, wParam, lParam, lpcfw);
1253
}
1254
return res;
1255
}
1256
1257
/***********************************************************************
1258
* FormatCharDlgProcW [internal]
1259
*/
1260
static INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1261
{
1262
LPCHOOSEFONTW lpcf;
1263
INT_PTR res = FALSE;
1264
1265
if (uMsg!=WM_INITDIALOG)
1266
{
1267
lpcf= GetPropW(hDlg, strWineFontData);
1268
if (lpcf && CFn_HookCallChk32(lpcf))
1269
res=CallWindowProcW((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
1270
if (res)
1271
return res;
1272
}
1273
else
1274
{
1275
lpcf=(LPCHOOSEFONTW)lParam;
1276
if (!CFn_WMInitDialog(hDlg, lParam, lpcf))
1277
{
1278
TRACE("CFn_WMInitDialog returned FALSE\n");
1279
return FALSE;
1280
}
1281
if (CFn_HookCallChk32(lpcf))
1282
return CallWindowProcW((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1283
}
1284
switch (uMsg)
1285
{
1286
case WM_MEASUREITEM:
1287
return CFn_WMMeasureItem(hDlg, lParam);
1288
case WM_DRAWITEM:
1289
return CFn_WMDrawItem(lParam);
1290
case WM_COMMAND:
1291
return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
1292
case WM_DESTROY:
1293
return TRUE;
1294
case WM_CHOOSEFONT_GETLOGFONT:
1295
TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08IX\n", lParam);
1296
memcpy( (LOGFONTW *)lParam, lpcf->lpLogFont, sizeof(LOGFONTW) );
1297
break;
1298
case WM_PAINT:
1299
return CFn_WMPaint(hDlg, wParam, lParam, lpcf);
1300
}
1301
return res;
1302
}
1303
1304