home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / os2 / timeserv / udtime.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  61KB  |  1,857 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 3:
  528.             /*************************************************************/
  529.             /*                      YDM                                  */
  530.             /*************************************************************/
  531.             Position4 = YEAR;
  532.             Position6 = MONTH;
  533.             break;
  534.         case 2:
  535.             /*************************************************************/
  536.             /*                      YMD                                  */
  537.             /*************************************************************/
  538.             Position4 = YEAR;
  539.             Position6 = DAY;
  540.             break;
  541.         case 1:
  542.             /*************************************************************/
  543.             /*                      DMY                                  */
  544.             /*************************************************************/
  545.             Position4 = DAY;
  546.             Position6 = YEAR;
  547.             break;
  548.         case 0:
  549.         default:
  550.             /*************************************************************/
  551.             /*                      MDY        USA == default            */
  552.             /*************************************************************/
  553.             Position4 = MONTH;
  554.             Position6 = YEAR;
  555.             break;
  556.         }
  557.  
  558.         switch(Key)
  559.         {
  560.  
  561.  
  562.         case VK_UP:
  563.             if (Selected == NOSELECT)
  564.                 Hit = ( (hCurrentFocus == hTime) ? (SHORT) HOUR : Position4);
  565.             else
  566.                 Hit = ((hCurrentFocus == hTime) ? (SHORT)UPTIME : (SHORT)UPDATE);
  567.             break;
  568.         case VK_DOWN:
  569.             if (Selected == NOSELECT)
  570.                 Hit = ((hCurrentFocus == hTime) ? (SHORT) SECOND : Position6);
  571.             else
  572.                 Hit = ((hCurrentFocus == hTime) ? (SHORT) DOWNTIME : (SHORT)DOWNDATE);
  573.             break;
  574.         case VK_LEFT:
  575.             if (Selected == NOSELECT)
  576.                 Hit = ((hCurrentFocus == hTime) ?  (SHORT)SECOND : Position4);
  577.             break;
  578.         case VK_RIGHT:
  579.             if (Selected == NOSELECT)
  580.                 Hit = ((hCurrentFocus == hTime) ? (SHORT)HOUR : Position6);
  581.             break;
  582.         default:
  583.             return(TRUE);
  584.             break;
  585.         }
  586.  
  587.         hPS = WinGetPS(hwnd);
  588.         for ( iter = 0;
  589.               iter < (SHORT)CHAR3FROMMP(mp1);
  590.               iter++                   ) { /* repeatcount times      */
  591.  
  592.             if (Key == VK_LEFT) {
  593.                 Hit = asLeftOf[Hit];
  594.             }
  595.             if (Key == VK_RIGHT) {
  596.                 Hit = asRightOf[Hit];
  597.             }
  598.  
  599.             ChangeDateTime(hPS, hwnd, Hit, 0);
  600.         }
  601.         WinReleasePS(hPS);
  602.         return(TRUE);
  603.     }
  604.  
  605.     /*****************************************************************/
  606.     /*      Time or Date values                                      */
  607.     /*****************************************************************/
  608.     if ( ( (hCurrentFocus == hTime) || (hCurrentFocus == hDate) ) &&
  609.          (!(SHORT1FROMMP(mp1) & KC_KEYUP)) &&
  610.          (SHORT1FROMMP(mp1) & KC_CHAR)) {
  611.  
  612.         /* check to make sure the value typed in is numeric */
  613.         /* if it is not numeric then beep and return true   */
  614.         if ((UserSpecifiedVal > '9') || (UserSpecifiedVal < '0')) {
  615.             WinAlarm (HWND_DESKTOP, WA_WARNING);
  616.             return (TRUE);
  617.         }
  618.  
  619.         /* otherwise it is a numeric value                        */
  620.         /* now change it from an ascii value to its numeric value */
  621.         UserSpecifiedVal -= 48;
  622.  
  623.         /*Freez time or date*/
  624.         if (hCurrentFocus == hTime) fTimeFreez = TRUE;
  625.         else fDateFreez = TRUE;
  626.  
  627.         /*Update value*/
  628.         Hit = ( (hCurrentFocus == hTime) ? (SHORT)TYPETIME : (SHORT)TYPEDATE);
  629.         hPS = WinGetPS(hwnd);
  630.         ChangeDateTime(hPS, hwnd, Hit, UserSpecifiedVal);
  631.         WinReleasePS(hPS);
  632.         return(TRUE);
  633.     }
  634.  
  635.  
  636.     return(TRUE);
  637. }
  638. /****************************************************************\
  639.  *
  640.  *--------------------------------------------------------------
  641.  *
  642.  *  Name:ChangeDateTime()
  643.  *
  644.  *  Purpose:
  645.  *     This function handles the user interface for changing the date and
  646.  *     time.
  647.  *
  648.  *
  649.  *  Usage:
  650.  *
  651.  *  Method:
  652.  *          -
  653.  *
  654.  *          -
  655.  *          -
  656.  *
  657.  *          -
  658.  *          -
  659.  *
  660.  *  Returns:
  661.  *
  662.  *
  663. \****************************************************************/
  664. VOID
  665. ChangeDateTime( HPS hpsPanel, HWND hwnd, SHORT HitRect, CHAR UserSpecifiedValue)
  666. {
  667.     SHORT onesdigit;
  668.     SHORT newvalue;
  669.     SHORT convertflag = FALSE;
  670.     SHORT savevalue;
  671.     COUNTRYCODE DosCyCode;
  672.     COUNTRYINFO DosCyInfo;
  673.     BOOL        DosCy;
  674.     USHORT      Country;
  675.     ULONG       iTemp;
  676.     SHORT       Position4;
  677.     SHORT       Position6;
  678.  
  679.     switch(HitRect)
  680.     {
  681.  
  682.     case HOUR:
  683.     case MINUTE:
  684.     case SECOND:
  685.         fTimeFreez = TRUE;
  686.         if (Selected == NOSELECT)      /* nothing selected           */
  687.             BringUpArrows(hwnd,HitRect);
  688.         else {                         /* take care of prev seln     */
  689.             if ( (Selected>=MONTH) && (Selected<=YEAR) ) {
  690.                                        /* if date item prev selected */
  691.                 PaintDateTime(hpsPanel);
  692.                 BringUpArrows(hwnd,HitRect);
  693.             }
  694.             wPrevDateTime[Selected] = -1; /* unhilite hilited */
  695.         }
  696.  
  697.         PreviousSelected = Selected;        /*save previously selected item */
  698.         Selected = HitRect;
  699.         PaintDateTime(hpsPanel);
  700.         break;
  701.  
  702.     case MONTH:
  703.     case DAY:
  704.     case YEAR:
  705.         fDateFreez = TRUE;
  706.         if (Selected == NOSELECT)      /* nothing selected           */
  707.             BringUpArrows(hwnd,HitRect);
  708.         else {                         /* take care of prev seln     */
  709.             if ( (Selected>=HOUR) && (Selected<=SECOND) ) {
  710.                                        /* if time item prev selected */
  711.                 BringUpArrows(hwnd,HitRect);
  712.             }
  713.             wPrevDateTime[Selected] = -1; /* unhilite hilited */
  714.         }
  715.         PreviousSelected = Selected;        /* @SNOR EviL save previously selected item */
  716.         Selected = HitRect;
  717.         PaintDateTime(hpsPanel);
  718.         break;
  719.  
  720.     case UPTIME:
  721.     case DOWNTIME:
  722.         if ( (Selected>=HOUR) && (Selected<=SECOND) ) {
  723.                                        /* if time item hilited       */
  724.             /* incr/decr */
  725.             if (HitRect == UPTIME)
  726.                 wDateTime[Selected] += 1;
  727.             else
  728.                 wDateTime[Selected] -= 1;
  729.  
  730.             /* take care of wraparound */
  731.             if (wDateTime[Selected] > wModulos[Selected])
  732.                 wDateTime[Selected] = HOUR;
  733.             if (wDateTime[Selected] < HOUR)
  734.                 wDateTime[Selected] = wModulos[Selected];
  735.  
  736.             PaintDateTime(hpsPanel);      /* show changed item          */
  737.         }
  738.         else
  739.             ChangeDateTime( hpsPanel,hwnd,
  740.                             (SHORT)( (HitRect == UPTIME) ? HOUR : SECOND), 0  );
  741.         break;
  742.  
  743.     case UPDATE:
  744.     case DOWNDATE:
  745.         if ( (Selected>=MONTH) && (Selected<=YEAR) ) {
  746.                                        /* if date item hilited       */
  747.  
  748.             /* incr/decr */
  749.             if (HitRect == UPDATE)
  750.                 wDateTime[Selected] += 1;
  751.             else
  752.                 wDateTime[Selected] -= 1;
  753.  
  754.             /* take care of wraparound */
  755.             FixDate(Selected);
  756.  
  757.             PaintDateTime(hpsPanel);      /* show changed item       */
  758.         }
  759.         else
  760.         {
  761.             /* determine which field to highlight by default for date field, */
  762.             /* depending on the date format for the particular country. */
  763.  
  764.             DosCyCode.country = 0;             /* Get default                */
  765.             DosCyCode.codepage = 0;            /* Get current process CP     */
  766.             DosCy = (BOOL) !DosGetCtryInfo( sizeof(COUNTRYINFO),
  767.                                      (PCOUNTRYCODE)&DosCyCode,
  768.                                      (PCOUNTRYINFO)&DosCyInfo,
  769.                                      (PULONG)&iTemp           );
  770.  
  771.             /*****************************************************************/
  772.             /*  If no info found by Dos, set USA                             */
  773.             /*****************************************************************/
  774.             Country = (USHORT) (DosCy ? DosCyInfo.country : COUNTRY_USA );
  775.  
  776.             /*****************************************************************/
  777.             /* that cool way of doing date format            @SNOR           */
  778.             /*****************************************************************/
  779.             iTemp = PrfQueryProfileInt( HINI_USER,
  780.                                         (PSZ)"PM_National",
  781.                                         (PSZ)"iDate",
  782.                                         (SHORT )( DosCy ? DosCyInfo.fsDateFmt
  783.                                                  : 0 )  );
  784.             switch(iTemp) {
  785.             case 2:
  786.                 /*************************************************************/
  787.                 /*                      YMD                  @SNOR           */
  788.                 /*************************************************************/
  789.                 Position4 = YEAR;
  790.                 Position6 = DAY;
  791.                 break;
  792.             case 1:
  793.                 /*************************************************************/
  794.                 /*                      DMY                  @SNOR           */
  795.                 /*************************************************************/
  796.                 Position4 = DAY;
  797.                 Position6 = YEAR;
  798.                 break;
  799.             case 0:
  800.             default:
  801.                 /*************************************************************/
  802.                 /*                      MDY        USA == default   @SNOR    */
  803.                 /*************************************************************/
  804.                 Position4 = MONTH;
  805.                 Position6 = YEAR;
  806.                 break;
  807.             }
  808.  
  809.             ChangeDateTime( hpsPanel, hwnd,
  810.                             (SHORT)
  811.                              ( (HitRect == UPDATE) ? Position4 : Position6) ,
  812.                                    0);
  813.         }
  814.         break;
  815.     case TYPETIME:
  816.         savevalue = wDateTime[Selected];
  817.  
  818.         /* if this is the first value typed in for this selected field, */
  819.         /* then replace it in the ones digit of the field               */
  820.         if (Selected != PreviousSelected) {
  821.  
  822.             /* treat hour with care if we are in 12 hr. format, */
  823.             /* cuz it is stored in 24 hour format.              */
  824.             /* convert it to 12 hour format, cuz that is what   */
  825.             /* the user sees on the screen, and then later      */
  826.             /* convert it back.                                 */
  827.             if ((Selected == HOUR) && bTwelveHourFormat) {
  828.                 if (wDateTime[HOUR] > 12) {
  829.                     wDateTime[HOUR] -= 12;
  830.                     convertflag = TRUE;
  831.                 }
  832.                 if (wDateTime[HOUR] == 0) {
  833.                     wDateTime[HOUR] = 12;
  834.                     convertflag = TRUE;
  835.                 }
  836.                 if (wDateTime[HOUR] == 12) {
  837.                     wDateTime[HOUR] = 0;
  838.                     convertflag = TRUE;
  839.                 }
  840.             }
  841.  
  842.             onesdigit = wDateTime[Selected] % (SHORT)10;
  843.             wDateTime[Selected] -= onesdigit;
  844.             wDateTime[Selected] += UserSpecifiedValue;
  845.  
  846.             /* if necessary, convert back to 24 hour format */
  847.             if (convertflag) {
  848.                 if (wDateTime[HOUR] > 12) {   /* invalid time */
  849.                     WinAlarm(HWND_DESKTOP, WA_WARNING);
  850.                     convertflag = FALSE;
  851.                     PreviousSelected = NOSELECT;
  852.                     wDateTime[HOUR] = savevalue;
  853.                     return;
  854.                 }
  855.                 else if (wDateTime[HOUR] == 12) {
  856.                     wDateTime[HOUR] = 0;
  857.                     convertflag = FALSE;
  858.                 }
  859.                 else {
  860.                     wDateTime[HOUR] += 12;
  861.                     convertflag = FALSE;
  862.                 }
  863.             }
  864.             PreviousSelected = Selected;
  865.         }
  866.  
  867.         /* otherwise, if this isnt the first value typed in for this      */
  868.         /* selected field, then insert it into the ones field             */
  869.         else {
  870.  
  871.  
  872.             /* treat hour with care if we are in 12 hr. format, */
  873.             /* cuz it is stored in 24 hour format.              */
  874.             /* convert it to 12 hour format, cuz that is what   */
  875.             /* the user sees on the screen, and then later      */
  876.             /* convert it back.                                 */
  877.             if ((Selected == HOUR) && bTwelveHourFormat) {
  878.                 if (wDateTime[HOUR] > 12) {
  879.                     wDateTime[HOUR] -= 12;
  880.                     convertflag = TRUE;
  881.                 }
  882.             }
  883.  
  884.             onesdigit           = wDateTime[Selected] % (SHORT)10;
  885.             wDateTime[Selected] = ( (onesdigit* (SHORT)10)+UserSpecifiedValue);
  886.  
  887.             /* handle invalid settings here */
  888.             if (Selected == HOUR){
  889.                 if ((bTwelveHourFormat) && (wDateTime[HOUR] > 12)){
  890.                     WinAlarm(HWND_DESKTOP, WA_WARNING);
  891.                     wDateTime[HOUR] = savevalue;
  892.                     PreviousSelected = NOSELECT;
  893.                     return;
  894.                 }
  895.                 else if ((!bTwelveHourFormat) && (wDateTime[HOUR] > 24)){
  896.                     WinAlarm(HWND_DESKTOP, WA_WARNING);
  897.                     wDateTime[HOUR] = savevalue;
  898.                     PreviousSelected = NOSELECT;
  899.                     return;
  900.                 }
  901.             }
  902.             if ((Selected == MINUTE) && (wDateTime[MINUTE] > 60)){
  903.                 WinAlarm(HWND_DESKTOP, WA_WARNING);
  904.                 wDateTime[MINUTE] = savevalue;
  905.                 PreviousSelected = NOSELECT;
  906.                 return;
  907.             }
  908.             if ((Selected == SECOND) && (wDateTime[SECOND] > 60)){
  909.                 WinAlarm(HWND_DESKTOP, WA_WARNING);
  910.                 wDateTime[SECOND] = savevalue;
  911.                 PreviousSelected = NOSELECT;
  912.                 return;
  913.             }  /* if it passes those tests then it is a valid setting */
  914.  
  915.             /* if necessary, convert back to 24 hour format */
  916.             if (convertflag) {
  917.                 if (wDateTime[HOUR] == 12) {
  918.                     wDateTime[HOUR] = 0;
  919.                     convertflag = FALSE;
  920.                 }
  921.                 else {
  922.                     wDateTime[HOUR] += 12;
  923.                     convertflag = FALSE;
  924.                 }
  925.             }
  926.         }
  927.  
  928.         /* finally, update screen                                          */
  929.         PaintDateTime(hpsPanel);
  930.         break;
  931.  
  932.     case TYPEDATE:                                          /* @SNOR EviL */
  933.         savevalue = wDateTime[Selected];
  934.  
  935.         /* if this is the first value typed in for this selected field, */
  936.         /* then replace it in the ones digit of the field               */
  937.         if (Selected != PreviousSelected)
  938.         {
  939.                 onesdigit = wDateTime[Selected] % (SHORT)10;
  940.                 wDateTime[Selected] -= onesdigit;
  941.                 wDateTime[Selected] += UserSpecifiedValue;
  942.                 PreviousSelected = Selected;
  943.         }
  944.  
  945.         /* otherwise, if this isnt the first value typed in for this      */
  946.         /* selected field, then insert it into the ones field             */
  947.         else {
  948.  
  949.             /* take special care not to trash the century if this is the */
  950.             /* year field.                                               */
  951.             if (Selected == YEAR) {
  952.                 onesdigit = wDateTime[Selected] % (SHORT)10;
  953.                 newvalue  = ((onesdigit* (SHORT)10)+UserSpecifiedValue);
  954.  
  955.                 if (newvalue >= (SHORT)80)
  956.                     wDateTime[Selected] = (SHORT)1900 + newvalue;
  957.                 else
  958.                     wDateTime[Selected] = (SHORT)2000 + newvalue;
  959.             }
  960.             else
  961.             {
  962.                 onesdigit           = wDateTime[Selected] % (SHORT)10;
  963.                 wDateTime[Selected] = ((onesdigit* (SHORT)10)+UserSpecifiedValue);
  964.             }
  965.         }
  966.  
  967.         /* test for valid value */
  968.         if ((Selected == MONTH) && (wDateTime[MONTH] > 12)){
  969.             WinAlarm(HWND_DESKTOP, WA_WARNING);
  970.             wDateTime[MONTH] = savevalue;
  971.             PreviousSelected = NOSELECT;
  972.             return;
  973.         }
  974.         if ((Selected == DAY) && (wDateTime[DAY] > 31)){
  975.             WinAlarm(HWND_DESKTOP, WA_WARNING);
  976.             wDateTime[DAY] = savevalue;
  977.             PreviousSelected = NOSELECT;
  978.             return;
  979.         }
  980.  
  981.         /* finally, update screen                                          */
  982.         PaintDateTime(hpsPanel);
  983.         break;
  984.  
  985.     default:                           /* outside relevant date/time */
  986.         if (Selected != NOSELECT) {    /* end "usSet" mode             */
  987.             wPrevDateTime[Selected] = -1; /* unhilite hilited        */
  988.             PreviousSelected = Selected;
  989.             Selected = NOSELECT;
  990.             PaintDateTime( hpsPanel);
  991.         }
  992.         break;
  993.  
  994.     }
  995. }
  996. /****************************************************************\
  997.  *
  998.  *--------------------------------------------------------------
  999.  *
  1000.  *  Name:ControlMinMax()
  1001.  *
  1002.  *  Purpose:
  1003.  *
  1004.  *
  1005.  *
  1006.  *  Usage:
  1007.  *
  1008.  *  Method:
  1009.  *          -
  1010.  *
  1011.  *          -
  1012.  *          -
  1013.  *
  1014.  *          -
  1015.  *          -
  1016.  *
  1017.  *  Returns:
  1018.  *
  1019.  *
  1020. \****************************************************************/
  1021. VOID ControlMinmax( MPARAM mp1,HWND hwnd )
  1022. {
  1023.  
  1024.     bIsIconic = (BOOL)( (((PSWP)mp1)->fl & SWP_MINIMIZE) != (SHORT) 0);
  1025.  
  1026.     if ( bIsIconic )
  1027.     {
  1028.           /*
  1029.            *A bad thing in dialog boxes is that when they are minimized they
  1030.            *still draw there control windows over the supplied icon. So we
  1031.            *find if we are minimizing or restoring and hide the control window
  1032.            *in the left button, happen to be MBID_OK
  1033.            */
  1034.            WinShowWindow(WinWindowFromID(hwnd,MBID_OK),FALSE);
  1035.  
  1036.  
  1037.     }
  1038. }
  1039.  
  1040. /****************************************************************\
  1041.  *
  1042.  *--------------------------------------------------------------
  1043.  *
  1044.  *  Name:
  1045.  *
  1046.  *  Purpose:
  1047.  *
  1048.  *
  1049.  *
  1050.  *  Usage:
  1051.  *
  1052.  *  Method:
  1053.  *          -
  1054.  *
  1055.  *          -
  1056.  *          -
  1057.  *
  1058.  *          -
  1059.  *          -
  1060.  *
  1061.  *  Returns:
  1062.  *
  1063.  *
  1064. \****************************************************************/
  1065. VOID  PanelPaint(  HPS hpsPanel)
  1066. {
  1067.    SHORT   iter;
  1068.  
  1069.     /*****************************************************************/
  1070.     /*  Write the date and time                                      */
  1071.     /*****************************************************************/
  1072.  
  1073.     /*****************************************************************/
  1074.     /*  Paint static fields                                          */
  1075.     /*****************************************************************/
  1076.  
  1077.     for(iter=0; iter<2; iter++)
  1078.     {
  1079.         WinDrawText( hpsPanel,
  1080.                      -1,
  1081.                      (PSZ)szTimeSep,
  1082.                      (PRECTL)&rTimeSep[iter],
  1083.                      SYSCLR_WINDOWTEXT,
  1084.                      SYSCLR_WINDOW,
  1085.                      DT_CENTER | DT_VCENTER );
  1086.         WinDrawText( hpsPanel,
  1087.                      -1,
  1088.                      (PSZ)szDateSep,
  1089.                      (PRECTL)&rDateSep[iter],
  1090.                      SYSCLR_WINDOWTEXT,
  1091.                      SYSCLR_WINDOW,
  1092.                      DT_CENTER | DT_VCENTER );
  1093.     }
  1094.  
  1095.     /*****************************************************************/
  1096.     /*  Paint varying fields                                         */
  1097.     /*****************************************************************/
  1098.     if (Selected == NOSELECT)
  1099.     {
  1100.        if (!fDateFreez) GetDate();
  1101.        if (!fTimeFreez) GetTime();
  1102.     }
  1103.  
  1104.     for (iter=0;iter<6;iter++)    /* ensure all fields get painted   */
  1105.        wPrevDateTime[iter] = -1;
  1106.     PaintDateTime( hpsPanel);
  1107.  
  1108.  
  1109.     /*****************************************************************/
  1110.     /*  This call was causing a problem where hitting Alt when       */
  1111.     /*  Time or Date selected didn't get rid of Menu highlight.      */
  1112.     /*  I'm not sure what it was doing here anyway...                */
  1113.     /*****************************************************************/
  1114.  
  1115. }   /* End of PanelPaint */
  1116. /****************************************************************\
  1117.  *
  1118.  *--------------------------------------------------------------
  1119.  *
  1120.  *  Name:PaintDateTime()
  1121.  *
  1122.  *  Purpose:
  1123.  *
  1124.  *
  1125.  *
  1126.  *  Usage:
  1127.  *
  1128.  *  Method:
  1129.  *          -
  1130.  *
  1131.  *          -
  1132.  *          -
  1133.  *
  1134.  *          -
  1135.  *          -
  1136.  *
  1137.  *  Returns: VOID
  1138.  *
  1139.  *
  1140. \****************************************************************/
  1141. VOID  PaintDateTime(HPS hpsPanel)
  1142. {
  1143.     SHORT   iter;
  1144.     CHAR  szNumber[4];                 /* ascii value                */
  1145.     CHAR  szPadding[4];                /* pad numbers on left        */
  1146.     SHORT   wHourSave;                   /* hours altered for 12hr fmt  */
  1147.     SHORT   wYearSave;                   /* year moduloed 100          */
  1148.  
  1149.     /*****************************************************************/
  1150.     /*  Save hours and year first. Outside here yields: Cur. held     */
  1151.     /*  as DOS uses; Prev. as drawn in panel. Inside here: both      */
  1152.     /*  Cur and Prev drawn as in Panel.                              */
  1153.     /*****************************************************************/
  1154.     wHourSave = wDateTime[HOUR];
  1155.     wYearSave = wDateTime[YEAR];
  1156.  
  1157.     if (bTwelveHourFormat)
  1158.     {
  1159.         if (wDateTime[HOUR] > 12)
  1160.             wDateTime[HOUR] -= 12;
  1161.         if (wDateTime[HOUR] == 0)
  1162.             wDateTime[HOUR] = 12;
  1163.     }
  1164.  
  1165.     /*****************************************************************/
  1166.     /*  Set 1159 & 2359 (i.e. "am" "pm" etc.).                       */
  1167.     /*****************************************************************/
  1168.     if (wPrevDateTime[HOUR] != wDateTime[HOUR])
  1169.     {
  1170.         WinFillRect( hpsPanel,
  1171.                      (PRECTL)&rTimeSep[AM_PM],
  1172.                      SYSCLR_WINDOW             );
  1173.         WinDrawText( hpsPanel,
  1174.                      -1,
  1175.                      ( (wHourSave < 12) ? (PSZ)szAnteMeridian
  1176.                                         : (PSZ)szPostMeridian ),
  1177.                      (PRECTL)&rTimeSep[AM_PM],
  1178.                      SYSCLR_WINDOWTEXT,
  1179.                      SYSCLR_WINDOW,
  1180.                      DT_CENTER | DT_VCENTER );
  1181.     }
  1182.  
  1183.     /*****************************************************************/
  1184.     /*  Save the century for DOS                                     */
  1185.     /*****************************************************************/
  1186.     wDateTime[YEAR] %= 100;
  1187.  
  1188.     /*****************************************************************/
  1189.     /*  Write each field if changed or selected                      */
  1190.     /*****************************************************************/
  1191.     for (iter=0;iter< (SHORT) 6;iter++)
  1192.     {              /* (hh)-mm-ss/mm-dd-yy */
  1193.  
  1194.         if ( (wDateTime[iter] != wPrevDateTime[iter])
  1195.              || (iter == Selected)                    )
  1196.         {
  1197.  
  1198.             /*********************************************************/
  1199.             /*  Get the digit string                                 */
  1200.             /*********************************************************/
  1201.             _itoa(wDateTime[iter],szNumber,10);
  1202.  
  1203.             /*********************************************************/
  1204.             /*  Pad if less than 2 digits; blank pad iff             */
  1205.             /*  !bLeadingZero and is leftmost of time or date        */
  1206.             /*  (remember date format is dependent on coutry format) */
  1207.             /*********************************************************/
  1208.             if( wDateTime[iter]<10 )
  1209.             {
  1210.                 strcpy( szPadding,
  1211.                         ( !bLeadingZero
  1212.                           && ( (iter == HOUR) ||
  1213.                                ( rDateTime[iter].xLeft
  1214.                                  == rDateAssign[0].xLeft ) )
  1215.                           ? " "
  1216.                           : "0" )
  1217.                       );
  1218.  
  1219.                 strcat( szPadding, szNumber);
  1220.                 strcpy( szNumber, szPadding);
  1221.  
  1222.             }  /* endif <10 */
  1223.  
  1224.             /* draw field */
  1225.             WinFillRect( hpsPanel,
  1226.                          (PRECTL)&rDateTime[iter],
  1227.                          SYSCLR_WINDOW             );
  1228.             WinDrawText( hpsPanel,
  1229.                          -1,
  1230.                          (PSZ)szNumber,
  1231.                          (PRECTL)&rDateTime[iter],
  1232.                          SYSCLR_WINDOWTEXT,
  1233.                          SYSCLR_WINDOW,
  1234.                          DT_CENTER | DT_VCENTER );
  1235.  
  1236.             /* hilite if selected */
  1237.             if (iter == Selected)
  1238.                 WinInvertRect( hpsPanel,
  1239.                                (PRECTL)&rDateTime[iter]);
  1240.  
  1241.         }  /* end if != ... */
  1242.  
  1243.         /*************************************************************/
  1244.         /*  Set new previous datetime                                */
  1245.         /*************************************************************/
  1246.         wPrevDateTime[iter] = wDateTime[iter];
  1247.  
  1248.     }    /* end for */
  1249.  
  1250.     /*****************************************************************/
  1251.     /*  Restore hours and year for setting date/time                  */
  1252.     /*****************************************************************/
  1253.    wDateTime[HOUR] = wHourSave;
  1254.    wDateTime[YEAR] = wYearSave;
  1255.  
  1256. }
  1257. /****************************************************************\
  1258.  *
  1259.  *--------------------------------------------------------------
  1260.  *
  1261.  *  Name: GetTime
  1262.  *
  1263.  *  Purpose:
  1264.  *  Get the current date and time.
  1265.  *
  1266.  *
  1267.  *  Usage:
  1268.  *
  1269.  *  Method:
  1270.  *          -
  1271.  *
  1272.  *          -
  1273.  *          -
  1274.  *
  1275.  *          -
  1276.  *          -
  1277.  *
  1278.  *  Returns:
  1279.  *          1 - if sucessful execution completed
  1280.  *          0 - if error
  1281. \****************************************************************/
  1282. VOID  GetTime(VOID)
  1283. {
  1284.     struct _DATETIME DT;
  1285.  
  1286.     DosGetDateTime( (LPDT)&DT);
  1287.     wDateTime[HOUR]   = (USHORT)DT.hours;
  1288.     wDateTime[MINUTE] = (USHORT)DT.minutes;
  1289.     wDateTime[SECOND] = (USHORT)DT.seconds;
  1290. }
  1291. /****************************************************************\
  1292.  *
  1293.  *--------------------------------------------------------------
  1294.  *
  1295.  *  Name:GetDate()
  1296.  *
  1297.  *  Purpose:
  1298.  *
  1299.  *
  1300.  *
  1301.  *  Usage:
  1302.  *
  1303.  *  Method:
  1304.  *          -
  1305.  *
  1306.  *          -
  1307.  *          -
  1308.  *
  1309.  *          -
  1310.  *          -
  1311.  *
  1312.  *  Returns:
  1313.  *          1 - if sucessful execution completed
  1314.  *          0 - if error
  1315. \****************************************************************/
  1316. VOID  GetDate(VOID)
  1317. {
  1318.     struct _DATETIME DT;
  1319.  
  1320.     DosGetDateTime( (LPDT)&DT);
  1321.     wDateTime[MONTH] = (USHORT)DT.month;
  1322.     wDateTime[DAY]   = (USHORT)DT.day;
  1323.     wDateTime[YEAR]  =       DT.year; /* Year is two bytes          */
  1324. }
  1325.  
  1326. /****************************************************************\
  1327.  *
  1328.  *--------------------------------------------------------------
  1329.  *
  1330.  *  Name:PanelVScrolls()
  1331.  *
  1332.  *  Purpose:
  1333.  *
  1334.  *
  1335.  *
  1336.  *  Usage:
  1337.  *
  1338.  *  Method:
  1339.  *          -
  1340.  *
  1341.  *          -
  1342.  *          -
  1343.  *
  1344.  *          -
  1345.  *          -
  1346.  *
  1347.  *  Returns:
  1348.  *
  1349.  *
  1350. \****************************************************************/
  1351. VOID  PanelVScrolls(HWND hwnd,USHORT ScrollMsg,MPARAM idScroll)
  1352. {
  1353.     HPS  hpsPanel;
  1354.  
  1355.     hpsPanel = WinGetPS(hwnd);
  1356.     switch(ScrollMsg)
  1357.     {
  1358.     case SB_LINEUP:                    /* line left                  */
  1359.     case SB_PAGEUP:                    /* page left                  */
  1360.  
  1361.         if (idScroll == (MPARAM)SCROLL_TIME)
  1362.             ChangeDateTime( hpsPanel, hwnd, UPTIME,  0);
  1363.         else
  1364.             ChangeDateTime( hpsPanel, hwnd, UPDATE, 0);
  1365.         WinReleasePS( hpsPanel);
  1366.         break;
  1367.  
  1368.  
  1369.     case SB_LINEDOWN:                  /* line right                 */
  1370.     case SB_PAGEDOWN:                  /* page right                 */
  1371.  
  1372.         if (idScroll == (MPARAM)SCROLL_TIME)
  1373.             ChangeDateTime( hpsPanel, hwnd, DOWNTIME, 0);
  1374.         else
  1375.             ChangeDateTime( hpsPanel, hwnd, DOWNDATE, 0);
  1376.         WinReleasePS( hpsPanel);
  1377.         break;
  1378.  
  1379.     default:
  1380.         WinReleasePS( hpsPanel);
  1381.         break;
  1382.     }
  1383. }
  1384.  
  1385. /****************************************************************\
  1386.  *
  1387.  *--------------------------------------------------------------
  1388.  *
  1389.  *  Name:MouseTrack()
  1390.  *
  1391.  *  Purpose:
  1392.  *
  1393.  *
  1394.  *
  1395.  *  Usage:
  1396.  *
  1397.  *  Method:
  1398.  *          -
  1399.  *
  1400.  *          -
  1401.  *          -
  1402.  *
  1403.  *          -
  1404.  *          -
  1405.  *
  1406.  *  Returns:
  1407.  *          Offset for mouse pointer if the mouse was hit
  1408. \****************************************************************/
  1409. SHORT MouseTrack(MPARAM mp1)
  1410. {
  1411.     POINTL  ptl;
  1412.     SHORT   iter;
  1413.  
  1414.     ptl.x = (ULONG)LOUSHORT( mp1);
  1415.     ptl.y = (ULONG)HIUSHORT( mp1);
  1416.  
  1417.     for (iter=0;iter<6;iter++)
  1418.         if ( WinPtInRect( hab,
  1419.                           (PRECTL)&rDateTime[iter],
  1420.                           &ptl)      )
  1421.             return(iter);
  1422.  
  1423.     return(NOSELECT);
  1424. }
  1425. /****************************************************************\
  1426.  *
  1427.  *--------------------------------------------------------------
  1428.  *
  1429.  *  Name:GetCountryDependent()
  1430.  *
  1431.  *  Purpose:
  1432.  *
  1433.  *
  1434.  *
  1435.  *  Usage:
  1436.  *
  1437.  *  Method:
  1438.  *          -
  1439.  *
  1440.  *          -
  1441.  *          -
  1442.  *
  1443.  *          -
  1444.  *          -
  1445.  *
  1446.  *  Returns: VOID
  1447.  *
  1448.  *
  1449. \****************************************************************/
  1450. VOID GetCountryDependent(VOID )
  1451. {
  1452.     ULONG       iTemp;
  1453.     COUNTRYCODE DosCyCode;
  1454.     COUNTRYINFO DosCyInfo;
  1455.     USHORT      Country;
  1456.     BOOL        DosCy;
  1457.  
  1458.     /*****************************************************************/
  1459.     /*  Get the DOS country info to use as default if OS2.INI lacks. */
  1460.     /*****************************************************************/
  1461.     DosCyCode.country = 0;             /* Get default                */
  1462.     DosCyCode.codepage = 0;            /* Get current process CP     */
  1463.     DosCy = (BOOL) !DosGetCtryInfo( sizeof(COUNTRYINFO),
  1464.                              (PCOUNTRYCODE)&DosCyCode,
  1465.                              (PCOUNTRYINFO)&DosCyInfo,
  1466.                              (PULONG)&iTemp           );
  1467.     /*****************************************************************/
  1468.     /*  If no info found by Dos, set USA                             */
  1469.     /*****************************************************************/
  1470.     Country = (USHORT)( DosCy ? DosCyInfo.country : COUNTRY_USA) ;
  1471.  
  1472.     /*****************************************************************/
  1473.     /* get 12/24 hours format flag                                    */
  1474.     /*****************************************************************/
  1475.     iTemp = PrfQueryProfileInt( HINI_USER,
  1476.                                 (PSZ)"PM_National",
  1477.                                 (PSZ)"iTime",
  1478.                                 (SHORT) (DosCy ? DosCyInfo.fsTimeFmt
  1479.                                          : 0  ) );
  1480.     /*****************************************************************/
  1481.     /* 0 == twelve hours format; 1 == twenty-four hours format         */
  1482.     /*****************************************************************/
  1483.     bTwelveHourFormat = (BOOL) !iTemp;
  1484.  
  1485.     /*****************************************************************/
  1486.     /* leading zero                                                  */
  1487.     /*****************************************************************/
  1488.     bLeadingZero = (BOOL)PrfQueryProfileInt( HINI_USER,
  1489.                                              (PSZ)"PM_National",
  1490.                                              (PSZ)"iLzero",
  1491.                                              0                  );
  1492.  
  1493.  
  1494.     /*****************************************************************/
  1495.     /* date separator string                                         */
  1496.     /*****************************************************************/
  1497.     PrfQueryProfileString( HINI_USER,
  1498.                            (PSZ)"PM_National",
  1499.                            (PSZ)"sDate",
  1500.                            DosCy ? (PSZ)DosCyInfo.szDateSeparator
  1501.                                  : (PSZ)"/",
  1502.                            (PSZ)szDateSep,
  1503.                            (ULONG)DATE_SEP_LEN+1                         );
  1504.  
  1505.  
  1506.     /*****************************************************************/
  1507.     /* time separator string                                         */
  1508.     /*****************************************************************/
  1509.     PrfQueryProfileString( HINI_USER,
  1510.                            (PSZ)"PM_National",
  1511.                            (PSZ)"sTime",
  1512.                            DosCy ? (PSZ)DosCyInfo.szTimeSeparator
  1513.                                  : (PSZ)":",
  1514.                            (PSZ)szTimeSep,
  1515.                            (ULONG)TIME_SEP_LEN+1                         );
  1516.  
  1517.     /*****************************************************************/
  1518.     /* AM/PM strings                                                 */
  1519.     /*****************************************************************/
  1520.     PrfQueryProfileString( HINI_USER,
  1521.                            (PSZ)"PM_National",
  1522.                            (PSZ)"s1159",
  1523.                            Country == COUNTRY_USA
  1524.                             ? (PSZ)"AM"
  1525.                             : Country == COUNTRY_UK
  1526.                               ? (PSZ)"am"
  1527.                               : (PSZ)"",
  1528.                            (PSZ)szAnteMeridian,
  1529.                            (ULONG)STRING_AM_LEN+1           );
  1530.     PrfQueryProfileString( HINI_USER,
  1531.                            (PSZ)"PM_National",
  1532.                            (PSZ)"s2359",
  1533.                            Country == COUNTRY_USA
  1534.                             ? (PSZ)"PM"
  1535.                             : Country == COUNTRY_UK
  1536.                               ? (PSZ)"pm"
  1537.                               : (PSZ)"",
  1538.                            (PSZ)szPostMeridian,
  1539.                            (ULONG)STRING_PM_LEN+1           );
  1540.  
  1541.     sFirstTime = HOUR;
  1542.     asLeftOf[HOUR] = SECOND;
  1543.     asLeftOf[MINUTE] = HOUR;
  1544.     asLeftOf[SECOND] = MINUTE;
  1545.     asRightOf[HOUR] = MINUTE;
  1546.     asRightOf[MINUTE] = SECOND;
  1547.     asRightOf[SECOND] = HOUR;
  1548.  
  1549.     /*****************************************************************/
  1550.     /* that cool way of doing date format                            */
  1551.     /*****************************************************************/
  1552.     vusDateFormat = iTemp = PrfQueryProfileInt( HINI_USER,
  1553.                                 (PSZ)"PM_National",
  1554.                                 (PSZ)"iDate",
  1555.                                 (SHORT ) ( DosCy ? DosCyInfo.fsDateFmt
  1556.                                           : 0 )  );
  1557.     switch(iTemp)
  1558.     {
  1559.     case 2:
  1560.         /*************************************************************/
  1561.         /*                      YMD                                  */
  1562.         /*************************************************************/
  1563.         WinCopyRect( hab,
  1564.                      (PRECTL)&rDateTime[YEAR],
  1565.                      (PRECTL)&rDateAssign[0]    );
  1566.         WinCopyRect( hab,
  1567.                      (PRECTL)&rDateTime[MONTH],
  1568.                      (PRECTL)&rDateAssign[1]    );
  1569.         WinCopyRect( hab,
  1570.                      (PRECTL)&rDateTime[DAY],
  1571.                      (PRECTL)&rDateAssign[2]    );
  1572.         sFirstDate = YEAR;
  1573.         asLeftOf[YEAR] = DAY;
  1574.         asLeftOf[MONTH] = YEAR;
  1575.         asLeftOf[DAY] = MONTH;
  1576.         asRightOf[YEAR] = MONTH;
  1577.         asRightOf[MONTH] = DAY;
  1578.         asRightOf[DAY] = YEAR;
  1579.         break;
  1580.     case 1:
  1581.         /*************************************************************/
  1582.         /*                      DMY                                  */
  1583.         /*************************************************************/
  1584.         WinCopyRect( hab,
  1585.                      (PRECTL)&rDateTime[DAY],
  1586.                      (PRECTL)&rDateAssign[0]    );
  1587.         WinCopyRect( hab,
  1588.                      (PRECTL)&rDateTime[MONTH],
  1589.                      (PRECTL)&rDateAssign[1]    );
  1590.         WinCopyRect( hab,
  1591.                      (PRECTL)&rDateTime[YEAR],
  1592.                      (PRECTL)&rDateAssign[2]    );
  1593.         sFirstDate = DAY;
  1594.         asLeftOf[YEAR] = MONTH;
  1595.         asLeftOf[MONTH] = DAY;
  1596.         asLeftOf[DAY] = YEAR;
  1597.         asRightOf[YEAR] = DAY;
  1598.         asRightOf[MONTH] = YEAR;
  1599.         asRightOf[DAY] = MONTH;
  1600.         break;
  1601.     case 0:
  1602.     default:
  1603.         /*************************************************************/
  1604.         /*                      MDY        USA == default            */
  1605.         /*************************************************************/
  1606.         WinCopyRect( hab,
  1607.                      (PRECTL)&rDateTime[MONTH],
  1608.                      (PRECTL)&rDateAssign[0]    );
  1609.         WinCopyRect( hab,
  1610.                      (PRECTL)&rDateTime[DAY],
  1611.                      (PRECTL)&rDateAssign[1]    );
  1612.         WinCopyRect( hab,
  1613.                      (PRECTL)&rDateTime[YEAR],
  1614.                      (PRECTL)&rDateAssign[2]    );
  1615.         sFirstDate = MONTH;
  1616.         asLeftOf[YEAR] = DAY;
  1617.         asLeftOf[MONTH] = YEAR;
  1618.         asLeftOf[DAY] = MONTH;
  1619.         asRightOf[YEAR] = MONTH;
  1620.         asRightOf[MONTH] = DAY;
  1621.         asRightOf[DAY] = YEAR;
  1622.         break;
  1623.     }
  1624.  
  1625.  
  1626. }
  1627. /****************************************************************\
  1628.  *
  1629.  *--------------------------------------------------------------
  1630.  *
  1631.  *  Name:BringUpArrows.
  1632.  *
  1633.  *  Purpose:
  1634.  *    Take care of up down arrows
  1635.  *
  1636.  *
  1637.  *  Usage:
  1638.  *
  1639.  *  Method:
  1640.  *          -
  1641.  *
  1642.  *          -
  1643.  *          -
  1644.  *
  1645.  *          -
  1646.  *          -
  1647.  *
  1648.  *  Returns:
  1649.  *
  1650.  *
  1651. \****************************************************************/
  1652. VOID BringUpArrows(HWND hwnd,SHORT Item)
  1653. {
  1654.  
  1655.    if( (Item>=HOUR) && (Item<=SECOND) )
  1656.    {     /* time item           */
  1657.  
  1658.       /* Set focus to current groupbox if control panel has focus */
  1659.       if ( WinQueryWindow(WinQueryFocus(HWND_DESKTOP), QW_PARENT) == hwnd )
  1660.       {
  1661.          WinSetFocus(HWND_DESKTOP, hTime);
  1662.          hCurrentFocus = hTime;
  1663.  
  1664.       }
  1665.    } /* endif time */
  1666.  
  1667.    else if( (Item>=MONTH) && (Item<=YEAR) )
  1668.    {   /* date item         */
  1669.  
  1670.       /* Set focus to current groupbox if control panel has focus */
  1671.       if ( WinQueryWindow(WinQueryFocus(HWND_DESKTOP), QW_PARENT) == hwnd)
  1672.       {
  1673.          WinSetFocus(HWND_DESKTOP, hDate);
  1674.          hCurrentFocus = hDate;
  1675.  
  1676.  
  1677.       }
  1678.    } /* endif Date */
  1679.  
  1680. }
  1681.  
  1682. /****************************************************************\
  1683.  *
  1684.  *--------------------------------------------------------------
  1685.  *
  1686.  *  Name: FixDate
  1687.  *
  1688.  *  Purpose:
  1689.  *  Takes care of date wraparound
  1690.  *
  1691.  *
  1692.  *  Usage:
  1693.  *
  1694.  *  Method:
  1695.  *          -
  1696.  *
  1697.  *          -
  1698.  *          -
  1699.  *
  1700.  *          -
  1701.  *          -
  1702.  *
  1703.  *  Returns:
  1704.  *
  1705.  *
  1706. \****************************************************************/
  1707. VOID  FixDate(SHORT Field)
  1708. {
  1709.     switch(Field)
  1710.     {
  1711.     case MONTH:
  1712.         if (wDateTime[MONTH] > 12)
  1713.             wDateTime[MONTH] = 1;
  1714.         if (wDateTime[MONTH] < 1)
  1715.             wDateTime[MONTH] = 12;
  1716.         FixDate(DAY);                    /* keep day in new bounds   */
  1717.         break;
  1718.  
  1719.     case DAY:
  1720.         /* check for leap year */
  1721.         if ( ( (wDateTime[YEAR] % 4 == 0 && wDateTime[YEAR] % 100 != 0)
  1722.                || wDateTime[YEAR] % 400 == 0
  1723.              ) && wDateTime[MONTH] == 2
  1724.            ) {
  1725.             if(wDateTime[DAY] > 29) wDateTime[DAY] = 1;
  1726.             if(wDateTime[DAY] < 1) wDateTime[DAY] = 29;
  1727.         }
  1728.         else
  1729.         {   /* non-leap year   */
  1730.             if (wDateTime[DAY] > DaysPerMonth[wDateTime[MONTH]])
  1731.                 wDateTime[DAY] = 1;
  1732.             if (wDateTime[DAY] < 1)
  1733.                 wDateTime[DAY] = DaysPerMonth[wDateTime[MONTH]];
  1734.         }
  1735.         break;
  1736.  
  1737.     case YEAR:
  1738.         if (wDateTime[YEAR] > 2079)
  1739.             wDateTime[YEAR] = 1980;
  1740.         if (wDateTime[YEAR] < 1980)
  1741.             wDateTime[YEAR] = 2079;
  1742.         FixDate(DAY);                    /* for leap yr. to non-leap */
  1743.         break;
  1744.  
  1745.    }
  1746.  
  1747. }
  1748.  
  1749.  
  1750. /****************************************************************\
  1751.  *
  1752.  *--------------------------------------------------------------
  1753.  *
  1754.  *  Name:Settime
  1755.  *
  1756.  *  Purpose:
  1757.  *  Sets the system time.
  1758.  *
  1759.  *
  1760.  *  Usage:
  1761.  *
  1762.  *  Method:
  1763.  *          -
  1764.  *
  1765.  *          -
  1766.  *          -
  1767.  *
  1768.  *          -
  1769.  *          -
  1770.  *
  1771.  *  Returns:
  1772.  *          1 - if sucessful execution completed
  1773.  *          0 - if error
  1774. \****************************************************************/
  1775. VOID  SetTime(VOID)
  1776. {
  1777.     struct _DATETIME DT;
  1778.     APIRET rc;
  1779.  
  1780.     DosGetDateTime( (LPDT)&DT);
  1781.     DT.hours   = (BYTE)wDateTime[HOUR]  ;
  1782.     DT.minutes = (BYTE)wDateTime[MINUTE];
  1783.     DT.seconds = (BYTE)wDateTime[SECOND];
  1784.     rc = DosSetDateTime( (LPDT)&DT);
  1785.     if (rc)
  1786.     {
  1787.           WinAlarm(HWND_DESKTOP, WA_WARNING);
  1788.     }
  1789.     /*
  1790.      *if the alarm
  1791.      *is set then update
  1792.      *it
  1793.      */
  1794.      if(cp.alarm.usMode & AM_ACTIVE )
  1795.      {
  1796.           AlarmSetTimer(cp.alarm.uchHour,
  1797.                               cp.alarm.uchMinutes);
  1798.      }
  1799.  
  1800. }
  1801. /****************************************************************\
  1802.  *
  1803.  *--------------------------------------------------------------
  1804.  *
  1805.  *  Name:SetDate()
  1806.  *
  1807.  *  Purpose:
  1808.  *  Set system date.
  1809.  *
  1810.  *
  1811.  *  Usage:
  1812.  *
  1813.  *  Method:
  1814.  *          -
  1815.  *
  1816.  *          -
  1817.  *          -
  1818.  *
  1819.  *          -
  1820.  *          -
  1821.  *
  1822.  *  Returns: VOID
  1823.  *
  1824.  *
  1825. \****************************************************************/
  1826. VOID SetDate(VOID)
  1827. {
  1828.     struct _DATETIME DT;
  1829.     APIRET rc;
  1830.  
  1831.     DosGetDateTime( (LPDT)&DT);
  1832.     DT.month = (BYTE)wDateTime[MONTH];
  1833.     DT.day   = (BYTE)wDateTime[DAY]  ;
  1834.     DT.year  =       wDateTime[YEAR] ; /* Year is two bytes          */
  1835.     rc = DosSetDateTime( (LPDT)&DT);
  1836.     if (rc)
  1837.     {
  1838.           WinAlarm(HWND_DESKTOP, WA_WARNING);
  1839.     }
  1840.  
  1841.     /*
  1842.      *if the alarm
  1843.      *is set then update
  1844.      *it
  1845.      */
  1846.      if(cp.alarm.usMode & AM_ACTIVE )
  1847.      {
  1848.  
  1849.           AlarmSetTimer(cp.alarm.uchHour,
  1850.                               cp.alarm.uchMinutes);
  1851.      }
  1852. }
  1853.  
  1854. /*--------------------------------------------------------------*\
  1855.  *  End of file :udtime.c
  1856. \*--------------------------------------------------------------*/
  1857.