home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / os2 / timeserv / dialogs.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  33KB  |  1,005 lines

  1. /*static char *SCCSID = "@(#)dialogs.c  6.6 92/02/18";*/
  2. /*=========================================================================\
  3.  *                                                                         *
  4.  *       FILE:dialogs.c                                                    *
  5.  *                                                                         *
  6.  *       DESCRIPTION:    Dialog procedures for PM clock                    *
  7.  *                                                                         *
  8.  *                                                                         *
  9.  *                                                                         *
  10.  *      Copyright 1989, 1990, 1992, 1996 IBM Corp.                         *
  11.  *                                                                         *
  12.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is        *
  13.  *      sample code created by IBM Corporation. This sample code is not    *
  14.  *      part of any standard or IBM product and is provided to you solely  *
  15.  *      for  the purpose of assisting you in the development of your       *
  16.  *      applications.  The code is provided "AS IS", without               *
  17.  *      warranty of any kind.  IBM shall not be liable for any damages     *
  18.  *      arising out of your use of the sample code, even if they have been *
  19.  *      advised of the possibility of   such damages.                      *
  20.  *                                                                         *
  21.  *-------------------------------------------------------------------------*
  22.  *
  23.  *--------------------------------------------------------------
  24.  *
  25.  *  This source file contains the following functions:
  26.  *
  27.  *  ClkTicksDlgProc()
  28.  *  AlarmDialogsProc()
  29.  *  AboutBoxDialogProc()
  30.  *  SetAlarmField()
  31.  *  GetAlarmTime()
  32.  *  AlarmVScrolls()
  33.  *  EntryFieldSubProc()
  34.  *  AlarmSetTimer()
  35.  *  ClkColorsDlgProc()
  36. \*==============================================================*/
  37.  
  38. /*--------------------------------------------------------------*\
  39.  *  Include files, macros, defined constants, and externs
  40. \*--------------------------------------------------------------*/
  41.  
  42. #define INCL_WININPUT
  43. #define INCL_WINFRAMEMGR
  44. #define INCL_WINTRACKRECT
  45. #define INCL_WINMENUS
  46. #define INCL_WINSYS
  47. #define INCL_WINTIMER
  48. #define INCL_WINMESSAGEMGR
  49. #define INCL_WINDIALOGS
  50. #define INCL_WINBUTTONS
  51. #define INCL_WINENTRYFIELDS
  52. #define INCL_WINWINDOWMGR
  53. #define INCL_WINSCROLLBARS
  54. #define INCL_GPITRANSFORMS
  55. #define INCL_GPIPRIMITIVES
  56. #define INCL_GPILOGCOLORTABLE
  57. #define INCL_DOSSEMAPHORES
  58. #define INCL_DOSDATETIME
  59.  
  60. #include <os2.h>
  61. #include <time.h>
  62. #include <stdio.h>
  63. #include <stdlib.h>
  64. #include <string.h>
  65. #include "clock.h"
  66. #include "res.h"
  67. #include "clkdata.h"
  68. /*--------------------------------------------------------------*\
  69.  *  Global variables  and definitions for this file
  70. \*--------------------------------------------------------------*/
  71.  
  72. /*--------------------------------------------------------------*\
  73.  *  Entry point declarations
  74. \*--------------------------------------------------------------*/
  75.  
  76. VOID InitAlarm    (HWND);
  77. VOID AlarmSet     (HWND);
  78. VOID SetAlarmField(HWND, UCHAR, UCHAR);
  79. VOID GetAlarmTime (HWND, UCHAR *, UCHAR *);
  80. VOID AlarmVScrolls(HWND, USHORT, MPARAM);
  81. VOID AlarmSetTimer(UCHAR uchHour, UCHAR uchMinutes);
  82.  
  83. MRESULT EXPENTRY AlarmDlgProc(HWND hwnd, ULONG usItem, MPARAM mp1, MPARAM mp2);
  84. MRESULT EXPENTRY EntryFieldSubProc(HWND hwnd, ULONG usItem, MPARAM mp1, MPARAM mp2);
  85.  
  86. /**************************************************************************\
  87. *                                                                          *
  88. *       ROUTINE:    ClkTicksDlgProc ( )                                    *
  89. *                                                                          *
  90. *       COMMENT:    "Ticks..." dialog                                      *
  91. *                                                                          *
  92. *       RETURNS:    MRESULT, 0 or return value from WinDefDlgProc          *
  93. *                                                                          *
  94. \**************************************************************************/
  95. MRESULT EXPENTRY ClkTicksDlgProc(HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2)
  96. {
  97.    static USHORT usMajorTickSel;
  98.    static USHORT usMinorTickSel;
  99.  
  100.    switch (usMsg)
  101.    {
  102.    case WM_INITDLG:
  103.  
  104.       /* show the current major tick preference */
  105.       WinSendMsg(WinWindowFromID(hwnd,
  106.                                  (CLKTM_MAJOR | cp.usMajorTickPref)),
  107.                                  BM_SETCHECK,
  108.                                  MPFROM2SHORT(TRUE, NULL),
  109.                                  MPVOID);
  110.  
  111.       /* show the current minor tick preference */
  112.       WinSendMsg(WinWindowFromID(hwnd,
  113.                                  (CLKTM_MINOR | cp.usMinorTickPref)),
  114.                                  BM_SETCHECK,
  115.                                  MPFROM2SHORT(TRUE, 0),
  116.                                  MPVOID);
  117.  
  118.       /* load the selection values from the preferences */
  119.       usMajorTickSel = cp.usMajorTickPref;
  120.       usMinorTickSel = cp.usMinorTickPref;
  121.  
  122.       /* let the default dialog procedure handle anything else */
  123.       break;
  124.  
  125.    case WM_COMMAND:
  126.        switch (LOUSHORT(mp1))
  127.        {
  128.        case DID_OK:
  129.            /* store away selections as preferences */
  130.           cp.usMajorTickPref = usMajorTickSel;
  131.           cp.usMinorTickPref = usMinorTickSel;
  132.  
  133.           /* repaint with the new preferences */
  134.           WinInvalidateRect(hwndFrame, NULL, TRUE);
  135.  
  136.        case DID_CANCEL:
  137.           WinDismissDlg(hwnd, TRUE);
  138.        }
  139.  
  140.        return NULL;
  141.  
  142.    case WM_CONTROL:
  143.       if (SHORT2FROMMP(mp1) == BN_CLICKED)
  144.       {
  145.          USHORT usButtonID = SHORT1FROMMP(mp1);
  146.  
  147.          switch (usButtonID & 0xff00)
  148.          {
  149.          case CLKTM_MAJOR:
  150.             usMajorTickSel = LOBYTE(usButtonID);
  151.             break;
  152.  
  153.          case CLKTM_MINOR:
  154.             usMinorTickSel = LOBYTE(usButtonID);
  155.             break;
  156.          }
  157.       }
  158.       /* fall through to the default control processing */
  159.    }
  160.  
  161.    return WinDefDlgProc(hwnd, usMsg, mp1, mp2);
  162. }
  163. /**************************************************************************\
  164. *                                                                          *
  165. *       ROUTINE:    AlarmDlgProc ( )                                       *
  166. *                                                                          *
  167. *       COMMENT:    "Alarm..." dialog                                      *
  168. *                                                                          *
  169. *       RETURNS:    MRESULT, 0 or return value from WinDefDlgProc          *
  170. *                                                                          *
  171. \**************************************************************************/
  172. MRESULT EXPENTRY AlarmDlgProc(HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2)
  173. {
  174.    switch (usMsg)
  175.    {
  176.    case WM_INITDLG:
  177.       hAlarmTime = hwnd; /* Put in a global variable so all functions know
  178.                              we have already have an opened dialog box.  */
  179.       InitAlarm(hwnd);
  180.       break;
  181.  
  182.    case WM_COMMAND:
  183.       switch (LOUSHORT(mp1))
  184.       {
  185.       case DID_OK:
  186.          AlarmSet(hwnd);
  187.  
  188.       case DID_CANCEL:
  189.          hAlarmTime = NULLHANDLE;
  190.          WinDismissDlg(hwnd, TRUE);
  191.       }
  192.       return NULL;
  193.  
  194.    case WM_CONTROL:
  195.       break;
  196.  
  197.    case WM_VSCROLL:
  198.       AlarmVScrolls(hwnd, HIUSHORT(mp2), mp1);
  199.       break;
  200.    }
  201.    return WinDefDlgProc(hwnd, usMsg, mp1, mp2);
  202. }
  203. /**********************************************************************
  204. * InitAlarm
  205. *
  206. ************************************************************************/
  207. void InitAlarm(HWND hwnd)
  208. {
  209.    USHORT usItem;
  210.    MPARAM Message;
  211.  
  212.    WinSendMsg(WinWindowFromID(hwnd,
  213.               SCROLL_HOURS),
  214.               SBM_SETSCROLLBAR,
  215.               MPFROMLONG(2),
  216.               MPFROM2SHORT(1, 3));
  217.    WinSendMsg(WinWindowFromID(hwnd,SCROLL_MINUTES),
  218.               SBM_SETSCROLLBAR,
  219.               MPFROMLONG(2),
  220.               MPFROM2SHORT(1, 3));
  221.    WinSendDlgItemMsg(hwnd,
  222.                      IDC_HOURMINUTES,
  223.                      EM_SETTEXTLIMIT,
  224.                      MPFROMLONG(5),
  225.                      MPVOID);
  226.    SetAlarmField(hwnd, cp.alarm.uchHour, cp.alarm.uchMinutes);
  227.    WinSendDlgItemMsg(hwnd,
  228.                      IDC_HOURMINUTES,
  229.                      EM_SETSEL,
  230.                      MPFROM2SHORT(0, 0),
  231.                      MPVOID);
  232.    pfnwpEntryField = WinSubclassWindow(WinWindowFromID(hwnd,
  233.                                                        IDC_HOURMINUTES),
  234.                                                        EntryFieldSubProc);
  235.    usItem = (USHORT)(cp.alarm.usMode & AM_ACTIVE ? RB_ALARMON : RB_ALARMOFF);
  236.    WinSendDlgItemMsg(hwnd,
  237.                      usItem,
  238.                      BM_SETCHECK,
  239.                      MPFROMLONG(1),
  240.                      MPVOID);
  241.    Message = (cp.alarm.usMode & AM_AUDIO)? MPFROMLONG(1) : MPFROMLONG(0);
  242.    WinSendDlgItemMsg(hwnd,
  243.                       IDC_BEEP,
  244.                       BM_SETCHECK,
  245.                       Message,
  246.                       MPVOID);
  247.  
  248.    Message = (cp.alarm.usMode & AM_MSGBOX) ? MPFROMLONG(1) : MPFROMLONG(0);
  249.    WinSendDlgItemMsg(hwnd,
  250.                      IDC_MSG,
  251.                      BM_SETCHECK,
  252.                      Message,
  253.                      MPVOID);
  254. }
  255.  
  256. /**************************************************************************
  257. * AlarmSet
  258. ***************************************************************************/
  259. VOID AlarmSet(HWND hwnd)
  260. {
  261.    GetAlarmTime(hwnd, &cp.alarm.uchHour, &cp.alarm.uchMinutes);
  262.    cp.alarm.usMode = (AM_ACTIVE * ((ULONG)WinSendDlgItemMsg(hwnd,
  263.                                                     RB_ALARMON,
  264.                                                     BM_QUERYCHECK,
  265.                                                     MPVOID,
  266.                                                     MPVOID)))
  267.                       |
  268.                       (AM_AUDIO  * ((ULONG)WinSendDlgItemMsg(hwnd,
  269.                                                     IDC_BEEP,
  270.                                                     BM_QUERYCHECK,
  271.                                                     MPVOID,
  272.                                                     MPVOID)))
  273.                       |
  274.                       (AM_MSGBOX * ((ULONG)WinSendDlgItemMsg(hwnd,
  275.                                                     IDC_MSG,
  276.                                                     BM_QUERYCHECK,
  277.                                                     MPVOID,
  278.                                                     MPVOID)));
  279.    AlarmSetTimer(cp.alarm.uchHour, cp.alarm.uchMinutes);
  280. }
  281.  
  282. /****************************************************************\
  283.  *
  284.  *--------------------------------------------------------------
  285.  *
  286.  *  Name:       AlarmSetTimer
  287.  *
  288.  *  Purpose:
  289.  *
  290.  *
  291.  *
  292.  *  Usage:
  293.  *
  294.  *  Method:
  295.  *          -
  296.  *
  297.  *          -
  298.  *          -
  299.  *
  300.  *          -
  301.  *          -
  302.  *
  303.  *  Returns:
  304.  *          1 - if successful execution completed
  305.  *          0 - if error
  306. \****************************************************************/
  307. VOID AlarmSetTimer(UCHAR uchHour, UCHAR uchMinutes)
  308. {
  309.    DATETIME DateTime;
  310.    time_t  UTCCurrentTime, UTCAlarmTime;
  311.    struct tm tmTime;
  312.  
  313.    memset(&DateTime, 0, sizeof(DATETIME));
  314.    memset(&tmTime, 0, sizeof(struct tm));
  315.  
  316.    /*
  317.     *      Get our current time then use mktime to get the UTC time.
  318.     */
  319.    DosGetDateTime(&DateTime);
  320.    tmTime.tm_min   = DateTime.minutes;
  321.    tmTime.tm_hour  = DateTime.hours;
  322.    tmTime.tm_mday  = DateTime.day;
  323.    tmTime.tm_sec   = DateTime.seconds;
  324.    tmTime.tm_mon   = --DateTime.month;
  325.    tmTime.tm_year  = (DateTime.year - 1900);
  326.  
  327.    UTCCurrentTime =  mktime(&tmTime);
  328.  
  329.     /*
  330.      *  If the alarm time is less than the current time
  331.      *  then the alarm must be for tomorrow.
  332.      */
  333.    if(uchHour < DateTime.hours  ||
  334.               (DateTime.hours == cp.alarm.uchHour
  335.               && uchMinutes < DateTime.minutes))
  336.    {
  337.       DateTime.day++;
  338.    }
  339.     /*
  340.      *    Get the time in UTC format for the timer to expire.
  341.      */
  342.    tmTime.tm_min   = uchMinutes;
  343.    tmTime.tm_hour  = uchHour;
  344.    tmTime.tm_mday  = DateTime.day;
  345.    tmTime.tm_sec   = 0;
  346.    tmTime.tm_isdst = 0;
  347.  
  348.     /*
  349.      * Set the timer value for the
  350.      * difference between our  current time
  351.      * and the alarm time (in milliseconds).
  352.      */
  353.    UTCAlarmTime = mktime(&tmTime);
  354.    TimerResources.ulTimerValue  = (UTCAlarmTime  - UTCCurrentTime) * 1000L;
  355.  
  356.     /*
  357.      *      Post the timer.
  358.      */
  359.    DosPostEventSem(TimerResources.hTimerDev);
  360. }
  361.  
  362.  
  363. /**************************************************************************\
  364. *                                                                          *
  365. *       ROUTINE:    ClkColorsDlgProc ( )                                   *
  366. *                                                                          *
  367. *       COMMENT:    "Clock Color Preferences" Dialog                       *
  368. *                                                                          *
  369. *       RETURNS:    MRESULT, 0 or return value from WinDefDlgProc          *
  370. *                                                                          *
  371. \**************************************************************************/
  372. MRESULT EXPENTRY ClkColorsDlgProc(HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2)
  373. {
  374.    static USHORT usCheckedPartID = 0, usCheckedColorID = 0;
  375.    static LONG clrBackgroundNew;
  376.    static LONG clrFaceNew;
  377.    static LONG clrHourHandNew;
  378.    static LONG clrMinuteHandNew;
  379.    static LONG *pclrNew;
  380.  
  381.    switch (usMsg)
  382.    {
  383.       USHORT usButtonID;
  384.       HWND hwndButton;
  385.       HPS hpsT;
  386.       RECTL rclButton, rclButtonInterior;
  387.  
  388.    case WM_INITDLG:
  389.       hpsT = WinGetPS(hwnd);
  390.  
  391.       GpiCreateLogColorTable(hpsT, LCOL_RESET, LCOLF_RGB, 0L, 0L, NULL);
  392.  
  393.       /* Load the new values from the current ones.    */
  394.       clrBackgroundNew = GpiQueryColorIndex(hpsT, 0L, cp.clrBackground);
  395.  
  396.       clrFaceNew       = GpiQueryColorIndex(hpsT, 0L, cp.clrFace      );
  397.       clrHourHandNew   = GpiQueryColorIndex(hpsT, 0L, cp.clrHourHand  );
  398.       clrMinuteHandNew = GpiQueryColorIndex(hpsT, 0L, cp.clrMinuteHand);
  399.  
  400.       WinReleasePS(hpsT);
  401.  
  402.       /* click the "Background" radio button */
  403.       WinPostMsg(WinWindowFromID(hwnd,
  404.                                  CLKCLR_BACKGROUND),
  405.                                  BM_CLICK,
  406.                                  MPFROMSHORT(TRUE),
  407.                                  MPVOID);
  408.  
  409.       /* Let the default dialog procedure handle anything else.   */
  410.       break;
  411.  
  412.    case WM_COMMAND:
  413.       switch (LOUSHORT(mp1))
  414.       {
  415.          case DID_OK:
  416.             hpsT = WinGetPS(hwnd);
  417.  
  418.             GpiCreateLogColorTable(hpsT, LCOLF_RGB, 0L, 0L, 0L, NULL);
  419.  
  420.               /*
  421.                * Uupdate the one the user has selected.
  422.                */
  423.             switch(usCheckedPartID)
  424.             {
  425.             case CLKCLR_BACKGROUND:
  426.                cp.clrBackground = GpiQueryRGBColor(hpsT, 0L, clrBackgroundNew);
  427.                break;
  428.  
  429.             case CLKCLR_FACE:
  430.                cp.clrFace = GpiQueryRGBColor(hpsT, 0L, clrFaceNew);
  431.                break;
  432.  
  433.             case CLKCLR_HOURHAND:
  434.                cp.clrHourHand = GpiQueryRGBColor(hpsT, 0L, clrHourHandNew);
  435.                break;
  436.  
  437.             case CLKCLR_MINUTEHAND:
  438.                cp.clrMinuteHand = GpiQueryRGBColor(hpsT, 0L, clrMinuteHandNew);
  439.                break;
  440.             }
  441.             WinReleasePS(hpsT);
  442.  
  443.               /* repaint with the new colors */
  444.             WinInvalidateRect(hwndFrame, NULL, TRUE);
  445.  
  446.          case DID_CANCEL:
  447.             WinDismissDlg(hwnd, TRUE);
  448.       }
  449.       return NULL;
  450.  
  451.    case WM_CONTROL:
  452.       usButtonID = SHORT1FROMMP(mp1);
  453.  
  454.       /* selecting a new object */
  455.       if (usButtonID & CLKCLR_OBJECTS)
  456.       {
  457.          MRESULT rc;
  458.  
  459.          switch (usButtonID)
  460.          {
  461.             case CLKCLR_BACKGROUND:
  462.                pclrNew = &clrBackgroundNew;
  463.                break;
  464.             case CLKCLR_FACE:
  465.                pclrNew = &clrFaceNew;
  466.                break;
  467.             case CLKCLR_HOURHAND:
  468.                pclrNew = &clrHourHandNew;
  469.                break;
  470.             case CLKCLR_MINUTEHAND:
  471.                pclrNew = &clrMinuteHandNew;
  472.          }
  473.          usCheckedPartID = usButtonID;
  474.  
  475.           /* click the button for the new object's current color */
  476.          rc = WinSendMsg(WinWindowFromID(hwnd,
  477.                                          (CLKCLR_BUTTONSHIFT + *pclrNew)),
  478.                                          BM_CLICK,
  479.                                          MPFROMSHORT(TRUE), MPVOID);
  480.          break;
  481.       }
  482.  
  483.       switch (SHORT2FROMMP(mp1))
  484.       {
  485.       case BN_CLICKED:
  486.          *pclrNew = (LONG)usButtonID - CLKCLR_BUTTONSHIFT;
  487.  
  488.            /* Turn off the check state of the previously checked
  489.             * button and turn on the check state of the button
  490.             * just clicked.
  491.             */
  492.          WinCheckButton(hwnd, usCheckedColorID, FALSE);
  493.          WinCheckButton(hwnd, usButtonID, TRUE);
  494.          usCheckedColorID = usButtonID;
  495.          break;
  496.  
  497.       case BN_PAINT:
  498.  
  499.               /* Fill only the interior of the button, so we don't
  500.                * conflict with the focus indicator */
  501.          hwndButton = ((PUSERBUTTON) mp2) -> hwnd;
  502.          WinQueryWindowRect(hwndButton, &rclButton);
  503.          rclButton.xLeft++;
  504.          rclButton.yBottom++;
  505.          rclButton.xRight--;
  506.          rclButton.yTop--;
  507.          WinFillRect(((PUSERBUTTON) mp2)->hps,
  508.                        &rclButton,
  509.                        (LONG)usButtonID - CLKCLR_BUTTONSHIFT);
  510.  
  511.          /* Hollow out those buttons which aren't checked */
  512.          if (!WinQueryButtonCheckstate(hwnd, usButtonID))
  513.          {
  514.             rclButtonInterior.xLeft   = rclButton.xLeft   + 4;
  515.             rclButtonInterior.yBottom = rclButton.yBottom + 4;
  516.             rclButtonInterior.xRight  = rclButton.xRight  - 4;
  517.             rclButtonInterior.yTop    = rclButton.yTop    - 4;
  518.             WinFillRect(((PUSERBUTTON)mp2)->hps,
  519.                           &rclButtonInterior, SYSCLR_WINDOW);
  520.          }
  521.          break;
  522.       }
  523.       /* fall through to the default control processing */
  524.    }
  525.    return WinDefDlgProc(hwnd, usMsg, mp1, mp2);
  526. }
  527.  
  528.  
  529. /**************************************************************************\
  530. *                                                                          *
  531. *       ROUTINE:    EntryFieldSubProc                                      *
  532. *                                                                          *
  533. *       COMMENT:    "Alarm..." dialog                                      *
  534. * This procedure filter messages for the entry field and make it a time    *
  535. * entry field. It doesn't allow for illigal characters according to the    *
  536. * current selection. It doesn't allow modification of the time separator.  *
  537. * It works only for hours and minutes. The entry field has to be limited   *
  538. * to 5 characters.                                                         *
  539. *                                                                          *
  540. *                                                                          *
  541. *       RETURNS:    MRESULT, 0 or return value from WinDefDlgProc          *
  542. *                                                                          *
  543. \**************************************************************************/
  544. MRESULT EXPENTRY EntryFieldSubProc(HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2)
  545. {
  546.    USHORT usSelect, fsKeyFlags, usLast;
  547.    UCHAR usChr1;
  548.    UCHAR uchHourMinutes[6];
  549.    BOOL bValid;
  550.  
  551.    if ((usMsg > WM_MOUSEFIRST) && (usMsg < WM_MOUSELAST))
  552.    {
  553.       MRESULT mresult = pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  554.       MRESULT mresultSel = pfnwpEntryField(hwnd, EM_QUERYSEL, (PLONG)NULL, (PLONG)NULL);
  555.  
  556.       usSelect = LOUSHORT(mresultSel);
  557.       usLast   = HIUSHORT(mresultSel);
  558.       if ((usSelect == 2))
  559.          pfnwpEntryField(hwnd, EM_SETSEL, MPFROM2SHORT(3, 3), NULL);
  560.       if ((usSelect == 5))
  561.          pfnwpEntryField(hwnd, EM_SETSEL, MPFROM2SHORT(4, 4), NULL);
  562.       return mresult;
  563.    }
  564.  
  565.    switch (usMsg)
  566.    {
  567.    case WM_SETFOCUS:
  568.       pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  569.       if (SHORT1FROMMP(mp2))
  570.           pfnwpEntryField(hwnd,
  571.                           EM_SETINSERTMODE,
  572.                           MPFROMSHORT(FALSE),
  573.                           (MPARAM)NULL);
  574.       return MPVOID;
  575.  
  576.    case WM_CHAR:
  577.       fsKeyFlags = SHORT1FROMMP(mp1);    /* key flags             */
  578.       if (!(fsKeyFlags & KC_KEYUP))
  579.       {
  580.          usSelect = (USHORT)WinSendMsg(hwnd, EM_QUERYSEL, MPVOID, MPVOID);
  581.          if (fsKeyFlags & KC_VIRTUALKEY)
  582.          {
  583.             switch(SHORT2FROMMP(mp2))
  584.             {
  585.             case VK_UP:
  586.             case VK_DOWN:
  587.                break;
  588.  
  589.             case VK_LEFT:
  590.                if (usSelect == 3)
  591.                    pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  592.                return pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  593.                break;
  594.  
  595.             case VK_RIGHT:
  596.                if (usSelect == 4)
  597.                {
  598.                   return MPVOID;
  599.                }
  600.                if (usSelect == 1)
  601.                   pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  602.                return pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  603.                break;
  604.  
  605.             case VK_DELETE:
  606.             case VK_BACKSPACE:
  607.             case VK_INSERT:
  608.                return MPVOID;
  609.  
  610.             case VK_SPACE:
  611.                switch (usSelect)
  612.                {
  613.                case 0:   /*  Hours most significant digit   */
  614.                   if (bTwelveHourFormat)
  615.                   {
  616.                      return pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  617.                   }
  618.  
  619.                default:
  620.                   return MPVOID;
  621.                }
  622.  
  623.             default:
  624.                return pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  625.                break;
  626.             }
  627.          }
  628.          else
  629.          {
  630.             if (fsKeyFlags & KC_CHAR)
  631.             {
  632.                bValid = FALSE;
  633.                WinQueryWindowText(hwnd, sizeof(uchHourMinutes), uchHourMinutes);
  634.                usChr1 = (UCHAR)CHAR1FROMMP(mp2);
  635.                switch (usSelect)
  636.                {
  637.                case 0:   /* Hours most significant digit */
  638.                   if (bTwelveHourFormat)
  639.                   {
  640.                      if ((usChr1 > '1') || (usChr1 < '0'))
  641.                      {
  642.                          return MPVOID;
  643.                      }
  644.                      else
  645.                      {
  646.                          pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  647.                          bValid = TRUE;
  648.                      }
  649.                   }
  650.                   else
  651.                   {
  652.                      if ((usChr1 > '2') || (usChr1 < '0'))
  653.                      {
  654.                          return MPVOID;
  655.                      }
  656.                      else
  657.                      {
  658.                          pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  659.                          bValid = TRUE;
  660.                      }
  661.                   }
  662.                   if (bValid)
  663.                   {
  664.                      uchHourMinutes[0] = usChr1;
  665.                      uchHourMinutes[1] = '0';
  666.                      WinSetWindowText(hwnd, uchHourMinutes);
  667.                      pfnwpEntryField(hwnd, EM_SETSEL, MPFROM2SHORT(1,1),(PLONG)NULL);
  668.                   }
  669.                   return MPVOID;
  670.                   break;
  671.  
  672.                case 1:
  673.                   if (bTwelveHourFormat)
  674.                   {
  675.                      if ((uchHourMinutes[0] == '0') || (uchHourMinutes[0] == ' '))
  676.                      {
  677.                         if ((usChr1 > '9') || (usChr1 < '0'))
  678.                         {
  679.                            return MPVOID;
  680.                         }
  681.                         else
  682.                         {
  683.                            pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  684.                            bValid = TRUE;
  685.                         }
  686.                    }
  687.                    else
  688.                    {    /* probably 1  */
  689.                       if ((usChr1 > '2') || (usChr1 < '0'))
  690.                       {
  691.                          return MPVOID;
  692.                       }
  693.                       else
  694.                       {
  695.                          pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  696.                          bValid = TRUE;
  697.                       }
  698.                    }
  699.                }
  700.                 else
  701.                 {
  702.                    if (uchHourMinutes[0] < '2')
  703.                    {
  704.                       if ((usChr1 > '9') || (usChr1 < '0'))
  705.                       {
  706.                          return MPVOID;
  707.                       }
  708.                       else
  709.                       {
  710.                          pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  711.                          bValid = TRUE;
  712.                       }
  713.                    }
  714.                    else
  715.                    {
  716.                       if ((usChr1 > '4') || (usChr1 < '0'))
  717.                       {
  718.                          return MPVOID;
  719.                       }
  720.                       else
  721.                       {
  722.                          pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  723.                          bValid = TRUE;
  724.                       }
  725.                    }
  726.                 }
  727.                 /*  Fill the entry field as if a time separator is in also */
  728.                 if (bValid)
  729.                 {
  730.                    mp2 = (MPARAM)(((ULONG)mp2 & 0xffffff00) | szTimeSep[0]);
  731.                    return pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  732.                 }
  733.                 break;
  734.  
  735.             case 3:   /* minutes left digit, 0-5 */
  736.                if ((usChr1 > '5') || (usChr1 < '0'))
  737.                {
  738.                   return MPVOID;
  739.                }
  740.                else
  741.                   return pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  742.                   break;
  743.  
  744.             case 4:   /*minutes right digit, 0-9*/
  745.                if ((usChr1 > '9') || (usChr1 < '0'))
  746.                {
  747.                   return MPVOID;
  748.                }
  749.                else
  750.                {
  751.                   pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  752.                   return pfnwpEntryField(hwnd, EM_SETSEL, MPFROM2SHORT(4,4), MPVOID);
  753.                }
  754.                break;
  755.             }
  756.          }
  757.       }
  758.    }
  759.  
  760.    default:
  761.       return pfnwpEntryField(hwnd, usMsg, mp1, mp2);
  762.    }
  763. }
  764. /****************************************************************\
  765.  *
  766.  *--------------------------------------------------------------
  767.  *
  768.  *  Name:AlarmScrolls()
  769.  *
  770.  *  Purpose:
  771.  *
  772.  *
  773.  *
  774.  *  Usage:
  775.  *
  776.  *  Method:
  777.  *          -
  778.  *
  779.  *          -
  780.  *          -
  781.  *
  782.  *          -
  783.  *          -
  784.  *
  785.  *  Returns:
  786.  *          1 - if successful execution completed
  787.  *          0 - if error
  788. \****************************************************************/
  789. VOID  AlarmVScrolls(HWND hwnd, USHORT ScrollMsg, MPARAM idScroll)
  790. {
  791.    UCHAR uchHours, uchMinutes;
  792.  
  793.    GetAlarmTime(hwnd, &uchHours, &uchMinutes);
  794.  
  795.    switch(ScrollMsg)
  796.    {
  797.    case SB_LINEUP:
  798.    case SB_PAGEUP:
  799.       if (idScroll == (MPARAM)SCROLL_HOURS)
  800.          if (uchHours == 23)
  801.             uchHours = 0;
  802.          else uchHours++;
  803.       else
  804.          if (uchMinutes == 59)
  805.             uchMinutes = 0;
  806.          else
  807.             uchMinutes++;
  808.          break;
  809.  
  810.  
  811.    case SB_LINEDOWN:
  812.    case SB_PAGEDOWN:
  813.       if (idScroll == (MPARAM)SCROLL_HOURS)
  814.          if (uchHours == 0)
  815.             uchHours = 23;
  816.          else uchHours--;
  817.       else
  818.          if (uchMinutes == 00)
  819.             uchMinutes = 59;
  820.          else
  821.             uchMinutes--;
  822.       break;
  823.  
  824.  
  825.     }
  826.     SetAlarmField(hwnd, uchHours, uchMinutes);
  827.     WinSendDlgItemMsg(hwnd,
  828.                         IDC_HOURMINUTES,
  829.                         EM_SETSEL,
  830.                         (idScroll == (MPARAM)SCROLL_HOURS) ?MPFROM2SHORT(0,0):MPFROM2SHORT(3,3),
  831.                         MPVOID);
  832. }
  833.  
  834. /****************************************************************\
  835.  *
  836.  *--------------------------------------------------------------
  837.  *
  838.  *  Name:        GetAlarmTime()
  839.  *
  840.  *  Purpose:
  841.  *
  842.  *
  843.  *
  844.  *  Usage:
  845.  *
  846.  *  Method:
  847.  *          -
  848.  *
  849.  *          -
  850.  *          -
  851.  *
  852.  *          -
  853.  *          -
  854.  *
  855.  *  Returns:
  856.  *
  857.  *          VOID
  858. \****************************************************************/
  859. VOID GetAlarmTime(HWND hwnd,UCHAR *npuchHours,UCHAR *npuchMinutes)
  860. {
  861.    UCHAR achHourMinutes[6];
  862.    UCHAR uchHours;
  863.  
  864.    WinQueryDlgItemText(hwnd,
  865.                        IDC_HOURMINUTES,
  866.                        sizeof(achHourMinutes),
  867.                        achHourMinutes);
  868.    uchHours = (UCHAR)atoi((const char *)achHourMinutes);
  869.  
  870.    if (bTwelveHourFormat)
  871.    {
  872.       if (WinSendDlgItemMsg(hwnd,
  873.                             RB_PM,
  874.                             BM_QUERYCHECK,
  875.                             MPVOID,
  876.                             MPVOID))
  877.       {
  878.          if(uchHours != 12)
  879.             uchHours += 12;
  880.       }
  881.       else
  882.       {
  883.          if(uchHours == 12)
  884.             uchHours = 0;
  885.       }
  886.    }
  887.    *npuchHours = uchHours;
  888.    *npuchMinutes = (UCHAR)atoi((const char *)&achHourMinutes[3]);
  889. }
  890.  
  891.  
  892. /****************************************************************\
  893.  *
  894.  *--------------------------------------------------------------
  895.  *
  896.  *  Name:     SetAlarmField
  897.  *
  898.  *  Purpose:
  899.  *
  900.  *
  901.  *
  902.  *  Usage:
  903.  *
  904.  *  Method:
  905.  *          -
  906.  *
  907.  *          -
  908.  *          -
  909.  *
  910.  *          -
  911.  *          -
  912.  *
  913.  *  Returns:
  914.  *          1 - if successful execution completed
  915.  *          0 - if error
  916. \****************************************************************/
  917. VOID SetAlarmField(HWND hwnd,UCHAR uchHours,UCHAR uchMinutes)
  918. {
  919.    UCHAR achHourMinutes[6];
  920.  
  921.    if (bTwelveHourFormat)
  922.    {
  923.       if (uchHours >= 12)
  924.       {
  925.          uchHours -= 12;
  926.          WinSendDlgItemMsg(hwnd,
  927.                            RB_PM,
  928.                            BM_SETCHECK,
  929.                            MPFROMLONG(1),
  930.                            MPVOID);
  931.         if (uchHours == 0)
  932.            uchHours = 12;
  933.       }
  934.       else
  935.       {
  936.          if (uchHours == 0)
  937.             uchHours = 12;
  938.          WinSendDlgItemMsg(hwnd,
  939.                            RB_AM,
  940.                            BM_SETCHECK,
  941.                            MPFROMLONG(1),
  942.                            MPVOID);
  943.       }
  944.    }
  945.    else
  946.    {
  947.        WinShowWindow(WinWindowFromID(hwnd,RB_PM),FALSE);
  948.        WinShowWindow(WinWindowFromID(hwnd,RB_AM),FALSE);
  949.    }
  950.    _itoa(uchHours, achHourMinutes,10);
  951.    _itoa(uchMinutes, &achHourMinutes[3],10);
  952.    achHourMinutes[2] = szTimeSep[0];
  953.    if (achHourMinutes[1] == 0)
  954.    {
  955.       achHourMinutes[1] = achHourMinutes[0];
  956.       achHourMinutes[0] = ' ';
  957.    }
  958.    if (achHourMinutes[4] == 0)
  959.    {
  960.       achHourMinutes[4] = achHourMinutes[3];
  961.       achHourMinutes[3] = '0';
  962.    }
  963.    WinSetDlgItemText(hwnd, IDC_HOURMINUTES, achHourMinutes);
  964. }
  965.  
  966. /****************************************************************\
  967.  *  Dialog procedure for the About dialog box
  968.  *--------------------------------------------------------------
  969.  *
  970.  *  Name:   AboutBoxDlgProc(hwnd, msg, mp1, mp2)
  971.  *
  972.  *  Purpose: Processes all messages sent to the About Box
  973.  *
  974.  *  Usage:  Called for each message sent to the About Box
  975.  *          dialog box.
  976.  *
  977.  *  Method: the about box only has a button control so this
  978.  *          routine only processes WM_COMMAND messages.  Any
  979.  *          WM_COMMAND posted must have come from the Ok
  980.  *          button so we dismiss the dialog upon receiving it.
  981.  *
  982.  *  Returns: Dependent upon message sent
  983.  *
  984. \****************************************************************/
  985. MRESULT EXPENTRY AboutBoxDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  986. {
  987.     switch(msg)
  988.     {
  989.         case WM_COMMAND:
  990.             /* no matter what the command, close the dialog */
  991.             WinDismissDlg(hwnd, TRUE);
  992.             break;
  993.  
  994.         default:
  995.             return WinDefDlgProc(hwnd, msg, mp1, mp2);
  996.             break;
  997.     }
  998.  
  999.     return MPVOID;
  1000. }   /* AboutBoxWndProc() */
  1001.  
  1002. /*--------------------------------------------------------------*\
  1003.  *  End of file: dialogs.c
  1004. \*--------------------------------------------------------------*/
  1005.