fontdlg.c 44.1 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 "cderr.h"
36
#include "cdlg.h"
37

38
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
39

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


Jacek Caban's avatar
Jacek Caban committed
49 50 51 52
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};
53

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

58 59
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);
60

61 62 63 64 65 66
/* 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)
67 68 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


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 */

99
static const WCHAR * const sample_lang_text[]={
100 101 102 103 104 105
    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};

106

107
static const BYTE CHARSET_ORDER[256]={
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    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),
};

126 127 128
static const struct {
    DWORD       mask;
    const char *name;
129 130 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
} 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
};

159
static void _dump_cf_flags(DWORD cflags)
160
{
161
    unsigned int i;
162

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

169
/***********************************************************************
170
 *           ChooseFontW   (COMDLG32.@)
171 172 173 174 175 176 177 178 179 180
 *
 * 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.
181
 */
182
BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
183
{
Rein Klazes's avatar
Rein Klazes committed
184 185 186 187
    LPCVOID template;
    HRSRC hResInfo;
    HINSTANCE hDlginst;
    HGLOBAL hDlgTmpl;
188

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

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

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

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

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

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

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

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

284 285 286 287 288
#define TEXT_EXTRAS 4
#define TEXT_COLORS 16

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

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

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

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

    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;

    if (e) e->added++;

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

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

/*************************************************************************
 *              SetFontStylesToCombo2                           [internal]
 *
 * Fill font style information into combobox  (without using font.c directly)
 */
Jacek Caban's avatar
Jacek Caban committed
361
static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTW *lplf)
362
{
Rein Klazes's avatar
Rein Klazes committed
363 364 365 366 367
#define FSTYLES 4
    struct FONTSTYLE
    {
        int italic;
        int weight;
368
        UINT resId;
Rein Klazes's avatar
Rein Klazes committed
369
    };
370
    static const struct FONTSTYLE fontstyles[FSTYLES]={
371 372 373 374
        { 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
375 376
    };
    HFONT hf;
Jacek Caban's avatar
Jacek Caban committed
377
    TEXTMETRICW tm;
Rein Klazes's avatar
Rein Klazes committed
378
    int i,j;
Jacek Caban's avatar
Jacek Caban committed
379
    LOGFONTW lf;
Rein Klazes's avatar
Rein Klazes committed
380

381
    lf = *lplf;
Rein Klazes's avatar
Rein Klazes committed
382 383 384 385 386

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

/*************************************************************************
 *              AddFontSizeToCombo3                           [internal]
 */
412
static int AddFontSizeToCombo3(HWND hwnd, UINT h, const CHOOSEFONTW *lpcf)
413 414
{
    int j;
Jacek Caban's avatar
Jacek Caban committed
415 416
    WCHAR buffer[20];
    static const WCHAR strFormat[] = {'%','2','d',0};
417 418

    if (  (!(lpcf->Flags & CF_LIMITSIZE))  ||
Rein Klazes's avatar
Rein Klazes committed
419
            ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
420
    {
Jacek Caban's avatar
Jacek Caban committed
421 422
        wsprintfW(buffer, strFormat, h);
        j=SendMessageW(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
Rein Klazes's avatar
Rein Klazes committed
423 424
        if (j==CB_ERR)
        {
Jacek Caban's avatar
Jacek Caban committed
425
            j=SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
Jacek Caban's avatar
Jacek Caban committed
426
            if (j!=CB_ERR) j = SendMessageW(hwnd, CB_SETITEMDATA, j, h);
Rein Klazes's avatar
Rein Klazes committed
427 428
            if (j==CB_ERR) return 1;
        }
429 430
    }
    return 0;
431 432
}

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

441
    for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
Rein Klazes's avatar
Rein Klazes committed
442 443
        if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
    return 0;
444 445
}

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

458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
/*************************************************************************
 *              GetScreenDPI                           [internal]
 */
static inline int GetScreenDPI(void)
{
    HDC hdc;
    int result;

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

    return result;
}

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

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

    TRACE("(nFontType=%d)\n",nFontType);
494
    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
495
            " ch=%d op=%d cp=%d q=%d pf=%xh\n",
Jacek Caban's avatar
Jacek Caban committed
496
            debugstr_w(lplf->lfFaceName),lplf->lfHeight,lplf->lfWidth,
Rein Klazes's avatar
Rein Klazes committed
497 498 499 500 501 502
            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)
    {
503
        INT points;
504
        points = MulDiv( lpNTM->ntmTm.tmHeight - lpNTM->ntmTm.tmInternalLeading,
505
                72, GetScreenDPI());
506
        i = AddFontSizeToCombo3(hcmb3, points, lpcf);
Jacek Caban's avatar
Jacek Caban committed
507
        if(i) return 0;
Rein Klazes's avatar
Rein Klazes committed
508 509
    } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;

Jacek Caban's avatar
Jacek Caban committed
510
    if (!SendMessageW(hcmb2, CB_GETCOUNT, 0, 0))
Rein Klazes's avatar
Rein Klazes committed
511
    {
512
        if(!(hdc = CFn_GetDC(lpcf))) return 0;
Rein Klazes's avatar
Rein Klazes committed
513
        i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
514
        CFn_ReleaseDC(lpcf, hdc);
Rein Klazes's avatar
Rein Klazes committed
515 516 517
        if (i)
            return 0;
    }
518
    if (!( hcmb5 = GetDlgItem(hDlg, cmb5))) return 1;
Jacek Caban's avatar
Jacek Caban committed
519
    i = SendMessageW( hcmb5, CB_FINDSTRINGEXACT, 0,
520
                (LPARAM)lpElfex->elfScript);
521
    if( i == CB_ERR) {
Jacek Caban's avatar
Jacek Caban committed
522
        i = SendMessageW( hcmb5, CB_ADDSTRING, 0,
523 524
                (LPARAM)lpElfex->elfScript);
        if( i != CB_ERR)
Jacek Caban's avatar
Jacek Caban committed
525
            SendMessageW( hcmb5, CB_SETITEMDATA, i, lplf->lfCharSet);
526
    }
Rein Klazes's avatar
Rein Klazes committed
527
    return 1 ;
528
}
529

530 531 532 533 534
static INT CFn_FitFontSize( HWND hDlg, int points)
{
    int i,n;
    int ret = 0;
    /* look for fitting font size in combobox3 */
Jacek Caban's avatar
Jacek Caban committed
535
    n=SendDlgItemMessageW(hDlg, cmb3, CB_GETCOUNT, 0, 0);
536 537
    for (i=0;i<n;i++)
    {
Jacek Caban's avatar
Jacek Caban committed
538
        if (points == (int)SendDlgItemMessageW
539 540
                (hDlg,cmb3, CB_GETITEMDATA,i,0))
        {
Jacek Caban's avatar
Jacek Caban committed
541 542
            SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,i,0);
            SendMessageW(hDlg, WM_COMMAND,
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
                    MAKEWPARAM(cmb3, CBN_SELCHANGE),
                    (LPARAM)GetDlgItem(hDlg,cmb3));
            ret = 1;
            break;
        }
    }
    return ret;
}

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

572 573 574 575

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

596 597 598
/***********************************************************************
 *                 FontStyleEnumProc32                     [internal]
 */
Jacek Caban's avatar
Jacek Caban committed
599 600
static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXW *lpElfex,
        const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam )
601
{
Rein Klazes's avatar
Rein Klazes committed
602 603 604 605
    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
606
    return AddFontStyle( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
607
                         dwFontType, s->lpcf32w, hcmb2, hcmb3, hDlg);
608 609 610 611 612
}

/***********************************************************************
 *           CFn_WMInitDialog                            [internal]
 */
613
static LRESULT CFn_WMInitDialog(HWND hDlg, LPARAM lParam, LPCHOOSEFONTW lpcf)
614
{
Rein Klazes's avatar
Rein Klazes committed
615 616
    HDC hdc;
    int i,j,init=0;
617
    long pstyle;
618
    CFn_ENUMSTRUCT s;
Jacek Caban's avatar
Jacek Caban committed
619 620 621
    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
622

623
    SetPropW(hDlg, strWineFontData, lpcf);
Rein Klazes's avatar
Rein Klazes committed
624 625 626
    lpxx=lpcf->lpLogFont;
    TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);

Jacek Caban's avatar
Jacek Caban committed
627
    if (lpcf->lStructSize != sizeof(CHOOSEFONTW))
628
    {
Rein Klazes's avatar
Rein Klazes committed
629 630 631
        ERR("structure size failure !!!\n");
        EndDialog (hDlg, 0);
        return FALSE;
632
    }
633
    if (!himlTT)
Jacek Caban's avatar
Jacek Caban committed
634
        himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
635
                TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
Rein Klazes's avatar
Rein Klazes committed
636

637 638 639 640 641 642 643 644 645
    /* 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
646 647 648 649
    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);
650 651
    if (lpcf->Flags & CF_NOSCRIPTSEL)
        EnableWindow(GetDlgItem(hDlg,cmb5),FALSE);
Rein Klazes's avatar
Rein Klazes committed
652
    if (lpcf->Flags & CF_EFFECTS)
653
    {
Rein Klazes's avatar
Rein Klazes committed
654
        for (i=0;i<TEXT_COLORS;i++)
655
        {
Jacek Caban's avatar
Jacek Caban committed
656
            WCHAR name[30];
Rein Klazes's avatar
Rein Klazes committed
657

Jacek Caban's avatar
Jacek Caban committed
658
            if( LoadStringW(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name,
Rein Klazes's avatar
Rein Klazes committed
659 660
                        sizeof(name)/sizeof(*name) )==0 )
            {
Jacek Caban's avatar
Jacek Caban committed
661
                memcpy(name, strColorName, sizeof(strColorName));
Rein Klazes's avatar
Rein Klazes committed
662
            }
Jacek Caban's avatar
Jacek Caban committed
663
            j=SendDlgItemMessageW(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
664
            SendDlgItemMessageW(hDlg, cmb4, CB_SETITEMDATA, j, textcolors[i]);
Rein Klazes's avatar
Rein Klazes committed
665
            /* look for a fitting value in color combobox */
666
            if (textcolors[i]==lpcf->rgbColors)
Jacek Caban's avatar
Jacek Caban committed
667
                SendDlgItemMessageW(hDlg,cmb4, CB_SETCURSEL,j,0);
668 669
        }
    }
Rein Klazes's avatar
Rein Klazes committed
670
    else
671
    {
Rein Klazes's avatar
Rein Klazes committed
672 673 674 675 676 677
        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);
    }
678
    if(!(hdc = CFn_GetDC(lpcf)))
Rein Klazes's avatar
Rein Klazes committed
679
    {
680 681 682 683
        EndDialog (hDlg, 0);
        return FALSE;
    }
    s.hWnd1=GetDlgItem(hDlg,cmb1);
Jacek Caban's avatar
Jacek Caban committed
684
    s.lpcf32w=lpcf;
685
    do {
Jacek Caban's avatar
Jacek Caban committed
686
        LOGFONTW elf;
687
        s.added = 0;
688 689 690
        elf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
        elf.lfPitchAndFamily = 0;
        elf.lfFaceName[0] = '\0'; /* enum all fonts */
Jacek Caban's avatar
Jacek Caban committed
691
        if (!EnumFontFamiliesExW(hdc, &elf, (FONTENUMPROCW)FontFamilyEnumProc, (LPARAM)&s, 0))
692 693
        {
            TRACE("EnumFontFamiliesEx returns 0\n");
Rein Klazes's avatar
Rein Klazes committed
694
            break;
695 696 697 698 699 700 701 702 703 704 705 706 707 708
        }
        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
709 710


711 712 713
    if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
    {
        /* look for fitting font name in combobox1 */
Kevin Koltzau's avatar
Kevin Koltzau committed
714
        j=SendDlgItemMessageW(hDlg,cmb1,CB_FINDSTRING,-1,(LPARAM)lpxx->lfFaceName);
715
        if (j!=CB_ERR)
Rein Klazes's avatar
Rein Klazes committed
716
        {
717 718 719 720
            INT height = lpxx->lfHeight < 0 ? -lpxx->lfHeight :
                lpxx->lfHeight;
            INT points;
            int charset = lpxx->lfCharSet;
721
            points = MulDiv( height, 72, GetScreenDPI());
722 723
            pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:
                    FW_NORMAL,lpxx->lfItalic !=0);
Jacek Caban's avatar
Jacek Caban committed
724 725
            SendDlgItemMessageW(hDlg, cmb1, CB_SETCURSEL, j, 0);
            SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
Rein Klazes's avatar
Rein Klazes committed
726
                    (LPARAM)GetDlgItem(hDlg,cmb1));
727 728 729 730 731 732
            init=1;
            /* 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
733
        }
734
    }
735
    if (!init)
736
    {
Jacek Caban's avatar
Jacek Caban committed
737 738
        SendDlgItemMessageW(hDlg,cmb1,CB_SETCURSEL,0,0);
        SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
739
                (LPARAM)GetDlgItem(hDlg,cmb1));
740 741 742 743 744 745 746 747 748
        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));
749
    }
750
    if ((lpcf->Flags & CF_USESTYLE) && lpcf->lpszStyle)
751
    {
Kevin Koltzau's avatar
Kevin Koltzau committed
752
        j=SendDlgItemMessageW(hDlg,cmb2,CB_FINDSTRING,-1,(LPARAM)lpcf->lpszStyle);
753 754
        if (j!=CB_ERR)
        {
Jacek Caban's avatar
Jacek Caban committed
755 756
            j=SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,j,0);
            SendMessageW(hDlg,WM_COMMAND,cmb2,
757
                    MAKELONG(LOWORD(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
758 759 760
        }
    }
    CFn_ReleaseDC(lpcf, hdc);
Rein Klazes's avatar
Rein Klazes committed
761 762
    SetCursor(hcursor);
    return TRUE;
763 764 765 766 767 768
}


/***********************************************************************
 *           CFn_WMMeasureItem                           [internal]
 */
769
static LRESULT CFn_WMMeasureItem(HWND hDlg, LPARAM lParam)
770
{
771 772 773
    HDC hdc;
    HFONT hfontprev;
    TEXTMETRICW tm;
Rein Klazes's avatar
Rein Klazes committed
774
    LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
775
    INT height = 0, cx;
776

777
    if (!himlTT)
Jacek Caban's avatar
Jacek Caban committed
778
        himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
779
                TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
780
    ImageList_GetIconSize( himlTT, &cx, &height);
781
    lpmi->itemHeight = height + 2;
782
    /* use MAX of bitmap height and tm.tmHeight .*/
Jacek Caban's avatar
Jacek Caban committed
783
    hdc=GetDC(hDlg);
784
    if(!hdc) return 0;
785
    hfontprev = SelectObject( hdc, GetStockObject( DEFAULT_GUI_FONT ) );
Jacek Caban's avatar
Jacek Caban committed
786
    GetTextMetricsW(hdc, &tm);
787
    if( tm.tmHeight > lpmi->itemHeight) lpmi->itemHeight = tm.tmHeight;
Jacek Caban's avatar
Jacek Caban committed
788 789
    SelectObject(hdc, hfontprev);
    ReleaseDC(hDlg, hdc);
Rein Klazes's avatar
Rein Klazes committed
790
    return 0;
791 792 793 794 795 796
}


/***********************************************************************
 *           CFn_WMDrawItem                              [internal]
 */
797
static LRESULT CFn_WMDrawItem(LPARAM lParam)
798
{
Rein Klazes's avatar
Rein Klazes committed
799
    HBRUSH hBrush;
Jacek Caban's avatar
Jacek Caban committed
800
    WCHAR buffer[40];
Rein Klazes's avatar
Rein Klazes committed
801 802 803
    COLORREF cr, oldText=0, oldBk=0;
    RECT rect;
    int nFontType;
804
    int idx;
Rein Klazes's avatar
Rein Klazes committed
805 806 807 808 809 810 811 812
    LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;

    if (lpdi->itemID == (UINT)-1)  /* got no items */
        DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
    else
    {
        if (lpdi->CtlType == ODT_COMBOBOX)
        {
813
            if (lpdi->itemState & ODS_SELECTED)
Rein Klazes's avatar
Rein Klazes committed
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
            {
                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"); */
Jacek Caban's avatar
Jacek Caban committed
833
            SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
Rein Klazes's avatar
Rein Klazes committed
834
                         (LPARAM)buffer);
Jacek Caban's avatar
Jacek Caban committed
835 836 837
            TextOutW(lpdi->hDC, lpdi->rcItem.left + TTBITMAP_XSIZE + 10,
                     lpdi->rcItem.top, buffer, lstrlenW(buffer));
            nFontType = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
838 839 840 841 842 843 844 845 846 847 848 849 850 851
            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,
                        lpdi->rcItem.top, ILD_TRANSPARENT);
Rein Klazes's avatar
Rein Klazes committed
852 853 854 855
            break;
        case cmb2:
        case cmb3:
            /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
856
        case cmb5:
Jacek Caban's avatar
Jacek Caban committed
857
            SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
Rein Klazes's avatar
Rein Klazes committed
858
                         (LPARAM)buffer);
Jacek Caban's avatar
Jacek Caban committed
859 860
            TextOutW(lpdi->hDC, lpdi->rcItem.left,
                     lpdi->rcItem.top, buffer, lstrlenW(buffer));
Rein Klazes's avatar
Rein Klazes committed
861 862 863 864
            break;

        case cmb4:
            /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
Jacek Caban's avatar
Jacek Caban committed
865 866 867 868 869
            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
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
            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 */
        }
889
        if (lpdi->itemState & ODS_SELECTED)
Rein Klazes's avatar
Rein Klazes committed
890 891 892 893 894 895
        {
            SetTextColor(lpdi->hDC, oldText);
            SetBkColor(lpdi->hDC, oldBk);
        }
    }
    return TRUE;
896 897 898 899 900
}

/***********************************************************************
 *           CFn_WMCommand                               [internal]
 */
901
static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFONTW lpcf)
902
{
903
    int i;
Rein Klazes's avatar
Rein Klazes committed
904 905 906
    long l;
    HDC hdc;

907 908
    if (!lpcf) return FALSE;

909
    TRACE("WM_COMMAND wParam=%08X lParam=%08lX\n", (LONG)wParam, lParam);
Rein Klazes's avatar
Rein Klazes committed
910 911 912 913 914
    switch (LOWORD(wParam))
    {
    case cmb1:
        if (HIWORD(wParam)==CBN_SELCHANGE)
        {
915 916 917 918 919
            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
920 921 922 923
            {
                EndDialog (hDlg, 0);
                return TRUE;
            }
Jacek Caban's avatar
Jacek Caban committed
924 925
            idx = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
            pointsize = (int)SendDlgItemMessageW( hDlg, cmb3, CB_GETITEMDATA,
926
                    idx, 0);
Jacek Caban's avatar
Jacek Caban committed
927 928 929 930 931 932 933 934 935
            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);
936 937
            if (i!=CB_ERR)
            {
Jacek Caban's avatar
Jacek Caban committed
938
                HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
939
                CFn_ENUMSTRUCT s;
Jacek Caban's avatar
Jacek Caban committed
940 941
                LOGFONTW enumlf;
                SendDlgItemMessageW(hDlg, cmb1, CB_GETLBTEXT, i,
942
                                    (LPARAM)enumlf.lfFaceName);
Jacek Caban's avatar
Jacek Caban committed
943
                TRACE("WM_COMMAND/cmb1 =>%s\n", debugstr_w(enumlf.lfFaceName));
944 945
                s.hWnd1=GetDlgItem(hDlg, cmb2);
                s.hWnd2=GetDlgItem(hDlg, cmb3);
Jacek Caban's avatar
Jacek Caban committed
946
                s.lpcf32w=lpcf;
947 948
                enumlf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
                enumlf.lfPitchAndFamily = 0;
Jacek Caban's avatar
Jacek Caban committed
949 950
                EnumFontFamiliesExW(hdc, &enumlf,
                        (FONTENUMPROCW)FontStyleEnumProc, (LPARAM)&s, 0);
951 952 953 954 955 956
                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
957
        }
958
        break;
Rein Klazes's avatar
Rein Klazes committed
959 960 961 962
    case chx1:
    case chx2:
    case cmb2:
    case cmb3:
963
    case cmb5:
Rein Klazes's avatar
Rein Klazes committed
964 965
        if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
        {
Jacek Caban's avatar
Jacek Caban committed
966
            WCHAR str[256];
Rein Klazes's avatar
Rein Klazes committed
967
            WINDOWINFO wininfo;
968
            LPLOGFONTW lpxx=lpcf->lpLogFont;
Rein Klazes's avatar
Rein Klazes committed
969 970

            TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
Jacek Caban's avatar
Jacek Caban committed
971
            i=SendDlgItemMessageW(hDlg,cmb1,CB_GETCURSEL,0,0);
Rein Klazes's avatar
Rein Klazes committed
972
            if (i==CB_ERR)
Jacek Caban's avatar
Jacek Caban committed
973
                i=GetDlgItemTextW( hDlg, cmb1, str, 256 );
Rein Klazes's avatar
Rein Klazes committed
974 975
            else
            {
Jacek Caban's avatar
Jacek Caban committed
976
                SendDlgItemMessageW(hDlg,cmb1,CB_GETLBTEXT,i,
Rein Klazes's avatar
Rein Klazes committed
977
                                    (LPARAM)str);
Jacek Caban's avatar
Jacek Caban committed
978
                l=SendDlgItemMessageW(hDlg,cmb1,CB_GETITEMDATA,i,0);
Rein Klazes's avatar
Rein Klazes committed
979 980 981 982
                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 */
983
                lpxx->lfPitchAndFamily = HIWORD(l) >> 8;
Rein Klazes's avatar
Rein Klazes committed
984
            }
985
            lstrcpynW(lpxx->lfFaceName, str, sizeof(lpxx->lfFaceName)/sizeof(lpxx->lfFaceName[0]));
Jacek Caban's avatar
Jacek Caban committed
986
            i=SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
Rein Klazes's avatar
Rein Klazes committed
987 988
            if (i!=CB_ERR)
            {
Jacek Caban's avatar
Jacek Caban committed
989
                l=SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
Rein Klazes's avatar
Rein Klazes committed
990 991 992 993 994
                if (0!=(lpxx->lfItalic=HIWORD(l)))
                    lpcf->nFontType |= ITALIC_FONTTYPE;
                if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
                    lpcf->nFontType |= BOLD_FONTTYPE;
            }
Jacek Caban's avatar
Jacek Caban committed
995
            i=SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
996
            if( i != CB_ERR)
Jacek Caban's avatar
Jacek Caban committed
997
                lpcf->iPointSize = 10 * LOWORD(SendDlgItemMessageW(hDlg, cmb3,
998
                            CB_GETITEMDATA , i, 0));
Rein Klazes's avatar
Rein Klazes committed
999
            else
1000
                lpcf->iPointSize = 100;
1001 1002
            lpxx->lfHeight = - MulDiv( lpcf->iPointSize ,
                    GetScreenDPI(), 720);
Jacek Caban's avatar
Jacek Caban committed
1003
            i=SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
1004
            if (i!=CB_ERR)
Jacek Caban's avatar
Jacek Caban committed
1005
                lpxx->lfCharSet=SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
1006 1007
            else
                lpxx->lfCharSet = DEFAULT_CHARSET;
Rein Klazes's avatar
Rein Klazes committed
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
            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
1026
        i=SendDlgItemMessageW(hDlg, cmb4, CB_GETCURSEL, 0, 0);
Rein Klazes's avatar
Rein Klazes committed
1027 1028 1029 1030
        if (i!=CB_ERR)
        {
            WINDOWINFO wininfo;

1031
            lpcf->rgbColors = SendDlgItemMessageW(hDlg, cmb4, CB_GETITEMDATA, i, 0);
Rein Klazes's avatar
Rein Klazes committed
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
            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
1043
        i=RegisterWindowMessageW( HELPMSGSTRINGW );
Rein Klazes's avatar
Rein Klazes committed
1044
        if (lpcf->hwndOwner)
Jacek Caban's avatar
Jacek Caban committed
1045
            SendMessageW(lpcf->hwndOwner, i, 0, (LPARAM)GetPropW(hDlg, strWineFontData));
Rein Klazes's avatar
Rein Klazes committed
1046 1047 1048 1049 1050
        break;

    case IDOK:
        if (  (!(lpcf->Flags & CF_LIMITSIZE))  ||
              ( (lpcf->Flags & CF_LIMITSIZE) &&
1051 1052
                (lpcf->iPointSize >= 10 * lpcf->nSizeMin) &&
                (lpcf->iPointSize <= 10 * lpcf->nSizeMax)))
Rein Klazes's avatar
Rein Klazes committed
1053 1054 1055
            EndDialog(hDlg, TRUE);
        else
        {
Jacek Caban's avatar
Jacek Caban committed
1056 1057 1058 1059 1060
            WCHAR buffer[80];
            WCHAR format[80];
            LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE, format, sizeof(format)/sizeof(WCHAR));
            wsprintfW(buffer, format, lpcf->nSizeMin,lpcf->nSizeMax);
            MessageBoxW(hDlg, buffer, NULL, MB_OK);
Rein Klazes's avatar
Rein Klazes committed
1061 1062 1063 1064 1065 1066 1067
        }
        return(TRUE);
    case IDCANCEL:
        EndDialog(hDlg, FALSE);
        return(TRUE);
    }
    return(FALSE);
1068 1069
}

1070
static LRESULT CFn_WMDestroy(HWND hwnd, LPCHOOSEFONTW lpcfw)
1071
{
Jacek Caban's avatar
Jacek Caban committed
1072 1073 1074 1075 1076
    LPCHOOSEFONTA lpcfa;
    LPSTR lpszStyle;
    LPLOGFONTA lpLogFonta;
    int len;

1077 1078
    if (!lpcfw) return FALSE;

Jacek Caban's avatar
Jacek Caban committed
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
    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);

1089
    if((lpcfw->Flags & CF_USESTYLE) && lpcfw->lpszStyle) {
1090
        len = WideCharToMultiByte(CP_ACP, 0, lpcfw->lpszStyle, -1, NULL, 0, 0, 0);
Jacek Caban's avatar
Jacek Caban committed
1091 1092 1093 1094 1095 1096
        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);
1097
    SetPropW(hwnd, strWineFontData, 0);
Jacek Caban's avatar
Jacek Caban committed
1098

Rein Klazes's avatar
Rein Klazes committed
1099
    return TRUE;
1100 1101
}

1102
static LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam, const CHOOSEFONTW *lpcf)
1103 1104 1105
{
    WINDOWINFO info;

1106 1107
    if (!lpcf) return FALSE;

1108 1109 1110 1111 1112 1113 1114
    info.cbSize=sizeof(info);
    if( GetWindowInfo( GetDlgItem( hDlg, stc5), &info ) )
    {
        PAINTSTRUCT ps;
        HDC hdc;
        HPEN hOrigPen;
        HFONT hOrigFont;
Jacek Caban's avatar
Jacek Caban committed
1115
        LOGFONTW lf = *(lpcf->lpLogFont);
1116

1117
        MapWindowPoints( 0, hDlg, (LPPOINT) &info.rcWindow, 2);
1118 1119
        hdc = BeginPaint( hDlg, &ps );

1120
        TRACE("erase %d, rect=(%d,%d)-(%d,%d)\n", ps.fErase,
1121 1122
              ps.rcPaint.left, ps.rcPaint.top,
              ps.rcPaint.right, ps.rcPaint.bottom);
1123 1124 1125 1126

        /* Paint frame */
        MoveToEx( hdc, info.rcWindow.left, info.rcWindow.bottom, NULL );
        hOrigPen=SelectObject( hdc, CreatePen( PS_SOLID, 2,
Rein Klazes's avatar
Rein Klazes committed
1127
                                               GetSysColor( COLOR_3DSHADOW ) ));
1128 1129 1130
        LineTo( hdc, info.rcWindow.left, info.rcWindow.top );
        LineTo( hdc, info.rcWindow.right, info.rcWindow.top );
        DeleteObject(SelectObject( hdc, CreatePen( PS_SOLID, 2,
Rein Klazes's avatar
Rein Klazes committed
1131
                                                   GetSysColor( COLOR_3DLIGHT ) )));
1132 1133 1134 1135 1136 1137 1138 1139 1140
        LineTo( hdc, info.rcWindow.right, info.rcWindow.bottom );
        LineTo( hdc, info.rcWindow.left, info.rcWindow.bottom );
        DeleteObject(SelectObject( hdc, hOrigPen ));

        /* Draw the sample text itself */
        info.rcWindow.right--;
        info.rcWindow.bottom--;
        info.rcWindow.top++;
        info.rcWindow.left++;
Jacek Caban's avatar
Jacek Caban committed
1141
        hOrigFont = SelectObject( hdc, CreateFontIndirectW( &lf ) );
Eric Pouech's avatar
Eric Pouech committed
1142
        SetTextColor( hdc, lpcf->rgbColors );
1143

1144 1145 1146
        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
1147

1148
        DeleteObject(SelectObject( hdc, hOrigFont ));
1149 1150 1151 1152
        EndPaint( hDlg, &ps );
    }
    return FALSE;
}
1153 1154

/***********************************************************************
1155
 *           FormatCharDlgProcA   [internal]
1156
 */
1157
static INT_PTR CALLBACK FormatCharDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1158
{
Jacek Caban's avatar
Jacek Caban committed
1159 1160
    LPCHOOSEFONTW lpcfw;
    LPCHOOSEFONTA lpcfa;
Rein Klazes's avatar
Rein Klazes committed
1161
    INT_PTR res = FALSE;
Jacek Caban's avatar
Jacek Caban committed
1162
    int len;
1163

Jacek Caban's avatar
Jacek Caban committed
1164
    if (uMsg!=WM_INITDIALOG) {
1165
        lpcfw = GetPropW(hDlg, strWineFontData);
1166
        if (lpcfw && CFn_HookCallChk32(lpcfw))
Jacek Caban's avatar
Jacek Caban committed
1167
            res=CallWindowProcA((WNDPROC)lpcfw->lpfnHook, hDlg, uMsg, wParam, lParam);
Rein Klazes's avatar
Rein Klazes committed
1168 1169
        if (res)
            return res;
Jacek Caban's avatar
Jacek Caban committed
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
    } 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);

1181
        if((lpcfa->Flags & CF_USESTYLE) && lpcfa->lpszStyle)  {
Jacek Caban's avatar
Jacek Caban committed
1182 1183 1184 1185 1186
            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);
        }

1187
        if (!CFn_WMInitDialog(hDlg, lParam, lpcfw))
Rein Klazes's avatar
Rein Klazes committed
1188 1189 1190 1191
        {
            TRACE("CFn_WMInitDialog returned FALSE\n");
            return FALSE;
        }
Jacek Caban's avatar
Jacek Caban committed
1192 1193
        if (CFn_HookCallChk32(lpcfw))
            return CallWindowProcA((WNDPROC)lpcfa->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1194
    }
Rein Klazes's avatar
Rein Klazes committed
1195
    switch (uMsg)
1196
    {
Rein Klazes's avatar
Rein Klazes committed
1197
    case WM_MEASUREITEM:
1198
        return CFn_WMMeasureItem(hDlg,lParam);
Rein Klazes's avatar
Rein Klazes committed
1199
    case WM_DRAWITEM:
1200
        return CFn_WMDrawItem(lParam);
Rein Klazes's avatar
Rein Klazes committed
1201
    case WM_COMMAND:
Jacek Caban's avatar
Jacek Caban committed
1202
        return CFn_WMCommand(hDlg, wParam, lParam, lpcfw);
Rein Klazes's avatar
Rein Klazes committed
1203
    case WM_DESTROY:
1204
        return CFn_WMDestroy(hDlg, lpcfw);
Rein Klazes's avatar
Rein Klazes committed
1205
    case WM_CHOOSEFONT_GETLOGFONT:
Jacek Caban's avatar
Jacek Caban committed
1206
        TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
Rein Klazes's avatar
Rein Klazes committed
1207 1208 1209
        FIXME("current logfont back to caller\n");
        break;
    case WM_PAINT:
Jacek Caban's avatar
Jacek Caban committed
1210
        return CFn_WMPaint(hDlg, wParam, lParam, lpcfw);
1211
    }
Rein Klazes's avatar
Rein Klazes committed
1212
    return res;
1213 1214 1215
}

/***********************************************************************
1216
 *           FormatCharDlgProcW   [internal]
1217
 */
1218
static INT_PTR CALLBACK FormatCharDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1219
{
Jacek Caban's avatar
Jacek Caban committed
1220
    LPCHOOSEFONTW lpcf;
Rein Klazes's avatar
Rein Klazes committed
1221
    INT_PTR res = FALSE;
1222

Rein Klazes's avatar
Rein Klazes committed
1223
    if (uMsg!=WM_INITDIALOG)
1224
    {
1225
        lpcf= GetPropW(hDlg, strWineFontData);
1226
        if (lpcf && CFn_HookCallChk32(lpcf))
Jacek Caban's avatar
Jacek Caban committed
1227
            res=CallWindowProcW((WNDPROC)lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
Rein Klazes's avatar
Rein Klazes committed
1228 1229
        if (res)
            return res;
1230
    }
Rein Klazes's avatar
Rein Klazes committed
1231 1232
    else
    {
Jacek Caban's avatar
Jacek Caban committed
1233
        lpcf=(LPCHOOSEFONTW)lParam;
1234
        if (!CFn_WMInitDialog(hDlg, lParam, lpcf))
Rein Klazes's avatar
Rein Klazes committed
1235 1236 1237 1238
        {
            TRACE("CFn_WMInitDialog returned FALSE\n");
            return FALSE;
        }
Jacek Caban's avatar
Jacek Caban committed
1239 1240
        if (CFn_HookCallChk32(lpcf))
            return CallWindowProcW((WNDPROC)lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
Rein Klazes's avatar
Rein Klazes committed
1241 1242
    }
    switch (uMsg)
1243
    {
Rein Klazes's avatar
Rein Klazes committed
1244
    case WM_MEASUREITEM:
1245
        return CFn_WMMeasureItem(hDlg, lParam);
Rein Klazes's avatar
Rein Klazes committed
1246
    case WM_DRAWITEM:
1247
        return CFn_WMDrawItem(lParam);
Rein Klazes's avatar
Rein Klazes committed
1248
    case WM_COMMAND:
Jacek Caban's avatar
Jacek Caban committed
1249
        return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
Rein Klazes's avatar
Rein Klazes committed
1250
    case WM_DESTROY:
Jacek Caban's avatar
Jacek Caban committed
1251
        return TRUE;
Rein Klazes's avatar
Rein Klazes committed
1252
    case WM_CHOOSEFONT_GETLOGFONT:
Jacek Caban's avatar
Jacek Caban committed
1253
        TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
Rein Klazes's avatar
Rein Klazes committed
1254 1255
        FIXME("current logfont back to caller\n");
        break;
Jacek Caban's avatar
Jacek Caban committed
1256 1257
    case WM_PAINT:
        return CFn_WMPaint(hDlg, wParam, lParam, lpcf);
1258
    }
Rein Klazes's avatar
Rein Klazes committed
1259
    return res;
1260
}