home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / SMF.ZIP / FATWND.C < prev    next >
C/C++ Source or Header  |  1990-05-21  |  11KB  |  276 lines

  1. /* code for the fattr dialog box,
  2.  *  and the char bundle dialog box.
  3.  *
  4.  * Both an Init procedure, and a window procedure.
  5.  */
  6.  
  7.  
  8.  
  9. #define INCL_WIN
  10. #define INCL_GPI
  11. #include <os2.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14.  
  15. #include "smf.h"
  16.  
  17. VOID    FattrInit(HWND hwnd)
  18. {
  19.      /* code to enumerate the entry fields.  (FATTRS window)
  20.       * for each one, set the presparms for a small font.
  21.       */
  22.     HENUM  heList;
  23.     HWND   hwndi;
  24.     CHAR    buffer[100];
  25.  
  26.     heList = WinBeginEnumWindows (hwnd);
  27.  
  28.     while (hwndi = WinGetNextWindow (heList) ) {
  29.         WinQueryClassName (hwndi, 100, buffer);
  30.         if ( (SHORT) atoi (&buffer[1]) == (SHORT) WC_ENTRYFIELD )
  31.             WinSetPresParam (hwndi, PP_FONTNAMESIZE,
  32.                 (ULONG)sizeof (szCourier), szCourier);
  33.     }
  34.  
  35.     WinEndEnumWindows (heList);
  36. }
  37.  
  38.  
  39. MRESULT EXPENTRY FattrWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  40. {
  41.     switch (msg)
  42.     {
  43.  
  44.     /* fontmetrics changed, selectively update fattrs window */
  45.     case WM_MAIN_FAT_CHANGE: {
  46.         FONTMETRICS *pfm;
  47.  
  48.         pfm = (PFONTMETRICS) mp1;
  49.         WinSetDlgItemShort (hwnd, F_lMatch, (USHORT) pfm->lMatch, FALSE);
  50.         WinSetDlgItemText (hwnd, F_szFacename, (PSZ) pfm->szFacename);
  51.  
  52.     } break;
  53.  
  54.     case WM_MAIN_CHB_FILLCHB:
  55.         if (hwnd == hwndCharbundle) {
  56.             HPS  hpsTest;
  57.  
  58.             hpsTest = (HPS) mp1;
  59.  
  60.             GpiQueryAttrs (hpsTest, PRIM_CHAR, flAttrsMask, &charbundle);
  61.  
  62.             WinSetDlgItemShort (hwnd, CB_lColor, (USHORT) charbundle.lColor, FALSE);
  63.             WinSetDlgItemShort (hwnd, CB_lBackColor, (USHORT) charbundle.lBackColor, FALSE);
  64.             WinSetDlgItemShort (hwnd, CB_usMixMode, (USHORT) charbundle.usMixMode, FALSE);
  65.             WinSetDlgItemShort (hwnd, CB_usBackMixMode, (USHORT) charbundle.usBackMixMode, FALSE);
  66.             WinSetDlgItemShort (hwnd, CB_usSet, (USHORT) charbundle.usSet, FALSE);
  67.             WinSetDlgItemShort (hwnd, CB_usPrecision, (USHORT) charbundle.usPrecision, FALSE);
  68.  
  69.             WinSetDlgItemShort (hwnd, CB_sizfxCell_X,
  70.                                 (USHORT) FIXEDINT(charbundle.sizfxCell.cx), FALSE);
  71.             WinSetDlgItemShort (hwnd, CB_sizfxCell_Y,
  72.                                 (USHORT) FIXEDINT(charbundle.sizfxCell.cy), FALSE);
  73.  
  74.             WinSetDlgItemShort (hwnd, CB_ptlAngle_X,
  75.                                 (USHORT) charbundle.ptlAngle.x, FALSE);
  76.             WinSetDlgItemShort (hwnd, CB_ptlAngle_Y,
  77.                                 (USHORT) charbundle.ptlAngle.y, FALSE);
  78.  
  79.             WinSetDlgItemShort (hwnd, CB_ptlShear_X,
  80.                                 (USHORT) charbundle.ptlShear.x, FALSE);
  81.             WinSetDlgItemShort (hwnd, CB_ptlShear_Y,
  82.                                 (USHORT) charbundle.ptlShear.y, FALSE);
  83.  
  84.             WinSetDlgItemShort (hwnd, CB_usDirection, (USHORT) charbundle.usDirection, FALSE);
  85.         }
  86.     break;
  87.  
  88.     case WM_MAIN_CHB_READ: {
  89.         USHORT      usTemp;
  90.         CHARBUNDLE  *pchb;
  91.         pchb = (CHARBUNDLE*) mp1;
  92.  
  93.         /* first bring the window to top & set focus for user */
  94.         WinSetWindowPos (hwnd, HWND_TOP, 0,0,0,0,
  95.               SWP_ZORDER | SWP_SHOW);
  96.         WinSetFocus (HWND_DESKTOP, hwnd);
  97.  
  98.         /* now pull each of the values off screen & put in structure */
  99.         if (!WinQueryDlgItemShort (hwnd, CB_lColor, &usTemp, FALSE)) {
  100.             WinMessageBox (hwndMain, hwndMain, "lColor must be a number",
  101.                 "CharBundle warning", 0, MB_ICONEXCLAMATION);
  102.             return (MRESULT) FALSE;
  103.         } else pchb->lColor = (LONG) usTemp;
  104.  
  105.         if (!WinQueryDlgItemShort (hwnd, CB_lBackColor, &usTemp, FALSE)) {
  106.             WinMessageBox (hwndMain, hwndMain, "lBAckColor must be a number",
  107.                 "CharBundle warning", 0, MB_ICONEXCLAMATION);
  108.             return (MRESULT) FALSE;
  109.         } else pchb->lBackColor = (LONG) usTemp;
  110.  
  111.         if (!WinQueryDlgItemShort (hwnd, CB_usMixMode, &usTemp, FALSE)) {
  112.             WinMessageBox (hwndMain, hwndMain, "usMixMode must be a number",
  113.                 "CharBundle warning", 0, MB_ICONEXCLAMATION);
  114.             return (MRESULT) FALSE;
  115.         } else pchb->usMixMode = usTemp;
  116.  
  117.         if (!WinQueryDlgItemShort (hwnd, CB_usBackMixMode, &usTemp, FALSE)) {
  118.             WinMessageBox (hwndMain, hwndMain, "usBackMixMode must be a number",
  119.                 "CharBundle warning", 0, MB_ICONEXCLAMATION);
  120.             return (MRESULT) FALSE;
  121.         } else pchb->usBackMixMode = usTemp;
  122.  
  123.         if (!WinQueryDlgItemShort (hwnd, CB_usSet, &usTemp, FALSE)) {
  124.             WinMessageBox (hwndMain, hwndMain, "usSet must be a number",
  125.                 "CharBundle warning", 0, MB_ICONEXCLAMATION);
  126.             return (MRESULT) FALSE;
  127.         } else pchb->usSet = usTemp;
  128.  
  129.         if (!WinQueryDlgItemShort (hwnd, CB_usPrecision, &usTemp, FALSE)) {
  130.             WinMessageBox (hwndMain, hwndMain, "usPrecision must be a number",
  131.                 "CharBundle warning", 0, MB_ICONEXCLAMATION);
  132.             return (MRESULT) FALSE;
  133.         } else pchb->usPrecision = usTemp;
  134.  
  135.         if (!WinQueryDlgItemShort (hwnd, CB_sizfxCell_X, &usTemp, TRUE)) {
  136.             WinMessageBox (hwndMain, hwndMain, "sizfxCell.x must be a number",
  137.                 "CharBundle warning", 0, MB_ICONEXCLAMATION);
  138.             return (MRESULT) FALSE;
  139.         } else pchb->sizfxCell.cx = MAKEFIXED (usTemp, 0);
  140.  
  141.         if (!WinQueryDlgItemShort (hwnd, CB_sizfxCell_Y, &usTemp, TRUE)) {
  142.             WinMessageBox (hwndMain, hwndMain, "sizfxCell.y must be a number",
  143.                 "CharBundle warning", 0, MB_ICONEXCLAMATION);
  144.             return (MRESULT) FALSE;
  145.         } else pchb->sizfxCell.cy = MAKEFIXED (usTemp, 0);
  146.  
  147.         if (!WinQueryDlgItemShort (hwnd, CB_ptlAngle_X, &usTemp, TRUE)) {
  148.             WinMessageBox (hwndMain, hwndMain, "ptlAngle.x must be a number",
  149.                 "CharBundle warning", 0, MB_ICONEXCLAMATION);
  150.             return (MRESULT) FALSE;
  151.         } else pchb->ptlAngle.x = (LONG)usTemp;
  152.  
  153.         if (!WinQueryDlgItemShort (hwnd, CB_ptlAngle_Y, &usTemp, TRUE)) {
  154.             WinMessageBox (hwndMain, hwndMain, "ptlAngle.y must be a number",
  155.                 "CharBundle warning", 0, MB_ICONEXCLAMATION);
  156.             return (MRESULT) FALSE;
  157.         } else pchb->ptlAngle.y = (LONG)usTemp;
  158.  
  159.         if (!WinQueryDlgItemShort (hwnd, CB_ptlShear_X, &usTemp, TRUE)) {
  160.             WinMessageBox (hwndMain, hwndMain, "ptlShear.x must be a number",
  161.                 "CharBundle warning", 0, MB_ICONEXCLAMATION);
  162.             return (MRESULT) FALSE;
  163.         } else pchb->ptlShear.x = (LONG)usTemp;
  164.  
  165.         if (!WinQueryDlgItemShort (hwnd, CB_ptlShear_Y, &usTemp, TRUE)) {
  166.             WinMessageBox (hwndMain, hwndMain, "ptlShear.y must be a number",
  167.                 "CharBundle warning", 0, MB_ICONEXCLAMATION);
  168.             return (MRESULT) FALSE;
  169.         } else pchb->ptlShear.y = (LONG)usTemp;
  170.  
  171.         if (!WinQueryDlgItemShort (hwnd, CB_usDirection, &usTemp, TRUE)) {
  172.             WinMessageBox (hwndMain, hwndMain, "usDirection must be a number",
  173.                 "CharBundle warning", 0, MB_ICONEXCLAMATION);
  174.             return (MRESULT) FALSE;
  175.         } else pchb->usDirection = usTemp;
  176.  
  177.         return TRUE;
  178.     } break;
  179.  
  180.  
  181.     /* pull out the values and fill up a fattr structure.
  182.      *  mp1 will be a pointer to the structure to be filled
  183.      */
  184.     case WM_MAIN_FAT_READ: {
  185.         SHORT       sTemp;
  186.         FATTRS      *pFattrs;
  187.  
  188.         /* first bring the fattr window to top & set focus for user */
  189.         WinSetWindowPos (hwndFattrs, HWND_TOP, 0,0,0,0,
  190.               SWP_ZORDER | SWP_SHOW);
  191.         WinSetFocus (HWND_DESKTOP, hwndFattrs);
  192.  
  193.  
  194.         pFattrs = (PFATTRS) mp1;
  195.  
  196.         pFattrs->usRecordLength = sizeof (FATTRS);
  197.         WinSetDlgItemShort (hwndFattrs, F_usRecordLength,
  198.                 (USHORT) (sizeof (FATTRS)), FALSE);
  199.  
  200.         if (!WinQueryDlgItemShort (hwndFattrs, F_fsSelection,
  201.                                    &(pFattrs->fsSelection), FALSE)) {
  202.             WinMessageBox (hwndMain, hwndMain, "fsSelection must be a number",
  203.                 "FATTRS warning", 0, MB_ICONEXCLAMATION);
  204.             return (MRESULT) FALSE;
  205.         }
  206.  
  207.         if (!WinQueryDlgItemShort (hwndFattrs, F_lMatch,
  208.                                    &sTemp, FALSE)) {
  209.             WinMessageBox (hwndMain, hwndMain, "lMatch must be a number",
  210.                 "FATTRS warning", 0, MB_ICONEXCLAMATION);
  211.             return (MRESULT) FALSE;
  212.         } else
  213.             pFattrs->lMatch = (LONG) sTemp;
  214.  
  215.         if (!WinQueryDlgItemShort (hwndFattrs, F_idRegistry,
  216.                                    &(pFattrs->idRegistry), FALSE)) {
  217.             WinMessageBox (hwndMain, hwndMain, "idRegistry must be a number",
  218.                 "FATTRS warning", 0, MB_ICONEXCLAMATION);
  219.             return (MRESULT) FALSE;
  220.         }
  221.  
  222.         if (!WinQueryDlgItemShort (hwndFattrs, F_usCodePage,
  223.                                    &(pFattrs->usCodePage), FALSE)) {
  224.             WinMessageBox (hwndMain, hwndMain, "usCodePage must be a number",
  225.                 "FATTRS warning", 0, MB_ICONEXCLAMATION);
  226.             return (MRESULT) FALSE;
  227.         }
  228.  
  229.         if (!WinQueryDlgItemText (hwndFattrs, F_szFacename,
  230.                                    FACESIZE, (pFattrs->szFacename))) {
  231.             WinMessageBox (hwndMain, hwndMain, "unable to read face name",
  232.                 "FATTRS warning", 0, MB_ICONEXCLAMATION);
  233.             return (MRESULT) FALSE;
  234.         }
  235.  
  236.         if (!WinQueryDlgItemShort (hwndFattrs, F_lMaxBaselineExt,
  237.                                    &sTemp, FALSE)) {
  238.             WinMessageBox (hwndMain, hwndMain, "lMaxBaselineExt must be a number",
  239.                 "FATTRS warning", 0, MB_ICONEXCLAMATION);
  240.             return (MRESULT) FALSE;
  241.         } else
  242.             pFattrs->lMaxBaselineExt = (LONG) sTemp;
  243.  
  244.         if (!WinQueryDlgItemShort (hwndFattrs, F_lAveCharWidth,
  245.                                    &sTemp, FALSE)) {
  246.             WinMessageBox (hwndMain, hwndMain, "lAveCharWidth must be a number",
  247.                 "FATTRS warning", 0, MB_ICONEXCLAMATION);
  248.             return (MRESULT) FALSE;
  249.         } else
  250.             pFattrs->lAveCharWidth = (LONG) sTemp;
  251.  
  252.         if (!WinQueryDlgItemShort (hwndFattrs, F_fsType,
  253.                                    &(pFattrs->fsType), FALSE)) {
  254.             WinMessageBox (hwndMain, hwndMain, "fsType must be a number",
  255.                 "FATTRS warning", 0, MB_ICONEXCLAMATION);
  256.             return (MRESULT) FALSE;
  257.         }
  258.  
  259.         if (!WinQueryDlgItemShort (hwndFattrs, F_fsFontUse,
  260.                                    &(pFattrs->fsFontUse), FALSE)) {
  261.             WinMessageBox (hwndMain, hwndMain, "fsFontUse must be a number",
  262.                 "FATTRS warning", 0, MB_ICONEXCLAMATION);
  263.             return (MRESULT) FALSE;
  264.         }
  265.  
  266.  
  267.         return (MRESULT) TRUE;
  268.     } break;
  269.  
  270.  
  271.  
  272.  
  273.     }
  274.     return WinDefDlgProc (hwnd, msg, mp1, mp2);
  275. }
  276.