home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / formef.zip / FORMATEF.C < prev    next >
C/C++ Source or Header  |  1994-06-08  |  24KB  |  774 lines

  1. #define INCL_DOS
  2. #define INCL_PM
  3. #include <os2.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <memory.h>
  8.  
  9.  
  10. #include "GpfUC.h"
  11. static UCHAR PictureMask[81];
  12.  
  13. #include "FormatEF.h"
  14. #include "FEFProgs.h"
  15.  
  16.   /**********************************************/
  17.   /**** F O R W A R D    D E F I N I T I O N S ***/
  18.   /**********************************************/
  19.  
  20. static void fillstar(PWINBLK win) ;
  21. static SHORT processChar(SHORT ch,PWINBLK win) ;
  22. static SHORT remwaste(PUCHAR buf,PSYNGROUP desc) ;
  23. static void fillfirst(PWINBLK win) ;
  24. static SHORT createdesc(PUCHAR patt) ;
  25. static PSYNGROUP creategroup(USHORT descQ,GROUPTYPE type,
  26.                  SHORT min,SHORT max,UCHAR code);
  27. static EFSTATE snapStatus(PWINBLK win) ;
  28. int searchg(GROUPTYPE type,PSYNGROUP patt ,SHORT oldn,UCHAR ch) ;
  29.  
  30.   /**********************************************/
  31.   /******** S T A T I C  D A T A ****************/
  32.   /**********************************************/
  33.  
  34. UCHAR dateAm[] = "##/##/####";
  35. PUCHAR    datprt[3] = {dateAm,"##-##-####","####.##.##"};
  36. PUCHAR    txtptr[10] = {
  37.          dateAm,
  38.          "##.##",
  39.          "(###)###-####",
  40.          "$********#.#*",
  41.         "#####-****",
  42.         "###-##-####",
  43.         "-*****#",
  44.         "-*******#.#******",
  45.         "-*******#.*******E-**",
  46.         PictureMask};
  47. unsigned char buf[MFEFMAXLEN];
  48.  
  49. SYNGROUP desc [40];
  50.  
  51.   /**********************************************/
  52.   /************* C O D E S **********************/
  53.   /**********************************************/
  54.  
  55.  
  56. static void getstate(PWINBLK win,EFSTATE err,PUCHAR buf) {
  57.    ULONG minmax;
  58.    win->state = err;
  59.    strcpy (win->buf,buf);
  60.    minmax = (ULONG) WinSendMsg(win->hwnd, EM_QUERYSEL,
  61.                    MPFROMP(NULL),MPFROMP(NULL));
  62.    win->min = (SHORT)minmax;
  63.    win->max = (SHORT)(minmax >> 16);
  64.    win->first = (SHORT) WinSendMsg(win->hwnd, EM_QUERYFIRSTCHAR,
  65.                    MPFROMP(NULL),MPFROMP(NULL));
  66.  
  67. }
  68.  
  69. static void setstate(PWINBLK win) {
  70.    WinSetWindowText(win->hwnd, win->buf);
  71.    WinSendMsg(win->hwnd, EM_SETSEL,
  72.           MPFROM2SHORT(win->min,win->max),MPFROMP(NULL));
  73.    WinSendMsg(win->hwnd, EM_SETFIRSTCHAR,
  74.           MPFROMP(win->first),MPFROMP(NULL));
  75.  
  76. }
  77.  
  78. static EFSTATE snapStatus(PWINBLK win) {
  79.    EFSTATE err;
  80.    SHORT  changepos = -1;
  81.    WinQueryWindowText(win->hwnd, sizeof(buf), buf);
  82.    err = SynErr(buf,win->desc,win->state);
  83.    if( err >= win->state ) {
  84.       if(win->state == INIT_S) {
  85.      changepos = remwaste(buf,win->desc);
  86.       }
  87.       getstate(win,err,buf);
  88.       if( win->min == win->max && changepos >= 0 && changepos < win->min) {
  89.      if(win->min>0) win->min --;
  90.      if(win->max>0) win->max --;
  91.       }
  92.       if(changepos >= 0) {
  93.      setstate(win);
  94.       }
  95.    } else setstate(win);
  96.    return err;
  97. }
  98.  
  99. int searchg(GROUPTYPE type,SYNGROUP patt [],SHORT oldn,UCHAR ch) {
  100.    SHORT newn;
  101.    SYNGROUP pat;
  102.    SHORT found = 0;
  103.    for(newn = oldn + 1 ;  ; newn ++) {
  104.       pat = patt[ newn ];
  105.       if( (pat.type != SEPAR_T && pat.type == type ) ||
  106.       (pat.type == SEPAR_T && pat.code == ch   )   ) {
  107.      found = 1;
  108.      patt[newn].digcnt = 1;
  109.      patt[newn].blcnt = 0;
  110.      break;
  111.       }
  112.       if(pat.min > 0 ) break; // not skip an important group
  113.       patt[newn].digcnt = 0;
  114.       patt[newn].blcnt = 0;
  115.    }
  116.    if( found ) return newn;
  117.    else return -1;
  118. }
  119.  
  120. EFSTATE SynErr( PUCHAR buf, PSYNGROUP patt, EFSTATE state) {
  121.    SHORT pos;      // pos number in buf
  122.    BOOL errfound;
  123.    BOOL indg;    // 'in-digit-group' status
  124.    SHORT digcnt;  // digit count
  125.    SHORT blcnt;   // blank count
  126.    UCHAR ch;
  127.    SHORT groupn;
  128.    SHORT groupnn;
  129.    BOOL chdigit;
  130.    groupn = -1;
  131.    errfound = 0;
  132.    indg = 0;
  133.    pos = 0;
  134.    do {
  135.       ch=buf[pos++];
  136.       chdigit = ch >= '0' && ch <= '9';
  137.       if( state == INIT_S && ch == ' ' ) chdigit = TRUE;
  138.       if( chdigit ) {
  139.      if(indg) {
  140.         if(ch != ' ')digcnt ++;
  141.         else blcnt ++;
  142.      } else {// dig & !indg
  143.         groupnn = searchg(DIGIT_T,patt,groupn,ch);
  144.         if(groupnn < 0 ) {
  145.            errfound = 3;
  146.         }
  147.         else { // dig &!indg &DIGIT found
  148.            groupn = groupnn;
  149.            digcnt = blcnt = 0;
  150.            if(ch != ' ')digcnt = 1;
  151.            else blcnt = 1;
  152.            indg = 1;
  153.         }
  154.      }
  155.       } else { // not digit
  156.      if(indg) {
  157.         patt[groupn].digcnt = digcnt;
  158.         patt[groupn].blcnt = blcnt;
  159.         indg = 0;
  160.      }
  161.      switch(ch) {
  162.         case '+':
  163.         case '-': // SIGN
  164.            groupnn = searchg(SIGN_T,patt,groupn,ch);
  165.            if(groupnn < 0 ) { errfound = 5; }
  166.            else { groupn = groupnn; }
  167.            break;
  168.         case 'E':
  169.         case 'e': // EXP
  170.            groupnn = searchg(EXP_T,patt,groupn,ch);
  171.            if(groupnn < 0 ) { errfound = 7; }
  172.            else { groupn = groupnn; }
  173.            break;
  174.         default :
  175.            groupnn = searchg(SEPAR_T,patt,groupn,ch);
  176.            if(groupnn < 0 ) { errfound = 8; }
  177.            else { groupn = groupnn; }
  178.            break;
  179.      }// end of switch
  180.       }// end of not digit
  181.       if(errfound) break;
  182.    }while(ch); // end of do-while
  183.    if(errfound) return ERROR_S; // struct error
  184.    /*********** syntax test *************/
  185.    for(groupn = 0;    ;groupn++) {
  186.       if(patt[groupn].type   == DIGIT_T       &&
  187.     (patt[groupn].digcnt >    patt[groupn].max ||
  188.      patt[groupn].digcnt <    patt[groupn].min)) {
  189.         errfound = TRUE;
  190.         break;
  191.       }
  192.       if(patt[groupn].type == SEPAR_T && patt[groupn].code ==0) break;
  193.    }
  194.    if(errfound) return INIT_S; // DIGIT error
  195.    /*********** range test *************/
  196.    // if(!rangeErr(buf)) return RANGEGOOD_S;
  197.    // else
  198.    return SYNGOOD_S;
  199. }// end of SYNTAX function
  200.  
  201. static PSYNGROUP creategroup(USHORT descQ,GROUPTYPE type,SHORT min,SHORT max,UCHAR code){
  202.    PSYNGROUP d = &desc[descQ];
  203.    d->type = type;
  204.    d->code = code;
  205.    d->min = min;
  206.    d->max = max;
  207.    return d;
  208. }
  209.  
  210. static SHORT createdesc(PUCHAR patt) {
  211.    SHORT pos;
  212.    SHORT descN;
  213.    SHORT descQ;
  214.    UCHAR ch;
  215.    BOOL indg;
  216.    PSYNGROUP d;
  217.    indg = FALSE;
  218.    descQ = 0;
  219.  
  220.    for(pos = 0;   ;pos ++) {
  221.       ch = patt[pos];
  222.       switch(ch) {
  223.      case '#':
  224.      case '*':
  225.         if(!indg ) d = creategroup(descQ++,DIGIT_T,0,0,0);
  226.         indg = TRUE;
  227.         d->max ++;
  228.         if(ch =='#') d->min ++;
  229.         break;
  230.      case ',':
  231.         indg = FALSE;
  232.         if(indg) d->code = ',';
  233.         else d = creategroup(descQ++,SEPAR_T,1,1,ch);
  234.         break;
  235.      case 'E':
  236.      case 'e':
  237.         indg = FALSE;
  238.         d = creategroup(descQ++,EXP_T,1,1,ch);
  239.         break;
  240.      case '+':
  241.      case '-':
  242.         indg = FALSE;
  243.         d = creategroup(descQ++,SIGN_T,ch=='+'?1:0,1,ch);
  244.         break;
  245.      default:
  246.         indg = FALSE;
  247.         d = creategroup(descQ++,SEPAR_T,1,1,ch);
  248.         break;
  249.       }
  250.       if(ch == 0) break;
  251.    }// end of for
  252.    for(descN = 1 ; descN < descQ - 1 ; descN ++ ) {
  253.       if(desc[descN  ].type == SIGN_T  &&
  254.      desc[descN-1].type == DIGIT_T &&
  255.      desc[descN+1].type == DIGIT_T     ) {
  256.         desc[descN].min = desc[descN].max = 1;
  257.         desc[descN].type = SEPAR_T;
  258.       }
  259.    }
  260.    return descQ;
  261. }
  262.  
  263. static void fillfirst(PWINBLK win) {
  264.    PUCHAR buf = win->buf;
  265.    PSYNGROUP desc= win->desc;
  266.    PSYNGROUP gr;
  267.    BOOL firstposfound = FALSE;
  268.    SHORT i;
  269.    SHORT pos;
  270.    for(pos = 0, gr = desc ;    ; gr++) {
  271.       switch(gr->type) {
  272.      case DIGIT_T:
  273.         if(!firstposfound) {
  274.            firstposfound = TRUE;
  275.            win->min = win->max = pos;
  276.         }
  277.         for(i=0; i<gr->min; i++ ) buf[pos++] = ' ';
  278.         break;
  279.      default:
  280.         if(gr->min > 0) buf[pos++] = gr->code;
  281.         break;
  282.       }// end of switch
  283.    if(gr->type == SEPAR_T && gr->code == 0) break;
  284.    }// end of for
  285. }
  286.  
  287. static SHORT remwaste(PUCHAR buf,PSYNGROUP desc) { // is called only after Syn
  288.    SHORT pos,pos1;
  289.    PSYNGROUP gr;
  290.    SHORT origlen;
  291.    BOOL changed = FALSE;
  292.    SHORT fstpos;
  293.    SHORT delcnt;
  294.    SHORT i;
  295.    UCHAR ch;
  296.    pos = pos1 = 0;
  297.    for( gr = desc ;    ; gr++ ) {
  298.       origlen = gr->blcnt+gr->digcnt;
  299.       if(gr->blcnt && origlen > gr->min) {
  300.      if(gr->blcnt <= origlen - gr->min) delcnt = gr->blcnt;
  301.      else delcnt = origlen - gr->min;
  302.       } else delcnt = 0;
  303.       // if(delcnt) changed = TRUE;
  304.       gr->blcnt -= delcnt;
  305.       for( i = 0; i < origlen ; i++ ) {
  306.      if( (ch = buf[pos++]) == ' ' && delcnt >0) {
  307.         delcnt --;
  308.         if(!changed) {
  309.            changed = TRUE;
  310.            fstpos = pos - 1;
  311.         }
  312.      }
  313.      else buf[pos1++] = ch;
  314.       }
  315.    if(gr->type == SEPAR_T && gr->code == 0) break;
  316.    }// end of for
  317.    return changed?fstpos:-1;
  318. }
  319.  
  320. static void fillstar(PWINBLK win) {
  321.    SHORT pos;
  322.    PSYNGROUP gr;
  323.    SHORT origlen;
  324.    SHORT i;
  325.    UCHAR gapcode;
  326.    pos = 0;
  327.    if(win->state != INIT_S ) {
  328.       return;
  329.    } else {
  330.       strcpy(win->starbuf,win->buf);
  331.    }
  332.    SynErr(win->starbuf,win->desc,INIT_S);
  333.    for( gr = win->desc ;    ; gr++ ) {
  334.       origlen = gr->blcnt+gr->digcnt;
  335.       if( gr->type != DIGIT_T ||
  336.      (gr->digcnt >= gr->min &&  gr->digcnt <= gr->max) ) {
  337.      pos += origlen;
  338.       } else {
  339.      if( gr->digcnt < gr->min ) gapcode = '#';
  340.      else gapcode = '*';
  341.      for(i = 0 ; i < origlen ; i ++ ) win->starbuf[pos++] = gapcode;
  342.       }
  343.       if(gr->type == SEPAR_T && gr->code == 0) break;
  344.    }// end of for
  345.    WinSetWindowText(win->hwnd,win->starbuf);
  346. }
  347.  
  348. static SHORT processChar(SHORT ch,PWINBLK win) {
  349.    SHORT endofgr,pos,grouplen,offs;
  350.    BOOL found;
  351.    PSYNGROUP gr;
  352.    if (win->min != win->max) return FALSE; // if it is not an insert mode
  353.    if (ch < 0x20 || ch > 0xFE) return FALSE; // control codes
  354.    pos = 0;
  355.    found = FALSE;
  356.    for( gr = win->desc ;    ; gr++ ) {
  357.       grouplen = gr->blcnt+gr->digcnt;
  358.       if(pos+grouplen >= win->min) {
  359.      found = TRUE;
  360.      break;
  361.       } else {
  362.      pos += grouplen;
  363.       }
  364.       if(gr->type == SEPAR_T && gr->code == 0) break;
  365.    }// end of for
  366.    if(!found) return FALSE;
  367.    // pos - begin of group
  368.    endofgr = pos+grouplen == win->min;
  369.    if(gr->type != DIGIT_T) return FALSE;
  370.    if(!endofgr) {
  371.       if(ch >'9' || ch < '0') return TRUE; // ignore alfa inside dig.group
  372.       if(gr->digcnt >= gr->max) return TRUE; // ignore the group ovrflw
  373.       else return FALSE;
  374.    } else { // !!! it is between groups & Dig.gr at left
  375.       if(ch <='9' && ch >= '0') {
  376.      if( gr->digcnt < gr->max) return FALSE;// additional digit
  377.      // find next dig group ,if not full, change cursor and FALSE
  378.      for(offs=0,gr++;gr->type != SEPAR_T || gr->code !=0;
  379.                        offs+=gr->digcnt+gr->blcnt,gr++) {
  380.         if(gr->type == DIGIT_T ) {
  381.            if(gr->digcnt >= gr->max) return TRUE; // ignore the group ovrflw
  382.            win->min+=offs;          // change cursor
  383.            win->max+=offs;
  384.            setstate(win);
  385.            return FALSE; // insert to new group
  386.         }
  387.      }
  388.      return TRUE; // ignore, next dig group does not exist
  389.       } else { // ch isn't a digit
  390.      if( gr[1].type != SEPAR_T) return FALSE;
  391.      if( ch == (SHORT)gr[1].code) {
  392.         win->min++;        // change cursor
  393.         win->max++;
  394.         setstate(win);
  395.      }
  396.      return TRUE; // ignore always
  397.       }
  398.    }
  399. }
  400.  
  401.  
  402.  
  403.  
  404.  
  405. #define EXTRAWORDS (4 * sizeof(PVOID))    /* Extra window words          */
  406.  
  407. static LONG  Style;
  408. static PFNWP pfnEditWndProc;
  409. static SHORT ExtraOffset;
  410.  
  411. typedef struct
  412.      {
  413.        SHORT    Reserved;
  414.        UCHAR    PictureMask[1];         /* Undefine Length    */
  415.      } EFCB;
  416.  
  417. /**********************************************************************/
  418. /*                                      */
  419. /* Structure Control Data                          */
  420. /*                                      */
  421. /**********************************************************************/
  422. typedef struct
  423.      {
  424.        SHORT    Length;
  425.        UCHAR    Data[1];            /* Undefine Length    */
  426.      } CTLDATA;
  427.  
  428. /**********************************************************************/
  429. /*                                      */
  430. /* STATIC Function prototypes for private C functions              */
  431. /*                                      */
  432. /**********************************************************************/
  433.  
  434. PUCC    EXPENTRY RegisterFormatEF(  VOID );
  435. MRESULT EXPENTRY fnwpFormatEF(
  436.          HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  437.  
  438. LONG    EXPENTRY ExtendedFormatEF(  LONG WsStyle , CTLDATA *pCtlData);
  439. MRESULT EXPENTRY fnwpExtendedFormatEF(
  440.          HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  441.  
  442. /**********************************************************************/
  443. /*                                      */
  444. /*   PRIVATE FUNCTION: RegisterFormatEF                   */
  445. /*                                      */
  446. /**********************************************************************/
  447.  
  448. PUCC EXPENTRY RegisterFormatEF( VOID )
  449.  {
  450.   HAB    hab;
  451.   CLASSINFO ClassInfo;
  452.   LONG    flClassStyle;
  453.   static UCC Ucc;
  454.  
  455.   hab = WinInitialize(0);
  456.   WinQueryClassInfo(hab, WC_ENTRYFIELD, (PCLASSINFO)&ClassInfo);
  457.   pfnEditWndProc = ClassInfo.pfnWindowProc;
  458.   flClassStyle = ClassInfo.flClassStyle;  /* Class style          */
  459.   flClassStyle &= ~CS_PUBLIC;          /* Reset Public Flag          */
  460.   ExtraOffset = ClassInfo.cbWindowData;   /* Extra window words       */
  461.  
  462.   /********************************************************************/
  463.   /*   Register the window class "FormatEF".                  */
  464.   /********************************************************************/
  465.   WinRegisterClass(              /* Register window class    */
  466.       hab,                  /* Anchor block handle      */
  467.       "FORMATEF",              /* Window class name (Upper)*/
  468.       (PFNWP)fnwpFormatEF,             /* Address window procedure */
  469.       flClassStyle,           /* Class style          */
  470.       ClassInfo.cbWindowData+4      /* Extra window words       */
  471.       );
  472.   Ucc.Capability = GPF_CAPS_WS_GROUP   |  /* Accept WS_GROUP Style    */
  473.            GPF_CAPS_WS_TABSTOP |  /* Accept WS_TABSTOP Style  */
  474.            GPF_CAPS_TEXT       |  /* Accept TEXT          */
  475.            GPF_CAPS_ACTION     |  /* Accept ACTION          */
  476.            GPF_CAPS_EXTENDED   |  /* Accept EXTENDED          */
  477.            GPF_CAPS_ASSOCIATE  |  /* Accept ASSOCIATE          */
  478.            GPF_CAPS_PRESPARAMS |  /* Accept PresParams          */
  479.            GPF_ALIAS_ENTRYFLD;      /* ENTRY FIELD          */
  480.   Ucc.WsStyle     = WS_VISIBLE | WS_TABSTOP | ES_MARGIN | ES_AUTOSCROLL;
  481.   Ucc.Cx     = 64;
  482.   Ucc.Cy     = 12;
  483.   return (&Ucc);
  484.  }
  485. /**********************************************************************/
  486. /*                                      */
  487. /*  WinProc: fnwpFormatEF                          */
  488. /*                                      */
  489. /*  Controls the "FormatEF"  Area.                      */
  490. /*                                      */
  491. /*                                      */
  492. /**********************************************************************/
  493.  
  494. MRESULT EXPENTRY fnwpFormatEF(
  495.          HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  496. {
  497.   // CHAR Key;
  498.   SHORT descQ;
  499.   PCREATESTRUCT pCrst;
  500.   PWINBLK win;
  501. // EFCB    *pEfcb;
  502.   MRESULT result;
  503.   CTLDATA *pCtlData;
  504.   SHORT flags;
  505.   SHORT ch;
  506.   SHORT vk;
  507.   SHORT   Length;
  508.  
  509.   /*******************************************************************/
  510.   /* Initialize Win  Parameters                     */
  511.   /*******************************************************************/
  512.   win = (PWINBLK) WinQueryWindowULong(hwnd,ExtraOffset);
  513.  
  514.   switch(msg)
  515.   {
  516.     /**************************************************************/
  517.     /* The application has asked for the window to be created.    */
  518.     /**************************************************************/
  519.    case WM_CREATE:
  520.     pCrst     = (PCREATESTRUCT) PVOIDFROMMP (mp2);
  521.     pCtlData = (CTLDATA*) pCrst->pCtlData;
  522.     if (pCtlData) {
  523.        if(pCtlData->Length) {
  524.           memcpy(PictureMask,pCtlData->Data,pCtlData->Length-1);
  525.           PictureMask[pCtlData->Length-1] = 0;
  526.           descQ = createdesc(PictureMask);
  527.           Length = sizeof(WINBLK);
  528.           DosAllocMem((PVOID*)&win,Length,PAG_READ|PAG_WRITE|PAG_COMMIT);        /* Getmain       */
  529.           memset(win,0,sizeof(WINBLK));        /* Clear Area  */
  530.           win->hwnd = hwnd;
  531.           win->state = INIT_S;
  532.           win->insertmode = TRUE;
  533.           Length = sizeof(SYNGROUP) * descQ;
  534.           DosAllocMem((PVOID*)&win->desc,Length,PAG_READ|PAG_WRITE|PAG_COMMIT);      /* Getmain     */
  535.           memcpy(win->desc,desc,Length);
  536.        } else {
  537.           win = NULL;
  538.        }
  539.     } else {                     /* no pict. mask */
  540.        win = NULL;
  541.     }
  542.     pCrst->pCtlData = NULL;  /* Reset CtlData for real EntryField */
  543.     WinSetWindowPtr(hwnd,ExtraOffset,win);
  544.     if(win) {
  545.        fillfirst(win);
  546.        WinSendMsg( hwnd,EM_SETINSERTMODE,MPFROMSHORT(TRUE),0L);
  547.        setstate(win);
  548.     }
  549.     return pfnEditWndProc( hwnd, msg, NULL, mp2 );
  550.  
  551.     /**************************************************************/
  552.     /* The application has asked for the window to be destroyed.  */
  553.     /**************************************************************/
  554.    case WM_DESTROY:
  555.     if(win == NULL) return pfnEditWndProc( hwnd, msg, NULL, mp2 );
  556.     WinSetWindowULong(hwnd,ExtraOffset,(ULONG)NULL);
  557.     DosFreeMem(win->desc);
  558.     DosFreeMem(win);
  559.     return pfnEditWndProc( hwnd, msg, mp1, mp2 );
  560.  
  561.     /**************************************************************/
  562.     /* Process Char                           */
  563.     /**************************************************************/
  564.     case WM_CHAR:
  565.      if(win == NULL) return pfnEditWndProc( hwnd, msg, NULL, mp2 );
  566.      if(win->star)     return pfnEditWndProc( hwnd, msg, NULL, mp2 );
  567.      flags = SHORT1FROMMP(mp1);
  568.      ch = SHORT1FROMMP(mp2);
  569.      vk = SHORT2FROMMP(mp2);
  570.  
  571.      if((flags & (KC_CHAR | KC_VIRTUALKEY)) && !(flags & KC_KEYUP) ) {
  572.         snapStatus(win);
  573.         if( flags & KC_CHAR) {
  574.            if( processChar(ch,win) )
  575.           return FALSE;
  576.         }
  577.         result = pfnEditWndProc( hwnd, msg, mp1, mp2 );
  578.         if(vk != VK_DOWN&&vk!=VK_UP&&vk!=VK_TAB&&vk!=VK_BACKTAB)
  579.            snapStatus(win);
  580.         return result;
  581.  
  582.      }
  583.      return pfnEditWndProc( hwnd, msg, mp1, mp2 );
  584.  
  585.     /**************************************************************/
  586.     /* Process FocusChange                             */
  587.     /**************************************************************/
  588.     case WM_FOCUSCHANGE:
  589.      if(win == NULL) return pfnEditWndProc( hwnd, msg, NULL, mp2 );
  590.      if((BOOL)SHORT1FROMMP(mp2)) { // focus is received
  591.         win->star = FALSE;
  592.         WinSendMsg( hwnd,EM_SETINSERTMODE,MPFROMSHORT(win->insertmode),0L);
  593.         if(win->insertmode) win->max = win->min;
  594.         else win->max = win->min + 1;
  595.         setstate(win);
  596.      } else {               // focus is losted
  597.         win->star = TRUE;
  598.         win->insertmode = (BOOL)WinSendMsg( hwnd,EM_SETINSERTMODE,MPFROMSHORT(TRUE),0L);
  599.         fillstar(win);
  600.      }
  601.     return pfnEditWndProc( hwnd, msg, mp1, mp2 );
  602.     /**************************************************************/
  603.     /* All other messages are passed to the default procedure.    */
  604.     /**************************************************************/
  605.    default:
  606.     /* Pass all other messages to the default window procedure    */
  607.     return pfnEditWndProc( hwnd, msg, mp1, mp2 );
  608.   }
  609. }
  610. /**********************************************************************/
  611. /*                                      */
  612. /*   PRIVATE FUNCTION: ExtendedFormatEF                   */
  613. /*                                      */
  614. /**********************************************************************/
  615.  
  616. LONG  EXPENTRY ExtendedFormatEF(  LONG WsStyle , CTLDATA *pCtlData)
  617.  {
  618.   HWND hwndActive;
  619.   HMODULE hmod;
  620.   UCHAR   Work[256];
  621.  
  622.   Style = WsStyle;    /* Set Local Style             */
  623.  
  624.   strncpy(PictureMask,pCtlData->Data,sizeof(PictureMask));
  625.   hwndActive = WinQueryActiveWindow( HWND_DESKTOP);
  626.  
  627.   DosLoadModule(Work,sizeof(Work),(PSZ)"FormatEF",&hmod);
  628.   /* Invoke a modal dialog with the main window frame as owner         */
  629.   WinDlgBox( HWND_DESKTOP,        /* Parent             */
  630.          hwndActive,        /* Owner             */
  631.          fnwpExtendedFormatEF,    /* Address of dialog proc    */
  632.          hmod,            /* Module handle         */
  633.          ID_FORMATEF,        /* ID of dialog in resource  */
  634.          NULL );            /* Initialization data         */
  635.  
  636.   pCtlData->Length = strlen(PictureMask)+1;
  637.   strcpy(pCtlData->Data,PictureMask);
  638.   return Style;
  639.  }
  640. /**********************************************************************/
  641. /*                                      */
  642. /*  WinProc: fnwpExtendedFormatEF                      */
  643. /*                                      */
  644. /*  Controls the "ExtendedFormatEF"  Area.                  */
  645. /*                                      */
  646. /*                                      */
  647. /**********************************************************************/
  648.  
  649. MRESULT EXPENTRY fnwpExtendedFormatEF(
  650.          HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  651. static SHORT oldarn;
  652. int arn,arnd;
  653.  
  654.   switch (msg)
  655.   {
  656.     case WM_INITDLG:
  657.       oldarn = 9; // ArOther
  658.       if (!(Style & (ES_CENTER | ES_RIGHT)) )
  659.      WinPostMsg( WinWindowFromID( hwnd, ID_LEFT ),
  660.              BM_SETCHECK,
  661.              MPFROM2SHORT( TRUE,0 ),
  662.              0L );
  663.       if ( (Style & ES_RIGHT) == ES_RIGHT )
  664.      WinPostMsg( WinWindowFromID( hwnd, ID_RIGHT ),
  665.              BM_SETCHECK,
  666.              MPFROM2SHORT( TRUE,0 ),
  667.              0L );
  668.       if ( (Style & ES_CENTER) == ES_CENTER )
  669.      WinPostMsg( WinWindowFromID( hwnd, ID_CENTER ),
  670.              BM_SETCHECK,
  671.              MPFROM2SHORT( TRUE,0 ),
  672.              0L );
  673.       if ( (Style & ES_MARGIN) == ES_MARGIN )
  674.      WinPostMsg( WinWindowFromID( hwnd, ID_MARGIN ),
  675.              BM_SETCHECK,
  676.              MPFROM2SHORT( TRUE,0 ),
  677.              0L );
  678.       if ( (Style & ES_AUTOSCROLL) == ES_AUTOSCROLL )
  679.      WinPostMsg( WinWindowFromID( hwnd, ID_AUTOSCROLL ),
  680.              BM_SETCHECK,
  681.              MPFROM2SHORT( TRUE,0 ),
  682.              0L );
  683.       WinSendDlgItemMsg( hwnd,
  684.              ID_PICTUREMASK,
  685.              EM_SETTEXTLIMIT,
  686.              MPFROMSHORT(sizeof(PictureMask)-1),
  687.              (MPARAM)NULL );
  688.       WinSetWindowText(WinWindowFromID(hwnd,ID_PICTUREMASK),PictureMask);
  689.       WinSendDlgItemMsg(hwnd,ID_AROTHER,BM_SETCHECK,
  690.       MPFROMSHORT(1),MPFROMP(NULL) );
  691.       WinEnableWindow(WinWindowFromID(hwnd,ID_EFMIN),FALSE );
  692.       WinEnableWindow(WinWindowFromID(hwnd,ID_TIME12),FALSE );
  693.       WinEnableWindow(WinWindowFromID(hwnd,ID_RANGE),FALSE );
  694.       WinEnableWindow(WinWindowFromID(hwnd,ID_EFMAX),FALSE );
  695.  
  696.       break;
  697.  
  698.     case WM_CONTROL:
  699.       switch( SHORT1FROMMP( mp1 ) ) { // ID_
  700.  
  701.           case ID_ARDATE:     // 0
  702.           case ID_ARTIME:     // 1
  703.           case ID_ARPHONE:     // 2
  704.           case ID_ARMONEY:     // 3
  705.           case ID_ARZIP:     // 4
  706.           case ID_ARSSN:     // 5
  707.           case ID_ARINT:     // 6
  708.           case ID_ARDEC:     // 7
  709.           case ID_AREXP:     // 8
  710.           case ID_AROTHER:     // 9
  711.           arn = (SHORT)WinSendDlgItemMsg(hwnd,ID_AROTHER,BM_QUERYCHECKINDEX,
  712.                  MPFROMP(NULL),MPFROMP(NULL) );
  713.           if( arn != oldarn ) {
  714.              oldarn = arn;
  715.              WinSendDlgItemMsg(hwnd,ID_PICTUREMASK,EM_SETREADONLY,
  716.                         MPFROMSHORT(arn != 9),MPFROMP(NULL) );
  717.              if(arn >= 0 && arn <= 9)
  718.             WinSetDlgItemText(hwnd,ID_PICTUREMASK,txtptr[arn]);
  719.           }
  720.           break;
  721.           case ID_DATEAM:
  722.           case ID_DATEEU:
  723.           case ID_DATEJA:
  724.       arnd = (SHORT)WinSendDlgItemMsg(hwnd,ID_DATEAM,BM_QUERYCHECKINDEX,
  725.                  MPFROMP(NULL),MPFROMP(NULL) );
  726.       if( arnd >= 0 && arnd <= 2) txtptr[0] = datprt[arnd];
  727.       arn = (SHORT)WinSendDlgItemMsg(hwnd,ID_AROTHER,BM_QUERYCHECKINDEX,
  728.              MPFROMP(NULL),MPFROMP(NULL) );
  729.       if(arn == 0 ) WinSetDlgItemText(hwnd,ID_PICTUREMASK,txtptr[arn]);
  730.           break;
  731.       } // end of switch ID_
  732.       break;
  733.  
  734.  
  735.     case WM_COMMAND:
  736.       switch( SHORT1FROMMP( mp1 ) )
  737.       {
  738.     case  ID_OK:    /* Enter key pressed or pushbutton selected  */
  739.     case DID_OK:    /* Enter key pressed or pushbutton selected  */
  740.       WinQueryWindowText(WinWindowFromID(hwnd,ID_PICTUREMASK),
  741.                  sizeof(PictureMask),
  742.                  PictureMask);
  743.       Style = 0;
  744.       if (SHORT1FROMMR( WinSendMsg( WinWindowFromID(hwnd,ID_RIGHT),
  745.                        BM_QUERYCHECK,0L,0L)))
  746.          Style  |= ES_RIGHT;
  747.       if (SHORT1FROMMR( WinSendMsg( WinWindowFromID(hwnd,ID_CENTER),
  748.                        BM_QUERYCHECK,0L,0L)))
  749.          Style  |= ES_CENTER;
  750.       if (SHORT1FROMMR( WinSendMsg( WinWindowFromID(hwnd,ID_MARGIN),
  751.                        BM_QUERYCHECK,0L,0L)))
  752.          Style  |= ES_MARGIN;
  753.       if (SHORT1FROMMR( WinSendMsg( WinWindowFromID(hwnd,ID_AUTOSCROLL),
  754.                        BM_QUERYCHECK,0L,0L)))
  755.          Style  |= ES_AUTOSCROLL;
  756.  
  757.       WinDismissDlg( hwnd, TRUE );      /* Finished with dialog box */
  758.       break;
  759.     case  ID_CANCEL: /* Escape key pressed or CANCEL pushbutton selected */
  760.     case DID_CANCEL: /* Escape key pressed or CANCEL pushbutton selected */
  761.       WinDismissDlg( hwnd, TRUE );      /* Finished with dialog box */
  762.       break;
  763.     default:
  764.       return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  765.       }
  766.       break;
  767.  
  768.     default:  /* Pass all other messages to the default dialog proc  */
  769.       return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  770.   }
  771.   return FALSE;
  772. }
  773.  
  774.