fontdlg.c 45 KB
Newer Older
1 2 3 4 5
/*
 * COMMDLG - Font Dialog
 *
 * Copyright 1994 Martin Ayotte
 * Copyright 1996 Albrecht Kleine
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21 22 23
 */

#include <ctype.h>
#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 33
#include "commdlg.h"
#include "dlgs.h"
34
#include "wine/debug.h"
35
#include "wine/unicode.h"
36
#include "cderr.h"
37
#include "cdlg.h"
38

39
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
40

41 42 43 44 45 46 47 48 49
typedef struct
{
  HWND hWnd1;
  HWND hWnd2;
  LPCHOOSEFONTW lpcf32w;
  int  added;
} CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;


Jacek Caban's avatar
Jacek Caban committed
50 51 52 53
static const WCHAR strWineFontData[] = {'_','_','W','I','N','E','_','F','O','N','T','D','L','G','D','A','T','A',0};
static const WCHAR strWineFontData_a[] =
                               {'_','_','W','I','N','E','_','F','O','N','T','D','L','G','D','A','T','A','_','A',0};
static const WCHAR chooseFontW[] = {'C','H','O','O','S','E','_','F','O','N','T',0};
54
static const WCHAR fontsizefmtW[] = {'%','d',0};
55

56 57 58
/* image list with TrueType bitmaps and more */
static HIMAGELIST himlTT = 0;
#define TTBITMAP_XSIZE 20 /* x-size of the bitmaps */
59

60 61
static INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
static INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
62

63 64 65 66 67 68
/* There is a table here of all charsets, and the sample text for each.
 * There is a second table that translates a charset into an index into
 * the first table.
 */

#define CI(cs) ((IDS_CHARSET_##cs)-IDS_CHARSET_ANSI)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100


static const WCHAR stWestern[]={'A','a','B','b','Y','y','Z','z',0}; /* Western and default */
static const WCHAR stSymbol[]={'S','y','m','b','o','l',0}; /* Symbol */
static const WCHAR stShiftJis[]={'A','a',0x3042,0x3041,0x30a2,0x30a1,0x4e9c,0x5b87,0}; /* Shift JIS */
static const WCHAR stHangul[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Hangul */
static const WCHAR stGB2312[]={0x5fae,0x8f6f,0x4e2d,0x6587,0x8f6f,0x4ef6,0}; /* GB2312 */
static const WCHAR stBIG5[]={0x4e2d,0x6587,0x5b57,0x578b,0x7bc4,0x4f8b,0}; /* BIG5 */
static const WCHAR stGreek[]={'A','a','B','b',0x0391,0x03b1,0x0392,0x03b2,0}; /* Greek */
static const WCHAR stTurkish[]={'A','a','B','b',0x011e,0x011f,0x015e,0x015f,0}; /* Turkish */
static const WCHAR stHebrew[]={'A','a','B','b',0x05e0,0x05e1,0x05e9,0x05ea,0}; /* Hebrew */
static const WCHAR stArabic[]={'A','a','B','b',0x0627,0x0628,0x062c,0x062f,0x0647,0x0648,0x0632,0};/* Arabic */
static const WCHAR stBaltic[]={'A','a','B','b','Y','y','Z','z',0}; /* Baltic */
static const WCHAR stVietname[]={'A','a','B','b',0x01a0,0x01a1,0x01af,0x01b0,0}; /* Vietnamese */
static const WCHAR stCyrillic[]={'A','a','B','b',0x0411,0x0431,0x0424,0x0444,0}; /* Cyrillic */
static const WCHAR stEastEur[]={'A','a','B','b',0xc1,0xe1,0xd4,0xf4,0}; /* East European */
static const WCHAR stThai[]={'A','a','B','b',0x0e2d,0x0e31,0x0e01,0x0e29,0x0e23,0x0e44,0x0e17,0x0e22,0}; /* Thai */
static const WCHAR stJohab[]={0xac00,0xb098,0xb2e4,'A','a','B','Y','y','Z','z',0}; /* Johab */
static const WCHAR stMac[]={'A','a','B','b','Y','y','Z','z',0}; /* Mac */
static const WCHAR stOEM[]={'A','a','B','b',0xf8,0xf1,0xfd,0}; /* OEM */
/* the following character sets actually behave different (Win2K observation):
 * the sample string is 'sticky': it uses the sample string of the previous
 * selected character set. That behaviour looks like some default, which is
 * not (yet) implemented. */
static const WCHAR stVISCII[]={'A','a','B','b',0}; /* VISCII */
static const WCHAR stTCVN[]={'A','a','B','b',0}; /* TCVN */
static const WCHAR stKOI8[]={'A','a','B','b',0}; /* KOI-8 */
static const WCHAR stIso88593[]={'A','a','B','b',0}; /* ISO-8859-3 */
static const WCHAR stIso88594[]={'A','a','B','b',0}; /* ISO-8859-4 */
static const WCHAR stIso885910[]={'A','a','B','b',0}; /* ISO-8859-10 */
static const WCHAR stCeltic[]={'A','a','B','b',0};/* Celtic */

101
static const WCHAR * const sample_lang_text[]={
102 103 104 105 106 107
    stWestern,stSymbol,stShiftJis,stHangul,stGB2312,
    stBIG5,stGreek,stTurkish,stHebrew,stArabic,
    stBaltic,stVietname,stCyrillic,stEastEur,stThai,
    stJohab,stMac,stOEM,stVISCII,stTCVN,
    stKOI8,stIso88593,stIso88594,stIso885910,stCeltic};

108

109
static const BYTE CHARSET_ORDER[256]={
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
    CI(ANSI), 0, CI(SYMBOL), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(MAC), 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    CI(JIS), CI(HANGUL), CI(JOHAB), 0, 0, 0, CI(GB2312), 0, CI(BIG5), 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, CI(GREEK), CI(TURKISH), CI(VIETNAMESE), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, CI(HEBREW), CI(ARABIC), 0, 0, 0, 0, 0, 0, 0, CI(BALTIC), 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(RUSSIAN), 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(THAI), 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CI(EE), 0,
    CI(VISCII), CI(TCVN), CI(KOI8), CI(ISO3), CI(ISO4), CI(ISO10), CI(CELTIC), 0, 0, 0, 0, 0, 0, 0, 0, CI(OEM),
};

128 129 130
static const struct {
    DWORD       mask;
    const char *name;
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
} cfflags[] = {
#define XX(x) { x, #x },
    XX(CF_SCREENFONTS)
    XX(CF_PRINTERFONTS)
    XX(CF_SHOWHELP)
    XX(CF_ENABLEHOOK)
    XX(CF_ENABLETEMPLATE)
    XX(CF_ENABLETEMPLATEHANDLE)
    XX(CF_INITTOLOGFONTSTRUCT)
    XX(CF_USESTYLE)
    XX(CF_EFFECTS)
    XX(CF_APPLY)
    XX(CF_ANSIONLY)
    XX(CF_NOVECTORFONTS)
    XX(CF_NOSIMULATIONS)
    XX(CF_LIMITSIZE)
    XX(CF_FIXEDPITCHONLY)
    XX(CF_WYSIWYG)
    XX(CF_FORCEFONTEXIST)
    XX(CF_SCALABLEONLY)
    XX(CF_TTONLY)
    XX(CF_NOFACESEL)
    XX(CF_NOSTYLESEL)
    XX(CF_NOSIZESEL)
    XX(CF_SELECTSCRIPT)
    XX(CF_NOSCRIPTSEL)
    XX(CF_NOVERTFONTS)
#undef XX
};

161
static void _dump_cf_flags(DWORD cflags)
162
{
163
    unsigned int i;
164

165
    for (i = 0; i < sizeof(cfflags)/sizeof(cfflags[0]); i++)
Rein Klazes's avatar
Rein Klazes committed
166
        if (cfflags[i].mask & cflags)
167 168
            TRACE("%s|",cfflags[i].name);
    TRACE("\n");
169 170
}

171
/***********************************************************************
172
 *           ChooseFontW   (COMDLG32.@)
173 174 175 176 177 178 179 180 181 182
 *
 * Create a font dialog box.
 *
 * PARAMS
 *  lpChFont [I/O] in:  information to initialize the dialog box.
 *                 out: User's color selection
 *
 * RETURNS
 *  TRUE:  Ok button clicked.
 *  FALSE: Cancel button clicked, or error.
183
 */
184
BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
185
{
Rein Klazes's avatar
Rein Klazes committed
186 187 188 189
    LPCVOID template;
    HRSRC hResInfo;
    HINSTANCE hDlginst;
    HGLOBAL hDlgTmpl;
190

Jacek Caban's avatar
Jacek Caban committed
191
    TRACE("(%p)\n", lpChFont);
Rein Klazes's avatar
Rein Klazes committed
192 193

    if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
194
    {
195
        template=lpChFont->hInstance;
196 197
    } else
    {
Rein Klazes's avatar
Rein Klazes committed
198 199 200
        if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
        {
            hDlginst=lpChFont->hInstance;
201 202
            if( !(hResInfo = FindResourceW(hDlginst, lpChFont->lpTemplateName,
                            (LPWSTR)RT_DIALOG)))
Rein Klazes's avatar
Rein Klazes committed
203 204 205 206 207 208 209
            {
                COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
                return FALSE;
            }
        } else
        {
            hDlginst=COMDLG32_hInstance;
210
            if (!(hResInfo = FindResourceW(hDlginst, chooseFontW, (LPWSTR)RT_DIALOG)))
Rein Klazes's avatar
Rein Klazes committed
211 212 213 214 215 216 217 218 219 220 221
            {
                COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
                return FALSE;
            }
        }
        if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
                !(template = LockResource( hDlgTmpl )))
        {
            COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
            return FALSE;
        }
222
    }
Rein Klazes's avatar
Rein Klazes committed
223 224
    if (TRACE_ON(commdlg))
        _dump_cf_flags(lpChFont->Flags);
225

226
    if (lpChFont->Flags & CF_SELECTSCRIPT)
Rein Klazes's avatar
Rein Klazes committed
227
        FIXME(": unimplemented flag (ignored)\n");
228

229 230
    return DialogBoxIndirectParamW(COMDLG32_hInstance, template,
            lpChFont->hwndOwner, FormatCharDlgProcW, (LPARAM)lpChFont );
231 232
}

233
/***********************************************************************
234
 *           ChooseFontA   (COMDLG32.@)
235
 *
Rico Schüller's avatar
Rico Schüller committed
236
 * See ChooseFontW.
237
 */
238
BOOL WINAPI ChooseFontA(LPCHOOSEFONTA lpChFont)
239
{
240 241 242 243
    LPCVOID template;
    HRSRC hResInfo;
    HINSTANCE hDlginst;
    HGLOBAL hDlgTmpl;
244

Jacek Caban's avatar
Jacek Caban committed
245 246
    TRACE("(%p)\n", lpChFont);

247
    if ( (lpChFont->Flags&CF_ENABLETEMPLATEHANDLE)!=0 )
248
    {
249
        template=lpChFont->hInstance;
250
    } else
251
    {
252 253 254 255 256 257 258 259 260 261 262 263
        if ( (lpChFont->Flags&CF_ENABLETEMPLATE)!=0 )
        {
            hDlginst=lpChFont->hInstance;
            if( !(hResInfo = FindResourceA(hDlginst, lpChFont->lpTemplateName,
                            (LPSTR)RT_DIALOG)))
            {
                COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
                return FALSE;
            }
        } else
        {
            hDlginst=COMDLG32_hInstance;
Jacek Caban's avatar
Jacek Caban committed
264
            if (!(hResInfo = FindResourceW(hDlginst, chooseFontW, (LPWSTR)RT_DIALOG)))
265 266 267 268 269 270 271 272 273 274 275
            {
                COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
                return FALSE;
            }
        }
        if (!(hDlgTmpl = LoadResource(hDlginst, hResInfo )) ||
                !(template = LockResource( hDlgTmpl )))
        {
            COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
            return FALSE;
        }
276
    }
Rein Klazes's avatar
Rein Klazes committed
277 278
    if (TRACE_ON(commdlg))
        _dump_cf_flags(lpChFont->Flags);
279
    if (lpChFont->Flags & CF_SELECTSCRIPT)
280
        FIXME(": unimplemented flag (ignored)\n");
Rein Klazes's avatar
Rein Klazes committed
281

282 283
    return DialogBoxIndirectParamA(COMDLG32_hInstance, template,
            lpChFont->hwndOwner, FormatCharDlgProcA, (LPARAM)lpChFont );
284
}
285

286 287 288 289 290
#define TEXT_EXTRAS 4
#define TEXT_COLORS 16

static const COLORREF textcolors[TEXT_COLORS]=
{
Rein Klazes's avatar
Rein Klazes committed
291 292 293 294
    0x00000000L,0x00000080L,0x00008000L,0x00008080L,
    0x00800000L,0x00800080L,0x00808000L,0x00808080L,
    0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
    0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
295 296 297 298 299
};

/***********************************************************************
 *                          CFn_HookCallChk32                 [internal]
 */
300
static BOOL CFn_HookCallChk32(const CHOOSEFONTW *lpcf)
301
{
Rein Klazes's avatar
Rein Klazes committed
302 303 304 305 306
    if (lpcf)
        if(lpcf->Flags & CF_ENABLEHOOK)
            if (lpcf->lpfnHook)
                return TRUE;
    return FALSE;
307 308 309 310 311
}

/*************************************************************************
 *              AddFontFamily                               [internal]
 */
312 313
static INT AddFontFamily(const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM,
                         UINT nFontType, const CHOOSEFONTW *lpcf, HWND hwnd, LPCFn_ENUMSTRUCT e)
314
{
Rein Klazes's avatar
Rein Klazes committed
315 316
    int i;
    WORD w;
Jacek Caban's avatar
Jacek Caban committed
317
    const LOGFONTW *lplf = &(lpElfex->elfLogFont);
Rein Klazes's avatar
Rein Klazes committed
318

Jacek Caban's avatar
Jacek Caban committed
319
    TRACE("font=%s (nFontType=%d)\n", debugstr_w(lplf->lfFaceName), nFontType);
Rein Klazes's avatar
Rein Klazes committed
320 321 322 323 324 325 326 327 328 329

    if (lpcf->Flags & CF_FIXEDPITCHONLY)
        if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
            return 1;
    if (lpcf->Flags & CF_ANSIONLY)
        if (lplf->lfCharSet != ANSI_CHARSET)
            return 1;
    if (lpcf->Flags & CF_TTONLY)
        if (!(nFontType & TRUETYPE_FONTTYPE))
            return 1;
330 331 332
    if (lpcf->Flags & CF_NOVERTFONTS)
        if (lplf->lfFaceName[0] == '@')
            return 1;
Rein Klazes's avatar
Rein Klazes committed
333 334 335

    if (e) e->added++;

Jacek Caban's avatar
Jacek Caban committed
336
    i=SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)lplf->lfFaceName);
337
    if (i == CB_ERR) {
Jacek Caban's avatar
Jacek Caban committed
338
        i = SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
339 340
        if( i != CB_ERR) {
            /* store some important font information */
341 342
            w = (lplf->lfPitchAndFamily) << 8 |
                (HIWORD(lpNTM->ntmTm.ntmFlags) & 0xff);
Jacek Caban's avatar
Jacek Caban committed
343
            SendMessageW(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
344
        }
Rein Klazes's avatar
Rein Klazes committed
345
    }
346
    return 1;
347 348 349 350 351
}

/*************************************************************************
 *              FontFamilyEnumProc32                           [internal]
 */
Jacek Caban's avatar
Jacek Caban committed
352 353
static INT WINAPI FontFamilyEnumProc(const ENUMLOGFONTEXW *lpElfex,
        const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam)
354
{
Rein Klazes's avatar
Rein Klazes committed
355 356
    LPCFn_ENUMSTRUCT e;
    e=(LPCFn_ENUMSTRUCT)lParam;
357
    return AddFontFamily( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
Jacek Caban's avatar
Jacek Caban committed
358
            dwFontType, e->lpcf32w, e->hWnd1, e);
359 360 361 362 363 364 365
}

/*************************************************************************
 *              SetFontStylesToCombo2                           [internal]
 *
 * Fill font style information into combobox  (without using font.c directly)
 */
366
static BOOL SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTW *lplf)
367
{
Rein Klazes's avatar
Rein Klazes committed
368 369 370 371 372
#define FSTYLES 4
    struct FONTSTYLE
    {
        int italic;
        int weight;
373
        UINT resId;
Rein Klazes's avatar
Rein Klazes committed
374
    };
375
    static const struct FONTSTYLE fontstyles[FSTYLES]={
376 377 378 379
        { 0, FW_NORMAL, IDS_FONT_REGULAR },
        { 1, FW_NORMAL, IDS_FONT_ITALIC },
        { 0, FW_BOLD,   IDS_FONT_BOLD },
        { 1, FW_BOLD,   IDS_FONT_BOLD_ITALIC }
Rein Klazes's avatar
Rein Klazes committed
380 381
    };
    HFONT hf;
Jacek Caban's avatar
Jacek Caban committed
382
    TEXTMETRICW tm;
Rein Klazes's avatar
Rein Klazes committed
383
    int i,j;
Jacek Caban's avatar
Jacek Caban committed
384
    LOGFONTW lf;
Rein Klazes's avatar
Rein Klazes committed
385

386
    lf = *lplf;
Rein Klazes's avatar
Rein Klazes committed
387 388 389 390 391

    for (i=0;i<FSTYLES;i++)
    {
        lf.lfItalic=fontstyles[i].italic;
        lf.lfWeight=fontstyles[i].weight;
Jacek Caban's avatar
Jacek Caban committed
392
        hf=CreateFontIndirectW(&lf);
Rein Klazes's avatar
Rein Klazes committed
393
        hf=SelectObject(hdc,hf);
Jacek Caban's avatar
Jacek Caban committed
394
        GetTextMetricsW(hdc,&tm);
Rein Klazes's avatar
Rein Klazes committed
395 396
        hf=SelectObject(hdc,hf);
        DeleteObject(hf);
397
                /* font successful created ? */
398 399
        if (((fontstyles[i].weight == FW_NORMAL && tm.tmWeight <= FW_MEDIUM) ||
             (fontstyles[i].weight == FW_BOLD && tm.tmWeight > FW_MEDIUM)) &&
400
            ((tm.tmItalic != 0)==fontstyles[i].italic))
Rein Klazes's avatar
Rein Klazes committed
401
        {
402 403 404
            WCHAR name[64];
            LoadStringW(COMDLG32_hInstance, fontstyles[i].resId, name, 64);
            j=SendMessageW(hwnd,CB_ADDSTRING,0,(LPARAM)name );
405
            if (j==CB_ERR) return TRUE;
Jacek Caban's avatar
Jacek Caban committed
406
            j=SendMessageW(hwnd, CB_SETITEMDATA, j,
407
                           MAKELONG(tm.tmWeight,fontstyles[i].italic));
408
            if (j==CB_ERR) return TRUE;
Rein Klazes's avatar
Rein Klazes committed
409 410
        }
    }
411
    return FALSE;
412 413 414 415 416
}

/*************************************************************************
 *              AddFontSizeToCombo3                           [internal]
 */
417
static BOOL AddFontSizeToCombo3(HWND hwnd, UINT h, const CHOOSEFONTW *lpcf)
418 419
{
    int j;
Jacek Caban's avatar
Jacek Caban committed
420
    WCHAR buffer[20];
421 422

    if (  (!(lpcf->Flags & CF_LIMITSIZE))  ||
Rein Klazes's avatar
Rein Klazes committed
423
            ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
424
    {
425
        sprintfW(buffer, fontsizefmtW, h);
Jacek Caban's avatar
Jacek Caban committed
426
        j=SendMessageW(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
Rein Klazes's avatar
Rein Klazes committed
427 428
        if (j==CB_ERR)
        {
429
            j=SendMessageW(hwnd, CB_INSERTSTRING, -1, (LPARAM)buffer);
Jacek Caban's avatar
Jacek Caban committed
430
            if (j!=CB_ERR) j = SendMessageW(hwnd, CB_SETITEMDATA, j, h);
431
            if (j==CB_ERR) return TRUE;
Rein Klazes's avatar
Rein Klazes committed
432
        }
433
    }
434
    return FALSE;
435 436
}

437 438 439
/*************************************************************************
 *              SetFontSizesToCombo3                           [internal]
 */
440
static BOOL SetFontSizesToCombo3(HWND hwnd, const CHOOSEFONTW *lpcf)
441
{
442
    static const BYTE sizes[]={6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
443
    unsigned int i;
444

445
    for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
446 447
        if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return TRUE;
    return FALSE;
448 449
}

450 451 452
/*************************************************************************
 *              CFn_GetDC                           [internal]
 */
453
static inline HDC CFn_GetDC(const CHOOSEFONTW *lpcf)
454 455 456 457 458 459 460 461
{
    HDC ret = ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ?
        lpcf->hDC :
        GetDC(0);
    if(!ret) ERR("HDC failure!!!\n");
    return ret;
}

462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
/*************************************************************************
 *              GetScreenDPI                           [internal]
 */
static inline int GetScreenDPI(void)
{
    HDC hdc;
    int result;

    hdc = GetDC(0);
    result = GetDeviceCaps(hdc, LOGPIXELSY);
    ReleaseDC(0, hdc);

    return result;
}

477 478 479
/*************************************************************************
 *              CFn_ReleaseDC                           [internal]
 */
480
static inline void CFn_ReleaseDC(const CHOOSEFONTW *lpcf, HDC hdc)
481 482 483 484 485
{
        if(!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
            ReleaseDC(0, hdc);
}

486 487 488
/***********************************************************************
 *                 AddFontStyle                          [internal]
 */
489 490
static INT AddFontStyle( const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM,
                         UINT nFontType, const CHOOSEFONTW *lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg)
491
{
Rein Klazes's avatar
Rein Klazes committed
492
    int i;
Jacek Caban's avatar
Jacek Caban committed
493
    const LOGFONTW *lplf = &(lpElfex->elfLogFont);
494
    HWND hcmb5;
495
    HDC hdc;
Rein Klazes's avatar
Rein Klazes committed
496 497

    TRACE("(nFontType=%d)\n",nFontType);
498
    TRACE("  %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d"
Rein Klazes's avatar
Rein Klazes committed
499
            " ch=%d op=%d cp=%d q=%d pf=%xh\n",
Jacek Caban's avatar
Jacek Caban committed
500
            debugstr_w(lplf->lfFaceName),lplf->lfHeight,lplf->lfWidth,
Rein Klazes's avatar
Rein Klazes committed
501 502 503 504 505 506
            lplf->lfEscapement,lplf->lfOrientation,
            lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
            lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
            lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
    if (nFontType & RASTER_FONTTYPE)
    {
507
        INT points;
508
        points = MulDiv( lpNTM->ntmTm.tmHeight - lpNTM->ntmTm.tmInternalLeading,
509
                72, GetScreenDPI());
510 511
        if (AddFontSizeToCombo3(hcmb3, points, lpcf))
            return 0;
Rein Klazes's avatar
Rein Klazes committed
512 513
    } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;

Jacek Caban's avatar
Jacek Caban committed
514
    if (!SendMessageW(hcmb2, CB_GETCOUNT, 0, 0))
Rein Klazes's avatar
Rein Klazes committed
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)
Rein Klazes's avatar
Rein Klazes committed
521 522
            return 0;
    }
523
    if (!( hcmb5 = GetDlgItem(hDlg, cmb5))) return 1;
Jacek Caban's avatar
Jacek Caban committed
524
    i = SendMessageW( hcmb5, CB_FINDSTRINGEXACT, 0,
525
                (LPARAM)lpElfex->elfScript);
526
    if( i == CB_ERR) {
Jacek Caban's avatar
Jacek Caban committed
527
        i = SendMessageW( hcmb5, CB_ADDSTRING, 0,
528 529
                (LPARAM)lpElfex->elfScript);
        if( i != CB_ERR)
Jacek Caban's avatar
Jacek Caban committed
530
            SendMessageW( hcmb5, CB_SETITEMDATA, i, lplf->lfCharSet);
531
    }
Rein Klazes's avatar
Rein Klazes committed
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 */
Jacek Caban's avatar
Jacek Caban committed
540
    n=SendDlgItemMessageW(hDlg, cmb3, CB_GETCOUNT, 0, 0);
541 542
    for (i=0;i<n;i++)
    {
Jacek Caban's avatar
Jacek Caban committed
543
        if (points == (int)SendDlgItemMessageW
544 545
                (hDlg,cmb3, CB_GETITEMDATA,i,0))
        {
Jacek Caban's avatar
Jacek Caban committed
546 547
            SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,i,0);
            SendMessageW(hDlg, WM_COMMAND,
548 549
                    MAKEWPARAM(cmb3, CBN_SELCHANGE),
                    (LPARAM)GetDlgItem(hDlg,cmb3));
550
            return;
551 552
        }
    }
553 554

    /* no default matching size, set text manually */
555
    SetDlgItemInt(hDlg, cmb3, points, TRUE);
556 557
}

558
static BOOL CFn_FitFontStyle( HWND hDlg, LONG packedstyle )
559 560
{
    LONG id;
561 562
    int i;
    BOOL ret = FALSE;
563 564 565
    /* look for fitting font style in combobox2 */
    for (i=0;i<TEXT_EXTRAS;i++)
    {
Jacek Caban's avatar
Jacek Caban committed
566
        id = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
567 568
        if (packedstyle == id)
        {
Jacek Caban's avatar
Jacek Caban committed
569 570
            SendDlgItemMessageW(hDlg, cmb2, CB_SETCURSEL, i, 0);
            SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE),
571
                    (LPARAM)GetDlgItem(hDlg,cmb2));
572
            ret = TRUE;
573 574 575 576 577
            break;
        }
    }
    return ret;
}
578

579

580
static BOOL CFn_FitCharSet( HWND hDlg, int charset )
581 582
{
    int i,n,cs;
583
    /* look for fitting char set in combobox5 */
Jacek Caban's avatar
Jacek Caban committed
584
    n=SendDlgItemMessageW(hDlg, cmb5, CB_GETCOUNT, 0, 0);
585 586
    for (i=0;i<n;i++)
    {
Jacek Caban's avatar
Jacek Caban committed
587
        cs =SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
588 589
        if (charset == cs)
        {
Jacek Caban's avatar
Jacek Caban committed
590 591
            SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, i, 0);
            SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
592
                    (LPARAM)GetDlgItem(hDlg,cmb2));
593
            return TRUE;
594 595 596
        }
    }
    /* no charset fits: select the first one in the list */
Jacek Caban's avatar
Jacek Caban committed
597 598
    SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, 0, 0);
    SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
599
            (LPARAM)GetDlgItem(hDlg,cmb2));
600
    return FALSE;
601 602
}

603 604 605
/***********************************************************************
 *                 FontStyleEnumProc32                     [internal]
 */
Jacek Caban's avatar
Jacek Caban committed
606 607
static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXW *lpElfex,
        const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam )
608
{
Rein Klazes's avatar
Rein Klazes committed
609 610 611 612
    LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
    HWND hcmb2=s->hWnd1;
    HWND hcmb3=s->hWnd2;
    HWND hDlg=GetParent(hcmb3);
Jacek Caban's avatar
Jacek Caban committed
613
    return AddFontStyle( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
614
                         dwFontType, s->lpcf32w, hcmb2, hcmb3, hDlg);
615 616 617 618 619
}

/***********************************************************************
 *           CFn_WMInitDialog                            [internal]
 */
620
static LRESULT CFn_WMInitDialog(HWND hDlg, LPARAM lParam, LPCHOOSEFONTW lpcf)
621
{
Rein Klazes's avatar
Rein Klazes committed
622
    HDC hdc;
623 624
    int i,j;
    BOOL init = FALSE;
625
    long pstyle;
626
    CFn_ENUMSTRUCT s;
Jacek Caban's avatar
Jacek Caban committed
627 628 629
    LPLOGFONTW lpxx;
    HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
    static const WCHAR strColorName[] = {'[','c','o','l','o','r',' ','n','a','m','e',']',0};
Rein Klazes's avatar
Rein Klazes committed
630

631
    SetPropW(hDlg, strWineFontData, lpcf);
Rein Klazes's avatar
Rein Klazes committed
632 633 634
    lpxx=lpcf->lpLogFont;
    TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);

Jacek Caban's avatar
Jacek Caban committed
635
    if (lpcf->lStructSize != sizeof(CHOOSEFONTW))
636
    {
Andrey Gusev's avatar
Andrey Gusev committed
637
        ERR("structure size failure!!!\n");
Rein Klazes's avatar
Rein Klazes committed
638 639
        EndDialog (hDlg, 0);
        return FALSE;
640
    }
641
    if (!himlTT)
Jacek Caban's avatar
Jacek Caban committed
642
        himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
643
                TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
Rein Klazes's avatar
Rein Klazes committed
644

645 646 647 648 649 650 651 652 653
    /* Set effect flags */
    if((lpcf->Flags & CF_EFFECTS) && (lpcf->Flags & CF_INITTOLOGFONTSTRUCT))
    {
        if(lpxx->lfUnderline)
            CheckDlgButton(hDlg, chx2, TRUE);
        if(lpxx->lfStrikeOut)
            CheckDlgButton(hDlg, chx1, TRUE);
    }

Rein Klazes's avatar
Rein Klazes committed
654 655 656 657
    if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
        ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
    if (!(lpcf->Flags & CF_APPLY))
        ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
658 659
    if (lpcf->Flags & CF_NOSCRIPTSEL)
        EnableWindow(GetDlgItem(hDlg,cmb5),FALSE);
Rein Klazes's avatar
Rein Klazes committed
660
    if (lpcf->Flags & CF_EFFECTS)
661
    {
Rein Klazes's avatar
Rein Klazes committed
662
        for (i=0;i<TEXT_COLORS;i++)
663
        {
Jacek Caban's avatar
Jacek Caban committed
664
            WCHAR name[30];
Rein Klazes's avatar
Rein Klazes committed
665

Jacek Caban's avatar
Jacek Caban committed
666
            if( LoadStringW(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name,
Rein Klazes's avatar
Rein Klazes committed
667 668
                        sizeof(name)/sizeof(*name) )==0 )
            {
Jacek Caban's avatar
Jacek Caban committed
669
                memcpy(name, strColorName, sizeof(strColorName));
Rein Klazes's avatar
Rein Klazes committed
670
            }
Jacek Caban's avatar
Jacek Caban committed
671
            j=SendDlgItemMessageW(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
672
            SendDlgItemMessageW(hDlg, cmb4, CB_SETITEMDATA, j, textcolors[i]);
Rein Klazes's avatar
Rein Klazes committed
673
            /* look for a fitting value in color combobox */
674
            if (textcolors[i]==lpcf->rgbColors)
Jacek Caban's avatar
Jacek Caban committed
675
                SendDlgItemMessageW(hDlg,cmb4, CB_SETCURSEL,j,0);
676 677
        }
    }
Rein Klazes's avatar
Rein Klazes committed
678
    else
679
    {
Rein Klazes's avatar
Rein Klazes committed
680 681 682 683 684 685
        ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
        ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
        ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
        ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
        ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
    }
686
    if(!(hdc = CFn_GetDC(lpcf)))
Rein Klazes's avatar
Rein Klazes committed
687
    {
688 689 690 691
        EndDialog (hDlg, 0);
        return FALSE;
    }
    s.hWnd1=GetDlgItem(hDlg,cmb1);
Jacek Caban's avatar
Jacek Caban committed
692
    s.lpcf32w=lpcf;
693
    do {
Jacek Caban's avatar
Jacek Caban committed
694
        LOGFONTW elf;
695
        s.added = 0;
696 697 698
        elf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
        elf.lfPitchAndFamily = 0;
        elf.lfFaceName[0] = '\0'; /* enum all fonts */
Jacek Caban's avatar
Jacek Caban committed
699
        if (!EnumFontFamiliesExW(hdc, &elf, (FONTENUMPROCW)FontFamilyEnumProc, (LPARAM)&s, 0))
700 701
        {
            TRACE("EnumFontFamiliesEx returns 0\n");
Rein Klazes's avatar
Rein Klazes committed
702
            break;
703 704 705 706 707 708 709 710 711 712 713 714 715 716
        }
        if (s.added) break;
        if (lpcf->Flags & CF_FIXEDPITCHONLY) {
            FIXME("No font found with fixed pitch only, dropping flag.\n");
            lpcf->Flags &= ~CF_FIXEDPITCHONLY;
            continue;
        }
        if (lpcf->Flags & CF_TTONLY) {
            FIXME("No font found with truetype only, dropping flag.\n");
            lpcf->Flags &= ~CF_TTONLY;
            continue;
        }
        break;
    } while (1);
Rein Klazes's avatar
Rein Klazes committed
717 718


719 720 721
    if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
    {
        /* look for fitting font name in combobox1 */
Kevin Koltzau's avatar
Kevin Koltzau committed
722
        j=SendDlgItemMessageW(hDlg,cmb1,CB_FINDSTRING,-1,(LPARAM)lpxx->lfFaceName);
723
        if (j!=CB_ERR)
Rein Klazes's avatar
Rein Klazes committed
724
        {
725 726 727 728
            INT height = lpxx->lfHeight < 0 ? -lpxx->lfHeight :
                lpxx->lfHeight;
            INT points;
            int charset = lpxx->lfCharSet;
729
            points = MulDiv( height, 72, GetScreenDPI());
730 731
            pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:
                    FW_NORMAL,lpxx->lfItalic !=0);
Jacek Caban's avatar
Jacek Caban committed
732 733
            SendDlgItemMessageW(hDlg, cmb1, CB_SETCURSEL, j, 0);
            SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
Rein Klazes's avatar
Rein Klazes committed
734
                    (LPARAM)GetDlgItem(hDlg,cmb1));
735
            init = TRUE;
736 737 738 739 740
            /* look for fitting font style in combobox2 */
            CFn_FitFontStyle(hDlg, pstyle);
            /* look for fitting font size in combobox3 */
            CFn_FitFontSize(hDlg, points);
            CFn_FitCharSet( hDlg, charset );
Rein Klazes's avatar
Rein Klazes committed
741
        }
742
    }
743
    if (!init)
744
    {
Jacek Caban's avatar
Jacek Caban committed
745 746
        SendDlgItemMessageW(hDlg,cmb1,CB_SETCURSEL,0,0);
        SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
747
                (LPARAM)GetDlgItem(hDlg,cmb1));
748 749 750 751 752 753 754 755 756
        SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,0,0);
        SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE),
                (LPARAM)GetDlgItem(hDlg,cmb1));
        SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,0,0);
        SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb3, CBN_SELCHANGE),
                (LPARAM)GetDlgItem(hDlg,cmb3));
        SendDlgItemMessageW(hDlg,cmb5,CB_SETCURSEL,0,0);
        SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
                (LPARAM)GetDlgItem(hDlg,cmb5));
757
    }
758 759 760
    /* limit text length user can type in as font size */
    SendDlgItemMessageW(hDlg, cmb3, CB_LIMITTEXT, 5, 0);

761
    if ((lpcf->Flags & CF_USESTYLE) && lpcf->lpszStyle)
762
    {
Kevin Koltzau's avatar
Kevin Koltzau committed
763
        j=SendDlgItemMessageW(hDlg,cmb2,CB_FINDSTRING,-1,(LPARAM)lpcf->lpszStyle);
764 765
        if (j!=CB_ERR)
        {
Jacek Caban's avatar
Jacek Caban committed
766 767
            j=SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,j,0);
            SendMessageW(hDlg,WM_COMMAND,cmb2,
768
                    MAKELONG(LOWORD(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
769 770 771
        }
    }
    CFn_ReleaseDC(lpcf, hdc);
Rein Klazes's avatar
Rein Klazes committed
772 773
    SetCursor(hcursor);
    return TRUE;
774 775 776 777 778 779
}


/***********************************************************************
 *           CFn_WMMeasureItem                           [internal]
 */
780
static LRESULT CFn_WMMeasureItem(HWND hDlg, LPARAM lParam)
781
{
782 783 784
    HDC hdc;
    HFONT hfontprev;
    TEXTMETRICW tm;
Rein Klazes's avatar
Rein Klazes committed
785
    LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
786
    INT height = 0, cx;
787

788
    if (!himlTT)
Jacek Caban's avatar
Jacek Caban committed
789
        himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
790
                TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
791
    ImageList_GetIconSize( himlTT, &cx, &height);
792
    lpmi->itemHeight = height + 2;
793
    /* use MAX of bitmap height and tm.tmHeight .*/
Jacek Caban's avatar
Jacek Caban committed
794
    hdc=GetDC(hDlg);
795
    if(!hdc) return 0;
796
    hfontprev = SelectObject( hdc, (HFONT)SendMessageW( hDlg, WM_GETFONT, 0, 0 ));
Jacek Caban's avatar
Jacek Caban committed
797
    GetTextMetricsW(hdc, &tm);
798
    if( tm.tmHeight > lpmi->itemHeight) lpmi->itemHeight = tm.tmHeight;
Jacek Caban's avatar
Jacek Caban committed
799 800
    SelectObject(hdc, hfontprev);
    ReleaseDC(hDlg, hdc);
Rein Klazes's avatar
Rein Klazes committed
801
    return 0;
802 803 804 805 806 807
}


/***********************************************************************
 *           CFn_WMDrawItem                              [internal]
 */
808
static LRESULT CFn_WMDrawItem(LPARAM lParam)
809
{
Rein Klazes's avatar
Rein Klazes committed
810
    HBRUSH hBrush;
Jacek Caban's avatar
Jacek Caban committed
811
    WCHAR buffer[40];
Rein Klazes's avatar
Rein Klazes committed
812 813 814
    COLORREF cr, oldText=0, oldBk=0;
    RECT rect;
    int nFontType;
815
    int cx, cy, idx;
Rein Klazes's avatar
Rein Klazes committed
816 817 818 819 820 821 822 823
    LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;

    if (lpdi->itemID == (UINT)-1)  /* got no items */
        DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
    else
    {
        if (lpdi->CtlType == ODT_COMBOBOX)
        {
824
            if (lpdi->itemState & ODS_SELECTED)
Rein Klazes's avatar
Rein Klazes committed
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843
            {
                hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
                oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
                oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
            }  else
            {
                hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
                SelectObject(lpdi->hDC, hBrush);
            }
            FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
        }
        else
            return TRUE;        /* this should never happen */

        rect=lpdi->rcItem;
        switch (lpdi->CtlID)
        {
        case cmb1:
            /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
844
            ImageList_GetIconSize( himlTT, &cx, &cy);
Jacek Caban's avatar
Jacek Caban committed
845
            SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
Rein Klazes's avatar
Rein Klazes committed
846
                         (LPARAM)buffer);
847
            TextOutW(lpdi->hDC, lpdi->rcItem.left + cx + 4,
Jacek Caban's avatar
Jacek Caban committed
848 849
                     lpdi->rcItem.top, buffer, lstrlenW(buffer));
            nFontType = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
850 851 852 853 854 855 856 857 858 859 860 861 862
            idx = -1;
            if (nFontType & TRUETYPE_FONTTYPE) {
                idx = 0;  /* picture: TT */
                if( nFontType & NTM_TT_OPENTYPE)
                    idx = 2; /* picture: O */
            } else if( nFontType & NTM_PS_OPENTYPE)
                idx = 3; /* picture: O+ps */
            else if( nFontType & NTM_TYPE1)
                idx = 4; /* picture: a */
            else if( nFontType & DEVICE_FONTTYPE)
                idx = 1; /* picture: printer */
            if( idx >= 0)
                ImageList_Draw( himlTT, idx, lpdi->hDC, lpdi->rcItem.left,
863
                                (lpdi->rcItem.top + lpdi->rcItem.bottom - cy) / 2, ILD_TRANSPARENT);
Rein Klazes's avatar
Rein Klazes committed
864 865 866 867
            break;
        case cmb2:
        case cmb3:
            /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
868
        case cmb5:
Jacek Caban's avatar
Jacek Caban committed
869
            SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
Rein Klazes's avatar
Rein Klazes committed
870
                         (LPARAM)buffer);
Jacek Caban's avatar
Jacek Caban committed
871 872
            TextOutW(lpdi->hDC, lpdi->rcItem.left,
                     lpdi->rcItem.top, buffer, lstrlenW(buffer));
Rein Klazes's avatar
Rein Klazes committed
873 874 875 876
            break;

        case cmb4:
            /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
Jacek Caban's avatar
Jacek Caban committed
877 878 879 880 881
            SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
                     (LPARAM)buffer);
            TextOutW(lpdi->hDC, lpdi->rcItem.left +  25+5,
                     lpdi->rcItem.top, buffer, lstrlenW(buffer));
            cr = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
Rein Klazes's avatar
Rein Klazes committed
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
            hBrush = CreateSolidBrush(cr);
            if (hBrush)
            {
                hBrush = SelectObject (lpdi->hDC, hBrush) ;
                rect.right=rect.left+25;
                rect.top++;
                rect.left+=5;
                rect.bottom--;
                Rectangle( lpdi->hDC, rect.left, rect.top,
                           rect.right, rect.bottom );
                DeleteObject( SelectObject (lpdi->hDC, hBrush)) ;
            }
            rect=lpdi->rcItem;
            rect.left+=25+5;
            break;

        default:
            return TRUE;  /* this should never happen */
        }
901
        if (lpdi->itemState & ODS_SELECTED)
Rein Klazes's avatar
Rein Klazes committed
902 903 904 905 906 907
        {
            SetTextColor(lpdi->hDC, oldText);
            SetBkColor(lpdi->hDC, oldBk);
        }
    }
    return TRUE;
908 909
}

910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
static INT get_dialog_font_point_size(HWND hDlg, CHOOSEFONTW *cf)
{
    BOOL invalid_size = FALSE;
    INT i, size;

    i = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
    if (i != CB_ERR)
        size = LOWORD(SendDlgItemMessageW(hDlg, cmb3, CB_GETITEMDATA , i, 0));
    else
    {
        WCHAR buffW[8], *endptrW;

        GetDlgItemTextW(hDlg, cmb3, buffW, sizeof(buffW)/sizeof(*buffW));
        size = strtolW(buffW, &endptrW, 10);
        invalid_size = size == 0 && *endptrW;

        if (size == 0)
            size = 10;
    }

    cf->iPointSize = 10 * size;
    cf->lpLogFont->lfHeight = -MulDiv(cf->iPointSize, GetScreenDPI(), 720);
    return invalid_size ? -1 : size;
}

935 936 937
/***********************************************************************
 *           CFn_WMCommand                               [internal]
 */
938
static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFONTW lpcf)
939
{
940
    int i;
Rein Klazes's avatar
Rein Klazes committed
941 942 943
    long l;
    HDC hdc;

944 945
    if (!lpcf) return FALSE;

946
    TRACE("WM_COMMAND wParam=%08X lParam=%08lX\n", (LONG)wParam, lParam);
Rein Klazes's avatar
Rein Klazes committed
947 948 949 950 951
    switch (LOWORD(wParam))
    {
    case cmb1:
        if (HIWORD(wParam)==CBN_SELCHANGE)
        {
952 953 954 955 956
            INT pointsize; /* save current pointsize */
            LONG pstyle;  /* save current style */
            int charset;
            int idx;
            if(!(hdc = CFn_GetDC(lpcf)))
Rein Klazes's avatar
Rein Klazes committed
957 958 959 960
            {
                EndDialog (hDlg, 0);
                return TRUE;
            }
Jacek Caban's avatar
Jacek Caban committed
961 962
            idx = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
            pointsize = (int)SendDlgItemMessageW( hDlg, cmb3, CB_GETITEMDATA,
963
                    idx, 0);
Jacek Caban's avatar
Jacek Caban committed
964 965 966 967 968 969 970 971 972
            idx = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
            pstyle = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, idx, 0);
            idx = SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
            charset = SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, idx, 0);

            SendDlgItemMessageW(hDlg, cmb2, CB_RESETCONTENT, 0, 0);
            SendDlgItemMessageW(hDlg, cmb3, CB_RESETCONTENT, 0, 0);
            SendDlgItemMessageW(hDlg, cmb5, CB_RESETCONTENT, 0, 0);
            i=SendDlgItemMessageW(hDlg, cmb1, CB_GETCURSEL, 0, 0);
973 974
            if (i!=CB_ERR)
            {
Jacek Caban's avatar
Jacek Caban committed
975
                HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
976
                CFn_ENUMSTRUCT s;
Jacek Caban's avatar
Jacek Caban committed
977 978
                LOGFONTW enumlf;
                SendDlgItemMessageW(hDlg, cmb1, CB_GETLBTEXT, i,
979
                                    (LPARAM)enumlf.lfFaceName);
Jacek Caban's avatar
Jacek Caban committed
980
                TRACE("WM_COMMAND/cmb1 =>%s\n", debugstr_w(enumlf.lfFaceName));
981 982
                s.hWnd1=GetDlgItem(hDlg, cmb2);
                s.hWnd2=GetDlgItem(hDlg, cmb3);
Jacek Caban's avatar
Jacek Caban committed
983
                s.lpcf32w=lpcf;
984 985
                enumlf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
                enumlf.lfPitchAndFamily = 0;
Jacek Caban's avatar
Jacek Caban committed
986 987
                EnumFontFamiliesExW(hdc, &enumlf,
                        (FONTENUMPROCW)FontStyleEnumProc, (LPARAM)&s, 0);
988 989 990 991 992 993
                CFn_FitFontStyle(hDlg, pstyle);
                if( pointsize != CB_ERR) CFn_FitFontSize(hDlg, pointsize);
                if( charset != CB_ERR) CFn_FitCharSet( hDlg, charset );
                SetCursor(hcursor);
            }
            CFn_ReleaseDC(lpcf, hdc);
Rein Klazes's avatar
Rein Klazes committed
994
        }
995
        break;
Rein Klazes's avatar
Rein Klazes committed
996 997 998 999
    case chx1:
    case chx2:
    case cmb2:
    case cmb3:
1000
    case cmb5:
Rein Klazes's avatar
Rein Klazes committed
1001 1002
        if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
        {
Jacek Caban's avatar
Jacek Caban committed
1003
            WCHAR str[256];
Rein Klazes's avatar
Rein Klazes committed
1004
            WINDOWINFO wininfo;
1005
            LPLOGFONTW lpxx=lpcf->lpLogFont;
Rein Klazes's avatar
Rein Klazes committed
1006 1007

            TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
1008 1009

            /* face name */
Jacek Caban's avatar
Jacek Caban committed
1010
            i=SendDlgItemMessageW(hDlg,cmb1,CB_GETCURSEL,0,0);
Rein Klazes's avatar
Rein Klazes committed
1011
            if (i==CB_ERR)
1012
                GetDlgItemTextW( hDlg, cmb1, str, sizeof(str)/sizeof(str[0]) );
Rein Klazes's avatar
Rein Klazes committed
1013 1014
            else
            {
Jacek Caban's avatar
Jacek Caban committed
1015
                SendDlgItemMessageW(hDlg,cmb1,CB_GETLBTEXT,i,
Rein Klazes's avatar
Rein Klazes committed
1016
                                    (LPARAM)str);
Jacek Caban's avatar
Jacek Caban committed
1017
                l=SendDlgItemMessageW(hDlg,cmb1,CB_GETITEMDATA,i,0);
Rein Klazes's avatar
Rein Klazes committed
1018 1019 1020 1021
                lpcf->nFontType = LOWORD(l);
                /* FIXME:   lpcf->nFontType |= ....  SIMULATED_FONTTYPE and so */
                /* same value reported to the EnumFonts
                   call back with the extra FONTTYPE_...  bits added */
1022
                lpxx->lfPitchAndFamily = HIWORD(l) >> 8;
Rein Klazes's avatar
Rein Klazes committed
1023
            }
1024
            lstrcpynW(lpxx->lfFaceName, str, sizeof(lpxx->lfFaceName)/sizeof(lpxx->lfFaceName[0]));
1025 1026

            /* style */
Jacek Caban's avatar
Jacek Caban committed
1027
            i=SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
Rein Klazes's avatar
Rein Klazes committed
1028 1029
            if (i!=CB_ERR)
            {
Jacek Caban's avatar
Jacek Caban committed
1030
                l=SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
Rein Klazes's avatar
Rein Klazes committed
1031 1032 1033 1034 1035
                if (0!=(lpxx->lfItalic=HIWORD(l)))
                    lpcf->nFontType |= ITALIC_FONTTYPE;
                if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
                    lpcf->nFontType |= BOLD_FONTTYPE;
            }
1036 1037 1038 1039 1040

            /* size */
            get_dialog_font_point_size(hDlg, lpcf);

            /* charset */
Jacek Caban's avatar
Jacek Caban committed
1041
            i=SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
1042
            if (i!=CB_ERR)
Jacek Caban's avatar
Jacek Caban committed
1043
                lpxx->lfCharSet=SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
1044 1045
            else
                lpxx->lfCharSet = DEFAULT_CHARSET;
Rein Klazes's avatar
Rein Klazes committed
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
            lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
            lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
            lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
            lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
            lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
            lpxx->lfQuality=DEFAULT_QUALITY;

            wininfo.cbSize=sizeof(wininfo);

            if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
            {
                MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
                InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
            }
        }
        break;

    case cmb4:
Jacek Caban's avatar
Jacek Caban committed
1064
        i=SendDlgItemMessageW(hDlg, cmb4, CB_GETCURSEL, 0, 0);
Rein Klazes's avatar
Rein Klazes committed
1065 1066 1067 1068
        if (i!=CB_ERR)
        {
            WINDOWINFO wininfo;

1069
            lpcf->rgbColors = SendDlgItemMessageW(hDlg, cmb4, CB_GETITEMDATA, i, 0);
Rein Klazes's avatar
Rein Klazes committed
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
            wininfo.cbSize=sizeof(wininfo);

            if( GetWindowInfo( GetDlgItem( hDlg, stc5), &wininfo ) )
            {
                MapWindowPoints( 0, hDlg, (LPPOINT) &wininfo.rcWindow, 2);
                InvalidateRect( hDlg, &wininfo.rcWindow, TRUE );
            }
        }
        break;

    case psh15:
Jacek Caban's avatar
Jacek Caban committed
1081
        i=RegisterWindowMessageW( HELPMSGSTRINGW );
Rein Klazes's avatar
Rein Klazes committed
1082
        if (lpcf->hwndOwner)
Jacek Caban's avatar
Jacek Caban committed
1083
            SendMessageW(lpcf->hwndOwner, i, 0, (LPARAM)GetPropW(hDlg, strWineFontData));
Rein Klazes's avatar
Rein Klazes committed
1084 1085 1086
        break;

    case IDOK:
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
    {
        WCHAR msgW[80];
        INT pointsize;

        pointsize = get_dialog_font_point_size(hDlg, lpcf);
        if (pointsize == -1)
        {
            LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE_INPUT, msgW, sizeof(msgW)/sizeof(*msgW));
            MessageBoxW(hDlg, msgW, NULL, MB_OK | MB_ICONINFORMATION);
            return TRUE;
        }

Rein Klazes's avatar
Rein Klazes committed
1099 1100
        if (  (!(lpcf->Flags & CF_LIMITSIZE))  ||
              ( (lpcf->Flags & CF_LIMITSIZE) &&
1101 1102
                (lpcf->iPointSize >= 10 * lpcf->nSizeMin) &&
                (lpcf->iPointSize <= 10 * lpcf->nSizeMax)))
Rein Klazes's avatar
Rein Klazes committed
1103 1104 1105
            EndDialog(hDlg, TRUE);
        else
        {
Jacek Caban's avatar
Jacek Caban committed
1106
            WCHAR format[80];
1107
            DWORD_PTR args[2];
Jacek Caban's avatar
Jacek Caban committed
1108
            LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE, format, sizeof(format)/sizeof(WCHAR));
1109 1110 1111
            args[0] = lpcf->nSizeMin;
            args[1] = lpcf->nSizeMax;
            FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
1112
                           format, 0, 0, msgW, sizeof(msgW)/sizeof(*msgW),
1113
                           (__ms_va_list*)args);
1114
            MessageBoxW(hDlg, msgW, NULL, MB_OK);
Rein Klazes's avatar
Rein Klazes committed
1115 1116
        }
        return(TRUE);
1117
    }
Rein Klazes's avatar
Rein Klazes committed
1118 1119 1120 1121 1122
    case IDCANCEL:
        EndDialog(hDlg, FALSE);
        return(TRUE);
    }
    return(FALSE);
1123 1124
}

1125
static LRESULT CFn_WMDestroy(HWND hwnd, LPCHOOSEFONTW lpcfw)
1126
{
Jacek Caban's avatar
Jacek Caban committed
1127 1128 1129 1130 1131
    LPCHOOSEFONTA lpcfa;
    LPSTR lpszStyle;
    LPLOGFONTA lpLogFonta;
    int len;

1132 1133
    if (!lpcfw) return FALSE;

Jacek Caban's avatar
Jacek Caban committed
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
    lpcfa = GetPropW(hwnd, strWineFontData_a);
    lpLogFonta = lpcfa->lpLogFont;
    lpszStyle = lpcfa->lpszStyle;
    memcpy(lpcfa, lpcfw, sizeof(CHOOSEFONTA));
    lpcfa->lpLogFont = lpLogFonta;
    lpcfa->lpszStyle = lpszStyle;
    memcpy(lpcfa->lpLogFont, lpcfw->lpLogFont, sizeof(LOGFONTA));
    WideCharToMultiByte(CP_ACP, 0, lpcfw->lpLogFont->lfFaceName,
                        LF_FACESIZE, lpcfa->lpLogFont->lfFaceName, LF_FACESIZE, 0, 0);

1144
    if((lpcfw->Flags & CF_USESTYLE) && lpcfw->lpszStyle) {
1145
        len = WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, NULL, 0, 0, 0);
Jacek Caban's avatar
Jacek Caban committed
1146 1147 1148 1149 1150 1151
        WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, lpcfa->lpszStyle, len, 0, 0);
        HeapFree(GetProcessHeap(), 0, lpcfw->lpszStyle);
    }

    HeapFree(GetProcessHeap(), 0, lpcfw->lpLogFont);
    HeapFree(GetProcessHeap(), 0, lpcfw);
1152
    SetPropW(hwnd, strWineFontData, 0);
Jacek Caban's avatar
Jacek Caban committed
1153

Rein Klazes's avatar
Rein Klazes committed
1154
    return TRUE;
1155 1156
}

1157
static LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam, const CHOOSEFONTW *lpcf)
1158 1159 1160
{
    WINDOWINFO info;

1161 1162
    if (!lpcf) return FALSE;

1163 1164 1165 1166 1167 1168
    info.cbSize=sizeof(info);
    if( GetWindowInfo( GetDlgItem( hDlg, stc5), &info ) )
    {
        PAINTSTRUCT ps;
        HDC hdc;
        HFONT hOrigFont;
Jacek Caban's avatar
Jacek Caban committed
1169
        LOGFONTW lf = *(lpcf->lpLogFont);
1170

1171
        MapWindowPoints( 0, hDlg, (LPPOINT) &info.rcWindow, 2);
1172 1173
        hdc = BeginPaint( hDlg, &ps );

1174
        TRACE("erase %d, rect=%s\n", ps.fErase, wine_dbgstr_rect(&ps.rcPaint));
1175 1176

        /* Paint frame */
1177
        DrawEdge( hdc, &info.rcWindow, EDGE_SUNKEN, BF_RECT|BF_ADJUST );
1178 1179

        /* Draw the sample text itself */
Jacek Caban's avatar
Jacek Caban committed
1180
        hOrigFont = SelectObject( hdc, CreateFontIndirectW( &lf ) );
Eric Pouech's avatar
Eric Pouech committed
1181
        SetTextColor( hdc, lpcf->rgbColors );
1182

1183 1184 1185
        DrawTextW( hdc,
                sample_lang_text[CHARSET_ORDER[lpcf->lpLogFont->lfCharSet]],
                -1, &info.rcWindow, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
Rein Klazes's avatar
Rein Klazes committed
1186

1187
        DeleteObject(SelectObject( hdc, hOrigFont ));
1188 1189 1190 1191
        EndPaint( hDlg, &ps );
    }
    return FALSE;
}
1192 1193

/***********************************************************************
1194
 *           FormatCharDlgProcA   [internal]
1195
 */
1196
static INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1197
{
Jacek Caban's avatar
Jacek Caban committed
1198 1199
    LPCHOOSEFONTW lpcfw;
    LPCHOOSEFONTA lpcfa;
Rein Klazes's avatar
Rein Klazes committed
1200
    INT_PTR res = FALSE;
Jacek Caban's avatar
Jacek Caban committed
1201
    int len;
1202

Jacek Caban's avatar
Jacek Caban committed
1203
    if (uMsg!=WM_INITDIALOG) {
1204
        lpcfw = GetPropW(hDlg, strWineFontData);
1205
        if (lpcfw && CFn_HookCallChk32(lpcfw))
Jacek Caban's avatar
Jacek Caban committed
1206
            res=CallWindowProcA((WNDPROC)lpcfw->lpfnHook, hDlg, uMsg, wParam, lParam);
Rein Klazes's avatar
Rein Klazes committed
1207 1208
        if (res)
            return res;
Jacek Caban's avatar
Jacek Caban committed
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
    } else {
        lpcfa=(LPCHOOSEFONTA)lParam;
        SetPropW(hDlg, strWineFontData_a, (HANDLE)lParam);

        lpcfw = HeapAlloc(GetProcessHeap(), 0, sizeof(CHOOSEFONTW));
        memcpy(lpcfw, lpcfa, sizeof(CHOOSEFONTA));
        lpcfw->lpLogFont = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGFONTW));
        memcpy(lpcfw->lpLogFont, lpcfa->lpLogFont, sizeof(LOGFONTA));
        MultiByteToWideChar(CP_ACP, 0, lpcfa->lpLogFont->lfFaceName,
                            LF_FACESIZE, lpcfw->lpLogFont->lfFaceName, LF_FACESIZE);

1220
        if((lpcfa->Flags & CF_USESTYLE) && lpcfa->lpszStyle)  {
Jacek Caban's avatar
Jacek Caban committed
1221 1222 1223 1224 1225
            len = MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, NULL, 0);
            lpcfw->lpszStyle = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
            MultiByteToWideChar(CP_ACP, 0, lpcfa->lpszStyle, -1, lpcfw->lpszStyle, len);
        }

1226
        if (!CFn_WMInitDialog(hDlg, lParam, lpcfw))
Rein Klazes's avatar
Rein Klazes committed
1227 1228 1229 1230
        {
            TRACE("CFn_WMInitDialog returned FALSE\n");
            return FALSE;
        }
Jacek Caban's avatar
Jacek Caban committed
1231 1232
        if (CFn_HookCallChk32(lpcfw))
            return CallWindowProcA((WNDPROC)lpcfa->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1233
    }
Rein Klazes's avatar
Rein Klazes committed
1234
    switch (uMsg)
1235
    {
Rein Klazes's avatar
Rein Klazes committed
1236
    case WM_MEASUREITEM:
1237
        return CFn_WMMeasureItem(hDlg,lParam);
Rein Klazes's avatar
Rein Klazes committed
1238
    case WM_DRAWITEM:
1239
        return CFn_WMDrawItem(lParam);
Rein Klazes's avatar
Rein Klazes committed
1240
    case WM_COMMAND:
Jacek Caban's avatar
Jacek Caban committed
1241
        return CFn_WMCommand(hDlg, wParam, lParam, lpcfw);
Rein Klazes's avatar
Rein Klazes committed
1242
    case WM_DESTROY:
1243
        return CFn_WMDestroy(hDlg, lpcfw);
Rein Klazes's avatar
Rein Klazes committed
1244
    case WM_CHOOSEFONT_GETLOGFONT:
1245 1246
    {
        LOGFONTA *logfont = (LOGFONTA *)lParam;
Jacek Caban's avatar
Jacek Caban committed
1247
        TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
1248 1249 1250
        memcpy( logfont, lpcfw->lpLogFont, FIELD_OFFSET( LOGFONTA, lfFaceName ));
        WideCharToMultiByte( CP_ACP, 0, lpcfw->lpLogFont->lfFaceName, LF_FACESIZE,
                             logfont->lfFaceName, LF_FACESIZE, NULL, NULL );
Rein Klazes's avatar
Rein Klazes committed
1251
        break;
1252
    }
Rein Klazes's avatar
Rein Klazes committed
1253
    case WM_PAINT:
Jacek Caban's avatar
Jacek Caban committed
1254
        return CFn_WMPaint(hDlg, wParam, lParam, lpcfw);
1255
    }
Rein Klazes's avatar
Rein Klazes committed
1256
    return res;
1257 1258 1259
}

/***********************************************************************
1260
 *           FormatCharDlgProcW   [internal]
1261
 */
1262
static INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1263
{
Jacek Caban's avatar
Jacek Caban committed
1264
    LPCHOOSEFONTW lpcf;
Rein Klazes's avatar
Rein Klazes committed
1265
    INT_PTR res = FALSE;
1266

Rein Klazes's avatar
Rein Klazes committed
1267
    if (uMsg!=WM_INITDIALOG)
1268
    {
1269
        lpcf= GetPropW(hDlg, strWineFontData);
1270
        if (lpcf && CFn_HookCallChk32(lpcf))
Jacek Caban's avatar
Jacek Caban committed
1271
            res=CallWindowProcW((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
Rein Klazes's avatar
Rein Klazes committed
1272 1273
        if (res)
            return res;
1274
    }
Rein Klazes's avatar
Rein Klazes committed
1275 1276
    else
    {
Jacek Caban's avatar
Jacek Caban committed
1277
        lpcf=(LPCHOOSEFONTW)lParam;
1278
        if (!CFn_WMInitDialog(hDlg, lParam, lpcf))
Rein Klazes's avatar
Rein Klazes committed
1279 1280 1281 1282
        {
            TRACE("CFn_WMInitDialog returned FALSE\n");
            return FALSE;
        }
Jacek Caban's avatar
Jacek Caban committed
1283 1284
        if (CFn_HookCallChk32(lpcf))
            return CallWindowProcW((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
Rein Klazes's avatar
Rein Klazes committed
1285 1286
    }
    switch (uMsg)
1287
    {
Rein Klazes's avatar
Rein Klazes committed
1288
    case WM_MEASUREITEM:
1289
        return CFn_WMMeasureItem(hDlg, lParam);
Rein Klazes's avatar
Rein Klazes committed
1290
    case WM_DRAWITEM:
1291
        return CFn_WMDrawItem(lParam);
Rein Klazes's avatar
Rein Klazes committed
1292
    case WM_COMMAND:
Jacek Caban's avatar
Jacek Caban committed
1293
        return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
Rein Klazes's avatar
Rein Klazes committed
1294
    case WM_DESTROY:
Jacek Caban's avatar
Jacek Caban committed
1295
        return TRUE;
Rein Klazes's avatar
Rein Klazes committed
1296
    case WM_CHOOSEFONT_GETLOGFONT:
Jacek Caban's avatar
Jacek Caban committed
1297
        TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
1298
        memcpy( (LOGFONTW *)lParam, lpcf->lpLogFont, sizeof(LOGFONTW) );
Rein Klazes's avatar
Rein Klazes committed
1299
        break;
Jacek Caban's avatar
Jacek Caban committed
1300 1301
    case WM_PAINT:
        return CFn_WMPaint(hDlg, wParam, lParam, lpcf);
1302
    }
Rein Klazes's avatar
Rein Klazes committed
1303
    return res;
1304
}