home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dbcs.zip / FONTDLG.C < prev    next >
C/C++ Source or Header  |  1996-01-21  |  12KB  |  333 lines

  1. #pragma    title("DBCS Driver  --  Version 1  --  (FontDlg.C)")
  2. #pragma    subtitle("   Font Metrics Display - Interface Definitions")
  3.  
  4. #define    INCL_DEV           /* Include OS/2 Device Interface    */
  5. #define    INCL_DOS           /* Include OS/2 DOS Kernal        */
  6. #define    INCL_DOSERRORS           /* Include OS/2 DOS Errors        */
  7. #define    INCL_GPI           /* Include OS/2 PM GPI Interface    */
  8. #define    INCL_WIN           /* Include OS/2 PM Windows Interface    */
  9.  
  10. #pragma    info(noext)
  11.  
  12. #include <os2.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16.  
  17. #include "appdefs.h"
  18. #include "prnsetup.h"
  19.  
  20. /* This    module contains    the routine to display selected    font metric    */
  21. /* information.                                */
  22.  
  23. /* Filename:   FilePrn.C                        */
  24.  
  25. /*  Version:   3                            */
  26. /*  Created:   1996-01-19                        */
  27. /*  Revised:   1996-01-19                        */
  28.  
  29. /* Routines:   MRESULT EXPENTRY    FontMetricsDlgProc(HWND    hWnd,        */
  30. /*                           ULONG msg,        */
  31. /*                           MPARAM mp1,        */
  32. /*                           MPARAM mp2);        */
  33.  
  34. /************************************************************************/
  35. /************************************************************************/
  36. /************************************************************************/
  37. /* DISCLAIMER OF WARRANTIES:                        */
  38. /* -------------------------                        */
  39. /* The following [enclosed] code is sample code    created    by IBM        */
  40. /* Corporation and Prominare Inc.  This    sample code is not part    of any    */
  41. /* standard IBM    product    and is provided    to you solely for the purpose    */
  42. /* of assisting    you in the development of your applications.  The code    */
  43. /* is provided "AS IS",    without    warranty of any    kind.  Neither IBM nor    */
  44. /* Prominare shall be liable for any damages arising out of your    */
  45. /* use of the sample code, even    if they    have been advised of the    */
  46. /* possibility of such damages.                        */
  47. /************************************************************************/
  48. /************************************************************************/
  49. /************************************************************************/
  50. /*               D I S C L A I M E R                */
  51. /* This    code is    provided on an as is basis with    no implied support.    */
  52. /* It should be    considered freeware that cannot    be rebundled as        */
  53. /* part    of a larger "*ware" offering without our consent.        */
  54. /************************************************************************/
  55. /************************************************************************/
  56. /************************************************************************/
  57.  
  58. /* Copyright ╕ International Business Machines Corp., 1996.        */
  59. /* Copyright ╕ 1996  Prominare Inc.  All Rights    Reserved.        */
  60.  
  61. /* --------------------------------------------------------------------    */
  62.  
  63. static PFONTMETRICS pfmDisplay;       /* Font Metrics Pointer        */
  64.  
  65.  
  66. /************************************************************************/
  67. /*                                    */
  68. /*     Module Prototype    Definitions                    */
  69. /*                                    */
  70. /************************************************************************/
  71.  
  72. #pragma    subtitle("   Font Metrics Display - Dialog Procedure")
  73. #pragma    page( )
  74.  
  75. /* --- FontMetricsDlgProc ------------------------------ [ Public ] ---    */
  76. /*                                    */
  77. /*     This function is    used to    display    selected font metric info.    */
  78. /*                                    */
  79. /*     Upon Entry:                            */
  80. /*                                    */
  81. /*     HWND   hWnd; = Dialog Window Handle                */
  82. /*     ULONG  msg;  = PM Message                    */
  83. /*     MPARAM mp1;  = Message Parameter    1                */
  84. /*     MPARAM mp2;  = Message Parameter    2                */
  85. /*                                    */
  86. /*     Upon Exit:                            */
  87. /*                                    */
  88. /*     FontMetricsDlgProc = Message Handling Result            */
  89. /*                                    */
  90. /* --------------------------------------------------------------------    */
  91.  
  92. MRESULT    EXPENTRY FontMetricsDlgProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  93.  
  94. {
  95. CHAR  szFacename[128];           /* Font Facename Buffer        */
  96. CHAR  szInfo[256];           /* Info Buffer            */
  97. HDC   hDC;               /* Device Context Handle        */
  98. HPS   hPS;               /* Presentation Space Handle        */
  99. LONG  cFontsDisplay;           /* Fonts Count            */
  100. LONG  lFontsTotal = 0L;           /* Fonts Count            */
  101. LONG  lXDeviceRes;           /* x    Device Resolution        */
  102. LONG  lYDeviceRes;           /* y    Device Resolution        */
  103. PSZ   pszFacename;           /* Facename                */
  104. PSZ   pszSep;               /* Separator                */
  105. register INT i;               /* Loop Counter            */
  106.  
  107. switch ( msg )
  108.    {
  109.  
  110. /************************************************************************/
  111. /* Perform dialog initialization                    */
  112. /************************************************************************/
  113.  
  114.    case    WM_INITDLG :
  115.        if ( (hPS = WinGetScreenPS(HWND_DESKTOP)) != (HPS)NULL )
  116.        if (    (hDC = GpiQueryDevice(hPS)) != (HDC)NULL )
  117.            {
  118.            DevQueryCaps(hDC, CAPS_HORIZONTAL_FONT_RES, 1L, &lXDeviceRes);
  119.            DevQueryCaps(hDC, CAPS_VERTICAL_FONT_RES,   1L, &lYDeviceRes);
  120.  
  121.                /* Get the number of fonts for the face name    */
  122.                /* provided                    */
  123.  
  124.  
  125.                /* Get the number of fonts for the face name    */
  126.                /* provided                    */
  127.  
  128.            cFontsDisplay = GpiQueryFonts(hPS, QF_PUBLIC, (PSZ)NULL,    &lFontsTotal, sizeof(FONTMETRICS), (PFONTMETRICS)NULL);
  129.  
  130.                /* Allocate space for the font metrics for the    */
  131.                /* different font sizes and devices of the font    */
  132.  
  133.            DosAllocMem((PVOID)&pfmDisplay, (ULONG)(sizeof(FONTMETRICS) * cFontsDisplay), PAG_READ |    PAG_WRITE | PAG_COMMIT);
  134.  
  135.                /* Make a pointer for the memory    allocated for    */
  136.                /* the font metrics and get the font metrics for    */
  137.                /* the number of    fonts for the face name        */
  138.                /* provided                    */
  139.  
  140.            GpiQueryFonts(hPS, QF_PUBLIC, (PSZ)NULL,    &cFontsDisplay,    sizeof(FONTMETRICS), pfmDisplay);
  141.  
  142.                /* Release the presentation space acquired to    */
  143.                /* determine the    screen height and to get the    */
  144.                /* font metrics                    */
  145.  
  146.            WinReleasePS(hPS);
  147.  
  148.            WinSendDlgItemMsg(hWnd, CBX_FONT, LM_DELETEALL, 0L, 0L);
  149.  
  150.                /* Loop through the font    metrics    returned to    */
  151.                /* and place each of the    different font names    */
  152.                /* within the fonts combo box            */
  153.  
  154.            for ( i = 0; i <    (INT)cFontsDisplay; i++    )
  155.            if (    ((pfmDisplay[i].sXDeviceRes == (SHORT)lXDeviceRes) && (pfmDisplay[i].sYDeviceRes == (SHORT)lYDeviceRes)) ||
  156.             ((pfmDisplay[i].sXDeviceRes == 1000) &&    (pfmDisplay[i].sYDeviceRes == 1000)) )
  157.                {
  158.                if ( pfmDisplay[i].fsType & (FM_TYPE_FACETRUNC |    FM_TYPE_ATOMS) )
  159.                WinQueryAtomName(WinQuerySystemAtomTable( ),    (ULONG)pfmDisplay[i].FaceNameAtom, pszFacename = szFacename, 128UL);
  160.                else
  161.                pszFacename = pfmDisplay[i].szFacename;
  162.                WinSendDlgItemMsg(hWnd, CBX_FONT, LM_SETITEMHANDLE,
  163.                   MPFROMSHORT(WinSendDlgItemMsg(hWnd, CBX_FONT,    LM_INSERTITEM, MPFROMSHORT(LIT_END),
  164.                                 MPFROMP(pfmDisplay[i].szFacename))), MPFROMLONG(i));
  165.                }
  166.            }
  167.        CenterDlg(hWnd);
  168.        break;
  169.  
  170. /************************************************************************/
  171. /* Process control selections                        */
  172. /************************************************************************/
  173.  
  174.    case    WM_CONTROL :
  175.        switch (    SHORT2FROMMP(mp1) )
  176.        {
  177.                /* Process message combo    box entry selections    */
  178.  
  179.        case    CBN_LBSELECT :
  180.            switch (    SHORT1FROMMP(mp1) )
  181.            {
  182.            case    CBX_FONT :
  183.                if ( (i = (INT)LONGFROMMR(WinSendDlgItemMsg(hWnd, CBX_FONT, LM_QUERYSELECTION, 0L, 0L)))    != LIT_NONE )
  184.                {
  185.                i = (INT)LONGFROMMR(WinSendDlgItemMsg(hWnd, CBX_FONT, LM_QUERYITEMHANDLE, MPFROMSHORT(i), 0L));
  186.                if (    pfmDisplay[i].fsType & (FM_TYPE_FACETRUNC | FM_TYPE_ATOMS) )
  187.                    WinQueryAtomName(WinQuerySystemAtomTable( ), (ULONG)pfmDisplay[i].FamilyNameAtom, pszFacename = szFacename, 128UL);
  188.                else
  189.                    pszFacename = pfmDisplay[i].szFamilyname;
  190.  
  191.                WinSetDlgItemText(hWnd, ST_FAMILYNAME, pszFacename);
  192.  
  193.                if (    pfmDisplay[i].fsType & (FM_TYPE_FAMTRUNC | FM_TYPE_ATOMS) )
  194.                    WinQueryAtomName(WinQuerySystemAtomTable( ), (ULONG)pfmDisplay[i].FaceNameAtom, pszFacename = szFacename, 128UL);
  195.                else
  196.                    pszFacename = pfmDisplay[i].szFacename;
  197.                WinSetDlgItemText(hWnd, ST_FACENAME,    pszFacename);
  198.                WinSetDlgItemText(hWnd, ST_SIZE, _ltoa(pfmDisplay[i].sNominalPointSize / 10,    szInfo,    10));
  199.                szInfo[0] = (CHAR)0;
  200.                pszSep = "";
  201.                if (    pfmDisplay[i].fsType & FM_TYPE_FIXED )
  202.                    {
  203.                    strcat(szInfo, "Fixed");
  204.                    pszSep =    ", ";
  205.                    }
  206.                if (    pfmDisplay[i].fsType & FM_TYPE_LICENSED    )
  207.                    {
  208.                    strcat(strcat(szInfo, pszSep), "Licensed");
  209.                    pszSep =    ", ";
  210.                    }
  211.                if (    pfmDisplay[i].fsType & FM_TYPE_KERNING )
  212.                    {
  213.                    strcat(strcat(szInfo, pszSep), "Kerning");
  214.                    pszSep =    ", ";
  215.                    }
  216.                if (    pfmDisplay[i].fsType & FM_TYPE_64K )
  217.                    {
  218.                    strcat(strcat(szInfo, pszSep), "64K");
  219.                    pszSep =    ", ";
  220.                    }
  221.                if (    pfmDisplay[i].fsType & FM_TYPE_DBCS )
  222.                    {
  223.                    strcat(strcat(szInfo, pszSep), "DBCS");
  224.                    pszSep =    ", ";
  225.                    }
  226.                if (    pfmDisplay[i].fsType & FM_TYPE_MBCS )
  227.                    {
  228.                    strcat(strcat(szInfo, pszSep), "MBCS");
  229.                    pszSep =    ", ";
  230.                    }
  231.                if (    pfmDisplay[i].fsType & FM_TYPE_FACETRUNC )
  232.                    {
  233.                    strcat(strcat(szInfo, pszSep), "Facename truncated");
  234.                    pszSep =    ", ";
  235.                    }
  236.                if (    pfmDisplay[i].fsType & FM_TYPE_FAMTRUNC    )
  237.                    {
  238.                    strcat(strcat(szInfo, pszSep), "Family name truncated");
  239.                    pszSep =    ", ";
  240.                    }
  241.                if (    pfmDisplay[i].fsType & FM_TYPE_ATOMS )
  242.                    strcat(strcat(szInfo, pszSep), "Atoms");
  243.                WinSetDlgItemText(hWnd, ST_TYPE, szInfo);
  244.                szInfo[0] = (CHAR)0;
  245.                pszSep = "";
  246.                if (    pfmDisplay[i].fsDefn & FM_DEFN_OUTLINE )
  247.                    {
  248.                    strcat(szInfo, "Outline");
  249.                    pszSep =    ", ";
  250.                    }
  251.                if (    pfmDisplay[i].fsDefn & FM_DEFN_GENERIC )
  252.                    strcat(strcat(szInfo, pszSep), "Generic");
  253.                WinSetDlgItemText(hWnd, ST_DEFINITION, szInfo);
  254.                szInfo[0] = (CHAR)0;
  255.                pszSep = "";
  256.                if (    pfmDisplay[i].fsSelection & FM_SEL_ITALIC )
  257.                    {
  258.                    strcat(szInfo, "Italic");
  259.                    pszSep =    ", ";
  260.                    }
  261.                if (    pfmDisplay[i].fsSelection & FM_SEL_UNDERSCORE )
  262.                    {
  263.                    strcat(szInfo, "Underscore");
  264.                    pszSep =    ", ";
  265.                    }
  266.                if (    pfmDisplay[i].fsSelection & FM_SEL_NEGATIVE )
  267.                    {
  268.                    strcat(szInfo, "Negative");
  269.                    pszSep =    ", ";
  270.                    }
  271.                if (    pfmDisplay[i].fsSelection & FM_SEL_OUTLINE )
  272.                    {
  273.                    strcat(szInfo, "Outline");
  274.                    pszSep =    ", ";
  275.                    }
  276.                if (    pfmDisplay[i].fsSelection & FM_SEL_STRIKEOUT )
  277.                    {
  278.                    strcat(szInfo, "Strikeout");
  279.                    pszSep =    ", ";
  280.                    }
  281.                if (    pfmDisplay[i].fsSelection & FM_SEL_BOLD    )
  282.                    {
  283.                    strcat(szInfo, "Bold");
  284.                    pszSep =    ", ";
  285.                    }
  286.                if (    pfmDisplay[i].fsSelection & FM_SEL_ISO9241_TESTED )
  287.                    strcat(strcat(szInfo, pszSep), "ISO9241 tested");
  288.                WinSetDlgItemText(hWnd, ST_SELECTION, szInfo);
  289.                WinSetDlgItemShort(hWnd, ST_LMATCH, pfmDisplay[i].lMatch, FALSE);
  290.                }
  291.                break;
  292.            }
  293.        }
  294.        break;
  295.  
  296. /************************************************************************/
  297. /* Process push    button selections                    */
  298. /************************************************************************/
  299.  
  300.    case    WM_COMMAND :
  301.        switch (    SHORT1FROMMP(mp1) )
  302.        {
  303.        case    DID_OK :
  304.            if ( pfmDisplay )
  305.            DosFreeMem((PVOID)pfmDisplay);
  306.            WinDismissDlg(hWnd, TRUE);
  307.            break;
  308.  
  309.        case    DID_CANCEL :
  310.            if ( pfmDisplay )
  311.            DosFreeMem((PVOID)pfmDisplay);
  312.            WinDismissDlg(hWnd, FALSE);
  313.            break;
  314.        }
  315.        break;
  316.  
  317. /************************************************************************/
  318. /* Close requested, exit dialogue                    */
  319. /************************************************************************/
  320.  
  321.    case    WM_CLOSE :
  322.        if ( pfmDisplay )
  323.        DosFreeMem((PVOID)pfmDisplay);
  324.        WinDismissDlg(hWnd, FALSE);
  325.        break;
  326.  
  327.             /* Pass    through    unhandled messages        */
  328.    default :
  329.        return(WinDefDlgProc(hWnd, msg, mp1, mp2));
  330.    }
  331. return(0L);
  332. }
  333.