set svn:eol-style to native
[reactos.git] / reactos / lib / comdlg32 / fontdlg16.c
index 9bfcb77..84a51e9 100644 (file)
-/*\r
- * COMMDLG - Font Dialog\r
- *\r
- * Copyright 1994 Martin Ayotte\r
- * Copyright 1996 Albrecht Kleine\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Lesser General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2.1 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
- * Lesser General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- */\r
-\r
-#include <ctype.h>\r
-#include <stdlib.h>\r
-#include <stdarg.h>\r
-#include <stdio.h>\r
-#include <string.h>\r
-#include "windef.h"\r
-#include "winbase.h"\r
-#include "wingdi.h"\r
-#include "winuser.h"\r
-#include "winnls.h"\r
-#include "wine/winbase16.h"\r
-#include "wine/winuser16.h"\r
-#include "commdlg.h"\r
-#include "dlgs.h"\r
-#include "wine/debug.h"\r
-#include "cderr.h"\r
-\r
-WINE_DEFAULT_DEBUG_CHANNEL(commdlg);\r
-\r
-#include "cdlg.h"\r
-#include "cdlg16.h"\r
-\r
-static void FONT_LogFont16To32W( const LPLOGFONT16 font16, LPLOGFONTW font32 )\r
-{\r
-    font32->lfHeight = font16->lfHeight;\r
-    font32->lfWidth = font16->lfWidth;\r
-    font32->lfEscapement = font16->lfEscapement;\r
-    font32->lfOrientation = font16->lfOrientation;\r
-    font32->lfWeight = font16->lfWeight;\r
-    font32->lfItalic = font16->lfItalic;\r
-    font32->lfUnderline = font16->lfUnderline;\r
-    font32->lfStrikeOut = font16->lfStrikeOut;\r
-    font32->lfCharSet = font16->lfCharSet;\r
-    font32->lfOutPrecision = font16->lfOutPrecision;\r
-    font32->lfClipPrecision = font16->lfClipPrecision;\r
-    font32->lfQuality = font16->lfQuality;\r
-    font32->lfPitchAndFamily = font16->lfPitchAndFamily;\r
-    MultiByteToWideChar(CP_ACP, 0, font16->lfFaceName,\r
-                        LF_FACESIZE, font32->lfFaceName, LF_FACESIZE);\r
-};\r
-\r
-static void FONT_Metrics16To32W( const TEXTMETRIC16 *pm16,\r
-                                 NEWTEXTMETRICEXW *pnm32w)\r
-{\r
-    ZeroMemory( pnm32w, sizeof(NEWTEXTMETRICEXW));\r
-    /* NOTE: only the fields used by AddFontStyle() are filled in */\r
-    pnm32w->ntmTm.tmHeight = pm16->tmHeight;\r
-    pnm32w->ntmTm.tmExternalLeading = pm16->tmExternalLeading;\r
-};\r
-\r
-static void CFn_CHOOSEFONT16to32W(LPCHOOSEFONT16 chf16, LPCHOOSEFONTW chf32w)\r
-{\r
-  int len;\r
-  if(chf16->lpTemplateName)\r
-  {\r
-    len = MultiByteToWideChar(CP_ACP, 0, (LPBYTE)chf16->lpTemplateName, -1, NULL, 0);\r
-    chf32w->lpTemplateName = HeapAlloc(GetProcessHeap(), 0,len*sizeof(WCHAR));\r
-    MultiByteToWideChar(CP_ACP, 0, (LPSTR)MapSL(chf16->lpTemplateName),\r
-                        -1, (LPWSTR)chf32w->lpTemplateName, len);\r
-  }\r
-  if(chf16->lpszStyle)\r
-  {\r
-    len = MultiByteToWideChar(CP_ACP, 0, (LPBYTE)chf16->lpszStyle, -1, NULL, 0);\r
-    chf32w->lpszStyle = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));\r
-    MultiByteToWideChar(CP_ACP, 0, (LPSTR)MapSL(chf16->lpTemplateName),\r
-                        -1, chf32w->lpszStyle, len);\r
-  }\r
-  chf32w->lStructSize=sizeof(CHOOSEFONTW);\r
-  chf32w->hwndOwner=HWND_32(chf16->hwndOwner);\r
-  chf32w->hDC=HDC_32(chf16->hDC);\r
-  chf32w->iPointSize=chf16->iPointSize;\r
-  chf32w->Flags=chf16->Flags;\r
-  chf32w->rgbColors=chf16->rgbColors;\r
-  chf32w->lCustData=chf16->lCustData;\r
-  chf32w->lpfnHook=NULL;\r
-  chf32w->hInstance=HINSTANCE_32(chf16->hInstance);\r
-  chf32w->lpszStyle=MapSL(chf16->lpszStyle);\r
-  chf32w->nFontType=chf16->nFontType;\r
-  chf32w->nSizeMax=chf16->nSizeMax;\r
-  chf32w->nSizeMin=chf16->nSizeMin;\r
-  FONT_LogFont16To32W(MapSL(chf16->lpLogFont), chf32w->lpLogFont);\r
-};\r
-\r
-/***********************************************************************\r
- *                          CFn_HookCallChk                 [internal]\r
- */\r
-static BOOL CFn_HookCallChk(LPCHOOSEFONT16 lpcf)\r
-{\r
- if (lpcf)\r
-  if(lpcf->Flags & CF_ENABLEHOOK)\r
-   if (lpcf->lpfnHook)\r
-    return TRUE;\r
- return FALSE;\r
-}\r
-\r
-/***********************************************************************\r
- *                FontFamilyEnumProc                     (COMMDLG.19)\r
- */\r
-INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,\r
-                                   UINT16 nFontType, LPARAM lParam )\r
-{\r
-  HWND hwnd=HWND_32(LOWORD(lParam));\r
-  HWND hDlg=GetParent(hwnd);\r
-  LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongPtrW(hDlg, DWLP_USER);\r
-  LOGFONT16 *lplf = MapSL( logfont );\r
-  TEXTMETRIC16 *lpmtrx16 = MapSL(metrics);\r
-  ENUMLOGFONTEXW elf32w;\r
-  NEWTEXTMETRICEXW nmtrx32w;\r
-  FONT_LogFont16To32W(lplf, &(elf32w.elfLogFont));\r
-  FONT_Metrics16To32W(lpmtrx16, &nmtrx32w);\r
-  return AddFontFamily(&elf32w, &nmtrx32w, nFontType,\r
-          (LPCHOOSEFONTW)lpcf->lpTemplateName, hwnd,NULL);\r
-}\r
-\r
-/***********************************************************************\r
- *                 FontStyleEnumProc                     (COMMDLG.18)\r
- */\r
-INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,\r
-                                  UINT16 nFontType, LPARAM lParam )\r
-{\r
-  HWND hcmb2=HWND_32(LOWORD(lParam));\r
-  HWND hcmb3=HWND_32(HIWORD(lParam));\r
-  HWND hDlg=GetParent(hcmb3);\r
-  LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongPtrW(hDlg, DWLP_USER);\r
-  LOGFONT16 *lplf = MapSL(logfont);\r
-  TEXTMETRIC16 *lpmtrx16 = MapSL(metrics);\r
-  ENUMLOGFONTEXW elf32w;\r
-  NEWTEXTMETRICEXW nmtrx32w;\r
-  FONT_LogFont16To32W(lplf, &(elf32w.elfLogFont));\r
-  FONT_Metrics16To32W(lpmtrx16, &nmtrx32w);\r
-  return AddFontStyle(&elf32w, &nmtrx32w, nFontType,\r
-          (LPCHOOSEFONTW)lpcf->lpTemplateName, hcmb2, hcmb3, hDlg, TRUE);\r
-}\r
-\r
-/***********************************************************************\r
- *                        ChooseFont   (COMMDLG.15)\r
- */\r
-BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)\r
-{\r
-    HINSTANCE16 hInst;\r
-    HANDLE16 hDlgTmpl16 = 0, hResource16 = 0;\r
-    HGLOBAL16 hGlobal16 = 0;\r
-    BOOL16 bRet = FALSE;\r
-    LPCVOID template;\r
-    FARPROC16 ptr;\r
-    CHOOSEFONTW cf32w;\r
-    LOGFONTW lf32w;\r
-    LOGFONT16 *font16;\r
-    SEGPTR lpTemplateName;\r
-\r
-    cf32w.lpLogFont=&lf32w;\r
-    CFn_CHOOSEFONT16to32W(lpChFont, &cf32w);\r
-\r
-    TRACE("ChooseFont\n");\r
-    if (!lpChFont) return FALSE;\r
-\r
-    if (TRACE_ON(commdlg))\r
-       _dump_cf_flags(lpChFont->Flags);\r
-\r
-    if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)\r
-    {\r
-        if (!(template = LockResource16( lpChFont->hInstance )))\r
-        {\r
-            COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);\r
-            return FALSE;\r
-        }\r
-    }\r
-    else if (lpChFont->Flags & CF_ENABLETEMPLATE)\r
-    {\r
-        HANDLE16 hResInfo;\r
-        if (!(hResInfo = FindResource16( lpChFont->hInstance,\r
-                                         MapSL(lpChFont->lpTemplateName),\r
-                                         (LPSTR)RT_DIALOG)))\r
-        {\r
-            COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);\r
-            return FALSE;\r
-        }\r
-        if (!(hDlgTmpl16 = LoadResource16( lpChFont->hInstance, hResInfo )) ||\r
-            !(template = LockResource16( hDlgTmpl16 )))\r
-        {\r
-            COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);\r
-            return FALSE;\r
-        }\r
-    }\r
-    else\r
-    {\r
-       HRSRC hResInfo;\r
-       HGLOBAL hDlgTmpl32;\r
-        LPCVOID template32;\r
-        DWORD size;\r
-        if (!(hResInfo = FindResourceA(COMDLG32_hInstance, "CHOOSE_FONT", (LPSTR)RT_DIALOG)))\r
-        {\r
-            COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);\r
-            return FALSE;\r
-        }\r
-        if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo)) ||\r
-            !(template32 = LockResource(hDlgTmpl32)))\r
-        {\r
-            COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);\r
-            return FALSE;\r
-        }\r
-        size = SizeofResource(COMDLG32_hInstance, hResInfo);\r
-        hGlobal16 = GlobalAlloc16(0, size);\r
-        if (!hGlobal16)\r
-        {\r
-            COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);\r
-            ERR("alloc failure for %ld bytes\n", size);\r
-            return FALSE;\r
-        }\r
-        template = GlobalLock16(hGlobal16);\r
-        if (!template)\r
-        {\r
-            COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);\r
-            ERR("global lock failure for %x handle\n", hGlobal16);\r
-            GlobalFree16(hGlobal16);\r
-            return FALSE;\r
-        }\r
-        ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);\r
-        hDlgTmpl16 = hGlobal16;\r
-\r
-    }\r
-\r
-    /* lpTemplateName is not used in the dialog */\r
-    lpTemplateName=lpChFont->lpTemplateName;\r
-    lpChFont->lpTemplateName=(SEGPTR)&cf32w;\r
-\r
-    ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 16);\r
-    hInst = GetWindowLongPtrA(HWND_32(lpChFont->hwndOwner), GWLP_HINSTANCE);\r
-    bRet = DialogBoxIndirectParam16(hInst, hDlgTmpl16, lpChFont->hwndOwner,\r
-                     (DLGPROC16) ptr, (DWORD)lpChFont);\r
-    if (hResource16) FreeResource16(hDlgTmpl16);\r
-    if (hGlobal16)\r
-    {\r
-        GlobalUnlock16(hGlobal16);\r
-        GlobalFree16(hGlobal16);\r
-    }\r
-    lpChFont->lpTemplateName=lpTemplateName;\r
-\r
-    lpChFont->iPointSize = cf32w.iPointSize;\r
-    lpChFont->Flags = cf32w.Flags;\r
-    lpChFont->rgbColors = cf32w.rgbColors;\r
-    lpChFont->lCustData = cf32w.lCustData;\r
-    lpChFont->nFontType = cf32w.nFontType;\r
-\r
-    font16 = MapSL(lpChFont->lpLogFont);\r
-    font16->lfHeight = cf32w.lpLogFont->lfHeight;\r
-    font16->lfWidth = cf32w.lpLogFont->lfWidth;\r
-    font16->lfEscapement = cf32w.lpLogFont->lfEscapement;\r
-    font16->lfOrientation = cf32w.lpLogFont->lfOrientation;\r
-    font16->lfWeight = cf32w.lpLogFont->lfWeight;\r
-    font16->lfItalic = cf32w.lpLogFont->lfItalic;\r
-    font16->lfUnderline = cf32w.lpLogFont->lfUnderline;\r
-    font16->lfStrikeOut = cf32w.lpLogFont->lfStrikeOut;\r
-    font16->lfCharSet = cf32w.lpLogFont->lfCharSet;\r
-    font16->lfOutPrecision = cf32w.lpLogFont->lfOutPrecision;\r
-    font16->lfClipPrecision = cf32w.lpLogFont->lfClipPrecision;\r
-    font16->lfQuality = cf32w.lpLogFont->lfQuality;\r
-    font16->lfPitchAndFamily = cf32w.lpLogFont->lfPitchAndFamily;\r
-    WideCharToMultiByte(CP_ACP, 0, cf32w.lpLogFont->lfFaceName,\r
-                          LF_FACESIZE, font16->lfFaceName, LF_FACESIZE, 0, 0);\r
-\r
-    HeapFree(GetProcessHeap(), 0, (LPBYTE)cf32w.lpTemplateName);\r
-    HeapFree(GetProcessHeap(), 0, cf32w.lpszStyle);\r
-\r
-    return bRet;\r
-}\r
-\r
-/***********************************************************************\r
- *           FormatCharDlgProc   (COMMDLG.16)\r
-             FIXME: 1. some strings are "hardcoded", but it's better load from sysres\r
-                    2. some CF_.. flags are not supported\r
-                    3. some TType extensions\r
- */\r
-BOOL16 CALLBACK FormatCharDlgProc16(HWND16 hDlg16, UINT16 message,\r
-                                  WPARAM16 wParam, LPARAM lParam)\r
-{\r
-  HWND hDlg = HWND_32(hDlg16);\r
-  LPCHOOSEFONT16 lpcf;\r
-  BOOL16 res=0;\r
-  if (message!=WM_INITDIALOG)\r
-  {\r
-   lpcf=(LPCHOOSEFONT16)GetWindowLongPtrW(hDlg, DWLP_USER);\r
-   if (!lpcf && message != WM_MEASUREITEM)\r
-      return FALSE;\r
-   if (CFn_HookCallChk(lpcf))\r
-     res=CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg16,message,wParam,lParam);\r
-   if (res)\r
-    return res;\r
-  }\r
-  else\r
-  {\r
-    lpcf=(LPCHOOSEFONT16)lParam;\r
-    if (!CFn_WMInitDialog(hDlg, wParam, lParam, (LPCHOOSEFONTW)lpcf->lpTemplateName))\r
-    {\r
-      TRACE("CFn_WMInitDialog returned FALSE\n");\r
-      return FALSE;\r
-    }\r
-    if (CFn_HookCallChk(lpcf))\r
-      return CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg16,WM_INITDIALOG,wParam,lParam);\r
-  }\r
-  switch (message)\r
-    {\r
-    case WM_MEASUREITEM:\r
-        {\r
-            MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);\r
-            MEASUREITEMSTRUCT mis;\r
-            mis.CtlType    = mis16->CtlType;\r
-            mis.CtlID      = mis16->CtlID;\r
-            mis.itemID     = mis16->itemID;\r
-            mis.itemWidth  = mis16->itemWidth;\r
-            mis.itemHeight = mis16->itemHeight;\r
-            mis.itemData   = mis16->itemData;\r
-            res = CFn_WMMeasureItem(hDlg, wParam, (LPARAM)&mis);\r
-            mis16->itemWidth  = (UINT16)mis.itemWidth;\r
-            mis16->itemHeight = (UINT16)mis.itemHeight;\r
-        }\r
-        break;\r
-    case WM_DRAWITEM:\r
-        {\r
-            DRAWITEMSTRUCT16* dis16 = MapSL(lParam);\r
-            DRAWITEMSTRUCT dis;\r
-            dis.CtlType       = dis16->CtlType;\r
-            dis.CtlID         = dis16->CtlID;\r
-            dis.itemID        = dis16->itemID;\r
-            dis.itemAction    = dis16->itemAction;\r
-            dis.itemState     = dis16->itemState;\r
-            dis.hwndItem      = HWND_32(dis16->hwndItem);\r
-            dis.hDC           = HDC_32(dis16->hDC);\r
-            dis.itemData      = dis16->itemData;\r
-            dis.rcItem.left   = dis16->rcItem.left;\r
-            dis.rcItem.top    = dis16->rcItem.top;\r
-            dis.rcItem.right  = dis16->rcItem.right;\r
-            dis.rcItem.bottom = dis16->rcItem.bottom;\r
-            res = CFn_WMDrawItem(hDlg, wParam, (LPARAM)&dis);\r
-        }\r
-        break;\r
-    case WM_COMMAND:\r
-        res=CFn_WMCommand(hDlg, MAKEWPARAM( wParam, HIWORD(lParam) ), LOWORD(lParam),\r
-                          (LPCHOOSEFONTW)lpcf->lpTemplateName);\r
-        break;\r
-    case WM_DESTROY:\r
-        return TRUE;\r
-    case WM_CHOOSEFONT_GETLOGFONT:\r
-        TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);\r
-        FIXME("current logfont back to caller\n");\r
-        break;\r
-    case WM_PAINT:\r
-        res= CFn_WMPaint(hDlg, wParam, lParam, (LPCHOOSEFONTW)lpcf->lpTemplateName);\r
-        break;\r
-    }\r
-  return res;\r
-}\r
+/*
+ * COMMDLG - Font Dialog
+ *
+ * Copyright 1994 Martin Ayotte
+ * Copyright 1996 Albrecht Kleine
+ *
+ * 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
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#include "windef.h"
+#include "winbase.h"
+#include "wingdi.h"
+#include "winuser.h"
+#include "winnls.h"
+#include "wine/winbase16.h"
+#include "wine/winuser16.h"
+#include "commdlg.h"
+#include "dlgs.h"
+#include "wine/debug.h"
+#include "cderr.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
+
+#include "cdlg.h"
+#include "cdlg16.h"
+
+static void FONT_LogFont16To32W( const LPLOGFONT16 font16, LPLOGFONTW font32 )
+{
+    font32->lfHeight = font16->lfHeight;
+    font32->lfWidth = font16->lfWidth;
+    font32->lfEscapement = font16->lfEscapement;
+    font32->lfOrientation = font16->lfOrientation;
+    font32->lfWeight = font16->lfWeight;
+    font32->lfItalic = font16->lfItalic;
+    font32->lfUnderline = font16->lfUnderline;
+    font32->lfStrikeOut = font16->lfStrikeOut;
+    font32->lfCharSet = font16->lfCharSet;
+    font32->lfOutPrecision = font16->lfOutPrecision;
+    font32->lfClipPrecision = font16->lfClipPrecision;
+    font32->lfQuality = font16->lfQuality;
+    font32->lfPitchAndFamily = font16->lfPitchAndFamily;
+    MultiByteToWideChar(CP_ACP, 0, font16->lfFaceName,
+                        LF_FACESIZE, font32->lfFaceName, LF_FACESIZE);
+};
+
+static void FONT_Metrics16To32W( const TEXTMETRIC16 *pm16,
+                                 NEWTEXTMETRICEXW *pnm32w)
+{
+    ZeroMemory( pnm32w, sizeof(NEWTEXTMETRICEXW));
+    /* NOTE: only the fields used by AddFontStyle() are filled in */
+    pnm32w->ntmTm.tmHeight = pm16->tmHeight;
+    pnm32w->ntmTm.tmExternalLeading = pm16->tmExternalLeading;
+};
+
+static void CFn_CHOOSEFONT16to32W(LPCHOOSEFONT16 chf16, LPCHOOSEFONTW chf32w)
+{
+  int len;
+  if(chf16->lpTemplateName)
+  {
+    len = MultiByteToWideChar(CP_ACP, 0, (LPBYTE)chf16->lpTemplateName, -1, NULL, 0);
+    chf32w->lpTemplateName = HeapAlloc(GetProcessHeap(), 0,len*sizeof(WCHAR));
+    MultiByteToWideChar(CP_ACP, 0, (LPSTR)MapSL(chf16->lpTemplateName),
+                        -1, (LPWSTR)chf32w->lpTemplateName, len);
+  }
+  if(chf16->lpszStyle)
+  {
+    len = MultiByteToWideChar(CP_ACP, 0, (LPBYTE)chf16->lpszStyle, -1, NULL, 0);
+    chf32w->lpszStyle = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
+    MultiByteToWideChar(CP_ACP, 0, (LPSTR)MapSL(chf16->lpTemplateName),
+                        -1, chf32w->lpszStyle, len);
+  }
+  chf32w->lStructSize=sizeof(CHOOSEFONTW);
+  chf32w->hwndOwner=HWND_32(chf16->hwndOwner);
+  chf32w->hDC=HDC_32(chf16->hDC);
+  chf32w->iPointSize=chf16->iPointSize;
+  chf32w->Flags=chf16->Flags;
+  chf32w->rgbColors=chf16->rgbColors;
+  chf32w->lCustData=chf16->lCustData;
+  chf32w->lpfnHook=NULL;
+  chf32w->hInstance=HINSTANCE_32(chf16->hInstance);
+  chf32w->lpszStyle=MapSL(chf16->lpszStyle);
+  chf32w->nFontType=chf16->nFontType;
+  chf32w->nSizeMax=chf16->nSizeMax;
+  chf32w->nSizeMin=chf16->nSizeMin;
+  FONT_LogFont16To32W(MapSL(chf16->lpLogFont), chf32w->lpLogFont);
+};
+
+/***********************************************************************
+ *                          CFn_HookCallChk                 [internal]
+ */
+static BOOL CFn_HookCallChk(LPCHOOSEFONT16 lpcf)
+{
+ if (lpcf)
+  if(lpcf->Flags & CF_ENABLEHOOK)
+   if (lpcf->lpfnHook)
+    return TRUE;
+ return FALSE;
+}
+
+/***********************************************************************
+ *                FontFamilyEnumProc                     (COMMDLG.19)
+ */
+INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
+                                   UINT16 nFontType, LPARAM lParam )
+{
+  HWND hwnd=HWND_32(LOWORD(lParam));
+  HWND hDlg=GetParent(hwnd);
+  LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongPtrW(hDlg, DWLP_USER);
+  LOGFONT16 *lplf = MapSL( logfont );
+  TEXTMETRIC16 *lpmtrx16 = MapSL(metrics);
+  ENUMLOGFONTEXW elf32w;
+  NEWTEXTMETRICEXW nmtrx32w;
+  FONT_LogFont16To32W(lplf, &(elf32w.elfLogFont));
+  FONT_Metrics16To32W(lpmtrx16, &nmtrx32w);
+  return AddFontFamily(&elf32w, &nmtrx32w, nFontType,
+          (LPCHOOSEFONTW)lpcf->lpTemplateName, hwnd,NULL);
+}
+
+/***********************************************************************
+ *                 FontStyleEnumProc                     (COMMDLG.18)
+ */
+INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
+                                  UINT16 nFontType, LPARAM lParam )
+{
+  HWND hcmb2=HWND_32(LOWORD(lParam));
+  HWND hcmb3=HWND_32(HIWORD(lParam));
+  HWND hDlg=GetParent(hcmb3);
+  LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongPtrW(hDlg, DWLP_USER);
+  LOGFONT16 *lplf = MapSL(logfont);
+  TEXTMETRIC16 *lpmtrx16 = MapSL(metrics);
+  ENUMLOGFONTEXW elf32w;
+  NEWTEXTMETRICEXW nmtrx32w;
+  FONT_LogFont16To32W(lplf, &(elf32w.elfLogFont));
+  FONT_Metrics16To32W(lpmtrx16, &nmtrx32w);
+  return AddFontStyle(&elf32w, &nmtrx32w, nFontType,
+          (LPCHOOSEFONTW)lpcf->lpTemplateName, hcmb2, hcmb3, hDlg, TRUE);
+}
+
+/***********************************************************************
+ *                        ChooseFont   (COMMDLG.15)
+ */
+BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
+{
+    HINSTANCE16 hInst;
+    HANDLE16 hDlgTmpl16 = 0, hResource16 = 0;
+    HGLOBAL16 hGlobal16 = 0;
+    BOOL16 bRet = FALSE;
+    LPCVOID template;
+    FARPROC16 ptr;
+    CHOOSEFONTW cf32w;
+    LOGFONTW lf32w;
+    LOGFONT16 *font16;
+    SEGPTR lpTemplateName;
+
+    cf32w.lpLogFont=&lf32w;
+    CFn_CHOOSEFONT16to32W(lpChFont, &cf32w);
+
+    TRACE("ChooseFont\n");
+    if (!lpChFont) return FALSE;
+
+    if (TRACE_ON(commdlg))
+       _dump_cf_flags(lpChFont->Flags);
+
+    if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
+    {
+        if (!(template = LockResource16( lpChFont->hInstance )))
+        {
+            COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
+            return FALSE;
+        }
+    }
+    else if (lpChFont->Flags & CF_ENABLETEMPLATE)
+    {
+        HANDLE16 hResInfo;
+        if (!(hResInfo = FindResource16( lpChFont->hInstance,
+                                         MapSL(lpChFont->lpTemplateName),
+                                         (LPSTR)RT_DIALOG)))
+        {
+            COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
+            return FALSE;
+        }
+        if (!(hDlgTmpl16 = LoadResource16( lpChFont->hInstance, hResInfo )) ||
+            !(template = LockResource16( hDlgTmpl16 )))
+        {
+            COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
+            return FALSE;
+        }
+    }
+    else
+    {
+       HRSRC hResInfo;
+       HGLOBAL hDlgTmpl32;
+        LPCVOID template32;
+        DWORD size;
+        if (!(hResInfo = FindResourceA(COMDLG32_hInstance, "CHOOSE_FONT", (LPSTR)RT_DIALOG)))
+        {
+            COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
+            return FALSE;
+        }
+        if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo)) ||
+            !(template32 = LockResource(hDlgTmpl32)))
+        {
+            COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
+            return FALSE;
+        }
+        size = SizeofResource(COMDLG32_hInstance, hResInfo);
+        hGlobal16 = GlobalAlloc16(0, size);
+        if (!hGlobal16)
+        {
+            COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
+            ERR("alloc failure for %ld bytes\n", size);
+            return FALSE;
+        }
+        template = GlobalLock16(hGlobal16);
+        if (!template)
+        {
+            COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
+            ERR("global lock failure for %x handle\n", hGlobal16);
+            GlobalFree16(hGlobal16);
+            return FALSE;
+        }
+        ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
+        hDlgTmpl16 = hGlobal16;
+
+    }
+
+    /* lpTemplateName is not used in the dialog */
+    lpTemplateName=lpChFont->lpTemplateName;
+    lpChFont->lpTemplateName=(SEGPTR)&cf32w;
+
+    ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 16);
+    hInst = GetWindowLongPtrA(HWND_32(lpChFont->hwndOwner), GWLP_HINSTANCE);
+    bRet = DialogBoxIndirectParam16(hInst, hDlgTmpl16, lpChFont->hwndOwner,
+                     (DLGPROC16) ptr, (DWORD)lpChFont);
+    if (hResource16) FreeResource16(hDlgTmpl16);
+    if (hGlobal16)
+    {
+        GlobalUnlock16(hGlobal16);
+        GlobalFree16(hGlobal16);
+    }
+    lpChFont->lpTemplateName=lpTemplateName;
+
+    lpChFont->iPointSize = cf32w.iPointSize;
+    lpChFont->Flags = cf32w.Flags;
+    lpChFont->rgbColors = cf32w.rgbColors;
+    lpChFont->lCustData = cf32w.lCustData;
+    lpChFont->nFontType = cf32w.nFontType;
+
+    font16 = MapSL(lpChFont->lpLogFont);
+    font16->lfHeight = cf32w.lpLogFont->lfHeight;
+    font16->lfWidth = cf32w.lpLogFont->lfWidth;
+    font16->lfEscapement = cf32w.lpLogFont->lfEscapement;
+    font16->lfOrientation = cf32w.lpLogFont->lfOrientation;
+    font16->lfWeight = cf32w.lpLogFont->lfWeight;
+    font16->lfItalic = cf32w.lpLogFont->lfItalic;
+    font16->lfUnderline = cf32w.lpLogFont->lfUnderline;
+    font16->lfStrikeOut = cf32w.lpLogFont->lfStrikeOut;
+    font16->lfCharSet = cf32w.lpLogFont->lfCharSet;
+    font16->lfOutPrecision = cf32w.lpLogFont->lfOutPrecision;
+    font16->lfClipPrecision = cf32w.lpLogFont->lfClipPrecision;
+    font16->lfQuality = cf32w.lpLogFont->lfQuality;
+    font16->lfPitchAndFamily = cf32w.lpLogFont->lfPitchAndFamily;
+    WideCharToMultiByte(CP_ACP, 0, cf32w.lpLogFont->lfFaceName,
+                          LF_FACESIZE, font16->lfFaceName, LF_FACESIZE, 0, 0);
+
+    HeapFree(GetProcessHeap(), 0, (LPBYTE)cf32w.lpTemplateName);
+    HeapFree(GetProcessHeap(), 0, cf32w.lpszStyle);
+
+    return bRet;
+}
+
+/***********************************************************************
+ *           FormatCharDlgProc   (COMMDLG.16)
+             FIXME: 1. some strings are "hardcoded", but it's better load from sysres
+                    2. some CF_.. flags are not supported
+                    3. some TType extensions
+ */
+BOOL16 CALLBACK FormatCharDlgProc16(HWND16 hDlg16, UINT16 message,
+                                  WPARAM16 wParam, LPARAM lParam)
+{
+  HWND hDlg = HWND_32(hDlg16);
+  LPCHOOSEFONT16 lpcf;
+  BOOL16 res=0;
+  if (message!=WM_INITDIALOG)
+  {
+   lpcf=(LPCHOOSEFONT16)GetWindowLongPtrW(hDlg, DWLP_USER);
+   if (!lpcf && message != WM_MEASUREITEM)
+      return FALSE;
+   if (CFn_HookCallChk(lpcf))
+     res=CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg16,message,wParam,lParam);
+   if (res)
+    return res;
+  }
+  else
+  {
+    lpcf=(LPCHOOSEFONT16)lParam;
+    if (!CFn_WMInitDialog(hDlg, wParam, lParam, (LPCHOOSEFONTW)lpcf->lpTemplateName))
+    {
+      TRACE("CFn_WMInitDialog returned FALSE\n");
+      return FALSE;
+    }
+    if (CFn_HookCallChk(lpcf))
+      return CallWindowProc16((WNDPROC16)lpcf->lpfnHook,hDlg16,WM_INITDIALOG,wParam,lParam);
+  }
+  switch (message)
+    {
+    case WM_MEASUREITEM:
+        {
+            MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
+            MEASUREITEMSTRUCT mis;
+            mis.CtlType    = mis16->CtlType;
+            mis.CtlID      = mis16->CtlID;
+            mis.itemID     = mis16->itemID;
+            mis.itemWidth  = mis16->itemWidth;
+            mis.itemHeight = mis16->itemHeight;
+            mis.itemData   = mis16->itemData;
+            res = CFn_WMMeasureItem(hDlg, wParam, (LPARAM)&mis);
+            mis16->itemWidth  = (UINT16)mis.itemWidth;
+            mis16->itemHeight = (UINT16)mis.itemHeight;
+        }
+        break;
+    case WM_DRAWITEM:
+        {
+            DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
+            DRAWITEMSTRUCT dis;
+            dis.CtlType       = dis16->CtlType;
+            dis.CtlID         = dis16->CtlID;
+            dis.itemID        = dis16->itemID;
+            dis.itemAction    = dis16->itemAction;
+            dis.itemState     = dis16->itemState;
+            dis.hwndItem      = HWND_32(dis16->hwndItem);
+            dis.hDC           = HDC_32(dis16->hDC);
+            dis.itemData      = dis16->itemData;
+            dis.rcItem.left   = dis16->rcItem.left;
+            dis.rcItem.top    = dis16->rcItem.top;
+            dis.rcItem.right  = dis16->rcItem.right;
+            dis.rcItem.bottom = dis16->rcItem.bottom;
+            res = CFn_WMDrawItem(hDlg, wParam, (LPARAM)&dis);
+        }
+        break;
+    case WM_COMMAND:
+        res=CFn_WMCommand(hDlg, MAKEWPARAM( wParam, HIWORD(lParam) ), LOWORD(lParam),
+                          (LPCHOOSEFONTW)lpcf->lpTemplateName);
+        break;
+    case WM_DESTROY:
+        return TRUE;
+    case WM_CHOOSEFONT_GETLOGFONT:
+        TRACE("WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
+        FIXME("current logfont back to caller\n");
+        break;
+    case WM_PAINT:
+        res= CFn_WMPaint(hDlg, wParam, lParam, (LPCHOOSEFONTW)lpcf->lpTemplateName);
+        break;
+    }
+  return res;
+}