home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / TOOLKIT / OS2 / TIMESERV / UDTIME.C < prev    next >
C/C++ Source or Header  |  1995-02-15  |  61KB  |  1,850 lines

  1. /*static char *SCCSID = "@(#)udtime.c    6.7 92/02/18";*/
  2. /*=========================================================================\
  3.  *                                                                         *
  4.  *       FILE: udtime.c                                                    *
  5.  *                                                                         *
  6.  *       DESCRIPTION:  miscellaneous time and date functions               *
  7.  *                                                                         *
  8.  *                                                                         *
  9.  *                                                                         *
  10.  *      Copyright 1992     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.  *      TimeDlgProc
  27.  *      GetControlCoordinates
  28.  *      PanelDlgFilter
  29.  *      ChangeDateTime
  30.  *      ControlMinmax
  31.  *      PanelPaint
  32.  *      PaintDateTime
  33.  *      GetDate
  34.  *      GetTime
  35.  *      PanelVScrolls
  36.  *      TimeInit
  37.  *      MouseTrack
  38.  *      GetCountryDependent
  39.  *      BringUpArrows
  40.  *      FixDate
  41.  *      SetDate
  42.  *      SetTime
  43. \*==============================================================*/
  44.  
  45. /*--------------------------------------------------------------*\
  46.  *  Include files, macros, defined constants, and externs
  47. \*--------------------------------------------------------------*/
  48. #define INCL_WINDIALOGS
  49. #define INCL_WINBUTTONS
  50. #define INCL_WINSYS
  51. #define INCL_WINMESSAGEMGR
  52. #define INCL_WINSHELLDATA
  53. #define INCL_WINFRAMEMGR
  54. #define INCL_WINPOINTERS
  55. #define INCL_WINSWITCHLIST
  56. #define INCL_WIN
  57. #define INCL_DOSNLS
  58. #define INCL_GPITRANSFORMS
  59. #define INCL_DOSSEMAPHORES
  60. #define INCL_DOSDATETIME
  61.  
  62. #include <os2.h>
  63. #include <string.h>
  64. #include <stdlib.h>
  65. #include "clock.h"
  66. #include "res.h"
  67. #include "clkdata.h"
  68.  
  69.  
  70.  
  71.  
  72. /*--------------------------------------------------------------*\
  73.  *  Global variables  and definitions for this file
  74. \*--------------------------------------------------------------*/
  75.  
  76.  
  77. SHORT DaysPerMonth[13] =
  78.        {0,31,28,31,30,31,30,31,31,30,31,30,31};
  79.  
  80. /*--------------------------------------------------------------*\
  81.  *  Entry point declarations
  82. \*--------------------------------------------------------------*/
  83.  
  84. MRESULT EXPENTRY TimeDlgProc(HWND, ULONG, MPARAM, MPARAM);
  85. VOID    GetControlCoordinates( HWND, HWND, SHORT *, SHORT *, SHORT *);
  86. BOOL    PanelDlgFilter( HWND, USHORT, MPARAM, MPARAM);
  87. VOID    ChangeDateTime( HPS, HWND, SHORT, CHAR );
  88. VOID    ControlMinmax( MPARAM,HWND);
  89. VOID    PanelPaint(  HPS );
  90. VOID    PaintDateTime( HPS );
  91. VOID    GetDate(void);
  92. VOID    GetTime(void);
  93. VOID    PanelVScrolls( HWND, USHORT,  MPARAM);
  94. VOID    TimeInit(HWND);
  95. SHORT   MouseTrack( MPARAM );
  96. VOID    GetCountryDependent(VOID);
  97. VOID    BringUpArrows( HWND, SHORT );
  98. VOID    FixDate( SHORT );
  99. VOID    SetDate(void);
  100. VOID    SetTime(void);
  101. /****************************************************************\
  102.  *  Routine Name:
  103.  *--------------------------------------------------------------
  104.  *
  105.  *  Name:TimeDlgProc()
  106.  *
  107.  *  Purpose:
  108.  *  This routine will handle the  processing necessary for the
  109.  *  time dialog box.
  110.  *
  111.  *  Usage:
  112.  *
  113.  *  Method:
  114.  *          -
  115.  *
  116.  *          -
  117.  *          -
  118.  *
  119.  *          -
  120.  *          -
  121.  *
  122.  *  Returns:
  123.  *
  124.  *
  125. \****************************************************************/
  126. MRESULT
  127. EXPENTRY TimeDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  128. {
  129.     HPS  hpsPanel;
  130.  
  131.     switch (msg)
  132.     {
  133.  
  134.     case WM_INITDLG:
  135.         /*
  136.          * Dialog boxes have no way to tell pmwin to ignore the x,y pos.  So
  137.          * we have to make pmwin decide anyway where to put this dialog box.
  138.          */
  139.         hDateTime = hwnd; /* put in a global var, so everybody know we
  140.                              already have an opened dialog box */
  141.         TimeInit (hwnd);
  142.         return ( (MRESULT) 0L);
  143.         break;
  144.  
  145.     case WM_CHAR:
  146.         if (!bIsIconic)
  147.             PanelDlgFilter( hwnd, msg, mp1, mp2);
  148.         break;
  149.  
  150.     case WM_BUTTON1DOWN:
  151.         if (bIsIconic)
  152.             return (WinDefDlgProc( hwnd, msg, mp1, mp2));
  153.         else
  154.         {
  155.             hpsPanel = WinGetPS(hwnd);
  156.             ChangeDateTime( hpsPanel, hwnd, MouseTrack(mp1 ),0 );
  157.             WinReleasePS( hpsPanel);
  158.             return( WinDefDlgProc( hwnd, msg, mp1, mp2) );
  159.         }
  160.         break;
  161.  
  162.     case WM_COMMAND:
  163.         switch (LOUSHORT(mp1))
  164.         {
  165.         case MBID_OK:
  166.             if (fTimeFreez) SetTime();
  167.             if (fDateFreez) SetDate();
  168.             /*Fall through to cancel*/
  169.  
  170.         case MBID_CANCEL:
  171.            /*The code here is executed also on MBID_OK*/
  172.             hDateTime = (HWND)NULL;
  173.             WinDismissDlg( hwnd, 0);
  174.             break;
  175.         }
  176.         break;
  177.  
  178.  
  179.     case WM_MINMAXFRAME:
  180.         ControlMinmax( mp1, hwnd );
  181.         break;
  182.  
  183.     case WM_PAINT:
  184.         if ( bIsIconic )
  185.             return( WinDefDlgProc( hwnd, msg, mp1, mp2) );
  186.         else {
  187.             WinDefDlgProc(hwnd, msg, mp1, mp2);
  188.             hpsPanel = WinGetPS(hwnd);
  189.             PanelPaint(  hpsPanel);
  190.             WinReleasePS( hpsPanel);
  191.         }
  192.         break;
  193.     case WM_TIMER:
  194.         hpsPanel = WinGetPS(hwnd);
  195.         if ( LOUSHORT( mp1) == IDR_MAIN ) {
  196.            if ( !(fTimeFreez)) GetTime();
  197.            if ( !(fDateFreez )) GetDate();
  198.            PaintDateTime( hpsPanel);
  199.         }
  200.         WinReleasePS( hpsPanel);
  201.         break;
  202.     case WM_VSCROLL:
  203.         if ( bIsIconic )
  204.             break;
  205.         PanelVScrolls( hwnd,
  206.                        HIUSHORT(mp2),
  207.                        mp1     );
  208.         break;
  209.  
  210.  
  211.  
  212.     default:
  213.         return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  214.         break;
  215.     }
  216.    return( (MRESULT)0L);
  217. }
  218. /****************************************************************\
  219.  *
  220.  *--------------------------------------------------------------
  221.  *
  222.  *  Name:GetControlCoordinates()
  223.  *
  224.  *  Purpose: Get coordinates for the current dialog box.
  225.  *
  226.  *
  227.  *
  228.  *  Usage:
  229.  *
  230.  *  Method:
  231.  *          -
  232.  *
  233.  *          -
  234.  *          -
  235.  *
  236.  *          -
  237.  *          -
  238.  *
  239.  *  Returns:
  240.  *
  241.  *
  242. \****************************************************************/
  243. VOID
  244. GetControlCoordinates( HWND hDlg, HWND hwnd, SHORT *px, SHORT *py,
  245.                                  SHORT *px2)
  246. {
  247.     WRECT wrcT;
  248.  
  249.     WinQueryWindowRect(hwnd, (PRECTL)&wrcT);
  250.  
  251.     /* Convert rect. relative coord.s to dlg relative coord.s Joho.  */
  252.  
  253.     WinMapWindowPoints( hwnd, hDlg, (PPOINTL)&wrcT, 2);
  254.  
  255.     /* Convert window coord.s to dialog coord.s (==font transform)   */
  256.  
  257.     WinMapDlgPoints( hDlg, (PPOINTL)&wrcT, 2, FALSE);
  258.  
  259.    *px = wrcT.xLeft;
  260.    *py = wrcT.yBottom;
  261.    *px2 = wrcT.xRight;
  262.  
  263. }
  264.  
  265.  
  266. /****************************************************************\
  267.  *
  268.  *--------------------------------------------------------------
  269.  *
  270.  *  Name:
  271.  *
  272.  *  Purpose:
  273.  *
  274.  *
  275.  *
  276.  *  Usage:
  277.  *
  278.  *  Method:
  279.  *          -
  280.  *
  281.  *          -
  282.  *          -
  283.  *
  284.  *          -
  285.  *          -
  286.  *
  287.  *  Returns: VOID
  288.  *
  289.  *
  290. \****************************************************************/
  291. VOID
  292. TimeInit(HWND hwnd)
  293. {
  294.     SHORT       xTime, yTime;
  295.     SHORT       xDate, yDate;
  296.     SHORT       x2Time, x2Date;
  297.  
  298.  
  299.     fTimeFreez = FALSE;
  300.     fDateFreez = FALSE;
  301.  
  302.  
  303.  
  304.     /*****************************************************************/
  305.     /*  Get focus items' handles                                     */
  306.     /*****************************************************************/
  307.     hTime = WinWindowFromID(hwnd,TIME);
  308.     hDate = WinWindowFromID(hwnd,DATE);
  309.     hTimeScroll = WinWindowFromID(hwnd,SCROLL_TIME);
  310.     hDateScroll = WinWindowFromID(hwnd,SCROLL_DATE);
  311.  
  312.  
  313.  
  314.     /**************************************************/
  315.     /*  Get coords of time and date                   */
  316.     /**************************************************/
  317.  
  318.     GetControlCoordinates( hwnd, hTime, &xTime, &yTime, &x2Time);
  319.     GetControlCoordinates( hwnd, hDate, &xDate, &yDate, &x2Date);
  320.  
  321.     hCurrentFocus = (HWND)NULL;        /* init focus to nowt        */
  322.  
  323.  
  324.     /*****************************************************************/
  325.     /*  Rectangles and locations for Hit-tests and drawing.          */
  326.     /*****************************************************************/
  327.  
  328.     /*****************************************************************/
  329.     /*  Date rectangles                                              */
  330.     /*****************************************************************/
  331.     rDateAssign[0].yTop =
  332.     rDateAssign[1].yTop =
  333.     rDateAssign[2].yTop =
  334.     rDateSep[0].yTop    =
  335.     rDateSep[1].yTop    = yDate + (UCHAR)15;
  336.  
  337.     rDateAssign[0].yBottom =
  338.     rDateAssign[1].yBottom =
  339.     rDateAssign[2].yBottom =
  340.     rDateSep[0].yBottom    =
  341.     rDateSep[1].yBottom    = yDate +  (UCHAR)3;
  342.  
  343.     rDateAssign[0].xLeft   = xDate + (UCHAR)4;
  344.  
  345.     rDateAssign[0].xRight = rDateSep[0].xLeft    = xDate + (SHORT)16;
  346.     rDateSep[0].xRight    = rDateAssign[1].xLeft = xDate + (SHORT)20;
  347.     rDateAssign[1].xRight = rDateSep[1].xLeft    = xDate + (SHORT)32;
  348.     rDateSep[1].xRight    = rDateAssign[2].xLeft = xDate + (SHORT)36;
  349.  
  350.     rDateAssign[2].xRight = xDate + (SHORT)48;
  351.  
  352.     /*****************************************************************/
  353.     /*  Now map the Dlg coord.s into Window coord.s ready for rect.s */
  354.     /*****************************************************************/
  355.  
  356.     WinMapDlgPoints( hwnd, (PPOINTL)&rDateAssign[0], 2, TRUE);
  357.     WinMapDlgPoints( hwnd, (PPOINTL)&rDateSep[0],    2, TRUE);
  358.     WinMapDlgPoints( hwnd, (PPOINTL)&rDateAssign[1], 2, TRUE);
  359.     WinMapDlgPoints( hwnd, (PPOINTL)&rDateSep[1],    2, TRUE);
  360.     WinMapDlgPoints( hwnd, (PPOINTL)&rDateAssign[2], 2, TRUE);
  361.  
  362.  
  363.     /*****************************************************************/
  364.     /*  time Rectangles                                              */
  365.     /*****************************************************************/
  366.     rDateTime[HOUR].yTop   =
  367.     rDateTime[MINUTE].yTop =
  368.     rDateTime[SECOND].yTop =
  369.     rTimeSep[0].yTop       =
  370.     rTimeSep[1].yTop       =
  371.     rTimeSep[2].yTop       = yTime + (SHORT)15;
  372.  
  373.     rDateTime[HOUR].yBottom   =
  374.     rDateTime[MINUTE].yBottom =
  375.     rDateTime[SECOND].yBottom =
  376.     rTimeSep[0].yBottom       =
  377.     rTimeSep[1].yBottom       =
  378.     rTimeSep[2].yBottom       = yTime +  (SHORT)3;
  379.  
  380.     rDateTime[HOUR].xLeft = xTime + (SHORT)4;
  381.  
  382.     rDateTime[HOUR].xRight   = rTimeSep[0].xLeft       = xTime + (SHORT)16;
  383.     rTimeSep[0].xRight       = rDateTime[MINUTE].xLeft = xTime + (SHORT)20;
  384.     rDateTime[MINUTE].xRight = rTimeSep[1].xLeft       = xTime + (SHORT)32;
  385.     rTimeSep[1].xRight       = rDateTime[SECOND].xLeft = xTime + (SHORT)36;
  386.  
  387.     rDateTime[SECOND].xRight = xTime + (SHORT)48;
  388.  
  389.     rTimeSep[AM_PM].xLeft    = xTime + (SHORT)50;
  390.     rTimeSep[AM_PM].xRight   = xTime + (SHORT)64;
  391.  
  392.     /*****************************************************************/
  393.     /*  Now map the Dlg coord.s into Window coord.s ready for rect.s */
  394.     /*****************************************************************/
  395.  
  396.     WinMapDlgPoints( hwnd, (PPOINTL)&rDateTime[HOUR],   2, TRUE);
  397.     WinMapDlgPoints( hwnd, (PPOINTL)&rTimeSep[0],       2, TRUE);
  398.     WinMapDlgPoints( hwnd, (PPOINTL)&rDateTime[MINUTE], 2, TRUE);
  399.     WinMapDlgPoints( hwnd, (PPOINTL)&rTimeSep[1],       2, TRUE);
  400.     WinMapDlgPoints( hwnd, (PPOINTL)&rDateTime[SECOND], 2, TRUE);
  401.     WinMapDlgPoints( hwnd, (PPOINTL)&rTimeSep[AM_PM],   2, TRUE);
  402.  
  403.     /*****************************************************************/
  404.     /*  Get time repaint region                                      */
  405.     /*****************************************************************/
  406.     WinSetRect( hab,
  407.                 (PRECTL)&rRepaintTime,
  408.                 rDateTime[HOUR].xLeft,    rDateTime[HOUR].yBottom,
  409.                 rDateTime[SECOND].xRight, rDateTime[SECOND].yTop   );
  410.     GetCountryDependent();
  411.  
  412.  
  413.  
  414.  
  415.     /* for the time and date scroll bars (spin buttons), just set the slider */
  416.     /* position in the middle of the range and never move it.    */
  417.     WinSendMsg( hTimeScroll,SBM_SETSCROLLBAR,
  418.                 MPFROMLONG(2),
  419.                 MPFROM2SHORT(1,3));
  420.     WinSendMsg( hDateScroll,SBM_SETSCROLLBAR,
  421.                 MPFROMLONG(2),
  422.                 MPFROM2SHORT(1,3));
  423.  
  424.  
  425. }
  426.  
  427. /*********************************************************************/
  428. /*  This routine does not actually filter the keystrokes, but        */
  429. /*  merely observes them in passing. It calls the DefDlgProc BEFORE  */
  430. /*  taking any action of its own, to prevent WinSetFocus calls (in   */
  431. /*  routines such as BringUpArrows in ChangeDateTime) from effecting */
  432. /*  the DlgProc behaviour.                                           */
  433. /*********************************************************************/
  434.  
  435. BOOL
  436. PanelDlgFilter( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  437. {
  438.    SHORT    Hit;                       /* item "hit", ala mouse hit */
  439.    SHORT    Key, iter;
  440.    HPS      hPS;
  441.    CHAR     UserSpecifiedVal;          /* value user typed in for time or date field  */
  442.    COUNTRYCODE DosCyCode;
  443.    COUNTRYINFO DosCyInfo;
  444.    BOOL        DosCy;
  445.    USHORT      Country;
  446.    ULONG       iTemp;
  447.    SHORT       Position4;
  448.    SHORT       Position6;
  449.  
  450.     /*****************************************************************/
  451.     /*      Tabs                                                     */
  452.     /*****************************************************************/
  453.  
  454.     Key = SHORT2FROMMP(mp2);           /* Keep the VKey around       */
  455.     UserSpecifiedVal =  CHAR1FROMMP(mp2);   /* Keep the VKey around       */
  456.  
  457.     hCurrentFocus = WinQueryFocus( HWND_DESKTOP); /* Debug    */
  458.  
  459.     WinDefDlgProc( hwnd, msg, mp1, mp2); /* Process NOW **************/
  460.  
  461.     hCurrentFocus = WinQueryFocus( HWND_DESKTOP);
  462.  
  463.     if ( !(SHORT1FROMMP(mp1) & KC_KEYUP) &&
  464.           (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) &&
  465.           ( (Key == VK_TAB) || (Key == VK_BACKTAB) ) ) {
  466.  
  467.  
  468.         /*************************************************************/
  469.         /*  Set time or date active if they get focus                */
  470.         /*************************************************************/
  471.         /*  NOTE that ChangeDateTime calls BringUpArrows which       */
  472.         /*  does WinSetFocus.                                        */
  473.         /*************************************************************/
  474.  
  475.         if (hCurrentFocus == hDate) {
  476.             hPS = WinGetPS( hwnd);
  477.             ChangeDateTime( hPS, hwnd, sFirstDate, 0 );
  478.             WinReleasePS( hPS);
  479.         }
  480.         else if (hCurrentFocus == hTime) {
  481.             hPS = WinGetPS( hwnd);
  482.             ChangeDateTime( hPS, hwnd, sFirstTime, 0 );
  483.             WinReleasePS( hPS);
  484.         }
  485.  
  486.         return(TRUE);
  487.  
  488.     } /* endif it's a Tab/Backtab */
  489.  
  490.  
  491.     /*****************************************************************/
  492.     /*      Arrows                                                   */
  493.     /*****************************************************************/
  494.  
  495.     if ( !(SHORT1FROMMP(mp1) & KC_KEYUP) &&
  496.           (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) &&
  497.          !(SHORT1FROMMP(mp1) & KC_CHAR) &&
  498.           ( (hCurrentFocus == hTime) || (hCurrentFocus == hDate) ) ) {
  499.  
  500.         Hit = Selected;                /* init ID-or-action          */
  501.  
  502.         /* determine which field to highlight by default for date field, */
  503.         /* depending on the date format for the particular country. SNOR */
  504.  
  505.         DosCyCode.country = 0;             /* Get default                */
  506.         DosCyCode.codepage = 0;            /* Get current process CP     */
  507.         DosCy = (BOOL)!DosQueryCtryInfo( sizeof(COUNTRYINFO),
  508.                                  (PCOUNTRYCODE)&DosCyCode,
  509.                                  (PCOUNTRYINFO)&DosCyInfo,
  510.                                  (PULONG)&iTemp           );
  511.  
  512.         /*****************************************************************/
  513.         /*  If no info found by Dos, set USA                             */
  514.         /*****************************************************************/
  515.         Country = (USHORT)(DosCy ? DosCyInfo.country : COUNTRY_USA) ;
  516.  
  517.         /*****************************************************************/
  518.         /* that cool way of doing date format                            */
  519.         /*****************************************************************/
  520.         iTemp = PrfQueryProfileInt( HINI_USER,
  521.                                     (PSZ)"PM_National",
  522.                                     (PSZ)"iDate",
  523.                                     (SHORT ) ( DosCy ? DosCyInfo.fsDateFmt
  524.                                                : 0 )  );
  525.         switch(iTemp)
  526.         {
  527.         case 2:
  528.             /*************************************************************/
  529.             /*                      YMD                                  */
  530.             /*************************************************************/
  531.             Position4 = YEAR;
  532.             Position6 = DAY;
  533.             break;
  534.         case 1:
  535.             /*************************************************************/
  536.             /*                      DMY                                  */
  537.             /*************************************************************/
  538.             Position4 = DAY;
  539.             Position6 = YEAR;
  540.             break;
  541.         case 0:
  542.         default:
  543.             /*************************************************************/
  544.             /*                      MDY        USA == default            */
  545.             /*************************************************************/
  546.             Position4 = MONTH;
  547.             Position6 = YEAR;
  548.             break;
  549.         }
  550.  
  551.         switch(Key)
  552.         {
  553.  
  554.  
  555.         case VK_UP:
  556.             if (Selected == NOSELECT)
  557.                 Hit = ( (hCurrentFocus == hTime) ? (SHORT) HOUR : Position4);
  558.             else
  559.                 Hit = ((hCurrentFocus == hTime) ? (SHORT)UPTIME : (SHORT)UPDATE);
  560.             break;
  561.         case VK_DOWN:
  562.             if (Selected == NOSELECT)
  563.                 Hit = ((hCurrentFocus == hTime) ? (SHORT) SECOND : Position6);
  564.             else
  565.                 Hit = ((hCurrentFocus == hTime) ? (SHORT) DOWNTIME : (SHORT)DOWNDATE);
  566.             break;
  567.         case VK_LEFT:
  568.             if (Selected == NOSELECT)
  569.                 Hit = ((hCurrentFocus == hTime) ?  (SHORT)SECOND : Position4);
  570.             break;
  571.         case VK_RIGHT:
  572.             if (Selected == NOSELECT)
  573.                 Hit = ((hCurrentFocus == hTime) ? (SHORT)HOUR : Position6);
  574.             break;
  575.         default:
  576.             return(TRUE);
  577.             break;
  578.         }
  579.  
  580.         hPS = WinGetPS(hwnd);
  581.         for ( iter = 0;
  582.               iter < (SHORT)CHAR3FROMMP(mp1);
  583.               iter++                   ) { /* repeatcount times      */
  584.  
  585.             if (Key == VK_LEFT) {
  586.                 Hit = asLeftOf[Hit];
  587.             }
  588.             if (Key == VK_RIGHT) {
  589.                 Hit = asRightOf[Hit];
  590.             }
  591.  
  592.             ChangeDateTime(hPS, hwnd, Hit, 0);
  593.         }
  594.         WinReleasePS(hPS);
  595.         return(TRUE);
  596.     }
  597.  
  598.     /*****************************************************************/
  599.     /*      Time or Date values                                      */
  600.     /*****************************************************************/
  601.     if ( ( (hCurrentFocus == hTime) || (hCurrentFocus == hDate) ) &&
  602.          (!(SHORT1FROMMP(mp1) & KC_KEYUP)) &&
  603.          (SHORT1FROMMP(mp1) & KC_CHAR)) {
  604.  
  605.         /* check to make sure the value typed in is numeric */
  606.         /* if it is not numeric then beep and return true   */
  607.         if ((UserSpecifiedVal > '9') || (UserSpecifiedVal < '0')) {
  608.             WinAlarm (HWND_DESKTOP, WA_WARNING);
  609.             return (TRUE);
  610.         }
  611.  
  612.         /* otherwise it is a numeric value                        */
  613.         /* now change it from an ascii value to its numeric value */
  614.         UserSpecifiedVal -= 48;
  615.  
  616.         /*Freez time or date*/
  617.         if (hCurrentFocus == hTime) fTimeFreez = TRUE;
  618.         else fDateFreez = TRUE;
  619.  
  620.         /*Update value*/
  621.         Hit = ( (hCurrentFocus == hTime) ? (SHORT)TYPETIME : (SHORT)TYPEDATE);
  622.         hPS = WinGetPS(hwnd);
  623.         ChangeDateTime(hPS, hwnd, Hit, UserSpecifiedVal);
  624.         WinReleasePS(hPS);
  625.         return(TRUE);
  626.     }
  627.  
  628.  
  629.     return(TRUE);
  630. }
  631. /****************************************************************\
  632.  *
  633.  *--------------------------------------------------------------
  634.  *
  635.  *  Name:ChangeDateTime()
  636.  *
  637.  *  Purpose:
  638.  *     This function handles the user interface for changing the date and
  639.  *     time.
  640.  *
  641.  *
  642.  *  Usage:
  643.  *
  644.  *  Method:
  645.  *          -
  646.  *
  647.  *          -
  648.  *          -
  649.  *
  650.  *          -
  651.  *          -
  652.  *
  653.  *  Returns:
  654.  *
  655.  *
  656. \****************************************************************/
  657. VOID
  658. ChangeDateTime( HPS hpsPanel, HWND hwnd, SHORT HitRect, CHAR UserSpecifiedValue)
  659. {
  660.     SHORT onesdigit;
  661.     SHORT newvalue;
  662.     SHORT convertflag = FALSE;
  663.     SHORT savevalue;
  664.     COUNTRYCODE DosCyCode;
  665.     COUNTRYINFO DosCyInfo;
  666.     BOOL        DosCy;
  667.     USHORT      Country;
  668.     ULONG       iTemp;
  669.     SHORT       Position4;
  670.     SHORT       Position6;
  671.  
  672.     switch(HitRect)
  673.     {
  674.  
  675.     case HOUR:
  676.     case MINUTE:
  677.     case SECOND:
  678.         fTimeFreez = TRUE;
  679.         if (Selected == NOSELECT)      /* nothing selected           */
  680.             BringUpArrows(hwnd,HitRect);
  681.         else {                         /* take care of prev seln     */
  682.             if ( (Selected>=MONTH) && (Selected<=YEAR) ) {
  683.                                        /* if date item prev selected */
  684.                 PaintDateTime(hpsPanel);
  685.                 BringUpArrows(hwnd,HitRect);
  686.             }
  687.             wPrevDateTime[Selected] = -1; /* unhilite hilited */
  688.         }
  689.  
  690.         PreviousSelected = Selected;        /*save previously selected item */
  691.         Selected = HitRect;
  692.         PaintDateTime(hpsPanel);
  693.         break;
  694.  
  695.     case MONTH:
  696.     case DAY:
  697.     case YEAR:
  698.         fDateFreez = TRUE;
  699.         if (Selected == NOSELECT)      /* nothing selected           */
  700.             BringUpArrows(hwnd,HitRect);
  701.         else {                         /* take care of prev seln     */
  702.             if ( (Selected>=HOUR) && (Selected<=SECOND) ) {
  703.                                        /* if time item prev selected */
  704.                 BringUpArrows(hwnd,HitRect);
  705.             }
  706.             wPrevDateTime[Selected] = -1; /* unhilite hilited */
  707.         }
  708.         PreviousSelected = Selected;        /* @SNOR EviL save previously selected item */
  709.         Selected = HitRect;
  710.         PaintDateTime(hpsPanel);
  711.         break;
  712.  
  713.     case UPTIME:
  714.     case DOWNTIME:
  715.         if ( (Selected>=HOUR) && (Selected<=SECOND) ) {
  716.                                        /* if time item hilited       */
  717.             /* incr/decr */
  718.             if (HitRect == UPTIME)
  719.                 wDateTime[Selected] += 1;
  720.             else
  721.                 wDateTime[Selected] -= 1;
  722.  
  723.             /* take care of wraparound */
  724.             if (wDateTime[Selected] > wModulos[Selected])
  725.                 wDateTime[Selected] = HOUR;
  726.             if (wDateTime[Selected] < HOUR)
  727.                 wDateTime[Selected] = wModulos[Selected];
  728.  
  729.             PaintDateTime(hpsPanel);      /* show changed item          */
  730.         }
  731.         else
  732.             ChangeDateTime( hpsPanel,hwnd,
  733.                             (SHORT)( (HitRect == UPTIME) ? HOUR : SECOND), 0  );
  734.         break;
  735.  
  736.     case UPDATE:
  737.     case DOWNDATE:
  738.         if ( (Selected>=MONTH) && (Selected<=YEAR) ) {
  739.                                        /* if date item hilited       */
  740.  
  741.             /* incr/decr */
  742.             if (HitRect == UPDATE)
  743.                 wDateTime[Selected] += 1;
  744.             else
  745.                 wDateTime[Selected] -= 1;
  746.  
  747.             /* take care of wraparound */
  748.             FixDate(Selected);
  749.  
  750.             PaintDateTime(hpsPanel);      /* show changed item       */
  751.         }
  752.         else
  753.         {
  754.             /* determine which field to highlight by default for date field, */
  755.             /* depending on the date format for the particular country. */
  756.  
  757.             DosCyCode.country = 0;             /* Get default                */
  758.             DosCyCode.codepage = 0;            /* Get current process CP     */
  759.             DosCy = (BOOL) !DosGetCtryInfo( sizeof(COUNTRYINFO),
  760.                                      (PCOUNTRYCODE)&DosCyCode,
  761.                                      (PCOUNTRYINFO)&DosCyInfo,
  762.                                      (PULONG)&iTemp           );
  763.  
  764.             /*****************************************************************/
  765.             /*  If no info found by Dos, set USA                             */
  766.             /*****************************************************************/
  767.             Country = (USHORT) (DosCy ? DosCyInfo.country : COUNTRY_USA );
  768.  
  769.             /*****************************************************************/
  770.             /* that cool way of doing date format            @SNOR           */
  771.             /*****************************************************************/
  772.             iTemp = PrfQueryProfileInt( HINI_USER,
  773.                                         (PSZ)"PM_National",
  774.                                         (PSZ)"iDate",
  775.                                         (SHORT )( DosCy ? DosCyInfo.fsDateFmt
  776.                                                  : 0 )  );
  777.             switch(iTemp) {
  778.             case 2:
  779.                 /*************************************************************/
  780.                 /*                      YMD                  @SNOR           */
  781.                 /*************************************************************/
  782.                 Position4 = YEAR;
  783.                 Position6 = DAY;
  784.                 break;
  785.             case 1:
  786.                 /*************************************************************/
  787.                 /*                      DMY                  @SNOR           */
  788.                 /*************************************************************/
  789.                 Position4 = DAY;
  790.                 Position6 = YEAR;
  791.                 break;
  792.             case 0:
  793.             default:
  794.                 /*************************************************************/
  795.                 /*                      MDY        USA == default   @SNOR    */
  796.                 /*************************************************************/
  797.                 Position4 = MONTH;
  798.                 Position6 = YEAR;
  799.                 break;
  800.             }
  801.  
  802.             ChangeDateTime( hpsPanel, hwnd,
  803.                             (SHORT)
  804.                              ( (HitRect == UPDATE) ? Position4 : Position6) ,
  805.                                    0);
  806.         }
  807.         break;
  808.     case TYPETIME:
  809.         savevalue = wDateTime[Selected];
  810.  
  811.         /* if this is the first value typed in for this selected field, */
  812.         /* then replace it in the ones digit of the field               */
  813.         if (Selected != PreviousSelected) {
  814.  
  815.             /* treat hour with care if we are in 12 hr. format, */
  816.             /* cuz it is stored in 24 hour format.              */
  817.             /* convert it to 12 hour format, cuz that is what   */
  818.             /* the user sees on the screen, and then later      */
  819.             /* convert it back.                                 */
  820.             if ((Selected == HOUR) && bTwelveHourFormat) {
  821.                 if (wDateTime[HOUR] > 12) {
  822.                     wDateTime[HOUR] -= 12;
  823.                     convertflag = TRUE;
  824.                 }
  825.                 if (wDateTime[HOUR] == 0) {
  826.                     wDateTime[HOUR] = 12;
  827.                     convertflag = TRUE;
  828.                 }
  829.                 if (wDateTime[HOUR] == 12) {
  830.                     wDateTime[HOUR] = 0;
  831.                     convertflag = TRUE;
  832.                 }
  833.             }
  834.  
  835.             onesdigit = wDateTime[Selected] % (SHORT)10;
  836.             wDateTime[Selected] -= onesdigit;
  837.             wDateTime[Selected] += UserSpecifiedValue;
  838.  
  839.             /* if necessary, convert back to 24 hour format */
  840.             if (convertflag) {
  841.                 if (wDateTime[HOUR] > 12) {   /* invalid time */
  842.                     WinAlarm(HWND_DESKTOP, WA_WARNING);
  843.                     convertflag = FALSE;
  844.                     PreviousSelected = NOSELECT;
  845.                     wDateTime[HOUR] = savevalue;
  846.                     return;
  847.                 }
  848.                 else if (wDateTime[HOUR] == 12) {
  849.                     wDateTime[HOUR] = 0;
  850.                     convertflag = FALSE;
  851.                 }
  852.                 else {
  853.                     wDateTime[HOUR] += 12;
  854.                     convertflag = FALSE;
  855.                 }
  856.             }
  857.             PreviousSelected = Selected;
  858.         }
  859.  
  860.         /* otherwise, if this isnt the first value typed in for this      */
  861.         /* selected field, then insert it into the ones field             */
  862.         else {
  863.  
  864.  
  865.             /* treat hour with care if we are in 12 hr. format, */
  866.             /* cuz it is stored in 24 hour format.              */
  867.             /* convert it to 12 hour format, cuz that is what   */
  868.             /* the user sees on the screen, and then later      */
  869.             /* convert it back.                                 */
  870.             if ((Selected == HOUR) && bTwelveHourFormat) {
  871.                 if (wDateTime[HOUR] > 12) {
  872.                     wDateTime[HOUR] -= 12;
  873.                     convertflag = TRUE;
  874.                 }
  875.             }
  876.  
  877.             onesdigit           = wDateTime[Selected] % (SHORT)10;
  878.             wDateTime[Selected] = ( (onesdigit* (SHORT)10)+UserSpecifiedValue);
  879.  
  880.             /* handle invalid settings here */
  881.             if (Selected == HOUR){
  882.                 if ((bTwelveHourFormat) && (wDateTime[HOUR] > 12)){
  883.                     WinAlarm(HWND_DESKTOP, WA_WARNING);
  884.                     wDateTime[HOUR] = savevalue;
  885.                     PreviousSelected = NOSELECT;
  886.                     return;
  887.                 }
  888.                 else if ((!bTwelveHourFormat) && (wDateTime[HOUR] > 24)){
  889.                     WinAlarm(HWND_DESKTOP, WA_WARNING);
  890.                     wDateTime[HOUR] = savevalue;
  891.                     PreviousSelected = NOSELECT;
  892.                     return;
  893.                 }
  894.             }
  895.             if ((Selected == MINUTE) && (wDateTime[MINUTE] > 60)){
  896.                 WinAlarm(HWND_DESKTOP, WA_WARNING);
  897.                 wDateTime[MINUTE] = savevalue;
  898.                 PreviousSelected = NOSELECT;
  899.                 return;
  900.             }
  901.             if ((Selected == SECOND) && (wDateTime[SECOND] > 60)){
  902.                 WinAlarm(HWND_DESKTOP, WA_WARNING);
  903.                 wDateTime[SECOND] = savevalue;
  904.                 PreviousSelected = NOSELECT;
  905.                 return;
  906.             }  /* if it passes those tests then it is a valid setting */
  907.  
  908.             /* if necessary, convert back to 24 hour format */
  909.             if (convertflag) {
  910.                 if (wDateTime[HOUR] == 12) {
  911.                     wDateTime[HOUR] = 0;
  912.                     convertflag = FALSE;
  913.                 }
  914.                 else {
  915.                     wDateTime[HOUR] += 12;
  916.                     convertflag = FALSE;
  917.                 }
  918.             }
  919.         }
  920.  
  921.         /* finally, update screen                                          */
  922.         PaintDateTime(hpsPanel);
  923.         break;
  924.  
  925.     case TYPEDATE:                                          /* @SNOR EviL */
  926.         savevalue = wDateTime[Selected];
  927.  
  928.         /* if this is the first value typed in for this selected field, */
  929.         /* then replace it in the ones digit of the field               */
  930.         if (Selected != PreviousSelected)
  931.         {
  932.                 onesdigit = wDateTime[Selected] % (SHORT)10;
  933.                 wDateTime[Selected] -= onesdigit;
  934.                 wDateTime[Selected] += UserSpecifiedValue;
  935.                 PreviousSelected = Selected;
  936.         }
  937.  
  938.         /* otherwise, if this isnt the first value typed in for this      */
  939.         /* selected field, then insert it into the ones field             */
  940.         else {
  941.  
  942.             /* take special care not to trash the century if this is the */
  943.             /* year field.                                               */
  944.             if (Selected == YEAR) {
  945.                 onesdigit = wDateTime[Selected] % (SHORT)10;
  946.                 newvalue  = ((onesdigit* (SHORT)10)+UserSpecifiedValue);
  947.  
  948.                 if (newvalue >= (SHORT)80)
  949.                     wDateTime[Selected] = (SHORT)1900 + newvalue;
  950.                 else
  951.                     wDateTime[Selected] = (SHORT)2000 + newvalue;
  952.             }
  953.             else
  954.             {
  955.                 onesdigit           = wDateTime[Selected] % (SHORT)10;
  956.                 wDateTime[Selected] = ((onesdigit* (SHORT)10)+UserSpecifiedValue);
  957.             }
  958.         }
  959.  
  960.         /* test for valid value */
  961.         if ((Selected == MONTH) && (wDateTime[MONTH] > 12)){
  962.             WinAlarm(HWND_DESKTOP, WA_WARNING);
  963.             wDateTime[MONTH] = savevalue;
  964.             PreviousSelected = NOSELECT;
  965.             return;
  966.         }
  967.         if ((Selected == DAY) && (wDateTime[DAY] > 31)){
  968.             WinAlarm(HWND_DESKTOP, WA_WARNING);
  969.             wDateTime[DAY] = savevalue;
  970.             PreviousSelected = NOSELECT;
  971.             return;
  972.         }
  973.  
  974.         /* finally, update screen                                          */
  975.         PaintDateTime(hpsPanel);
  976.         break;
  977.  
  978.     default:                           /* outside relevant date/time */
  979.         if (Selected != NOSELECT) {    /* end "usSet" mode             */
  980.             wPrevDateTime[Selected] = -1; /* unhilite hilited        */
  981.             PreviousSelected = Selected;
  982.             Selected = NOSELECT;
  983.             PaintDateTime( hpsPanel);
  984.         }
  985.         break;
  986.  
  987.     }
  988. }
  989. /****************************************************************\
  990.  *
  991.  *--------------------------------------------------------------
  992.  *
  993.  *  Name:ControlMinMax()
  994.  *
  995.  *  Purpose:
  996.  *
  997.  *
  998.  *
  999.  *  Usage:
  1000.  *
  1001.  *  Method:
  1002.  *          -
  1003.  *
  1004.  *          -
  1005.  *          -
  1006.  *
  1007.  *          -
  1008.  *          -
  1009.  *
  1010.  *  Returns:
  1011.  *
  1012.  *
  1013. \****************************************************************/
  1014. VOID ControlMinmax( MPARAM mp1,HWND hwnd )
  1015. {
  1016.  
  1017.     bIsIconic = (BOOL)( (((PSWP)mp1)->fl & SWP_MINIMIZE) != (SHORT) 0);
  1018.  
  1019.     if ( bIsIconic )
  1020.     {
  1021.           /*
  1022.            *A bad thing in dialog boxes is that when they are minimized they
  1023.            *still draw there control windows over the supplied icon. So we
  1024.            *find if we are minimizing or restoring and hide the control window
  1025.            *in the left button, happen to be MBID_OK
  1026.            */
  1027.            WinShowWindow(WinWindowFromID(hwnd,MBID_OK),FALSE);
  1028.  
  1029.  
  1030.     }
  1031. }
  1032.  
  1033. /****************************************************************\
  1034.  *
  1035.  *--------------------------------------------------------------
  1036.  *
  1037.  *  Name:
  1038.  *
  1039.  *  Purpose:
  1040.  *
  1041.  *
  1042.  *
  1043.  *  Usage:
  1044.  *
  1045.  *  Method:
  1046.  *          -
  1047.  *
  1048.  *          -
  1049.  *          -
  1050.  *
  1051.  *          -
  1052.  *          -
  1053.  *
  1054.  *  Returns:
  1055.  *
  1056.  *
  1057. \****************************************************************/
  1058. VOID  PanelPaint(  HPS hpsPanel)
  1059. {
  1060.    SHORT   iter;
  1061.  
  1062.     /*****************************************************************/
  1063.     /*  Write the date and time                                      */
  1064.     /*****************************************************************/
  1065.  
  1066.     /*****************************************************************/
  1067.     /*  Paint static fields                                          */
  1068.     /*****************************************************************/
  1069.  
  1070.     for(iter=0; iter<2; iter++)
  1071.     {
  1072.         WinDrawText( hpsPanel,
  1073.                      -1,
  1074.                      (PSZ)szTimeSep,
  1075.                      (PRECTL)&rTimeSep[iter],
  1076.                      SYSCLR_WINDOWTEXT,
  1077.                      SYSCLR_WINDOW,
  1078.                      DT_CENTER | DT_VCENTER );
  1079.         WinDrawText( hpsPanel,
  1080.                      -1,
  1081.                      (PSZ)szDateSep,
  1082.                      (PRECTL)&rDateSep[iter],
  1083.                      SYSCLR_WINDOWTEXT,
  1084.                      SYSCLR_WINDOW,
  1085.                      DT_CENTER | DT_VCENTER );
  1086.     }
  1087.  
  1088.     /*****************************************************************/
  1089.     /*  Paint varying fields                                         */
  1090.     /*****************************************************************/
  1091.     if (Selected == NOSELECT)
  1092.     {
  1093.        if (!fDateFreez) GetDate();
  1094.        if (!fTimeFreez) GetTime();
  1095.     }
  1096.  
  1097.     for (iter=0;iter<6;iter++)    /* ensure all fields get painted   */
  1098.        wPrevDateTime[iter] = -1;
  1099.     PaintDateTime( hpsPanel);
  1100.  
  1101.  
  1102.     /*****************************************************************/
  1103.     /*  This call was causing a problem where hitting Alt when       */
  1104.     /*  Time or Date selected didn't get rid of Menu highlight.      */
  1105.     /*  I'm not sure what it was doing here anyway...                */
  1106.     /*****************************************************************/
  1107.  
  1108. }   /* End of PanelPaint */
  1109. /****************************************************************\
  1110.  *
  1111.  *--------------------------------------------------------------
  1112.  *
  1113.  *  Name:PaintDateTime()
  1114.  *
  1115.  *  Purpose:
  1116.  *
  1117.  *
  1118.  *
  1119.  *  Usage:
  1120.  *
  1121.  *  Method:
  1122.  *          -
  1123.  *
  1124.  *          -
  1125.  *          -
  1126.  *
  1127.  *          -
  1128.  *          -
  1129.  *
  1130.  *  Returns: VOID
  1131.  *
  1132.  *
  1133. \****************************************************************/
  1134. VOID  PaintDateTime(HPS hpsPanel)
  1135. {
  1136.     SHORT   iter;
  1137.     CHAR  szNumber[4];                 /* ascii value                */
  1138.     CHAR  szPadding[4];                /* pad numbers on left        */
  1139.     SHORT   wHourSave;                   /* hours altered for 12hr fmt  */
  1140.     SHORT   wYearSave;                   /* year moduloed 100          */
  1141.  
  1142.     /*****************************************************************/
  1143.     /*  Save hours and year first. Outside here yields: Cur. held     */
  1144.     /*  as DOS uses; Prev. as drawn in panel. Inside here: both      */
  1145.     /*  Cur and Prev drawn as in Panel.                              */
  1146.     /*****************************************************************/
  1147.     wHourSave = wDateTime[HOUR];
  1148.     wYearSave = wDateTime[YEAR];
  1149.  
  1150.     if (bTwelveHourFormat)
  1151.     {
  1152.         if (wDateTime[HOUR] > 12)
  1153.             wDateTime[HOUR] -= 12;
  1154.         if (wDateTime[HOUR] == 0)
  1155.             wDateTime[HOUR] = 12;
  1156.     }
  1157.  
  1158.     /*****************************************************************/
  1159.     /*  Set 1159 & 2359 (i.e. "am" "pm" etc.).                       */
  1160.     /*****************************************************************/
  1161.     if (wPrevDateTime[HOUR] != wDateTime[HOUR])
  1162.     {
  1163.         WinFillRect( hpsPanel,
  1164.                      (PRECTL)&rTimeSep[AM_PM],
  1165.                      SYSCLR_WINDOW             );
  1166.         WinDrawText( hpsPanel,
  1167.                      -1,
  1168.                      ( (wHourSave < 12) ? (PSZ)szAnteMeridian
  1169.                                         : (PSZ)szPostMeridian ),
  1170.                      (PRECTL)&rTimeSep[AM_PM],
  1171.                      SYSCLR_WINDOWTEXT,
  1172.                      SYSCLR_WINDOW,
  1173.                      DT_CENTER | DT_VCENTER );
  1174.     }
  1175.  
  1176.     /*****************************************************************/
  1177.     /*  Save the century for DOS                                     */
  1178.     /*****************************************************************/
  1179.     wDateTime[YEAR] %= 100;
  1180.  
  1181.     /*****************************************************************/
  1182.     /*  Write each field if changed or selected                      */
  1183.     /*****************************************************************/
  1184.     for (iter=0;iter< (SHORT) 6;iter++)
  1185.     {              /* (hh)-mm-ss/mm-dd-yy */
  1186.  
  1187.         if ( (wDateTime[iter] != wPrevDateTime[iter])
  1188.              || (iter == Selected)                    )
  1189.         {
  1190.  
  1191.             /*********************************************************/
  1192.             /*  Get the digit string                                 */
  1193.             /*********************************************************/
  1194.             _itoa(wDateTime[iter],szNumber,10);
  1195.  
  1196.             /*********************************************************/
  1197.             /*  Pad if less than 2 digits; blank pad iff             */
  1198.             /*  !bLeadingZero and is leftmost of time or date        */
  1199.             /*  (remember date format is dependent on coutry format) */
  1200.             /*********************************************************/
  1201.             if( wDateTime[iter]<10 )
  1202.             {
  1203.                 strcpy( szPadding,
  1204.                         ( !bLeadingZero
  1205.                           && ( (iter == HOUR) ||
  1206.                                ( rDateTime[iter].xLeft
  1207.                                  == rDateAssign[0].xLeft ) )
  1208.                           ? " "
  1209.                           : "0" )
  1210.                       );
  1211.  
  1212.                 strcat( szPadding, szNumber);
  1213.                 strcpy( szNumber, szPadding);
  1214.  
  1215.             }  /* endif <10 */
  1216.  
  1217.             /* draw field */
  1218.             WinFillRect( hpsPanel,
  1219.                          (PRECTL)&rDateTime[iter],
  1220.                          SYSCLR_WINDOW             );
  1221.             WinDrawText( hpsPanel,
  1222.                          -1,
  1223.                          (PSZ)szNumber,
  1224.                          (PRECTL)&rDateTime[iter],
  1225.                          SYSCLR_WINDOWTEXT,
  1226.                          SYSCLR_WINDOW,
  1227.                          DT_CENTER | DT_VCENTER );
  1228.  
  1229.             /* hilite if selected */
  1230.             if (iter == Selected)
  1231.                 WinInvertRect( hpsPanel,
  1232.                                (PRECTL)&rDateTime[iter]);
  1233.  
  1234.         }  /* end if != ... */
  1235.  
  1236.         /*************************************************************/
  1237.         /*  Set new previous datetime                                */
  1238.         /*************************************************************/
  1239.         wPrevDateTime[iter] = wDateTime[iter];
  1240.  
  1241.     }    /* end for */
  1242.  
  1243.     /*****************************************************************/
  1244.     /*  Restore hours and year for setting date/time                  */
  1245.     /*****************************************************************/
  1246.    wDateTime[HOUR] = wHourSave;
  1247.    wDateTime[YEAR] = wYearSave;
  1248.  
  1249. }
  1250. /****************************************************************\
  1251.  *
  1252.  *--------------------------------------------------------------
  1253.  *
  1254.  *  Name: GetTime
  1255.  *
  1256.  *  Purpose:
  1257.  *  Get the current date and time.
  1258.  *
  1259.  *
  1260.  *  Usage:
  1261.  *
  1262.  *  Method:
  1263.  *          -
  1264.  *
  1265.  *          -
  1266.  *          -
  1267.  *
  1268.  *          -
  1269.  *          -
  1270.  *
  1271.  *  Returns:
  1272.  *          1 - if sucessful execution completed
  1273.  *          0 - if error
  1274. \****************************************************************/
  1275. VOID  GetTime(VOID)
  1276. {
  1277.     struct _DATETIME DT;
  1278.  
  1279.     DosGetDateTime( (LPDT)&DT);
  1280.     wDateTime[HOUR]   = (USHORT)DT.hours;
  1281.     wDateTime[MINUTE] = (USHORT)DT.minutes;
  1282.     wDateTime[SECOND] = (USHORT)DT.seconds;
  1283. }
  1284. /****************************************************************\
  1285.  *
  1286.  *--------------------------------------------------------------
  1287.  *
  1288.  *  Name:GetDate()
  1289.  *
  1290.  *  Purpose:
  1291.  *
  1292.  *
  1293.  *
  1294.  *  Usage:
  1295.  *
  1296.  *  Method:
  1297.  *          -
  1298.  *
  1299.  *          -
  1300.  *          -
  1301.  *
  1302.  *          -
  1303.  *          -
  1304.  *
  1305.  *  Returns:
  1306.  *          1 - if sucessful execution completed
  1307.  *          0 - if error
  1308. \****************************************************************/
  1309. VOID  GetDate(VOID)
  1310. {
  1311.     struct _DATETIME DT;
  1312.  
  1313.     DosGetDateTime( (LPDT)&DT);
  1314.     wDateTime[MONTH] = (USHORT)DT.month;
  1315.     wDateTime[DAY]   = (USHORT)DT.day;
  1316.     wDateTime[YEAR]  =       DT.year; /* Year is two bytes          */
  1317. }
  1318.  
  1319. /****************************************************************\
  1320.  *
  1321.  *--------------------------------------------------------------
  1322.  *
  1323.  *  Name:PanelVScrolls()
  1324.  *
  1325.  *  Purpose:
  1326.  *
  1327.  *
  1328.  *
  1329.  *  Usage:
  1330.  *
  1331.  *  Method:
  1332.  *          -
  1333.  *
  1334.  *          -
  1335.  *          -
  1336.  *
  1337.  *          -
  1338.  *          -
  1339.  *
  1340.  *  Returns:
  1341.  *
  1342.  *
  1343. \****************************************************************/
  1344. VOID  PanelVScrolls(HWND hwnd,USHORT ScrollMsg,MPARAM idScroll)
  1345. {
  1346.     HPS  hpsPanel;
  1347.  
  1348.     hpsPanel = WinGetPS(hwnd);
  1349.     switch(ScrollMsg)
  1350.     {
  1351.     case SB_LINEUP:                    /* line left                  */
  1352.     case SB_PAGEUP:                    /* page left                  */
  1353.  
  1354.         if (idScroll == (MPARAM)SCROLL_TIME)
  1355.             ChangeDateTime( hpsPanel, hwnd, UPTIME,  0);
  1356.         else
  1357.             ChangeDateTime( hpsPanel, hwnd, UPDATE, 0);
  1358.         WinReleasePS( hpsPanel);
  1359.         break;
  1360.  
  1361.  
  1362.     case SB_LINEDOWN:                  /* line right                 */
  1363.     case SB_PAGEDOWN:                  /* page right                 */
  1364.  
  1365.         if (idScroll == (MPARAM)SCROLL_TIME)
  1366.             ChangeDateTime( hpsPanel, hwnd, DOWNTIME, 0);
  1367.         else
  1368.             ChangeDateTime( hpsPanel, hwnd, DOWNDATE, 0);
  1369.         WinReleasePS( hpsPanel);
  1370.         break;
  1371.  
  1372.     default:
  1373.         WinReleasePS( hpsPanel);
  1374.         break;
  1375.     }
  1376. }
  1377.  
  1378. /****************************************************************\
  1379.  *
  1380.  *--------------------------------------------------------------
  1381.  *
  1382.  *  Name:MouseTrack()
  1383.  *
  1384.  *  Purpose:
  1385.  *
  1386.  *
  1387.  *
  1388.  *  Usage:
  1389.  *
  1390.  *  Method:
  1391.  *          -
  1392.  *
  1393.  *          -
  1394.  *          -
  1395.  *
  1396.  *          -
  1397.  *          -
  1398.  *
  1399.  *  Returns:
  1400.  *          Offset for mouse pointer if the mouse was hit
  1401. \****************************************************************/
  1402. SHORT MouseTrack(MPARAM mp1)
  1403. {
  1404.     POINTL  ptl;
  1405.     SHORT   iter;
  1406.  
  1407.     ptl.x = (ULONG)LOUSHORT( mp1);
  1408.     ptl.y = (ULONG)HIUSHORT( mp1);
  1409.  
  1410.     for (iter=0;iter<6;iter++)
  1411.         if ( WinPtInRect( hab,
  1412.                           (PRECTL)&rDateTime[iter],
  1413.                           &ptl)      )
  1414.             return(iter);
  1415.  
  1416.     return(NOSELECT);
  1417. }
  1418. /****************************************************************\
  1419.  *
  1420.  *--------------------------------------------------------------
  1421.  *
  1422.  *  Name:GetCountryDependent()
  1423.  *
  1424.  *  Purpose:
  1425.  *
  1426.  *
  1427.  *
  1428.  *  Usage:
  1429.  *
  1430.  *  Method:
  1431.  *          -
  1432.  *
  1433.  *          -
  1434.  *          -
  1435.  *
  1436.  *          -
  1437.  *          -
  1438.  *
  1439.  *  Returns: VOID
  1440.  *
  1441.  *
  1442. \****************************************************************/
  1443. VOID GetCountryDependent(VOID )
  1444. {
  1445.     ULONG       iTemp;
  1446.     COUNTRYCODE DosCyCode;
  1447.     COUNTRYINFO DosCyInfo;
  1448.     USHORT      Country;
  1449.     BOOL        DosCy;
  1450.  
  1451.     /*****************************************************************/
  1452.     /*  Get the DOS country info to use as default if OS2.INI lacks. */
  1453.     /*****************************************************************/
  1454.     DosCyCode.country = 0;             /* Get default                */
  1455.     DosCyCode.codepage = 0;            /* Get current process CP     */
  1456.     DosCy = (BOOL) !DosGetCtryInfo( sizeof(COUNTRYINFO),
  1457.                              (PCOUNTRYCODE)&DosCyCode,
  1458.                              (PCOUNTRYINFO)&DosCyInfo,
  1459.                              (PULONG)&iTemp           );
  1460.     /*****************************************************************/
  1461.     /*  If no info found by Dos, set USA                             */
  1462.     /*****************************************************************/
  1463.     Country = (USHORT)( DosCy ? DosCyInfo.country : COUNTRY_USA) ;
  1464.  
  1465.     /*****************************************************************/
  1466.     /* get 12/24 hours format flag                                    */
  1467.     /*****************************************************************/
  1468.     iTemp = PrfQueryProfileInt( HINI_USER,
  1469.                                 (PSZ)"PM_National",
  1470.                                 (PSZ)"iTime",
  1471.                                 (SHORT) (DosCy ? DosCyInfo.fsTimeFmt
  1472.                                          : 0  ) );
  1473.     /*****************************************************************/
  1474.     /* 0 == twelve hours format; 1 == twenty-four hours format         */
  1475.     /*****************************************************************/
  1476.     bTwelveHourFormat = (BOOL) !iTemp;
  1477.  
  1478.     /*****************************************************************/
  1479.     /* leading zero                                                  */
  1480.     /*****************************************************************/
  1481.     bLeadingZero = (BOOL)PrfQueryProfileInt( HINI_USER,
  1482.                                              (PSZ)"PM_National",
  1483.                                              (PSZ)"iLzero",
  1484.                                              0                  );
  1485.  
  1486.  
  1487.     /*****************************************************************/
  1488.     /* date separator string                                         */
  1489.     /*****************************************************************/
  1490.     PrfQueryProfileString( HINI_USER,
  1491.                            (PSZ)"PM_National",
  1492.                            (PSZ)"sDate",
  1493.                            DosCy ? (PSZ)DosCyInfo.szDateSeparator
  1494.                                  : (PSZ)"/",
  1495.                            (PSZ)szDateSep,
  1496.                            (ULONG)DATE_SEP_LEN+1                         );
  1497.  
  1498.  
  1499.     /*****************************************************************/
  1500.     /* time separator string                                         */
  1501.     /*****************************************************************/
  1502.     PrfQueryProfileString( HINI_USER,
  1503.                            (PSZ)"PM_National",
  1504.                            (PSZ)"sTime",
  1505.                            DosCy ? (PSZ)DosCyInfo.szTimeSeparator
  1506.                                  : (PSZ)":",
  1507.                            (PSZ)szTimeSep,
  1508.                            (ULONG)TIME_SEP_LEN+1                         );
  1509.  
  1510.     /*****************************************************************/
  1511.     /* AM/PM strings                                                 */
  1512.     /*****************************************************************/
  1513.     PrfQueryProfileString( HINI_USER,
  1514.                            (PSZ)"PM_National",
  1515.                            (PSZ)"s1159",
  1516.                            Country == COUNTRY_USA
  1517.                             ? (PSZ)"AM"
  1518.                             : Country == COUNTRY_UK
  1519.                               ? (PSZ)"am"
  1520.                               : (PSZ)"",
  1521.                            (PSZ)szAnteMeridian,
  1522.                            (ULONG)STRING_AM_LEN+1           );
  1523.     PrfQueryProfileString( HINI_USER,
  1524.                            (PSZ)"PM_National",
  1525.                            (PSZ)"s2359",
  1526.                            Country == COUNTRY_USA
  1527.                             ? (PSZ)"PM"
  1528.                             : Country == COUNTRY_UK
  1529.                               ? (PSZ)"pm"
  1530.                               : (PSZ)"",
  1531.                            (PSZ)szPostMeridian,
  1532.                            (ULONG)STRING_PM_LEN+1           );
  1533.  
  1534.     sFirstTime = HOUR;
  1535.     asLeftOf[HOUR] = SECOND;
  1536.     asLeftOf[MINUTE] = HOUR;
  1537.     asLeftOf[SECOND] = MINUTE;
  1538.     asRightOf[HOUR] = MINUTE;
  1539.     asRightOf[MINUTE] = SECOND;
  1540.     asRightOf[SECOND] = HOUR;
  1541.  
  1542.     /*****************************************************************/
  1543.     /* that cool way of doing date format                            */
  1544.     /*****************************************************************/
  1545.     vusDateFormat = iTemp = PrfQueryProfileInt( HINI_USER,
  1546.                                 (PSZ)"PM_National",
  1547.                                 (PSZ)"iDate",
  1548.                                 (SHORT ) ( DosCy ? DosCyInfo.fsDateFmt
  1549.                                           : 0 )  );
  1550.     switch(iTemp)
  1551.     {
  1552.     case 2:
  1553.         /*************************************************************/
  1554.         /*                      YMD                                  */
  1555.         /*************************************************************/
  1556.         WinCopyRect( hab,
  1557.                      (PRECTL)&rDateTime[YEAR],
  1558.                      (PRECTL)&rDateAssign[0]    );
  1559.         WinCopyRect( hab,
  1560.                      (PRECTL)&rDateTime[MONTH],
  1561.                      (PRECTL)&rDateAssign[1]    );
  1562.         WinCopyRect( hab,
  1563.                      (PRECTL)&rDateTime[DAY],
  1564.                      (PRECTL)&rDateAssign[2]    );
  1565.         sFirstDate = YEAR;
  1566.         asLeftOf[YEAR] = DAY;
  1567.         asLeftOf[MONTH] = YEAR;
  1568.         asLeftOf[DAY] = MONTH;
  1569.         asRightOf[YEAR] = MONTH;
  1570.         asRightOf[MONTH] = DAY;
  1571.         asRightOf[DAY] = YEAR;
  1572.         break;
  1573.     case 1:
  1574.         /*************************************************************/
  1575.         /*                      DMY                                  */
  1576.         /*************************************************************/
  1577.         WinCopyRect( hab,
  1578.                      (PRECTL)&rDateTime[DAY],
  1579.                      (PRECTL)&rDateAssign[0]    );
  1580.         WinCopyRect( hab,
  1581.                      (PRECTL)&rDateTime[MONTH],
  1582.                      (PRECTL)&rDateAssign[1]    );
  1583.         WinCopyRect( hab,
  1584.                      (PRECTL)&rDateTime[YEAR],
  1585.                      (PRECTL)&rDateAssign[2]    );
  1586.         sFirstDate = DAY;
  1587.         asLeftOf[YEAR] = MONTH;
  1588.         asLeftOf[MONTH] = DAY;
  1589.         asLeftOf[DAY] = YEAR;
  1590.         asRightOf[YEAR] = DAY;
  1591.         asRightOf[MONTH] = YEAR;
  1592.         asRightOf[DAY] = MONTH;
  1593.         break;
  1594.     case 0:
  1595.     default:
  1596.         /*************************************************************/
  1597.         /*                      MDY        USA == default            */
  1598.         /*************************************************************/
  1599.         WinCopyRect( hab,
  1600.                      (PRECTL)&rDateTime[MONTH],
  1601.                      (PRECTL)&rDateAssign[0]    );
  1602.         WinCopyRect( hab,
  1603.                      (PRECTL)&rDateTime[DAY],
  1604.                      (PRECTL)&rDateAssign[1]    );
  1605.         WinCopyRect( hab,
  1606.                      (PRECTL)&rDateTime[YEAR],
  1607.                      (PRECTL)&rDateAssign[2]    );
  1608.         sFirstDate = MONTH;
  1609.         asLeftOf[YEAR] = DAY;
  1610.         asLeftOf[MONTH] = YEAR;
  1611.         asLeftOf[DAY] = MONTH;
  1612.         asRightOf[YEAR] = MONTH;
  1613.         asRightOf[MONTH] = DAY;
  1614.         asRightOf[DAY] = YEAR;
  1615.         break;
  1616.     }
  1617.  
  1618.  
  1619. }
  1620. /****************************************************************\
  1621.  *
  1622.  *--------------------------------------------------------------
  1623.  *
  1624.  *  Name:BringUpArrows.
  1625.  *
  1626.  *  Purpose:
  1627.  *    Take care of up down arrows
  1628.  *
  1629.  *
  1630.  *  Usage:
  1631.  *
  1632.  *  Method:
  1633.  *          -
  1634.  *
  1635.  *          -
  1636.  *          -
  1637.  *
  1638.  *          -
  1639.  *          -
  1640.  *
  1641.  *  Returns:
  1642.  *
  1643.  *
  1644. \****************************************************************/
  1645. VOID BringUpArrows(HWND hwnd,SHORT Item)
  1646. {
  1647.  
  1648.    if( (Item>=HOUR) && (Item<=SECOND) )
  1649.    {     /* time item           */
  1650.  
  1651.       /* Set focus to current groupbox if control panel has focus */
  1652.       if ( WinQueryWindow(WinQueryFocus(HWND_DESKTOP), QW_PARENT) == hwnd )
  1653.       {
  1654.          WinSetFocus(HWND_DESKTOP, hTime);
  1655.          hCurrentFocus = hTime;
  1656.  
  1657.       }
  1658.    } /* endif time */
  1659.  
  1660.    else if( (Item>=MONTH) && (Item<=YEAR) )
  1661.    {   /* date item         */
  1662.  
  1663.       /* Set focus to current groupbox if control panel has focus */
  1664.       if ( WinQueryWindow(WinQueryFocus(HWND_DESKTOP), QW_PARENT) == hwnd)
  1665.       {
  1666.          WinSetFocus(HWND_DESKTOP, hDate);
  1667.          hCurrentFocus = hDate;
  1668.  
  1669.  
  1670.       }
  1671.    } /* endif Date */
  1672.  
  1673. }
  1674.  
  1675. /****************************************************************\
  1676.  *
  1677.  *--------------------------------------------------------------
  1678.  *
  1679.  *  Name: FixDate
  1680.  *
  1681.  *  Purpose:
  1682.  *  Takes care of date wraparound
  1683.  *
  1684.  *
  1685.  *  Usage:
  1686.  *
  1687.  *  Method:
  1688.  *          -
  1689.  *
  1690.  *          -
  1691.  *          -
  1692.  *
  1693.  *          -
  1694.  *          -
  1695.  *
  1696.  *  Returns:
  1697.  *
  1698.  *
  1699. \****************************************************************/
  1700. VOID  FixDate(SHORT Field)
  1701. {
  1702.     switch(Field)
  1703.     {
  1704.     case MONTH:
  1705.         if (wDateTime[MONTH] > 12)
  1706.             wDateTime[MONTH] = 1;
  1707.         if (wDateTime[MONTH] < 1)
  1708.             wDateTime[MONTH] = 12;
  1709.         FixDate(DAY);                    /* keep day in new bounds   */
  1710.         break;
  1711.  
  1712.     case DAY:
  1713.         /* check for leap year */
  1714.         if ( ( (wDateTime[YEAR] % 4 == 0 && wDateTime[YEAR] % 100 != 0)
  1715.                || wDateTime[YEAR] % 400 == 0
  1716.              ) && wDateTime[MONTH] == 2
  1717.            ) {
  1718.             if(wDateTime[DAY] > 29) wDateTime[DAY] = 1;
  1719.             if(wDateTime[DAY] < 1) wDateTime[DAY] = 29;
  1720.         }
  1721.         else
  1722.         {   /* non-leap year   */
  1723.             if (wDateTime[DAY] > DaysPerMonth[wDateTime[MONTH]])
  1724.                 wDateTime[DAY] = 1;
  1725.             if (wDateTime[DAY] < 1)
  1726.                 wDateTime[DAY] = DaysPerMonth[wDateTime[MONTH]];
  1727.         }
  1728.         break;
  1729.  
  1730.     case YEAR:
  1731.         if (wDateTime[YEAR] > 2079)
  1732.             wDateTime[YEAR] = 1980;
  1733.         if (wDateTime[YEAR] < 1980)
  1734.             wDateTime[YEAR] = 2079;
  1735.         FixDate(DAY);                    /* for leap yr. to non-leap */
  1736.         break;
  1737.  
  1738.    }
  1739.  
  1740. }
  1741.  
  1742.  
  1743. /****************************************************************\
  1744.  *
  1745.  *--------------------------------------------------------------
  1746.  *
  1747.  *  Name:Settime
  1748.  *
  1749.  *  Purpose:
  1750.  *  Sets the system time.
  1751.  *
  1752.  *
  1753.  *  Usage:
  1754.  *
  1755.  *  Method:
  1756.  *          -
  1757.  *
  1758.  *          -
  1759.  *          -
  1760.  *
  1761.  *          -
  1762.  *          -
  1763.  *
  1764.  *  Returns:
  1765.  *          1 - if sucessful execution completed
  1766.  *          0 - if error
  1767. \****************************************************************/
  1768. VOID  SetTime(VOID)
  1769. {
  1770.     struct _DATETIME DT;
  1771.     APIRET rc;
  1772.  
  1773.     DosGetDateTime( (LPDT)&DT);
  1774.     DT.hours   = (BYTE)wDateTime[HOUR]  ;
  1775.     DT.minutes = (BYTE)wDateTime[MINUTE];
  1776.     DT.seconds = (BYTE)wDateTime[SECOND];
  1777.     rc = DosSetDateTime( (LPDT)&DT);
  1778.     if (rc)
  1779.     {
  1780.           WinAlarm(HWND_DESKTOP, WA_WARNING);
  1781.     }
  1782.     /*
  1783.      *if the alarm
  1784.      *is set then update
  1785.      *it
  1786.      */
  1787.      if(cp.alarm.usMode & AM_ACTIVE )
  1788.      {
  1789.           AlarmSetTimer(cp.alarm.uchHour,
  1790.                               cp.alarm.uchMinutes);
  1791.      }
  1792.  
  1793. }
  1794. /****************************************************************\
  1795.  *
  1796.  *--------------------------------------------------------------
  1797.  *
  1798.  *  Name:SetDate()
  1799.  *
  1800.  *  Purpose:
  1801.  *  Set system date.
  1802.  *
  1803.  *
  1804.  *  Usage:
  1805.  *
  1806.  *  Method:
  1807.  *          -
  1808.  *
  1809.  *          -
  1810.  *          -
  1811.  *
  1812.  *          -
  1813.  *          -
  1814.  *
  1815.  *  Returns: VOID
  1816.  *
  1817.  *
  1818. \****************************************************************/
  1819. VOID SetDate(VOID)
  1820. {
  1821.     struct _DATETIME DT;
  1822.     APIRET rc;
  1823.  
  1824.     DosGetDateTime( (LPDT)&DT);
  1825.     DT.month = (BYTE)wDateTime[MONTH];
  1826.     DT.day   = (BYTE)wDateTime[DAY]  ;
  1827.     DT.year  =       wDateTime[YEAR] ; /* Year is two bytes          */
  1828.     rc = DosSetDateTime( (LPDT)&DT);
  1829.     if (rc)
  1830.     {
  1831.           WinAlarm(HWND_DESKTOP, WA_WARNING);
  1832.     }
  1833.  
  1834.     /*
  1835.      *if the alarm
  1836.      *is set then update
  1837.      *it
  1838.      */
  1839.      if(cp.alarm.usMode & AM_ACTIVE )
  1840.      {
  1841.  
  1842.           AlarmSetTimer(cp.alarm.uchHour,
  1843.                               cp.alarm.uchMinutes);
  1844.      }
  1845. }
  1846.  
  1847. /*--------------------------------------------------------------*\
  1848.  *  End of file :udtime.c
  1849. \*--------------------------------------------------------------*/
  1850.