home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DAYFIELD.ZIP / DAYSUBPR.C < prev    next >
C/C++ Source or Header  |  1989-07-31  |  11KB  |  292 lines

  1. /* ----------------------------------------------------------------------
  2. .context DaySubWinProc
  3. .category Day-Field-Windows
  4. MRESULT EXPENTRY DaySubWinProc ( HWND   hwnd,
  5.                                 USHORT msg,
  6.                                 MPARAM mp1,
  7.                                 MPARAM mp2 );
  8.  
  9. Description:
  10.      This procedure is the Window Procedure used to Subclass the
  11. WC_ENTRYFIELD window.
  12.  
  13. Parameter     Description
  14. -------------------------------------------------------------------------
  15. hwnd          A handle (32 bit) for the window to which the message is
  16.               addressed.
  17.  
  18. msg           A USHORT identifying the type of message that is being
  19.               received.
  20.  
  21. mp1           Message type specific 32 bit value.
  22.  
  23. mp2           Message type specific 32 bit value.
  24.  
  25.  
  26.  
  27. Returns:  
  28.      a MRESULT: a 32 bit pointer to a void data type
  29.  
  30. Comments: 
  31.      The DAYFIELD class is used to allow the user to enter Monday -
  32. Sunday in an entry field.  All other values are not allowed or cause
  33. the focus to shift to other windows.  This is done by subclassing the
  34. default WC_ENTRYFIELD window class and only passing the allowed WM_CHAR
  35. msgs. This procedure is the procedure that does the filtering of the
  36. WM_CHAR messages.
  37.  
  38. References: 
  39.      Charles Petzolds Programming the OS/2 Presentation Manager.
  40.  
  41. See Also: WinSubclassWindow
  42. .ref  WinSubclassWindow
  43.  
  44. Development History: 
  45.   Date         Programmer          Description of modification   
  46.   07/11/1989   Paul Montgomery     Initial development           
  47. -------------------------------------------------------------------- */
  48. #define INCL_PM
  49. #include <os2.h>
  50.  
  51. #include "day.h"
  52. #include "crmenu.h"
  53.  
  54. MRESULT EXPENTRY DaySubWinProc( HPS hwnd,
  55.                                USHORT msg,
  56.                                MPARAM mp1,
  57.                                MPARAM mp2 )
  58.    {
  59.    WNDPARAMS wp;
  60.    CHAR      buf[12];  // size of largest text + room for  '\0' and '~'
  61.    HWND      hMenu;
  62.    USHORT    item;
  63.    BOOL      move;
  64.    INT       i;
  65.    PFNWP     pfentry;
  66.    HWND      parent;
  67.    HMODULE   hmod;
  68.    RECTL     rc;
  69.  
  70.    pfentry = (PFNWP) WinQueryWindowULong(hwnd, QWL_USER); 
  71.    switch ( msg )
  72.       {
  73.       case WM_COMMAND:
  74.          if (COMMANDMSG(&msg)->source != CMDSRC_MENU)
  75.             {
  76.             return ((pfentry)(hwnd, msg, mp1, mp2));
  77.             }
  78.          // a message from the menu window
  79.          item = COMMANDMSG(&msg)->cmd;
  80.          hMenu = WinWindowFromID(hwnd,FID_MENU);
  81.  
  82.          // get the selected text
  83.          WinSendMsg(hMenu, MM_QUERYITEMTEXT,
  84.                     MPFROM2SHORT(item, (USHORT)sizeof(buf)), (MPARAM)buf);
  85.          
  86.          // get rid of the '~' if there is one
  87.          move == FALSE;
  88.          for (i=0;i < (sizeof(buf) - 1);i++)
  89.             {
  90.             if ((buf[i] == '~') || (move == TRUE))
  91.                {
  92.                // move all of the rest of the characters to the left one
  93.                buf[i] = buf[i+1];
  94.                move = TRUE;
  95.                }
  96.             }
  97.  
  98.          // set the WC_ENTRYFIELD to the value from the menu
  99.          wp.fsStatus = WPM_CCHTEXT | WPM_TEXT;
  100.          wp.cchText = sizeof(buf);
  101.          wp.pszText = buf;
  102.          ((pfentry)(hwnd, WM_SETWINDOWPARAMS,
  103.                           (MPARAM) &wp, 0));
  104.  
  105.          // move the focus to the next window,  This really only works
  106.          // in the case of this window being used in a Dialog Box
  107.          WinSetFocus ( HWND_DESKTOP,
  108.             WinEnumDlgItem ( WinQueryWindow( hwnd,QW_OWNER,FALSE),
  109.                              hwnd,
  110.                              EDI_NEXTTABITEM, FALSE ));
  111.          return TRUE;
  112.          break;
  113.  
  114.       case WM_CHAR:
  115.          if (CHARMSG(&msg)->fs & KC_VIRTUALKEY)
  116.             {
  117.             switch (CHARMSG(&msg)->vkey)
  118.                {
  119.                case VK_BACKTAB:
  120.                case VK_UP:
  121.                case VK_LEFT:
  122.                   if (!(CHARMSG(&msg)->fs & KC_KEYUP))
  123.                      {
  124.                      WinSetFocus ( HWND_DESKTOP,
  125.                         WinEnumDlgItem ( WinQueryWindow( hwnd,QW_OWNER,FALSE),
  126.                               hwnd,
  127.                               EDI_PREVTABITEM, FALSE ));
  128.                      }
  129.                   return 0L;
  130.                   break;
  131.                case VK_TAB:
  132.                case VK_DOWN:
  133.                case VK_RIGHT:
  134.                   if (!(CHARMSG(&msg)->fs & KC_KEYUP))
  135.                      {
  136.                      WinSetFocus ( HWND_DESKTOP,
  137.                         WinEnumDlgItem ( WinQueryWindow( hwnd,QW_OWNER,FALSE),
  138.                               hwnd,
  139.                               EDI_NEXTTABITEM, FALSE ));
  140.                      }
  141.                   return 0L;
  142.                   break;
  143.                case VK_BACKSPACE:
  144.                case VK_SPACE:
  145.                   break;
  146.                default:
  147.                   return ((pfentry)(hwnd, msg, mp1, mp2));
  148.                }
  149.             }
  150.          if (CHARMSG(&msg)->fs & KC_CHAR)
  151.             {
  152.             switch (CHARMSG(&msg)->chr)
  153.                {
  154.                case '\x008':
  155.                   // on a backspace clear out the entire text
  156.                   buf[0] = '\0';
  157.                   wp.fsStatus = WPM_CCHTEXT | WPM_TEXT;
  158.                   wp.cchText = sizeof(buf);
  159.                   wp.pszText = buf;
  160.                   return ((pfentry)(hwnd, WM_SETWINDOWPARAMS,
  161.                                     (MPARAM) &wp, 0));
  162.                   break;
  163.  
  164.                case 'M':
  165.                case 'm':
  166.                case '1':
  167.                   WinSetFocus ( HWND_DESKTOP,
  168.                         WinEnumDlgItem ( WinQueryWindow( hwnd,QW_OWNER,FALSE),
  169.                               hwnd,
  170.                               EDI_NEXTTABITEM, FALSE ));
  171.                   strcpy(buf,"MONDAY");
  172.                   wp.fsStatus = WPM_CCHTEXT | WPM_TEXT;
  173.                   wp.cchText = sizeof(buf);
  174.                   wp.pszText = buf;
  175.                   return ((pfentry)(hwnd, WM_SETWINDOWPARAMS,
  176.                                     (MPARAM) &wp, 0));
  177.                   break;
  178.  
  179.                case 'T':
  180.                case 't':
  181.                case '2':
  182.                   WinSetFocus ( HWND_DESKTOP,
  183.                         WinEnumDlgItem ( WinQueryWindow( hwnd,QW_OWNER,FALSE),
  184.                               hwnd,
  185.                               EDI_NEXTTABITEM, FALSE ));
  186.                   strcpy(buf,"TUESDAY");
  187.                   wp.fsStatus = WPM_CCHTEXT | WPM_TEXT;
  188.                   wp.cchText = sizeof(buf);
  189.                   wp.pszText = buf;
  190.                   return ((pfentry)(hwnd, WM_SETWINDOWPARAMS,
  191.                                     (MPARAM) &wp, 0));
  192.                   break;
  193.  
  194.                case 'W':
  195.                case 'w':
  196.                case '3':
  197.                   WinSetFocus ( HWND_DESKTOP,
  198.                         WinEnumDlgItem ( WinQueryWindow( hwnd,QW_OWNER,FALSE),
  199.                               hwnd,
  200.                               EDI_NEXTTABITEM, FALSE ));
  201.                   strcpy(buf,"WEDNESDAY");
  202.                   wp.fsStatus = WPM_CCHTEXT | WPM_TEXT;
  203.                   wp.cchText = sizeof(buf);
  204.                   wp.pszText = buf;
  205.                   return ((pfentry)(hwnd, WM_SETWINDOWPARAMS,
  206.                                     (MPARAM) &wp, 0));
  207.                   break;
  208.  
  209.                case 'H':
  210.                case 'h':
  211.                case '4':
  212.                   WinSetFocus ( HWND_DESKTOP,
  213.                         WinEnumDlgItem ( WinQueryWindow( hwnd,QW_OWNER,FALSE),
  214.                               hwnd,
  215.                               EDI_NEXTTABITEM, FALSE ));
  216.                   strcpy(buf,"THURSDAY");
  217.                   wp.fsStatus = WPM_CCHTEXT | WPM_TEXT;
  218.                   wp.cchText = sizeof(buf);
  219.                   wp.pszText = buf;
  220.                   return ((pfentry)(hwnd, WM_SETWINDOWPARAMS,
  221.                                     (MPARAM) &wp, 0));
  222.                   break;
  223.  
  224.                case 'F':
  225.                case 'f':
  226.                case '5':
  227.                   WinSetFocus ( HWND_DESKTOP,
  228.                         WinEnumDlgItem ( WinQueryWindow( hwnd,QW_OWNER,FALSE),
  229.                               hwnd,
  230.                               EDI_NEXTTABITEM, FALSE ));
  231.                   strcpy(buf,"FRIDAY");
  232.                   wp.fsStatus = WPM_CCHTEXT | WPM_TEXT;
  233.                   wp.cchText = sizeof(buf);
  234.                   wp.pszText = buf;
  235.                   return ((pfentry)(hwnd, WM_SETWINDOWPARAMS,
  236.                                     (MPARAM) &wp, 0));
  237.                   break;
  238.  
  239.                case 'S':
  240.                case 's':
  241.                case '6':
  242.                   WinSetFocus ( HWND_DESKTOP,
  243.                         WinEnumDlgItem ( WinQueryWindow( hwnd,QW_OWNER,FALSE),
  244.                               hwnd,
  245.                               EDI_NEXTTABITEM, FALSE ));
  246.                   strcpy(buf,"SATURDAY");
  247.                   wp.fsStatus = WPM_CCHTEXT | WPM_TEXT;
  248.                   wp.cchText = sizeof(buf);
  249.                   wp.pszText = buf;
  250.                   return ((pfentry)(hwnd, WM_SETWINDOWPARAMS,
  251.                                     (MPARAM) &wp, 0));
  252.                   break;
  253.  
  254.                case 'U':
  255.                case 'u':
  256.                case '7':
  257.                case '0':
  258.                   WinSetFocus ( HWND_DESKTOP,
  259.                         WinEnumDlgItem ( WinQueryWindow( hwnd,QW_OWNER,FALSE),
  260.                               hwnd,
  261.                               EDI_NEXTTABITEM, FALSE ));
  262.                   strcpy(buf,"SUNDAY");
  263.                   wp.fsStatus = WPM_CCHTEXT | WPM_TEXT;
  264.                   wp.cchText = sizeof(buf);
  265.                   wp.pszText = buf;
  266.                   return ((pfentry)(hwnd, WM_SETWINDOWPARAMS,
  267.                                     (MPARAM) &wp, 0));
  268.                   break;
  269.  
  270.                default:
  271.                   parent = WinQueryWindow(hwnd, QW_PARENT, FALSE );
  272.                   hmod = (HMODULE)WinQueryWindowULong(parent,DAYHMOD_OFFSET);
  273.                   WinQueryWindowRect(hwnd, &rc);
  274.                   CreateMenu(hwnd, hmod, 100, rc.xRight, rc.yTop);
  275.                   DosBeep(600,40);
  276.                   return TRUE;
  277.                }
  278.             }
  279.          else
  280.             {
  281.             return ((pfentry)(hwnd, msg, mp1, mp2));
  282.             }
  283.          break;
  284.  
  285.       default:
  286.          return ((pfentry)(hwnd, msg, mp1, mp2));
  287.       }
  288.    return 0L;
  289.    }
  290.  
  291.  
  292.